Oooh, pretty. Is that using curses?
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
You have an error on your 03
intcode with mode 2
hehe, the error code is self-explanatory
Apparently (= val)
is valid clojure
You were not the only one. 203 seems to have been the biggest stumbling block this day.
(map-indexed (fn [i v] [i v]))
(map-indexed vector)
Today, I realize how much basic trig I've forgotten.
For part one I didn't need trig. Part 2 not so sure
Ayup.
Viz: http://quil.info/sketches/show/5d471cd687426dd3ffa006d6c50133e7aed9c984ccada11be36ea06ab5fc5970
so cool!!
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:
do you mean the top right corner? that one is reachable
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.
โevery asteroid is exactly in the center of its marked positionโ
Oh right, that makes sense. The map put me in Manhattan distance state of mind.
:thumbsup::skin-tone-2: ๐
My laser already killed astroid 200 on the first round. Lucky I guess
Personal challenge for today, make it fast
donโt forget about threads
pmap
all the things
Want to look more into reducing algorithmic complexity. Using more power is cheating ๐
Current solution is at least O(n^2)
I am checking all other asteroids to see if one is blocking the line of sight which is stupid
Better to determine LoS and see if it has astroids
group-by angle, sort-by distance
@mpcjanssen whatโs LoS?
line of sight
line of sight
how fast is fast for you?
right now it takes 16 secs want to improve to below 5
"Elapsed time: 108.515633 msecs" "Elapsed time: 4.428149 msecs"
๐๏ธ
had "seconds" p1 solution, then re-implemented with angles
way less code, tests, and faster
any link
wasted too much time on it, so did not clean up https://github.com/akovantsev/adventofcode/blob/master/src/adventofcode/2019/day10.clj
ah so group by angle and take closest gives the visible astroids immediately
smart, i would just be worried about floating point inaccuracies in the angles.
it's the first time I've ever found clojure's Rational type to be useful :)
that "smart" solution cost me 2+ hours :harold:
just take the (/ dy dx)
and count the frequencies
tried to cycle outermost xys instead, but it was not granular enough, etc.
with the exception that opposite quadrants give the same gradient, so take the sign of dy and dx to disambiguate
yeah, spent time on adjusting coordinate system as well
@misha with groupby orderby it goes from 16s to 300ms
proving again that improving algoritm beats brute force at any day
simpler too
Interesting, did something similar, you can use mod
in your rotate
function to avoid cond->
I think
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
there must be an floating point error because i didn't make rational number lowest form..
maybe we can avoid math functions at all.
Hmm my original algorithm was n^3
So I am guessing day 10 is when the questions start ramping up.
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.
Although my part 1 day 10 was a hack brute force
how?
The angles idea is great! Although I struggled with orienting the co-ordinate frame! @misha
Faffing around in the REPL let me figure it out by recollection and informed intuition. The quickest win for me was (thread for spoilers)
|| to reverse the x and y arguments to atan2
. || From there, you could convert the range by normal means.
When you aren't familiar with the behaviour of a mathematical function, playing with it in the repl can sometimes be good enough. ๐
My day 10 solution: <https://github.com/chrisblom/advent-of-code/blob/master/src/adventofcode/2019/day10.clj>
Could be made more efficient, but it was fast enough for the input
Last years I remember that solutions already needed to be more efficient by day 10
@misha nicely done
My day 10: https://github.com/pesterhazy/advent2019/blob/master/typescript/src/puzzle10.ts#L1
Took me a while today because (like last year) I had to read up on dot products and atan2
REPL driven math?
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.
I also tried a bunch of example vectors, [0 1] [1 1] [1 0] etc to get a feel for how atan2 develops
of course I still had to debug the code because I forgot to prefer closer asteroids
things never work on the first run for me
And don't forget that one of dy
or dx
can be zero ๐.