Fork me on GitHub
#adventofcode
<
2019-12-10
>
fellshard01:12:04

Oooh, pretty. Is that using curses?

Mario C.02:12:24

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

mpcjanssen04:12:25

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

Jean09:12:02

You have an error on your 03 intcode with mode 2

pesterhazy22:12:14

hehe, the error code is self-explanatory

Mario C.02:12:59

Apparently (= val) is valid clojure

fellshard06:12:54

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

mpcjanssen08:12:39

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

roman01la07:12:32

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:

meikemertsch07:12:36

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

meikemertsch07:12:04

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.

meikemertsch07:12:27

“every asteroid is exactly in the center of its marked position”

roman01la07:12:09

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

meikemertsch07:12:51

:thumbsup::skin-tone-2: 🍀

mpcjanssen08:12:37

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

mpcjanssen11:12:43

Personal challenge for today, make it fast

roman01la11:12:15

don’t forget about threads

roman01la11:12:32

pmap all the things

mpcjanssen11:12:55

Want to look more into reducing algorithmic complexity. Using more power is cheating 😉

mpcjanssen11:12:59

Current solution is at least O(n^2)

mpcjanssen11:12:24

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

mpcjanssen11:12:50

Better to determine LoS and see if it has astroids

misha11:12:12

group-by angle, sort-by distance

👏 1
mpcjanssen11:12:09

line of sight

misha11:12:12

line of sight

misha11:12:55

how fast is fast for you?

mpcjanssen11:12:28

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

misha11:12:54

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

misha11:12:34

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

misha11:12:51

way less code, tests, and faster

Average-user14:12:29

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

ghadi21:12:57

@misha nicely done

opieop 1
mpcjanssen11:12:46

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

mpcjanssen11:12:38

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

yuhan11:12:22

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

misha11:12:36

that "smart" solution cost me 2+ hours harold

yuhan11:12:12

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

yuhan11:12:30

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

misha11:12:11

yeah, spent time on adjusting coordinate system as well

rjray22:12:53

And don't forget that one of dy or dx can be zero 🙂.

misha04:12:05

I left it to Math/atan2 : > * &lt;li&gt;If the first argument is positive and the second argument is > * positive zero or negative zero, or the first argument is positive > * infinity and the second argument is finite, then the result is the > * {@code double} value closest to &lt;i&gt;pi&lt;/i&gt;/2.

misha11:12:38

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

mpcjanssen14:12:51

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

opieop 1
mpcjanssen14:12:46

proving again that improving algoritm beats brute force at any day

nam.hyunwoo14:12:43

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
nam.hyunwoo15:12:12

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

nam.hyunwoo15:12:25

maybe we can avoid math functions at all.

mpcjanssen15:12:17

Hmm my original algorithm was n^3

Mario C.16:12:55

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

Mario C.16:12:14

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.16:12:49

Although my part 1 day 10 was a hack brute force

pastafari20:12:53

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

misha04:12:13

took me awhile and a bunch of printing too

fellshard21:12:56

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

fellshard21:12:14

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

fellshard21:12:25

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

pesterhazy21:12:12

REPL driven math?

fellshard22:12:48

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.

pesterhazy22:12:32

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

☝️ 1
pesterhazy22:12:03

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

pesterhazy22:12:18

things never work on the first run for me

chrisblom21:12:21

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

chrisblom21:12:30

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

chrisblom21:12:05

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

pesterhazy21:12:00

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