# project_euler

committed 2f42dd4 Draft

solved euler 84

# euler_084.py

`+#!/usr/bin/env python`
`+# coding: utf-8`
`+from random import choice`
`+from collections import Counter`
`+`
`+FIELDS = [`
`+    "GO", "A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3",`
`+    "JAIL", "C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3",`
`+    "FP", "E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3",`
`+    "G2J", "G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"`
`+]`
`+`
`+CHEST = [None] * 14`
`+CHEST += ["GO", "JAIL"]`
`+`
`+CHANCE = [None] * 6`
`+CHANCE += ["GO", "JAIL", "C1", "E3", "H2", "R1"]`
`+CHANCE += ["+R", "+R", "+U", "-3"]`
`+`
`+DICE = range(1, 7)  # 6 sides`
`+#DICE = range(1, 5)  # 4 sides`
`+`
`+N = 10000000  # number of moves`
`+`
`+pos = 0`
`+`
`+field_visits = Counter()`
`+field_visits[0] += 1`
`+double_count = 0`
`+`
`+def pos_from_card(card, field):`
`+    if card is None:`
`+        return pos`
`+`
`+    if card[0] not in "+-":`
`+        return FIELDS.index(card)`
`+    if card == "-3":`
`+        return pos - 3`
`+    if card == "+R":`
`+        if field == "CH1":`
`+            return FIELDS.index("R2")`
`+        if field == "CH2":`
`+            return FIELDS.index("R3")`
`+        if field == "CH3":`
`+            return FIELDS.index("R1")`
`+    if card == "+U":`
`+        if field == "CH1":`
`+            return FIELDS.index("U1")`
`+        if field == "CH2":`
`+            return FIELDS.index("U2")`
`+        if field == "CH3":`
`+            return FIELDS.index("U1")`
`+`
`+    assert False`
`+`
`+for n in xrange(N):`
`+    d1 = choice(DICE)`
`+    d2 = choice(DICE)`
`+    moves = d1 + d2`
`+`
`+    if d1 == d2:`
`+        double_count += 1`
`+    else:`
`+        double_count = 0`
`+`
`+    if double_count == 3:`
`+        pos = 10`
`+        double_count = 0`
`+`
`+    pos = (pos + moves) % 40`
`+    if pos == 30:`
`+        pos = 10`
`+`
`+    while True:`
`+        field = FIELDS[pos]`
`+`
`+        if field.startswith("CH"):`
`+            card = choice(CHANCE)`
`+        elif field.startswith("CC"):`
`+            card = choice(CHEST)`
`+        else:`
`+            card = None`
`+        pos = pos_from_card(card, field)`
`+`
`+        if card is None:`
`+            break`
`+`
`+    field_visits[pos] += 1`
`+`
`+#for f, c in field_visits.most_common():`
`+#    print FIELDS[f], c / float(N)`
`+`
`+print "".join("%02d" % f for f, c in field_visits.most_common(3))`
`+`
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.