Advertisement
Guest User

manifold chaos grid

a guest
Mar 27th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. 1st number is score
  2. 2nd number is options (out of 6^35)
  3. 3rd number is probability
  4.  
  5. 0 508402923859133368733470285 0.29574286523483245
  6. 1 563547687387504213553504280 0.32782110397662306
  7. 2 365469312545766886634219560 0.212597010314672
  8. 3 176987805124542159863618880 0.1029555066320965
  9. 4 70419262837704337023640390 0.04096356173812611
  10. 5 24147360871089391257363720 0.014046751811864431
  11. 6 7360359763451861759691760 0.004281591988258432
  12. 7 2041369182714806209073680 0.001187484065818319
  13. 8 526026486887529394386045 0.0003059946611649216
  14. 9 128633736389854169290440 7.482748029265524e-05
  15. 10 30548641660519232117660 1.7770438346686986e-05
  16. 11 7211657649760171664400 4.19509054008454e-06
  17. 12 1726317877921691376190 1.0042156949989083e-06
  18. 13 424630933785946638200 2.470118937789469e-07
  19. 14 107939805185245411500 6.278962169623372e-08
  20. 15 28304055346633917200 1.6464740923280225e-08
  21. 16 7599460149557300165 4.420678979987004e-09
  22. 17 2071366776823308000 1.2049339545098678e-09
  23. 18 570434884944610960 3.3182745296359596e-10
  24. 19 158467128171760840 9.218185091326763e-11
  25. 20 44283339227717780 2.5760043876144266e-11
  26. 21 12411827244879520 7.220079153631094e-12
  27. 22 3481854382500360 2.0254281458389684e-12
  28. 23 973468236355520 5.662758255785523e-13
  29. 24 271445766822700 1.5790261044654166e-13
  30. 25 75633033671360 4.399646232280166e-14
  31. 26 21111422739800 1.2280717433446924e-14
  32. 27 5849716172920 3.4028360983015223e-15
  33. 28 1600061390560 9.307710833050978e-16
  34. 29 434389928800 2.5268879493710835e-16
  35. 30 117712545920 6.847451887218761e-17
  36. 31 31427820560 1.8281865159130912e-17
  37. 32 8408904005 4.891540247342111e-18
  38. 33 2205272520 1.2828282118006603e-18
  39. 34 582833320 3.3903974175193643e-19
  40. 35 142865720 8.31063618909167e-20
  41. 36 37909550 2.2052349446891817e-20
  42. 37 8911960 5.184172752689546e-21
  43. 38 2369480 1.3783492805222226e-21
  44. 39 501520 2.9173900229902978e-22
  45. 40 143935 8.372837233990837e-23
  46. 41 27320 1.5892306473938214e-23
  47. 42 7340 4.269748518254264e-24
  48. 43 1080 6.282463759829162e-25
  49. 44 410 2.3850093903055155e-25
  50. 45 40 2.3268384295663565e-26
  51. 46 20 1.1634192147831783e-26
  52. 47 0 0.0
  53. 48 1 5.817096073915891e-28
  54.  
  55. Some checks:
  56.  
  57. 0 chance of n=47 score, 20 for n=46 (can vary each of 4 corners 5 different values)
  58. Sum of column 2 = 6^35
  59. Sum of dot product of column 1 and column 2 = 8*6^34. i.e. Expected score is 4/3, which matches the calculation (48 possible tri's, each tri has a 1/36 chance of being good, then linearity of expectation.
  60.  
  61. And now, the code. Python, so it's slow.
  62. --------------------------------------
  63.  
  64. # Observation: the quad/pent/hex calculation is "independent" - it really is just two/three/four tri's.
  65. # So there is no special handling required for this.
  66.  
  67. # We solve this using dynamic programming. We keep track of the last six rolls, as well as tracking whether
  68. # a roll is equal to the roll six rolls before (i.e. "above"). Because we track the last rolls, we don't need
  69. # to also keep additional state for horizontal tri's.
  70.  
  71. # This gives us a state space of 12^6 or about 3 million.
  72. # Runtime of this not terribly optimized code is about an hour on my laptop.
  73. # Addendum: Oh I guess it also eats up like 8gb ram. After all 3 million states * 49 element score array ~ 150 million integers, some which are bigints
  74.  
  75. # FAQ
  76. # Why do you keep track of the last 6 rolls directly and not just equality data?
  77. # I thought that this was sufficient (and seemed tantalizing - only 4^6 = 4096 states required!). But this is incorrect.
  78. # Whether something is equal to the left or the above number is not independent with respect to the equality data.
  79. # For example, in this grid:
  80. # A B
  81. # C D
  82. # If A=C and A!=B, then B and C cannot both equal D.
  83. # If A=C and A=B, then D cannot equal only one of B and C.
  84. # But even if you account for this, there are more pernicious cases:
  85. # ABC
  86. # DEF
  87. # GHI
  88.  
  89. # If A=B=C=F=D=G=H but not E, then similar issue with I. But now you need to go back further in the history to determine this.
  90. # It is much easier to simply store the values.
  91.  
  92. # How to optimize this slow code?
  93. # I prioritized writing this code quickly rather than runtime (as long as it finishes << a day). After all I only need to run this once for a random Manifold market.
  94. # 1) Probably rewrite this in a language that is not Python, lol
  95. # 2) Traverse the grid more intelligently. E.g. do it by diagonals. I think then the state space can be smaller most of the time.
  96. ## I think 6x6 is about the limit with this code. Implementing 2 probably lets us compute 7x7
  97.  
  98. ROWS = 6
  99. COLUMNS = 6
  100. DICE_FACES = 6
  101.  
  102. states = {(0,):[1]} # WLOG the top left roll is a 0.
  103.  
  104. def add_vec(vec1, vec2): # vec1 gets updated inplace
  105. for i in range(len(vec2)):
  106. if i < len(vec1):
  107. vec1[i] += vec2[i]
  108. else:
  109. vec1.append(vec2[i])
  110.  
  111. def add_state(statemap, state, vals):
  112. if state in statemap:
  113. add_vec(statemap[state], vals)
  114. else:
  115. statemap[state] = vals
  116.  
  117. for i in range(1, ROWS*COLUMNS):
  118. print(i)
  119. nextstates = {}
  120. for s in states:
  121. up_point = (i >= COLUMNS and s[0] % 2)
  122. left_point = (i % COLUMNS >= 2 and s[-1] // 2 == s[-2] // 2)
  123. if i < COLUMNS:
  124. for roll in range(DICE_FACES):
  125. if roll != (s[-1] // 2):
  126. add_state(nextstates, s+(2*roll,), states[s])
  127. else:
  128. add_state(nextstates, s+(2*roll,), [0]*left_point+states[s])
  129. else:
  130. for roll in range(DICE_FACES):
  131. if (roll != (s[0] // 2)) and (roll != (s[-1] // 2)):
  132. add_state(nextstates, s[1:]+(2*roll,), states[s])
  133. elif roll != (s[0] // 2):
  134. add_state(nextstates, s[1:]+(2*roll,), [0]*left_point+states[s])
  135. elif roll != (s[-1] // 2):
  136. add_state(nextstates, s[1:]+(2*roll+1,), [0]*up_point+states[s])
  137. else:
  138. add_state(nextstates, s[1:]+(2*roll+1,), [0]*(left_point+up_point)+states[s])
  139. states = nextstates
  140.  
  141. final = []
  142. print(len(states))
  143. for s in states:
  144. final = add_vec(final, states[s])
  145. print(final)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement