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
fellshard 2019-12-10T01:58:04.013900Z

Oooh, pretty. Is that using curses?

Mario C. 2019-12-10T02:10:24.015800Z

I kept getting the 203 error with day 9. All the tests cases worked. Even the ones made up by redditors but the actual input kept giving 203. Turns out it I left out the "2" in the condition for mode checking. Legit lost 4 hours tracking that down

Jean 2019-12-10T09:04:02.025100Z

You have an error on your 03 intcode with mode 2

pesterhazy 2019-12-10T22:00:14.064900Z

hehe, the error code is self-explanatory

Mario C. 2019-12-10T02:10:59.016300Z

Apparently (= val) is valid clojure

mpcjanssen 2019-12-10T04:18:25.016600Z

You were not the only one. 203 seems to have been the biggest stumbling block this day.

misha 2019-12-10T04:46:51.016800Z

(map-indexed (fn [i v] [i v]))

(map-indexed vector) 

๐Ÿ™ 1
fellshard 2019-12-10T06:36:54.019300Z

Today, I realize how much basic trig I've forgotten.

mpcjanssen 2019-12-10T08:00:39.023700Z

For part one I didn't need trig. Part 2 not so sure

rjray 2019-12-10T06:37:03.019500Z

Ayup.

2019-12-10T07:21:10.020400Z

so cool!!

2019-12-10T07:49:32.022500Z

I don't get day 10 description, the very first example says only 1 asteroid is unreachable, but looking at the map it's clear there are two of them :thinking_face:

2019-12-10T07:50:36.022600Z

do you mean the top right corner? that one is reachable

2019-12-10T07:52:04.022800Z

if there was an asteroid between the highlighted one and the top right corner, it would have to sit at a position with non-integer coordinates.

2019-12-10T07:52:27.023Z

โ€œevery asteroid is exactly in the center of its marked positionโ€

2019-12-10T07:54:09.023200Z

Oh right, that makes sense. The map put me in Manhattan distance state of mind.

2019-12-10T07:54:51.023400Z

:thumbsup::skin-tone-2: ๐Ÿ€

mpcjanssen 2019-12-10T08:47:37.024900Z

My laser already killed astroid 200 on the first round. Lucky I guess

mpcjanssen 2019-12-10T11:16:43.025800Z

Personal challenge for today, make it fast

2019-12-10T11:17:15.026100Z

donโ€™t forget about threads

2019-12-10T11:17:32.026400Z

pmap all the things

mpcjanssen 2019-12-10T11:18:55.027700Z

Want to look more into reducing algorithmic complexity. Using more power is cheating ๐Ÿ˜‰

mpcjanssen 2019-12-10T11:19:59.028300Z

Current solution is at least O(n^2)

mpcjanssen 2019-12-10T11:21:24.029600Z

I am checking all other asteroids to see if one is blocking the line of sight which is stupid

mpcjanssen 2019-12-10T11:21:50.030600Z

Better to determine LoS and see if it has astroids

misha 2019-12-10T11:22:12.031100Z

group-by angle, sort-by distance

๐Ÿ‘ 1
2019-12-10T11:22:58.031500Z

@mpcjanssen whatโ€™s LoS?

mpcjanssen 2019-12-10T11:23:09.032Z

line of sight

misha 2019-12-10T11:23:12.032100Z

line of sight

misha 2019-12-10T11:23:55.032400Z

how fast is fast for you?

mpcjanssen 2019-12-10T11:24:28.033300Z

right now it takes 16 secs want to improve to below 5

misha 2019-12-10T11:24:54.033800Z

"Elapsed time: 108.515633 msecs" "Elapsed time: 4.428149 msecs"

2019-12-10T11:25:33.034400Z

๐ŸŽ๏ธ

misha 2019-12-10T11:25:34.034500Z

had "seconds" p1 solution, then re-implemented with angles

misha 2019-12-10T11:25:51.034800Z

way less code, tests, and faster

mpcjanssen 2019-12-10T11:28:41.035Z

any link

misha 2019-12-10T11:30:17.035200Z

wasted too much time on it, so did not clean up https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/2019/day10.clj

mpcjanssen 2019-12-10T11:32:46.036400Z

ah so group by angle and take closest gives the visible astroids immediately

mpcjanssen 2019-12-10T11:36:38.038300Z

smart, i would just be worried about floating point inaccuracies in the angles.

yuhan 2019-12-10T11:39:22.039100Z

it's the first time I've ever found clojure's Rational type to be useful :)

misha 2019-12-10T11:40:36.040500Z

that "smart" solution cost me 2+ hours :harold:

yuhan 2019-12-10T11:41:12.041Z

just take the (/ dy dx) and count the frequencies

misha 2019-12-10T11:41:38.041900Z

tried to cycle outermost xys instead, but it was not granular enough, etc.

yuhan 2019-12-10T11:42:30.043100Z

with the exception that opposite quadrants give the same gradient, so take the sign of dy and dx to disambiguate

misha 2019-12-10T11:43:11.043400Z

yeah, spent time on adjusting coordinate system as well

mpcjanssen 2019-12-10T14:07:51.044400Z

@misha with groupby orderby it goes from 16s to 300ms

1
mpcjanssen 2019-12-10T14:08:12.044700Z

@misha

mpcjanssen 2019-12-10T14:10:46.045900Z

proving again that improving algoritm beats brute force at any day

mpcjanssen 2019-12-10T14:13:03.046300Z

simpler too

Average-user 2019-12-10T14:35:29.047100Z

Interesting, did something similar, you can use mod in your rotate function to avoid cond-> I think

uneman 2019-12-10T14:35:43.047300Z

done! Peeling asteroids clockwise from the inside was super easy with mapcat ๐Ÿ˜‰ https://github.com/namenu/advent-of-code/blob/master/src/year2019/day10.clj

1
uneman 2019-12-10T15:05:12.052300Z

there must be an floating point error because i didn't make rational number lowest form..

uneman 2019-12-10T15:06:25.052500Z

maybe we can avoid math functions at all.

mpcjanssen 2019-12-10T15:26:17.053400Z

Hmm my original algorithm was n^3

Mario C. 2019-12-10T16:41:55.054500Z

So I am guessing day 10 is when the questions start ramping up.

Mario C. 2019-12-10T16:43:14.055700Z

I have intcode PTSD now so I am afraid to hack together solutions for the sake of solutions and feel the need to write a scalable feature-wise solution.

Mario C. 2019-12-10T16:43:49.056100Z

Although my part 1 day 10 was a hack brute force

misha 2019-12-10T19:57:39.057200Z

how?

2019-12-10T20:46:53.057800Z

The angles idea is great! Although I struggled with orienting the co-ordinate frame! @misha

fellshard 2019-12-10T21:23:56.059300Z

Faffing around in the REPL let me figure it out by recollection and informed intuition. The quickest win for me was (thread for spoilers)

fellshard 2019-12-10T21:24:14.059400Z

|| to reverse the x and y arguments to atan2. || From there, you could convert the range by normal means.

fellshard 2019-12-10T21:25:25.059600Z

When you aren't familiar with the behaviour of a mathematical function, playing with it in the repl can sometimes be good enough. ๐Ÿ™‚

2019-12-10T21:28:21.060300Z

My day 10 solution: <https://github.com/chrisblom/advent-of-code/blob/master/src/adventofcode/2019/day10.clj>

2019-12-10T21:30:30.061400Z

Could be made more efficient, but it was fast enough for the input

2019-12-10T21:32:05.063200Z

Last years I remember that solutions already needed to be more efficient by day 10

ghadi 2019-12-10T21:39:57.063400Z

@misha nicely done

1
pesterhazy 2019-12-10T21:56:00.064600Z

Took me a while today because (like last year) I had to read up on dot products and atan2

pesterhazy 2019-12-10T21:58:12.064700Z

REPL driven math?

fellshard 2019-12-10T22:00:48.065100Z

Pretty much - take a sampling of inputs, examine the outputs to make sure you're understanding your changes correctly. Here, I did a quick guess in my head as to what flipping the coordinates would do, confirmed it in the REPL, and fixed the issue wherein the range was still flipped and offset by 180deg. Quick sampling lets me vet how the function behaved at the edges.

pesterhazy 2019-12-10T22:02:32.065300Z

I also tried a bunch of example vectors, [0 1] [1 1] [1 0] etc to get a feel for how atan2 develops

โ˜๏ธ 1
pesterhazy 2019-12-10T22:03:03.065500Z

of course I still had to debug the code because I forgot to prefer closer asteroids

pesterhazy 2019-12-10T22:03:18.065700Z

things never work on the first run for me

rjray 2019-12-10T22:19:53.066Z

And don't forget that one of dy or dx can be zero ๐Ÿ™‚.