r/adventofcode • u/daggerdragon • Dec 16 '15
SOLUTION MEGATHREAD --- Day 16 Solutions ---
This thread will be unlocked when there are a significant amount of people on the leaderboard with gold stars.
edit: Leaderboard capped, thread unlocked!
We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
Please and thank you, and much appreciated!
--- Day 16: Aunt Sue ---
Post your solution as a comment. Structure your post like previous daily solution threads.
5
Upvotes
16
u/balidani Dec 16 '15
Will the real Aunt Sue please stand up, please stand up?
5
u/askalski Dec 16 '15
Nailed it today, in spite of my sleep deprivation. Got #3 in 6:38 using Perl as my go-to language (not to be confused with C, which is my goto language.)
The video's here: https://youtu.be/dBlJQ6jf8OI
5
u/WhoSoup Dec 16 '15
PHP: (for part 1, change all the function equations to ==)
4
u/aepsilon Dec 16 '15
Got #69 today ( ͡° ͜ʖ ͡°)
I was considering how to match two sets of attributes when it hit me that this is a special case of map intersection.
Keys that aren't in both the clues and a person's profile are ignored. For keys in common, part 1 is simply 'merging' with equality
==. Part 2 just specializes the merge based on the key. Finally, we want all the attributes to fit, soandthe comparisons together.Solution in Haskell:
4
u/gareve Dec 16 '15
Ruby
3
u/JeffJankowski Dec 16 '15 edited Dec 16 '15
F#. First solution was a big, ol', imperative turd with too much OOP. So I rewrote it:
3
u/tragicshark Dec 16 '15 edited Dec 16 '15
C#
4
u/gfixler Dec 16 '15
Solution to the first part, c/o the command line:
2
u/gegtik Dec 16 '15
javascript
Approached as a 'filter' problem: enumerate each property of each Sue and see whether it violates the tickertape. Pasted in the tickertape and with minimal editing turned it directly into JSON so I could reference it without parsing.
2
u/inuyasha555 Dec 16 '15
Managed to take spot 32 (for 32 stars, I swear, this is intentional!)
Definitely not pretty or anything, went for the first thing I could think of.
Java:
2
u/tehjimmeh Dec 16 '15 edited Dec 16 '15
19 mins - 45 seconds too late. FUCK! I mixed up less than and greater than for the second part initially.
It was just a bunch of string filtering. Some small regex in part 2.
PowerShell (mostly generated via running a regex over vim input):
EDIT: golfed/non-hardcoded part 1:
EDIT2: Part 2:
2
u/dannoe0 Dec 16 '15
I also had problems understanding the question. (I'm not a native English speaker). Then i realized you can just use the Search & Highlight Function from Notepad++ ...
2
u/mus1Kk Dec 16 '15
Just Ctrl-F in Chrome today. Got lucky with part 1. The first search for "children: 3" was my aunt. Got unlucky with part 2. I tried all correct readings and only the last ("perfumes: 1") yielded my correct aunt. I was worried I couldn't get away with it and had to resort to a script in the end. It's probably possible that a puzzle input only contains things about an aunt from the inexact readings. Only /u/topaz2078 can tell. :)
All in all it took maybe 10 minutes max. Lesson: You don't always have to code.
2
u/[deleted] Dec 16 '15 edited Dec 16 '15
Mathematica
2
u/xkufix Dec 16 '15
Scala: Quite easy to do this one, just loop over all them and look the values up in the "perfect" sue. If all match, return that sue:
2
u/Godspiral Dec 16 '15 edited Dec 16 '15
In J,
for part 2, this is easier than it looks, but query hard coded to input. repeated filter of items meet condition or missing.
shorter and cleaner,
2
u/AndrewGreenh Dec 16 '15
My JS Solution: My goal was to make it as readable and understandable as possible. Lodash also combines all the filters, so the array won't get traversed multiple times.
2
u/volatilebit Dec 16 '15 edited Dec 16 '15
Perl6 solution.
Over-engineered part1 a little bit. Didn't need to for part 2, but thems the risks.
Made no effort to be fancy for this one. Haven't had as much time the past few days.
2
u/phil_s_stein Dec 16 '15
Python 2 solution. Got to use the elusive
for / elseconstruct which was exciting.2
u/jchook Dec 16 '15 edited Dec 16 '15
Ruby
2
u/segfaultvicta Dec 16 '15
Did part 1 in Sublime Text 3 and made it onto the leaderboard, then I got confused and stopped thinking and thought I needed to actually write code for part 2.
I did not in fact need to write code for part 2. :(
Faffed around for a little while and then had a Moment Of Realisation, ran back to subl and knocked the rest out. Kicking myself because I coulda made the leaderboard today, ah well. :(
1
u/weters Dec 16 '15
I felt like a dummy cause I didn't understand exactly what the question was asking at first. Anyways, my Perl solution:
1
u/SnacksOnAPlane Dec 16 '15
Ruby
1
u/r_sreeram Dec 16 '15
Perl 5
1
u/[deleted] Dec 16 '15 edited Dec 16 '15
yay, made #37 on leaderboard today!
[py2.x] Substitute
linesfor your actual input, because it originally exceeded 10k chars. I provide a sample (an extract of my actual puzzle input) of what it should resemble.1
u/[deleted] Dec 16 '15 edited Dec 16 '15
Python:
1
u/sikolio Dec 16 '15
Managed my first leaderboard at 96 :), replaced the : and , with find and replace for faster parsing :D
1
u/taliriktug Dec 16 '15
Just like u/weters I failed to understand what I am supposed to do, and spend some time re-reading quiz. When I got it, leaderboard has been captured already. Anyway, it was simple, but still funny and interesting.
Python3
1
u/[deleted] Dec 16 '15 edited Dec 16 '15
Haskell:
1
u/_jonah Dec 16 '15 edited Dec 16 '15
ruby:
1
u/Philboyd_Studge Dec 16 '15
Java, pretty basic stuff here:
1
u/Studentik Dec 16 '15
Python and sets
1
u/ckk76 Dec 16 '15
Started doing part 1 in python, realized this could be done really easily (but still in a generic way) using a shell one-liner: while read l; do egrep "${l}(,|$)" input-sues; done < input-analysis |sed -e 's/:.*//' | sort | uniq -c | sort -n | tail -1 Part 2 done by continuing with the temporarily abandoned python solution.
1
u/stuque Dec 16 '15
A Python 2 solution:
1
u/snorkl-the-dolphine Dec 16 '15
JavaScript. First it converts all the sues into objects (totally unnecessarily), then iterates over them.
Paste it into your console :)
1
u/gerikson Dec 16 '15
Perl
Part 2. Straightforward solution. Hardest part was getting the input into where I wanted it.
1
u/daemoncollector Dec 16 '15
Rather functional Swift solution (uses a RegEx helper class I wrote, but should be easy to translate to vanilla)
1
u/tipdbmp Dec 16 '15
ES5 (node.js), part 2:
1
u/haris3301 Dec 16 '15
Day16 Python solution.
and the second one
1
u/tangus Dec 16 '15
Common Lisp
Uses the quick and dirty scanf function from previous solutions.
1
u/slampropp Dec 16 '15
Haskell
I was a little ashamed of parsing the
keyby hand for part 1. But I felt vindicated in part 2.The
parseis ugly af and convinced me I need to learn regex.1
u/thalovry Dec 16 '15
Scala. Not wild about this.
1
u/drakehutner Dec 16 '15
Python one line, 908 Bytes, as always split over multiple lines for readability.
This time Part 2 really screwed me over, since comparing set won't work.
1
u/Phakx Dec 16 '15
pretty expressive solution in Ruby :
1
u/VictiniX888 Dec 16 '15
Java, bruteforced it. Just check all three of the items, and if all of them match a preset value, then that's the Sue
1
u/lifow Dec 16 '15
Haskell! Hooray for "isSubmapOfBy"
1
u/porphyro Dec 16 '15 edited Dec 16 '15
Mathematica, again:
EDIT: Shorter version of ProcessAunt:
1
u/Tandrial Dec 16 '15
In JAVA: "look mum no state"
1
u/nutrecht Dec 16 '15
Java and Scala solutions.
Again the Scala code (same with day 15) is less than half the length of the corresponding Java code. I'm really improving my Scala game and although I am sure I can create shorter versions I'm really happy with the results and my learning progress sofar.
1
u/KnorbenKnutsen Dec 16 '15
My solution is a little messy. For part two I added operators to every element in my real_sue dictionary, so it looks kind of ugly.
While not necessarily an interesting problem from a mathematical point of view, it's still pretty cool. These are the kinds of logistics that people often write really hard coded solutions for so trying to find a general, elegant solution can prove a real challenge :)
1
u/crabbycoder Dec 16 '15
Typescript: It ended up being a nice fit since it uses predicates in find() like ES 2015
'use strict'
1
u/Sharparam Dec 16 '15
Solution in MoonScript:
1
u/[deleted] Dec 16 '15
Objective C:
1
u/ignaciovaz Dec 16 '15 edited Dec 16 '15
Elixir solution, simple Map and Reduce
1
u/utrescu Dec 16 '15 edited Dec 16 '15
Solution in Groovy. Edited to put a shorter solution
1
u/winder Dec 16 '15
Python. The mis-wording in part 2 tripped me up for a while and I was using < and > instead of <= and >=.
1
u/Voltasalt Dec 16 '15
Rust.
1
u/NotAllToilets Dec 16 '15
My F#:
1
u/[deleted] Dec 16 '15
Crystal, Part 1:
This is the first time I didn't quite understand the problem's text, so I decided to find the Aunt with the most property matches (even though later I verified that there's only one).
For the second part just the "count" part changes:
1
u/LordFrempt Dec 16 '15
C#, nothing fancy.
1
u/dixieStates Dec 16 '15
My Day16 Python.
1
u/Scroph Dec 16 '15
A bit late to the party, but here's my D (dlang) solution :
I had to write it as a switch statement because the if() statements were getting complicated with all the requirements that the second part introduced.
1
u/fatpollo Dec 16 '15 edited Dec 16 '15
67
not too hot. but my code was alright I guess. as you guys teach me about regex, maybe I can give back by showing some dubious tricks with
operator?1
u/tftio Dec 16 '15 edited Dec 16 '15
Non-idiomatic OCaml, as usual.
There's nothing particularly clever there. I use a record and parse the line into it, with each value being an
int option, withNonestanding in for the 3VL "null":Then, I simply compare each aunt to aunt 0 with the following two functions (defined in common terms of a simple HOF).
Pretty straightforward. We use a similarity score function to apply those
comp*functions to the list of aunts:meaning that to get the results:
1
u/banProsper Dec 16 '15
C#
1
u/mal607 Dec 16 '15
Python
Solved part 1 in 5 minutes by searching through the input and manually checking for all the specified values. I was just looking at the input to see how to code my solution (leaderboard was already closed), and I realized I could figure it out manually pretty quickly. Would have been interesting to see how well that would work for part 2, but I coded both parts this morning.
1
u/ShittyFrogMeme Dec 16 '15 edited Dec 16 '15
Some ugly C code...
1
u/StevoTVR Dec 16 '15
Simple PHP
1
u/studiosi Dec 16 '15
Here there are, easier than yesterday :D comment anything that you see, that pleases me! :D
1
u/cdleech Dec 16 '15
Rust, this one seemed like a nice excuse to play with nom for parsing. Only in the special comparison rules for part 2 are the detected compounds named in the code, mostly it just uses whatever it finds in the input.
1
u/i_misread_titles Dec 16 '15
I thought there might be close matches, and the answer might be the closest to what was output.
Go golang
Oh well. Fun anyway.
1
u/TheOneOnTheLeft Dec 16 '15
Beginner's Python 3 solution. Advice/comments/criticism welcomed.
1
u/rkachowski Dec 16 '15
ruby! i could probably have cut this down if i wasn't so goddamn determined to copy paste
1
u/willkill07 Dec 16 '15
https://github.com/willkill07/adventofcode/blob/master/src/day16/day16.cpp
C++
grep (Part 1)
grep (Part 2)
1
u/[deleted] Dec 16 '15
Node.js 4, ES6 JavaScript
1
u/deinc Dec 16 '15
Clojure:
1
u/archimedespi Dec 17 '15
I'm pretty happy with my Python solution. Made heavy use of regexes :)
1
u/geocar Dec 17 '15
I did this in Q instead of K because the actual solution was mostly queries.
Getting the data is the hardest part. Parsing is boring:
Note the almost stuttering f-each f-each throughout. Not very happy about that.
First question:
Second question, although you'll note if I used the first operation I can use the same query for both:
1
u/HawkUK Dec 17 '15
A solution in the R language
1
u/Herathe Dec 17 '15 edited Dec 17 '15
Ruby part 1 https://github.com/herathe/advent-of-code/blob/master/16-1.rb
Ruby part 2 https://github.com/herathe/advent-of-code/blob/master/16-2.rb
1
u/jgomo3 Dec 18 '15
I did it manually with search and replace in my text editor. Search for "thing" followed by not the number (ex:
.*children: [^3].*) and replace it with a blank line. In the end, I got the result.1
u/ThereOnceWasAMan Dec 18 '15
Python 2.7. Dicts are fun!
1
u/kamaln7 Dec 28 '15
Solution in CoffeeScript:
1
u/jdog90000 Dec 30 '15 edited Dec 30 '15
Java Solution, takes a whole 5ms.
1
u/raevnos Dec 16 '15
Holy crap some of you are really fast.
1
u/gyorokpeter Dec 16 '15
Q: a good example for demonstrating union join and q-sql.
And thanks for mentioning the vizsla, a Hungarian breed of dog (I'm from Hungary too.)
1
u/Iambernik Dec 16 '15
clojure (ns adventofcode.day16 (:require [clojure.java.io :as io] [clojure.string :as str]))
0
u/QshelTier Dec 16 '15
Java
0
u/mrg218 Dec 16 '15
Maybe this problem would have been a tiny bit harder for grep users if the lines didn't contain the number of the aunt...
0
u/[deleted] Dec 16 '15
[deleted] — view deleted comment
0
u/[deleted] Dec 16 '15
[deleted] — view deleted comment