adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
mfikes 2017-12-18T00:03:41.000146Z

Is Val's exponentiation somewhat along the lines of saying x^16 = (x^8)^2 = ((x^4)^2)^2 = (((x^2)^2)^2)^2 ? (Thus leading to logarithmic time complexity?)

mfikes 2017-12-18T00:05:03.000075Z

The pre- and post- multiplication aspect is frigging cool too!

val_waeselynck 2017-12-18T00:57:44.000071Z

@mfikes exactly :)

val_waeselynck 2017-12-18T01:51:41.000162Z

@mikelis.vindavs AFAICT the main difference is that in your solution, compilation consists of composing functions to avoid the cost of navigating data structures, whereas in mine it consists of compacting the steps into a concrete data structure - which is what enables exponentiation

bhauman 2017-12-18T02:51:14.000135Z

wow this is really cool

2017-12-18T03:30:43.000054Z

weekend is done, need to catch up (^_^;)

mikelis 2017-12-18T09:21:11.000127Z

Hmm it’s function composition only in the sense that mapping a vector of indices over a vector of indices is composition. I’m compiling the dance down to 2 actions - spin+exchange and partner. They could each be passed to exponentiate to get the nth result

mikelis 2017-12-18T09:21:23.000012Z

Actually I should probably try that :)

2017-12-18T11:08:27.000328Z

aww man, stuck ininfinite loops for 18pt2

orestis 2017-12-18T11:10:31.000003Z

Day 18 is fun; I implemented my first multi method for part 1, and I’m tempted to use core.async for part 2 🙂

2017-12-18T11:27:26.000140Z

oh shit.. is it first in first out.. ahhhhhhh

2017-12-18T11:27:46.000266Z

lol

2017-12-18T11:28:44.000157Z

damn

2017-12-18T11:28:47.000367Z

ok got it

2017-12-18T11:29:09.000079Z

time to go home

2017-12-18T14:36:33.000180Z

http://adventofcode.com/2017/day/16 it just struck me that wrapping the function from the part 1 in memoize would be even less work than finding cycles

2017-12-18T14:36:49.000125Z

and it looks like it finishes in 5 minutes, thanks clojure

bhauman 2017-12-18T14:45:38.000206Z

ok the instructions are really unclear on this one, does "how many sent" mean "sent and received" ?

borkdude 2017-12-18T14:46:08.000027Z

I’m counting the messages that p1 sends (so not on the queue but sent in total).

borkdude 2017-12-18T14:46:16.000409Z

But I haven’t finished it yet.

bhauman 2017-12-18T14:46:35.000159Z

yeah I'm counting that and my answer is wrong, too high to be exact

borkdude 2017-12-18T14:46:59.000033Z

My program doesn’t halt. And when it did it was indeed too high.

borkdude 2017-12-18T14:47:12.000061Z

How long does yours take to run?

bhauman 2017-12-18T14:47:22.000198Z

not long

bhauman 2017-12-18T14:47:26.000365Z

22s

borkdude 2017-12-18T14:47:38.000357Z

ok, there must be an error in mine somewhere. I’ll look at it tonight

bhauman 2017-12-18T14:48:24.000005Z

ok what about this what if one program comes to and end and the other is still running sending its little heart out

borkdude 2017-12-18T14:49:07.000221Z

that’s not deadlock

borkdude 2017-12-18T14:49:26.000335Z

at least not for both programs

ihabunek 2017-12-18T14:50:29.000259Z

deadlock is reached when both programs are stuck on rcv, so it means they received all messages sent by the other

ihabunek 2017-12-18T14:50:39.000561Z

so it shouldn't matter if you count sent or received

ihabunek 2017-12-18T14:51:03.000332Z

but my result is wrong, so what do i know.

bhauman 2017-12-18T15:05:56.000410Z

I was counting wrong

bhauman 2017-12-18T15:06:20.000396Z

I was counting messages received let's see if that fixes it

ihabunek 2017-12-18T15:14:55.000138Z

lol, i just got: > That's not the right answer; your answer is too high. Curiously, it's the right answer for someone else; you're either cheating, logged in to the wrong account, or got an unlucky guess.

ihabunek 2017-12-18T15:15:01.000271Z

^^;

bhauman 2017-12-18T15:15:13.000276Z

I got that too, I was copying your answer though 🙂

ihabunek 2017-12-18T15:15:31.000123Z

this was a total accident

bhauman 2017-12-18T15:15:36.000262Z

yeah me too

ihabunek 2017-12-18T15:15:40.000051Z

at least i'm in the right ballpark

orestis 2017-12-18T15:22:58.000426Z

Bah, I get a too-low number as an answer for part 2.

bhauman 2017-12-18T15:24:08.000698Z

I'm now walking through my instructions step by step, and "everything seems correct"™️

2017-12-18T15:37:01.000248Z

Be careful of the jumps X value

mfikes 2017-12-18T15:43:02.000525Z

@bhauman Given the backlog here, I wonder if there might be a bug in Advent of Code. If your input is available, and you give me the answer you are getting, I could run my code on your input and see if I get the same answer as you. (You could theoretically do the same, but you might not want to be spoiled by seeing any code, or any answers. That last aspect could be fixed by using == instead of having the code emit the answer.)

bhauman 2017-12-18T15:43:32.000196Z

@mfikes yeah I'd love that

ihabunek 2017-12-18T15:43:33.000365Z

cool,

ihabunek 2017-12-18T15:43:39.000341Z

i'll pm you

borkdude 2017-12-18T15:43:46.000565Z

If there were a bug, it would be a hot topic on Reddit by now?

bhauman 2017-12-18T15:43:56.000011Z

good point

borkdude 2017-12-18T15:43:56.000476Z

(didn’t check Reddit yet)

mfikes 2017-12-18T15:44:06.000688Z

Yeah. Unless lots of people are building up anxiety right now, ready to start posting.

mfikes 2017-12-18T15:44:55.000300Z

To be honest, this problem was sufficiently complex where an error on AoC side seems slightly possible.

bhauman 2017-12-18T15:45:42.000642Z

@bhauman uploaded a file: https://clojurians.slack.com/files/U064J0EFR/F8GA5TAP6/-.clj

bhauman 2017-12-18T15:46:08.000687Z

output: 7477

bhauman 2017-12-18T15:46:12.000337Z

really?

borkdude 2017-12-18T15:49:41.000304Z

HINT

mfikes 2017-12-18T15:51:23.000193Z

@borkdude Spec saved my ass immediately with that particular gotcha

borkdude 2017-12-18T15:51:24.000511Z

ok… jgz can also take two ints as operators

borkdude 2017-12-18T15:51:39.000108Z

jgz 1 3, I definitely didn’t handle that case. Thanks to this reddit comment: https://www.reddit.com/r/adventofcode/comments/7kkumq/help_2017_day_18_part_2rust_stuck_on_infinite_loop/

borkdude 2017-12-18T15:52:07.000389Z

long live Spec!

ihabunek 2017-12-18T15:52:09.000145Z

i discovered that when i got an exception

borkdude 2017-12-18T15:52:27.000539Z

If I’d used a decent parser (non handwritten) I would have discovered it too

bhauman 2017-12-18T15:52:38.000420Z

yeah but > doesn't work very well on 'p

borkdude 2017-12-18T15:53:28.000186Z

@bhauman What do you mean?

bhauman 2017-12-18T15:53:49.000255Z

jgz p p

mfikes 2017-12-18T15:53:55.000354Z

@bhauman For your input (which differs from mine in only one instruction), I get a lower value of output than 7477

bhauman 2017-12-18T15:54:21.000705Z

cool that's what AoC is telling me

borkdude 2017-12-18T15:54:34.000030Z

@bhauman That is valid. You should compare p to zero and jump the value of p if p > 0.

mfikes 2017-12-18T15:54:39.000421Z

What was your part 1 answer, @bhauman I can check that as well

bhauman 2017-12-18T15:55:01.000236Z

my part 1 answer was accepted at 8600

borkdude 2017-12-18T15:55:16.000136Z

My part 1 was 3188

mfikes 2017-12-18T15:55:18.000711Z

Cool. That's what I'm getting on your input as well.

ihabunek 2017-12-18T15:56:12.000102Z

ok, so it's not a bug, we're just stupid 🙂

bhauman 2017-12-18T15:56:28.000426Z

@borkdude I here you I got what you were saying backwards

2017-12-18T15:56:41.000150Z

weird, mine was 8600 as well

ihabunek 2017-12-18T15:56:57.000466Z

mine too

ihabunek 2017-12-18T15:57:11.000380Z

no idea how many variants of input exist

mfikes 2017-12-18T15:58:13.000510Z

This part 2 is brutal because if you get it wrong, then there isn't much to go on...

1
bhauman 2017-12-18T15:58:14.000655Z

I looked at @mfikes code and we are basically doing the same thing so the is obviously a wrong assumption in my code

mfikes 2017-12-18T15:58:28.000577Z

(I got part 2 wrong a couple of times, but was able to suss it out.)

bhauman 2017-12-18T15:58:44.000636Z

yeah they don't give you a real example program and answer for part 2

mfikes 2017-12-18T15:58:58.000280Z

Ahh, good point...

ihabunek 2017-12-18T15:59:09.000143Z

having a very close answer is a pain because it's not obvious what's wrong

mfikes 2017-12-18T15:59:50.000216Z

@bhauman Since you looked at my code, you can also diff your input with mine. Up to you.

mfikes 2017-12-18T16:00:14.000270Z

I don't see how that diff would provide much of a clue... hmm

bhauman 2017-12-18T16:00:34.000571Z

thanks, well I would have an example program and output to target

mfikes 2017-12-18T16:00:43.000070Z

True 🙂

bhauman 2017-12-18T16:00:57.000564Z

so I'm not just chasing nothing

bhauman 2017-12-18T16:07:51.000323Z

oh I think I found it

bhauman 2017-12-18T16:12:18.000513Z

its a very very clojure trap to fall into

mfikes 2017-12-18T16:12:22.000474Z

Please. I'm really curious now.

2017-12-18T16:15:25.000471Z

https://repl.it/repls/CompassionateGroundedHalicore this is my 1st part

orestis 2017-12-18T16:19:46.000014Z

Ah! Read the requirements, the p register is not that special…

ihabunek 2017-12-18T16:21:20.000578Z

it's just pre-populated

orestis 2017-12-18T16:21:53.000054Z

Yep; I misread that somehow as “it resolves always to 0 or 1”.

orestis 2017-12-18T16:26:08.000903Z

@mfikes Ah, clojure.lang.PersistentQueue - this doesn’t show up on my Dash doc viewer…

mfikes 2017-12-18T16:27:53.000561Z

@orestis Yes. I wonder if Clojure will get a reader tag for it like ClojureScript has.

mfikes 2017-12-18T16:29:14.000454Z

^ https://dev.clojure.org/jira/browse/CLJ-976

orestis 2017-12-18T16:30:13.000198Z

I was looking for a way to do an atomic pop-and-return-value, that would return [head, rest-of-coll] — I initially thought of running the two programs in two threads and use some of Clojure’s concurrency constructs, but I don’t know enough and it seemed a bit fiddly.

bhauman 2017-12-18T16:32:50.000659Z

I won't spoil it by saying what hung me up but feel free to message me if you want to know

borkdude 2017-12-18T16:33:00.000783Z

@orestis you can use compare-and-set for that… I tried it, but my program isn’t working yet 🙂

borkdude 2017-12-18T16:33:28.000413Z

@bhauman Feel free to put a HINT in a thread under this message

bhauman 2017-12-18T16:34:20.000383Z

HINT

bhauman 2017-12-18T16:35:38.000563Z

my problem was a common clojure problem

bhauman 2017-12-18T16:35:57.000535Z

I was using a vector for an input-queue

bhauman 2017-12-18T16:36:09.000530Z

and using conj to append to the end

bhauman 2017-12-18T16:36:24.000255Z

but then the queue type got flipped to a seq

bhauman 2017-12-18T16:36:39.000151Z

and then conj started adding to the front

borkdude 2017-12-18T16:36:52.000314Z

hmm, I used a PersistentQueue for that

orestis 2017-12-18T16:37:10.000252Z

That is so annoying. I thought of that, and in the end just used (vec (rest ..))

borkdude 2017-12-18T16:37:44.000391Z

Is PersistentQueue somehow not valid for this problem?

mfikes 2017-12-18T16:38:03.000363Z

@borkdude That's what I used

bhauman 2017-12-18T16:38:03.000364Z

@borkdude just not needed in my implementation

borkdude 2017-12-18T16:38:23.000072Z

ok, phew… my program still won’t terminate… annoying.

bhauman 2017-12-18T16:38:41.000232Z

my runtime is 500ms

orestis 2017-12-18T16:38:43.000110Z

I couldn’t figure out a way to make the two program communicate cleanly what with the circular dependency; I took a different approach.

orestis 2017-12-18T16:38:51.000087Z

Yes, it should end within 3-4 seconds…

mfikes 2017-12-18T16:38:54.000615Z

@borkdude I was hypothesizing: If you implement it with threads, is a potential outcome a bona fide deadlock.

borkdude 2017-12-18T16:39:27.000486Z

I didn’t do threads. To make it easy on me I started using two atoms with a PersistentQueue in each which are shared with both programs.

bhauman 2017-12-18T16:39:40.000196Z

persistent queue is better for this

borkdude 2017-12-18T16:40:06.000130Z

I first had an algorithm which exchanged the queues after each iteration, but since that didn’t work I turned to atoms.

bhauman 2017-12-18T16:40:07.000771Z

I'm still doing stepwise evaluation in mine

borkdude 2017-12-18T16:40:35.000404Z

I had some stupid mistakes like not setting the init value properly and things like that. There might still be something like that in there.

orestis 2017-12-18T16:40:36.000033Z

I took a hint from the puzzle description, and run the programs one-by-one until they block…

bhauman 2017-12-18T16:40:55.000701Z

right on that's my approach

mfikes 2017-12-18T16:41:20.000477Z

I wonder if there is a name for that approach. Greedy zig-zag?

borkdude 2017-12-18T16:41:41.000513Z

This is what I’m trying right now: run program 1 until it’s waiting, then turn to program 2, etc. until they are both waiting.

ihabunek 2017-12-18T16:41:54.000369Z

i'm a colossal idiot.

borkdude 2017-12-18T16:41:57.000442Z

Should work right?

bhauman 2017-12-18T16:41:59.000672Z

oh I'm not doing that

ihabunek 2017-12-18T16:42:12.000257Z

programs are 0-indexed

borkdude 2017-12-18T16:42:16.000364Z

Since the speed is arbitrary it should be valid.

bhauman 2017-12-18T16:42:19.000849Z

each program gets one instruction evaluated each step

ihabunek 2017-12-18T16:42:23.000091Z

so "program 1" is the second program

ihabunek 2017-12-18T16:42:31.000618Z

i was calculating the value for first

mfikes 2017-12-18T16:42:33.000024Z

I made that mistake, FWIW 🙂

ihabunek 2017-12-18T16:42:35.000160Z

😢

borkdude 2017-12-18T16:42:46.000370Z

They are not running on their own instruction set?

ihabunek 2017-12-18T16:42:52.000256Z

i lost over an hour 😄

bhauman 2017-12-18T16:43:21.000120Z

yes each program runs its own set

borkdude 2017-12-18T16:43:28.000411Z

yeah

bhauman 2017-12-18T16:43:37.000003Z

or rather each has its own program-counter

ihabunek 2017-12-18T16:43:49.000025Z

sorry, should this have been under a HINT?

borkdude 2017-12-18T16:43:51.000434Z

right, the instructions are immutable, but each has their own counter

bhauman 2017-12-18T16:43:55.000355Z

I don't think so

bhauman 2017-12-18T16:44:09.000316Z

I'm in the dunce club as well

mfikes 2017-12-18T16:45:09.000800Z

Bruce, is it fair to say your queue s are of length 1?

mfikes 2017-12-18T16:45:56.000146Z

Hmm. Maybe not... still trying to grok it.

bhauman 2017-12-18T16:46:37.000301Z

only my output-queue

mfikes 2017-12-18T16:46:39.000508Z

Ahh, I see how you pull an item off the front of the vector.

mfikes 2017-12-18T16:47:09.000643Z

Interesting. So you have 4 queues.

bhauman 2017-12-18T16:47:31.000520Z

really only two

mfikes 2017-12-18T16:47:47.000111Z

Cool. 2 of them are just temporary buffers

bhauman 2017-12-18T16:47:49.000019Z

output-queue is a misnomer

bhauman 2017-12-18T16:48:07.000189Z

should be output-message

mfikes 2017-12-18T16:48:12.000386Z

Yeah, maybe output-port of somesuch

orestis 2017-12-18T16:48:15.000574Z

Similar to my dynamic rebinding dance so that p always evaluated to 0 or 1, rather than been just propulated. 45 minutes 🙂

bhauman 2017-12-18T16:48:17.000867Z

yeah

bhauman 2017-12-18T16:49:25.000645Z

I like that the states of the to programs are separate and then cross pollinated in a separate step

orestis 2017-12-18T16:49:37.000164Z

I get the correct answer by doing that zig-zag; run 0 until blocks, then 1 until blocks. The logic to detect the deadlock is a bit gnarly though.

bhauman 2017-12-18T16:51:02.000697Z

nope here:

bhauman 2017-12-18T16:51:20.000676Z

I skipped the fnil

mfikes 2017-12-18T16:51:28.000767Z

Ouch. Harder to see that one.

bhauman 2017-12-18T16:53:06.000005Z

if I'd just had the habit of using a persistent-queue it wouldn't have been a problem

mfikes 2017-12-18T16:53:54.000124Z

Yeah, that p thing was a bit odd.

bhauman 2017-12-18T16:54:17.000149Z

its how they got different behavior from the same program

orestis 2017-12-18T16:54:18.000612Z

Isn’t this a prime candidate of where a persistent data structure is more trouble? Because you need to make sure that both references point to the updated one.

mfikes 2017-12-18T16:54:22.000610Z

Perhaps it is what makes the programs follow a different path?

mfikes 2017-12-18T16:55:36.000160Z

Cool. The use of p while also using the words “p rogram ID” probably caught a lot of people off guard if you don't read the description carefully.

borkdude 2017-12-18T17:03:16.000425Z

I didn’t read this properly: > Once both of your programs have terminated (regardless of what caused them to do so) This means that not both programs have to be deadlocked…

borkdude 2017-12-18T17:04:20.000537Z

right?

mfikes 2017-12-18T17:05:06.000294Z

Well, one could fall of the end of the instruction range....

orestis 2017-12-18T17:05:16.000745Z

The only other case where a program terminates is when it jumps before or after the instruction list; so then the other keeps on going. But to be honest in my input both programs end up as blocked.

mfikes 2017-12-18T17:05:38.000424Z

It is interesting if you look at https://adventofcode.com/2017/stats and calculate the percentage of participants who haven't completed part 2 for each day:

{1 16,
2 14,
3 26,
4 9,
5 4,
6 4,
7 23,
8 2,
9 2,
10 9,
11 3,
12 3,
13 9,
14 8,
15 2,
16 11,
17 7,
18 39}

mfikes 2017-12-18T17:06:10.000232Z

Something was up with day 7

borkdude 2017-12-18T17:06:15.000250Z

yeah, I would get an exception if that would happen

mfikes 2017-12-18T17:07:01.000034Z

Ahh right, day 7 involved some tricky math mixed with recursion

mfikes 2017-12-18T17:07:41.000235Z

I think that one had the highest missed guess rate for me, and I ultimately solved it by hand before successfully writing proper code for it.

mfikes 2017-12-18T17:08:11.000052Z

Yes me too.

ihabunek 2017-12-18T17:08:21.000139Z

day 3 was tricky as well, i remember my group of friends had trouble solving it

ihabunek 2017-12-18T17:09:11.000419Z

fortunately, i had solved something similar recently doing the python challenge

mfikes 2017-12-18T17:10:30.000662Z

@borkdude Do you end up with both programs going into a waiting state, or do they just keep running indefinitely?

borkdude 2017-12-18T17:11:05.000352Z

This is my output before I cancel execution:

1 waiting...
1 waiting...
1 waiting...
1 waiting...
1 waiting...
1 waiting...
1 waiting...
1 waiting...
1 waiting...
1 waiting...
1 waiting...
boot.user> 

mfikes 2017-12-18T17:12:05.000109Z

That means that program 1 is waiting?

borkdude 2017-12-18T17:12:14.000430Z

yes (program 0 is still running)

mfikes 2017-12-18T17:13:15.000016Z

That would seem to imply program 0 is running but never sending.

mfikes 2017-12-18T17:13:34.000137Z

(Like an infinite loop without a snd instruction.)

borkdude 2017-12-18T17:14:05.000495Z

hmm yes…

ihabunek 2017-12-18T17:15:22.000280Z

what if you just run program 0 until it blocks for the first time? does that ever happen?

borkdude 2017-12-18T17:15:38.000633Z

going to test..

orestis 2017-12-18T17:16:07.000057Z

Dumping the queues at every step also helps.

borkdude 2017-12-18T17:16:12.000522Z

I’m printing the buffers now. ^

borkdude 2017-12-18T17:16:50.000417Z

it seems buffer 0 is not properly filled up

borkdude 2017-12-18T17:17:05.000525Z

(the one program 1 should read from)

borkdude 2017-12-18T17:19:21.000684Z

This is obviously very wrong:

p0 is writing to buf0 4424
[] [3142 7236 6781 1615 9553 9174 487 5263 8490 4877 7397 1572 2781 724 7087 1957 2396 4361 7509 630 3489 7917 1716 2592 7872 5372 8575 4031 8051 4352 5790 9023 9786 1147 1335 8212 9615 4144 2025 4572 4593 5030 3448 9823 4746 9209 5195 208 8618 9927 8093 6367 4333 5895 8710 4486 911 7895 1137 1585 8978 4112 6266 9370 5106 7721 5788 1700 4571 1129 2265 3188 6142 3291 2270 3551 6243 7724 8606 4149 5014 4268 9066 8617 474 933 645 8505 364 1643 9447 8181 3920 95 9224 1056 5457 6781 2362 2203 2164 3543 4309 3842 8826 7245 8414 5958 8188 110 7505 767 1239 9936 1807 5936 4265 1283 1809 4109 8173 385 3587 3021]

fellshard 2017-12-18T17:27:55.000363Z

I considered moving my solution to a linearized version just to see how the solution works itself out differently. I ended up running both programs in parallel at each step, then syncing outputs of each into each other's queues to conclude the step.

borkdude 2017-12-18T17:36:54.000592Z

Hm, seems to be correct after all:

buf0 changes to [1335]
1 waiting...
buf0 changes to []
prog 1 succeeded reading 1335

borkdude 2017-12-18T17:39:37.000281Z

I think I might have the situation where p1 writes so fast to the queue that compare-and-set never wins

borkdude 2017-12-18T17:40:11.000183Z

which is a deadlock in and of itself

bhauman 2017-12-18T18:12:16.000293Z

concurrent programming is hard 😬

ihabunek 2017-12-18T18:18:32.000257Z

<hint> i just ran the first program until it blocked, then the second, and did that in a loop until both were blocked

borkdude 2017-12-18T18:18:51.000136Z

yeah I had that at first, I might revert to that. Thanks!

borkdude 2017-12-18T19:25:44.000075Z

I keep getting 127, but that’s not the right anwer

mfikes 2017-12-18T20:31:48.000257Z

@borkdude Getting 127 was also one of my failure modes, FWIW.

mfikes 2017-12-18T20:35:21.000211Z

@borkdude I'm able to repro how I produced 127, if you end up wanting a hint.

borkdude 2017-12-18T20:47:05.000212Z

Yes please sir.

mfikes 2017-12-18T20:57:53.000338Z

@borkdude My coding error that produced 127 involved an incorrect calculation for when a program is blocked.

mfikes 2017-12-18T20:58:28.000624Z

In other words, it concluded that it was blocked, when it need not be.

mfikes 2017-12-18T20:58:51.000513Z

(Not sure if these vague hints are adding confusion.)

borkdude 2017-12-18T20:59:07.000024Z

I think I get what you mean yeah

borkdude 2017-12-18T20:59:25.000373Z

This is my end condition…

(and (:waiting? p0)
                   (:waiting? p1)
                   (empty? (:in p0))
                   (empty? (:in p1)))

mfikes 2017-12-18T20:59:55.000187Z

Cool. My 127 error involved the lack of the empty? checks.

borkdude 2017-12-18T21:00:02.000504Z

😢

mfikes 2017-12-18T21:00:54.000084Z

It was pretty cut-n-dry for me because one of the programs was marked as waiting when it had stuff left to consume in its queue.

mfikes 2017-12-18T21:01:32.000379Z

Do you mark a program as :waiting? when it tries to rcv but finds its inbound queue is empty?

borkdude 2017-12-18T21:02:15.000254Z

yes

mfikes 2017-12-18T21:02:34.000358Z

Cool. That sounds right. (It matches my logic.)

mfikes 2017-12-18T21:02:46.000492Z

Do you ever unmark the :waiting? flag?

borkdude 2017-12-18T21:03:42.000440Z

snd
      (let [v (get-val registers reg)]
        (do (when (= id 1)
              (swap! p1-sending inc)))
        (->
         p
         (update :ctr inc)
         (update :out conj v)))
      rcv (if-let [v (peek in)]
            (assoc p
                   :in (pop in)
                   :waiting? false)
            (assoc p :waiting? true))

borkdude 2017-12-18T21:04:06.000284Z

the p1-sending is just a hack for now which I would clean up when I find the answer

mfikes 2017-12-18T21:08:49.000065Z

Is :ctr the instruction pointer?

mfikes 2017-12-18T21:10:41.000475Z

If so, I'm wondering if the instruction pointer is incremented upon a successful (non-`:waiting?`) rcv

mfikes 2017-12-18T21:15:19.000229Z

Another potential problem @borkdude is that the v associated with rcv is discarded.

mfikes 2017-12-18T21:15:36.000312Z

(Can't tell from the code fragment.)

borkdude 2017-12-18T21:18:13.000167Z

The program counter was missing indeed.. I refactored it and forgot. Now it doesn’t terminate…

borkdude 2017-12-18T21:18:18.000142Z

Another good point. Brb!

borkdude 2017-12-18T22:10:28.000503Z

FWIW here’s my day 18 so far… https://github.com/borkdude/aoc2017/blob/master/src/day18.clj

borkdude 2017-12-18T22:12:26.000051Z

Oh, I should store the value on RCV…

borkdude 2017-12-18T22:13:38.000310Z

still 127 with that “fix"

erwin 2017-12-18T22:24:27.000353Z

shouldn't you reset the waiting state on a send?

borkdude 2017-12-18T22:25:26.000325Z

@erwin hm, why? I reset it when I received a value

erwin 2017-12-18T22:26:18.000180Z

if p1 sends you should reset waiting for p0

erwin 2017-12-18T22:26:52.000408Z

otherwise you stay in locked state, maybe I do not read your code correct and this is fixed in a different way

borkdude 2017-12-18T22:26:56.000166Z

doesn’t that happen when p0 receives the message?

erwin 2017-12-18T22:27:21.000069Z

but your loop-until-wait never gets there?

borkdude 2017-12-18T22:27:47.000032Z

it does next time in the loop

borkdude 2017-12-18T22:28:14.000358Z

I mean, it does next time next-state' is called I think?

erwin 2017-12-18T22:28:40.000250Z

https://github.com/borkdude/aoc2017/blob/master/src/day18.clj#L105 this is called the next time ?

borkdude 2017-12-18T22:30:11.000493Z

This is what’s happening: https://gist.github.com/borkdude/d54ad43d7001334adde2912c87d9a1d6

borkdude 2017-12-18T22:30:13.000058Z

@borkdude shared a file: https://clojurians.slack.com/files/U04V15CAJ/F8FRV8D32/gistfile1.txt

borkdude 2017-12-18T22:30:48.000198Z

so p0 builds up the out queue as far as possible

borkdude 2017-12-18T22:31:06.000381Z

then p1 takes over and does the same

borkdude 2017-12-18T22:31:24.000234Z

eventually everything is empty and both are waiting

erwin 2017-12-18T22:32:29.000502Z

ah and then you are done, but the value is wrong

borkdude 2017-12-18T22:33:01.000506Z

right

bhauman 2017-12-18T22:37:08.000482Z

I'm looking at your code @borkdude and your jump counter looks weird to me

borkdude 2017-12-18T22:37:54.000395Z

tell

bhauman 2017-12-18T22:39:04.000505Z

it looks like you increment twice on zero?

borkdude 2017-12-18T22:39:17.000060Z

the idea is, it’s always incremented, unless (and then the old value ctr is used + something)

bhauman 2017-12-18T22:39:42.000366Z

gotcha you save the counter

bhauman 2017-12-18T22:39:58.000232Z

and overwrite

borkdude 2017-12-18T22:40:01.000101Z

right

borkdude 2017-12-18T22:40:20.000240Z

could someone try my input just for sanity?

erwin 2017-12-18T22:44:06.000291Z

do you want the answer?

bhauman 2017-12-18T22:44:10.000050Z

yep it runs

borkdude 2017-12-18T22:44:23.000391Z

just knowing it’s not 127 is good enough

erwin 2017-12-18T22:44:31.000314Z

it is not 127

bhauman 2017-12-18T22:44:32.000208Z

its up around our numbers

borkdude 2017-12-18T22:44:40.000317Z

in the ballpark of?

bhauman 2017-12-18T22:44:52.000137Z

no where near 127

borkdude 2017-12-18T22:45:02.000531Z

what is “our numbers"

bhauman 2017-12-18T22:45:04.000140Z

near above 7000

erwin 2017-12-18T22:45:14.000064Z

between 7000 - 8000

borkdude 2017-12-18T22:47:35.000413Z

I might save this one for christmas then… the first 😢

orestis 2017-12-18T22:48:42.000251Z

What happens if a program that is already waiting is re-run?

borkdude 2017-12-18T22:49:36.000005Z

then loop-until-wait returns the program

borkdude 2017-12-18T22:49:41.000384Z

without modification

orestis 2017-12-18T22:52:59.000263Z

But you don't give a chance to run while in waiting state? To see if new values arrived?

orestis 2017-12-18T22:54:56.000403Z

That is, loop-until-wait checks for the previously set waiting flag, not the current one, I think. Reading this on a mobile, might be misreading...

val_waeselynck 2017-12-18T22:55:05.000344Z

Ah right, I guess I misunderstood the code then

bhauman 2017-12-18T22:56:49.000261Z

@borkdude I just added some assertions to check that the input queue is empty before you overwrite it

bhauman 2017-12-18T22:56:53.000248Z

and it failed

borkdude 2017-12-18T22:57:06.000030Z

loop-until-wait lets a program consume its entire in queue and then returns it in a waiting state with an empty in queue

bhauman 2017-12-18T22:57:17.000207Z

its not empty??

borkdude 2017-12-18T22:57:46.000104Z

bhauman: I responded to orestis, didn’t see your comment yet… gonna check

bhauman 2017-12-18T22:57:47.000162Z

@bhauman uploaded a file: https://clojurians.slack.com/files/U064J0EFR/F8HC7DNFQ/-.clj

bhauman 2017-12-18T22:58:23.000132Z

i just posted a snippet to the main chat area

borkdude 2017-12-18T22:58:58.000324Z

thank you

borkdude 2017-12-18T22:59:08.000068Z

going to investigate

orestis 2017-12-18T22:59:34.000480Z

@borkdude yes but the second time round, it doesn't call next-state, does it? The waiting flag is only cleared after next state is run...

borkdude 2017-12-18T23:00:22.000080Z

aah

borkdude 2017-12-18T23:02:03.000529Z

I added both bhaumans assertions and your suggestion now… it’s running

bhauman 2017-12-18T23:03:29.000026Z

I know the answer if you want to check it

erwin 2017-12-18T23:03:47.000198Z

@borkdude I fixed a couple bugs in your code and it prints the correct answer now

erwin 2017-12-18T23:04:11.000504Z

(as in: the same as @bhauman and my code)

borkdude 2017-12-18T23:04:25.000066Z

that’s good… 🙂

borkdude 2017-12-18T23:05:03.000158Z

how many were there…?

erwin 2017-12-18T23:05:36.000030Z

the problem I suggested to you, and another

erwin 2017-12-18T23:05:52.000173Z

so 2

borkdude 2017-12-18T23:07:40.000045Z

@erwin is this one of the solutions?

(defn loop-until-wait
  [instructions prog]
  (loop [p (next-state instructions prog)]
    (if (:waiting? p)
      p
      (recur (next-state instructions p)))))

erwin 2017-12-18T23:09:17.000127Z

ah, yes, I fixed it different, but that would also work

erwin 2017-12-18T23:09:53.000454Z

for the other: please read carefully how the instructions work

borkdude 2017-12-18T23:10:23.000257Z

you mean snd and rcv specifically?

orestis 2017-12-18T23:10:33.000237Z

I'm off for the night -- I hope the elusive bug will be found soon :)

borkdude 2017-12-18T23:10:45.000331Z

thanks orestis

erwin 2017-12-18T23:11:38.000159Z

@borkdude no

erwin 2017-12-18T23:11:43.000221Z

zero check

borkdude 2017-12-18T23:15:50.000093Z

aaaaaaa ffffff

borkdude 2017-12-18T23:15:54.000029Z

thanks 🙂

erwin 2017-12-18T23:17:10.000081Z

your welcome 🙂

borkdude 2017-12-18T23:18:27.000074Z

aw man, without you guys I would still be sitting here until 3 AM 🙂

bhauman 2017-12-18T23:30:34.000153Z

I rearranged your logic and got it working, not that that is helpful

bhauman 2017-12-18T23:30:42.000132Z

but your code does work 🙂

borkdude 2017-12-18T23:31:50.000192Z

how is that not helpful?

borkdude 2017-12-18T23:32:01.000228Z

it’s super helpful!

borkdude 2017-12-18T23:32:09.000180Z

credits in the code: https://github.com/borkdude/aoc2017/blob/master/src/day18.clj

bhauman 2017-12-18T23:34:30.000069Z

you got it working!!!

borkdude 2017-12-18T23:35:25.000262Z

with a little help from my friends

bhauman 2017-12-18T23:36:44.000165Z

can I show you my alternative logic?

borkdude 2017-12-18T23:37:04.000001Z

yes

bhauman 2017-12-18T23:37:22.000083Z

@bhauman uploaded a file: https://clojurians.slack.com/files/U064J0EFR/F8GHRKGUC/-.clj

bhauman 2017-12-18T23:38:05.000074Z

in the main chat

mfikes 2017-12-18T23:38:09.000145Z

Ugh. So in the end it was a jgz vs. jnz mistake? That kind of stuff is insidious to find.

borkdude 2017-12-18T23:38:30.000070Z

@mfikes yes, that was one of the bugs. another one was pointed out by orestis and erwin

bhauman 2017-12-18T23:38:44.000073Z

yes and the first exercise was so week that it didn't detect it

borkdude 2017-12-18T23:39:02.000090Z

@bhauman what does #(reduce conj % (seq (:out p0) do, copy the queue?

borkdude 2017-12-18T23:39:08.000271Z

who not just take it as it is?

mfikes 2017-12-18T23:39:09.000069Z

The challenge on this one is you need to get all of the planets in alignment with no way of figuring out which (or which ones) are off

bhauman 2017-12-18T23:39:36.000116Z

I'm combining the queues because they are not empty now

bhauman 2017-12-18T23:39:44.000120Z

only taking one step at a time

borkdude 2017-12-18T23:39:47.000194Z

aaah and then it worked?

bhauman 2017-12-18T23:39:51.000273Z

yep

borkdude 2017-12-18T23:40:11.000114Z

wow

borkdude 2017-12-18T23:40:26.000151Z

good catch man

borkdude 2017-12-18T23:40:42.000128Z

I’m off to bed…

bhauman 2017-12-18T23:40:59.000247Z

have a good night

borkdude 2017-12-18T23:41:40.000004Z

thanks again