mirror of
https://github.com/seigler/advent-of-code-browser-console
synced 2025-07-26 00:06:10 +00:00
day 7
This commit is contained in:
parent
53f2b9aec4
commit
f656a9c872
1 changed files with 1 additions and 0 deletions
1
2021/day07.js
Normal file
1
2021/day07.js
Normal file
|
@ -0,0 +1 @@
|
|||
with(Math){C=$('pre').innerText.trim().split`,`.map(x=>+x),l=C.length,S=0;C.map(c=>S+=c);a=round((S-l)/(l-1));p=q=0;C.map(c=>p+=abs(c-a));q=ceil(S/l);[p,[q-1,q].map(x=>C.reduce((a,c)=>a+(1+abs(c-x))*abs(c-x)/2,0)).sort((a,b)=>a-b)[0]]}
|
Loading…
Add table
Add a link
Reference in a new issue