Advent of Code 2021 day 20
12/20/2022, 5:00 AMbabel
12/20/2022, 5:36 AM1, 2, -2, -3, 0, 3, 4
-2 moves between 4 and 1:
1, 2, -3, 0, 3, 4, -2
elizarov
12/20/2022, 6:02 AMMarcin Wisniowski
12/20/2022, 6:09 AMVlad Petrushkevich
12/20/2022, 6:16 AMSergei Petunin
12/20/2022, 7:05 AM811589153, 1623178306, -2434767459, 2434767459, -1623178306, 0, 3246356612
811589153 % 7 = 4
, moving it 4
to the right:
0, 3246356612, 1623178306, -2434767459, 2434767459, -1623178306, *811589153*
1623178306 % 7 = 1
, moving 1
to the right:
0, 3246356612, -2434767459, *1623178306*, 2434767459, -1623178306, 811589153
-2434767459 % 7 = -5
, moving 5
to the left:
0, 3246356612, 1623178306, -*2434767459*, 2434767459, -1623178306, 811589153
2434767459 % 7 = 5
, moving 5
to the right:
0, 3246356612, 1623178306, *2434767459*, -2434767459, -1623178306, 811589153
-1623178306 % 7 = -1
, moving 1
to the left:
0, 3246356612, 1623178306, 2434767459, -*1623178306*, -2434767459, 811589153
`0 % 7 = 0`:
0, 3246356612, 1623178306, 2434767459, -1623178306, -2434767459, 811589153
3246356612 % 7 = 2
, moving 2
to the right, and here's my state after 1 round of mixing:
0, 1623178306, 2434767459, *3246356612*, -1623178306, -2434767459, 811589153
But the example shows that after 1 round of mixing we should have:
0, -2434767459, 3246356612, -1623178306, 2434767459, 1623178306, 811589153
rkechols
12/20/2022, 7:06 AMn_elements - 1
, but my natural thought was that a full circle would be moving it n_elements
timesMarcin Wisniowski
12/20/2022, 7:07 AMn_element
times, where the list it’s moving through does not contain the element that moves, otherwise there be two, one static in the list and a moving duplicate.Marcin Wisniowski
12/20/2022, 7:08 AMn_elements
is right, it’s just that you have to remember the element you are moving is no longer sitting there, so the list is one smaller!rkechols
12/20/2022, 7:10 AMinitial: [811589153, 1623178306, -2434767459, 2434767459, -1623178306, 0, 3246356612]
[1623178306, -2434767459, 2434767459, -1623178306, 0, 811589153, 3246356612]
[-2434767459, 2434767459, -1623178306, 0, 1623178306, 811589153, 3246356612]
[2434767459, -1623178306, 0, -2434767459, 1623178306, 811589153, 3246356612]
[-1623178306, 0, -2434767459, 2434767459, 1623178306, 811589153, 3246356612]
[0, -2434767459, -1623178306, 2434767459, 1623178306, 811589153, 3246356612]
[0, -2434767459, 3246356612, -1623178306, 2434767459, 1623178306, 811589153]
Kai Yuan
12/20/2022, 7:10 AMvalue % (totalSize*-1*)
nodes. So it's 6 instead of 7Sergei Petunin
12/20/2022, 7:12 AMJonathan Kolberg
12/20/2022, 7:37 AMJan Durovec
12/20/2022, 7:44 AMLong % Int
returns Long
if the remainder should clearly be smaller than modulus so if modulus is Int
then the result should also be Int
? 🤔Jan Durovec
12/20/2022, 7:49 AM+/-1
headacheelizarov
12/20/2022, 7:51 AM%
for longs is an unfortunate Java/C/C++ legacy. For this particular problem you should be using Long.mod(Int)
extension function that has the convenient return type of Int
and also does exactly what you need for the negative value, that is, it performs a proper mathematical modulus operation.Jonathan Kolberg
12/20/2022, 8:03 AM0 does not move:
1, 2, -3, 0, 3, 4, -2
4 moves between -3 and 0:
1, 2, -3, 4, 0, 3, -2
elizarov
12/20/2022, 8:07 AMSergei Petunin
12/20/2022, 9:01 AMJakub Gwóźdź
12/20/2022, 9:04 AMSergei Petunin
12/20/2022, 9:18 AMn % (size - 1) == 0
Sergei Petunin
12/20/2022, 9:22 AMephemient
12/20/2022, 11:03 AMephemient
12/20/2022, 11:04 AMephemient
12/20/2022, 11:07 AMephemient
12/20/2022, 11:09 AMAlyssa Burlton
12/20/2022, 11:39 AMoriginalIndex
as well as the value. And then went through the indices, looking up the element with that originalIndex and moving it 😄ritesh
12/20/2022, 12:26 PMSergei Petunin
12/20/2022, 12:33 PM±(n-1)
which are not supposed to shift. E.g. my input was 5000 numbers long, and there was the number -9998
ritesh
12/20/2022, 1:10 PMritesh
12/20/2022, 1:11 PMritesh
12/20/2022, 1:13 PMMath.floorMod()
came handy.ephemient
12/20/2022, 1:27 PMMath.floorMod()
, just use Kotlin's own .mod()
kqr
12/20/2022, 1:45 PMkqr
12/20/2022, 1:49 PMphldavies
12/20/2022, 2:57 PMyear 2022 day 20 part 1
Default took 48.874454ms: 13967
year 2022 day 20 part 2
Default took 644.260733ms: 1790365671518
Paul Woitaschek
12/20/2022, 3:39 PMPaul Woitaschek
12/20/2022, 3:57 PMOlaf Gottschalk
12/20/2022, 4:38 PMritesh
12/20/2022, 4:45 PMmix
means for part-2 as i hadn't read the whole problem for part 1 and had just looked at the sample input and output 😄ephemient
12/20/2022, 5:37 PMephemient
12/20/2022, 5:39 PMPaul Woitaschek
12/20/2022, 5:39 PMPaul Woitaschek
12/20/2022, 5:41 PMephemient
12/20/2022, 5:44 PMi
, you want it at index j
, so just move everything in-between up or down by one (depending on whether it's going down or up) and then put it in https://github.com/ephemient/aoc2022/blob/main/kt/src/commonMain/kotlin/com/github/ephemient/aoc2022/Day20.kt#L39-L40phldavies
12/20/2022, 7:55 PMindexOf
equalities stay unique.ephemient
12/20/2022, 9:22 PMephemient
12/20/2022, 10:01 PM$ wc -l input.txt
5000
$ sort input.txt | uniq | wc -l
3649
todd.ginsberg
12/20/2022, 10:02 PMephemient
12/20/2022, 10:14 PM