↤ go back, or return home

jack's advent of code 2022 ramblings

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:

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 src/data/aoc/2022/data

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

[maegpi-nl/advent_of_code] src/data/aoc/2022/data

i 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 ;)

[briannamcdonald/advent-of-code-2022] python src/data/aoc/2022/data

brianna also did well on the leaderboard, i believe inbetween myself and mudkip

[krbarter/Advent-Of-Code-2022] python src/data/aoc/2022/data

kent out here

[nint8835/AdventOfCode2022] f# & python src/data/aoc/2022/data

riley going in with the f# again this year! nice to have another functional friend :)

[hamzahap/AdventOfCode2022] sheets src/data/aoc/2022/data

hamzah pls

amazing though, seeing excel solutions is always fun

curious how long this lasts until you fallback to, well, a programming language :)

[TheCrypticCanadian/advent-of-code-2022] python src/data/aoc/2022/data

there is a jupyter notebook file here, and two .py files

gump whats going on here

great job though, keep it up <3

[STollenaar/AdventOfCode2022] golang src/data/aoc/2022/data

its 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

[DanielPower/AdventOfCode2022] haskell src/data/aoc/2022/data

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

[emilydormody/advent-of-code] src/data/aoc/2022/data

there 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

[ecumene/advent_of_code] python notebook src/data/aoc/2022/data

mitch going ham with utilities that fetch problem input directly from the site, and even submit answers to the site from the code, neat

[zcvaters/adventofcode2022] swift src/data/aoc/2022/data

swift! neat

type definitions here look funky, it feels familiar in some ways, but also foreign in others

[chadmroberts88/advent-of-code-2022] typescript src/data/aoc/2022/data

nice lil input parsing, and great usage of condensing previous problem into something reusable for the second

[devthedevel/advent_of_code] typescript src/data/aoc/2022/data

dev 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

[mathieuboudreau/advent] python notebook src/data/aoc/2022/data

clean lil notebook, with a link to open in [binder], which is the first i have heard of it, looks cool

[SteveParson/AOC2022] c, python, & java src/data/aoc/2022/data

keeping 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

[ajhynes7/advent-of-code-2022] julia src/data/aoc/2022/data

cute little julia solution, i find julia is always nice to look at

[ericthomasca/adventofcode2022] rust src/data/aoc/2022/data

pretty decent rust solution, more unwraps than one would hope to see, but being here to solve problems = unwraps being welcome <3

[Keenan-Nicholson/AdventOfCode] typescript src/data/aoc/2022/data

this 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 :)

[CameronSquires/AdventOfCode2022] python src/data/aoc/2022/data

pretty compact, clever usage to keep getting the max from a list and removing that item from the list!

[RyanBrushett/adventofcode2022] ruby src/data/aoc/2022/data

my 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 clean

ruby is just clean in my mind, i will admit, i am biased

[joel1842/advent-of-code-2022] python src/data/aoc/2022/data

joel out here gold golfin’ with the bulk of the logic in a one liner!

[canetoads.ca] javascript src/data/aoc/2022/data

an 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

[apreynolds1989/AdventOfCode2022] typescript src/data/aoc/2022/data

a 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

[leahmarg/Advent-of-Code-2022] python src/data/aoc/2022/data

leah is so epic