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
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:

Adbot
ADBOT LOVES YOU

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

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.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Been trying to learn Pandas for work. 2016 Problem #3

import pandas as pd

Part 1:
df = pd.read_csv('./data_A.txt', header=None, sep=r"\s+")
df.values.sort()
df.loc[(df[0] + df[1] > df[2])].count()[0]


Part 2:
df2 = df[0].append([df[1],df[2]])
df2_list = (list(df2.values))
new_groupings = [(x,y,z) for x, y, z in zip(*[iter(df2_list)]*3)]
tf = pd.DataFrame(new_groupings)
tf.values.sort()
tf.loc[(tf[0] + tf[1] > tf[2])].count()[0]

Hughmoris fucked around with this message at 02:08 on Dec 4, 2016

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Pandas for Problem #4:


import pandas as pd
from collections import Counter

def top_five(x):
d = dict(Counter(''.join(sorted(x))))
s = sorted(d.items(), key=lambda x: (-x[1], x[0]))
return (''.join([i[0] for i in s[:5]]))

df = pd.read_csv('./raw_data_4A.txt', names=["raw_strings"])
df["checksum"] = df["raw_strings"].str.extract('\[(\w+)\]')
df["sectID"] = df["raw_strings"].str.extract('-(\d+)\[')
df["string"] = df.raw_strings.str[:-11]
df.drop('raw_strings', axis=1, inplace=True)
df["string"] = df["string"].str.replace('-','')
df.sectID = pd.to_numeric(df.sectID)

df["top_five"] = df["string"].apply(top_five)
df.loc[df.checksum == df.top_five]['sectID'].sum()

Adbot
ADBOT LOVES YOU

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

Pointsman posted:

Banging through this year's in Erlang: https://github.com/ctbaran/adventcode2016
And doing last year's in Haskell (read a ton of Haskell, written considerably less): https://github.com/ctbaran/adventcode2015

Check out my awful code (or don't :) ).

Good stuff. I've tried my hand at Haskell a couple of times but it just doesn't stick for me.

  • Locked thread