1. 50

This is the place to plug your blog, your source repo, your random flashes of inspiration regarding this year’s Advent of Code.

Through the magic of Github follows and / or RSS, those interested can easily keep up during the contest!

Other resources:

  • the contest itself has an official subreddit: https://www.reddit.com/r/adventofcode/. There’s a daily solutions megathread there
  • this very site has an IRC channel: #lobsters-advent on Freenode

There are 2 leaderboards for this site, here are the codes

  • 989653-afc97283 (already full?)
  • 400344-db76bd5d
  1.  

  2. 62

    Thanks! Here’s to another year of giving up after a week.

    1. 3

      Last year I tried doing every day in a different programming language. That didn’t last long.

      1. 2

        If time wasn’t a problem, could you have done it? Being able to use 24 different langauges would be quite impressive.

        1. 6

          okay, I nerdsniped myself and I’m trying to do this again this year.

          1. 6

            Apparently I gave up 4 days in: https://git.sr.ht/~ianloic/AdventOfCode2019/tree but in that time I used one language I’d never used before (clojure - and I really have almost zero lisp/scheme experience) and two I hadn’t used in 20-25 years (TCL, DOS assembly language).

            I had come up with a list of language I could use and remaining were 6 I currently use regularly, 8 I’ve used in the past but am still fairly familiar with and 17 that I haven’t used, but I’m sure I can solve simple problems in - I didn’t for example include prolog.

            One thing that’s challenging is that the problems build upon each other so having to rebuild everything from the ground up in a new language each day is frustrating. If I could bring myself to dealing with a JVM I could try using a different JVM language every day because generally they have the ability to call into each other.

            1. 1

              I did Clojure one year, it was good. Still use Clojure for lots of my coding.

              I did Pharo Smalltalk one year. Convinced me to never use Smalltalk again. (I wanted it to be nirvana. It was not.)

              This year I’m doing Racket. It’s much more of a Lisp than Clojure ever wants to be. Very different experience, and I’ve not yet made up my mind. If I can’t stand Racket, I’ll switch to Fennel partway through.

            2. 1

              Me too! I think I made it about 14 days or so? I shouldn’t have used my main languages for the early days

              1. 1

                I did this for most of 2016’s! https://github.com/pablo-meier/advent-of-code 22ish days.

              2. 1

                I usually make it to the third IntCode interpreter problem before I bail.

              3. 25

                I am going to write up my Haskell solution at some point, but I liked this:

                CREATE TABLE day_01 (v INT NOT NULL UNIQUE);
                COPY day_01 FROM 'Projects/AOC/2020/data/Day01.txt';
                
                SELECT 1 AS part, a.v * b.v AS answer
                  FROM day_01 a CROSS JOIN day_01 b 
                 WHERE a.v <> b.v AND a.v + b.v = 2020
                 UNION
                SELECT 2 AS part, a.v *  b.v * (2020 - a.v - b.v) AS answer
                  FROM day_01 a CROSS JOIN day_01 b
                 WHERE a.v <> b.v
                   AND 2020 - a.v - b.v > 0
                   AND EXISTS (SELECT 1 FROM day_01 WHERE v = 2020 - a.v - b.v);
                

                And it’s crazy fast:

                   part |  answer
                 -------+----------
                      1 |   800139
                      2 | 59885340
                (2 rows)
                
                Time: 6.732 ms
                
                1. 7

                  I love the SQL solution. If you want to use it with a version of sqlite that shipped post-2004, change COPY... to .import day01.txt day_01

                  1. 2

                    In part 2, what about using three join instead of the exists?

                    1. 1

                      That would be better, yeah. This is basically a port of my Haskell solution, though.

                    2. 1

                      The Haskell version I ported from:

                      solve01 :: [Int] -> Int
                      solve01 xs = head [a * b | a <- xs, let b = 2020 - a, b `elem` xs]
                      
                      solve02 :: [Int] -> Int
                      solve02 xs = 
                        head [a * b * c | a <- xs, b <- xs, a /= b, let c = 2020 - a - b, c `elem` xs]
                      

                      Tedious IO is left to the reader.

                      1. 1

                        Looks neat, and it’s also all one line of code! Woot!

                        Would love to see that done for the triples in the next section.

                        If everything keeps building on everything, that’s going to be a fun hunk of code to watch evolve. :)

                        1. 3

                          It actually does both :)

                          1. 2

                            If DDL does not count as code, would it be zero lines of code if I could make a macro that reports the solution in an error? Or maybe if one used dependently typed programming where the compiler can infer the solution? If I used Datalog, would the queries count as code, but that statements not? ;)

                          2. 1

                            I believe you have a bug? a.v <> b.v should be a.id <> b.id or something?

                            1. 2

                              Since the numbers are unique, they’re using that to make sure they’re not checking the number added with itself since that wouldn’t be a valid solution even if it added up to 2020.

                              1. 1

                                Right. Does the problem specify that the numbers are unique? Perhaps I missed that.

                                1. 1

                                  It doesn’t, but wc -l and sort -u | wc -l gave me the same number, so.

                                  1. 3

                                    Plus I assume you would’ve found out pretty quickly if they weren’t all unique when you tried to import them into a column with a unique constraint.

                                    1. 1

                                      My first solution was in Haskell, so I had already determined that particular bit of data modelling.

                                      1. 2

                                        Ah, I guess it makes sense that the SQL implementation wasn’t the one you started with.

                              2. 2

                                The column in the table is named v.

                                1. 2

                                  Is there just one column? I was wondering how you’d handle duplicates where the answer is a perfect square.

                                  1. 1

                                    Yep, just the one. I cheated :)

                                    1. 2

                                      Ah, the ol’ overtraining-on-single-input. Carry on :)

                            2. 16

                              I’m just going to say that the title might be clickbait, because it sounds like “coming up with a solution for a problem in under a second”. Of course, it’s also my fault, for being naive enough to belive it. Perhaps I was expecting some APL-wizardry.

                              1. 5

                                I had the same thought from my initial read of the title. I assumed they had done some really clever analysis of the previous problems to come up with potential new problems and solve them pre-emptively. Oh what the mind can come up with to justify something outrageous!

                                In any case, the title is both clickbait and completely accurate, if not slightly vague.

                              2. 12

                                You can also join #lobsters-advent on freenode to chat about problems.

                                1. 9

                                  Since the first one filled up, I set up a second one, code 400344-db76bd5d to join.

                                  1. 8

                                    I’m trying to do it in machine code, but ok :)

                                    1. 6

                                      This was a pretty fun read.

                                      Regarding “readable and elegant” as being a virtue of a good language. As someone who doesn’t know Raku and isn’t familiar with perl, I have to admit that your example, for me anyway, was completely impenetrable. I’m not trying to burst your bubble, but on the other hand demonstrate how horribly subjective these things are. I’m in the process of trying to learn Haskell, and the example you gave actually had a very Haskell-esk/FP kind of feel to it.

                                      Long story short, I might look into Raku.

                                      1. 4

                                        This was really pleasant to read and was nice because it sounds like the author really just enjoys using Raku. Which is, perhaps, an underrated feature of our tools.

                                        1. 2

                                          This was really pleasant to read

                                          Thanks!

                                          it sounds like the author really just enjoys using Raku

                                          I definitely do. One of Raku’s key design goals is to be “optimized for fun” (-Ofun). This isn’t because Raku was built by a bunch of programmers who want to enjoy using it (though it was!). More importantly, we believe that making a language -Ofun makes it better: software is fundamentally a craft, and making the tools of a craft more enjoyable to use naturally leads to an improvement in the finished product.

                                        2. 3

                                          Since lobsters is publicly viewable, I don’t think that leaderboard is very private.

                                          1. 14

                                            “Private” in this case just means it’s a namespace with a selection of usernames, with internal scoring.

                                            I.e. in the global leaderboard (not visible by default), me and my buddy might be separated by thousands of entries. A private leaderboard just excludes anyone but those on it.

                                            1. 8

                                              Private, not secret.

                                            2. 3

                                              Can you be on more than one leaderboard at the same time?

                                                1. 3

                                                  I took a look at Raku for the first time in a long time for this year’s advent.

                                                  I’ve already had several omg/wtf/wow moments. There seems to be a lot of very mature, interesting work here.

                                                  Lots of people will hate it (those who dislike sigils, more than one way to do things etc), but when I read that the for loop takes an iterable and a block, so you can use a “pointy block” and the arrow in the example code I was looking at was part of the block syntax, I was pretty amazed.

                                                  It seems like the language is built out of an interesting set of abstractions. I don’t know if I’m going to deep dive, but it is seems pretty exciting.

                                                  1. 3

                                                    Last year was the first year I finished all 25 days, let’s see if I can keep up this year as well. Doing it in Rust to see if I hate it a little less after forcing myself to use it for a while.

                                                    1. 3

                                                      Just to clarify in case people wonder why I’m using a language I don’t like: I love the ideas behind Rust but so far haven’t gotten much enjoyment from actually writing it. I’m hoping by forcing myself to use it, I’ll get to the point where I feel like the compiler is helping me instead of a thing I’m fighting against, similar to how I feel when writing e.g. Haskell.

                                                      1. 1

                                                        I used Smalltalk last year to actually have practice with it.

                                                        At the end I decided it really wasn’t for me. But where else am I going to get four dozen coding problems with an artificial deadline and recorded metrics?

                                                        1. 1

                                                          I’m going with rust as well (and I did the same last year). Not sure if this is the best language for something that’s practically throwaway code, but at least I get to exercise some of the patterns like reading stuff from files and common libraries like regex.

                                                          1. 1

                                                            I’m doing the same! I posted my own comment to this thread, but I’m currently in the phase of shotgunning my code with & while I slowly learn how ownership works haha.

                                                      2. 3

                                                        As someone who prefers book to learn a new programming language, which one would be the best? I see there is “Learning Perl 6” and the brand new “Raku Fundamentals”.

                                                        1. 3

                                                          This post is day 1 of the 2020 Raku Advent Calendar, so there will be another 24 daily posts on Raku-related topics between now and Christmas.

                                                          The article links to the Advent of Raku 2020 Git repo, which is collecting Raku solutions to Advent of Code. The day one solutions have already presented multiple different approaches – just as you might expect from Raku!

                                                          1. 3

                                                            Today was fun!

                                                            I had seen the links and commentary in years past, but I always had something else to do. This year I might do a few. It reminds me of “nerd crosswords”, ie, fun little intellectual games to get the juices flowing first thing in the morning.

                                                            1. 3

                                                              I’ll share my repo – I’m learning Rust right now and needed something to force me to write code in it so I can move out of the “throwing & at the code until the compiler stops yelling at me” phase of learning Rust :D

                                                              https://github.com/3digitdev/aoc2020

                                                              1. 2

                                                                I’m trying out this year’s puzzles in OCaml: https://github.com/yawaramin/aoc2020/

                                                                This year trying not to worry about generality too much, and just solving the specific puzzle itself. Also trying to think up ways to avoid being ‘accidentally quadratic’. Not sure how long I can keep it up, but so far so good.

                                                                1. 2

                                                                  I wrote a post about my solutions for day 1 and 2: https://jlelse.blog/dev/aoc-2020-day1-2

                                                                  I will continue posting solutions to the dev section of my blog: https://jlelse.blog/dev

                                                                  1. 2

                                                                    It’s full, :-(

                                                                    1. 2

                                                                      Reposting @syn-ack’s text story because the merged story view doesn’t show it.

                                                                      Hey there! I’ve created a private leaderboard for Lobste.rs on AoC2020. Use the code 989653-afc97283 to join.

                                                                      Please submit AoC links in comments here. As usual for story merging, we’ll do one story per week.

                                                                      1. 2

                                                                        My solutions are / will be at: https://github.com/joelgrus/advent2020

                                                                        I also stream while I’m trying to solve the problems, those videos end up here: https://www.youtube.com/playlist?list=PLeDtc0GP5ICmVrjHJrIiDZFW_xr__Ifqk

                                                                        1. 2

                                                                          I’m using Clojure this year - check my solutions at https://github.com/st3fan/aoc/tree/master/2020/advent-of-code/src/advent_of_code

                                                                          1. 2

                                                                            I’m still working on getting my blog together for it, but I’m doing all of the problems in COBOL on IBM i as a way to learn both COBOL and IBM i. It’s been relatively straightforward so far, but I expect things to get much trickier soon.

                                                                            Once I get it published, the blog will be available at https://thequux.github.io

                                                                            1. 1

                                                                              That sounds really interesting, I’d love to see COBOL in this sort of situation.

                                                                              1. 2

                                                                                It’s published, along with the writeups for days 1 and 2.

                                                                              2. 1

                                                                                That sounds really cool. I hope you manage to get it published. And even if it gets too tricky to keep going, saying why would be interesting.

                                                                                If you’re not already planning to say so, I’d be interested to hear about the setup that lets you do this, too.

                                                                                1. 1

                                                                                  It’s published, along with the writeups for days 1 and 2.

                                                                                  And yes, I do plan a post in a day or two that’s more on how I actually got my hands on one of these mythical beasts (and you can too!)

                                                                                  1. 1

                                                                                    Very nice. Thanks for taking all the time it must’ve required to write that.

                                                                              3. 2

                                                                                Question from a noob: are we supposed to upload our work to GitHub? I saw some other lobsters posting links. If so, is there a place to register your repo once you upload it?

                                                                                1. 3

                                                                                  There’s no requirement to upload your work. But feel free to share it somewhere if you like!

                                                                                  1. 3

                                                                                    It’s up to you if you do or not, I like to for archival’s sake. I don’t know of any central place to register your repo, but it can be useful for posting links to your solutions in discussions.

                                                                                    1. 4

                                                                                      This was a thing a few years ago

                                                                                      https://github.com/a-red-christmas

                                                                                      Not sure who’s responsible for it now. I remember it being pretty clunky.

                                                                                      Simplest way to share code is probably to stick a link in ones lobste.rs bio and let people know that way.

                                                                                      I’ve personally set up a bunch of scripts that allow me to make short blog posts for each entry and stick them in one place: http://gerikson.com/blog/comp/Advent-of-Code-2020.html

                                                                                    2. 1

                                                                                      If you log in to adventofcode.com with github, you can choose to let it link to your github profile.

                                                                                      No option for sr.ht :(

                                                                                      1. 1

                                                                                        Well, if they allow for the officially hosted sr.ht login then they might feel obligated to also support all self-hosted instances.

                                                                                        1. 2

                                                                                          Yes indeed, though I was actually hoping for the ability to use any URL as my link, not to use my sr.ht login on AoC. I understand why this might lead to some ‘interesting’ links from the AoC, though!

                                                                                    3. 2

                                                                                      Hey all, my solutions will be here: https://github.com/lindgrenj6/adventofcode_2020

                                                                                      I’m doing it in elixir this year, kind of fell off last year but going to attempt to do at least 2 weeks this year!

                                                                                      1. 2

                                                                                        This is my first year doing it! I’m trying to use J. My only other experience with J is some Project Euler problems.

                                                                                        It’s fun thinking spatially and coming up with a concise solution, but this makes me realize how absolutely dependent I am on Google/StackOverflow to learn by example. There is some stuff out there for J, but compared to more popular languages it’s nothing. Even for simple things like “split a string on a multi-character delimiter” (I eventually found the built-in splitstring and the load 'regex' library). I think it will get easier once I memorize more of NuVoc.

                                                                                          1. 2

                                                                                            Thanks for stepping up. I’ve joined!

                                                                                            1. 1
                                                                                              1. 1

                                                                                                I’m solving mine with Emacs Lisp and literate programming: https://tildegit.org/acdw/aoc-2020/src/branch/main/aoc.org

                                                                                                1. 1

                                                                                                  Well, I’m going to try this in Janet, and only do it on weekends: https://github.com/yumaikas/aoc2020

                                                                                                  1. 1

                                                                                                    My day 3 in Haskell baby-talk. I’m really looking forward to when the wheels come off.

                                                                                                    1. 1

                                                                                                      I did question 1a, 3a and 3b without writing code, using brain, fingers, kakoune editor and calculator.

                                                                                                      1. 1

                                                                                                        I’m not gonna try join a leaderboard, since I’m using the AoC to teach myself Rust.

                                                                                                        https://github.com/offbyone/advent-of-code-2020 though, if anyone wants to watch a Python dev figure out this “Rust” thing :)

                                                                                                        1. 1

                                                                                                          Thanks, just joined. 2 hours to go!

                                                                                                          1. 1

                                                                                                            Thanks, joined as well.

                                                                                                            1. 1

                                                                                                              Just joined! Every year I end up doing only a few of these but let’s see how it goes this year.

                                                                                                              1. 1

                                                                                                                Thanks for putting this together! I joined. Looking forward to it.

                                                                                                                1. 1

                                                                                                                  Wow! All y’all are impressively fast! I’m happy to not be last. :)

                                                                                                                  (That’s in reference to tonight’s scores. For readers from the future, this is the second night but the first that there are scores, since the first night’s scores were disqualified due to server capacity issues.)

                                                                                                                  1. 1

                                                                                                                    Yeah…

                                                                                                                    That private leaderboard is full.

                                                                                                                    1. 1

                                                                                                                      https://lobste.rs/s/lgotqc/lobste_rs_advent_code_2020_private#c_zna0br

                                                                                                                      I’m seeing a market opportunity for AoC to sell access to larger leaderboards to organizations who are prepared to pay for them..

                                                                                                                  2. 1

                                                                                                                    Putting my words where my mouth is:

                                                                                                                    1. 1

                                                                                                                      I will be posting my solutions at https://gitlab.com/Lomanic/aoc, for the moment I used bash on Day 1 & 2 and Go+Python on Day 1 (to compare performances of the three nested loops as I didn’t optimize this solution at all).

                                                                                                                      1. 1

                                                                                                                        Because of the merged-threads, I’ll just be reyping to this comment.

                                                                                                                        I don’t think I’ll be writing about AoC, but I’m posting my code here: https://git.sr.ht/~zge/aoc20/tree/master/aoc20.cl. The way it looks, I’ll just be adding everyting into one file, to make re-using code easier.

                                                                                                                      2. 1

                                                                                                                        The irc channel is a true gem! Great discussions.

                                                                                                                        I will be blogging on progress (and learning) on https://bulters.dev and code will be up on https://GitHub.com/bulters/aoc20

                                                                                                                        Good luck to all participants!