Created
October 19, 2014 10:42
-
-
Save piyushkandpal/8eb633aad02b928a4d93 to your computer and use it in GitHub Desktop.
//https://www.hackerrank.com/challenges/the-quickest-way-up Snake and ladder game python solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enter your code here. Read input from STDIN. Print output to STDOUT | |
T = raw_input() | |
#print T | |
jumps = {} | |
for i in range(int(T)): | |
L,S = raw_input().split(',') | |
ladder_dict = { k:v for k,v in (d.split(',') for d in iter(raw_input().split())) } | |
snake_dict = { k:v for k,v in (d.split(',') for d in iter(raw_input().split())) } | |
ladder_dict.update(snake_dict) | |
jumps = ladder_dict | |
print jumps | |
final_pos = 100 | |
positions = {0} #initial position off the board | |
nsteps = 0 | |
while final_pos not in positions: | |
nsteps += 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 nsteps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment