repl.it
@anonymous/

StainedMonthlyOutput

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
jumps = {2: 21, 4:9, 10:20, 17:23, 21:0, 19:9, 14: 2, 18:5,}
final_pos = 25

n_steps = [0]

def snakes_ladders():
    positions = {0}  #initial position off the board
    while final_pos not in positions:
        n_steps[0] += 1
        old_positions = positions
        positions = set()
        for pos in old_positions:
            for dice in range(1, 7):
                new_pos = pos + dice
                positions.add(jumps.get(new_pos, new_pos))

    print (f'Reached finish in {n_steps[0]} steps.')

if __name__ == '__main__':   
     snakes_ladders()