đŸ’Ÿ Archived View for dioskouroi.xyz â€ș thread â€ș 29403522 captured on 2021-12-04 at 18:04:22. Gemini links have been rewritten to link to archived content

View Raw

More Information

âžĄïž Next capture (2021-12-05)

-=-=-=-=-=-=-

Advent of Code 2021

Author: ducharmdev

Score: 719

Comments: 262

Date: 2021-12-01 13:41:56

Web Link

________________________________________________________________________________

patrickdavey wrote at 2021-12-01 17:29:34:

I love adventofcode. I have a rule I follow now which makes it a lot more enjoyable: if I can't make headway on a problem after trying for a day or so, I'll use the subreddit to find a hint, and then usually that's enough to help me to the answer. Very occasionally I just completely cheat (often the pure math based questions).

I don't like missing out on the stars.... I mean it's the only way you get to see the awesome ascii art when you collect all 50 for the year.

Many thanks to Eric and team for what must be a huge effort to run such a fun programme.

Oh, the other thing I do: I don't even start until sometime in January :) far less stress and keeps the whole family much happier ;)

Toutouxc wrote at 2021-12-01 16:25:24:

I'd like to remind everyone that it's totally okay to do the first 10-15 days and leave the really hard stuff to people who are smarter or maybe have more free time. The first few days will still be fun.

I'm checking out Elixir this year, because I write 95 % Ruby at work and I'm getting really intrigued by the functional stuff seeping into it.

qsort wrote at 2021-12-01 17:14:25:

It's also okay to just do the problems without the competitive aspect. I love competitions and all, but sure as hell I'm not waking up at 5AM for an entire month in the pursuit of internet points.

mumblemumble wrote at 2021-12-01 17:55:57:

My main use case for AoC is practice with new languages. So I tend to prefer to do the same one from several years ago over and over, because then I can focus on grokking the language and not the problem, and I can compare my solutions across languages to get a better feel for how they affect how I solve problems.

The leaderboard is occasionally interesting to me for the first week of December, but, realistically, I can't see getting invested in it without also moving far, far to the west of where I live now.

epolanski wrote at 2021-12-02 00:44:17:

Don’t you risk solving the problem in suboptimal or just “wrong” ways for the language you’re trying?

elliekelly wrote at 2021-12-02 13:46:54:

I don’t know about others but I‘be found AoC is quite good for naturally discovering how you’ve solved a problem “wrong” or sub-optimally when you get to Part 2.

mumblemumble wrote at 2021-12-02 01:13:34:

I also check out how other people did it on GitHub. But only after I've taken a crack at it myself first.

andreineculau wrote at 2021-12-01 19:53:20:

Thought about that last year. You wouldn't have your solutions public but any chance?

pablodavila wrote at 2021-12-01 17:48:51:

José Valim (creator of Elixir) will be streaming his solutions on Twitch. Thought that might be interesting for you.

whalesalad wrote at 2021-12-01 19:56:43:

I started doing mine in Elixir last year but it was a very steep gradient combined with everything else going on in life. So excited to hear this! I will be watching every episode for sure.

bear8642 wrote at 2021-12-02 01:28:05:

could you provide a link? Having trouble finding

graedus wrote at 2021-12-02 03:41:35:

twitch:

https://www.twitch.tv/josevalim

related tweet:

https://twitter.com/josevalim/status/1465327529238183940?s=2...

Toutouxc wrote at 2021-12-01 19:23:00:

Beautiful, thanks!

regulation_d wrote at 2021-12-01 19:19:03:

I really enjoy doing these problems in Elixir, but the fact that the default collection type is a linked list makes certain problems difficult. However, Erlang does have a fifo queue (a doubly linked list), which can be helpful and let's you practice some Erlang interop while you're at it.

https://www.erlang.org/doc/man/queue.html

princemaple wrote at 2021-12-02 03:47:36:

queue in erlang is a tuple with 2 lists. it reverses the items in one list and put them in the other, if the second was empty, when you try to access the head of the queue. new items still goes into the first list.

np_tedious wrote at 2021-12-02 10:42:01:

I have failed to finish a few times. Not necessarily because they get harder (tho that contributes), but because I go at the speed/time I'm willing to dedicate and once the new year hits I invariably lose interest

Still enjoy whatever I get done

SketchySeaBeast wrote at 2021-12-01 16:27:49:

Also, you can be strategic, the weekend ones are built to be longer than the weekday ones, so there's still some fun to be had later on even if you get stuck.

Rendello wrote at 2021-12-02 04:38:27:

I normally skip out on these things, but I've been wanting to learn Erlang for a few months now and this comment inspired me to go for it this year! It might not help with learning the OTP stuff, but even after finishing the first two challenges I feel my mind expanding (first time doing functional programming).

dimgl wrote at 2021-12-01 19:15:06:

I did Elixir one year for advent of code! It was pretty fun and helped me learn the language a bit more actually. Hope you enjoy.

TrueDuality wrote at 2021-12-01 21:07:04:

I do love using these advents to try out new things. New patterns, new languages, new algorithms.

thanksfortherem wrote at 2021-12-01 17:01:51:

Thanks for the reminder, guy who knows Ruby and is learning Elixir and makes authoritative comments.

Waterluvian wrote at 2021-12-01 22:57:20:

I respect that AoC gets very difficult and is for an audience that isn’t me.

But I love the format and what I’d enjoy is a similar project where the difficulty doesn’t really increase, but each day is a different problem domain. Breadth not depth.

For example, perhaps we start with some data processing from a file. Then answer some basic statistics question about the data. Then maybe some basic signal processing. We form an image. We transform the image. We play the image as audio. We break it into packets of some sort then share it on a “network.” We reassemble it. We build a state machine and pass it the reassembled data in some way. We discover some new output.

Etc. etc. culminating with some fun discovery that inside that original data was a secret code or whatever.

And instead of an intense challenge, we’ve just had a fun walk through an intro to two dozen subdomains of CS/sweng. You may not have immediately known the answer to each puzzle but you never felt lost.

thr0w__4w4y wrote at 2021-12-01 23:51:21:

I like this idea. I've participated each year, only finished the 2020 one (most have 1-2 to go, never had the time & motivation to fight through it.)

BTW, there is a great book that is right up this alley -- maybe you know it -- "The New Turing Omnibus: 66 Excursions in Computer Science"[0]

I discovered "Omnibus" from Peter / Catonmat [1]

It's 66 short, manageable topics, each ~5-8 pages:

1 Algorithms

2 Finite Automata

3 Systems of Logic

4 Simulation

5 Godel's Theorem

6 Game Trees

7 The Chomsky Hierarchy

8 Random Numbers

9 Mathematical Research

10 Program Correctness

11 Search Trees

12 Error-Corecting Codes

13 Boolean Logic

14 Regular Languages

15 Time and Space Complexity

16 Genetic Algorithms

17 The Random Access Machine

18 Spline Curves

19 Computer Vision

20 Karnaugh Maps

21 The Newton-Raphson Method

22 Minimum Spanning Trees

23 Generative Grammars

24 Recursion

25 Fast Multiplication

26 Nondeterminism

27 Perceptrons

28 Encoders and Multiplexers

29 CAT Scanning

30 The Partition Problem

31 Turing Machines

32 The Fast Fourier Transform

33 Analog Computing

34 Satisfiability

35 Sequential Sorting

36 Neural Networks That Learn

37 Public Key Cryptography

38 Sequential Cirucits

39 Noncomputerable Functions

40 Heaps and Merges

41 NP-Completeness

42 Number Systems for Computing

43 Storage by Hashing

44 Cellular Automata

45 Cook's Theorem

46 Self-Replicating Computers

47 Storing Images

48 The SCRAM

49 Shannon's Theory

50 Detecting Primes

51 Universal Turing Machines

52 Text Compression

53 Disk Operating Systems

54 NP-Complete Problems

55 Iteration and Recursion

56 VLSI Computers

57 Linear Programming

58 Predicate Calculus

59 The Halting Problem

60 Computer Viruses

61 Searching Strings

62 Parallel Computing

63 The Word Problem

64 Logic Programming

65 Relational Data Bases

66 Church's Thesis

[0]

https://www.amazon.com/New-Turing-Omnibus-Sixty-Six-Excursio...

[1]

https://catonmat.net/top-100-books-part-one

zerr wrote at 2021-12-01 23:45:36:

Interesting, what kind of difficulty is it? Does one need to know some particular theory topics, e.g. Computational Geometry or advanced/exotic data structures & algorithms? Or is it about the size/complexity of the solution? Or is it an A-ha moment?

Waterluvian wrote at 2021-12-02 01:54:05:

I think my best example is if you play or watch a play of Human Resource Machine.

The game is relatively easy. You never feel lost. But there’s some thinking involved. And before you even realize it, you’ve implemented a linked list in Assembly.

Jtsummers wrote at 2021-12-02 02:06:34:

And its sequel, 7 Billion Humans. Fantastic game exploring concurrency and coordination in a similar assembly-ish language. It starts off without too much trouble, but develops to some really neat challenges trying to coordinate a dozen or more humans running the same program.

cjbprime wrote at 2021-12-02 01:08:32:

On the very easy end of tech interview style problems, requiring almost no computer science theory yet having concrete solutions, but there's a split between part 1 and part 2 of each challenge, and one of the most interesting parts is having to abstract the first solution to accomodate the second (which might e.g. introduce a new constraint or scale up the problem).

d_burfoot wrote at 2021-12-02 01:49:33:

AoC starts easy and gets harder over the course of the month. Having done both tech interview problems and AoC, I can assure you that the later AoC questions are not on the "very easy end".

flaie wrote at 2021-12-01 15:27:22:

I have been solving these since years, I find it a nice way of assessing a language and deep dive since it will cover lot of parts of what makes a language.

I have been porting my old solutions in other languages into Kotlin over the time, and will be again doing them in Kotlin. I find it a nice language for AOC since custom extensions and DSL possibilities, it has a good builtin libraries and you can always fallback on Java, even if it has some shortcomings.

Regarding the AOC per se, I take it as a fun daily challenge, I know I won't be able to be part of the top 100, at least I would with some luck during the first 3 days, and then.. nope, that's life, try not to be too competitive. Last year it took me 8 hours to solve day 20, but it's a game, you should have fun doing it (I had), if not people should stop.

However, I strive in trying to write pretty, compact, idiomatic and as functional as possible code, which means that sometimes I will write an ugly solution in 5 minutes, and will take an hour to make it beautiful.

Besides I like to read the story, I know plenty of friends who don't even read the adventures of Santa, they just solve the puzzle and that's it, they don't even know they saved Christmas :-D !

Jtsummers wrote at 2021-12-01 16:13:25:

> which means that sometimes I will write an ugly solution in 5 minutes, and will take an hour to make it beautiful.

I think I spent 2 hours last night just playing around with different methods of solving it after my initial version. Other libraries, slightly altered algorithms. I think that's one of the parts I enjoy the most, solving the puzzles is fun. Trying a dozen different variations is, for me, more fun (and more edifying).

matsemann wrote at 2021-12-01 17:46:02:

Yeah, kotlins stdlib for collections is great. Has all kinds of variants of reducing, grouping, filtering, mapping, taking, dropping etc one can think of. Today's solution was to just call the window function.

101011 wrote at 2021-12-01 19:58:37:

Spoilers dude! I haven't started yet.

akpa1 wrote at 2021-12-02 17:34:51:

2020's day 20 was really tricky - that, and day 23 were the only two days I didn't manage to solve two parts on. I managed to get part one for day 20, but neither parts for day 23. It was good fun trying both, though!

ducharmdev wrote at 2021-12-01 17:17:10:

Haha, your last line really made me smile.

raldenx wrote at 2021-12-01 20:53:23:

I can vouch for wasting hours of coding due to not reading the problem thoroughly.

patrickdavey wrote at 2021-12-01 21:09:03:

Or not trimming your input. I worked and reworked and reworked a problem once, the answer was some number in the billions. Eventually I gave up because I just couldn't work out where I went wrong. I then took someone's working solution and plugged my input in, and I was out by one, because it counted chars and I had a stray newline.

I'd like to say it only happened once, but, it happened again later that year... And then never again (because I pulled out code to always strip newlines after reading it in ;)

tslater2006 wrote at 2021-12-02 00:16:23:

This led me one year to registering adventofrealizingicantread.com

It just redirects to the advent site but I've grown to love it :)

reikonomusha wrote at 2021-12-01 20:46:09:

AoC is often used to learn a new programming language, but it can also be used to improve them—especially less established ones.

Theres a small community [0] of people who decided to try out Coalton [1], which is a Common Lisp DSL that has a strict, Haskell-like type system, and has strict evaluation (not lazy) semantics. Pattern matching, algebraic data types, all that jazz are supported directly in a Common Lisp environment.

For example, here is a function to read in the first problem's data, which makes use of the usual high order functions (map and filter), as well as currying (only one argument provided to /=, making it curried):

(declare read-aoc-data (Unit -> (List Integer)))
    (define (read-aoc-data _)
      "Read the data for problem 1."
      (let ((data (fromSome "Couldn't read AOC1 data."
                            (read-file-into-string aoc1-input-file))))
        (map parse-int-or-fail
             (filter (/= "") (split-string #\Newline data)))))

Type annotations, as in any good ML, are optional (except when there are polymorphism bugs, like one found during AoC!). Unlike Haskell, purity isn't demanded.

There's a small contest [2] with all sorts of prizes for doing AoC in Coalton and contributing back to the project through tutorials, PRs, and bug reports.

[0] They hang out on Discord

https://discord.gg/cPb6Bc4xAH

[1]

https://github.com/coalton-lang/coalton

[2]

https://coalton-lang.github.io/20211129-aoc-contest/

mynameisash wrote at 2021-12-02 02:28:51:

I didn't know _anything_ about AoC until just recently when I took a very brief look at the 2020 problems (but didn't deep-dive). I'm trying to find good problems that can help me learn SAT/SMT solvers, but there doesn't seem to be much out there. Anyone know how well-suited these are for AoC?

dunefox wrote at 2021-12-01 21:15:44:

Oh man, I'm using CL for aoc this year and just figured out how to install Coalton. Maybe I'll do couple of days in it as well!

LandR wrote at 2021-12-01 14:59:24:

Like every year, I feel I'm being lured in by an overly easy day 1.

Then somewhere between day 10 and 15, there will be a steep increase in difficulty and I'll tap out for the year. Then come back to the puzzles over the course of the year and maybe knock out another one or two.

bhrgunatha wrote at 2021-12-01 15:30:57:

There are some plots [1] of the time taken for the first 100 solutions to part 1 (silver dot) and part 2 (gold dot). They're a good visual indication of the relative difficulty of each question and how the difficulty of the second part increases.

[1]

http://www.maurits.vdschee.nl/scatterplot/

djaychela wrote at 2021-12-01 16:55:00:

Those plots are really comforting for me, as on the days where a part was difficult (such as day 20 part 2 last year) I didn't find a solution. Thanks, I'll be keeping an eye on them this year as things progress (or not!)

speedgoose wrote at 2021-12-01 19:25:05:

And that's for the top 100. I would assume that the differences would be even larger for the average developers.

oceliker wrote at 2021-12-01 23:50:17:

That's crazy. I have no idea how anybody can solve this problem in 258 seconds:

https://adventofcode.com/2020/day/20

Did they hope the corner tiles had unique edges and look for those? (which would be unlikely under normal circumstances, considering there are more than a hundred tiles and only 256 different possible edges...)

CameronAavik wrote at 2021-12-02 02:24:32:

Funny you mention that, the person who solved part 1 in 258 seconds recorded themself solving that one live:

https://www.youtube.com/watch?v=ODUkgEeF7sc

buttercraft wrote at 2021-12-02 03:29:35:

Wow, it took me longer than 258 seconds just to understand the problem statement. I had to read it several times before I understood what "border" meant, as it does not match common usage. I noticed that you referred to them as "edges" instead which would have immediately made sense to me.

It's not just measuring your problem solving abilities but also your famiarity with the author's writing style.

rovolo wrote at 2021-12-02 19:46:44:

Just curious, what is the difference is between "Border" and "Edge" to you? To me, they are nearly synonyms.

Apple's Dictionary (Oxford?)

> 2 the edge or boundary of something, or the part near it: the northern border of their distribution area | figurative : the unknown regions at the borders of physics and electronics.

https://www.merriam-webster.com/dictionary/border

> 1 : an outer part or edge

https://www.dictionary.com/browse/border

> the part or edge of a surface or area that forms its outer boundary.

yesbabyyes wrote at 2021-12-02 01:07:31:

While I agree four minutes is very quick, if you take into account that no side fits with more than one other side, and that the sides (#, .) may just as well be interpreted as binary numbers, it becomes an issue of parsing, mostly, and then matching numbers.

I remember being flabbergasted at first, and then realizing the above. My solution is here:

https://github.com/linus/aoc/blob/main/2020/js/day-20/app.js

oceliker wrote at 2021-12-02 01:43:09:

So it turns out I missed those parts of the problem statement. That makes it fairly easy. I probably still can't write working code for that in four minutes, but it does sound humanly possible, at least.

Also, that's really nicely written code :)

jcranmer wrote at 2021-12-02 00:14:43:

From the problem statement:

> Tiles at the edge of the image also have this border, but the outermost edges won't line up with any other tiles.

So they didn't need to hope; the problem guaranteed it for them.

oceliker wrote at 2021-12-02 01:39:44:

Ah, sorry, I missed that. That does make it easy.

wpietri wrote at 2021-12-01 17:29:12:

Ooh, that's really interesting. And given how many folks here talk about dropping out as it gets harder, that suggests the later problems look easier than they are.

Jtsummers wrote at 2021-12-01 17:31:00:

The weekday problems tend to be easier so you get a ramp up, but with drops in difficulty. A lot of people give up after one or two of the hard days and don't continue, but there's no actual requirement to do them in order. If they'd skip the hard ones they'd probably find several more solvable (for them) problems remaining in the year.

pedrosorio wrote at 2021-12-01 22:21:10:

These plots only include the first 100 people. Those dropping out as it gets harder were unlikely to be be represented in the top 100 for later problems either way.

Strilanc wrote at 2021-12-01 16:00:59:

I like that the data clearly shows the server issues on day 1.

Volundr wrote at 2021-12-01 18:38:00:

Is this really saying for 2021, the first solution to the first problem came in 30 seconds after being posted? That's insane!

Rietty wrote at 2021-12-01 19:14:51:

People are incredibly quick at both skimming/parsing the problem, coupled with a language like python where you can generally express stuff incredibly concisely and not have to worry too much about types, it makes it very quick.

notafraudster wrote at 2021-12-01 21:46:45:

I'm in a really bad time zone for AoC right now, but here was my solution in R for day 1 problem 1.

      library(tidyverse) # pre-typed
    lines = readLines("data/day1.txt") %>% as.numeric() # Read data
    diff(lines) %>% .[. > 0] %>% length() # Part 1

This didn't involve me being a sophisticated or good programmer, and if I was in a time zone to be competitive I also would have written a function to submit my answer from within my IDE (which can also be pre-written). I could absolutely buy people wanting to be competitive and being able to do this in 30 seconds. I actually could have pre-written the second line of three, in point of fact.

jazzyjackson wrote at 2021-12-02 11:02:09:

whoa I didn’t even consider automating my answer submission, suppose it’s just a curl away

artursapek wrote at 2021-12-01 17:46:40:

...is the y axis showing DD:HH:MM or HH:MM:SS?

Jtsummers wrote at 2021-12-01 17:50:59:

HH:MM:SS, the first 100 solvers are usually done within minutes, hours at most, and never days. None of the problems are _that_ hard.

artursapek wrote at 2021-12-01 21:28:38:

wow 0:

time_to_smile wrote at 2021-12-01 16:09:44:

And for anyone celebrating the holidays day 10-15 tends to be where I find real life holiday planning/activities start to rapidly take over my free time. I'm certainly not going to miss out on eggnog with friends and family so I can solve a few extra AoC problems.

I personally don't mind, if I spend 10 days learning a new language and solving some problems I'm satisfied. I'm still very excited when AoC comes up every year!

simmonmt wrote at 2021-12-02 01:43:40:

You only have yourself to blame if you stop early due to misplaced priorities :)

codingdave wrote at 2021-12-01 15:06:07:

Agreed - I did Day One by copy/pasting the input into a spreadsheet and calculating the answers in additional columns. I suspect I'll need to actually write code soon, though. And give up soon after that.

jaywalk wrote at 2021-12-01 17:08:01:

I did the same thing. I was about to start writing some code, and then figured it would be much quicker to just drop it in Excel and write a couple formulas.

drc500free wrote at 2021-12-01 23:47:47:

I usually get at least 10-15 days in using Excel, and sometimes can do the later ones as well. Some of the problems are MUCH easier this way, especially since I moved to Product years ago.

SketchySeaBeast wrote at 2021-12-01 15:02:30:

Yup, the first couple of days are always simple, but then you're on Saturday of week 2 and wondering why it's already 4 AM.

uyt wrote at 2021-12-01 15:41:29:

If you're doing AoC you should join the subreddit /r/AdventOfCode:

https://www.reddit.com/r/adventofcode

There's usually a lot of different solutions (including many in esoteric languages or code golfed) along with screencasts and visualizations to explain how they got there. I find that even when the puzzles are easy I still learn a lot from the community by seeing all the different ways to skin a cat!

jstx1 wrote at 2021-12-01 15:07:52:

One of the fascinating things is reading other people's solutions. You get wild extremes - from easy clean solutions that I would never think of to some very weird choices. Especially in the first few days when the puzzles are easier it's more of the latter - there are some extreme abuses of Python in today's solutions thread on reddit. I get that it works but I also hope that nobody I work with ever writes code that way. I assume it happens more with Python because beginners are more likely to use it and because it gives you so much flexibility.

On the flip side, it's a bit humbling to see people solving the difficult days extremely quickly or having very concise and elegant solutions.

bussierem wrote at 2021-12-01 15:15:23:

I really enjoyed the early part of this last year, but I got to Day 19 and suddenly it became

"if you memorized some mathematical concepts and an obscure algorithm and also recognize that this exact algorithm is the only efficient solution to the problem then you can solve this in 5 seconds, otherwise it will never finish running with any other algorithm".

I immediately quit. I'm not doing these to prove I'm smarter than other people or memorized random math concepts, I'm doing this to practice writing code or to learn a new language.

Not sure if this is indicative of other years (This is the farthest I've persisted in the 3 I've tried) but it was EXTREMELY demotivating, and killed every desire to continue or to even try it again next year.

Strilanc wrote at 2021-12-01 15:46:21:

Interesting. I think one of the main benefits of AoC is it tends to teach you things. So I would have gotten stuck, read peoples answers on the subreddit the next day, and the problem would have stuck in my memory as one that taught me something new.

I also wouldn't consider knowing properties of the GCD to be a "random math concept". It shows up in a reasonably large number of contexts. For example, in public key cryptography. A specific case is that at one point someone realized they could just collect hundreds of millions of RSA public keys and crack low entropy ones by checking for common divisors. Doing this naively by checking each pair would have been very costly, but they used properties of the GCD to massively reduce the cost by pooling keys [1].

[1]: Page 7 of

https://www.quintessencelabs.com/wp-content/uploads/2020/03/...

justinsaccount wrote at 2021-12-01 15:42:51:

> if you memorized some mathematical concepts and an obscure algorithm and also recognize that this exact algorithm is the only efficient solution to the problem then you can solve this in 5 seconds, otherwise it will never finish running with any other algorithm

well that's just not true at all.

I had no idea WTF the Chinese Remainder Theorem was and just worked out the issue iteratively. All you had to know was that if you are trying to find some large number that is divisible by other prime numbers, the deltas between the candidates will be the product of the numbers.

as in, if you are trying to find a number that is divisible by both 37 and 41, you really just need to find numbers divisible by 1517.

I forget what the name for this mathematical concept is, but it's far less obscure than the CRT.

gknoy wrote at 2021-12-01 19:39:36:

> All you had to know was that if you are trying to find some large number that is divisible by other prime numbers, the deltas between the candidates will be the product of the numbers.

"All you have to know is .. {this magic}" -- that really reminds me of my freshman year math classes where the TAs would just say, "well if you do it THIS WAY..." (when my main question was how the heck you stumble upon looking at the problem that way, vs all the failed ways)

solveit wrote at 2021-12-01 20:28:20:

> when my main question was how the heck you stumble upon looking at the problem that way, vs all the failed ways

Well you stumble through half a dozen failed ways first, is the usual method. Eventually you gain "intuition" that lets you jump straight to the way that works and you can't explain exactly how you thought up the correct method, but it just feels so natural and anyway, you can explain in great detail why nothing else would work.

I'm teaching calculus this year so I sympathise with both sides. The problem is that the answer to "how did you know to do it that way?" is experience, as in all fields. But students rarely have the time to accumulate experience and intuition before finals, so there's frustration all around.

What I'm saying is I'm not looking forward to grading six hundred finals where many students will inevitably spend too much time on approaches that were obviously (to me) doomed from the start because they haven't stumbled enough to know it yet.

justinsaccount wrote at 2021-12-01 21:49:20:

It's not really magic though. Here's a simpler variation of the problem:

Two buses make different circular routes from the same depot. One bus takes 3 hours to do a loop, the other takes 5. At what times from the start of the day will both buses be at the depot at the same time?

you could write a loop like this:

      for t in range(0, 10000):
        if t % 3 == 0 and t % 5 == 0:
            print("same at", t)

which if you run, you'd see:

      same at 0
    same at 15
    same at 30
    same at 45
    same at 60
    same at 75
    same at 90

and even if you knew nothing about math, you could see that and think, oh, so they just meet every 15, which happens to be 3 times 5... You don't need to count up one at a time and check remainders, you can just increment by 15 and get the exact same result..

      for t in range(0, 10000, 15):
        print("same at", t)

That's more or less what I did when I solved it.. saw how the problem simplified to finding the common multiples of numbers, which when they are prime is just the product. apply this process iteratively and you have the solution.

boutell wrote at 2021-12-01 15:59:12:

Yes, I worked it out similarly and I saw comments on the twitters recently from others who did. Also usually the tough stuff is in the second part of each day, which I feel is pretty fair and provides a way to feel reasonably good about your result if you're not completely successful.

justinsaccount wrote at 2021-12-01 16:03:22:

Yeah, I always liked how I could generally solve something a "dumb" way for part 1, but would likely need to refactor it to be a bit smarter to solve part 2.

shever73 wrote at 2021-12-01 16:23:03:

Yep, that's pretty much how I solved it too. I had (and still have) no idea how to apply the Chinese Remainder Theorem. Looking back at my solution, I just iterated through the input, which I'd mapped to a Python list.

Someone wrote at 2021-12-01 17:27:14:

Nitpick: there’s no way to _apply_ the Chinese Remainder Theorem. It merely states that _“if one knows the remainders of the Euclidean division of an integer n by several integers, then _one can* determine uniquely the remainder of the division of n by the product of these integers, under the condition that the divisors are pairwise coprime.”* (

https://en.wikipedia.org/wiki/Chinese_remainder_theorem

) It doesn’t say _how_ to determine that number.

https://en.wikipedia.org/wiki/Chinese_remainder_theorem#Comp...

describes a few algorithms for doing that.

anandoza wrote at 2021-12-01 18:26:58:

Well, you can apply the theorem to the problem. Or apply its principles to the problem.

Someone wrote at 2021-12-03 09:16:00:

No, you can’t. It only says the problem has a unique solution. It doesn’t even say an efficient algorithm for computing it exists, or even whether an algorithm exists. Neither of those are very hard to prove, but the theorem won’t help you there.

For comparison, let’s say the _“sorting theorem”_ says _“if you have n different numbers, you can place them in a sequence so that no number is larger than its predecessor”_.

Now, you have two numbers. How do you apply that theorem to place them in a sequence so that no number is larger than its predecessor?

dunham wrote at 2021-12-01 16:24:25:

least common multiple. It's also what popped into my head when I first saw the fizzbuzz problem.

I've only done 2019 and 2020, but found 2020 to be a lot easier. I got stuck for a day or two on one of the 2019 ones. The one point I was briefly stuck in 2020 was when I was using the wrong data structure. (I don't want to spoil anything.)

smcl wrote at 2021-12-01 16:45:08:

Yeah 2019 had a couple of mind-benders involving mazes - there are two Part 2s that I need to motivate myself to come back to because my fumbling that got me the respective Part 1 solution was useless for Part 2 (Day 18 and Day 20). Looking back at them they shouldn't be _too_ hard, I just think that at that moment I didn't have the time to spare and never felt like coming back to them. Maybe if I'm bored between Xmas and New Year :)

Buttons840 wrote at 2021-12-01 15:30:53:

Does every problem need to be solvable by everyone?

Project Euler used to say something along the lines of "not everyone can solve every problem, and that's OK". Looks like they've removed that statement though. I remember encountering it early in my career and realizing some problems I cannot solve, even though others can.

nouveaux wrote at 2021-12-01 17:32:46:

Project Euler was one of the first programming puzzle sites. I give credit to them for my interest in programming puzzles. However, I quickly abandoned them once I found other sites that was less math focused.

For my personal goals, I want to get better at programming and not at math. When I find myself spending more time on the math rather than programming, I just skip the problem. I suspect many people abandon Project Euler for the same reasons I encountered.

With all that said, I agree that not everyone can solve every problem and that is ok.

jweather wrote at 2021-12-01 19:14:36:

What other sites do you recommend with less math-focused problems?

Jtsummers wrote at 2021-12-01 19:27:23:

https://www.spoj.com

When I was in college we used this (or an earlier version, that's a different URL than what I recall) in preparation for ACM programming competitions.

nouveaux wrote at 2021-12-02 15:17:59:

Just the popular ones now but 10 years ago, they were really novel. Leetcode, Hacker Rank and of course, the best one is Advent of Code.

https://adventofcode.com/

vbezhenar wrote at 2021-12-01 15:39:32:

It's pretty daunting when you're invested into something, spent a plenty hours only to realize that you're not in those 5% who's going to complete this challenge.

IMO AoC should strife to be completable by 80% of programmers (number is out of thin air, but you got the idea).

Project Euler is a different beast.

Of course that's just my opinion.

overboard2 wrote at 2021-12-01 16:25:56:

I for one want that 5% to have interesting challenges, even if I can't be a part of that 5%. Unique achievements should be meaningful and celebrated, not removed for fear of upsetting the majority who cannot achieve them.

progbits wrote at 2021-12-01 16:18:53:

While I agree with the sentiment of creating accessible content I think if you make the problems so easy 80% can solve them, what fraction will have fun doing so? Wouldn't say 50% find them trivial and boring/unsatisfying?

I think AoC goes for slowly growing difficulty which helps keep more skilled people engaged.

auxym wrote at 2021-12-01 15:51:23:

For what it's worth, I'm not a (professionnal) programmer, and I can usually solve 80% of the AoC problems intuitively. That's OK for me.

For the other 20% where I don't even know where to start, I look up a solution on reddit, try to understand it and re-implement it myself, and learn something new. The 2020 day 13 problem mentioned by GP was indeed one of those for me last year.

ollien wrote at 2021-12-01 16:22:34:

Honestly, I didn't even understand how the CRT applied even after knowing it was required. This visualization[1] is what eventually helped me solve it.

[1]:

https://www.reddit.com/r/adventofcode/comments/kcl7d2/2020_d...

NikolaeVarius wrote at 2021-12-01 22:53:26:

Why is there a lack of "git gud" in some of these programming circles.

Its meant to be hard and meant to force you to learn.

Epitom3 wrote at 2021-12-01 18:43:23:

> IMO AoC should strife to be completable by 80% of programmers

What would be the point then, it will be just another leetcode

sdevonoes wrote at 2021-12-01 16:31:48:

What's the main difference (besides submitting an answer faster than anyone else) between Project Euler and AoC? I find both rather similar (and I can do Project Euler any time of the year)

Jtsummers wrote at 2021-12-01 16:36:47:

Project Euler problems seem to be all math based, at least as far as I've seen. Advent of Code problems have numbers as results (most of the time), but aren't always based on some mathematical formulation(s).

See 2019's IntCode puzzles for instance for something very far from Project Euler. They also had the side-effect of benefiting anyone who spent time refactoring their initial versions to create a better interface, a later day (23?) has you run 50 IntCode computers concurrently and communicating with each other. This became very hard to actually implement for many people because of the structure of their simulator and how they'd handled concurrent simulations earlier.

hu3 wrote at 2021-12-01 15:29:29:

I had the same feeling about

https://projecteuler.net/

but PE is very clear about being math focused so that's on me.

I wish Advent of Code puzzles were strictly algorithm focused without relying on specifics of mathematics. Skipping puzzles is demotivating for the completionist in me that lacks time to re-read math books.

Buttons840 wrote at 2021-12-01 15:35:35:

We should avoid certain questions because they're demotivating to some people?

Perhaps a compromise would be to start with an easy input that any pile of if statements can handle, then give a longer input that will break all but the best algorithms as a bonus.

bussierem wrote at 2021-12-01 15:40:08:

I think it's more that the puzzles should avoid having a "correct solution" in the form of a known algorithm. If the puzzle can basically only be solved by remembering a specific algorithm, and any other algorithm (or attempt) will grind for hours, then the puzzle isn't about algorithms, or about coding, it's about whether or not you memorized a part of a math textbook and can recognize that it applies to the problem.

Granted, I don't know the process of AoC in terms of vetting and building their puzzles, but it seems that the person/people involved all share very similar levels and domain of knowledge. Having more people reviewing or involved in the process that have a wider range of skillsets might avoid these situations.

Example from what I was talking about before: Day 13 of AoC2020 was basically "the answer is the Chinese Remainder Theorem". If you remembered that...great you could solve this in 10 seconds (hell some languages have a _function_ for that theorem!). If not....well good luck finding a solution that runs in under 6h. That has nothing to do with _programming_. Its just math, there wasn't even programming involved (literally some solutions were just "parse the input and pass it to mathlib.chinese_remainder()"). That's not satisfying to solve for the majority of people, I feel (opinion, I know).

Joker_vD wrote at 2021-12-01 17:18:30:

Is this CRT? Not exactly sure, but it does not run for six hours:

        result = 0
    addend = 1

    for divisor, desired_offset in [(7, 0), (13, 1), (59, 4), (31, 6), (19, 7)]:
        # keep trying numbers until we find the one that, with
        # the desired offset added to it, would divide without
        # remainder
        while (result + desired_offset) % divisor != 0:
            result += addend

        # adding another addend should not break previous results
        # so make it divisible by all previous divisors
        addend *= divisor

    result %= 7*13*59*31*19  # Is it really needed? Eh.
    print(result)

bussierem wrote at 2021-12-01 15:35:36:

This is exactly my thoughts on it. Granted I was never strong in math, and that's partly on me, but the early days (and even most mid days) of AoC are usually all about algorithms design and efficiency, but then sometimes you get these random "pick the right math formula" ones and just like you said, I have to "skip" them and it's so demotivating.

jstx1 wrote at 2021-12-01 15:21:55:

I see it as on opportunity to expose yourself to a bunch of things in mathematics and computer science. Also, I'm pretty sure that you could get to the solution you're referring to without knowing any number theory at all.

smcl wrote at 2021-12-01 15:56:07:

I was the same as you for a few minutes - I was demotivated and when I found out what was behind it I thought "huh I never learned this and I'm not sure how I _would have_ ever learned this" and felt a little bit defeated. But then I read a little bit on the subreddit, read the wiki on CRT, put together a solution and moved on. It's meant to be a bit of fun, if you have to skip one challenge (or cut a couple corners) it's no big deal - you can always come back to it later :)

It can be demotivating if you check the number of people who solved it quicker you, but just pretend they all cheated off one really really smart person and you'll feel much better :D

Strilanc wrote at 2021-12-01 15:58:31:

It actually was on day 19, it's just that puzzle #13 was the 19th puzzle given out [1]. I'm not sure why the numbers didn't come in order last year.

[1]:

https://adventofcode.com/2020

shows the number order

mercurywells wrote at 2021-12-01 16:28:47:

If you look at the 'map' on the left side and also follow the plot in the puzzle descriptions, you can see that you were island hopping, so top to bottom is not the order the puzzles came out in.

Strilanc wrote at 2021-12-01 19:42:57:

Oh yeah, that's right.

tyingq wrote at 2021-12-01 15:23:17:

Link to last year's Day 19:

https://adventofcode.com/2020/day/19

I didn't read it in depth, but it feels like you could build regexes on the fly to solve it. Perhaps I missed something crucial.

Edit: Ahh, day 13:

https://adventofcode.com/2020/day/13

Jtsummers wrote at 2021-12-01 15:32:26:

Part 2 complicated it, but yes. I just built regexes on the fly for Part 1. I wonder if they mean Day 13. The underlying math is based on the Chinese Remainder Theorem, but it is solvable without knowing it (or, in my case, "knowing" it, once I saw others mention it it came back but my math degree was a long time ago). A solution could be discovered incrementally without knowing the math by trying to optimize the naive version.

bussierem wrote at 2021-12-01 15:41:34:

I did mean Day 13, thank you -- I updated my post accordingly. Sorry about the confusion!

CastFX wrote at 2021-12-01 19:08:46:

I loved day 19 because I managed to use some Automata theory I studied at uni. Something like, I cannot simply use a regex because it's a context-free grammar. Then I learned about recursive regexes and how they could be used to parse a cfg. Aaah fascinating, really.

bussierem wrote at 2021-12-01 15:34:05:

Apologies, I updated my post. It was Day 13 where this happened. Not sure why I stopped at Day 19, tbh.

ZiiS wrote at 2021-12-01 15:42:06:

Day 13 you really needed to know of Chinese remainder theorem; I would say this was probably the only day in the last couple of years so dependent on non-trivial maths. I would still recommend AoC though.

justinsaccount wrote at 2021-12-01 15:34:31:

yep, that's what I did. simply converted the input into a regex and matched it. part 2 had to add a little special casing but ultimately not that difficult.

matsemann wrote at 2021-12-01 16:19:48:

I often find that part1 can be solved by most, but part2 sometimes needs a clever trick, experience or some knowledge. Doing only part1 or skipping some day is perfectly fine, though. So I don't really get your anger.

I actually like when it teaches me something new. If you get stuck you could always google for the concepts you need and learn of them, or go to the subreddit and get hints but still solve the programming part yourself.

LandR wrote at 2021-12-01 15:49:10:

I solved day 13, both parts, and I'm pretty far from an algorithm wiz, I also never used Chinese Remainder Theorem.

Part 1 runs in ~0.5 msecs

Part 2 runs in ~2 msecs

lostdog wrote at 2021-12-01 18:32:25:

Last year I figured it out from first principles, like some of the other commenters, but that problem was one of the hardest for me (like the tile rotating problem, which was excellent).

This year, my rule is that if it looks like the Chinese remainder theorem, then I can just look it up. There's no need to stay stuck on something that's supposed to be fun.

Peritract wrote at 2021-12-03 14:06:35:

I like AoC because it is the least 'know the specific maths trick' of the various coding challenges out there; there are normally a couple of problems like that each year, but most can be worked out if you can think even if you don't have a huge body of maths knowledge.

TYMorningCoffee wrote at 2021-12-01 15:42:09:

For Day 13, I played around with the numbers and eventually noticed that you could increment by the product of the numbers you consumed so far.

petercooper wrote at 2021-12-01 15:18:15:

At the time, I had the same thought process as you. I did eventually come back and do the rest of the days though which were surprisingly trivial in comparison! I seem to recall some people _did_ manage to solve that day using brute force with a non modular approach though.

bussierem wrote at 2021-12-01 15:22:18:

I'm quite surprised, I spent hours on multiple different solution and every single one was brutally slow.

petercooper wrote at 2021-12-01 15:40:05:

My memory is hazy, but I seem to recall it involved a lot of parallelization and running it for a couple of days on high end gear along with luck. So definitely not the intended approach! :)

Joker_vD wrote at 2021-12-01 15:51:21:

Excuse me, what? You don't need to know CRT or indeed anything about the number theory except that you can divide numbers, the solution is simply:

  for each ID in list:
        next_departure = round_up_to_next_integer(earliest_time / ID) * ID
        delay[ID] = next_departure - earliest_time
    nearest_bus = ID with lowest delay
    return nearest_bus * delay[nearest_bus]

That's it. I can think of only two other algorithms: the one that replaces division on the second line by repeated subtraction, and the one that uses repeated increments and checking whether the result is divided by the ID without a remainder.

How do you even use CRT to solve this?

Jtsummers wrote at 2021-12-01 16:07:02:

Are you looking at part 1 or part 2? GP is talking about part 2.

Joker_vD wrote at 2021-12-01 17:12:25:

Can't find part 2 on the site, had to google...

      result = 0
    addend = 1
    for divisor, desired_offset in [(7, 0), (13, 1), (59, 4), (31, 6), (19, 7)]:
        # keep trying numbers until we find the one that, with
        # the desired offset added to it, would divide without
        # remainder
        while (result + desired_offset) % divisor != 0:
            result += addend

        # adding another addend should not break previous results
        # so make it divisible by all previous divisors
        addend *= divisor
    print(result % (7*13*59*31*19))

This algorithm self-evidently works and is indeed "fast enough" if done by the computer.

Jtsummers wrote at 2021-12-01 17:28:34:

The key insight that many people, particularly those without the stronger math background, miss is that you can increase the addend like you (and I, in my solution) have done. So they either leave it at 1 (and the solution is around 1-2 trillion, IIRC, so that's not happening quickly) or they do _one_ optimization which is to set it to the first divisor (7 in your example, which still leaves you with hundreds of billions of loop executions), but don't adjust it with each newly matched bus line.

And instead of talking down to people, it can be more productive if you walk through a solution instead of stating "This algorithm self-evidently works" like a jerk.

Also, the last modulo isn't needed.

Joker_vD wrote at 2021-12-01 17:52:44:

> walk through a solution instead of stating "This algorithm self-evidently works" like a jerk.

After every iteration, "result" gives correct remainders for all divisors considered so far, so if the loop ends, the "result" will give correct remainders for all divisors. The only problem is whether it will end or not, and that I just tried experimentally: it stopped, so ok. Not really sure how to explain it further.

> Also, the last modulo isn't needed.

Good to know, I was not sure if I wouldn't step past it due to constantly increasing addend. I knew about this modular reduction from that one time when I needed to align/move/scroll things on a 80x25 grid.

karmanyaahm wrote at 2021-12-01 17:54:53:

fwiw the Chinese Remainder Theorem is taught in basic cryptography courses. ig it could be obscure for someone outside the field though

_pmf_ wrote at 2021-12-01 15:47:41:

> Not sure if this is indicative of other years

It is.

estomagordo wrote at 2021-12-01 15:28:47:

I'm sorry you were coerced into thinking :(

Xavdidtheshadow wrote at 2021-12-01 21:49:13:

AoC is one of my favorite events of the year. I find the puzzles to be much more approachable than things like Project Euler. I regularly credit my yearly participation for making me a better programmer.

I also do a daily writeup of my solution, which helps make sure I understand the problem and help others who are learning. I found it super rewarding last year, so I'm doing it again this year. They're in my GH repo. Here's today's:

https://github.com/xavdid/advent-of-code/tree/main/solutions...

My big tip is that you probably don't need to worry about competing for the leaderboard (unless you really want to). Go at your own pace, don't stay up weird hours, and take a break.

nineplay wrote at 2021-12-01 16:36:00:

I love Advent of Code. As I sit here trying to prepare for my next set of 'leet' interviews, I wish employers could switch over to this style of tech questions. Advent of Code requires good coding and problem solving skills. Leet coding requires you to memorize every operation for dozens of data structures like how to insert elements in a min heap.

( Insert elements at the end and swap with the parent until the tree is correctly ordered again. Good luck figuring this out in 20 minutes if you don't know it ahead of time. )

( Now prepare yourself to remember how to insert/delete/search for elements in every other data structure with any number of different qualifiers when it's not going to be obvious at the outset of the question what kind of data structure to use )

( Oh and make sure you've memorized the time and space complexity )

( Not that I'm bitter or anything )

jhenkens wrote at 2021-12-01 17:12:55:

I'm there with you 100%. I just took a break after 6 years of consecutive employment. Apparently I did well at my job - remained an IC, but was given more recognition via titles and more and more cross-org design meetings. But now after 6 years of solving hard big scale problems, I've got to come back to how to interview for companies again. Incredible waste of time spending days studying leetcode, interviewing for companies I'd likely not work for just to practice skills I haven't needed in 6 years.

pedrosorio wrote at 2021-12-01 22:47:54:

> Leet coding requires you to memorize every operation for dozens of data structures like how to insert elements in a min heap.

I’ve done dozens of leetcode contests (4 problems every Saturday) and never had to use knowledge of the implementation of a min-heap (though I did “import heapq” a few times) to solve any of the problems.

Are you using “leet coding” to refer to technical interviews that simply ask you to implement textbook data structures (somewhat boring imo), as opposed to solving leetcode problems?

nineplay wrote at 2021-12-01 23:05:10:

You are right, I'm referring to leet code as something every job hunter needs to solve if all the books, websites, and online courses are to be believed. min-heaps usually show up on the List Of Data Structures To Understand.

Probably no one ever asks about them but it's a crapshoot.

kristaps wrote at 2021-12-01 16:52:44:

My current company actually did just that - I got to solve two AoC2020 puzzles for my code sample.

nouveaux wrote at 2021-12-01 17:36:34:

Do you mind sharing what company did this? Seems like a great place to work?

weatherlight wrote at 2021-12-02 04:18:29:

ooo what day where the puzzles from?

paxys wrote at 2021-12-01 15:22:46:

Advent of Code has become an annual tradition for me. I do wish that they would update their scoring in some way to prioritize something other than how quickly you can write up the solution every day at midnight when the question is released.

volfied wrote at 2021-12-01 16:13:30:

I wish private leaderboards allowed for people to "start" solving when they send the first request to the problem page. I know it can be abused, but if it's just for private leaderboards, it will level the time zone problems.

makapuf wrote at 2021-12-01 21:35:06:

Problem is, you can have two accounts, get you algorithm on the first and flash through the second.

volfied wrote at 2021-12-02 01:48:03:

Should at least be an option for private leader boards then. I run the one for my company, and I want people of all time zones to comfortably compete

jugg1es wrote at 2021-12-01 16:44:28:

This is a great idea. Maybe submit it as a suggestion.

Jtsummers wrote at 2021-12-01 16:55:14:

It's been brought up in the subreddit over the past few years and always rejected.

estomagordo wrote at 2021-12-01 15:30:45:

Any ideas? The only thing I can think of is time after you saw the problem, which would work with an honor system on a social/friendly leaderboard.

paxys wrote at 2021-12-01 16:23:29:

I don't know the technical solution for this, but there can be some judgement on the quality of the solution (like how efficient it is in terms of time and space).

Here's an example – in part 2 of day 1 of this year (2021), there's no need to actually add up the 3 measurement range, since the middle 2 values will always cancel out. You simply need to loop through the array compare index i with i+3. Maybe there should be an extra point for people who figured this out?

Another problem is that the input set is always small enough to make a brute force solution the most favorable one. So what they are really judging is the speed at which someone can read/parse the input file and write some loops.

Strilanc wrote at 2021-12-01 19:59:59:

One of the genius things about advent of code is that the server never needs to touch unknown, potentially malicious, code. The server just compares the claimed answer to the stored answer.

Maybe one way it could do the performance testing is: 24 hours after the puzzle is announced, a "speed test input" becomes available. The speed test input would be substantially larger than normal inputs. Because people have had time to write the code, all they have to do is dump the input into the code and put the output into the box the fastest. A notable bottleneck is that every problem does have to be solved by the server ahead of time, and if it starts taking ten minutes to solve each instance then that's expensive unless you use very small pools of inputs.

Jtsummers wrote at 2021-12-01 20:15:43:

> Another problem is that the input set is always small enough to make a brute force solution the most favorable one. So what they are really judging is the speed at which someone can read/parse the input file and write some loops.

That's only true for, well, ok maybe 1/2-2/3rds of the days. The rest require something more complicated, either with more complicated algorithms or more clever algorithms to get performance to a reasonable level. See the other discussion here about 2020 Day 13. The naive solution worked on the samples, but would not have worked on the actual input.

matsemann wrote at 2021-12-01 17:49:36:

Sounds like

https://open.kattis.com/

would be right up your alley.

the-smug-one wrote at 2021-12-01 19:49:17:

Fun fact: Kattis is how a lot of homework is distributed at KTH, seeing it being mentioned always brings up some nice memories :).

OwlsParlay wrote at 2021-12-01 15:37:43:

The only thing I can think of is if they teamed up with LeetCode to allow people to use the built-in compiler to solve the problems.

Obviously for the folks who use <ObscureLanguageX> this wouldn't work but it would be a nice collaboration otherwise.

Mountain_Skies wrote at 2021-12-01 15:59:15:

If you enjoy Advent of Code, be sure to check out their sponsors. Not only because their support helps make AoC possible but also because they often have their own coding challenges that can be a fun compliment to AoC itself.

Barrin92 wrote at 2021-12-01 20:05:07:

Eric Wastl who makes Advent of Code also made the Synacor Challenge (

https://challenge.synacor.com/

) a bunch of years ago which is similar to the Intcode AOC problems and a lot of fun.

qiqitori wrote at 2021-12-02 02:31:29:

I don't follow AoC but I think Eric Wastl is awesome because he used to transcribe anime music (or someone with the same name). (E.g., search for 'eric wastl haibane renmei')

Mountain_Skies wrote at 2021-12-01 21:18:36:

Nice, now I'll have something to do in January while going through AoC withdraw.

w-m wrote at 2021-12-01 20:14:38:

Anybody interested in getting a just-for-fun HN user leaderboard going? Here's my code: 194284-90c48b41

In the last couple years I usually stopped up after a few days when I didn't find the time to do one of the puzzles or got stuck with the Rust borow checker. Maybe having a leaderboard helps with the motivation to keep on going! :)

gmfawcett wrote at 2021-12-02 01:05:34:

Thanks for the open invite. I probably won't finish until February or so, but I'll cheer you on in the meantime!

akpa1 wrote at 2021-12-02 18:31:55:

Thanks for the invite, looking forwards to playing!

Personally, joining leaderboards like this certainly help with motivation, though I couldn't say why.

Cyphase wrote at 2021-12-01 22:14:34:

Having a fun group to do it with does. Come join us in #adventofcode on Libera.Chat! We also have an IRC leaderboard.

the_only_law wrote at 2021-12-01 15:50:31:

I was going to do something fun, but gimmicky and try to implement them all in like SPL/2100 on an emulator running RTE, but quickly found I'd end up spending the month learning the latter.

I've been trying to think I've something, else fun to do or maybe use a language I've been itching to try, like Ada, but I’m not sure any of the questions will be of a nature to let me utilize the strengths of that language and I fear it will all end up being really boring procedural algorithms. I can think of a ton of other gimmicky solutions, but none that are very fun.

tester34 wrote at 2021-12-01 14:28:40:

I wonder how popularity of "exotic" languages increases when AoC's around

F#, Lisp and so on

petercooper wrote at 2021-12-01 15:20:28:

APL is the language I only _ever_ see around AoC. But it's so impressive too. Like the first part of today's solution is "+/¯1↓x<1⊖x" (stolen from someone on Reddit) and I'm like.. ok, I need to learn this language one day.

(Since their solution is now being discussed, it's from here:

https://www.reddit.com/r/adventofcode/comments/r66vow/2021_d...

)

maximus-decimus wrote at 2021-12-04 14:18:15:

and this is the solution in Q, including paring the file: `(+/) 1_ (>':) "I" $ read0 `:input_1.txt`

I don't think their second solution actually works unless I'm missing something though : +/¯3↓x<3⊖x

This compares every element to the the one 3 positions before it, when the question was to take the sum of each 3 elements and check if it's smaller than the previous sum.

Jtsummers wrote at 2021-12-01 16:23:26:

Interesting solution.

    1⊖x

Rotates the sequence so the first becomes the last.

    x < 1⊖x

Element-wise compare each, resulting in a list of 1s and 0s

    ¯1 ↓ x<1⊖x

Drop the last element because it's actually not part of the solution (thanks to the earlier rotation).

    +/ ¯1↓x<1⊖x

Sum all of them, since it's just 1s and 0s this gives a correct count. Part 2 is solvable (unless I missed something, works on the sample data) by just changing two characters from that solution. Neat.

petercooper wrote at 2021-12-01 17:15:11:

Thanks for the explanation! I just found someone with a different approach who has similarly broken it down on Twitter:

https://twitter.com/janiczek/status/1465969017089363969

Jtsummers wrote at 2021-12-01 17:18:06:

https://tryapl.org

That's an online APL REPL with all the symbols listed at the top, hover to get a tooltip that tells you both how to type it into the REPL and what its name is. I'd forgotten what rotate was because my APL deep-dive was 2 or 3 years ago now. It's handy for discovering the symbols and breaking down the harder-to-understand one-liners (for novices or those unfamiliar with it).

ollran wrote at 2021-12-01 16:55:08:

APL is quite common in the code golf scene.

mcjiggerlog wrote at 2021-12-01 14:55:23:

It seems like 80% of people I've heard talking about AoC are planning on doing it in Rust (including me!). It's definitely a great way to get up to speed with a language you're interested in learning.

ducharmdev wrote at 2021-12-01 15:29:45:

Yup, I'm doing Rust this year as well. I've worked through rustlings a couple times in the past, but haven't had many excuses to use Rust.

I was proud last year when I got to day 18 with Python, but I'm setting the bar much lower this year. I don't have any experience with C/C++ (just C# and a bit of Go), so thinking more carefully about memory mgmt is new to me. But the functional aspects of Rust are pretty exciting.

jstx1 wrote at 2021-12-01 14:58:05:

In last year's survey Rust was around 10%. It's definitely overrepresented but not quite that much.

aunderscored wrote at 2021-12-01 15:11:35:

I definitely enjoyed doing rust. I'm planning on doing go, rust, and python. We'll see how well that holds up

jstx1 wrote at 2021-12-01 14:56:09:

There's definitely a selection effect - the type of person that will spend time on Advent of Code is also likely to be the type of person that learns and uses more exotic languages, or at least languages that aren't used that much commercially.

Some stats to confirm -

https://preview.redd.it/jrhlcxrzy0761.png?width=2275&format=...

- taken from from last years' unofficial survey -

https://www.reddit.com/r/adventofcode/comments/kj53l1/unoffi...

asicsp wrote at 2021-12-01 14:55:44:

Some create a language just for AoC, for example:

https://github.com/healeycodes/adventlang

mnw21cam wrote at 2021-12-01 15:39:28:

That'd be interesting given that 2019 was already _about_ a created language.

riffraff wrote at 2021-12-01 19:11:32:

One of the solutions I saw today was in Intcode (the language from 2019), it was pretty incredible.

mikewarot wrote at 2021-12-01 15:15:30:

I'll balance that out for you, I do my programming in Pascal. I'm going through the old ones as well, hoping to back-fill in answers to all of them.

https://github.com/mikewarot/Advent_of_Code_in_Pascal

overkalix wrote at 2021-12-01 14:40:42:

Not particularly exotic, but the last two years I pushed myself to do them in elixir (although my solutions become progressively shoddy until I quit, usually around day 10-12). Then I promptly forget everything I've learnt because I can't introduce the language in my work.

phillipcarter wrote at 2021-12-01 19:30:05:

I'm using it as an opportunity to try out Crystal. I have zero Ruby experience, so it's a fun experience coming in from a "no, actually, none of this is familiar to me" perspective. Nice language.

runevault wrote at 2021-12-01 15:48:07:

I've been getting back into f# lately and going to use it for AoC to give me real challenges to work on instead of arbitrary ideas, so it is certainly helping one of the mentioned for me.

riffraff wrote at 2021-12-01 19:13:53:

There's always some cool stuff done with Raku, I'm giving it a chance this year as my "second language", we'll see how it goes.

Jenz wrote at 2021-12-01 14:30:38:

Lisp is exotic?

Scarbutt wrote at 2021-12-01 14:45:13:

Esoteric is the word I would use.

carnitine wrote at 2021-12-01 15:04:46:

Seriously? Lisp of all languages? Also esoteric is already applied to languages like Brainfuck which are designed to be as abstruse as possible.

Scarbutt wrote at 2021-12-01 16:02:22:

Yes, Lisp and F# are esoteric programming languages in the industry.

mrtranscendence wrote at 2021-12-01 16:19:37:

I've only seen "esoteric" refer to programming languages that are deliberately constructed to be obscure or unusual, usually in ways that make them unusable in some practical sense. Your Brainfucks or Malbolges, say. I've never heard of anyone applying that term to Lisp or especially F#. They might be unpopular, but they're usable, practical languages with good implementations.

ByteJockey wrote at 2021-12-01 17:25:38:

A lot of people consider anything not in the tiobe top 10 to be esoteric (especially for the purposes of enterprise work).

Maybe obscure is a better word here?

mrtranscendence wrote at 2021-12-01 18:04:42:

Obscure is a good choice. I’d probably use niche. Honestly, esoteric _could_ be a good word to describe lisp, except for the fact that it seems to already exist as a term for a category that wouldn’t include lisp.

ByteJockey wrote at 2021-12-01 20:40:26:

Niche is fair. Basically, I'm trying to describe "not mainstream".

bcrosby95 wrote at 2021-12-01 20:49:08:

By this metric, Ruby, Swift, Go, Rust, Kotlin, and Typescript are all obscure. Some of these are even more obscure than Lisp.

ByteJockey wrote at 2021-12-02 13:16:23:

Correct. I know plenty of enterprises that do not touch any of those, mostly because of their fear of not being able to find devs familiar with those languages.

As discussed elsewhere, it's possible niche might be a better term to describe what I'm talking about here than obscure.

aarchi wrote at 2021-12-01 18:57:01:

I'm solving Advent of Code in Whitespace, a quintessential esolang.

https://github.com/andrewarchi/ws-challenges

jarpschop wrote at 2021-12-01 14:34:25:

Why would Alexandria Ocasio-Cortez' presence increase the popularity of some programming language?

speg wrote at 2021-12-01 14:37:29:

Advent of Code.

BiteCode_dev wrote at 2021-12-01 14:40:06:

That sounded like a joke :)

gerikson wrote at 2021-12-01 14:44:36:

The price of humor on HN is eternal downvotes.

Nicksil wrote at 2021-12-01 15:22:58:

>The price of humor on HN is eternal downvotes.

Not if its funny.

Toutouxc wrote at 2021-12-01 16:46:42:

It's important to understand that for every person familiar with the name and the abbreviation there are roughly 22 people who have no idea who she is.

whalesalad wrote at 2021-12-01 19:58:00:

I wish I could take a month off from my client obligations to jam on stuff like this. I always get started - make it a few rounds - and then get crushed by the pressure of everything else. These sorts of games are so fun with TDD. Red. Red. Red. Red. .... Green!

Anyone here currently on any kind of sabbatical to just decompress and learn new stuff?

joshgrib wrote at 2021-12-01 20:13:23:

Seconding this as a great time to use/try TDD! Every problem comes with a small sample input and output, so you get a test case for free

zora_goron wrote at 2021-12-01 14:56:02:

Related thread from last week:

https://news.ycombinator.com/item?id=29292818

timvisee wrote at 2021-12-01 15:25:57:

Last year I solved all puzzles in less than 1 second. This year, for lack of a better goal, I'll be trying to do the same:

https://github.com/timvisee/advent-of-code-2021

estomagordo wrote at 2021-12-01 15:29:33:

Man, it takes me longer to even read a problem statement!

auxym wrote at 2021-12-01 15:54:35:

I think they mean 1 second of program execution time :)

gray_-_wolf wrote at 2021-12-01 19:41:19:

To be honest I'm amazed by the times. Mine (reasonably written C) is 4ms, so 0.025ms is quite amazing. Any idea what magic does rust do inside to achieve this speed?

Toutouxc wrote at 2021-12-01 16:27:36:

I thought you were trolling at first. :)

ta988 wrote at 2021-12-01 15:32:43:

Try 500ms and divide by two every year

taftster wrote at 2021-12-01 17:21:37:

Moore's law and all that.

briffle wrote at 2021-12-01 15:31:12:

Looks like the Sysadvent has started again today, after taking last year off.

Its great for those of us on the more OPS side of DEVOPS:

https://sysadvent.blogspot.com/

shever73 wrote at 2021-12-01 15:58:42:

It's great to have AoC back again. Last year was my best yet, where I managed to get up to day 23. This year, I'm focusing on keeping the solution to as few lines of code as possible.

vidro3 wrote at 2021-12-01 15:06:35:

this always sounds appealing but i really don't find these types of problems fun to do, mostly frustrating.

penjelly wrote at 2021-12-01 17:34:19:

dont those statements contradict eachother? it sounds appealing how? cause its a challenge exercise? But challenges are frustrating?

anandoza wrote at 2021-12-01 18:36:17:

You don't understand how something can sound appealing at first, but then in practice isn't enjoyable?

penjelly wrote at 2021-12-01 18:49:35:

"always sounds appealing" implies the same thing happens every year to parent comment. either you dont enjoy it or you do? its not like the type of exercises change year to year. theyre coding challenges everytime.

vidro3 wrote at 2021-12-01 19:16:59:

yes, i get tricked every year. at first it's 'ooh some neat challenges to help me improve or learn new skills'

then it's like, 'ugh this is annoying and i don't like it.'

sdevonoes wrote at 2021-12-01 16:30:05:

Only reason I don't do Advent of Code is because you have to wake up at 5-6am in Europe. I barely can make me a coffee at that time.

jstx1 wrote at 2021-12-01 16:43:28:

The global leaderboard really isn't the point for most of the people who do AoC. You can always do the puzzles later in the day.

Jtsummers wrote at 2021-12-01 16:39:50:

You don't _have_ to wake up early, only if you want to be part of the 100 first solvers. I gave up on that after my first year, if I can't solve it at night (10pm my time now, used to be midnight) in less than an hour, I punt to the next afternoon.

ZoomZoomZoom wrote at 2021-12-02 13:56:15:

Some need to wake up early just to complete a task before the next one appears.

boutell wrote at 2021-12-01 16:00:50:

Tackling it in TypeScript this year, which is interesting because I haven't used TypeScript before (I'm experienced with JavaScript). This is a good way to really drill it into my fingertips.

If you care to follow along:

https://github.com/boutell/advent-of-code-2021

kryptiskt wrote at 2021-12-01 17:11:56:

I'm also doing it in Typescript this year, but I'm doing it in the browser to get a little modern web experience (I'm a C++ developer by day). I have a pretty nifty setup with Snowpack that will rebuild it and refresh the browser automatically when I save, and a little scaffolding for making a widget for a problem, I don't use a framework:

https://github.com/melted/aoc2021

.

volfied wrote at 2021-12-01 16:12:09:

I recommend using a runner like

https://github.com/caderek/aocrunner

, so you can focus on coding, rather than project set up.

penjelly wrote at 2021-12-01 17:33:09:

tsc file.ts && node file.js

is pretty simple but yeah.. i guess as the scope increases it may require a dist folder or scripts

edit: wow nevermind im seeing a sibling comment here is using the browser and it looks like a major headache..

Cyphase wrote at 2021-12-01 18:06:45:

Anyone who's interested is welcome to join the group in #adventofcode on Libera.Chat. We hang out there and in the spoilers channel, especially around and for some hours after the release time each day. Lots of interesting discussion goes on. A lot of people aim for the leaderboard (which is certainly not required), then afterwards discuss solutions, optimizations, rewrites, edge cases, and more. We also have an IRC leaderboard (the AoC site has a private leaderboard feature). It's all good fun!

Disclosure, just in case: I'm one of the ops in the channel.

sireat wrote at 2021-12-01 21:46:13:

Decided to try Golang this year.

Compared to Python and Scala it is way more verbose for simple challenges as this.

I almost feel like I am back in the early 1990s of writing C.

I miss zip, sum, map and list comprehensions...

WoodenChair wrote at 2021-12-02 04:38:08:

Go has first-class functions and now has generics. So, you can definitely implement zip, sum, map, filter, reduce, etc. The fact that they're not included in the standard library I think has more to do with the opinionated creators of the language than any limitation[0]. You can absolutely implement them yourself (and a couple of these are pretty trivial to implement) in a library as an aid. I've done that in the past. I miss them too.

In fact at the link below you'll see one of the creators explicitly say they're easy to implement (and his own implementation pre-generics) but he doesn't think you should use them (Rob Pike). "Having written it a couple of years ago, I haven't had occasion to use it once. Instead, I just use "for" loops.

You shouldn't use it either."

0:

https://github.com/robpike/filter

Jtsummers wrote at 2021-12-02 04:47:17:

Looking at it, I wouldn't want to use it either. It seems to add a lot of overhead. In the first 15 lines of the function it's mostly implementing type checking at runtime using reflection. Every single time this is used it would redo that type checking. In most statically typed functional languages that would just be done once at compile time and the implementation would be the equivalent of the last 7 lines or so.

I imagine with generics it could be greatly simplified, but I don't know Go well enough to venture how it would be done. Though if it weren't faster than that version I'd be shocked.

For clarity, I was looking at reduce.go, all the others seem to do similar tricks with reflection that would also add overhead that generics should eliminate.

WoodenChair wrote at 2021-12-02 05:10:55:

Right, using generics all of the reflection should be unnecessary and the implementation should be much simpler and more performant.

orange_puff wrote at 2021-12-01 18:13:03:

This is my first year participating. I've solved about 20-30 questions from previous years and really loved them. I tried to compete last night for top 100 and was 7 seconds off (rank 123). I shouldn't have tested my code for the first problem because it was too trivial!!

But, that gets the competitive aspect of this challenge out of the way immediately so I can simply have fun with these problems :)

I am excited for them to become a bit more challenging because my friend and I are going to work on them together.

clircle wrote at 2021-12-01 18:20:33:

I'm using Advent of Code this year to learn Common Lisp. I started doing the 2015 exercises a few days ago, and I'm having the _most_ fun you can have with a computer.

surfer7837 wrote at 2021-12-01 20:56:19:

Am doing it in Haskell. Every year I do it in Haskell, and then promptly forget half the language until I start it in December again

djhworld wrote at 2021-12-01 21:40:23:

Enjoy doing these when I can, although probably takes me 6 months to complete the puzzles, doing them here and there.

Not really into the competitive aspect, although I guess it doesn't matter that much anyway.

There was on AoC a few years ago that got you to build a toy computer, to the point where you were running simple games on it. That was mind blowingly fun!

kemiller wrote at 2021-12-01 18:56:46:

I love these puzzles, and I'm grateful they only let you do two per day or I'd never get any work done.

YoungWeb wrote at 2021-12-01 20:22:09:

This is my first time encountering this and I like it. I am looking forward to completing these this month.

WesleyJohnson wrote at 2021-12-01 15:37:47:

This is the first year I'm going to participate. Not really interested in competing with anyone else, just against my own imposter syndrome. Based on the responses regarding the obscure algorithms you may need, I'm no longer confident I'll win against him either.

Toutouxc wrote at 2021-12-01 17:36:43:

Look at this this way: other solid, good, honest programmers (just like you) on HN and reddit agree that some AoC puzzles require obscure algorithms, and they also get stuck on those.

exdsq wrote at 2021-12-01 19:50:30:

Rust this year! We should have a daily HN post to share our solutions for open code reviews :)

Jtsummers wrote at 2021-12-01 20:19:59:

They have a daily mega thread for solutions over on Reddit:

https://www.reddit.com/r/adventofcode/

https://www.reddit.com/r/adventofcode/comments/r66vow/2021_d...

It's interesting to see the various solutions, especially when you realize, "Oh, duh, I did more work than necessary." and can go back and improve your own with the new knowledge.

exdsq wrote at 2021-12-02 01:25:04:

My Rust implementation was horrible! First time I'd written Rust. It's fun to see peoples far better Rust solutions or, amazingly, the most recent solution that was in Powershell!

Jtsummers wrote at 2021-12-02 01:28:23:

Mine was delightfully mediocre. No actual blunders, but several missteps that I removed later (like calling _enumerate_ and then in the next step using _map_ to remove the index...). I've written some Rust in the past but it's been long enough I only remember the basic language syntax, not the libraries.

jodrellblank wrote at 2021-12-02 19:00:26:

Rust looks like a very popular choice this year:

https://aocweb.yulrizka.com/?year=2021&day=1&language=Rust

floitsch wrote at 2021-12-01 17:30:00:

Perfect time to explore Toit (

http://github.com/toitlang/toit

) :)

nnoitra wrote at 2021-12-02 03:59:58:

Copilot came up with? Nah, it really did not. Some poor soul on GitHub did though and wrote good documentation for it. God bless them.

MYEUHD wrote at 2021-12-01 20:39:27:

Is it considered cheating if I use another program (such as wc) to know the number of lines in the input file?

saagarjha wrote at 2021-12-04 11:22:22:

When I download my input data I have it print out the number of lines in the process. I find this to be quite helpful, in general.

Cyphase wrote at 2021-12-01 22:03:40:

People have solved puzzles by hand in the past. No tool is off limit, including your brain, pen, and paper.

I would say the only thing that's "cheating" would be looking up solutions to "solve" the problem faster than other people, whether they be the rest of the world on the global leaderboard (which is unlikely since the people who make the leaderboard are good about not posting solutions until it's full) or some friends you're competing with on a private leaderboard.

Otherwise, let your conscience be your guide. As the saying goes, when you cheat, you're only cheating yourself.

Mountain_Skies wrote at 2021-12-01 21:21:34:

That's for you to decide but the point of the exercise, besides having fun, is finding a solution. If wc is something you'd use to solve a similar problem, seems reasonable to use it here too and within the spirit of the challenge.

kryptn wrote at 2021-12-01 23:42:16:

Nah, not in my opinion. Use whatever you want to solve the problems. Ultimately you have to submit an answer to the site for the day.

Even then, if you go and look up solutions it's still up to you whether or not you call that cheating.

ninju wrote at 2021-12-01 21:39:12:

Any software tools are acceptable. I used Excel to solve 2021 day 1

nnoitra wrote at 2021-12-02 04:01:16:

What is this Advent Of Code for?

macintux wrote at 2021-12-02 04:05:55:

https://adventofcode.com/2021/about

In short, it's a creative set of challenges released once/day for 25 days during December. It's also a creative community of people solving the problems (sometimes programming, sometimes with other tools, even just pencil & paper) and more than that creating visualizations and new programming languages, learning new programming languages...

It's just a fun ride. To me it's the digital equivalent of RAGBRAI, which is a rolling party across Iowa each year that happens to be on bicycle. Advent of Code is as much about the community as the problems.

(Minor wording edit.)

GabeIsko wrote at 2021-12-02 03:05:41:

More like, advent of excel

throwawaygal7 wrote at 2021-12-01 14:41:22:

I really like this event but wish the name would be changed to something more sensitive.

Would this have been named 'Kwanzaa of code' or 'Diwali of code' or 'lesser eid of code'? Of course not

dang wrote at 2021-12-03 02:17:24:

Please don't take HN threads into flamewar. It's tedious, usually turns nasty, and is the sort of thing we're hoping to avoid here.

Also, starting a flamewar and then pouring fuel on the flames, as you did with

https://news.ycombinator.com/item?id=29407387

, is definitely not ok.

https://news.ycombinator.com/newsguidelines.html

matsemann wrote at 2021-12-01 14:45:24:

How is it insensitive? In my country (Norway) there's advent calendars for everything and has been since I was a child. Home made advent calendars with a small gift each day, or store bought with a chocolate, beer, liquorice, or similar per day. There are special advent calendar TV shows, where an episode is released each day in December.

throwawaygal7 wrote at 2021-12-01 18:35:52:

Here you go:

Advent is a season of the liturgical year observed in most Christian denominations as a time of expectant waiting and preparation for both the celebration of the Nativity of Christ at Christmas and the return of Christ at the Second Coming. Advent is the beginning of the liturgical year in Western Christianity, and is part of the wider Christmas and holiday season.

matsemann wrote at 2021-12-01 20:42:46:

I know what advent is, as I said I and my fellow countrymen do loads of advent stuff.

Why does that make this offensive?

silicon2401 wrote at 2021-12-01 14:45:45:

There's nothing insensitive about the word 'advent'. Additionally, you are free to start a Kwanzaa of Code or Diwali of Code or both and people are free to join.

petercooper wrote at 2021-12-01 15:22:27:

I had to look up the etymology and it basically comes from Latin ad-venire or "to come".. so symbolizes merely the eventual arrival of something or prelude to something.

silicon2401 wrote at 2021-12-01 16:22:56:

Exactly. That comment was a great example of outrage culture. Instead of stopping to think of what advent means or put in the effort to start a Kwanzaa of code, the other commenter instead chose to just complain and get upset over nothing

dang wrote at 2021-12-03 02:19:24:

Please do not perpetuate flamewars on HN. It's just what we're trying to avoid here.

https://news.ycombinator.com/newsguidelines.html

throwawaygal7 wrote at 2021-12-01 18:36:51:

You're the one that has no idea what Advent means in western European culture

throwawaygal7 wrote at 2021-12-01 18:36:22:

Advent is a season of the liturgical year observed in most Christian denominations as a time of expectant waiting and preparation for both the celebration of the Nativity of Christ at Christmas and the return of Christ at the Second Coming. Advent is the beginning of the liturgical year in Western Christianity, and is part of the wider Christmas and holiday season.

the-smug-one wrote at 2021-12-01 19:52:06:

And that is bad?

Mountain_Skies wrote at 2021-12-01 21:29:51:

Unfortunately to some their idea of being inclusive means hating anything and everything about whatever culture is dominate. The destruction and elimination of that culture is their only acceptable path to diversity and inclusion.

dang wrote at 2021-12-03 02:19:28:

Please do not perpetuate flamewars on HN. It's just what we're trying to avoid here.

https://news.ycombinator.com/newsguidelines.html