adventofcode

Aleks 2021-12-17T04:56:47.187700Z

🧵Day 17 Solutions Thread: post your solution here

Miķelis Vindavs 2021-12-17T10:40:14.194100Z

very nice parsing 👍🏻

nbardiuk 2021-12-17T14:26:56.194300Z

thanks, although today we can avoid parsing, just store numbers in a map

2021-12-17T14:36:30.194500Z

I like your part1 😅

euccastro 2021-12-17T15:35:27.195100Z

Closed form for part1, brute force for part 2 (but part1 gave me confidence about the bounds in the y direction): https://github.com/euccastro/advent-of-code-2021/blob/main/day17.clj

euccastro 2021-12-17T15:49:58.195400Z

the insight for part 1 (and for narrowing down the y space) is that after reaching as high as it can, the bullet will fall down to exactly zero height, and the next step must be within the target. if we want to reach as high as we can, the next step after reaching zero height will be at the bottom of the target. (this is assuming that the target is below 0, which is kind of implied in the problem description but I didn't assume in my code; I think I could have assumed that x is always positive too)

euccastro 2021-12-17T15:56:26.195600Z

I've cleaned up my code with the assumption (again, kind of implied in the description) that the target is in the bottom right quadrant. it's shorter and prettier now

Sam Adams 2021-12-17T17:46:57.196100Z

Brute force: https://samadams.dev/2021/12/17/advent-of-code-day-17.html

Antonio Bibiano 2021-12-17T20:21:23.196500Z

Was happy to find a solution for part1 but then got super lazy about finishing part 2 :(

genmeblog 2021-12-17T21:12:46.197Z

after some refactoring I ended up with one function which covers both cases and is short (`reductions` is huge helper here). But it was long process... https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2021/day17.clj

genmeblog 2021-12-17T21:23:46.197300Z

@euccastro seems to work, however there are gaps in initial x velocities when target is missed. For example for x between 195 and 238 (my case) velocities between 81 and 97 miss the target.

tschady 2021-12-17T21:39:12.197600Z

I got a closed form solution (so no boundary checking necessary). 0.1ms, 7ms. writeup: https://github.com/tschady/advent-of-code/blob/main/doc/2021.adoc#aoc-2021-d17

🙌 3
2021-12-17T21:58:06.198500Z

https://github.com/kfirmanty/advent-of-code-2021/blob/main/src/day17.clj prior to any refactoring. I had a formula to find possible x-velocities but then for y velocities used the dumbest thing that works i.e minimum velocity is the lowest y of target and upper bound is 1000 which is less than ideal. Will try to optimize it later but I must admit solving AoC while having a flu is much harder than without one 😄

kevinc 2021-12-18T04:42:21.199400Z

https://github.com/kconner/advent-of-code/blob/master/2021/17a.cljhttps://github.com/kconner/advent-of-code/blob/master/2021/17b.clj. I got way, way too clever on my first try. I'd rather have to improve a slow naive solution than debug a fast, complex, wrong solution.

Miķelis Vindavs 2021-12-17T05:33:17.187900Z

Classic AoC where part1 makes you feel like you should find a formula to solve it in constant time, but then part2 says “nope, it’s brute force after all simple_smile

😅 2
Miķelis Vindavs 2021-12-17T06:14:19.190800Z

the y search space can be reduced to (range (dec y1) (- y1))

2021-12-17T06:14:20.191Z

I hard coded one my bounds experimentally. I am sure I could figure out a more correct solution, but on AoC when you get the answer, it's time to sleep.

➕ 3
2021-12-17T06:15:28.192200Z

Thanks. I assumed something like that would be correct, but I wasn't sure.

AC 2021-12-17T06:31:54.192700Z

@mikelis.vindavs that certainly speeds up my brute-force.

Aleks 2021-12-17T06:37:32.193Z

It is slow, but works 🙃 https://github.com/zelark/AoC-2021/blob/main/src/zelark/aoc_2021/day_17.clj

euccastro 2021-12-18T21:23:24.210600Z

@tsulej what "seems to work" but doesn't? I didn't do anything clever about x velocities; I just try all the ones that could possibly work

euccastro 2021-12-18T21:24:17.210800Z

and even some that couldn't, but no big harm in that since my brute force code runs almost instantly