Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
:siren: And now, for the grand finale... Day 25! :siren: [ goto ]

Think you know code? Want internet points on a leaderboard? Check out Advent of Code!

quote:

Advent of Code is a series of small programming puzzles for a variety of skill levels. They are self-contained and are just as appropriate for an expert who wants to stay sharp as they are for a beginner who is just learning to code. Each puzzle calls upon different skills and has two parts that build on a theme.

My buddy who created this crazy thing is equal parts genius and madman, and now he's sharing his insanity with you. Whether you're looking for an excuse to learn a new language or brush up on a rarely-used language (or stick to your tried-and-true), the Advent of Code will give you a run for your money.

So, let's get this Advent party started. Every midnight I'll (try to remember to) post the daily challenge summary. It's up to you to make 'em go!

--- Day 1: Not Quite Lisp ---

quote:

Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by stars, and he's fresh out! To save Christmas, he needs you to collect fifty stars by December 25th.

Collect stars by helping Santa solve puzzles. Two puzzles will be made available on each day in the advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

daggerdragon fucked around with this message at 06:03 on Dec 25, 2015

Adbot
ADBOT LOVES YOU

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 2: I Was Told There Would Be No Math ---

quote:

The elves are running low on wrapping paper, and so they need to submit an order for more. They have a list of the dimensions (length l, width w, and height h) of each present, and only want to order exactly as much as they need.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
I'm on it, elves!

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 3: Perfectly Spherical Houses in a Vacuum ---

quote:

Santa is delivering presents to an infinite two-dimensional grid of houses. [...] However, the elf back at the north pole has had a little too much eggnog, and so his directions are a little off, and Santa ends up visiting some houses more than once. How many houses receive at least one present?

Spraynard Kruger
May 8, 2007

Hey, I went to college with this guy, that's neat. Gonna give it a try!

IronDoge
Nov 6, 2008

Ooh, I'm always up for some coding challenges.

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
Oh good, the forums are finally back up. Here's day 4's belated post.

--- Day 4: The Ideal Stocking Stuffer ---

quote:

Santa needs help mining some AdventCoins (very similar to bitcoins) to use as gifts for all the economically forward-thinking little girls and boys.

IronDoge
Nov 6, 2008

A bunch of people are putting up visualizations of the Day 3 answer. Spoilers obviously.
http://snk.digibase.ca/advent3.html

It's pretty neat looking.

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

On it! I'm always indecisive about whether I want to use these as opportunities to try to work with a new programming language or not. Usually I start with trying to write it in [Flavor Of The Week], bang my head on the desk for an hour, then give up and write it in Python in 5 minutes.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
I had fun doing all four days in node. They're neat little simple puzzles. Love that visualization thanks for posting Iron Doge.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

chutwig posted:

On it! I'm always indecisive about whether I want to use these as opportunities to try to work with a new programming language or not. Usually I start with trying to write it in [Flavor Of The Week], bang my head on the desk for an hour, then give up and write it in Python in 5 minutes.

Yeah, I enjoy little puzzles like these as I try to learn a new language. Currently fiddling with Perl 6, and just got my first two stars. :3:

Volguus
Mar 3, 2009
This Day 4 challenge, I have the feeling that I should have done it by actually knowing how MD5 works (very well) and then figuring out what kind of message would produce what kind of output. But then I just brute forced it, parallelized it and called it a day. I feel dirty. Then again, it is the simplest solution, but ...

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 5: Doesn't He Have Intern-Elves For This? ---

quote:

Santa needs help figuring out which strings in his text file are naughty or nice.

ephphatha
Dec 18, 2009




Volguus posted:

This Day 4 challenge, I have the feeling that I should have done it by actually knowing how MD5 works (very well) and then figuring out what kind of message would produce what kind of output. But then I just brute forced it, parallelized it and called it a day. I feel dirty. Then again, it is the simplest solution, but ...

I didn't feel that dirty doing it that way, my slow rear end perl script took less than a second to do part 1 and about 3 seconds to do part 2. Only crashed my terminal once when I called the script with no input and triggered a warning on every iteration... This string parsing challenge was pretty simple to do with perls regex engine as well.

Is there any way to change what link is associated with your name to something other than the default for the login service you used? I used Google as my id provider but I'd rather link my github profile than my g+ profile if I end up making it onto the leaderboard.

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

Day 5: REGULAR EXPRESSIONS :arghfist::downs:

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.

Ephphatha posted:

I didn't feel that dirty doing it that way, my slow rear end perl script took less than a second to do part 1 and about 3 seconds to do part 2. Only crashed my terminal once when I called the script with no input and triggered a warning on every iteration... This string parsing challenge was pretty simple to do with perls regex engine as well.

Is there any way to change what link is associated with your name to something other than the default for the login service you used? I used Google as my id provider but I'd rather link my github profile than my g+ profile if I end up making it onto the leaderboard.

My buddy is not willing to screw with the logins while the Advent is running since we're trying to make sure that the server (and code) stay stable for the entire duration of the Advent.

However, you can create another account using your Github profile, re-use your existing code (you did save it, right?) to solve up to today's puzzle, and only use that one to solve future puzzles from now on if you want to try to make it on the leaderboard.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I've looked at it every which way but I'm clueless on how to go about solving Day 4. I have a basic gist of hexadecimals but I'm not understanding MD5 hashes and what is needed to solve the problem. Anyone able to break the problem down in a different way?

*I'm trying to solve this using Perl 6.

Hughmoris fucked around with this message at 01:51 on Dec 6, 2015

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

Hughmoris posted:

I've looked at it every which way but I'm clueless on how to go about solving Day 4.
*I'm trying to solve this using Perl 6.

Here is how I solved it in Python: https://github.com/erhudy/adventofcode-solutions/blob/master/problem4.py

Basically you need to concatenate the given key to the string form of a monotonically increasing integer, hash it with whatever MD5 function Perl 6 provides that will give you back a string, and check the start of the string for "00000". If not, increment the integer and try again. E.g., if your key is "abcdef", you would MD5 hash "abcdef0", check the hex output for a start of "00000", then try "abcdef1", "abcdef2", and so forth.

Googling around, it looks like actually doing the hashing in Perl 6 might be a pain. You can shell out and use md5/md5sum (just be sure to strip newlines):
code:
In [3]: hashlib.md5(b'blah').hexdigest()
Out[3]: '6f1ed002ab5595859014ebf0951522d9'
code:
$ echo -n "blah" | md5   
6f1ed002ab5595859014ebf0951522d9

chutwig fucked around with this message at 04:04 on Dec 6, 2015

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 6: Probably a Fire Hazard ---

quote:

Because your neighbors keep defeating you in the holiday house decorating contest year after year, you've decided to deploy one million lights in a 1000x1000 grid.

Furthermore, because you've been especially nice this year, Santa has mailed you instructions on how to display the ideal lighting configuration.

Hughmoris
Apr 21, 2007
Let's go to the abyss!

chutwig posted:

Here is how I solved it in Python: https://github.com/erhudy/adventofcode-solutions/blob/master/problem4.py

Basically you need to concatenate the given key to the string form of a monotonically increasing integer, hash it with whatever MD5 function Perl 6 provides that will give you back a string, and check the start of the string for "00000". If not, increment the integer and try again. E.g., if your key is "abcdef", you would MD5 hash "abcdef0", check the hex output for a start of "00000", then try "abcdef1", "abcdef2", and so forth.

Googling around, it looks like actually doing the hashing in Perl 6 might be a pain. You can shell out and use md5/md5sum (just be sure to strip newlines):
code:
In [3]: hashlib.md5(b'blah').hexdigest()
Out[3]: '6f1ed002ab5595859014ebf0951522d9'
code:
$ echo -n "blah" | md5   
6f1ed002ab5595859014ebf0951522d9

Thanks for the tips. I'm going to take another look at it.

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 7: Some Assembly Required ---

quote:

This year, Santa brought little Bobby Tables a set of wires and bitwise logic gates! Unfortunately, little Bobby is a little under the recommended age range, and he needs help assembling the circuit.

IronDoge
Nov 6, 2008

Well I forced myself to learn regex this weekend, so I suppose I got something of all this. Took this opportunity to mess around with Python as well.

Vitamin Me
Mar 30, 2007

Did the first 6 tests in PHP today :banjo:

Will be looking around for other solutions to see how well my code designs are

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 8: Matchsticks ---

quote:

Space on the sleigh is limited this year, and so Santa will be bringing his list as a digital copy. He needs to know how much space it will take up when stored.

Santa needs to get a goddamn Kindle or something for that list of his...

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer
I've been solving these with Haskell. Mostly it's been going well, but my Day 6 solution was very inefficient because I implemented it with the Data.Array module and couldn't figure out how to only run through the indices that were actually changed with the available functions, so I ended up updating the entire array every time. I probably should've used a mutable 2D array of some sort instead, but my initial solution was barely fast enough to be acceptable so I didn't bother.

Day 7 tripped me up repeatedly because I didn't understand the question correctly:
- At first I thought a wire would always already have a signal at the time it's used to provide a signal for another wire, mostly because that was the case in the example. Actually looking at the input cleared up that misconception.
- Then I for some reason got it into my head that if a wire doesn't have a signal when it's used it should be treated as having the value 0. I pulled this out of thin air, and it was obviously wrong.
- At last I realized that you're supposed to go through the list repeatedly until all the signals are turned on (or build some sort of expression tree by going backwards, I guess), so I changed up my algorithm and got a plausible result, but it was still wrong.
- Then I spent another half hour or so until I finally realized I had been rotating the bits instead of shifting them. :v:

I found Day 8 to be simpler in comparison. I used the very awesome Parsec library to parse the strings and got the right result pretty quickly. Using regex or even just simple string matching would probably be just as easy, but they're not as cool as Parsec.

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.

LOOK I AM A TURTLE posted:

I found Day 8 to be simpler in comparison.

We've noticed that Day 8 was polarizing in that players either immediately understood and knew how to solve it (like you) or had absolutely no clue where to even start. It's fascinating.

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 9: All in a Single Night ---

quote:

Every year, Santa manages to deliver all of his presents in a single night.

This year, however, he has some new locations to visit; his elves have provided him the distances between every pair of locations. He can start and end at any two (different) locations he wants, but he must visit each location exactly once. What is the shortest distance he can travel to achieve this?

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 10: Elves Look, Elves Say ---

quote:

Today, the Elves are playing a game called look-and-say. They take turns making sequences by reading aloud the previous sequence and using that reading as the next sequence.

daggerdragon fucked around with this message at 05:59 on Dec 11, 2015

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



daggerdragon posted:

(you did save it, right?)

Haha, I actually got up to 7 in the Chrome console and just closed it when I was done. Dunno if I feel like attempting it in there, though.

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 11: Corporate Policy ---

quote:

Santa's previous password expired, and he needs help choosing a new one.

invision
Mar 2, 2009

I DIDN'T GET ENOUGH RAPE LAST TIME, MAY I HAVE SOME MORE?
You ever wrote some code, then in the middle of it went "I'm dumb", except you instead of doing it correctly you just beat it with a hammer and pray for the best?

code:
namespace Day3_House_In_Vacuum
{
    class Program
    {
        static void Main(string[] args)
        {
            string inputstring = String.input;
            int length = inputstring.Length;
            int[ , , ] map = new int[length*2, length*2, 1];//'cause negative indexes don't work and memory is cheap.
           
            map[0, 0, 0] = 1; //since we've been here already.        
            int counter = 1; //for first move.
            int character = 0; //for counting characters in the string
           
            int x = 8192; //'cause we're gonna hit a negative index otherwise
            int y = 8192; //and because I'm a lazy jerk
           

            while (character < length)
            { 
           	char currentchar = inputstring[character];
            	Console.WriteLine(currentchar.ToString());
           	if (currentchar.ToString().Contains("^")) 
            	{                
                    x += 1; //move north
                    Console.WriteLine("north " + x);               
                    if (map[x, y, 0] == 0)
                    {
                        counter++;
                    }                               
                map[x, y, 0] = 1;                
                }
             }    

invision fucked around with this message at 12:17 on Dec 11, 2015

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 12: JSAbacusFramework.io ---

quote:

Santa's Accounting-Elves need help balancing the books after a recent order. Unfortunately, their accounting software uses a peculiar storage format. That's where you come in.

Xarn
Jun 26, 2015

After I finally gave in and used regexes for a problem, the second part kinda hurt.

So I just created a bracket matcher and deleter. Sometimes everything IS a nail. :v:

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 13: Knights of the Dinner Table ---

quote:

In years past, the holiday feast with your family hasn't gone so well. Not everyone gets along! This year, you resolve, will be different. You're going to find the optimal seating arrangement and avoid all those awkward conversations.

Spraynard Kruger
May 8, 2007

I pretty much copied my solution from Day 9 for this one, kinda disappointing.

I still need to figure out Day 7 though, drat wires. :argh:

daggerdragon
Jan 22, 2006

My titan engine can kick your titan engine's ass.
--- Day 14: Reindeer Olympics ---

quote:

This year is the Reindeer Olympics! Reindeer can fly at high speeds, but must rest occasionally to recover their energy. Santa would like to know which of his reindeer is fastest, and so he has them race.

elite_garbage_man
Apr 3, 2010
I THINK THAT "PRIMA DONNA" IS "PRE-MADONNA". I MAY BE ILLITERATE.
Did the first 3, then looked to see what lay ahead and got to day 7 and checked the input...that fuckin' took the wind out of my sails hahaha. Even the following days seem easy in comparison.

After finals this week I'll be knocking more of these out. Thanks for sharing.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
I spent so much time on 9 to get a recursive thing to work without crapping on me. Turned out sometimes js really fucks with its variables. Nothing a judicious use of var can't fix, but I still don't know where exactly it went wrong. Bah humbug.

For 7 I couldn't get my head around it until I figured out that the value of a wire was an equation with variables and if you knew the value of those variables you could substitute the equation for the resulting value. Keep looping over the wires until solved. If I had a cs background I'd probably create a graph from all the rules and walk it top to bottom, but eh close enough!

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



KARMA! posted:

I spent so much time on 9 to get a recursive thing to work without crapping on me. Turned out sometimes js really fucks with its variables. Nothing a judicious use of var can't fix, but I still don't know where exactly it went wrong. Bah humbug.

For 7 I couldn't get my head around it until I figured out that the value of a wire was an equation with variables and if you knew the value of those variables you could substitute the equation for the resulting value. Keep looping over the wires until solved. If I had a cs background I'd probably create a graph from all the rules and walk it top to bottom, but eh close enough!

I think that's what I'm going to have to do. My first attempt has been to transpile it to JS (bn RSHIFT 2 -> bo => function bo_wire(){return bn_wire() >> 2;}) and let the interpreter figure out the graph for me but that's so loving slow I left it running all day and it hadn't finished, which I expected problem 5 to do, but nooo - that took whole seconds. Second attempt was changing the transpiler to emit F# and then try to sort the calls to make it a valid F# program (single-pass compilers in tyool 2015!), but I can't get that second part of that right and doing it by hand? Bleh :(

Would have been done with this in an hour if my first attempt worked as well as I'd hoped.

Adbot
ADBOT LOVES YOU

Xarn
Jun 26, 2015
Why is the site down just as I decided to procrastinate and code? :v:

Also 9 (and 14, duh) is the one that I haven't done yet. Its not hard per se, it will just take some annoying boilerplate I don't care for writing, especially since I want to do it properly. (Construct an ad-hoc graph and then solve it by going from the leaves.)

  • Locked thread