/aocg/ - Advent of Code 2017 General #12

Wall of text for ants 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.

The new leaderboard with empty space is
join-code: 43046-941b8011

The old (full) leaderboard is
join-code: 194764-c554ff91

Other urls found in this thread:

adventofcode.com/2015/day/14
pastebin.com/kXBCs5pC
pastebin.com/H5MVwsyP
pastebin.com/vhec0tdp
pastebin.com/DKyQALL9
twitter.com/NSFWRedditImage

> const char hex[] = { ... }; over three lines
> not const char* hex = "0123456789abcdef";

...

Knot Hash was disappointing.
I got confused because the part 2 text was vague on what it meant by "rounds" and then it's just a mindless recipe list, follow these steps to get the answer, it's all spelled out for you.

The only remotely interesting bit was how to handle the circular array reverse.
I just took the easy way out, copy to a normal continuous buffer, reverse the bytes and copy it back.

I rotated the array so the current position was always at index 0, then rotated back to the correct order at the very end.

>your mind on linked lists

>not
const char hex[] = {
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"
};

I just did 2015 day 6 (the one with the 1000x1000 Christmas light grid), and the performance of my program is just abhorrent. It takes it 2 minutes and 18 seconds to give an answer to part one.

seq = [17, 31, 73, 47, 23]
with open('input10.txt') as f:
for l in f.readlines():
line = [ord(x) for x in l.strip()]
line += seq

knot = [x for x in range(256)]
index, skip = 0, 0
for i in range(64):
for c in line:
index %= 256
knot = knot[index:] + knot[:index] # rotate
knot = knot[:c][::-1] + knot[c:]
knot = knot[-1*index:] + knot[:-1*index] # undo rotation
index += c + skip
skip += 1

a = []
for i in range(16):
a.append(knot[16*i:16*i+16])

tot = ""
for i in a:
x = i[0]
for j in range(1, 16):
x ^= i[j]
tot += str(hex(x))[2:]
print('p2', tot)


not the cleanest formatting, but meh. glad to get to use list rotation, i've used it for a rubik's cube variant I made

Try running it on repl.it

How?

Good problem today. I implemented a ring buffer class the other day and already had a chance to use it.

Pic related.

Idk, I guess sets don't have the performance I thought they had. I used a map for part two, and that one only took 30 seconds.

>Erlang
oh, data structures are immutable there aren't they? in which case I guess it makes sense because of how many copies of data it'd involve

>I rotated the array so the current position was always at index 0, then rotated back to the correct order at the very end.
That's what I did too and it caused me endless pain because I kept miscalculating the amount to rotate it back by at the end. My list was always correct order-wise, but I kept fucking up the rotation correction

Some user on 8ch is claiming that the hardest challenges will be on 12th, 18th and 25th, but he didn't provide any sources.

>program runs the test correctly but doesn't run the input correctly

make better tests

So when do we stop for part 1? When skip = list size?

no, once you have gone through each element of the input

Got it thanks. Fucking wall of text

doesn't werk on my machine

Whitespace in input file
or
Your test answers are actually wrong because every number in the dense hash less than 16 is missing a leading 0 in the string representation

>he can't even read the assignment
FAIL

You're right user, you're so smart
:^)

>Your test answers are actually wrong because every number in the dense hash less than 16 is missing a leading 0 in the string representation

I'm still on part 1...

It's just the inverse of the current position mod 256 user

I know. I was modulo'ing by 255. I'm in the background of the OP image ;_;

what's the error?
pastebin me your input/solution for p2

my bad, it works now

...

good stuff, was worried I'd fluked it for a second

Does anyone remember 2016 day 19? Part 1 was very quick, but part 2 is taking ages to compute

Your answer will also break if there's any leading 0s in the string representation
It gives the wrong answer for the '1,2,3' test case

wtf
118,140,85,174,212,72,7,210,214,191,23,225,26,80,93,192
768C55AED4487D2D6BF17E11A505DC0


>length: 31

wat

wasn't bothered with the test cases for part 2, but where does it fail for leading zeroes?

Top line is the correct solution for 1,2,3, bottom line is the solution your code produces
3efbe78a8d82f29979031a4aa0b16a9d
3efbe78a8d82f2997931a4aa0b16a9d

See Also your answer is wrong
Also it probably won't be accepted unless it's lowercase

do you know who this is reverse search justrshows loads of profile pictures for various websites

my input is:
147,37,249,1,31,2,226,0,161,71,254,243,183,255,30,70
there is no leading zeroes

adventofcode.com/2015/day/14

>--- Part Two ---

>Seeing how reindeer move in bursts, Santa decides he's not pleased with the old scoring system.

>Instead, at the end of each second, he awards one point to the reindeer currently in the lead. (If there are multiple reindeer tied for the lead, they each get one point.) He keeps the traditional 2503 second time limit, of course, as doing otherwise would be entirely ridiculous.

>Given the example reindeer from above, after the first second, Dancer is in the lead and gets one point. He stays in the lead until several seconds into Comet's second burst: after the 140th second, Comet pulls into the lead and gets his first point. Of course, since Dancer had been in the lead for the 139 seconds before that, he has accumulated 139 points by the 140th second.

>After the 1000th second, Dancer has accumulated 689 points, while poor Comet, our old champion, only has 312. So, with the new scoring system, Dancer would win (if the race ended at 1000 seconds).

>Again given the descriptions of each reindeer (in your puzzle input), after exactly 2503 seconds, how many points does the winning reindeer have?

How the fuck do Dancer and Comet have a combined 1001 points after 1000 seconds?

it's a drawing

oh right, should've used
format(i, '#04x')[2:]


nice catch

isn't it a character from some vn?

Someone post their puzzle and answer for p2 so I can test

>If there are multiple reindeer tied for the lead, they each get one point.

70,66,255,2,48,0,54,48,80,141,244,254,160,108,1,41
decdf7d377879877173b7f2fb131cf1b

Puzzle: 165,1,255,31,87,52,24,113,0,91,148,254,158,2,73,153
Answer: 2f8c3d2100fdd57cec130d928b0fd2dd

Found the problem, it was one typo. I was stuck on this for an hour ;__;

it's natsuha from monobeno. Cool vn to read with your friends

>>If there are multiple reindeer tied for the lead, they each get one point.

>reading comprehension

Okay, may be I failed to understand something.

Correct me if I'm wrong:
Puzzle input is
147,37,249,1,31,2,226,0,161,71,254,243,183,255,30,70

For example.
We treat it as a string
>"147,37,249,1,31,2,226,0,161,71,254,243,183,255,30,70"
Including ',' but ignoring any trailing or leading whitespaces.
Now, each character in the string we convert to ASCII code if his, each number and ','
To the resulting sequence of byte array {213,14, etc} we append the suffix part {17, 31, 73, 47, 23}

Now we have an array of bytes (or integers whatever) from 0 to 255.
This is now our input. Using it, we do 64 rounds of part1.

Everything is correct so far?

Everything correct so far

r8 my day 10 part 1

You can remove pos %= list.size();

Okay, so we preserve the array state and skipsize and position after each round, right? But we do reset the local SEQUENCE position to 0 each new round.

I dont see any errors in my part1 64 rounds, all good. Weird

Oh yeah I clamp the value already in swap but it makes it easier to understand

I would keep it there to keep pos bounded

r8/h8/appreci8

let list = Array.from({ length: 256 }, (_, i) => i);
let current = 0;
let skip = 0;

let input = Array.from('76,1,88,148,166,217,130,0,128,254,16,2,130,71,255,229')
.map(s => s.charCodeAt(0))
.concat([17, 31, 73, 47, 23]);

for (let r = 0; r < 64; r++) {
input.forEach(l => {
for (let i = 0; i < Math.floor(l / 2); i++) {
let a = (i + current) % list.length;
let b = (current + l - i - 1) % list.length;
[list[a], list[b]] = [list[b], list[a]]
}

current = (current + l + skip++) % list.length;
});
}

let dense = [];

for (let i = 0; i < list.length; i += 16) {
let out = list
.slice(i, i + 16)
.reduce((a, c) => a ^ c);
dense.push(out);
}

let hash = dense.map(n => (n

>we do reset the local SEQUENCE position to 0 each new round
What did he mean by this?

What's your element0 * element1 after 64 rounds with this puzzle input:

147,37,249,1,31,2,226,0,161,71,254,243,183,255,30,70

not testable/10

After 64 rounds of knotting with lengths, where lengths is an array of bytes for each character in that input concatenated with the integers [17, 31, 73, 47, 23], element0 * element1 is 49060

nono, just normal puzzle input:
147,37,249,1,31,2,226,0,161,71,254,243,183,255,30,70


Treat it as a ready to go array, basically I ask you to do part1 with 64 rounds with that ^ input

After 64 rounds of knotting with that array of integers, element0 * element1 is 16830

pastebin.com/kXBCs5pC
pastebin.com/H5MVwsyP

The more I code in Haskell, the more I see it as >hasklel

My god, it has shit substring extraction.I'm trying to solve AoC solely using Haskell, but it's becoming more overengineered by the day.

My bad
After 64 rounds of knotting with your array of integers, element0 * element1 is 13770
I accidentally used my own puzzle input here

I'm just happy I fit a lambda function in there, one day I will ascend brainlet status

pastebin.com/vhec0tdp

And yet you can just replace it with int.__xor__ :^)

Or from operator import xor

not bad, you can get rid of that shitty loop by doing something like i have though:
def xor_hex_chunks(state):
return ''.join(['{:02x}'.format(hex) for hex in [
reduce(lambda x, y: x ^ y, state[n:n + 16]) for n in range(0, len(state), 16)
]])

To partition an integer for 2015 day 15, I'm using this retarded recursive generator:

def part(total,n):
if n>1:
for i in range(0,total+1):
for j in part(total-i,n-1):
yield (i,)+j
else:
yield (total,)


What's the best way to do this?

Why not just
''.join('%02x' % reduce(int.__xor__, my_list[i:i+16]) for i in xrange(0, 256, 16))

''.join([format(j,'0>2x') for j in [reduce(xor,arr[16*i:16*i+16]) for i in range(16)]]

>int.__xor__
python is so fucking gross

Then use operator.xor

>NameError: name 'operator' is not defined

>importing a function that's already there and using it once just to avoid typing in a dunder
You dunderhead

>what is automatic coercion
Do you even know why one would use operator.add instead of [type].__add__?

from operator import xor

>>> int.__xor__(True, False)
1
Oh wow it's fucking magic

>have to import the fucking xor operator
Truly pythonic

Come on now, at least be more creative when you bait. Every Python user knows that bool is a subclass of int.

Okay buddy write me a scrpit where you have to reduce sets with xor and reduce integers with xor and then you can do your silly import

But ^ exists in default python

So my logic is correct
What gives then

Give me the answer you're getting
I'll see if I can replicate the error

What do you get for part 2?

import sys, struct
quad = struct.Struct('

188,150,76,87,242,151,141,120,159,161,11,91,68,182,44,17
188 to BC
150 to 96
76 to 4C
87 to 57
242 to F2
151 to 97
141 to 8D
120 to 78
159 to 9F
161 to A1
11 to B
91 to 5B
68 to 44
182 to B6
44 to 2C
17 to 11
BC964C57F2978D789FA1B5B44B62C11


>11 to B

REEEEEEEEEEEEE
WHY

Use %02x instead of %X

why?

So you can have leading zeroes, and the the the answer needs to be in lowercase.

for fucks sake

i spent YEARS

>100,000 accounts created
>less than 5000 gold stars
>not even halfway through the month

Keep it up brainlets, you can do it if you really try. I believe in you!

>mfw still wrong
HOW

Is 188,150,76,87,242,151,141,120,159,161,11,91,68,182,44,17 the array you get after reducing the spare hashes sub-arrays with xor?

I started Friday and I'm on 7 pt 2. At this rate I'll never catch up to the big kids. Also this is a perfect chance to learn recursion but I don't think I'm going to.

pastebin.com/DKyQALL9

Post your code faggit

Array 64 perms (line 56) is wrong