mirror of
https://github.com/chylex/Advent-of-Code.git
synced 2025-06-08 23:34:03 +02:00
Add 2021 - Day 3 - Part 1
This commit is contained in:
parent
8004a505e4
commit
d6aa3ac901
11
.idea/runConfigurations/2021___Day_03.xml
Normal file
11
.idea/runConfigurations/2021___Day_03.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="2021 - Day 03" type="JetRunConfigurationType">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="MainKt" />
|
||||||
|
<module name="Advent_of_Code.2021-03" />
|
||||||
|
<shortenClasspath name="NONE" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/2021/03" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
</component>
|
1000
2021/03/input/1.txt
Normal file
1000
2021/03/input/1.txt
Normal file
File diff suppressed because it is too large
Load Diff
19
2021/03/main.kt
Normal file
19
2021/03/main.kt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import java.io.File
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val lines = File("input/1.txt").readLines().filter(String::isNotEmpty)
|
||||||
|
|
||||||
|
val totalRows = lines.size
|
||||||
|
val totalColumns = lines[0].length
|
||||||
|
val totalOnesPerColumn = Array(totalColumns) { column ->
|
||||||
|
lines.count { it[column] == '1' }
|
||||||
|
}
|
||||||
|
|
||||||
|
val gammaRate = totalOnesPerColumn
|
||||||
|
.map { if (it > totalRows / 2) 1 else 0 }
|
||||||
|
.foldIndexed(0) { index, total, bit -> total or (bit shl (totalColumns - index - 1)) }
|
||||||
|
|
||||||
|
val epsilonRate = gammaRate xor ((1 shl totalColumns) - 1)
|
||||||
|
|
||||||
|
println("Power consumption: ${gammaRate * epsilonRate}")
|
||||||
|
}
|
@ -32,3 +32,4 @@ The versions should not matter, but I used Visual Studio 2019 with `MSVC v142 (1
|
|||||||
| 2015 | 01 | NASM x86 |
|
| 2015 | 01 | NASM x86 |
|
||||||
| 2021 | 01 | Kotlin |
|
| 2021 | 01 | Kotlin |
|
||||||
| 2021 | 02 | Kotlin |
|
| 2021 | 02 | Kotlin |
|
||||||
|
| 2021 | 03 | Kotlin |
|
||||||
|
@ -34,4 +34,5 @@ sourceSets {
|
|||||||
|
|
||||||
make(2021, 1)
|
make(2021, 1)
|
||||||
make(2021, 2)
|
make(2021, 2)
|
||||||
|
make(2021, 3)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user