/aocg/ - Advent of Code 2018 General #30

Cellular automaton 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: day_12.png (1530x1005, 17K)

Other urls found in this thread:

pastebin.com/ygk0s5sh
pastebin.com/P2Hkbfbt
pastebin.com/VW4RMxz7
pastebin.com/EdEWzjLy
pastebin.com/raw/nL6N7Ybx
pastebin.com/Rk80928c
pastebin.com/pm3pqbXu
pastebin.com/x7CSeK9r
paste.debian.net/1055537/
paste.debian.net/1055541/
gist.github.com/Wunkolo/249646f7a922ee045c70
github.com/Wunkolo/MarchASCII
en.wikipedia.org/wiki/Linear_function_(calculus)
twitter.com/SFWRedditVideos

>tfw this was also the night I gave up, went to sleep on time and solved it in the morning
Hello fellow coper

where the brute force codelets at?

Probably waiting for their process to finish.

I have to admit I did leave my first solution running for a while as I worked on the second half. Hope springs eternal.

First 1000 cycles of big boy rule 110 input with random initial state.

pastebin.com/ygk0s5sh

Attached: rule_110.png (1997x1001, 66K)

no calendar updates:(

I'll learn to count tomorrow.

Attached: Screen Shot 2018-12-13 at 1.12.43 am.png (1598x166, 58K)

Still stuck at part 2.
I check whether the current pattern matches the last pattern to detect when the sliding starts
I take the sum of the last pattern before sliding
Then I take the count of pots in the first sliding pattern
I multiply the amount of pots with (50000000000 minus startnumber of sliding pattern) and add the result on top of the sum
What am I doing wrong?

Attached: Screenshot from 2018-12-12 15-12-54.png (1057x169, 10K)

What you wrote is all right. Probably implementation mistake, check for off by ones.

Can you give your input & your solutions so I can check?

I'm not sure it I should be pleased or disgusted with my solution for part 2.
start = 50000000000
print(sum(range(start-92+5, start-92+5+186, 1)))

I got fucking lucky with my input, it' converges on a solid line 186 long moving right, starting on gen 92.
I just dumped 100+ generations to a text file and looked at the row/column it got stuck. Pen and paper without the pen and paper.

$ ./1 < input
Part 1: 2893
Part 2: 2500000000695


pastebin.com/P2Hkbfbt
Compile with -std=c++17. Not particularly pretty.

Umm, input: pastebin.com/VW4RMxz7

Does anyone have an input, along with its solution, where the repeating pattern shifts by some amount *other than* by one to the right? Want to verify my implementation.

Not exactly hard to come up with one:
pastebin.com/EdEWzjLy

3421
2550000001195

ok this is the first input since last and this thread where my part one is incorrect, so I would guess somethings still off

Shit, sorry, part 1 is 2911. I played around with Part 1 when I aimed for Part 2.

Ok then my part 1 is working.
I'm getting 2499999999397 for part 2, which is -1298 below your result.
Which of my vars is most likely off by a few?

>Pen and paper without the pen and paper
Are you fucking shitting me with that line?

by the way, this is my output.
offset is the offset from the initial 0 point
pastebin.com/raw/nL6N7Ybx

Looks allright, what is the semantic meaning of "offset"? Mine also starts repeating at gen 91.

if this is the initial state
##.#...#.#.#....###.#.#....##.#...##.##.###..#.##.###..####.#..##..#.##..#.......####.#.#..#....##.#
I check 4 - indexOf('#'), so in initial state index of the first # is 0 -> I add 4 dots to the front and increase the offset
If there are 5 dots infront this will be -1, so I remove 1 dot from the front and decrease the offset

Everytime there's a calendar brainlet. The calendar updates on FRIDAY of the WEEK!

Offsets also seem allright. You just fuck up the final calculation somehow.

solved it. checked the wrong generation state at one point during calculation.
thanks for helping and comparing user

Attached: Screenshot from 2018-12-12 16-38-37.png (801x325, 50K)

Some interesting rules with A E S T H E T I C outputs.

pastebin.com/Rk80928c

Attached: rule_18.png (1996x501, 69K)

pretty

pastebin.com/pm3pqbXu

Attached: rule_150.png (1996x501, 102K)

pastebin.com/x7CSeK9r

Attached: rule_106.png (1497x501, 65K)

what kind of concepts do you think might pop up further along the way?

Does anyone know of a Life program that can handle these rules? I want to see if they can handle true bigboy rules.
Hashlife and everything else in golly don't seem to support range 2 neighborhoods.

checked

I toyed with the idea to use golly. You can rewrite range 2 neighborhood rules to range 1 multi state rules.

Example:
initial state:
011001
New states:
01 11 10 00 01
1 3 2 0 1

golly can handle this.

big_boy rules produce linearly growing "plant range". At the 50000000000th round one would need ~12GiB of ram to store only the plant's positions. An inplace updating mechanism is warranted (as opposed to the naive double buffering). Not to mention that by the end you have to read that 12GiB every single round.

have you guys heard of L-systems? the task comes down to derivation of context L-systems, or (2, 2)-systems to be precise, because of the lengths of left and right context
you can draw all kinds of shit with them & turtle graphics, including the subject of my diploma thesis, procedurally generated plants

Attached: Untitled.png (1100x1100, 718K)

butifel

it's time we updated that calendar

Fucking saved. You just store an offset. The nth element of the array refers to the (n + offset)th pot. offset can be negative.

Now I feel stupid.

For the non-chaotic growth rules, a good simulator like hashlife can compress the data trmendously. But I guess for rule 30 and friends I'll only crash my computer halfway through.

paste.debian.net/1055537/

Grows both ways by 2 in every turn. I don't see any compressible pattern, it would need ~24GiB of memory to store the state at the 50000000000th round.

Attached: sum_rule_1.png (2994x501, 117K)

Some more aesthetic.
paste.debian.net/1055541/

Attached: nice.png (2994x501, 71K)

day 11 still needs an image

Attached: cal.png (10000x10000, 2.88M)

The same with only two starting pots.
Kinda looks like a snowy mountain with trees. It even has shading.

Attached: nice_1.png (1028x257, 14K)

Attached: python_day_11.png (1284x1079, 412K)

There wasn't really anything that screamed tree about yesterday, if that's what you're going for. Pyfags getting fucked is definitely a good highlight, but the visualizations are the best part of the day desu.
If I knew where to take it I would probably give it a go, but I unfortunately don't really.

>but the visualizations are the best part of the day
true, also I'm surprised that there were no "power level" jokes.

I did the second part by hand.
First I got the part 1 answer then I just changed 20 by 50 billion and as it was taking too long I killed the program and then tried 1000 and got 61491. Then I tried 10000 and got 619491.
so:
1000 -> 61491
10000 -> 619491

then I did
5000->309491

and reasoned that
50billion -> 3099999999491

Attached: 1317645189052.gif (290x189, 2.9M)

my code

Attached: code.png (1248x1640, 191K)

Now add all the thread screencaps

Attached: day11.png (1024x1024, 1.5M)

So what are you guys using for those fancy visualisations?

Doesn't need too many screencaps, only a couple if that.

>tfw tried to actually compute the 50 gazilion iterations

Attached: russian led.jpg (480x640, 54K)

wtf is this
live power being put through a big ass pole?

looks like a shabby connection to a ground rod

Me and another user who posted use pygame, I posted a script last thread here that can do one for the day.
Pygame is pretty old and somewhat outdated, but it's great at this kind of 2D stuff (I especially use image.frombuffer() in these).
I have my own basic 5 KB framework for it, but it really doesn't really need much boilerplate to get working (as seen in my post).
I've used it for many visualizations, tools, demos, etc. It is technically intended for games, but it's rarely used for anything notable for performance reasons, other than the ren'py visual novel engine (Katawa Shoujo, Doki Doki Literature Club, etc.).

Webm related is one I made for last year. Pygame has no 3D functionality by default, I wrote my own crappy 3D code for this. It is however made to work with PyOpenGL for 3D things. If you have questions, feel free to ask.

Attached: aoc particles.webm (800x800, 2.5M)

The power distribution panel to my house probably looked like this until the user said to not run it to completion.

Attached: glownut.jpg (797x579, 153K)

>Pygame has no 3D functionality by default, I wrote my own crappy 3D code for this.
whoa, cool stuff

I use imsave from scipy.misc
feed in a numpy array get a png, simple as that.

What the fuck is day 6 part 1 and how the fuck do I do it? This is as far as I got in python.

with open('day6/aoc.txt', 'r') as f:
coordinates = f.readlines()

grid = [['.'] * 500 for i in range(500)]

for iter, cords in enumerate(coordinates):
x = int(cords.split(',')[0])
y = int(cords.split(',')[1][1])
grid[y][x] = iter

I found that I can use scipy for this, but that is only to calculate distance, I would rather solve this on my own. Also even if I am able to calculate the distance between two points, how do I get the area? Do I just divide the distance by half between all points that it borders and calculate from there?

It's shite, but it works. No texture mapping in my code though, I'll post a screenshot of how that went in a moment.

Attached: 3D engine demo.webm (800x800, 2.97M)

I just dropped it in the background of but it's still not great. Should have at least some mention of summed-area tables.

Attached: 1537251731011.png (1284x1079, 1.62M)

ah, an user from /diy/ & /ohm/ I see, cheers mate

the easiest option is just computing the nearest point for every point in the grid

Here you have it, texture mapping on the CPU with python. Not even numpy or cython. The reason the framerate is even that high is that that's the lowest the counter I made goes.

I browse occasionally, it's pretty comfy.

Attached: Capture.png (816x840, 184K)

Wait until you see this

Attached: glowgasline.jpg (1078x960, 138K)

I think it would probably be better with the posts up in just the black area only

Today wasn't brainlet filter since I made it.

manhattan distance is sort of a simplified heuristic of euclidean distance - you just calculate the absolute value of the difference between x and y coordinates of two points and sum them up, no square root bullshit; that is abs(x1-x2)+abs(y1-y2)
then you have to deal with the infinite areas. But you can easily find which of them are infinite by noticing that any area laying on an edge of a boundary box enclosing the points is infinite (a box such that every point is within it)
do the calculations for every point within the box, discard infinite areas and viola

>texture mapping on the CPU with python
madman

>But you can easily find which of them are infinite by noticing that any area laying on an edge of a boundary box enclosing the points is infinite

Attached: image.jpg (337x168, 3K)

is this better?

Attached: day11.png (1024x1024, 1.03M)

huh?

Yo I love the 3D stuff you managed, but since it's just acting as a wrapper for SDL, why do you write this in pygame?

it can be infinite even if it's not on the edge
it just needs to be closer to that edge than any other point

>But you can easily find which of them are infinite by noticing that any area laying on an edge of a boundary box enclosing the points is infinite
>any area

here's another example, E is clearly infinite

Attached: E.png (300x300, 3K)

>it can be infinite even if it's not on the edge
that's not what I meant; I didn't mean the pivot point
if the "c" area is infinite, it has to cross the boundary box somewhere; this is the same for every infinite area
so to find infinite areas you just have to follow the edge and put them into a set
otoh the finite areas will make up a convex shape, which means no finite area will cross the box

Got filtered hard on this one boys, had to dissect another user's code just to wrap my head around what was going on. Thought I had a working idea but apparently I just wasn't getting it. Feels real fuckin' bad man. Hopefully tonight's works out better :(

Attached: jlaic9.jpg (662x807, 316K)

indeed, didn't read closely enough
this was a common mistake in the original thread so I just assumed it was being made again

>if the "c" area is infinite, it has to cross the boundary box somewhere;
again false

Attached: screenshot.png (330x311, 20K)

Why do they troll us? Why? I rewrite my OCaml code to an efficient C code, but it was still too slow, so I look. Fuck off, I solve it, but it was stupid.

create two distance fields,
one at some large value bounds, and one slightly larger

the infinite areas are which ever areas are different between the two

how are you gonna contain an infinite area in a finite bounding box?

how is it false? how can an infinite area be enclosed within a finite rectangle box?
it has to cross the box somewhere

I find it really strange that this one was hard for so many people
I thought it was the easiest one in a long time
it's just like a dozen lines in C++ compared to all my other solutions which are literally 2-3x longer
all I did was map the inputs to the outputs and do a couple loops and that's it

it can be finite and "close up" farther down outside the bounding box

Difficulty peaked around day 7-8. Are we in for another brainlet filter soon?

Not with manhattan distance.

Why?
#define F(i) (-(i) - 1)

typedef long int pos_t;

static unsigned int *left;
static unsigned int *right;
pos_t mini = 0;
pos_t maxi = 0;
static int rules[32] = {0};

static int get (pos_t i) {
unsigned int *ptr;
pos_t q;
pos_t r;
if (i < 0) {
i = F (i);
ptr = left;
} else {
ptr = right;
}
q = i / 32;
r = i % 32;
return (ptr[q] & (1 > r;
}

static void set (pos_t i, int x) {
unsigned int *ptr;
size_t q;
size_t r;
if (i < mini && x) {
mini = i;
}
if (i > maxi && x) {
maxi = i;
}
if (i < 0) {
i = F (i);
ptr = left;
} else {
ptr = right;
}
q = i / 32;
r = i % 32;
if (x) {
ptr[q] |= (1

The only language I am any good at is python, having only done a little C++ for an arduino and basic lua before. As far as pygame over other libraries, it's just the one I'm most familiar with.
The 3D stuff was always just an experiment of mine, starting with crude 3D effects in lua with absolutely no graphical interface - Writing to a buffer of text and printing it out all at once at ~20 FPS.
The flickering in the webm isn't a conversion artifact, it's because the framerate doesn't line up with the printing and I'm not aware of a way to directly edit the text on the command line, despite searching and asking in the /sqt/.

Attached: output.webm (676x342, 813K)

is there no ncurses for python on windows?

>Are we in for another brainlet filter soon?
Day 13. Hence tomorrow.

How does this one () work? It seems to be magic, because it does not seem to establish what value -4, -3, 101, 102, etc. will have.

Check this out:
gist.github.com/Wunkolo/249646f7a922ee045c70
github.com/Wunkolo/MarchASCII

Attached: 68747470733a2f2f692e696d6775722e636f6d2f723935613972492e676966.gif (540x490, 3.3M)

sexy

Can someone ELI5 why
((50000000000 - 500) * pattern) + sum@500
works?

en.wikipedia.org/wiki/Linear_function_(calculus)

with the rules we were given, at some point the pattern stops changing and just shifts to the side. at that point you can calculate the point increase from one iteration to the next and use it to calculate the value at any number of iterations after that