/aocg/ - Advent of Code 2017 General #24

Previous thread: Too intelligent for math edition

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:

notehub.org/3zo8a
pastebin.com/raw/MUjA4Lb3
pastebin.com/BXx1d33k
ghostbin.com/paste/vk3u2
rst.ninjs.org
twitter.com/NSFWRedditImage

Reposting my explanation from the old thread: notehub.org/3zo8a

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)

Finally fucking finished it.
Being this tired doesn't mix well with reverse engineering.

>simple math calculations
>"le reverse engineering!"

are you trying to make yourself look big and mighty?

>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.

// 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.

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.

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

> give me complete algorithm and I will rewrite it in my favourite language

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

>A skill everyone here will be tested on countless times in real life
this, but unironically

>Not basing you career on startup hopping so you never need to worry about the past or the future

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.

>this, but unironically
Yes I know, I was being unironic

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?

Brainlet here,
does this line (30) mean that the program ends right? since there are not instructions left 3 lines after this.

>h = h - 1
Look closely. If it's like my puzzle, it's actually subtracting -1 (adding 1).

1) It's probable h - (-1)
2) You're missing the condition that enables h to change and then resets

Yes. But it can only reach that instruction if g == 0. Otherwise it will start over from line 9.

Yeah, that's basically exit()

>2) You're missing the condition that enables h to change and then resets
what
H never resets
there is only one H operation

Reding. The condition resets

The condition resets.

How fast would this program run if you translated it naively into x86 assembly?

>mfw

it's ogre

Don't try too much with wrong answers, you'll get locked out of the question

It would still loop roughly six trillion times

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.

Whatever it has stopped being fun so I couldnt care less
at least 40% of puzzlesi n this AoC were shit, this one especially

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.

Never forget about the six gazillion iterations

>Tfw I counted 999 loops instead of 1000 and had to wait 5 mins to input answer+1

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.

You got 1000. There are 1000 numbers you test for primality/composition. Meaning your algorithm failed to detect composite/prime. Check the condition.

If assembly code is so fast, how come I can compute the answer faster on paper?

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

You use different algorithm.

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

h is changed only if f is zero. Look where f is set to 0.

There are thousand loops in which H resets to 1. There

it is always zero if it passed d, it just takes FUCKTON of empty loops

No, it's not always 0. The thing checks if e*d passes b, which is not true if b is prime.

>it is always zero if it passed d
Wrong

not in my case, the e only resets if h changed so H always changes every loop

>People here cry too much
My opinion on Sup Forums as a whole.

I'm 95% sure that we all have exactly the same assembly with a constant changed at the top. Pastebin your input.

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.

Please make this part of the OP image

Welp, it was 10 times, then you get disqualified.

pastebin.com/raw/MUjA4Lb3

>small sweatshop of Taiwanese math nerds.
Does this count as a computer? I wouldn't know to program it though

Yes human wagecucks count as computers

This needs to make it into the calendar image for today.

Our input is the same except for a constant. What makes you think e resets only if h is changed?

what was you answer?
I cant check mine anymore because it is locked now.

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.

>mfw men invented computers to get rid of women in the workplace

903 was my answer. I can check your best guess if you like.

my last attempt before I got disq. was 168

Way off

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.

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.

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

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.

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

You can post here. We can check your answer.

this

about 1.32 increments per minute
the answer is around 900
so about 681 minutes or 11.36 hours
on my machine, anyway

It gets slower as it goes, since b grows.

4 hours later but I did it..

Great job! This was not an easy puzzle.

pastebin.com/BXx1d33k
shouldn't this result in 1000 or am I a brainlet?

Brainlet confirmed.
Tip: translate to higher level pseudocode

Less than 1000
Not every iteration increments `h`

There are only 1000 checked, so no input should give that.

i see it now thanks

>primality check
its like i'm doing a project euler problem

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

Not if b is prime. Which means it is NOT divisble by any numbers but 1 and itself.
Also remember the variables are integers.

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.

Will I be able to do those problems after this event ends?

No. On 26th the page goes 404.

Based on the fact that the older ones are still available, probably.

But what if problem 25 is so incomprehensibly hard that no one solves it in 24 hours?

Tough luck. Noone gets a point. Everyone's a loser.

I'm getting 501 as an answer which cant be right

>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

>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

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.

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.

That's not the right answer. Your answer is too low. (that is if [107900,124900] is your interval)

Yeah I know
int b1 = 107900;
int z = 0;
while (b1

>mfw

...

nvm I'm retarded I'm checking composite incorrectly

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.

reposting for autism's sake:

Can you tell the lad who creates the next thread to consider adding a link to this:

ghostbin.com/paste/vk3u2

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?

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

def postOrderIterator: Iterator[Node] =
kids.iterator.flatMap{_.postOrderIterator} ++ Iterator(this)

final def root: Node = if (parent.isDefined) parent.get.root
else this }

def parseTree(lines: Iterator[String]): Node = {
val kidsOf = collection.mutable.Map[String,Vector[String]]()
val parentOf = collection.mutable.Map[String,String]()
val id2node = collection.mutable.Map[String,Node]()

// create nodes, parent-child maps
lines foreach {
def s2node(s: String) = {
val NameWeight = """(\S+) \((.*)\)""".r
s match { case NameWeight(n,w) => Node(n,w.toInt) } }

_.split(" -> ") match {
case Array(nw) => val n = s2node(nw); id2node(n.id) = n
case Array(pNW, cidsS) => {
val p = s2node(pNW)
id2node(p.id) = p

val cids = cidsS.split(", ").toVector
kidsOf(p.id) = cids
cids foreach {parentOf(_) = p.id} } } }

// Link nodes
for (p

>That's not the right answer.
The amount of primes between 107900 and 124900 is 94 and since I need to find composite, I just 1000-94=906

Where were you when you realized Advent is just recruitment ground for The CIA/NSA/DOD?

Pic related is glguy on the leaderboards. He also holds more a decade's haskell experience.