Last active
December 5, 2024 12:41
-
-
Save fmo91/756a44d4583fa374b016f43fad7eb626 to your computer and use it in GitHub Desktop.
AdventOfCode2024 in Kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.math.abs | |
fun solve(input: String): Int { | |
val firstList: MutableList<Int> = mutableListOf() | |
val secondList: MutableList<Int> = mutableListOf() | |
var result = 0 | |
for (line in input.lines()) { | |
val components = line.split(" ").filter { it != "" }.map { it.toInt() } | |
firstList.add(components[0]) | |
secondList.add(components[1]) | |
} | |
firstList.sort() | |
secondList.sort() | |
for (index in 0 ..< firstList.count()) { | |
result += abs(firstList[index] - secondList[index]) | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Day 2 Part 2