Advent of Code 2021 day 17
12/17/2021, 5:00 AMDavid Whittaker
12/17/2021, 5:23 AMilya.gorbunov
12/17/2021, 5:32 AMJakub Gwóźdź
12/17/2021, 6:36 AMy=-115..-63
I ended up with dy=-115..115
covering all possibilities, but I have no idea (yet) why is it enough :)Dan Fingal-Surma
12/17/2021, 6:42 AMsequence
or generateSequence
but keep getting:
File being compiled: problem_17.main.kts
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50) (problem_17.main.kts): org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
File being compiled: problem_17.main.kts
The root cause java.lang.RuntimeException was thrown at: org.jetbrains.kotlin.backend.jvm.codegen.FunctionCodegen.generate(FunctionCodegen.kt:50)
Dan Fingal-Surma
12/17/2021, 6:45 AMVector.next()
from member to extension fixes itJakub Gwóźdź
12/17/2021, 6:52 AMJakub Gwóźdź
12/17/2021, 6:53 AMMichael de Kaste
12/17/2021, 6:57 AMx² + x - 2 * xMin = 0
rounded up, but ended up with approximating it with sqrt(2.0 * xMin).roundToInt()
Jakub Gwóźdź
12/17/2021, 7:03 AMelizarov
12/17/2021, 7:06 AMMichael de Kaste
12/17/2021, 7:16 AMDan Fingal-Surma
12/17/2021, 7:27 AMDan Fingal-Surma
12/17/2021, 7:28 AMJakub Gwóźdź
12/17/2021, 7:53 AM[y1..y2]
(as long as both are negative) the proper max vertical velocity is -y1-1
… anything more and probe overshoots (as it has too much velocity when hitting the surface on way back down)Dan Fingal-Surma
12/17/2021, 7:56 AMfor (y in target.min.y..1000) {
--> for (y in target.min.y..-target.min.y) {
yields the same answersDan Fingal-Surma
12/17/2021, 7:58 AMDan Fingal-Surma
12/17/2021, 7:59 AMelizarov
12/17/2021, 8:00 AMDan Fingal-Surma
12/17/2021, 8:00 AMephemient
12/17/2021, 8:33 AMephemient
12/17/2021, 8:36 AMephemient
12/17/2021, 8:36 AMephemient
12/17/2021, 8:37 AMDan Fingal-Surma
12/17/2021, 8:48 AMTodor Grudev
12/17/2021, 9:16 AMgenerateSequence
it only takes ~400ms. I really enjoyed this one 🙂 reminds me of https://archive.org/download/win3_BANGBANG/screenshot_00.jpg▾
Michael Böiers
12/17/2021, 10:17 AMMichael de Kaste
12/17/2021, 10:22 AMMichael de Kaste
12/17/2021, 10:33 AMMichael Böiers
12/17/2021, 10:55 AMMichael Böiers
12/17/2021, 1:39 PMelizarov
12/17/2021, 2:30 PM;
in Kotlin is clearly a cheat.todd.ginsberg
12/17/2021, 3:09 PMMichael Böiers
12/17/2021, 3:10 PMelizarov
12/17/2021, 3:34 PM;
sometimes myself, but I would only use it when I need to show that certain pattern repeats from one row to the next. In general, though, ;
in Kotlin is discouraged.Michael Böiers
12/17/2021, 3:45 PMNir
12/17/2021, 3:56 PMNir
12/17/2021, 3:56 PMLuke
12/17/2021, 4:15 PMDan Fingal-Surma
12/17/2021, 6:34 PMDan Fingal-Surma
12/17/2021, 6:49 PMMichael Böiers
12/17/2021, 7:15 PMMichael Böiers
12/17/2021, 7:18 PMpx, py, vx, vy = px+vx, py+vy, Max(0, vx-1), vy-1
Dan Fingal-Surma
12/17/2021, 7:21 PMMichael Böiers
12/17/2021, 7:21 PMMichael Böiers
12/17/2021, 8:24 PMRegex("""x=(.+)\.\.(.+), y=(.+)\.\.(.+)""").find(readln())!!.destructured.toList().map(String::toInt)
Michael Böiers
12/17/2021, 8:34 PMfun main() = Regex("""(.+)\.\.(.+)""".let { "x=$it, y=$it" }).find(readln())!!.destructured.toList().map(String::toInt)
.let { (tLeft, tRight, tBottom, tTop) ->
(1..tRight).flatMap { vx -> (tBottom..-tBottom).map { vx to it } }.mapNotNull { (vx0, vy0) ->
var maxY = 0
var hitTarget = false
var x = 0
var y = 0
var vx = vx0
var vy = vy0
while (x <= tRight && y >= tBottom) {
x += vx
y += vy
vx += 0.compareTo(vx)
vy += -1
if (y > maxY) maxY = y
if (x in tLeft..tRight && y in tBottom..tTop) hitTarget = true
}
maxY.takeIf { hitTarget }
}
}.apply { println(maxOf { it }) }.run { println(size) }
Paul Woitaschek
12/17/2021, 10:56 PMephemient
12/17/2021, 11:57 PMphldavies
12/18/2021, 12:53 AMDan Fingal-Surma
12/18/2021, 1:26 AMString::toIntOrNull
niceKiet
12/18/2021, 9:06 AMkqr
12/18/2021, 2:56 PM