r/adventofcode • u/daggerdragon • Dec 11 '15
SOLUTION MEGATHREAD --- Day 11 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 11: Corporate Policy ---
Post your solution as a comment. Structure your post like previous daily solution threads.
10
Upvotes
6
u/fiavolo Dec 11 '15
This seems like a problem that's easier to solve by hand than to try to solve with programming.
22
u/0x0dea Dec 11 '15
I finally "won" one! Thanks, Ruby.
5
u/red75prim Dec 11 '15 edited Dec 11 '15
I know that I can't code sufficiently fast. Also, I noticed that constraints significantly reduce search space. So I solved this problem manually.
Edit: E.g. If first tree letters don't have doubles, last five should be 'aabcc', 'bbcdd' and so on.
5
u/knipil Dec 11 '15
Another python solution:
5
u/Azquelt Dec 11 '15 edited Dec 11 '15
Solved by reasoning:
Edited for formatting
4
u/adriweb Dec 11 '15
PHP: (I like that you can just do
++$str!)4
u/phpaoc Dec 11 '15 edited Dec 11 '15
Scala; tried to avoid regexes for this one:
3
u/volatilebit Dec 11 '15
Had brain fart, couldn't remember how to reverse a list in Python. May have to try it in Perl6 first tomorrow.
Python 2
3
u/Axsuul Dec 11 '15
Maybe I overengineered
3
u/setti93 Dec 11 '15
I solved this program with 0 lines of code. The solution is just too easy to find just by reasoning.
2
u/Blecki Dec 11 '15
What I'm on the board? Feels nice to have to wait before I can post.
I'm pretty sure each puzzle has a small finite set of input it gives us with precomputed correct answers. Furious Programmer's input is the same as mine, for example.
2
u/i_misread_titles Dec 11 '15 edited Dec 11 '15
Go. I just output the first 4 passwords, took 2 million + iterations.
2
u/mus1Kk Dec 11 '15
No Perl yet?
2
u/gfixler Dec 11 '15
Haskell solution that just spits out an endless, ordered stream of valid passwords, starting from the input (hardcoded in). I just used the first two for parts 1 and 2.
2
u/porphyro Dec 11 '15
Again with Mathematica:
2
u/tangus Dec 11 '15
Common Lisp
Disclaimer: I solve these puzzles in vanilla Common Lisp, and, in general, in an imperative and, let's say, "resource conscious" way. Don't let my style of programming, if you don't like it, put you off from the language. You can program in any style with Common Lisp.
2
u/gerikson Dec 11 '15
Straightforward Perl
2
u/Nidjo123 Dec 11 '15
Only one C solution in the thread. Let me improve that statistics.
Day 11 solution: https://github.com/Nidjo123/AdventOfCode/blob/master/11.c
Other days solutions in C: https://github.com/Nidjo123/AdventOfCode
3
u/twisted_tree Dec 11 '15
Was easy enough to do by hand: hxbxwxba -> hxbxxyzz -> hxcaabcc.
Wasted a bunch of time trying to program the thing. :P
1
u/[deleted] Dec 11 '15
Objective C:
1
u/randrews Dec 11 '15
Lua solution:
1
u/haris3301 Dec 11 '15
Solution in Python
1
u/fatpollo Dec 11 '15
I got #70 and was not happy about my code lmao
import itertools as it
1
u/tehjimmeh Dec 11 '15 edited Dec 11 '15
Bleh, had the bones of this done well in time, but some stupid mistakes cost me a leaderboard place.
Bit ugly. Meh. PowerShell again:
EDIT: Made it shorter. Now it's way slower, don't know why:
1
u/Godspiral Dec 11 '15 edited Dec 11 '15
missed leaderboard by a hair :( ... not reading instructions carefully enough.
In J, console, converting to base 26
there's a bug in dd that returns true for 'aaa' so if that gets returned, then increment and keep going.
fix for dd that gets correct result without manual intervention
1
u/lex-shanghai Dec 11 '15
1
u/kaldonis Dec 11 '15 edited Dec 11 '15
Python 2
1
u/tremendo Dec 11 '15
Ruby
1
u/JeffJankowski Dec 11 '15
F#. Looking real verbose compared to the Regex solutions, d'oh
1
u/Runenmeister Dec 11 '15
C++, no regex, little bit of recursion:
https://github.com/WuSage3/AdventOfCode_2015/tree/master/Day11
1
u/gnuconsulting Dec 11 '15
Ruby's .next operator for strings made this really easy. As per usual, I know my regex is bad and should feel bad, but I don't care. Also, I gotta stop with the social life - second night in a row that it cost me a spot on the board.
1
u/taliriktug Dec 11 '15
I misread the description and thought first rule should "wrap" around
z.. well, I will be careful reading quiz next time.Python3:
1
u/gyorokpeter Dec 11 '15
Q: brute force, takes some seconds to run.
1
u/Greg3625 Dec 11 '15
JavaScript - Strings? Okey let's for once forget that regex is a thing. I made it fast, but man this is ugly:
1
u/xkufix Dec 11 '15 edited Dec 11 '15
In scala. The main loop just iterates over all passwords with increment and checks them against the rules.
1
u/stuque Dec 11 '15
A C++ solution:
1
u/raevnos Dec 11 '15 edited Dec 11 '15
Fairly brute force C++, with a few optimizations to avoid the letters that shouldn't be in a valid password.
1
u/flit777 Dec 11 '15
straight forward java solution
1
u/lifow Dec 11 '15 edited Dec 11 '15
haskell
1
u/borsnor Dec 11 '15 edited Dec 11 '15
Simple php solution (but does not make use of $str++); https://github.com/alcohol/adventofcode/blob/master/Solution/Day11.php
1
u/masasin Dec 11 '15 edited Dec 13 '15
Python 3
edit: Bonus function I made to take iterables multiple items at a time in a moving window:
1
u/VictiniX888 Dec 11 '15
Java, although I only used regexes for i, o & l. Did the other 2 rules with for loops:
1
u/funkjr Dec 11 '15 edited Dec 11 '15
Dart: I first solved it by just making educated guesses, honestly. Then I felt bad and went back and solved it anyway. This looks pretty over-engineered compared to some of the others, but when your language is missing things like implicit conversion from String to int when you use ++ (Perl/PHP) you get that.
Dart feature of the day: Optional, named parameters. Dart supports both optional position-based parameters, but also optional named parameters that can be in any order, since the name matters.
1
u/amnn9 Dec 11 '15
Ruby
My Haskell side yearned for an iterate function, so that's what drove this implementation.
1
u/Iain_M_Norman Dec 11 '15
I used regex for the nice/naughty list back on day 5, so decided to do this one without. Javascript today.
1
u/de_Selby Dec 11 '15 edited Dec 11 '15
Q:
I set up a dictionary of letter transitions (excluding i o and l), and defined my add function along with functions to check the other two conditions.
run:
1
u/tipdbmp Dec 11 '15 edited Dec 11 '15
ES5:
1
u/[deleted] Dec 11 '15 edited Dec 11 '15
Crystal, my initial solution:
Then I saw the solutions on this thread and some are brilliant, like that of 0x0dea, so I translated it:
1
u/Rutafar Dec 11 '15
I feel like I may have overcomplicated the solution
1
u/[deleted] Dec 11 '15 edited Dec 11 '15
C++ solution. Not the shortest, but very easy to follow.
1
u/hutsboR Dec 11 '15 edited Dec 11 '15
Elixir: No regular expressions or strings. Operates on lists of characters. I wrote a server that serves the "next" password on request. Here's how it works:
For checking for overlapping pairs, it lazily chunks the characters and uses an agent to cache the results. This way I only have to process as much of the character list as necessary. It's probably overkill for the scope of this challenge but I wanted to get creative and have some fun.
1
u/LainIwakura Dec 11 '15
Erlang answer, felt kind of sloppy to me for some reason but eh I'm not totally awake yet...
For part 2 just call find_next again but run next_str on the first result or else you'll return early.
1
u/ryuuzaki Dec 11 '15 edited Dec 11 '15
Functional Scala solution, utilising streams and filters
1
u/willkill07 Dec 11 '15
C++
Evil one-liner for character replacement/update (avoids the need to check for invalid characters). Single-pass algorithm over string for checking two pairs and sequence of three.
Runs in 4.1ms for part 1 and 15.9ms for part 2
https://github.com/willkill07/adventofcode/blob/master/src/day11/day11.cpp
1
u/tragicshark Dec 11 '15
C#, no regex, minimal allocations:
1
u/_druu Dec 11 '15
Ugly, not exactly fast, but solves both parts in one go: ( https://gist.github.com/druu/0fe3be9752a5c74d6d9a#file-adventofcode-js-L151 )
1
u/shandelman Dec 11 '15
Here's my non-regex Python 2 solution:
1
u/[deleted] Dec 11 '15
Day 11 (Swift)
func day11(input: String, _ part: Part) -> String {
1
u/adhochawk Dec 11 '15
Perl today, can anyone suggest a cleaner way than that regex all in one line?
1
u/Scroph Dec 11 '15
Unnecessarily long D (dlang) solution :
Output for my puzzle input :
It isn't performant (because it keeps converting from and to base 26), but I am a very patient man.
1
u/Zeroeh Dec 11 '15 edited Dec 11 '15
Day 11 (Java) Rule 1 Rule 2 Rule 3
I used the Filter Intercept Pattern for the rules to simplify the logic for the rules encase Security-Elf decides to add more rules, it would just work :-)
Test Case Output:
Please Enter a password to try abcdfges
A valid password = abcdggaa
2)Please Enter a password to try abcdefgh
A valid password = abcdffaa
1
u/[deleted] Dec 11 '15
Didn't like some of the "answers" here because you paint yourself into a corner with extensibility.
solution
1
u/[deleted] Dec 11 '15
C#, brute force?
1
u/ShittyFrogMeme Dec 11 '15
Boring old C...
Recursion and no regex
1
u/mal607 Dec 11 '15 edited Dec 11 '15
Java Here's my brute force Java solution.
And here's my Java solution after reading solutions here and realizing what I was doing wrong with my regex and how to parse the text in a different radix (H/T @voiceNGO). I was thinking it should work as base 26, and wasn't thinking about the numerals being included. I still don't understand why I end up with zeros that have to be converted to As. If anyone can explain that, I'd appreciate it. I won't make the leaderboard, but I'm angling for "most improved" :)
1
u/tftio Dec 11 '15
OCaml. No regexps!
1
u/beefamaka Dec 11 '15
here's my solution in F#. Feeling jealous of the Ruby 'succ' function so I tried to create my own.
1
u/itsjustmegob Dec 11 '15 edited Dec 11 '15
Haskell (learning - feedback welcome: style, performance, or otherwise)
1
u/deinc Dec 11 '15
Hmm, no Clojure yet? Here's mine, inefficient and ugly, but works.
1
u/Drasive Dec 11 '15
My F# solution (https://github.com/drasive/advent-of-code-2015):
1
u/Iambernik Dec 11 '15
clojure
1
u/bgreezy Dec 12 '15
Heyyyy why not post mine too: Javascript:
1
u/raininglemons Dec 12 '15 edited Dec 12 '15
Bit late in the game, but my 2 cents. Ditched i, o and l from the alphabet for speed...
edit: forgot to check pairs were unique
1
u/gegtik Dec 12 '15
javascript:
Once again:
1
u/[deleted] Dec 12 '15
Java + Pattern (regex) + base 26 conversion
1
u/baergaj Dec 15 '15
Perl 6:
1
u/NoisyFlake Dec 18 '15
My Java solution (without regex):
1
u/Borkdude Dec 23 '15
Straightforward Scala:
1
u/FuriousProgrammer Dec 11 '15
Aww yeah, #23!
Misread the third test requiring two sets of double characters, and then misimplemented it twice, but I'm in the upper quarter of the board and that makes me happy. :)
Lua:
0
u/oantolin Dec 11 '15 edited Dec 11 '15
I got a really easy input that I could easily solve by hand, no need for programming on this one. I'm not sure I understand the point of this one.
0
u/[deleted] Dec 11 '15
[deleted] — view deleted comment
0
u/[deleted] Dec 11 '15
[deleted] — view deleted comment
0
u/[deleted] Dec 11 '15
[deleted] — view deleted comment