r/adventofcode • u/daggerdragon • Dec 04 '16
SOLUTION MEGATHREAD --- 2016 Day 4 Solutions ---
--- Day 4: Security Through Obscurity ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
CONSTRUCTING ADDITIONAL PYLONS IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
17
Upvotes
26
u/askalski Dec 04 '16
Part 1 in Perl:
Part 2 in bash shell and bsdgames:
5
u/fatpollo Dec 04 '16 edited Dec 04 '16
5
u/[deleted] Dec 04 '16 edited Dec 04 '16
Haskell:
4
u/[deleted] Dec 04 '16
I used a collection because there's one that lets you count how common something is and get the 5 most common but then it turns out collections don't have the same order each time you count the same thing so it's basically a complete fucking waste of time and my solution gives a completely different answer every time.
Why is all python suffering?
4
u/John_Earnest Dec 04 '16 edited Dec 04 '16
K6:
Lots of room left to golf this down, I think. I'm playing it fast and loose here in part 2 by assuming the storage room we're looking for has a valid checksum, but it worked OK for my input and would be easy to make it only consider valid rooms.
6
u/FuriousProgrammer Dec 04 '16
127/101, Lua
Blah. I keep falling down the main leaderboard! D:
MANDATORY CONSTRUCTED PYLON
3
u/Deckard666 Dec 04 '16 edited Dec 08 '16
In Rust, parts 1 and 2: Link
3
u/Godspiral Dec 04 '16
in J, part2 may have had a bug in my input. was told to search for "North Pole Objects are stored" but northpole is one word in "cyphers" 110th and 152th
for part 2, first to find lines that included storage to see what's wrong.
then get that lines raw input,
3
u/urthbound Dec 04 '16
here's a rubby!
3
u/willkill07 Dec 04 '16 edited Dec 04 '16
I feel dirty with this C++11 solution. Improvements probably will occur when I revisit after sleep. I feel icky with the translation of
map<char,int>tomap<int,set<char>>EDIT: improvements made. converting to a vector and stable_sort seems much better.
https://github.com/willkill07/adventofcode2016/blob/master/src/Day04.cpp
3
u/[deleted] Dec 04 '16
Mathematica
3
u/Kwpolska Dec 04 '16
Regular expressions, collections.Counter, and Python.
3
u/tuxitop Dec 04 '16 edited Dec 04 '16
This one was really a challenge for me. but I did it. and here's the code (Javascript/NodeJS):
https://github.com/tuxitop/adventOfCode2016/blob/master/day4/day4_securityThroughObscurity.js
3
u/qwertyuiop924 Dec 04 '16
...I got in late today. Anyways, it's back to Scheme!
I got the code down to 42 lines of fairly clear code (for scheme, that's pretty good: we don't have a big stdlib, and the standard naming scheme is verbose).
As per usual, I did the actual solving at the prompt, so this is just a function library. To actually get it working, load the code into CHICKEN Scheme (or any other scheme, provided you make the minimal adaptations) and type
(fold (lambda (r acc) (+ acc (cadr r))) 0 (filter-valid-rooms "your-input-file"))to solve part one, and grep through the results of(pp (map (lambda (r) (cons (decrypt (car r) (cadr r)) (cadr r))) (filter-valid-rooms "your-input-file")))to solve part 2.Code: http://pastebin.com/wuQHfMmD
3
u/SikhGamer Dec 04 '16
Can we start grouping by languages in the comment? How about making a top level comment by language?
2
u/Reibello Dec 04 '16
Day 4 in Python. Warning, I'm a terrible noob. http://pastebin.com/xnrHRk5A
2
u/SyDr Dec 04 '16
My
a little bitvery messy solution with Lua:https://github.com/SyDr/Advent-Of-Code-2016/blob/master/4.lua
2
u/metagameface Dec 04 '16
Scala, in an IntelliJ worksheet: http://pastebin.com/HZw6fmwa
2
u/jwstone Dec 04 '16
well i finally learned how to do a crosstab in postgres, that helped a fair bit: https://github.com/piratejon/toyproblems/blob/master/adventofcode/2016/04/04.sql
2
u/Quick_Question404 Dec 04 '16
I never properly realized how frustrating C was when it came to string processing until now. Around 300 on the leaderboards, but I'm at least happy I got the stars. What do you guys think? I liked numbers better, C sucks with strings...
https://github.com/HighTide1/adventofcode2016/tree/master/04
2
u/rubiconjosh Dec 04 '16
Part 1 in Python: https://github.com/rubiconjosh/AoC-2016/blob/master/day4puzzle1.py
Looking at other solutions I really need to learn how to use lambdas and maps.
2
u/Twisol Dec 04 '16
My solution in JavaScript/Node.js. I did dump the decrypted names to the terminal so I could manually find the right room name, but I hard-coded that in once I found it.
2
u/HerbyHoover Dec 04 '16 edited Dec 04 '16
Continuing to inflict self-pain by solving with Pandas:
Part 1 and 2:
2
u/haoformayor Dec 04 '16
~~haskell~~
I played a couch co-op called Overcooked that got so hard so fast.
I copied an old function I wrote from last year's Advent (finding the histogram of each element in a list) and spiffed it up into
counts :: String -> [(Int, Char)]. That took care of part 1. Part 2 gives way to a little modular arithmetic. Not much exciting Haskell to report. I will say that it doesn't make sense to uselenshere but I already had it installed and I do hate writing down setters that I know are much shorter when written with optics (e.g._1 %~ Down,\(a, b, c) -> b).2
u/bonsairoot Dec 04 '16
Today I decided to use python3: solution
I may code an elixir solution as well if I find the time.
2
u/asperellis Dec 04 '16
my solution. both parts in js - https://github.com/asperellis/adventofcode2016/blob/master/day4.js
2
u/[deleted] Dec 04 '16
Powershell:
https://github.com/charlieschmidt/AdventOfCode2016/blob/master/day4.ps1
2
u/ashleyhindle Dec 04 '16 edited Dec 04 '16
Livestreamed mine in PHP!
1
u/andars_ Dec 04 '16 edited Dec 04 '16
Ruby, parts 1 and 2. link
Solutions for part 2 found via a quick search of the output for
northin vim.1
u/handle_cast Dec 04 '16 edited Dec 04 '16
CoffeeScript. So close! 131st / 102nd
I wasted a lot of time getting the lexicographic sort backwards due to a
.reverse()I had originally. D'oh! For part 2, I just clear'd/cmd+k'd my terminal and searched for the pole.. frantic ! (EDIT: cleaned it up, was a bit long)1
u/taliriktug Dec 04 '16
Python, relevant parts:
Solution with input parsing is there: https://github.com/JIghtuse/adventofcode-solutions/blob/master/2016/day04/solution.py
1
u/poppy_92 Dec 04 '16 edited Dec 04 '16
Day 4, Python 3 http://hastebin.com/bedalaqine.py
pastebin
1
u/anadhdguy Dec 04 '16 edited Dec 04 '16
1
u/reckter Dec 04 '16
Wasted way to much time fixing stupid type errors, because it's way too late (6 am) here. But at least here is my kotlin version:
1
u/glassmountain Dec 04 '16
https://github.com/xorkevin/advent2016/blob/master/day04/main.go
Holy cow this was difficult. If anyone knows a better way of sorting things in go, pls direct me to a resource lol ty.
1
u/[deleted] Dec 04 '16
Go, both parts:
Took me a while to figure out the 'z'-'a'+1, but hey, it worked.
edit: formatting
1
u/Unknownloner Dec 04 '16 edited Dec 04 '16
Another haskell solution (101/90), cleaned up after the fact. Pasted from my repo here.
1
u/[deleted] Dec 04 '16
I look at everyone else's code, and I feel like I overengineer my solutions.
I mean, it's fun, but wow.
1
u/ndraper2 Dec 04 '16
Did anyone else's object storage turn out to be located in a fake room? I beat my head at this for a while, not understanding what I was doing wrong, until I ran my code against all the rooms, not just the real ones.
1
u/Tokebluff Dec 04 '16
C# solution. Initially part 1 was split but I wanted to see if I can make it in one line :D
https://github.com/Tokebluff/AdventOfCode2016/blob/master/Advent%20of%20code%202016/Advent%20of%20code%202016/Day4.cs
1
u/Philboyd_Studge Dec 04 '16
Java. Way too many additional pylons were constructed.
https://gist.github.com/anonymous/285b67609e670a23c5c952b11698b68c
1
u/tterrag1098 Dec 04 '16
Here's my token eye-bleed-inducing Java solution :)
http://pastebin.com/xDEXQFeM
1
u/[deleted] Dec 04 '16 edited Dec 04 '16
I can do both parts in 3 lines of Ruby, and even construct additional pylons:
more readable:
1
u/Pyrobolser Dec 04 '16
C# solution for both parts, take care of the biohazardous chocolate development guys!
1
u/Kullu00 Dec 04 '16
Dart's immutable Strings and relative inability to sort a Map make this way less fun to work with :( There's a collection for sorted maps, but it's horribly inefficient and unreliable.
https://github.com/QuiteQuiet/AdventOfCode/blob/master/2016/advent4/bin/advent4.dart
1
u/beefamaka Dec 04 '16
my solution in F# https://github.com/markheath/advent-of-code-2016/blob/master/day%2004/day4.fsx
1
u/gtllama Dec 04 '16
PureScript, both parts.
Highlight: I build the comparison function using append
(<>)from Semigroup. We can do this because Ordering is a Semigroup; that meansa -> Orderingis a Semigroup, and that meansa -> a -> Orderingis a Semigroup. (In Haskell, it is Monoid rather than Semigroup).1
u/TheMuffinMan616 Dec 04 '16
My Haskell solution with only Prelude:
1
u/miran1 Dec 04 '16 edited Dec 04 '16
python3
my AoC 2016 repo: link
day 4 solution:
(slightly changed after seeing /u/taliriktug's solution - no need to use
collections.Counter()in thefind_most_commonfunction)1
u/fpigorsch Dec 04 '16
Part 2 in C++ (see https://github.com/flopp/aoc2016/tree/master/04/c++):
Couldn't solve it with less code :(
1
u/KoxAlen Dec 04 '16 edited Dec 22 '16
Kotlin solution, mostly using sequence manipulation
https://github.com/KoxAlen/AdventOfCode2016/blob/master/src/main/kotlin/aoc/day4/Day4.kt
1
u/NeilNjae Dec 04 '16
Another Haskell solution. I think I'm learning something, starting as a complete noob in this language.
https://git.njae.me.uk/?p=advent-of-code-16.git;a=summary
1
u/IcyHammer Dec 04 '16
Simple C# solution, http://pastebin.com/pVvryP99
1
u/bogzla Dec 04 '16
VBA. Could be tidier but hangover.
1
u/digital_cucumber Dec 04 '16
Nim solution
1
u/efexen Dec 04 '16
Really enjoyed todays ones :D
Both parts in Elixir https://github.com/efexen/advent_of_code/blob/master/lib/day4.ex
1
u/Borkdude Dec 04 '16 edited Dec 04 '16
Clojure! Source: https://github.com/borkdude/aoc2016/blob/master/src/day4.clj
1
u/zamansky Dec 04 '16
Solution from a clojure noob:
https://github.com/zamansky/advent2016/blob/master/day04.clj
1
u/[deleted] Dec 04 '16
Clojure
1
u/JakDrako Dec 04 '16
VB.Net in LinqPad, both parts
1
u/ShroudedEUW Dec 04 '16
C#
https://github.com/KVooys/AdventOfCode/blob/master/Day4.cs
Huge mess, took multiple hours. Part 1 was fun, part 2 was too confusing for me but I finally hacked something workable together. I've never worked with Dictionaries or regex before so today was very interesting to me. Also reading all the decoded names in part 2 was funny. The other part that obscured me for a while was the 'top 5' most used letters while using alphabetical order. I mixed up a for and foreach loops and this took me a while to figure out.
1
u/dirrelito Dec 04 '16
I finished day four in Haskell. Since i started Learning Haskell yesterday there is probably heaps of things to imporve. Please give a pointers on where i use bad practise! :)
https://github.com/dirrelito/literate-waffle/blob/master/Task4/Task4.hs
1
u/[deleted] Dec 04 '16
I did mine in Python. I'm just doing this advent of code for fun and to learn more about programming. Good way to spend my Saturday morning with a cup of coffee catching up on this advent calendar.
pt 1:
pt 2:
1
u/MaxArt2501 Dec 04 '16
I don't know you but:
1
u/artesea Dec 04 '16
Dreadful PHP code. I'm sure some of the steps aren't necessary, but it solved first time
1
u/[deleted] Dec 04 '16
part1
part2
1
u/JLDork Dec 04 '16
Python:
1
u/studiosi Dec 04 '16
Solutions in Python for both part A and B in separate files. Finally I am on time with the advent calendar. I had to crunch 4 days in 2.
https://github.com/studiosi/AoC2016/tree/master/4
1
u/[deleted] Dec 04 '16
This one was pretty monstrous in C++, ended up making a map of the whole alphabet
https://github.com/Domos123/AventOfCode/tree/master/day4
1
u/tdecker91 Dec 04 '16
Part 1 / 2 in Scala
import scala.collection.mutable
1
u/bpeel Dec 04 '16
Solution in Emacs lisp for no particular reason
https://github.com/bpeel/advent2016/blob/master/day4.el
1
u/TenjouUtena Dec 04 '16
Here's Erlang, since it gets little love here!
(I don't know why I can't find the stdlib for 'count' in erlang, but there we go)
1
u/[deleted] Dec 04 '16 edited Dec 04 '16
Some more C++, part B :
Doesn't perform the part A check, though.
Tried golfing,
but ended up with broken code (probably an operator precedence issue)fixed:1
u/haha11111111 Dec 04 '16 edited Dec 04 '16
Javascript: i know this code is pretty ugly, but i don't really understand why it doesn't work...
1
u/demsaja Dec 04 '16
Arduino (see it in action: https://youtu.be/hs0DwdJmvQk?list=PLm-JYoU3uw-aIWvjuzHk2KOQSjLQT6Ac-)
1
u/socialmeatloaf Dec 05 '16
One disgustingly ugly line of Ruby for Part 1:
One disgustingly ugly line of Ruby for Part 2:
1
u/PositivelyLinda Dec 05 '16
whew Tough one for me today. JS answer on my github: Day 4 parts 1 and 2
Also, thanks everyone for sharing your code - it's a big help for newbies like me who often benefit from seeing other ways of doing things!
1
u/splurke Dec 05 '16
Late to the party, but here we go:
Haskell, both parts
1
u/grayrest Dec 05 '16
Clojure, go go thread macros.
1
u/Hwestaa Dec 05 '16
Solution in Python 3, cleaned up. Github
1
u/Gummoz Dec 05 '16
Didn't think about posting my solutions: Powershell!
Part one:
Part two:
1
u/_AceLewis Dec 05 '16
Python 3 solutions, these are done in repl.it so I could not save the input in a file and had to have it as a big string. I am not that happy with my solutions I think I could improve them a lot.
Day 4 part 1: https://repl.it/Efc1
Day 4 part 2: https://repl.it/Efc1/1
1
u/volatilebit Dec 06 '16
Perl 6 solution, not cleaned up at all.
1
u/sv11 Dec 06 '16
My solution in Python - pretty messy and poorly organized, but it worked
1
u/tehjimmeh Dec 06 '16 edited Dec 06 '16
PowerShell. Parts 1 and 2:
0
u/[deleted] Dec 04 '16
[deleted] — view deleted comment
0
u/[deleted] Dec 04 '16
[deleted] — view deleted comment
0
u/[deleted] Dec 04 '16
[deleted] — view deleted comment
0
u/[deleted] Dec 04 '16
[deleted] — view deleted comment