-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from collections import Counter, defaultdict, deque | ||
|
||
import aoc_helper | ||
from aoc_helper import ( | ||
Grid, | ||
PrioQueue, | ||
SparseGrid, | ||
decode_text, | ||
extract_ints, | ||
extract_iranges, | ||
extract_ranges, | ||
extract_uints, | ||
frange, | ||
irange, | ||
iter, | ||
list, | ||
map, | ||
multirange, | ||
range, | ||
search, | ||
tail_call, | ||
) | ||
|
||
raw = aoc_helper.fetch(1, 2024) | ||
|
||
|
||
def parse_raw(raw: str): | ||
return raw | ||
|
||
|
||
data = parse_raw(raw) | ||
|
||
|
||
# providing this default is somewhat of a hack - there isn't any other way to | ||
# force type inference to happen, AFAIK - but this won't work with standard | ||
# collections (list, set, dict, tuple) | ||
def part_one(data=data): | ||
list_one = [] | ||
list_two = [] | ||
for line in data.splitlines(): | ||
list_one.append(int(line.split()[0])) | ||
list_two.append(int(line.split()[1])) | ||
list_one.sort() | ||
list_two.sort() | ||
t = 0 | ||
for i in range(len(list_one)): | ||
t += abs(list_two[i]-list_one[i]) | ||
return t | ||
|
||
aoc_helper.lazy_test(day=1, year=2024, parse=parse_raw, solution=part_one) | ||
|
||
|
||
# providing this default is somewhat of a hack - there isn't any other way to | ||
# force type inference to happen, AFAIK - but this won't work with standard | ||
# collections (list, set, dict, tuple) | ||
def part_two(data=data): | ||
list_one = [] | ||
list_two = [] | ||
for line in data.splitlines(): | ||
list_one.append(int(line.split()[0])) | ||
list_two.append(int(line.split()[1])) | ||
t = 0 | ||
for item in list_one: | ||
c = list_two.count(item) | ||
t += item * c | ||
return t | ||
|
||
aoc_helper.lazy_test(day=1, year=2024, parse=parse_raw, solution=part_two) | ||
|
||
aoc_helper.lazy_submit(day=1, year=2024, solution=part_one, data=data) | ||
aoc_helper.lazy_submit(day=1, year=2024, solution=part_two, data=data) |