Skip to content

Instantly share code, notes, and snippets.

@emplv
Last active December 8, 2019 21:31
Show Gist options
  • Select an option

  • Save emplv/ed61b5e0246a410701e2017db0f1f6d6 to your computer and use it in GitHub Desktop.

Select an option

Save emplv/ed61b5e0246a410701e2017db0f1f6d6 to your computer and use it in GitHub Desktop.
Advent of Code - day 8
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)
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment