Day 8... Screw it... Python onwards...
Then I’ll probably fall back on Python. :)
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE Strict #-}
stateful s' f = runState f s'
forEach xs state' f = foldM f state' xs
solve input = forEach input initial_state $ \st current_value -> stateful st do
...I want to try again this year, do you have any advice for how to get going with Ocaml as someone who has programmed long enough to understand how recursion, linked lists, and all that jazz works, and just wants to figure out how to be productive in the language?
Additionally I've been solving for a number of years, but for the past 2 years, I've done a daily explanation of the solution. I use interesting parts of the Python stdlib and walk readers through common algorithms. I've found it _incredibly_ rewarding and plan on doing it again this year.
You can see all of those solutions here: https://github.com/xavdid/advent-of-code/tree/main/solutions
Please let me know if you enjoy reading these, I love hearing from folks!
1) The site should ask for the language used to solve the problem and then use this as semi-scientific data for comparing "time-to-solution" for various languages. The sheer volume of data and the relatively high difficulty of cheating on novel problems would make this data set interesting and maybe even useful.
2) I wish all the puzzles had a "hardcore" mode where a naive approach would take a million years of compute, or exabytes of memory. Have multi-gigabyte inputs[1] such that the time-to-solution isn't just how fast you can bang out some simple parsers and loops, but the runtime performance would materially affect your time score.
[1] A method for this would be to use an input-file-generator that is small to download but can generate huge puzzle inputs.
I do find there's usually one or two spots that you can eek by with threads and throwing compute power at the problem. But those are rare — usually you have to actually solve it.
I think this would just show you the average time zone of the language's users.
I can't believe any valid causal inference about languages could be drawn from this, because the skill of the individual programmer at solving these types of puzzles (recognizing the patterns, knowing the number theory, etc.) would surely dominate any impact of the language itself.
I suppose you could conclude something along the lines of "newer programmers use Python more often than Haskell", but I doubt there would be many surprises there.
You'll see those stats and others' solutions (well, not on all challenges).
My favorite so far is 2019, where several of the problems had you write and extend an emulator for the imaginary (and wacky) "IntCode" computer.
Reddit r/adventofcode is also fun. People post not only solutions in various languages, but visualizations of solutions (e.g., an animation of that game of Breakout). Sometimes people post fun things, like a solution to a puzzle in Apple II BASIC and a video of it running on an actual Apple II.
Agree.
I think it helps to do it in a language you're not familiar with, or with some artificial limitation on how to solve it (no third party libraries for instance).
It takes more time, but felt less like a grind for me.
https://www.kylheku.com/cgit/advent/tree/2021/19
Some people's solutions used some linear algebra libraries in ways I don't understand; one day I will revisit that.
I also think the choice of language matters a lot. I did it in prolog a few years ago and it was super concise because you just dealt with pure logic at that point.
I can see it be more verbose in Java :) but seriously I find these puzzles hard but not in a chore kind of way.
The idea is that you read and understand a small piece of code (full of useful techniques) and make a small change to demonstrate understanding.
Games that require you to write the code are limited to rehashing the same old tired algorithms... reverse a string and other sequence techniques, edit distance and dp variants, optimization by binary search and evaluation, etc., the standard leetcode stuff. Basically, useless wankery you will never use. The competitive programming standards.
If you don't have to write it, just understand it, the game can cover some very interesting new algorithmic terrain. It becomes part book, part game. Like Hacker's Delight: The Game.
Seems like it might help me get better at code reviews too. Granted, I don’t like doing code reviews (mostly cus it’s usually pretty uninteresting code). But I do like puzzles! I’ll check it out :)
I felt I was quite fast in being done with part1 after 3 minutes and part2 in 4 minutes (rank ~1000). I even tried to skimread the explanation to be fast, have a script to download the input and run it etc., but still no match!
2. Use a language that makes the edit/run cycle short.
3. Be very familiar with that language and how to process input in it.
4. Have solved many similar problems in the past so you can parse these problem statements quickly.
5. Have solved many similar problems in the past so you know exactly what code to write or use (if you have a utility library).
Definitely. A lot of it is always the same (open files, iterate over input, operating on arrays/lists etc.). Something like Peter Norvig has in Python:
https://github.com/norvig/pytudes/blob/main/ipynb/Advent%20o...
This sounds like an advent of code specific thing. The problem itself is trivial, no need to have solved anything similar in the past, but the description is so verbose (because it’s a cute Santa-related story) that it becomes hard to parse the problem we’re trying to solve, quickly.
I don’t think this is common in any other competitive programming environment.
And I guess I could do better on 2, but on this day I only needed 1 run. I use Kotlin, and guess I lose a second or two on it compiling before running. I see today's winner just did everything in browser console as a repl. So that's probably a good way to minimize the loop. Pretty annoying for the later problems, though.
curl https://adventofcode.com/2022/day/1/input
Puzzle inputs differ by user. Please log in to get your puzzle input.Who cares what others do with the game? Have fun while doing it
You're asked to write server code that meets the given protocol definition.
I've created this leaderboard last year and announced it here. It has a few people I know personally, and a few people from HN I've never met.
There's no community Discord or anything like that. The only form of communication are the stars appearing after other people's names after a while :)
Tangential question - why does the HN crowd hate these types of questions in interviews but apparently likes to do them on their own time? Different folks answering to different posts? Honestly curious.
- You can take your time, no pressure.
- You can use whatever language or paradigm you like.
- You don't have to explain anything to anyone.
- You are not ashamed of using hacks or shortcuts.
- It's a learning exercise if you are using a new language.
- You can google for things like "I know this problem needs A* but I forgot how to implement it", which show you know the important part, how to solve the problem, but forgot the useless part, the algorithm itself, which you can easily google.
- There's a single, objective answer to the problem and it gives you hints about it (too low, too high).
If interviews where like this where I could do problems at my own pace at home and then later in the next interview we'd discuss my solution, interviews would be way less stressful and interesting. The interviewer would even know how long I took to solve the problem.
(Now for context, the interview questions I typically would recommend are a order of magnitude easier than AoC's typical bar, in the language of the candidate's choice, ideally on a real computer and not a whiteboard. Tonight's question though (a warmup) wouldn't be a bad one. It's straight-forward, no trickery, nothing clever, and directly applicable to real-world coding. And it would screen >50% of candidates that I'd give it to.)
(We do not ask in interviews questions of the same nature as the last third of AoC. If anything, most of our interview questions are below AoC day 1 in difficulty. And yet they screen absurd numbers of candidates.)
Last year I solved two puzzles by looking up the answer on reddit, and other than that I tried to solve them as is. But I feel like it is sometimes a bit like solving a puzzle is a bit like reinventing parts of math and computer science if you didn't happen to have learned those from school or a book.
Use platforms such as codingame.com for more targetted training, or if you need motivation.
Best of luck to everyone!
Here's how today's #1 did it (day 1 solution SPOILER): https://youtu.be/Vl1w7kWRtDg?t=144
The presence of files with the "lpi" and "lps" extensions means you are using an IDE ? Moreover, I thought the extension for Pascal source code was "pas" but I see "lpr". Why ?
I could very well be wrong.
Now this is simplified I know, but I'm not convinced in your proposed duality.
I may also do it in F# and .NET Interactive notebooks using the Polyglot Notebooks Visual Studio Code extension, but I suspect the solutions will look very similar.
In the 350 (for now) stars club.
I also cannot tolerate hard problems so probably will stop around the same number.
I couldn't find anything on the About page that clarifies this.
Edit: I see anonymous users in the leaderboard, so it seems like it might be possible.