Day 8, pretty cool
This commit is contained in:
1 parent
579b97e2e6
commit
46e7df3308
2 files changed
+56
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package com.basdado.adventofcode.day8
|
||||
|
||||
import com.basdado.adventofcode.line
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.stream.Collectors
|
||||
|
||||
|
||||
const val DAY8_INPUT_PATH = "/day/8/input.txt"
|
||||
const val IMG_WIDTH = 25
|
||||
const val IMG_HEIGHT = 6
|
||||
|
||||
|
||||
fun main() {
|
||||
|
||||
Day8.puzzle1()
|
||||
Day8.puzzle2()
|
||||
}
|
||||
|
||||
object Day8 {
|
||||
|
||||
fun puzzle1() {
|
||||
|
||||
val counter = AtomicInteger()
|
||||
|
||||
val layer = line(DAY8_INPUT_PATH)
|
||||
.chars()
|
||||
.map { it - '0'.toInt() }
|
||||
.mapToObj { it }
|
||||
.collect(Collectors.groupingBy<Int, Int> { counter.getAndIncrement() / (IMG_WIDTH * IMG_HEIGHT) })
|
||||
.minBy { it.value.stream().filter { n -> n == 0 }.count() }!!
|
||||
.value
|
||||
|
||||
println(layer.count { it == 1 } * layer.count { it == 2 })
|
||||
|
||||
}
|
||||
|
||||
fun puzzle2() {
|
||||
|
||||
val counter = AtomicInteger()
|
||||
|
||||
val img = line(DAY8_INPUT_PATH)
|
||||
.chars()
|
||||
.map { it - '0'.toInt() }
|
||||
.mapToObj { it }
|
||||
.collect(Collectors.groupingBy<Int, Int> { counter.getAndIncrement() % (IMG_WIDTH * IMG_HEIGHT) })
|
||||
.map { it.value.firstOrNull { n -> n != 2 } }
|
||||
|
||||
for(i in 0 until IMG_HEIGHT) {
|
||||
for (j in 0 until IMG_WIDTH) {
|
||||
print(if(img[i * IMG_WIDTH + j] == 1) "#" else " ")
|
||||
}
|
||||
println()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
2212220010221202222222222122222202002222222222221222222222202222222122222221220222222022222222222122122222222222202220222220210220222222222022222222202222221022220202222222222122222202222222222222221222222222202222222222222221222222212222222222222022222222222222202222222220210221222222222122222222222212222000220222222222222222222212212222222222221222222222222222222222222220221222202022222222222022222222222222212222222221220221222222221022222222222222221120222202222222222022222212012222222222222222222222222222222022222220220222212122222222222222022222222222222220222220222222222222220122222222212222221222221212220222222122222202002222222222220222222222202222222222222222211222222122222222222222222222222222222222222221222221222222220022222222202202220210221222220222222022222202202222222222220222222222202222222022220220200222212222222222222122222222022222222222222221212220222222221222222222212222220201220212222222222122222222122222222222222222222222212222222222221220221222222122222222222122022222122222202222222222201222222222220222222222222222220121220212221222222022222222122222222222220222222222212222222222220220210222222022222222222122222222222222222221222222221220222222220122222222222212220010221222222222222122222212212222222222222222222222202222222022220221200222202122222222222022122222122222212220222220201221222222220122222222212212222110220222222222222122222222202222222222220222222222222222222222221220221222202222222222222122122222122222212220222220211220222222222122222222212222220102221222220222222122222202012222222222221212222222212222222022221220210222212022222222222122122222022212202221222220211221222222222122220222202212221101222202222222222222222212002222222222220222222222202222222222220222221222202022222222222022122222122222202222222222210220222222220222221222202202220020221212220222222022222212112222222222220212222222202222222222222222211222212222222222222022022222122222222221222221202221222222220022122222212222220022221212221222222022222212102222222222222202222222212222222022220221211222222222222222222022222222122212212221222221222222222222222022221220222212221010220212220222222022222202012222222222220212222222202222222222222221201222202022222222222222122222122212222220222222201220222222222022002222202222222001220202220222222022222002010222222222220202222222212222222122120221212222202122222222222120222222022222222221222222220222222222221122210221222222222000221212222222222122222112101222222222220212222220212222222122122220220222212222222222222121022222122202202222222220212221222222220022000220212212220112221212222222222122202112210222222222221202222221222222222122220220201222202122222222222020022222122202202221222220221212222222221122012220202212220102220222222222222122202202012222222222221222222221222222222222022222220222222222222222222120122222022202212222222221211210222222222022212220202202221120220222222222222022212122112222222222221222222222222222222022120221122222222222222222222022122222122222202220222221210200222222220022120220222212222020220212222222222022222122221222222222222212222222212222222122120220112222012222222022222020121222022202222221222220210202222222222222101222212222222000222222221222222222202112221222222222221222222220222222222022121221121222222022222002222221020222221202222222222221221210222222220022110221222202222012221212222222222222212212222222222222222222222220202222222122021222011222002222222012222221022222220212222220222221212212222222220122211222222212220212222212222222220122212102212222222222220202222220202222222222222222010222122122222122222120121222222222202222222222220222222222220122001222202222220110221212220222222222212212212222222202221222222220202222222122121222002222102122222002222020120222022202202222222222222220222222220122201222222212220100220222222222222222202222222222222222220212212222222222222122220221020222002222222012222122120222220212222221222220220220222222220022120222222202222200220202222222220022202212212222222202221212202221202222222222222220202222202022222102222021022222121222222220222220221220022222222122111220212212222220220222221222220122222222100222222212220212012222212222222122120221212222222222222002222122122222222212212220222221202200222022221022222221222212221020222222220222222022202122001222222202220202212220212222222222221221101222012222222222222221022222120222202221222220001211122122222022002220202212220012222212222222222222222102001222222222221222102220202222222022220121022222222122222222222221220222022212202222222221121201122222222122001222222212222111221212221222221122222022211222222202222202002220202222222022221221012222022222222022222022120222120212212222222222100221122222222022010221212202220211121212222222221022202102210222222222220212222222222222222022020020111222202222222112222202200222121202222220222221011211222022220122101220222202220221220202220222121122212012111222222202221212222222212222222122120120222222212122222212222112020222202222202222222221111220122022221022222220212222222012220222221222120222222002211222222212221Line truncated
|
||||
Reference in new issue
Block a user