This file contains hidden or 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
d=(I=``.trim().split`\n`)[0].length; | |
// part 1 | |
Math.max(I.flatMap(x=>x.split``).map((x,i,a)=>x=='#'?a.map((y,j)=>i!=j&&x==y?Math.atan2(j%d-i%d,(j/d|0)-(i/d|0)):NaN).filter((z,k,b)=>1/z&&b.findIndex(q=>q==z)==k).length:0)) | |
// part 2 | |
// |
This file contains hidden or 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
const INPUT = ` | |
3,8,1001,8,10,8,105,1,0,0,21,38,55,72,93,118,199,280,361,442,99999,3,9,1001,9,2,9,1002,9,5,9,101,4,9,9,4,9,99,3,9,1002,9,3,9,1001,9,5,9,1002,9,4,9,4,9,99,3,9,101,4,9,9,1002,9,3,9,1001,9,4,9,4,9,99,3,9,1002,9,4,9,1001,9,4,9,102,5,9,9,1001,9,4,9,4,9,99,3,9,101,3,9,9,1002,9,3,9,1001,9,3,9,102,5,9,9,101,4,9,9,4,9,99,3,9,101,1,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,101,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,102,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,99,3,9,101,2,9,9,4,9,3,9,101,1,9,9,4,9,3,9,101,1,9,9,4,9,3,9,102,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,2,9,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,2,9,4,9,3,9,1002,9,2,9,4,9,3,9,101,1,9,9,4,9,99,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3,9,1001,9,1,9,4,9,3,9,1001,9,2,9,4,9,3,9,102,2,9,9,4,9,3,9,1001,9,1,9,4,9,3,9,1002,9,2,9,4,9,3 |
This file contains hidden or 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
const INPUT = ``.trim(); | |
// part 1 | |
INPUT.match(/.{150}/g).map(X=>[X.replace(/1|2/g,x=>(x<2?O++:T++,''),O=T=0),O*T]).sort()[0][1] | |
// part 2 | |
// INPUT.match(/.{150}/g).reduce((t,b)=>[...t].map((x,i)=>x<2?x:b[i]).join``).match(/.{25}/g) | |
// [...INPUT].map((x,i,a)=>a[j=i%150]<2?a[j]:a[j]=x).join``.slice(-150).match(/.{25}/g) | |
[...INPUT].reduce((r,x,i)=>(r[j=i%150]=r[j]<2?r[j]:x,r),[]).join``.match(/.{25}/g) | |
// |
This file contains hidden or 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
const INPUT = ` | |
COPY & PASTE HERE | |
`.trim``.split`\n`; | |
// prepare orbit map | |
INPUT.map(x=>o[[s,y]=x.split`)`,y]=s,o={}); // o == all orbits | |
// Part 1 | |
c={}; // cache | |
a=k=>c[k]||(o[k]?c[k]=1+a(o[k]):0); // get all orbiters count | |
t=Object.keys(o).reduce((t,c)=>t+a(c),0); // count total | |
// Part 2 |
This file contains hidden or 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
const INPUT = ` | |
COPY & PASTE HERE | |
`.trim``.split`,`; | |
// part 1 | |
(z=y=>([q,w,e,r]=t.slice(y),99-(u=q%100))?(t[[,r,r,w][u]]=[,(i=(b=q/100|0)&1?w:t[w])-+-(o=b&8?e:t[e]),i*o,x][u],z(y+2**2**(u<3))):+i)(0,x=1,t=[...INPUT]); | |
// part 2 (also works for part1) | |
(z=y=>([q,w,e,r]=t.slice(y),99-(u=q%100))?(t[[,r,r,w][u%6]]=[,(i=(b=q/100|0)&1?w:t[w])-+-(o=b&8?e:t[e]),i*o,x,,,,i<o,i==o][u],z(y+=u%7<3?4:u<5?2:u<6^!+i?+o-y:3)):i)(0,x=5,t=[...INPUT]); | |
// | |
x=5,t=[...fetchSync('http://ix.io/23CO').trim().split(',')]; | |
// |
This file contains hidden or 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
const INPUT = ` | |
COPY & PASTE HERE | |
`.trim().split`,`; | |
function doInstructions([...arr],one=12,two=2) { | |
for(arr[1]=one,arr[2]=two,i=0;[o,a,b,t]=arr.slice(i),99-o||~'12'.search(o);i+=4)arr[t]=2==o?arr[a]*arr[b]:arr[a]- -arr[b]; | |
return arr[0]; | |
} | |
// part 1 |
This file contains hidden or 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
const INPUT = ` | |
COPY & PASTE HERE | |
`.trim().split`\n`; | |
// part 1 | |
INPUT.map(x=>t+=(i=x/3-2|0)>0?i:0,t=0)|t; | |
// part 2 | |
INPUT.map(f=i=>(i=i/3-2|0)>0?f(i,t+=i):0,t=0)|t |
This file contains hidden or 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
const INPUT = '000000-000000'; | |
const [ from, to ] = INPUT.split`-`; | |
// Part 1 | |
for(x=0,i=from;i<to;) | |
(a=[...''+i++]).every((c,j)=>!j||+c>=+a[j-1]) | |
&&a.some((c,j)=>c==a[j-1]) | |
&&x++,x | |
// Part 2 | |
for(x=0,i=236491;i<713786;) | |
(a=[...''+i++]).every((c,j)=>!j||+c>=+a[j-1]) |
This file contains hidden or 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
const INPUT = ` | |
COPY & PASTE HERE INPUT LINES | |
`; | |
const [firstLine,secondLine]=INPUT.trim().split`\n`; | |
const first = firstLine.split`,`; | |
const second = secondLine.split`,`; | |
const wires = {}; | |
[first,second].forEach(input => { | |
const currentWire = {}; |
This file contains hidden or 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
for(c=Array(32).fill(2);l=readline(p='');c[e]={S:3,A:c[e]&c[g],O:c[e]|c[g]}[d]|0)[[d],e,g]=l.split` ` | |
c.map(f=>p='0.?1'[f]+p) | |
writeline(p) |