1 min read

2026 Advent of Code day 1 oneliner

This is an extremely cursed piece of code, but I had fun writing the solution for both parts as a oneliner, with my own bare hands. Visit adventofcode.com.

// https://adventofcode.com/2026/day/1
// oneliner solution lmao

await Bun.file('./01/01.ids.txt').text().then((list) => list // parse input as text
  .split('\n')
  .filter(item => item.length > 0) // get rid of blank values
  .reduce((table: Record<string, number>, current) => ({ // count intances
    ...table, // ...yea, using reduce is extremely inefficient way to handle objects
    [current]: (table[current] ?? 0) + 1 // ...yea, ik, its cursed
  }), {}))
.then(table => Object.entries(table).sort(([, countA], [, countB]) => countB - countA)) // sorting and parsing
.then(arr => [arr.slice(0, 3),arr.slice(-3)]) // making two arrays to multiply, for part 1 and 2
.then(arr => arr.map(vals => vals.reduce((a, b) => parseInt(a) * parseInt(b))).map(ans => console.log(ans)))