this post was submitted on 09 Nov 2025
5 points (77.8% liked)

Advent Of Code

1119 readers
9 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2024

Solution Threads

M T W T F S S
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 2 years ago
MODERATORS
 

Quest 3: The Deepest Fit

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

Link to participate: https://everybody.codes/

Also, don't wait for me to make these posts, feel free to post yourself :)

you are viewing a single comment's thread
view the rest of the comments
[โ€“] janAkali@lemmy.sdf.org 2 points 4 days ago* (last edited 4 days ago)

Nim

Reading this day's quest I was at first a bit confused what it asks me to calculate. Took me about a minute to realize that most of descriptions are not important and actual calculations for each part are very simple:

part 1 wants sum of each unique crate size
part 2 is same but only 20 smallest
part 3 is max count, because you can always put most crates in one large set and you only need 1 extra set per duplicate crate

proc solve_part1*(input: string): Solution =
  var seen: set[int16]
  for num in input.split(','):
    let num = parseInt(num).int16
    if num in seen: continue
    else:
      seen.incl num
      result.intVal += num

proc solve_part2*(input: string): Solution =
  var set = input.split(',').mapIt(parseInt(it).uint16)
  set.sort()
  result := set.deduplicate(isSorted=true)[0..<20].sum()

proc solve_part3*(input: string): Solution =
  var cnt = input.split(',').toCountTable()
  result := cnt.largest.val

Full solution at Codeberg: solution.nim