Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1st number is score
- 2nd number is options (out of 6^35)
- 3rd number is probability
- 0 508402923859133368733470285 0.29574286523483245
- 1 563547687387504213553504280 0.32782110397662306
- 2 365469312545766886634219560 0.212597010314672
- 3 176987805124542159863618880 0.1029555066320965
- 4 70419262837704337023640390 0.04096356173812611
- 5 24147360871089391257363720 0.014046751811864431
- 6 7360359763451861759691760 0.004281591988258432
- 7 2041369182714806209073680 0.001187484065818319
- 8 526026486887529394386045 0.0003059946611649216
- 9 128633736389854169290440 7.482748029265524e-05
- 10 30548641660519232117660 1.7770438346686986e-05
- 11 7211657649760171664400 4.19509054008454e-06
- 12 1726317877921691376190 1.0042156949989083e-06
- 13 424630933785946638200 2.470118937789469e-07
- 14 107939805185245411500 6.278962169623372e-08
- 15 28304055346633917200 1.6464740923280225e-08
- 16 7599460149557300165 4.420678979987004e-09
- 17 2071366776823308000 1.2049339545098678e-09
- 18 570434884944610960 3.3182745296359596e-10
- 19 158467128171760840 9.218185091326763e-11
- 20 44283339227717780 2.5760043876144266e-11
- 21 12411827244879520 7.220079153631094e-12
- 22 3481854382500360 2.0254281458389684e-12
- 23 973468236355520 5.662758255785523e-13
- 24 271445766822700 1.5790261044654166e-13
- 25 75633033671360 4.399646232280166e-14
- 26 21111422739800 1.2280717433446924e-14
- 27 5849716172920 3.4028360983015223e-15
- 28 1600061390560 9.307710833050978e-16
- 29 434389928800 2.5268879493710835e-16
- 30 117712545920 6.847451887218761e-17
- 31 31427820560 1.8281865159130912e-17
- 32 8408904005 4.891540247342111e-18
- 33 2205272520 1.2828282118006603e-18
- 34 582833320 3.3903974175193643e-19
- 35 142865720 8.31063618909167e-20
- 36 37909550 2.2052349446891817e-20
- 37 8911960 5.184172752689546e-21
- 38 2369480 1.3783492805222226e-21
- 39 501520 2.9173900229902978e-22
- 40 143935 8.372837233990837e-23
- 41 27320 1.5892306473938214e-23
- 42 7340 4.269748518254264e-24
- 43 1080 6.282463759829162e-25
- 44 410 2.3850093903055155e-25
- 45 40 2.3268384295663565e-26
- 46 20 1.1634192147831783e-26
- 47 0 0.0
- 48 1 5.817096073915891e-28
- Some checks:
- 0 chance of n=47 score, 20 for n=46 (can vary each of 4 corners 5 different values)
- Sum of column 2 = 6^35
- 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.
- And now, the code. Python, so it's slow.
- --------------------------------------
- # Observation: the quad/pent/hex calculation is "independent" - it really is just two/three/four tri's.
- # So there is no special handling required for this.
- # We solve this using dynamic programming. We keep track of the last six rolls, as well as tracking whether
- # a roll is equal to the roll six rolls before (i.e. "above"). Because we track the last rolls, we don't need
- # to also keep additional state for horizontal tri's.
- # This gives us a state space of 12^6 or about 3 million.
- # Runtime of this not terribly optimized code is about an hour on my laptop.
- # 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
- # FAQ
- # Why do you keep track of the last 6 rolls directly and not just equality data?
- # I thought that this was sufficient (and seemed tantalizing - only 4^6 = 4096 states required!). But this is incorrect.
- # Whether something is equal to the left or the above number is not independent with respect to the equality data.
- # For example, in this grid:
- # A B
- # C D
- # If A=C and A!=B, then B and C cannot both equal D.
- # If A=C and A=B, then D cannot equal only one of B and C.
- # But even if you account for this, there are more pernicious cases:
- # ABC
- # DEF
- # GHI
- # 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.
- # It is much easier to simply store the values.
- # How to optimize this slow code?
- # 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.
- # 1) Probably rewrite this in a language that is not Python, lol
- # 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.
- ## I think 6x6 is about the limit with this code. Implementing 2 probably lets us compute 7x7
- ROWS = 6
- COLUMNS = 6
- DICE_FACES = 6
- states = {(0,):[1]} # WLOG the top left roll is a 0.
- def add_vec(vec1, vec2): # vec1 gets updated inplace
- for i in range(len(vec2)):
- if i < len(vec1):
- vec1[i] += vec2[i]
- else:
- vec1.append(vec2[i])
- def add_state(statemap, state, vals):
- if state in statemap:
- add_vec(statemap[state], vals)
- else:
- statemap[state] = vals
- for i in range(1, ROWS*COLUMNS):
- print(i)
- nextstates = {}
- for s in states:
- up_point = (i >= COLUMNS and s[0] % 2)
- left_point = (i % COLUMNS >= 2 and s[-1] // 2 == s[-2] // 2)
- if i < COLUMNS:
- for roll in range(DICE_FACES):
- if roll != (s[-1] // 2):
- add_state(nextstates, s+(2*roll,), states[s])
- else:
- add_state(nextstates, s+(2*roll,), [0]*left_point+states[s])
- else:
- for roll in range(DICE_FACES):
- if (roll != (s[0] // 2)) and (roll != (s[-1] // 2)):
- add_state(nextstates, s[1:]+(2*roll,), states[s])
- elif roll != (s[0] // 2):
- add_state(nextstates, s[1:]+(2*roll,), [0]*left_point+states[s])
- elif roll != (s[-1] // 2):
- add_state(nextstates, s[1:]+(2*roll+1,), [0]*up_point+states[s])
- else:
- add_state(nextstates, s[1:]+(2*roll+1,), [0]*(left_point+up_point)+states[s])
- states = nextstates
- final = []
- print(len(states))
- for s in states:
- final = add_vec(final, states[s])
- print(final)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement