/aocg/ - Advent of Code 2018 General #28

Unfiltered edition

Previous Thread adventofcode.com/
>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.
You need to register with an account but you can appear as anonymous.

Private leaderboard join code:

368748-e33dcae3


People who are inactive for 5 days will be kicked, but other leaderboards can be made if desired.

Alternative leaderboard for those waiting for inactives to be kicked from the first:

208834-4a1a9383

Attached: letsalllovelain.gif (1005x742, 2.53M)

Other urls found in this thread:

youtube.com/watch?v=hjGZLnja1o8
geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/
twitter.com/SFWRedditGifs

OH FUCK I HAVE TO BINARY TREE

Reposting cheatsheet
Task
Implement a binary tree where each node carries an integer, and implement:

pre-order,
in-order,
post-order, and
level-order traversal.

Use those traversals to output the following tree:

1
/ \
/ \
/ \
2 3
/ \ /
4 5 6
/ / \
7 8 9
The correct output should look like this:

preorder: 1 2 4 7 5 3 6 8 9
inorder: 7 4 2 5 1 8 6 9 3
postorder: 7 4 5 2 8 9 6 3 1
level-order: 1 2 3 4 5 6 7 8 9

T MINUS TWENTY MINUTES

ITS REAL NIBBA HOURS, WHO UP???

Attached: sansundertale.png (450x272, 178K)

If the puzzle is actually another fucking tree I'll jump off a bridge.

Why the fuck am I always eating when these start? I keep having to rush through my meal. It's not even like it's lunch time of anything, it's fucking midnight.

well you better head out now, you've only got 20 minutes before you need to jump

Unlikely, the order of puzzles is partially determined by the results gained from beta testers on each puzzle, so they shouldn't know the final order even if they did leak.

Why can't you eat in 20 minutes?

I set up 10 mins early so I only have about 5, and it's a big meal that's spicy as fuck.
I tend to eat slower than average to top it off, too.

Stress generally makes you hungry.

Oh, I may have misread that. Whatever. I'm already in the middle of a big meal.

>big meal
>at midnight
y tho

going to sleep hungry is the worst
I'd rather eat at night than any other time of day

NEET lifestyle

Attached: dafuckujustsay.png (576x699, 194K)

>10 minutes until challenge drops
Time to masturbate, fall asleep, and look at the problem tomorrow

Attached: trees.jpg (450x272, 54K)

based

Time to get out of bed, solve a problem, have breakfast, masturbate and go back to sleep

Time again to ruin Filtered's day?

Attached: brainlet.jpg (1414x1010, 100K)

5 minutes, why is the thread so dead?

TRYING NOT TO THINK
ABOUT THIS GIGANTIC SHIT
I HAVE TO TAKE

prepping shit

the brainlets were the only thing keeping this fun desu. most of the people left just post their code when they're done and jerk off to how much they can optimize it

thinking of going to sleep so I can be well rested at work tomorrow.. do I have the willpower to do it?

>implemented a binary tree real quick just in case the oracle user is right

Attached: 1352089148717.jpg (279x242, 23K)

I'm glad you took the time at this late hour.

Have a look at the puzzle, if it's easy as shit, might as well do it now. Otherwise, sleep. I did on day 7.

That user must feel good, knowing that he can make a handful of anons implement a binary tree at will

FUCK

Thanks. I'll be here for the rest of my life.

practicing?

youtube.com/watch?v=hjGZLnja1o8

geeksforgeeks.org/tree-traversals-inorder-preorder-and-postorder/

hey lads, just in time

thanks I was waiting for this

FUCK

FUCK

what the actual fuck is this

Been working on Day 10 for over an hour and its not going well. I am getting the correct time but the output plot is not coming out right.

import math
from scipy.optimize import minimize_scalar
import matplotlib.pyplot as plt

def evalute_position(pos_array):
xmean = pos_array[:,0].mean()
ymean = pos_array[:,1].mean()
stdev = math.sqrt((pos_array[:,0]**2).mean() - xmean**2) + \
math.sqrt((pos_array[:,1]**2).mean() - ymean**2)
return stdev

def currpos(time, pos_array, vec_array):
curr_pos = pos_array + (vec_array * time)
stdev = evalute_position(curr_pos)
return stdev

def currarray(time, pos_array, vec_array):
curr_pos = pos_array + (vec_array * time)
return curr_pos

import numpy as np
with open("test.txt", 'r') as file:
inp = file.read().splitlines()
inp = list(map(lambda s:s.replace(",", " ").replace(">", " ").replace("

Attached: brainlet.png (366x252, 5K)

Yeah I don't give a fuck about this problem. A man needs his sleep. Enjoy slaving away for 0 points faggots

>people actually believed the cuck who said it would be trees

FUCK

what a tedious problem. fuck it

>1-indexed array
wow, I'm not even doing this one on principle.

Doing this one tomorrow during work, would rather watch toradora desu

ahahahahahah

Attached: hahahaa.png (597x275, 21K)

this one doesn't look too difficult.

just reading this made me think "why am i even bothering with this shit"

I don't understand why is the puzzle input an int rather than a table?

for fake points that give a rush of dopamine when you get them

>1 indexed
FUCKING WHY

What am I suppose to do with the input number?
>t. ultra brainlet

i've been filtered, i'm just here to watch /ourguy/.

he just double starred. post code fren.

THE ABSOLUTE STATE OF PETERTSENG

>Increase the power level by the value of the grid serial number (your puzzle input).

There sure are a lot of these 2d grid questions this year...

1/8, beat out all 3 of the other contenders today. Also I think petertseng is getting rekt again
Wrote part 1 in python but it was too slow for 2 so I rewrote it in C
Probably should've just used pypy, I always forget that exists
It's actually still pretty slow in C because I used a stupid algorithm, but my target size was only like 14 and it got that far pretty damn quick

Attached: aoc18day11.png (1243x1182, 138K)

got it thanks

/leddit/ btfo

136 possible points and dropping

>Wrote part 1 in python but it was too slow for 2 so I rewrote it in C
Pythonfags BTFO.

>add the serial number
FUCK, i multiplied it. and now i have to wait 5 minutes

Prude furcesd p1, now to p2 is shit
PYPY HERE WE GO!

never mind, I can't read documentation

And he just missed the part2 leaderboard again. Damn, that dude is not having a good week

Attached: aocgraph.png (1100x500, 14K)

>all test cases work
>real one doesn't
fuck

Does it not strip my spaces or something? wtf
Did anyone enter in the form "x, y" and have success?

fuck, and now my input was off by one.
i should have tried the test input.

Today was lots of fun

from collections import defaultdict

def val(z,k):
x,y=k
return int(f"{((x+10)*y+z)*(x+10):3d}"[-3])-5

class keydefaultdict(defaultdict):
def __missing__(self, key):
if self.default_factory is None:
raise KeyError( key )
else:
ret = self[key] = self.default_factory(key)
return ret

def calc(data, size=None):
try:
grid=keydefaultdict(partial(val,data))
mx = 0
retval = 0
for size in ([size] if size is not None else range(1,301)):
print(size, retval, mx)
for x in range(1,302-size):
for y in range(1,302-size):
th = sum(grid[(x+i,y+j)] for i in range(size) for j in range(size))
if th > mx:
mx = th
retval = (x,y,size)
except KeyboardInterrupt:
pass
return retval

if __name__ == '__main__':
data = 1723
print(calc(data,3))
print(calc(data))


Almost got on the leaderboard, too.

-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
11 00:12:04 379 0 00:17:29 118 0


I actually learned about that keydefaultdict thing today at work when I needed it for something.

Attached: bocchi smile hood.png (393x363, 67K)

-------Part 1-------- -------Part 2--------
Day Time Rank Score Time Rank Score
11 00:11:52 357 0 00:21:52 205 0

I'm #100 now
I think it's safe to say it's my last day on the leaderboard

Code btw (still running but I tried the best of size 12 and it worked)
arg = 5153
L = [[0 for y in range(300)] for x in range(300)]

for x in range(300):
for y in range(300):
p = ((((x+10)*y + arg)*(x+10))%1000)//100 - 5
L[x][y] = p

best = -999999999
bestx = 0
besty = 0
bests = 0
s = dict()
for x in range(300):
for y in range(300):
s[(x,y)] = L[x][y]
for size in range(1,301):
print(size, bestx, besty, bests, best)
for x in range(300-size+1):
for y in range(300-size+1):
p = 0
for xx in range(size-1):
s[(x,y)] += L[x+xx][ y + size -1]
for yy in range(size-1):
s[(x,y)] += L[x+ size - 1][ y + yy]
s[(x,y)] += L[x+ size - 1][ y + size -1]
p = s[(x,y)]
if p > best:
best = p
bestx =x
besty = y
bests = size

Attached: 1541733359176.png (189x328, 67K)

>Part 2
I think I'm about to get F I L T E R E D

ARE YOU FUCKING KIDDING ME, THAT WAS IT
I JUST HAD TO ENTER THE SAME NUMBERS WITHOUT A SPACE
Retards can't even strip their strings holy shit,

fuck it's too slow

Attached: Capture.png (677x493, 52K)

That is kind of shitty, though fwiw every example on the page is X,Y with no space

Same here
Serial = 5093
Answer = 242,48 @ 31
>type 242,48
>doesn't work

Attached: Screenshot_20181211_152459.png (571x539, 48K)

based bocchi poster

Whoops, add from functools import partial to the top of that.

Attached: bocchi bwah.jpg (411x316, 41K)

This outputs
4
-5
242 48 31

which indicates that what I'm doing is getting the right answers.

And for completeness, change that :3d to :03d. Fortunately that didn't bite me in the butt this time.

Print the best so far as it finds them. I just tried plain old cpython and it reaches the actual answer in about a minute, long before it would ever finish up to the full size 300

DON'T WAIT FOR YOUR PART 2 TO ACTUALLY FINISH
JUST PRINT YOUR BEST X,Y,SIZE FOR EACH SIZE AND TAKE IT ONCE IT STAGNATES

You're off by one, my dude

I get 285,169,15 for 5093.

Also make sure to start at 1x1 and not 300x300.

tfw I waited for my part 2 to finish and I got rank 125...

thx, it stagnated in 1 sec while my previous instance was going already for 5 mins with no answer

>2nd part taking forever
>try the current max value
>its right
wew.

Yeah, it's shitty. I swear I saw one of the X,Y examples with a space but it looks like there isn't one. Super shitty to not tell you how to format your input right by the box. They have space for a whole dumb story and no space for a simple input format explanation, since this time it isn't a number.

>waste 5 minutes thinking your algorithm is botched
>turns out the array isn't zeroed
this is why C shouldn't exist anymore

>oh wow part 1 was actually really easy, i guess today wont be too ba-
>mfw part 2

Attached: diarrhea.png (218x218, 87K)

>tried the best of size 12 and it worked
Thank you! That makes part 2 run very quickly.

>he doesn't use calloc
deserved.

Attached: 1544415344720.jpg (519x359, 45K)

my input wont fucking work

>spent 35 minutes on part 1
>WHY THE FUCK wont it take 492,455
>I've checked 20 times, it's the right fucking answer
>read the question for the 10th time
>300x300 grid
that's it, I'm done

Attached: EESUFAM.png (921x647, 1.44M)

Proofread much?

Attached: 1542675313251.jpg (739x673, 101K)

i keep putting in "90,214" for "1718" and it wont fucking work

>doze off yesterday, drop from 21 to 31 (private leaderboard)
>go back to 21 today
i am okay with this

Attached: yukko_epic.png (459x410, 120K)