Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #part1 Julia
- wide, tall=101,103
- parse_coords(coord_str) = parse.(Int, split(split(coord_str, "=")[2], ","))
- robots = split.(readlines("input"))
- positions = [mod.(pos .+ vel .* 100, [wide, tall]) for robot in robots]
- quadrants = [
- count(el -> el[1] > wide ÷ 2 && el[2] > tall ÷ 2, positions),
- count(el -> el[1] > wide ÷ 2 && el[2] < tall ÷ 2, positions),
- count(el -> el[1] < wide ÷ 2 && el[2] > tall ÷ 2, positions),
- count(el -> el[1] < wide ÷ 2 && el[2] < tall ÷ 2, positions)
- ]
- println(prod(quadrants))
- #part2 Python
- import numpy as np
- from numpy.fft import fft2
- wide,tall=101,103
- def next_pos(pos,vel): return (pos[0]+vel[0])%wide,(pos[1]+vel[1])%tall
- robots=[x.split() for x in open('input').read().splitlines()]
- pos = [list(map(int, x[0].split("=")[1].split(","))) for x in robots]
- vel = [list(map(int, x[1].split("=")[1].split(","))) for x in robots]
- values=[]
- for i in range(10000):
- pos=[next_pos(p,v) for p,v in zip(pos,vel)]
- values.append(np.min(np.real(fft2(np.array(pos)))))
- print(np.argmin(values)+1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement