Skip to content

Instantly share code, notes, and snippets.

@asonge
Last active December 2, 2021 06:14
Show Gist options
  • Save asonge/4848680eede5ae8f55ec750cb82c0c67 to your computer and use it in GitHub Desktop.
Save asonge/4848680eede5ae8f55ec750cb82c0c67 to your computer and use it in GitHub Desktop.
a=b=0;require('fs').readFileSync(0,{encoding:'utf8'}).replace(/^(.).*(\d+)$/gm,(_,v,d)=>{a+=d*(v=='f'),b+=v=='d'?+d:v=='u'?-d:0});console.log(a*b)
console.log([...require('fs').readFileSync(0,{encoding:'utf8'}).matchAll(/^(.).*(\d+)$/gm)].reduce(([a,b],[_,v,d])=>[a+=d*(v=='f'),b+=v=='d'?+d:v=='u'?-d:0],[0,0]).reduce((a,b)=>a*b))
a=b=c=0;require('fs').readFileSync(0,{encoding:'utf8'}).replace(/^(.).*(\d+)$/gm,(_,v,d)=>{a+=v=='d'?+d:v=='u'?-d:0,b+=(v=='f')*d,c+=(v=='f')*a*d});console.log(b*c)
console.log([...require('fs').readFileSync(0,{encoding:'utf8'}).matchAll(/^(.).*(\d+)$/gm)].reduce(([a,b,c],[_,v,d])=>[a+=v=='d'?+d:v=='u'?-d:0,b+=(v=='f')*d,c+=(v=='f')*a*d],[0,0,0]).slice(1).reduce((a,b)=>a*b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment