Advent of Code 2022 day 10
12/10/2023, 5:00 AMMarcin Wisniowski
12/10/2023, 5:47 AMJonathan Kolberg
12/10/2023, 5:50 AMMarcin Wisniowski
12/10/2023, 6:04 AMMarcin Wisniowski
12/10/2023, 6:05 AMPoint
, Direction
, and their methods.Marcin Wisniowski
12/10/2023, 6:08 AMJerry hanks
12/10/2023, 7:33 AMJakub Gwóźdź
12/10/2023, 7:38 AMJonathan Kolberg
12/10/2023, 7:39 AMJohnny Wulgaru
12/10/2023, 7:47 AMNeil Banman
12/10/2023, 8:40 AMStokes Theorem to the rescue 🙂I just googled that. Suffice it to say that neither Mr. Stokes nor his theorem will be coming to my rescue any time soon. My knight in shining armor (BFS) was slow to arrive (750ms) and has a bad case of acne (spaghetti code), but he did (eventually) slay the dragon.
Marcin Wisniowski
12/10/2023, 8:48 AMFredrik Rødland
12/10/2023, 9:18 AMJakub Gwóźdź
12/10/2023, 9:23 AMDan Fingal-Surma
12/10/2023, 9:51 AMDan Fingal-Surma
12/10/2023, 9:52 AMDan Fingal-Surma
12/10/2023, 9:52 AMDan Fingal-Surma
12/10/2023, 9:52 AMPaul Woitaschek
12/10/2023, 9:54 AMMichael de Kaste
12/10/2023, 10:05 AMDan Fingal-Surma
12/10/2023, 10:07 AMphldavies
12/10/2023, 10:11 AMphldavies
12/10/2023, 10:12 AMMichael de Kaste
12/10/2023, 10:14 AMDan Fingal-Surma
12/10/2023, 10:14 AMDan Fingal-Surma
12/10/2023, 10:20 AMDan Fingal-Surma
12/10/2023, 10:20 AMDan Fingal-Surma
12/10/2023, 10:22 AMDan Fingal-Surma
12/10/2023, 10:24 AMDan Fingal-Surma
12/10/2023, 10:26 AMphldavies
12/10/2023, 10:27 AMphldavies
12/10/2023, 10:27 AMephemient
12/10/2023, 10:28 AMphldavies
12/10/2023, 10:28 AMephemient
12/10/2023, 10:29 AMephemient
12/10/2023, 10:29 AMDan Fingal-Surma
12/10/2023, 10:30 AMDan Fingal-Surma
12/10/2023, 10:30 AMfun part2(input: Input) = input.fold(0 to 0) { (sum, d), move ->
when (move) {
N -> sum to d + 1
S -> sum to d - 1
W -> sum - d to d
E -> sum + d to d
}
}.first.absoluteValue - (input.size / 2) + 1
Dan Fingal-Surma
12/10/2023, 10:30 AMDan Fingal-Surma
12/10/2023, 10:30 AMDan Fingal-Surma
12/10/2023, 10:33 AMThe line integral of a vector field over a loop is equal to its _curl_ through the enclosed surface.
ritesh
12/10/2023, 10:33 AMephemient
12/10/2023, 10:34 AM.F7
FSJ
LJ.
counted as a closed loop for the purposes of stoke's…ephemient
12/10/2023, 10:34 AMritesh
12/10/2023, 10:36 AM.....
.S-7.
.|.|.
.L-J.
.....
row(2,1) -> |
can be more than 1 steps from source, if other path is considered (S -> 7 -> | -> J -> - <L-|)Jakub Gwóźdź
12/10/2023, 10:39 AMDan Fingal-Surma
12/10/2023, 10:40 AMritesh
12/10/2023, 11:41 AMS
which will connect to two neighbouring pipes 🤔Michael de Kaste
12/10/2023, 12:09 PMnvbahool
12/10/2023, 12:28 PM...........
.S-------7.
.|F-----7|.
.||.....||.
.||.....||.
.|L-7.F-J|.
.|..|.|..|.
.L--J.L--J.
...........
became this:
.~.~.~.~.~.~.~.~.~.~.
~~~~~~~~~~~~~~~~~~~~~
.~S=-=-=-=-=-=-=-=7~.
~~!~~~~~~~~~~~~~~~!~~
.~|~F=-=-=-=-=-=7~|~.
~~!~!~~~~~~~~~~~!~!~~
.~|~|~.~.~.~.~.~|~|~.
~~!~!~~~~~~~~~~~!~!~~
.~|~|~.~.~.~.~.~|~|~.
~~!~!~~~~~~~~~~~!~!~~
.~|~L=-=7~.~F=-=J~|~.
~~!~~~~~!~~~!~~~~~!~~
.~|~.~.~|~.~|~.~.~|~.
~~!~~~~~!~~~!~~~~~!~~
.~L=-=-=J~.~L=-=-=J~.
~~~~~~~~~~~~~~~~~~~~~
.~.~.~.~.~.~.~.~.~.~.
Tiles ~
indicate that we can go there from any adjacent tile that is not connected to the main loop. And tiles !
and =
mean that we can’t – the pipes of the main loop are connected there. I used this transformed map of tiles to find out if it is possible to squeeze between the pipes in places where they might be connected.Jakub Gwóźdź
12/10/2023, 1:31 PMS----7
|.F7.|
|.LJ.|
L----J
Jakub Gwóźdź
12/10/2023, 1:32 PMJonathan Kolberg
12/10/2023, 1:32 PMMichael de Kaste
12/10/2023, 1:34 PMJakub Gwóźdź
12/10/2023, 1:35 PMephemient
12/10/2023, 2:03 PMJaap Beetstra
12/10/2023, 2:25 PMDamir Krancpiler
12/10/2023, 3:35 PMDave
12/10/2023, 3:39 PMJakub Gwóźdź
12/10/2023, 3:59 PMephemient
12/10/2023, 4:40 PMKroppeb
12/10/2023, 5:27 PMval perimeter = cycle.size
val area = cycle.zip(cycle.drop(1) + cycle.take(1)) { a, b -> a.x * b.y - a.y * b.x }.sum().abs() / 2
val points = area - perimeter / 2 + 1
Kroppeb
12/10/2023, 5:28 PMPoint
class but Pair
would work too, just use first
and second
insteadKroppeb
12/10/2023, 5:30 PMPaul Woitaschek
12/10/2023, 5:30 PMMichael de Kaste
12/10/2023, 5:44 PMoverride fun part1(): Int = points.size / 2
override fun part2() = points.plus(points.first())
.zipWithNext { (y1, x1), (_, x2) -> (x2 - x1) * y1 }
.sum() - part1() + 1
where points is a list of all the points of the pipeline in order.
"area of n-sided polygon" generalizes nicely in a strict 2D worldDamir Krancpiler
12/10/2023, 6:14 PMRiccardo Lippolis
12/10/2023, 6:51 PMMarcin Wisniowski
12/10/2023, 7:02 PMTolly Kulczycki
12/10/2023, 8:27 PMTolly Kulczycki
12/10/2023, 8:28 PMKash Kabeya
12/10/2023, 9:34 PMephemient
12/10/2023, 11:02 PMNeil Banman
12/10/2023, 11:38 PMtodd.ginsberg
12/11/2023, 12:11 AMDan Fingal-Surma
12/11/2023, 2:12 AMephemient
12/11/2023, 4:16 AMLidonis Calhau
12/11/2023, 4:31 AMephemient
12/11/2023, 4:32 AMJakub Gwóźdź
12/11/2023, 4:41 AMLidonis Calhau
12/11/2023, 4:46 AMandriyo
12/11/2023, 9:05 AMWerner Altewischer
12/11/2023, 10:51 AMWerner Altewischer
12/11/2023, 11:04 AMMichael Böiers
12/11/2023, 12:30 PMMichael Böiers
12/11/2023, 12:38 PMPetr Sýkora
12/11/2023, 2:44 PMKiet
12/18/2023, 6:16 AM