Advent of Code 2021 day 22
12/22/2021, 5:00 AMJintin
12/22/2021, 7:46 AMJakub Gwóźdź
12/22/2021, 8:13 AMjava.util.BitSet
. Apparently Kotlin has BitSet only in native stdlib…Jintin
12/22/2021, 8:18 AMJakub Gwóźdź
12/22/2021, 8:19 AMelizarov
12/22/2021, 8:33 AMJintin
12/22/2021, 8:36 AMelizarov
12/22/2021, 8:37 AMJakub Gwóźdź
12/22/2021, 8:37 AMexample
00:00:00.266: parsed 60 commands
00:00:00.279: split into 116*116*118 cubes
00:00:00.377: commands executed
00:00:00.386: 460960 cubes turned on
00:00:01.818: 2758514936282235
memory
00:00:01.820: parsed 420 commands
00:00:01.825: split into 830*829*824 cubes
00:00:03.159: commands executed
00:00:03.165: 149763891 cubes turned on
00:00:52.981: 1387966280636636
Jakub Gwóźdź
12/22/2021, 8:38 AMJakub Gwóźdź
12/22/2021, 8:41 AMreturn generateSequence(result.nextSetBit(0)) { index ->
result.nextSetBit(index + 1).let { if (it >= 0) it else null }
}
.sumOf { index ->
val xx = index / 1000000
val yy = index / 1000 % 1000
val zz = index % 1000
...
so it’s not a waste 🙂Jintin
12/22/2021, 10:04 AMphldavies
12/22/2021, 1:16 PMphldavies
12/22/2021, 1:17 PMIntRange
doesn’t have a .size
propertyMichael Böiers
12/22/2021, 3:45 PMelizarov
12/22/2021, 4:05 PMphldavies
12/22/2021, 4:14 PMphldavies
12/22/2021, 4:33 PMMichael Böiers
12/22/2021, 4:39 PMphldavies
12/22/2021, 4:40 PMphldavies
12/22/2021, 4:40 PMRuud Wiegers
12/22/2021, 6:31 PMphldavies
12/22/2021, 6:43 PMelizarov
12/22/2021, 6:55 PMephemient
12/22/2021, 11:01 PMephemient
12/22/2021, 11:03 PMtodd.ginsberg
12/22/2021, 11:23 PMDan Fingal-Surma
12/23/2021, 12:07 AMFredrik Rødland
12/23/2021, 12:08 AMphldavies
12/23/2021, 12:11 AMDan Fingal-Surma
12/23/2021, 12:14 AMtodd.ginsberg
12/23/2021, 12:26 AMphldavies
12/23/2021, 12:31 AMJintin
12/23/2021, 12:36 AMfor part 2 I encounter memory issue too, so I solve it by join section by section. I think it's around 1 sec for part 2 in this way.By changing List to IntRange the performance is increasing a lot, data structure is really important here, haha.
ephemient
12/23/2021, 1:49 AMphldavies
12/23/2021, 11:06 PM