[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[数值计算] [分享]24点计算批处理脚本

原创区貌似俺发不了帖子,反正还有BUG,就先发到这里讨论一下.
24点计算脚本,用户给出数字,脚本给出式子:
由于cmd只支持整数运算,在计算例如2 3 4 5数字组合时,有时会有BUG
由于相同原因,脚本解不出类似 5 5 5 1的组合
经过了一定的优化,速度和代码量有所改善,但还有待提高.
  1. @echo off&&color f2&&title SYBN 24点自动计算脚本 V0.2&&setlocal enabledelayedexpansion
  2. set ff1=^*
  3. set ff2=^+
  4. set ff3=^-
  5. set ff4=^/
  6. set S1=1
  7. set S2=2
  8. set S3=3
  9. set S4=4
  10. : begain
  11. set b1=0
  12. set b2=1
  13. set b3=1
  14. set SS=1
  15. set XS=1
  16. set cf=1
  17. set cs=0
  18. set c1=0
  19. set c2=0
  20. set c3=0
  21. set c4=0
  22. set c5=0
  23. set c6=0
  24. echo ============= .: SYBN 24点自动计算脚本 V0.2 :. ==============
  25. echo 请依次输入要用于计算的4个数字,并以空格隔开.例如输入:"1 2 3 4".
  26. set /p p=[默认: %S1% %S2% %S3% %S4%]:
  27. for /f "tokens=1,2,3,4,*" %%a in ("%p%") do if not "%%b" == "" set /a S1=%%a&& set /a S2=%%b&& set /a S3=%%c&& set /a S4=%%d&&if not "%%e" == "" set /a SS=%%e
  28. if %S1% lss 1 goto wx
  29. if %S2% lss 1 goto wx
  30. if %S3% lss 1 goto wx
  31. if %S4% lss 1 goto wx
  32. if %S1% gtr 13 goto wx
  33. if %S2% gtr 13 goto wx
  34. if %S3% gtr 13 goto wx
  35. if %S4% gtr 13 goto wx
  36. if %SS% == 543001 echo on&&set SS=1
  37. if %S1% == %S2% set /a cf=cf+1
  38. if %S1% == %S3% set /a cf=cf+1&&set /a S5=S2&&set /a S2=S3&&set /a S3=!S5!
  39. if %S2% == %S3% if not %S1% == %S2% set /a cf=cf+1&&set /a S5=S1&&set /a S1=S3&&set /a S3=!S5!
  40. if %S1% == %S4% set /a cf=cf+1&&set /a S5=S4&&set /a S4=S3&&set /a S3=S2&&set /a S2=!S5!
  41. if %S2% == %S4% set /a cf=cf+1&&set /a S5=S4&&set /a S4=S3&&set /a S3=S1&&set /a S1=!S5!
  42. if %S3% == %S4% if %S2% == %S3% set /a cf=4
  43. if %S3% == %S4% if not %S2% == %S3% set /a cf=5
  44. ::echo %S1% %S2% %S3% %S4% %SS% %cf%
  45. ::pause
  46. : pl
  47. set /a b1=b1+1
  48. if %b1% gtr 4 set /a b1=1&& set /a b2=b2+1
  49. if %b2% gtr 4 set /a b2=1&& set /a b3=b3+1
  50. if %b3% gtr 4 echo 无解!&& goto begain
  51. set f1=!ff%b1%!
  52. set f2=!ff%b2%!
  53. set f3=!ff%b3%!
  54. if %b2% == 1 title 正在计算^-
  55. if %b2% == 2 title 正在计算^\
  56. if %b2% == 3 title 正在计算^|
  57. if %b2% == 4 title 正在计算^/
  58. if %cf% == 4 (
  59. call :js %S1% %S1% %S1% %S1% %f1% %f2% %f3%
  60. goto pl
  61. )
  62. if %cf% == 3 (
  63. call :js %S1% %S1% %S1% %S4% %f1% %f2% %f3%
  64. call :js %S1% %S1% %S4% %S1% %f1% %f2% %f3%
  65. call :js %S1% %S4% %S1% %S1% %f1% %f2% %f3%
  66. call :js %S4% %S1% %S1% %S1% %f1% %f2% %f3%
  67. goto pl
  68. )
  69. if %cf% == 5 (
  70. call :js %S1% %S1% %S3% %S3% %f1% %f2% %f3%
  71. call :js %S1% %S3% %S1% %S3% %f1% %f2% %f3%
  72. call :js %S1% %S3% %S3% %S1% %f1% %f2% %f3%
  73. call :js %S3% %S1% %S1% %S3% %f1% %f2% %f3%
  74. call :js %S3% %S1% %S3% %S1% %f1% %f2% %f3%
  75. call :js %S3% %S3% %S1% %S1% %f1% %f2% %f3%
  76. goto pl
  77. )
  78. call :js %S1% %S2% %S3% %S4% %f1% %f2% %f3%
  79. call :js %S1% %S2% %S4% %S3% %f1% %f2% %f3%
  80. call :js %S1% %S3% %S2% %S4% %f1% %f2% %f3%
  81. call :js %S1% %S3% %S4% %S2% %f1% %f2% %f3%
  82. call :js %S1% %S4% %S2% %S3% %f1% %f2% %f3%
  83. call :js %S1% %S4% %S3% %S2% %f1% %f2% %f3%
  84. if not %cf% == 2 call :js %S2% %S1% %S3% %S4% %f1% %f2% %f3%
  85. if not %cf% == 2 call :js %S2% %S1% %S4% %S3% %f1% %f2% %f3%
  86. if not %cf% == 2 call :js %S2% %S3% %S1% %S4% %f1% %f2% %f3%
  87. if not %cf% == 2 call :js %S2% %S3% %S4% %S1% %f1% %f2% %f3%
  88. if not %cf% == 2 call :js %S2% %S4% %S1% %S3% %f1% %f2% %f3%
  89. if not %cf% == 2 call :js %S2% %S4% %S3% %S1% %f1% %f2% %f3%
  90. call :js %S3% %S1% %S2% %S4% %f1% %f2% %f3%
  91. call :js %S3% %S1% %S4% %S2% %f1% %f2% %f3%
  92. if not %cf% == 2 call :js %S3% %S2% %S1% %S4% %f1% %f2% %f3%
  93. if not %cf% == 2 call :js %S3% %S2% %S4% %S1% %f1% %f2% %f3%
  94. call :js %S3% %S4% %S1% %S2% %f1% %f2% %f3%
  95. if not %cf% == 2 call :js %S3% %S4% %S2% %S1% %f1% %f2% %f3%
  96. call :js %S4% %S1% %S2% %S3% %f1% %f2% %f3%
  97. call :js %S4% %S1% %S3% %S2% %f1% %f2% %f3%
  98. if not %cf% == 2 call :js %S4% %S2% %S1% %S3% %f1% %f2% %f3%
  99. if not %cf% == 2 call :js %S4% %S2% %S3% %S1% %f1% %f2% %f3%
  100. call :js %S4% %S3% %S1% %S2% %f1% %f2% %f3%
  101. if not %cf% == 2 call :js %S4% %S3% %S2% %S1% %f1% %f2% %f3%
  102. goto pl
  103. : wx
  104. title 对不起,您输入的数字无效,请重新输入.
  105. goto begain
  106. :js
  107. if %XS% gtr %SS% goto begain
  108. set /a j=100*(%1%5%2%6%3%7%4) 2>nul
  109. set X=%1%5%2%6%3%7%4
  110. if %j% == 2400 call :24 &&goto :EOF
  111. set /a j=100*((%1%5%2)%6%3%7%4) 2>nul
  112. set X=(%1%5%2)%6%3%7%4
  113. if %j% == 2400 call :24 &&goto :EOF
  114. set /a j=100*(%1%5(%2%6%3)%7%4) 2>nul
  115. set X=%1%5(%2%6%3)%7%4
  116. if %j% == 2400 call :24 &&goto :EOF
  117. set /a j=100*(%1%5%2%6(%3%7%4)) 2>nul
  118. set X=%1%5%2%6(%3%7%4)
  119. if %j% == 2400 call :24 &&goto :EOF
  120. set /a j=100*((%1%5%2%6%3)%7%4) 2>nul
  121. set X=(%1%5%2%6%3)%7%4
  122. if %j% == 2400 call :24 &&goto :EOF
  123. set /a j=100*((%1%5%2)%6(%3%7%4)) 2>nul
  124. set X=(%1%5%2)%6(%3%7%4)
  125. if %j% == 2400 call :24 &&goto :EOF
  126. set /a j=100*(%1%5(%2%6%3%7%4)) 2>nul
  127. set X=%1%5(%2%6%3%7%4)
  128. if %j% == 2400 call :24 &&goto :EOF
  129. set /a j=100*(((%1%5%2)%6%3)%7%4) 2>nul
  130. set X=((%1%5%2)%6%3)%7%4
  131. if %j% == 2400 call :24 &&goto :EOF
  132. set /a j=100*((%1%5(%2%6%3))%7%4) 2>nul
  133. set X=(%1%5(%2%6%3))%7%4
  134. if %j% == 2400 call :24 &&goto :EOF
  135. set /a j=100*(%1%5((%2%6%3)%7%4)) 2>nul
  136. set X=%1%5((%2%6%3)%7%4)
  137. if %j% == 2400 call :24 &&goto :EOF
  138. set /a j=100*(%1%5(%2%6(%3%7%4))) 2>nul
  139. set X=%1%5(%2%6(%3%7%4))
  140. if %j% == 2400 call :24 &&goto :EOF
  141. goto :EOF
  142. :24
  143. if %j% == 2400 (
  144. echo 计算完成,结果:"%X%"^=24
  145. set /a XS=XS+1
  146. goto :EOF
  147. )
  148. goto :EOF
复制代码

[ 本帖最后由 sl543001 于 2009-11-18 18:04 编辑 ]
SYBN QQ:354324773

恩,有了吗?
郁闷啊!那也没办法了!
下回先搜搜看啊!
SYBN QQ:354324773

TOP

还真是强人,代码确实精辟得很,恩值得学习研究,研究中。。。
SYBN QQ:354324773

TOP

返回列表