/aocg/ - Advent of Code 2017 General #20

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:

pastebin.com/4ZYZqiwJ
cs.put.poznan.pl/csobaniec/software/python/py-qrc.html
hastebin.com/raw/yowuzatora
reddit.com/r/adventofcode/comments/7kjoyy/2017_day_18_part_2_any_reason_why_my_solution/dreww46/
streamable.com/orwbr
twitter.com/NSFWRedditVideo

almost there day 20

Any suggestions for improvements?

Day 14, part 2
pastebin.com/4ZYZqiwJ

>tfw no more of these comfy threads after the 25th
I'll probably be doing last year's, but these threads are some of the comfiest on this board.

Ended up wasting an hour or two because I overlooked how I kept track of the previous location when turning (it kept thinking it was where it was two steps ago one step ago at corners).

we could make threads for weekly challenges in other sites like codwars or codefights.

>these threads are some of the comfiest on this board
totally agree. we should keep up a Sup Forums daily challenge thread of sorts

Don't forget codeforces, csacademy and atcoder

I've wasted an hour just processing the input, more or less.

First challenge: Fizzbuzz

aye

^

idk, once more than one site will be used it will get chaotic

I mean, we could make a really simple site for it that links out to the challenge of the day or whatever

That sounds good I guess.

You mean algorithmical or regarding code style?

Hi guys, brainlet here.

I can't even do the first day challenge. I'm working in python. Can you recommend any textbooks?

nothing lasts forever, user. enjoy the experience while it lasts.

No textbook is going to teach you basic problem solving

I feel like I know how to solve it but I can't work well enough with the programming langauge to express what I want to do.

try reading this, and when in doubt just search stack overflow answers x100
cs.put.poznan.pl/csobaniec/software/python/py-qrc.html

Been away for a week so I'm catching up. Could someone run my input through their day 11 part 1 solution and tell me what you get?

hastebin.com/raw/yowuzatora

I thought I had the right answer (878) but evidently I didn't.

877

Ah, off by one. Thank you!

I'm fucking retarded and printed the sent count of program:p=0 (as in "the first of the two programs, i.e. program 1 (out of 2), rite, sheesh")
and it's obvious in retrospect* that I'm retarded and it's program:p=1.sent.
Gold star for gryffindor

*As in "after I saw that random leddit comment": reddit.com/r/adventofcode/comments/7kjoyy/2017_day_18_part_2_any_reason_why_my_solution/dreww46/

Don't code while mentally handicapped, kids.

/pcg/ programming challenges general?

I was pretty sure you solution had to be O(sqrt n) so I tested it myself, now I'm pretty sure it's O( (log n)2 )

>the sum of all digits that match the next digit in the list
that is poorly written

>if ((sum(previous_digits) == next_digit)) {counter++;}

>that is poorly written
No it's not

yes it is

No it's not

un-uh

>have to use botnet to log in
um no sweetie

Turns out I forgot to strip the newline character off the input file string, meaning the last step didn't get parsed.

Algorithmical. I'm not paying attention to code style for these contests, just hacking it together.

Just make a dummy reddit account. They don't even ask for email

Why do you post this every fucking thread you retard. Get your turbo autismo back to /dpt/ where you belong nigger

don't feed the troll
shitty b8 deserves to be ignored

Rank my O(sqrt(n)) solution to day 3 problem 1. (Could be O(1) if I wasn't lazy)

const int N = 312051;
int main() {
for (int i = 0;; ++i){
int left, up, right, down;
left = 1 + 4*i*i + i;
up = 1 + 4*i*i - i;
right = 1 + 4*i*i - 3*i;
down = 1 + 4*i*i + 3*i;
if (i >= abs(N - left)){
std::cout = abs(N - right)){
std::cout = abs(N - up)){
std::cout = abs(N - down)){
std::cout

um no sweetie

How long did you wait for Day 16 Part 2 solution?

I did one round according to the steps in the input. Derived permutation cycle and then applied the permutation cycle on the dancers 1bil times. Takes too long.

Any hints how to speed it up?

183 ms
It could be faster but it's more than good enough for me.

>How long did you wait for Day 16 Part 2 solution?
about 50 ms
>Any hints how to speed it up?
don't brute force it. you do not need to run it 1 billion times.

>I've wasted an hour just processing the input, more or less.
language? what did you attempt?

>self-contained
*snort*

40ms, but I'm going to try and improve it. tip: you don't need to run it 1 billion times

Thanks. Figured it out. The configurations starts to repeat after some iterations.

Yeah. By the way even if you could get your hash function to run in 0.5ms it would still take over 5 days to get your solution.

Got it down to 22ms average but I can't seem to get it down any further. Still satisfied tho.

I did days 1-9 then stopped because schoolwork caught up.

What are the hardest/most interesting ones of days 10-19?

>Solution doesn't handle the case of a letter being next to a turning +
>No such case appears in my input
who here /devilish/

Hardest: day 18
Most interesting: day 16

>tfw stuck in day 3 part II

Day 17 is the most interesting because I got it to run under 0.1ms (zero point one millisecond).
Try to best me.

Literally all you have to do is hashmap the coordinates of the squares to their values

What's the problem?

Talking about part 2 of course.

Forgot to actually ask because meme

Do you guys actually generate the asked grid, or calculate the solution?

So no need to run it and insert all 50mil values?

no need to insert anything

I didn't keep the entire grid. Only some parts.

Can it be calculated directly? What area of math/cs should I read?

Yes I generate the grid in a spiral until I get the answer

post yfw you see my code for day 7 part 2 :^)

Just use your brain. Try to print out the first few iteration.

The trick is that 0 is always at index 0 so the value after 0 is always at index 1
You don't actually have to insert into an array to keep track of its length and the index of the current position

>giving him the solution
>not letting user figure it out to better himself
>mfw

I used a calculator for part one, and made the whole grid for part two.

>tfw solution for part 2 was off by 1 again

⎕io ← 0
data ← ⊃((⎕ucs 10)∘≠⊂⊢)⎕nread'I:\2017d19.txt'⎕ntie 0

∇ (list step) ← follow maze; dir pos path take pari temp next
list ← ''
step ← 1

dir ← 1
pos ← 0, maze[0;] ⍳ '|'
path ← 0 5 6 9 10 ⍳ (maze = '+') ∧ 2 ⊥ ⊃ ¯1 1 (∘.⊖,∘.⌽) ⊂ maze ∊ '|-', ⎕A
path[(⊂1 0) + (1 ⊖ (maze ∊ '|-', ⎕A) ∧ 1 = +⌿ ⊃ ¯1 1 (∘.⊖,∘.⌽) ⊂ maze ∊ '|-+', ⎕A) ⍳ 1] ← 5

take ← ({⌊dir ÷ 2: ⌽ pos[pari] ↑ ⍵ ⋄ (pos[pari] + 1) ↓ ⍵} {pari: ⍵[pos[0];] ⋄ ⍵[;pos[1]]})
next ← 5 4⍴0 0 1 0 1 1 1 2 0 0 3 0 3 2 2 2

pari ← ∼2 ∣ dir
temp ← 1 + (0 ≠ take path) ⍳ 1
list ,← (∊∘(⎕A)/⊙⊢) temp ↑ take maze
pos[pari] +← temp × ¯1 * ⌊dir ÷ 2
step +← temp
dir ← next[path[⊂pos]-1;dir]
→ 12 ↑⍨ path[⊂pos] ≠ 5

Not as nice as I hoped.

how 2 lern apl?

what language is this?

For part 1 isn't necessary since the position of the value can be calculated by simple math.
For part 2 you have to generate the square.

>tfw too brainlet to solve day 13

is programming with runes as magical as it looks, or is it like any other programming language once you learn it?

i'm impressed with how quickly you do these because they're completely fucking incomprehensible to me.

it's really like any other
each "rune" is basically just applying a function

Google (or equivalent) is your friend.

APL.

Not really. Elegance becomes more of a concern than speed, though, and many things aren't done in a very straightforward way. For example, take
path ← 0 5 6 9 10 ⍳ (maze = '+') ∧ 2 ⊥ ⊃ ¯1 1 (∘.⊖,∘.⌽) ⊂ maze ∊ '|-', ⎕A

First take the entire input as a matrix (maze) and check, for each element, whether or not it is contained in the set {'|-', ⎕A} (where ⎕A is the vector of all uppercase letters).
Then make a scalar out of that vector (⊂) and rotate it up, down, left and right (¯1 1 (∘.⊖,∘.⌽)), in that order.
Then make it a 3-dimensional array (⊃), that is, 4 by whatever the input was, and consider the sections of the four planes as 4-bit numbers (2 ⊥).
Then mask it (∧, which is actually both LCM and logical AND) with the result of checking, for each element of the input, whether or not it is equal to '+' (maze = '+').
Finally, find the position of each element of the resulting matrix (⍳) in the vector [0 5 6 9 10].

What you get is a matrix with zeroes everywhere, except for pluses in the original input, which have been replaced by 1..4, depending on what kind of corner they represented.

∇∘⎕'12∘∊_⌊⎕'⊤666⌊⎕∇
⍳↑∘⍳∘∩⊥'4*'∊⌈'○⌊*_'
⌊∇'⎕4∘○

how is this log (n), it looks linear

How do I run and test execution time on my system to comapre with mine on diff lang?

appreciate the explanation. if I wasn't a brainlet it might have helped

The axes are on log scales

What do you use to build these graphs?

Looks like some office suite's spreadsheet app. Probably LibreOffice or Google Sheets

Free GoogleSheets can do that?
I didn't know.

I use Gnumeric which is generally a little more useful than LibreOffice, but all office suites are terrible

streamable.com/orwbr
visualised my input desu

Pretty comfy desu

Kind of reminds me of that pipes screensaver, just in reverse.

Added posts to today's calendar image.

Who had two paths?

Fuck you, problem 19. If you wanted Longs you should have said Longs. If you were expecting to overflow any reasonable data set you should have specified the register size.

A guy who read his input wrong

glad to see my code made it..

>Try this thing out
>Code the trivial first exercise
>Copy paste input
>Submit solution, it's wrong
>Recheck things
>Nothing
>Download input and copy paste from gedit instead
>It's right
Wut

Yep, using long longs for every int from now on
Learned my lesson

Are you ready boys?

N-no.

I just hope our AoC overlords have mercy with us today. I want to sleep at least 4 hours for once.

READY

FUCK

FUCK

Stayed up but don't have the energy to program. This one definitely has a simple formula though.