Day 07 (minified)

This commit is contained in:
Sebastian Seedorf
2021-12-07 10:58:41 +01:00
parent 530d103717
commit f2989b0946
2 changed files with 4 additions and 0 deletions

2
day07/part1.min.py Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env python3
l=list(map(int,list(open("input.txt"))[0].split(',')));l.sort();print(sum(abs(x-l[((len(l)+1)//2)-1])for x in l))

2
day07/part2.min.py Normal file
View File

@@ -0,0 +1,2 @@
#!/usr/bin/env python3
(l:=list(map(int,list(open("input.txt"))[0].split(',')))).sort();n=round(sum(l)/len(l));print(min(sum(abs(x-m)*(abs(x-m)+1)//2 for x in l)for m in range(n-1,n+2)))