My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add 2022/04

+34 -3
+26
2022/day04.py
··· 1 + import fileinput 2 + 3 + 4 + part_1 = 0 5 + part_2 = 0 6 + 7 + for line in fileinput.input(): 8 + elf_1, elf_2 = line.strip().split(',') 9 + a, b = [int(x) for x in elf_1.split('-')] 10 + c, d = [int(x) for x in elf_2.split('-')] 11 + 12 + # Part 1 13 + if a <= c <= b and a <= d <= b: 14 + part_1 += 1 15 + elif c <= a <= d and c <= b <= d: 16 + part_1 += 1 17 + 18 + 19 + # Part 2 20 + if a <= c <= b or a <= d <= b: 21 + part_2 += 1 22 + elif c <= a <= d or c <= b <= d: 23 + part_2 += 1 24 + 25 + print("Part 1:", part_1) 26 + print("Part 2:", part_2)
+1 -1
2022/starter.py
··· 15 15 # combinations_with_replacement('ABCD', 2) AA AB AC AD BB BC BD CC CD DD 16 16 # combinations('ABCD', 2) AB AC AD BC BD CD 17 17 18 - # day .lines .nlines .pars .npars .board .pboard .tboard 18 + # day .lines .nlines(negs=True) .pars .npars(negs=True) .board .pboard .tboard 19 19 20 20 tot = 0 21 21 res = []
+7 -2
2022/utils.py
··· 198 198 needs to be consumed afterwards, and b is a Counter over the values 199 199 in `grid`. 200 200 201 - f: a function to transform the values of grid to something printable. 202 - quiet: don't output to stdout. 201 + Arguments: 202 + f: a function to transform the values of grid to something printable. 203 + quiet: don't output to stdout. 204 + 205 + Returns: 206 + List[String]: Serialized, printable version of the grid. 207 + Counter: The values contained in the grid. 203 208 """ 204 209 if f is None: 205 210 f = lambda x: str(x) # NOQA