Advertisement
Guest User

minesweeper

a guest
Mar 15th, 2014
1,177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.90 KB | None | 0 0
  1. (* Content-type: application/vnd.wolfram.cdf.text *)
  2.  
  3. (*** Wolfram CDF File ***)
  4. (* http://www.wolfram.com/cdf *)
  5.  
  6. (* CreatedBy='Mathematica 9.0' *)
  7.  
  8. (*************************************************************************)
  9. (* *)
  10. (* The Mathematica License under which this file was created prohibits *)
  11. (* restricting third parties in receipt of this file from republishing *)
  12. (* or redistributing it by any means, including but not limited to *)
  13. (* rights management or terms of use, without the express consent of *)
  14. (* Wolfram Research, Inc. For additional information concerning CDF *)
  15. (* licensing and redistribution see: *)
  16. (* *)
  17. (* www.wolfram.com/cdf/adopting-cdf/licensing-options.html *)
  18. (* *)
  19. (*************************************************************************)
  20.  
  21. (*CacheID: 234*)
  22. (* Internal cache information:
  23. NotebookFileLineBreakTest
  24. NotebookFileLineBreakTest
  25. NotebookDataPosition[ 1063, 20]
  26. NotebookDataLength[ 8705, 250]
  27. NotebookOptionsPosition[ 9365, 250]
  28. NotebookOutlinePosition[ 9710, 265]
  29. CellTagsIndexPosition[ 9667, 262]
  30. WindowFrame->Normal*)
  31.  
  32. (* Beginning of Notebook Content *)
  33. Notebook[{
  34. Cell[BoxData[
  35. RowBox[{"Manipulate", "[",
  36. RowBox[{
  37. RowBox[{"(", "\[IndentingNewLine]",
  38. RowBox[{
  39. RowBox[{"t", "=",
  40. RowBox[{"data", "[",
  41. RowBox[{"[",
  42. RowBox[{
  43. RowBox[{"1", ";;", "h"}], ",",
  44. RowBox[{"1", ";;", "h"}]}], "]"}], "]"}]}], ";",
  45. "\[IndentingNewLine]",
  46. RowBox[{"nums", "=",
  47. RowBox[{"p", "[",
  48. RowBox[{"t", ",",
  49. RowBox[{"_", "?", "NumberQ"}]}], "]"}]}], ";", "\[IndentingNewLine]",
  50. RowBox[{"fx", "=",
  51. RowBox[{"Nearest", "[",
  52. RowBox[{"p", "[",
  53. RowBox[{"t", ",", "x"}], "]"}], "]"}]}], ";", "\[IndentingNewLine]",
  54. RowBox[{"flagMinus", "/@",
  55. RowBox[{"p", "[",
  56. RowBox[{"t", ",", "F"}], "]"}]}], ";", "\[IndentingNewLine]",
  57. RowBox[{"eqs", "=",
  58. RowBox[{"MapIndexed", "[",
  59. RowBox[{
  60. RowBox[{
  61. RowBox[{
  62. RowBox[{"t", "[",
  63. RowBox[{"[",
  64. RowBox[{"c", "@@",
  65. RowBox[{
  66. RowBox[{"nums", "[",
  67. RowBox[{"[", "#2", "]"}], "]"}], "[",
  68. RowBox[{"[", "1", "]"}], "]"}]}], "]"}], "]"}], "\[Equal]",
  69. RowBox[{"g", "@", "#1"}]}], "&"}], ",",
  70. RowBox[{
  71. RowBox[{
  72. RowBox[{"fx", "[",
  73. RowBox[{"#", ",",
  74. RowBox[{"{",
  75. RowBox[{"8", ",", "1.5"}], "}"}]}], "]"}], "&"}], "/@",
  76. "nums"}]}], "]"}]}], ";", "\[IndentingNewLine]",
  77. RowBox[{"vars", "=",
  78. RowBox[{"Union", "@",
  79. RowBox[{"Cases", "[",
  80. RowBox[{"eqs", ",", "_q", ",", "4"}], "]"}]}]}], ";",
  81. "\[IndentingNewLine]",
  82. RowBox[{"s", "=",
  83. RowBox[{"Solve", "[",
  84. RowBox[{
  85. RowBox[{"Join", "[",
  86. RowBox[{"eqs", ",",
  87. RowBox[{"Thread", "[",
  88. RowBox[{"0", "\[LessEqual]", "vars", "<", "2"}], "]"}]}], "]"}],
  89. ",", "vars", ",", "Integers"}], "]"}]}], ";", "\[IndentingNewLine]",
  90. RowBox[{"If", "[",
  91. RowBox[{
  92. RowBox[{"s", "\[Equal]",
  93. RowBox[{"{",
  94. RowBox[{"{", "}"}], "}"}]}], ",",
  95. RowBox[{"ns", "=", "\"\<No Solutions\>\""}], ",",
  96. RowBox[{"ns", "=", "\"\<\>\""}]}], "]"}], ";", "\[IndentingNewLine]",
  97. RowBox[{"numSols", "=",
  98. RowBox[{"Length", "@", "s"}]}], ";", "\[IndentingNewLine]",
  99. RowBox[{"If", "[",
  100. RowBox[{
  101. RowBox[{"numSols", "\[NotEqual]", "0"}], ",",
  102. RowBox[{"res", "=",
  103. RowBox[{
  104. RowBox[{"(",
  105. RowBox[{"Transpose", "@", "s"}], ")"}], "[",
  106. RowBox[{"[",
  107. RowBox[{"All", ",", "All", ",", "2"}], "]"}], "]"}]}]}], "]"}], ";",
  108. "\[IndentingNewLine]",
  109. RowBox[{"If", "[",
  110. RowBox[{
  111. RowBox[{"numSols", "\[NotEqual]", "0"}], ",",
  112. RowBox[{"colMap", "=",
  113. RowBox[{"Grid", "[",
  114. RowBox[{
  115. RowBox[{"Union", "[",
  116. RowBox[{
  117. RowBox[{
  118. RowBox[{"{",
  119. RowBox[{
  120. RowBox[{"Graphics", "[",
  121. RowBox[{
  122. RowBox[{"{",
  123. RowBox[{
  124. RowBox[{"Blend", "[",
  125. RowBox[{
  126. RowBox[{"{",
  127. RowBox[{"Green", ",", "Red"}], "}"}], ",", "#"}], "]"}],
  128. ",",
  129. RowBox[{"Rectangle", "[", "]"}]}], "}"}], ",",
  130. RowBox[{"ImageSize", "\[Rule]", "20"}]}], "]"}], ",",
  131. RowBox[{"N", "@", "#"}]}], "}"}], "&"}], "/@",
  132. RowBox[{"(",
  133. RowBox[{
  134. RowBox[{"Tr", "/@", "res"}], "/", "numSols"}], ")"}]}], "]"}],
  135. ",",
  136. RowBox[{"Dividers", "\[Rule]", "All"}]}], "]"}]}], ",",
  137. RowBox[{"colMap", "=", "\"\<\>\""}]}], "]"}], ";",
  138. "\[IndentingNewLine]",
  139. RowBox[{"(*",
  140. RowBox[{
  141. "Store", " ", "Prob", " ", "of", " ", "bomb", " ", "in", " ", "h"}],
  142. "*)"}], "\[IndentingNewLine]",
  143. RowBox[{"If", "[",
  144. RowBox[{
  145. RowBox[{"numSols", "\[NotEqual]", "0"}], ",",
  146. RowBox[{"cols", "=",
  147. RowBox[{"Thread", "[",
  148. RowBox[{"Rule", "[",
  149. RowBox[{
  150. RowBox[{"First", "/@",
  151. RowBox[{"List", "@@@", "vars"}]}], ",",
  152. RowBox[{
  153. RowBox[{
  154. RowBox[{"Blend", "[",
  155. RowBox[{
  156. RowBox[{"{",
  157. RowBox[{"Green", ",", "Red"}], "}"}], ",", "#"}], "]"}],
  158. "&"}], "/@",
  159. RowBox[{"(",
  160. RowBox[{
  161. RowBox[{"Tr", "/@", "res"}], "/", "numSols"}], ")"}]}]}], "]"}],
  162. "]"}]}], ",",
  163. RowBox[{"cols", "=",
  164. RowBox[{"{", "}"}]}]}], "]"}], ";", "\[IndentingNewLine]",
  165. RowBox[{"Row", "[",
  166. RowBox[{"{",
  167. RowBox[{
  168. RowBox[{"Grid", "[",
  169. RowBox[{
  170. RowBox[{"Take", "[",
  171. RowBox[{"data", ",", "h", ",", "h"}], "]"}], ",",
  172. RowBox[{"Background", "\[Rule]",
  173. RowBox[{"{",
  174. RowBox[{"None", ",", "None", ",", "cols"}], "}"}]}], ",",
  175. RowBox[{"Alignment", "\[Rule]",
  176. RowBox[{"{",
  177. RowBox[{"Center", ",", "Center"}], "}"}]}], ",",
  178. RowBox[{"Dividers", "\[Rule]", "All"}]}], "]"}], ",", "\"\< \>\"",
  179. ",",
  180. RowBox[{"Column", "[",
  181. RowBox[{"{",
  182. RowBox[{"\"\<Probability\>\"", ",", "colMap"}], "}"}], "]"}], ",",
  183. "\"\< \>\"", ",", "ns"}], "}"}], "]"}]}], "\[IndentingNewLine]",
  184. ")"}], ",", "\[IndentingNewLine]",
  185. RowBox[{"{",
  186. RowBox[{
  187. RowBox[{"{",
  188. RowBox[{"data", ",",
  189. RowBox[{"ConstantArray", "[",
  190. RowBox[{"x", ",",
  191. RowBox[{"{",
  192. RowBox[{"10", ",", "10"}], "}"}]}], "]"}]}], "}"}], ",",
  193. RowBox[{"ControlType", "\[Rule]", "None"}]}], "}"}], ",",
  194. "\[IndentingNewLine]",
  195. RowBox[{"{",
  196. RowBox[{
  197. RowBox[{"{",
  198. RowBox[{"h", ",", "5"}], "}"}], ",", "1", ",", "10", ",", "1"}], "}"}],
  199. ",", "\[IndentingNewLine]",
  200. RowBox[{"Dynamic", "[",
  201. RowBox[{"Panel", "[",
  202. RowBox[{"Grid", "[",
  203. RowBox[{"Outer", "[",
  204. RowBox[{
  205. RowBox[{
  206. RowBox[{"PopupMenu", "[",
  207. RowBox[{
  208. RowBox[{"Dynamic", "[",
  209. RowBox[{"data", "[",
  210. RowBox[{"[",
  211. RowBox[{"#1", ",", "#2"}], "]"}], "]"}], "]"}], ",",
  212. RowBox[{"Join", "[",
  213. RowBox[{
  214. RowBox[{"{",
  215. RowBox[{"x", ",", "F"}], "}"}], ",",
  216. RowBox[{"Range", "[",
  217. RowBox[{"0", ",", "8"}], "]"}]}], "]"}]}], "]"}], "&"}], ",",
  218. RowBox[{"Range", "[", "h", "]"}], ",",
  219. RowBox[{"Range", "[", "h", "]"}]}], "]"}], "]"}], "]"}], "]"}], ",",
  220. "\[IndentingNewLine]",
  221. RowBox[{"Initialization", "\[RuleDelayed]",
  222. RowBox[{"(", "\[IndentingNewLine]",
  223. RowBox[{
  224. RowBox[{"c", "=", "Sequence"}], ";", "\[IndentingNewLine]",
  225. RowBox[{"p", "=", "Position"}], ";", "\[IndentingNewLine]",
  226. RowBox[{
  227. RowBox[{"flagMinus", "[", "flag_", "]"}], ":=",
  228. RowBox[{
  229. RowBox[{
  230. RowBox[{"If", "[",
  231. RowBox[{
  232. RowBox[{
  233. RowBox[{"Norm", "[",
  234. RowBox[{"#", "-", "flag"}], "]"}], "<", "1.5"}], ",",
  235. RowBox[{
  236. RowBox[{"t", "[",
  237. RowBox[{"[",
  238. RowBox[{"c", "@@", "#"}], "]"}], "]"}], "--"}]}], "]"}], "&"}],
  239. "/@", "nums"}]}], ";", "\[IndentingNewLine]",
  240. RowBox[{
  241. RowBox[{"g", "@", "x_List"}], ":=",
  242. RowBox[{"Tr", "[",
  243. RowBox[{
  244. RowBox[{
  245. RowBox[{"q", "[", "#", "]"}], "&"}], "/@", "x"}], "]"}]}], ";"}],
  246. "\[IndentingNewLine]", ")"}]}], ",", "\[IndentingNewLine]",
  247. RowBox[{"TrackedSymbols", "\[RuleDelayed]",
  248. RowBox[{"{",
  249. RowBox[{"data", ",", "h"}], "}"}]}]}], "]"}]], "Input"]
  250. },
  251. WindowSize->{715, 655},
  252. WindowMargins->{{144, Automatic}, {Automatic, 30}},
  253. FrontEndVersion->"9.0 for Microsoft Windows (32-bit) (January 25, 2013)",
  254. StyleDefinitions->"Default.nb"
  255. ]
  256. (* End of Notebook Content *)
  257.  
  258. (* Internal cache information *)
  259. (*CellTagsOutline
  260. CellTagsIndex->{}
  261. *)
  262. (*CellTagsIndex
  263. CellTagsIndex->{}
  264. *)
  265. (*NotebookFileOutline
  266. Notebook[{
  267. Cell[1463, 33, 7898, 215, 812, "Input"]
  268. }
  269. ]
  270. *)
  271.  
  272. (* End of internal cache information *)
  273.  
  274. (* NotebookSignature 2wTDTMpMbF488DgSEz3tFiLs *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement