Last active
January 10, 2018 02:28
-
-
Save whaley/c495c237c1bc27191bae2d6709ec7200 to your computer and use it in GitHub Desktop.
This file contains 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
fun checksum(spreadsheet: String): Int { | |
val lines = spreadsheet.split("\n") | |
val rows : List<List<Int>> = lines.map { it -> it.split(Regex("""\s""")).map { it -> Integer.valueOf(it) } } | |
return rows.fold(0, {sum:Int, list: List<Int> -> sum + (list.max() ?: 0) - (list.min() ?: 0)}) | |
} |
This file contains 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
package com.morninghacks.aoc2017 | |
import org.jetbrains.spek.api.Spek | |
import org.jetbrains.spek.api.dsl.given | |
import org.jetbrains.spek.api.dsl.it | |
import org.jetbrains.spek.api.dsl.on | |
import kotlin.test.assertEquals | |
object Day02Spec : Spek({ | |
given("Day Two : Part One") { | |
val spreadsheet = """5 1 9 5 | |
.7 5 3 | |
.2 4 6 8""".trimMargin(".") | |
on("checksum") { | |
assertEquals(18,checksum(spreadsheet)) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment