1. 40
  1.  

  2. 7

    I’ve been working the problems in Clojure again but looking for opportunities to use Quil/Processing to make animated visualizations of the solutions:

    1. 1

      Day 4: https://www.youtube.com/watch?v=9OfLNCWM_yA

      Each guard gets a unique color, their naps are overlaid as slices on a clock face, and the extending lines’ lengths and colors are proportional to how often the guards were sleeping during that minute.

      1. 1

        Might you open source your visualization code please? I’m also working in Clojure and knowing how to visualize the data might be a step up from my current stare-at-maps method

        1. 1

          Absolutely, it’s all here https://github.com/taylorwood/advent-of-code

    2. 3

      I’ve been doing this in python and it’s been a blast. For day 3 it introduced me to numpy and matrices! Of course, it’s humbling seeing other’s solutions and how much more elegant their solutions are, but that’s been a great learning opportunity too.

      Don’t forget there’s a lobsters leaderboard!

      1. 3

        I love AoC! I’m doing it in Rust for my second year in a row, and prior to that I used it to learn me an Elixir. (Edit: https://github.com/gamache/advent2018 if you wanna heckle me)

        AoC hits such a sweet spot between the dryness of Project Euler where you’re solving ten-word math problems and the showoff problems in Google Foobar where you’re mostly reading math.stackexchange and journal articles that came out under three years ago.

        1. 2

          Really enjoyed this article! Am definitely going to give this year’s puzzles a whirl in C++ since I’m learning that now.

          (Though I’m terribly stuck in Chapter 5 of Stroustrup’s Tour of C++ on copy/move :)

          1. 3

            If you can easily access a copy, I think that Scott Meyers does a better job covering the copy/move distinction in Effective Modern C++. You’d want to look around page 350 or so.

            That section of that book, incidentally, also has one of my favorite examples of how complicated C++ has gotten:

            std::move doesn’t move anything, for example […]. Move operations aren’t always cheaper than copying; when they are, they’re not always as cheap as you’d expect; and they’re not always called in a context where moving is valid. The construct type&& doesn’t always represent an rvalue reference.

            It’s occasionally just nice to know that it’s not you, it’s the language.

            1. 1

              Thanks for that. I’ve been referred to that book right along but I felt like I needed a gentler introduction to the language, which is why I turned to Tour but I will definitely check the Meyers book out for the copy/move stuff. I have a Safari membership so all you can eat books for one price. (I love it :)

              That section of that book, incidentally, also has one of my favorite examples of how complicated C++ has gotten:

              Interesting that you point this out. I’m actually finding that C++, at least at the beginner level I’m interfacing with it, feels considerably less complex and more abstract than the C++ I last touched in the early 90s.

              I’m sure this is because I haven’t had to delve into the inner workings of STL and the like - I’m guessing the … uh… water? Gets MUCH deeper there :)

              1. 2

                The language doesn’t grow less complex for having more high level abstractions.

          2. 2

            As someone who doesn’t even review pull requests at work any more, I appreciate the excuse to actually write code. Too, it’s a chance to monkey around with Haskell, and as a social activity with a variety of groups, both at work and home.

            1. 2

              I solved the very first challenge with a simple AWK one-liner.

              I suspect many of us had the same approach here :)

              1. 3

                awk ‘{total += $1} END {print total}’ adv1.txt ;)

                1. 2

                  This is almost exactly what I had, but after doing some of the other puzzles I realised I am not very smart and I should just lean on Haskell for everything.

                  1. 1
                    awk '{c+=$1} END {print c}' day1.input
                    awk '{c+=$1; if (c in seen) { print c; exit 0} else seen[c]=1}' <(while cat day1.input; do :; done)
                    

                    ;)

                  2. 2

                    I suspect many of us had the same approach here :)

                    I don’t know what others think, but until now every puzzle seemed to be most comfortably solved in AWK. It’s a bit sad because I wanted to use a new language each day, but lack of time forces me to be lazy :(

                    Update: just in: day 3, part 2 didn’t even take a minute ^^

                    1. 2

                      I don’t think it’s so sad. For me at least, it makes the case that all programmers should know AWK.

                      1. 1

                        Huh. We must have thought very differently about day 3, part 2. How did you do it? (I did a very “mathematiciany” approach where I generated the coordinates each box would touch, then put those in a map of those coordinates to a list of IDs, and did the set difference of all IDs with the lists that had more than one element. Hugely wasteful in CPU terms, just fine in brain terms.)

                        1. 2

                          (spoiler: this was my script): I read in the file twice, first time counting how often each x y coordinate was requested, filling up a 2D map (AWK’s pseudo-arrays), and the second time going through all the lines again, looking for any request that only had 1’s in the map, then printed that out. Not pretty, but it was easy to extend my first solution to work with it.

                          What language did you use, if I may ask?

                          1. 2

                            Nice. I guess that’s pretty similar to what I did.

                            What language did you use, if I may ask?

                            Python. I’m brushing up on it for a job I’m starting in January, otherwise I think I’d have tried something lispy: https://github.com/gunnihinn/advent-2018/blob/master/day03b.py

                    2. 2

                      What is going on in the Minecraft example? I tried to find the creator by searching Google, but didn’t find anything.

                      1. 5

                        You can see in the lower left hand corner of the loading screen some references to MCP and Forge, which are tools used to modify/load mods into Minecraft. I assume this person just wrote a Java solution to the problem and basically just used the Minecraft client as a container for their GUI.

                        It’s been a while since I’ve messed around with any of this stuff, but I did have fun building a fairly complex adding machine a few years ago using this mod https://github.com/dan200/ComputerCraft - which makes available in-game monitors, cabling, and a “computer” that is programmable with LUA. Using something like ComputerCraft could be a fun way to solve one of these problems. You could hook the in-game computer up to some light blocks and have the solution displayed in the game world rather than just using the client as a wrapper.

                        1. 2

                          I had assumed the same but their solution is a little more elaborate than that as outlined in comments in this Reddit post.

                          If I understand correctly, they’re using the / commands, primarily the /scoreboard manipulation commands as ‘memory’ and math primitives. These / commands can be be saved into a .MCFUNCTION file. They have built up an assembler and C compiler based on these primitives that emits these .MCFUNCTION files, which can then be run in Minecraft.

                          1. 1

                            Oh, I missed that. Thanks!

                            Yeah, I’ve seen a few cool YouTube videos of people doing interesting things with ComputerCraft. A long time ago, I was working on getting an adder working just using redstone.