File tree 2 files changed +21
-1
lines changed
Filter options
2 files changed +21
-1
lines changed
Original file line number Diff line number Diff line change 14
14
| [ 10] ( https://adventofcode.com/2020/day/10 ) | Adapter Array| [ py] ( /day10/main.py ) , [ alt] ( /day10/alt.py ) |
15
15
| [ 11] ( https://adventofcode.com/2020/day/11 ) | Seating System| [ py] ( /day11/main.py ) |
16
16
| [ 12] ( https://adventofcode.com/2020/day/12 ) | Rain Risk| [ py] ( /day12/main.py ) |
17
- | [ 13] ( https://adventofcode.com/2020/day/13 ) | - | - |
17
+ | [ 13] ( https://adventofcode.com/2020/day/13 ) | Shuttle Search | [ py ] ( /day13/main.py ) |
18
18
| [ 14] ( https://adventofcode.com/2020/day/14 ) | -| -|
19
19
| [ 15] ( https://adventofcode.com/2020/day/15 ) | -| -|
20
20
| [ 16] ( https://adventofcode.com/2020/day/16 ) | -| -|
Original file line number Diff line number Diff line change
1
+ import numpy as np
2
+ from math import prod
3
+
4
+ with open ("input.txt" ) as f :
5
+ lines = [x .strip () for x in f ]
6
+
7
+ arrival = int (lines [0 ])
8
+ buses = [(i , int (e )) for i , e in enumerate (lines [1 ].split ("," )) if e .isdigit ()]
9
+
10
+ offsets , times = zip (* buses )
11
+ b = [e - (arrival % e ) for e in times ]
12
+ print (np .min (b ) * times [np .argmin (b )])
13
+
14
+ def chinese_remainder (ns , rems ):
15
+ p = prod (ns )
16
+ x = sum (r * (p // n ) * pow (p // n , - 1 , n ) for r , n in zip (rems , ns ))
17
+ return x % p
18
+
19
+ rems = [time - offset for offset , time in buses ]
20
+ print (chinese_remainder (times , rems ))
You can’t perform that action at this time.
0 commit comments