day 20 aoc: the cupid shuffle

https://youtube.com/watch?v=h24_zoqu4_Q

to the right to the right to the right

to the left to the left to the left

post your aoc solutions for day 20 or smth, all checks notes 5+ of you

42
Jump in the discussion.

No email address required.

const p1 = true
let obj = fs.readFileSync('/tmp/d201','utf8').split('\n').filter(a=>a.length).map((a,i)=> ({a:p1 ? +a : (+a)*811589153,i}))
for (let x=0;x<(p1 ? 1 : 10);x++)
for (let i=0;i<obj.length;i++){
  const k = obj.findIndex(a=> a.i === i)
  const a = obj[k]
  let newi = a.a + k
  if (newi < 0) newi += Math.ceil(-newi/(obj.length-1))*(obj.length-1)
  newi %= (obj.length - 1)
  if (newi == 0) newi = obj.length
  obj = obj.slice(0, k).concat(obj.slice(k+1))
  obj = obj.slice(0, newi).concat([a]).concat(obj.slice(newi))
}
const i = obj.map(a=>a.a).indexOf(0)
out:(obj[(i+1000)%obj.length].a+obj[(i+2000)%obj.length].a+obj[(i+3000)%obj.length].a)
Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.