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
primes = [] with open('test.txt', encoding='utf8', mode='r') as primes_109900_126900: for line in primes_109900_126900: primes += [int(x) for x in line.strip().split()] print(len(primes))
non_primes = 0 for i in range(109900, 126900+1, 17): if i not in primes: non_primes += 1 print(non_primes)
Brayden Jenkins
Finally fucking finished it. Being this tired doesn't mix well with reverse engineering.
Landon Thomas
>simple math calculations >"le reverse engineering!"
are you trying to make yourself look big and mighty?
Christopher Ortiz
>the puzzle requires you to do something else than just directly implementing the instrictions
>No it is not. It is math. >There is no fun, no logic - just multiple calculations. >Basically this whole """""""puzzle"""""""""" it just a bunch of random calculations one after another. >Where is guesswork here, where is design thought? Once you realize it you cannot unsee how dull it is.
Oliver Harris
// While b != c, increment h if b is a // prime number, and then increment b by 17. int b = 109300, c = 126300, h = 0; b -= 17; while (b != c) { b += 17; for (int d = 2; d < b; d++) { if (b % d == 0) { h++; break; } } } return h;
That was an amazing puzzle. I feel like a fucking codebreaker or something. I've also realized how brilliant old-school programmers must've been to write entire games in assembly language.
Thank you for this advice. "Running" the program in a notebook was the key to understanding what it does.
Levi Ward
Since when does "le reverse engineering!" make someone big and mighty? On a technology board, it shouldn't be anything out of the normal. In regards to it being reverse engineering, if it was raw machine code, would you call figuring out what the program does reverse engineering? Assembly language, at least in this form, is no different except for being human readable. 3/10, made me reply.
Ryan Baker
You should always have draft paper with you when you code
I'm glad you enjoyed it, I did too. Last week I finished the 2016 puzzles, and there were several cases of pseudo assembly like this. I did them all on paper because there was no time pressure and I was curious, so I started directly on paper today. Couldn't beat /ourguy/ and the other usual top guys though
Jaxon Adams
> give me complete algorithm and I will rewrite it in my favourite language
Kevin Nguyen
More like >figure out what's wrong with this pajeet-coded program that loops six trillion times A skill everyone here will be tested on countless times in real life
Parker Garcia
>A skill everyone here will be tested on countless times in real life this, but unironically
Asher King
>Not basing you career on startup hopping so you never need to worry about the past or the future
Eli Howard
But that's what most of problems in real life looks like. The naive (pajeet) approach hits your immediately. And it's up to you to figure out how to optimize it. People here cry too much.
Thomas Watson
>this, but unironically Yes I know, I was being unironic
Oliver Russell
oops wrong thread So it seems like I have similar puzzle.
Basically in my case it sent b to 107900 c to b + 17000
then there are 3 nested loops inside each runs 5496 times until finally it reaches h = h -1 and then b+17 and so on until c-b = 0 then it terminates
So by logic it should be 1000 * -1 = -1000 but it isnt
where I'm wrong?
Jack Turner
Brainlet here, does this line (30) mean that the program ends right? since there are not instructions left 3 lines after this.
Lincoln Moore
>h = h - 1 Look closely. If it's like my puzzle, it's actually subtracting -1 (adding 1).
Luke Cooper
1) It's probable h - (-1) 2) You're missing the condition that enables h to change and then resets
Cooper Rodriguez
Yes. But it can only reach that instruction if g == 0. Otherwise it will start over from line 9.
Carson Kelly
Yeah, that's basically exit()
Dylan Moore
>2) You're missing the condition that enables h to change and then resets what H never resets there is only one H operation
Isaac Price
Reding. The condition resets
Brody Torres
The condition resets.
Luis Wright
How fast would this program run if you translated it naively into x86 assembly?
Ayden Russell
>mfw
it's ogre
Dylan Thompson
Don't try too much with wrong answers, you'll get locked out of the question
Jeremiah Ward
It would still loop roughly six trillion times
Lincoln Fisher
Not to scare you, but I've heard you get disqualified after 8 tries. The real answer should be less than 1000 and more than 1.
Cameron Sanders
Whatever it has stopped being fun so I couldnt care less at least 40% of puzzlesi n this AoC were shit, this one especially
Kayden Russell
There's about 1.1762311e+13 iterations that will occur with my input, each with about 23 instructions. An intel i5 3.0ghz will run at most 3 instructions per cycle, and runs 3000000000 cycles per second. This means that it will run all the instructions in 11762 seconds, or about 3 hours.
Liam Rodriguez
Never forget about the six gazillion iterations
Jeremiah Reed
>Tfw I counted 999 loops instead of 1000 and had to wait 5 mins to input answer+1
Colton Jenkins
Excuse my math, I forgot to include the 23 instructions. This increases the time by a factor of 23, leaving you with 69 hours, nearly 3 days.
Adam Taylor
You got 1000. There are 1000 numbers you test for primality/composition. Meaning your algorithm failed to detect composite/prime. Check the condition.
Gabriel Thompson
If assembly code is so fast, how come I can compute the answer faster on paper?
Asher Wright
I'm not even detecting anything, I see there is only 1000 loops in which H being changed but answer is not 1000 or -1000
Nathan Young
You use different algorithm.
Xavier Thomas
You're fucking fast if you can determine the number of primes between 106500 and 123500, with a step of 17, entirely on paper in less than three hours
Sebastian Rivera
h is changed only if f is zero. Look where f is set to 0.
Cooper Powell
There are thousand loops in which H resets to 1. There
Leo Gray
it is always zero if it passed d, it just takes FUCKTON of empty loops
Daniel Bell
No, it's not always 0. The thing checks if e*d passes b, which is not true if b is prime.
Hudson Foster
>it is always zero if it passed d Wrong
Julian Murphy
not in my case, the e only resets if h changed so H always changes every loop
Jackson Hughes
>People here cry too much My opinion on Sup Forums as a whole.
Aaron Wilson
I'm 95% sure that we all have exactly the same assembly with a constant changed at the top. Pastebin your input.
Hudson Bell
It would take no more than ~50,000 calculations to brute-force. All you need is a steady supply of ink, and small sweatshop of Taiwanese math nerds.
>small sweatshop of Taiwanese math nerds. Does this count as a computer? I wouldn't know to program it though
Henry Miller
Yes human wagecucks count as computers
Xavier Johnson
This needs to make it into the calendar image for today.
Grayson Parker
Our input is the same except for a constant. What makes you think e resets only if h is changed?
Dylan Taylor
what was you answer? I cant check mine anymore because it is locked now.
Aiden Miller
Oh boy, I spent an extra hour or so trying to figure out what in the world I was doing wrong. Turns out my supposed primality test was fucked and I also got trapped by an off by one error once again.
I fucking hate off by one errors, they always get me.
Connor Lewis
>mfw men invented computers to get rid of women in the workplace
Gabriel Robinson
903 was my answer. I can check your best guess if you like.
Alexander Murphy
my last attempt before I got disq. was 168
Colton King
Way off
Chase Morales
That's a bit too low. What this program does is basically (pseudocode): for i in (2..b): for j in (2..b): if b == i*j: flag = 0 if (flag == 0) h++
So, this doesn't increment h if b is prime.
Elijah James
I'm a retard who forgot the code tag. for i in (2..b): for j in (2..b): if b == i*j: flag = 0 if (flag == 0) h++
It does this until b is equal to c, incrementing b by 17 every time.
Juan James
Yeah whatever
I guess could use dupe account and quickly get back to 23 since I have all other tasks completed but I wont, this day is utter shit and I dont feel like continuing aoc
Andrew Brooks
Hey, don't give up. Give it a rest, get some sleep, but I'm sure you can pull it off in the end. You're very close to the end.
Xavier Sanchez
Well, i already cant check the answer for my solution since the input box is removed when I got locked out.
And honestly I dont wanna make a dummy account.
It is not a big deal, just bad after taste. Shot started so good but escalated quickly into borefest
Aiden Wilson
You can post here. We can check your answer.
Austin Martinez
this
Gavin Hughes
about 1.32 increments per minute the answer is around 900 so about 681 minutes or 11.36 hours on my machine, anyway
Brainlet confirmed. Tip: translate to higher level pseudocode
Mason Rogers
Less than 1000 Not every iteration increments `h`
Nathaniel Morgan
There are only 1000 checked, so no input should give that.
Joshua Scott
i see it now thanks
Samuel Brooks
>primality check its like i'm doing a project euler problem
Matthew Clark
long b = 107900; long c = 124900; long d = 2; long e = 2; long f = 1; long h = 0; while (b != c) {
if (d * e == b) { f = 0; } e = e + 1; if (e == b) { d = d + 1; if (d == b) { if (f == 0) {
h = h + 1; } } else { e = 2; continue; }
} else { continue; } b = b + 17; d = 2; e = 2; f = 1; }
I'm failing to see the condition under which "f" failes to be 0. It ALWAYS can be 0 because "e" being increment by +1 so b/2 eventually will match "e" at some iteration
Cameron Jenkins
Not if b is prime. Which means it is NOT divisble by any numbers but 1 and itself. Also remember the variables are integers.
Brayden Lee
This is not the right structure. The e==b and d==b are both loops, and f=o is nested inside the two loops. That makes it go through all pairs of numbers less than b and check if the multiply to b, thus being a primality check.
Jaxon Butler
Will I be able to do those problems after this event ends?
Owen Harris
No. On 26th the page goes 404.
Adrian Anderson
Based on the fact that the older ones are still available, probably.
Julian Reed
But what if problem 25 is so incomprehensibly hard that no one solves it in 24 hours?
Adrian Perez
Tough luck. Noone gets a point. Everyone's a loser.
Bentley Wright
I'm getting 501 as an answer which cant be right
Jason Phillips
>The e==b and d==b are both loops, and f=o is nested inside the two loops. They are loops just implemented via `IF` and `continue` The state does not reset with `continue` only if cycle finishes normally
Dominic Murphy
>Not if b is prime. Which means it is NOT divisble by any numbers but 1 and itself. Incorrect. B isnt static, it is being increment by +17 each loop. And nor d nor e are static too, they arent always w, they increment too. At some point d and e are the exact values multiplication of which equals current b
Nathan Richardson
If the i-th increment is prime you won't find a tuple (d,e) such that d*e=b. So you have to skip to next increment. Therefore f remains 1 and h won't increment in the i-th iteration.
Eli Thompson
This cant be right, because it means the only way h increments if b%2 ==0 which gives answer 501 and I know this answer is incorrect.
Jordan Moore
That's not the right answer. Your answer is too low. (that is if [107900,124900] is your interval)
H icrements if b is a composite, not necessarily an even number. Suppose b=107917 (it's the first increment). For d=311 and e=347 you get: 311 × 347 = 107917. Which means f remains 1, and h won't increment.
Jordan Scott
reposting for autism's sake:
Can you tell the lad who creates the next thread to consider adding a link to this:
contains - links to all /aocg/ generals by # - links to first posts after puzzle announcement by day
To quickly get clickable links, paste it in rst.ninjs.org
I'll keep the bitch updated.
Also, does anyone know of a pastebin-like that does clickable links and can do editing/deletion of pastes?
Brody Foster
Went and started solving the days I missed (1-10,16)
Day 7, part 2, Scala in fitty "readable" lines 1. Helpers: case class Node(id: String, weight: Int) { var parent = Option.empty[Node] var kids = Vector.empty[Node] lazy val treeWeight: Int = weight + kids.map{_.treeWeight}.sum