completed 2017.05.2
This commit is contained in:
		
							parent
							
								
									50802d3c8c
								
							
						
					
					
						commit
						a3017435b7
					
				
							
								
								
									
										27
									
								
								2017/05/2trampoline-maze.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										27
									
								
								2017/05/2trampoline-maze.py
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,27 @@ | ||||
| #!/usr/bin/env python3 | ||||
| 
 | ||||
| # input file has an integer on every line | ||||
| # pointer starts at the first line | ||||
| # each 'jump' moves by the value of the line | ||||
| # positive goes downward, negative goes upward | ||||
| # after the jump, increment the jumping-off line by +1 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     with open("input", "r", encoding="utf-8") as maze_file: | ||||
|         maze_strings = maze_file.readlines() | ||||
|         maze_size = len(maze_strings) | ||||
|         maze_ints = [] | ||||
|         for i in range(maze_size): | ||||
|             maze_ints.append(int(maze_strings[i])) | ||||
|         pointer = 0 | ||||
|         jumps = 0 | ||||
|         while pointer < maze_size and pointer >= 0: | ||||
|             current_value = maze_ints[pointer] | ||||
|             if current_value >= 3: | ||||
|                 maze_ints[pointer] = current_value - 1 | ||||
|             else: | ||||
|                 maze_ints[pointer] = current_value + 1 | ||||
|             jumps += 1 | ||||
|             pointer += current_value | ||||
|         print(f'finally, jumping from {current_value} at {pointer - current_value}, you missed {pointer}!') | ||||
|         print(f'it took {jumps} jumps!') | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user