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
Volguus
Mar 3, 2009

chutwig posted:

Finally had time to return to the problems after a busy December and restart all the way back at problem 7. Having it laid bare that I'm a systems programmer with little knowledge of algorithms is teeth-gritting sometimes, but that makes it all the more gratifying when I get the solution.

Welcome, you're gonna have a lot of fun (until Day 19, drat that day). But, I'm just curious, what does "systems programmer with little knowledge of algorithms" means? From what I know, systems programming still is programming (with a different focus), where algorithms are just as prevalent and as important (if not more so) than application programming.

Adbot
ADBOT LOVES YOU

chutwig
May 28, 2001

BURLAP SATCHEL OF CRACKERJACKS

Volguus posted:

Welcome, you're gonna have a lot of fun (until Day 19, drat that day). But, I'm just curious, what does "systems programmer with little knowledge of algorithms" means? From what I know, systems programming still is programming (with a different focus), where algorithms are just as prevalent and as important (if not more so) than application programming.

Sorry, I don't mean systems like low level C/assembly guy. I mean I'm the sysadmin who knows Python who winds up gluing other projects together for deployments, monitoring, that kind of stuff. Describing it as "systems programming" was not the right choice of words.

chutwig fucked around with this message at 03:08 on Dec 28, 2015

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
I just found this, I'm trying to day 4 in Haskell, but it's taking over ten minutes to do part one and it's only into the 41,000,000s for some reason.


{-# LANGUAGE OverloadedStrings #-}

import Crypto.Hash.MD5 as MD5
import Data.ByteString.Char8 ()
import Data.ByteString.Char8 as BS

import Debug.Trace


pickBy :: (a -> Bool) -> [a] -> a
pickBy p (x:xs)
| p x = x
| otherwise = pickBy p xs
pickBy _ [] = undefined


main =
do
let input = "blahblah"

let possible = Prelude.map (\n -> (BS.pack $ input ++ show n, n) ) [1..]

let (_, n) = pickBy (\(str, n) -> traceShow n $ (BS.take 5 $ MD5.hash str) == "00000") possible

print n

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
The question is asking you to check the initial digits of the hexadecimal encoding of the hash output.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
So far this has been putting my reading comprehension skills to the test more than my coding skills.

kazoosandthings
Dec 6, 2004

In order to join the pirate crew,
you must prove yourself on the kazoo.
It's happening again! I didn't make the leaderboard on the first challenge but I'm going to try my speedy luck again tonight. This year I am aiming to solve in SQL to the extent possible. Problem 1 this year seems about as challenging as problem 2 last year -- will things prove twice as hard overall?

Munkeymon
Aug 14, 2003

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



Aww hell yeah - I might even have time to finish this year, heh

Erwin
Feb 17, 2006

I've been doing a few of the days that I never finished last year in anticipation of 2016 starting. Did last year's in Python, doing this year's in Go.

Volguus
Mar 3, 2009

Erwin posted:

I've been doing a few of the days that I never finished last year in anticipation of 2016 starting. Did last year's in Python, doing this year's in Go.

One guy did yesterday's challenge in brainf*ck: https://www.reddit.com/r/adventofcode/comments/5g1cx1/spoilers_2016_day_1_brainfck_dear_fsm_why_did_i/
Yea ... beat that.

Erwin
Feb 17, 2006


I just came up with Erwin's law:

Given any online programming challenge and ample time, someone will solve it in brainfuck.

whodatwhere
Aug 24, 2013

Do you actually have to log in with one of the mentioned methods to get the second part of each day's puzzle?

e: guess you have to log in to do any of it.

whodatwhere fucked around with this message at 19:24 on Dec 2, 2016

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()

kazoosandthings
Dec 6, 2004

In order to join the pirate crew,
you must prove yourself on the kazoo.
Your Python/Pandas looks a bit like how it might look in R, with the data frame subsetting and filtering and whatnot.

I did part 4 in postgresql; the translate function made the substitution cipher much less painful than I thought it would be at first: https://github.com/piratejon/toyproblems/blob/master/adventofcode/2016/04/04.sql

Pointsman
Oct 9, 2010

If you see me posting about fitness
ASK ME HOW MY HELLRAISER TRAINING IS GOING
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 :) ).

kazoosandthings
Dec 6, 2004

In order to join the pirate crew,
you must prove yourself on the kazoo.
I am Erlang-illiterate and hard pressed to understand your approaches by reading the code alone. I wonder if it will become more clear when the problems are more complex and have to be broken into smaller pieces.

iSurrender
Aug 25, 2005
Now with 22% more apathy!
Getting the wrong answer for today's part 1, despite it working for the example case. Frustrating.

edit: Because Im a sloppy moron. Got it.

iSurrender fucked around with this message at 09:44 on Dec 6, 2016

pepperoni and keys
Sep 7, 2011

I think about food literally all day every day. It's a thing.

iSurrender posted:

Getting the wrong answer for today's part 1, despite it working for the example case. Frustrating.

edit: Because Im a sloppy moron. Got it.

Did you also hard code the string length to 6, without noticing it was 8 in the actual input?

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.

IronDoge
Nov 6, 2008

I never finished last year's stuff, so luckily I have things to do after I finish this year's easy beginning puzzles! I inadvertently solved both parts of the Day 8 today when I made a visualizer to help debug the first part.

My python solutions

Adbot
ADBOT LOVES YOU

Pointsman
Oct 9, 2010

If you see me posting about fitness
ASK ME HOW MY HELLRAISER TRAINING IS GOING

Hughmoris posted:

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

It's alright, I'm bad at Haskell too.

Here's a day 12 solution in Erlang using a zipper (just cause I felt like it), the data structure with the highest simplicity:cool ratio:
https://github.com/ctbaran/adventcode2016/blob/master/ac12/ac12_1.erl

  • Locked thread