Day 5: If You Give a Seed a Fertilizer


Megathread guidelines

  • 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)
  • Code block support is not fully rolled out yet but likely will be in the middle of the event. Try to share solutions as both code blocks and using something such as https://topaz.github.io/paste/ , pastebin, or github (code blocks to future proof it for when 0.19 comes out and since code blocks currently function in some apps and some instances as well if they are running a 0.19 beta)

FAQ


🔒This post will be unlocked when there is a decent amount of submissions on the leaderboard to avoid cheating for top spots

🔓 Unlocked after 27 mins (current record for time, hard one today)

  • sjmulder@lemmy.sdf.org
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    11 months ago

    [C]

    My first approach to part 2 was to take the list of ranges, map it to a new list of (possibly split up) ranges, etc, but I realized that would take more memory and bookkeeping than I’d like. Scrapped it and rewrote it with recursion. Much cleaner and the benchmarks are still looking good! (But for how much longer?)

    $ bmake bench
    day01  0:00.00  1380 Kb  0+78 faults
    day02  0:00.00  1660 Kb  0+82 faults
    day03  0:00.00  1540 Kb  0+107 faults
    day04  0:00.00  1536 Kb  0+80 faults
    day05  0:00.00  1668 Kb  0+83 faults
    

    https://github.com/sjmulder/aoc/blob/master/2023/c/day05.c

    Edit: I see some people went for looping from 0 to try possible answers. Clever and short but I wanted to go for a more efficient approach.