π¦ Everybody.Codes 2025 Quest 3 Solutions π¦
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 :)
Scheme/Guile
Guile doesn't seem to come with a bag implementation :(. Not a big deal, a linear scan works about as well.
I'm so far behind on these, but it's rare that I see a lanugage I've never heard before. I've heard of scheme. How did you come to using this language for the challenges?
I wanted to learn scheme and perhaps work through SICP. Guille seemed like a reasonable scheme to choose because I've also been considering learning Guix. Guix is a package manager similar to Nix, and it uses Guille as its configuration language.
Very simple task for Uiua.
-> 29, 781, 3
I was scared of a hard combinatorial puzzle day, but this was a breeze.
I thought this was going to be the knapsack problem, but no.
Uiua
I'm currently going through the 2025 Quests to learn Rust, committing great sins along the way.
Decided to take a shot at the third one with Uiua because it looked nice and simple, and it was. This may have been the fastest I've ever finished a complete quest :P
Run with example input
:::spoiler Code
:::
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
Full solution at Codeberg: solution.nim
FSharp
I'm a month late, but eh. Compared to everyone else, it looks like my approach of preserving duplicates was unnecessary. I chose to use SortedSets (redundant since I sort the inputs) and cascade to the next best fit. The sorted sets also let me grab the Max/Min values and I thought that it was more in line with the intention than having a list that happens to be sorted.
I also sorted part 1 based on what I thought was the best fit, which was the same solution for part 3.
For part 2 I duplicated part 1's logic but reversed the order to asc instead of desc, but I don't know that that made a difference and excluded it here. The only difference is the "add if count < 20".
Rust