Our great sponsors

Go. https://github.com/jasontconnell/advent/blob/master/2021/17/main.go

python modeling the equations was the way to go no need to loop over all time steps to get the en position, just using equations of motion

SonarLint
Deliver Cleaner and Safer Code  Right in Your IDE of Choice!. SonarLint is a free and open source IDE extension that identifies and catches bugs and vulnerabilities as you code, directly in the IDE. Install from your favorite IDE marketplace today.

I actually did just that here! Completes part 2 in 400 mics. I think this could be optimized even further as well.

Kotlin (1177/731)

Go, 1093/563


adventofcode
Advent of Code solutions of 2015, 2016, 2017, 2018, 2019, 2020 and 2021 in Scala (by sim642)
My Scala solution.

Scout APM
Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.

Rust 991 / 584

So anyway, I started blasting


Basic C# solution with a straightforward tryeverything simulation. This one could've been called 50 Thousand Iterations Under the Sea

Java https://github.com/SimonBaars/AdventOfCodeJava/blob/master/src/main/java/com/sbaars/adventofcode/year21/days/Day17.java

F#


Raku, 4863/4996. I thought for awhile about analytic solutions, concluded that it was probably covered by some calculus or linear algebra that I forgot, and decided to brute force it. I'm glad I did, since part 2 would be even more challenging analytically. I also managed to introduce a whole bunch of bugs, including an extended period of WTF until I realized that (257i).re ∈ 20..30 is False because Complex.re returns a Num but a Range of Int only accepts ∈ on Ints. Meanwhile, (257i).re ~~ 20..30 (smartmatch, not set containment) returns True because There's More Than One Way To Do It, And Some Of Them Are Subtly Wrong.

My solution in Go.

Full code here

Repository


This is so clean. I had it in my mind to not brute force from the beginning, but I should've given up given that up given the input size as well. It produced a lot more readable code than mine

My solutions as per usual at my Github

COBOL brute force.

ReScript code

Today's seemed weirdly easier than the previous days, like "too good to be true". Javascript solution


I first computed bounds and checked within a certain region of velocities. Compared with yesterday this was a piece of cake. I guess for must inputs the solution to part1 is simply y*(y+1)/2 where y is the absolute value of the lower bond  1. github

My Python3 solution





Brute force like most people I think  kept wondering if there was going to be some horrible gotcha that meant brute force would not work, but it did.

Python day 17 solution (GitHub). Not the fewest lines of code, but used dataclasses and modular functions to try improve readability  I got very confused with keeping track of indices of velocities vs coordinates in other people's posted solutions. I find dataclasses in Python can be a great way to be descriptive about the quantities you are iterating


Python 3 Just brute forced this one, why not? https://github.com/PeteEdleyEdleyIT/AdventofCode2021Day17/blob/master/Problem1.py


Nice! I've got a similar repo


Brute force Scala using tail recursion. There could be some optimizations on the velocity ranges I used, but it works. Hardest part was finding the proper minimum y velocity for part 2 (which I realized by looking at the example is just yRange.min)

I did the maths. My idea was that for a given time t, you can obtain all possible values of y and x (x is more complicated) such that after t step the probe is in the target area. GitLab.


TypeScript, Rare day where Part 1 was solved with a formula and Part 2 required brute force.

Slow



Python (3918/3570)

Part one: https://github.com/AugustsK/adventofcodesolutions/blob/master/2021/day17/partOne.js

The whole solution: https://github.com/premun/adventofcode/tree/main/src/17

My full solution: github


github: https://github.com/GMainardi/Advent2021/tree/main/17

Elixir 3 ms each part, sme math might have been involved.


AdventOfCode2021
Some solutions for as much of advent of code 2021 as I can be bothered to do. (by TomHemery)
C# github Code footprint is small, vaguely sensible bounds on a brute force solution. Why not? I'm more proud of my commit name than my solution.

C# full solution


I'm using dumber bounds in Kotlin, Python, and Rust since it was easier. But basically, assuming 0 ≤ all target x, we only need to check 0 ≤ 𝚫x ≤ max target x —anything else immediately overshoots the target— and assuming all target y < 0, we only need to check min target y ≤ 𝚫y ≤ max abs target y —anything smaller will immediately overshoot and anything larger will also overshoot after returning to origin.

F# solution with Jupyter Notebook. Brute force. I actually solved Part 2 before solving Part 1, unknowingly.

adventofcode
My collection of Advent of Code solutions in a slightly overkill project setup 🙃👻 (by marcelblijleven)

Common Lisp. Very disappointing problem since you can just brute force over even unreasonable bounds quickly. Would have been more appropriate as a day 4 or 5 problem



Part 1

advent_of_code
This repository contains solutions to each of the problems in Advent of Code 2021 in C++, 2020 in both C++ and Python and 2019 in C++. (by vss2sn)
Solutions in C++: Part 1 Part 2 (As always, every file is a self ontained solution) Explanatory notes added for the math used.


Go

Python 3: Part 1 / Part 2

Python 3





Python3  https://github.com/expsmartin/AOC2021/blob/main/d17.py Threw away 3 hours trying to solve this like a trick question. walked away for 6 hours, came back and assumed “nah, it reads how it reads” and solved p1 in 20 mins and p2 in 20 seconds.


I left a longer comment about why it is so in my solution, you can see it here!



AdventOfCode2021
Advent of Code 2021 challenge: 13 different languages, one chosen at random every day! (by Qualia91)

Python day 17
