day 1
note: i wrote this on the evening of day 2, so this is a day-after retrospective
another year, another advent of code!
as expected, day 1 is very approachable, with more story preamble than problem definition (since there isn’t much to even explain)
my plan this year is to rehash the same set of tools i picked last year, [Elixir], being written within an instance of [Livebook] running on my personal DigitalOcean server
click to view my solution
given the sample input:
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
assuming input
is the above as one big string,
input =
input
|> String.trim()
|> String.split("\n\n")
|> Enum.map(fn elf ->
elf |> String.split("\n") |> Enum.map(&String.to_integer/1)
end)
split the string on \n\n
, causing each group to be its own chunk,
and since that chunk is still a compact string, split it again by \n
, and map
each value to an integer
[
[1000, 2000, 3000],
[4000],
[5000, 6000],
[7000, 8000, 9000],
[10000]
]
this leaves us with the following list of lists
elfs = input |> Enum.map(&Enum.sum/1) |> Enum.sort(&(&1 >= &2))
i then sum each list within this list of lists, and sort this new list of just sums in descending order
[24000, 11000, 10000, 6000, 4000]
which leaves me with this list
part 1
Enum.at(elfs, 0) # -> 24000
plucking the first element of this list gives me the elf with the most calories
part 2
elfs |> Enum.take(3) |> Enum.sum() # -> 45000
and, plucking the top 3, and then summing this list of 3 items, give us the combined calories
the full solution can be found [here]
this year i have quite a few places that are all actively taking part in advent of code:
[MUN Computer Science Society] discord, specifically in the channels prefixed with #aoc-...
[CTSNL] slack, in threads posted in #general
[NDev] slack, in #advent-of-code
[Get Coding]‘s private slack, in #general
most of these have their own leaderboard, and due to staying up until 1:30am to solve the problem, i managed to snag first on ctsnl & ndev, but due to the muncs leaderboard being filled with late night tryhards, even though i took less than 10 minutes to solve, I was 4/5th on that leaderboard
i know placement means nothing, and that sacrificing sleep isn’t worthwhile, i just find the first few days of advent of code are quite fun, when:
-
more people are taking part, since its more approachable, and people will fall off quickly over the next few days
-
the problems can be solved before 2am, so some sleep is acquired
i will go to bed better for the rest of this month i swear :)
others
while this is my ramblings, i’m thinking i can also use this place to advertise other peoples solutions to problems, adding in my own bit of (potentially cheeky) commentary as well
this list will quickly become a lot less long as people drop off, but it’ll give me more chance to dig into the specifics of each persons solution as the days progress and become more complex, because at the moment most solutions look quite similar
[Mudkip/AdventOfCode] python[maegpi-nl/advent_of_code]mudkip killed in on the muncs leaderboard, managing to snag #1, even though beforehand they mentioned they weren’t planning on taking part on aoc this year, and not staying up late, tsk tsk!
also, not going with php this year, safe choice for someone who seems to care less about doing it in an interesting way this year
[briannamcdonald/advent-of-code-2022] pythoni think mat managed to get this problem done, but the repository is bare as of authoring this page…
i hope to see some common lisp in this repository in time ;)
[krbarter/Advent-Of-Code-2022] pythonbrianna also did well on the leaderboard, i believe inbetween myself and mudkip
[nint8835/AdventOfCode2022] f# & pythonkent out here
[hamzahap/AdventOfCode2022] sheetsriley going in with the f# again this year! nice to have another functional friend :)
[TheCrypticCanadian/advent-of-code-2022] pythonhamzah pls
amazing though, seeing excel solutions is always fun
curious how long this lasts until you fallback to, well, a programming language :)
[STollenaar/AdventOfCode2022] golangthere is a jupyter notebook file here, and two .py files
gump whats going on here
great job though, keep it up <3
[DanielPower/AdventOfCode2022] haskellits sven, so of course its go
split up into nice little packages, with some shared utils
using a struct to hold the inventories too, webscale
[emilydormody/advent-of-code]dan back again with the haskell this year, functional gang unite
similar in concept to my solution it seems, just done using a larger more mathematical brain than i have
[ecumene/advent_of_code] python notebookthere is a repo here, but like mats, as of the writing of this, there is no code here
actually even mats has a readme, this is proper empty!
but emily did get this problem done according to the leaderboard! good job
[zcvaters/adventofcode2022] swiftmitch going ham with utilities that fetch problem input directly from the site, and even submit answers to the site from the code, neat
[chadmroberts88/advent-of-code-2022] typescriptswift! neat
type definitions here look funky, it feels familiar in some ways, but also foreign in others
[devthedevel/advent_of_code] typescriptnice lil input parsing, and great usage of condensing previous problem into something reusable for the second
[mathieuboudreau/advent] python notebookdev has blessed us with some code from the clouds
although i am curious why each function in this solution is an async function
however, i will not dare question the clouds
[SteveParson/AOC2022] c, python, & javaclean lil notebook, with a link to open in [binder], which is the first i have heard of it, looks cool
[ajhynes7/advent-of-code-2022] juliakeeping it real, steve is, with a bit of low level c
[12:46 AM] Степан111: Shame that C doesn’t have a built in sort method
- steve
[ericthomasca/adventofcode2022] rustcute little julia solution, i find julia is always nice to look at
[Keenan-Nicholson/AdventOfCode] typescriptpretty decent rust solution, more unwraps than one would hope to see, but being here to solve problems = unwraps being welcome <3
[CameronSquires/AdventOfCode2022] pythonthis solution was almost javascript, but thankfully i sat down with sir keenan and sorted him out for this to be written in typescript, and future problems to stay typescript
i’m biased with this one since during the typescriptification, i also helped refactor it slightly :)
[RyanBrushett/adventofcode2022] rubypretty compact, clever usage to keep getting the
max
from a list and removing that item from the list!
[joel1842/advent-of-code-2022] pythonmy advent of code 2019/2020 solutions were done in crystal, so its nice see a ruby solution
input parsing is clean, and using the inline postfix
if
is cleanruby is just clean in my mind, i will admit, i am biased
[canetoads.ca] javascriptjoel out here gold golfin’ with the bulk of the logic in a one liner!
[apreynolds1989/AdventOfCode2022] typescriptan interesting deployment method by nathan over from ndev
with an even better way of how i’m noticed of his solutions:
canetoads.ca/rss.rss
an rss feed
truly living in the future
the solution itself is simple and functional
just how i like it
[leahmarg/Advent-of-Code-2022] pythona nice little typescript solution, good usage of utility functions to make the actual problem solving step clean
getThreeHighest(createNestedArr(readFile(file))));
this is one of those cases where i’d recommend someone to using the pipe operator, if only [this proposal] becomes stable / later stage eventually
readFile(file) |> createNestedArr() |> getThreeHighest();
just imagine if the above was valid syntax!
maybe one day
leah is so epic