Advent of Code 2023 day 24
12/24/2023, 5:00 AMJonathan Kolberg
12/24/2023, 5:46 AMMichael de Kaste
12/24/2023, 6:27 AMJonathan Kolberg
12/24/2023, 6:27 AMJonathan Kolberg
12/24/2023, 6:28 AMMichael de Kaste
12/24/2023, 6:28 AMJonathan Kolberg
12/24/2023, 6:28 AMJonathan Kolberg
12/24/2023, 6:29 AMJonathan Kolberg
12/24/2023, 6:29 AMMichael de Kaste
12/24/2023, 6:30 AMfun intersects(input1: Input, input2: Input): Boolean {
val x: Double = (input2.equation.b - input1.equation.b) / (input1.equation.slope - input2.equation.slope)
val y: Double = (input1.equation.slope * x + input1.equation.b)
val rangex1 = if(input1.xDiff >= 0L) input1.x.toDouble()..UPPERBOUND else LOWERBOUND..input1.x.toDouble()
val rangey1 = if(input1.yDiff >= 0L) input1.y.toDouble()..UPPERBOUND else LOWERBOUND..input1.y.toDouble()
val rangex2 = if(input2.xDiff >= 0L) input2.x.toDouble()..UPPERBOUND else LOWERBOUND..input2.x.toDouble()
val rangey2 = if(input2.yDiff >= 0L) input2.y.toDouble()..UPPERBOUND else LOWERBOUND..input2.y.toDouble()
val toReturn = x in rangex1 && x in rangex2 && y in rangey1 && y in rangey2
return toReturn
}
where equation
val equation = run {
val x2 = x + xDiff
val y2 = y + yDiff
val slope = (y2 - y) / (x2 - x).toDouble()
val b = y - slope * x
Equation(slope, b)
}
Michael de Kaste
12/24/2023, 6:31 AMMichael de Kaste
12/24/2023, 6:31 AMMichael de Kaste
12/24/2023, 6:31 AMbj0
12/24/2023, 6:33 AMJonathan Kolberg
12/24/2023, 6:36 AMMichael de Kaste
12/24/2023, 6:37 AMconst val LOWERBOUND = 200000000000000.0
const val UPPERBOUND = 400000000000000.0
bj0
12/24/2023, 6:39 AMJonathan Kolberg
12/24/2023, 6:41 AMMarcin Wisniowski
12/24/2023, 7:24 AMMarcin Wisniowski
12/24/2023, 7:35 AMMichael de Kaste
12/24/2023, 8:13 AMMarcin Wisniowski
12/24/2023, 8:27 AMapt install z3
, done, easy. 😄Michael de Kaste
12/24/2023, 8:27 AMdaugian
12/24/2023, 8:48 AMphldavies
12/24/2023, 8:59 AMdaugian
12/24/2023, 9:13 AMDouble
vs BigDecimal
issue for part 1 (where I needed to use the latter) 🤦♂️daugian
12/24/2023, 9:33 AMdaugian
12/24/2023, 9:33 AMdaugian
12/24/2023, 9:33 AMdaugian
12/24/2023, 9:35 AMJonathan Kolberg
12/24/2023, 11:31 AMelizarov
12/24/2023, 11:45 AMphldavies
12/24/2023, 11:47 AMTomasz Linkowski
12/24/2023, 12:40 PMWerner Altewischer
12/24/2023, 2:29 PMWerner Altewischer
12/24/2023, 2:29 PMWerner Altewischer
12/24/2023, 3:57 PM- We can treat each component (x, y, z) separately
- We can brute force check all possible speeds (the max speed for any of the stones seem to be quite small)
- (position2 - position1) / (velocity1 - velocity2) has to be integer divisible for each stone, a fact we can use to thin out a possible range of positions by comparing with each stone
I have not been able to work out all the details, but quickly scanning the solution of @elizarov this seems to be the right direction.elizarov
12/24/2023, 5:09 PMJonathan Kolberg
12/24/2023, 5:14 PMWerner Altewischer
12/24/2023, 5:15 PMWerner Altewischer
12/24/2023, 5:17 PMWerner Altewischer
12/24/2023, 5:19 PMelizarov
12/24/2023, 5:19 PMdaugian
12/24/2023, 5:47 PMTomasz Linkowski
12/24/2023, 7:17 PMJonathan Kolberg
12/24/2023, 7:19 PMdaugian
12/24/2023, 8:22 PMMax Thiele
12/24/2023, 9:17 PMMax Thiele
12/24/2023, 9:24 PMelizarov
12/24/2023, 11:41 PMbj0
12/25/2023, 3:31 AMdaugian
12/25/2023, 5:34 AMelizarov
12/25/2023, 7:48 AMWerner Altewischer
12/25/2023, 11:28 AMbj0
12/25/2023, 11:41 PMMax Thiele
12/26/2023, 9:46 AMbj0
12/26/2023, 4:34 PMbj0
12/26/2023, 4:44 PMMax Thiele
12/26/2023, 6:49 PMbj0
12/26/2023, 7:12 PMephemient
12/27/2023, 1:31 PMephemient
12/27/2023, 1:44 PMLong
, I'm using Double
which leads to rounding errors. so I'm actually performing the above calculation for all triples, then taking the most common resultephemient
12/27/2023, 1:47 PMi128
built-in which is enough (picking up Ratio
from the num-rational
crate, but that's much easier to implement from scratch than bigints, having done both before)ephemient
12/27/2023, 1:48 PMjava.lang.BigInteger
because I'm targeting JS and Native toobnorm
12/27/2023, 3:34 PM