Last active
August 16, 2018 22:00
-
-
Save plallin/caa78505397684fbdc80165b35c37b15 to your computer and use it in GitHub Desktop.
My Solution for Functional Kubs' katas of August 2018
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 functionalkubs | |
/** | |
* Implement part 1 of http://adventofcode.com/2017/day/1. | |
* See https://github.com/raphait/kotlin-functional-kubs for instructions. | |
*/ | |
object Part1 { | |
fun captcha(input: String): Int { | |
return getArrayOfDoubleDigit(numberToArray(input)).sum() | |
} | |
fun numberToArray(numString: String): List<Int> { | |
return numString.split("").filter{!it.isBlank()}.map{it.toInt()} | |
} | |
fun getArrayOfDoubleDigit(originalArray: List<Int>): List<Int> { | |
return originalArray.filterIndexed { index, value -> originalArray[(index + 1) % originalArray.size] == value } | |
} | |
} | |
/** | |
* Implement part 2 of http://adventofcode.com/2017/day/1. | |
* See https://github.com/raphait/kotlin-functional-kubs for instructions. | |
*/ | |
object Part2 { | |
fun captcha(input: String): Int { | |
return getArrayOfDoubleDigit(numberToArray(input)).sum() | |
} | |
fun numberToArray(numString: String): List<Int> { | |
return numString.split("").filter{!it.isBlank()}.map{it.toInt()} | |
} | |
fun getArrayOfDoubleDigit(originalArray: List<Int>): List<Int> { | |
return originalArray.filterIndexed { index, value -> originalArray[(index + (originalArray.size / 2)) % originalArray.size] == value } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment