jmooremcc

AoC 2015 Day 3 Part 1

Dec 21st, 2021 (edited)
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #-*-coding:utf8;-*-
  2.  
  3. print("AoC 2015 Day 3 Part 1")
  4. from collections import Counter
  5.  
  6. Directions = '^><^>>>^<^v<v^^'
  7. x=0
  8. y=0
  9. movelst=[(0,0)]
  10.  
  11. dirmap={
  12.         '^':1,
  13.         'v': -1,
  14.         '>' : 1,
  15.         '<' : -1
  16.     }
  17.  
  18. def move(direction):
  19.     global x, y
  20.    
  21.     if direction in "<>":
  22.         x += dirmap[direction]
  23.     else:
  24.         y += dirmap[direction]
  25.          
  26.     movelst.append((x,y))
  27.    
  28.    
  29. for direction in Directions:
  30.      move(direction)
  31.      
  32.    
  33. counts = dict(c for c in Counter(movelst).items())
  34. numhomes = len(counts)
  35. numstops = len(movelst)
  36.  
  37. print(f"Santa made {numstops:,} stops at {numhomes:,} homes.")
  38. print ("Finished...")
  39.  
Advertisement
Add Comment
Please, Sign In to add comment