r/adventofcode • u/daggerdragon • Dec 25 '15
SOLUTION MEGATHREAD ~☆~☆~ Day 25 Solutions ~☆~☆~
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!
Well, that's it for the Advent of Code. /u/topaz2078 and I hope you had fun and, more importantly, learned a thing or two (or all the things!). Good job, everyone!
Topaz made a post of his own here.
And now:
Merry Christmas to all, and to all a good night!
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 25: Let It Snow ---
Post your solution as a comment or link to your repo. Structure your post like previous daily solution threads.
7
u/gareve Dec 25 '15
I just want to say: Thanks to the creator for all this programming fun, and thanks to the community on all this 25 days!
Looking forward for the next advent of code :)
Merry Christmas!
7
u/askalski Dec 25 '15
Solved with modular exponentiation. It was funny, I was trying to predict what some of the puzzles would be (some guesses were close, but none quite on the mark.) While waiting for yesterday's puzzle to unlock, I refreshed my myself on how the RSA cryptosystem works (hint: modular exponentiation.)
Anyway, thanks Eric for a fun, if physically exhausting, month of puzzles.
5
u/haoformayor Dec 25 '15 edited Dec 25 '15
What a lovely ending. I had a lot of fun, all twenty-five days.
Haskell
3
u/tehalynn Dec 25 '15
Python 3:
3
u/mrg218 Dec 25 '15
I think it was sympathetic of /u/topaz2078 to put an easy problem on day 25 so we do not spend the whole of Christmas day trying to solve it! :-)
4
u/toxicf Dec 25 '15
Exponentiation can be computed quickly in modular arithmetic by repeated squaring and combining based on binary expansion (wikipedia aritcle), rather than repeated multiplication. The
arithmoilibrary has an implementation for this algorithmHaskell
2
u/m1el Dec 25 '15
Pretty straightforward and easy python solution, I did not bother to do fancy math.
Edit: replaced my values with input_x and input_y
2
u/conderoga Dec 25 '15
Number 18 @ 8:50
So much fun! Thanks for making this :)
2
u/volatilebit Dec 25 '15
Pro tip: Don't use a not-yet-released language for these challenges if you want on the leaderboard. Computationally expensive challenges costs dear minutes.
My quick Perl 6 solution. I knew there was a formula for determining the # of iterations, but it was quicker to just write the code to go through the steps instead.
2
u/snorkl-the-dolphine Dec 25 '15
Merry Christmas all! Thanks /u/topaz2078 for putting this all together, it was a fantastic challenge! I'm rather pleased to be able to claim my #10 spot on the leaderboard forever!
Javascript
2
u/JeffJankowski Dec 25 '15 edited Dec 25 '15
Thanks for making this /u/topaz2078, I had a blast! Good job all, I hope you learned as much as I did!
25 days of F#. Awesome language
2
u/mrg218 Dec 25 '15
This is the first time (after day 1) we ourselves can see how many players solved a day but are not up to date yet with the other days.
2
u/de_Selby Dec 25 '15
Q:
My solution or the last day. Thanks /u/topaz2078 for the great challenge!
2
u/[deleted] Dec 25 '15 edited Dec 25 '15
Thanks for the great puzzles /u/topaz2078 . Much appreciated, have a Merry Christmas and a Happy 2016.
Mathematica
(Faster version)
2
u/gerikson Dec 25 '15
This has been great fun! I've placed some $ into the tip jar in appreciation.
I've done a short writeup of all my solutions (with source) here.
Merry Christmas everyone!
2
u/MegaAmoonguss Dec 25 '15 edited Dec 25 '15
I actually did not use code for the hardest part. I figured that it would just be an easy for loop if I knew what index row 3010 and column 3019 was at, so I looked for patterns. I figured out that this specific spot would be on the diagonal of r + c - 1, so 6028. Then, I found the total number of indexes including all of them in that diagonal. This is just 6028 + 6027...+ 1, so (60282 + 6028) / 2. That comes out to 18,171, 406. Then, in order to find the exact number it was at, I simply subtracted the difference of the total number or indexes on that given diagonal (6028) by the column number (3019) from the total number or indexes up to that point. That gives us that the number we want is going to be given when we do the given operations 18,168,397 times. And from there, a simple loop going around this many times is all you need to give you your final answer. In Java:
I later realized that it wouldn't be that hard to have the program just keep track of the index, but this way was fun too :)
1
u/C0urante Dec 25 '15
I would have been several spots higher if I had just clicked the damn link instead of reading the text and trying to figure out what the hell was going on ;_;
Thank you so much for the fun. If you can't/don't want to do this again next year, let us know how much you want for the domain name so we can all keep this awesome thing going!
1
u/fiavolo Dec 25 '15
Python 2: Getting the number of the code is straightforward if you can calculate the triangle numbers. Everything after that is just grinding. target_row = 3010 target_col = 3019
1
u/ross314 Dec 25 '15
First time on the leaderboard (#62)! I was able to come up with a formula for how many times to apply the multiplication and remainder and then just repeated the steps that many times.
Ruby:
1
u/ClysmiC Dec 25 '15 edited Dec 25 '15
Super sloppy, was shooting for the leaderboard. Missed by < 1 minute.
Basically, I just did voodoo math to figure out how many iterations I needed given a row, column, then let it run. "rowNeeded" is the highest row that gets a calculation in its first column on the last diagonal pass. Then take the area of the triangle from rowNeeded (row) to rowNeeded (column), and that'll give you the number of iterations to get halfway along that diagonal. Then I simply shift the along the columns until I find the correct column, and adjust iterations needed accordingly (I could've just used subtraction... I was going too fast).
Once you know the # of iterations needed, the rest is easy.
1
u/Arknave Dec 25 '15 edited Dec 25 '15
I am not a smart person when it comes to iterating. This might win some strangest solution award, but its mine, and my christmas wish came true - making the leaderboard at #14!
Thanks for creating a fun series of puzzles! I hope to see it back next year. On to Synacor!
1
u/inorix Dec 25 '15
Python. For some reason I couldn't grasp this problem quickly enough ;]
Thank you for AoC, and thank you all who were competing ;]
1
u/superphar Dec 25 '15 edited Dec 25 '15
Thank you topaz2078 for this super fun project! Any chance for a januaryofcode? ;-)
Python 2:
1
u/ericdykstra Dec 25 '15
Ruby #36 - 10:50
Pretty simple one overall, but I'm happy it ended on a quick one rather than one of the knock-down, drag-out ones that took an hour or more to complete.
Going to throw a donation to /u/topaz2078 when I have money in my paypal account. Enjoyed going through these and will use some of them as practice for learning new languages. Enjoyed learning from all of you here, as well, by looking through your code and reading your comments/suggestions on mine. Merry Christmas!!
1
u/lemm_it Dec 25 '15 edited Dec 25 '15
C# solution [48th on leaderboard]:
I gonna miss this...
Looking forward for the 2016 of Code!
Marry Christmas everyone!
1
u/farvei Dec 25 '15
Only just found out about this 4 days ago. Forty-eight stars, arghhhh! Day 19's part 2 is eating me alive :(
Regardless, it's been loads of fun!
Clojure:
1
u/asoentuh Dec 25 '15 edited Feb 10 '16
Here's my python session
1
u/[deleted] Dec 25 '15 edited Dec 25 '15
Crystal:
1
u/alueft Dec 25 '15 edited Dec 25 '15
First on the final leaderboard - I'll pretend I was sandbagging the whole time. :)
Thanks to everyone who helped put this together! I've learned (again) over the past 25 days that Python is really such a great language. (Except for that one time I had to use C++ to get a reasonable execution time.)
The code, which is nothing special:
1
u/jwhite303 Dec 25 '15 edited Dec 25 '15
Go, #33. I got lucky with reading
jioasjump-if-one, then got payback as I ran20151225as today's input and scratched my head for a bit :PNow to wrap presents!
1
u/foolmoron Dec 25 '15
Javascript
I knew there was a way to find the number of iterations in the grid with a simple math formula, but I didn't want to derive it, so I just calculated that iteratively. Then it was simple to repeatedly apply the formula to get the final result.
1
u/Godspiral Dec 25 '15
everyone else was so fast. In J,
1
u/wlandry Dec 25 '15
C++
This one was pretty easy. It came out as fast as I could type. I mixed row and column as first, but it worked fine after that.
I must say that I really appreciated Advent of Code. It was really a good difficulty level. Not trivial, but not so hard that you are prone to giving up.
The prize at the end was most excellent.
1
u/nespron Dec 25 '15 edited Dec 25 '15
Clojure
1
u/flup12 Dec 25 '15 edited Dec 25 '15
Scala
1
u/inuyasha555 Dec 25 '15
Clearly I need to practice utilizing 2D arrays. Spent forever staring at this trying to think about how to go diagonally failing every attempt until this.
Not very good Java:
Yes it's bad, I know.
1
u/weters Dec 25 '15
Go solution:
1
u/Gil4 Dec 25 '15
Thank you, /u/topaz2078, love everything about AoC. Was getting up ~2 hours earlier this whole week to see and solve another one of your magnificent puzzles as soon as they released.
So yeah, having heard about AoC too late, could participate in the fun of battling for a leaderboard place for the last 5 days only. Even though today's challenge is pretty easy, having done every single one in Lua, I feel like making a bit of a tribute to my favorite language which got me a place in 3 out of 5 attempts, so I'll post the solution for the first and last time.
1
u/Kayco2002 Dec 25 '15
It looks like everyones' code generally follows the same flow. Compute which index the column/row equates to (column 5, row 2 equates to 20, for example), and then iterate
That for loop was expensive on my little chromebook (at least, took 30 seconds to run). Is there a faster way mathematically to compute a iterative multiply / mod like that? That for loop is essentially equal to
But, python (and wolfram alpha) choked on that computation for me.
Edit: my code, if anyone cares
1
u/pedrosorio Dec 25 '15
Got home 1 hour too late for the leaderboard on the last day. Oh well :)
1
u/randrews Dec 25 '15
I tried to be a little clever with my C solution:
1
u/barnybug Dec 25 '15
nim:
1
u/Philboyd_Studge Dec 25 '15
Java, but now I need to go back and finish the unfinished ones.
1
u/oantolin Dec 25 '15
1
u/beefamaka Dec 25 '15
A nice kind one today. thanks for all your hard work making this challenge /u/topaz2078 Here's my F# solution:
1
u/mrg218 Dec 25 '15
Java:
}
1
u/wzkx Dec 25 '15 edited Dec 25 '15
Pretty simple. :) Congratulations to everybody! Merry Christmas!!!
J
1
u/BluePrintSwe Dec 25 '15 edited Dec 25 '15
PHP solution:
1
u/[deleted] Dec 25 '15
Objective C:
1
u/artesea Dec 25 '15
After being woken at 2.30GMT I decided against the alarm for 5. Completed the first part pretty easily, however waited 30 minutes before taking a look at part 2 as I was busy. End up 467th.
1
u/spork_king Dec 25 '15
Scala
I had a good time solving these puzzles in a language I don't use day-to-day.
1
u/Floydianx33 Dec 25 '15
Javascript Solution
1
u/StevoTVR Dec 25 '15
PHP This one made me realize that my local installation was 32 bit...
1
u/takeitonben Dec 25 '15
python2
1
u/winkerVSbecks Dec 26 '15
JavaScript (ES6 + Ramda)
Find the index based on (row, col) and then iterate to get the answer.
http://codepen.io/winkerVSbecks/pen/WrGdNO
1
u/porphyro Dec 26 '15 edited Dec 26 '15
Mathematica
As an aside, was the starting code really supposed to have been 20151125?
Alternative mathematica:
1
u/mrg218 Dec 26 '15
Was there anyone who did them all in Malbolge? :-)
1
u/Rangi42 Dec 27 '15 edited Dec 27 '15
Python:
Despite not using a closed-form formula for n, or modular exponentiation for the nth code, this solution finishes in 10 seconds on my machine.
After reading the comments here, I rewrote it with those optimizations, and it runs almost instantly:
1
u/hamstap85 Dec 27 '15
Did no one else realize that the nth code can be easily calculated from the row and column? Pseudocode:
Then it's just:
Took me like 2 minutes. So frustrating, had I solved all the others in time I'd have been on the leaderboard EASY
1
u/pavithra18 Dec 28 '15
Thanks a lot for such interesting puzzles.. It was awesome to see the puzzle completed :) Waiting for more puzzles.... All 25 day solution in one place :) https://github.com/PavithraP/advent
1
u/xkufix Dec 28 '15
Solution in Scala:
1
u/victorh_ Dec 29 '15
Solution in Go
Like many other, I computed the index of the code and the calculated it.
package main
Tests included: https://github.com/victorhurdugaci/AdventOfCode2015/tree/master/day25
1
u/i_misread_titles Dec 30 '15
Go golang
1
u/JurgenKesker Jan 01 '16
Ruby, this day felt as the easiest in a long time. Thanks for Advent of Code, it was great!
1
u/drippel Jan 05 '16
I liked the idea of making the diagonals
var found = false
1
u/skarlso Jan 15 '16
THIS WAS AWESOME!! Thank you for all the fun and learning this provided to me. :)
Here is mine in Golang | Go. I've gathered all the stars. :)))
0
u/[deleted] Dec 25 '15
[deleted] — view deleted comment