Created
January 8, 2018 11:48
-
-
Save whaley/1c94f250a9b3b0e0bc31c5a3af5407f4 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 captcha(input: String, stepping: Int = 1): Int { | |
val ints = input.map { Character.getNumericValue(it) } | |
fun calcValueAtStepping(currentIndex: Int) : Int { | |
val wrappedIndex = currentIndex + stepping | |
return if (wrappedIndex < ints.size - 1) ints[wrappedIndex] else ints[wrappedIndex % ints.size] | |
} | |
var sum = 0 | |
for ((index, current) in ints.withIndex()) { | |
sum += if (current == calcValueAtStepping(index)) current else 0 | |
} | |
return sum | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment