Last active
November 2, 2015 16:37
-
-
Save mknudsen/5c860a6b4bfb1f1f605e 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 main(args: Array<String>) { | |
// Starte mit "rats live on arona no evil star" | |
val sentence = "rats live on arona no evil star" | |
// 1. change all letters with their counterparts in the alphabet | |
val alphabetCounterparts: String = sentence.split(' ').map { word -> word.map { ch -> (122 - (ch.toInt() - 97)).toChar().toLowerCase() }.joinToString("") }.joinToString(" ") | |
// 2. convert all letters to their numeric value in the alphabet (a = 1) | |
val lettersToNumericValues:List<List<Int>> = alphabetCounterparts.split(' ').map { word -> word.map { ch -> ch.toInt() - 96 } } | |
// 3. add 1 to each number, repeat this step until the largest number is 99 | |
val incrementedUntilOneIs99: List<List<Int>> = lettersToNumericValues.map { numberWord -> numberWord.map { it + (99 - (lettersToNumericValues.map { it.max() ?: 0 }.max() ?: 0)) } } | |
// 4. reverse the phrase but keep the order in the individual numbers | |
val reversed: List<List<Int>> = incrementedUntilOneIs99.reversed() | |
// 5. replace all numbers with their difference with 100 | |
val substractedFrom100: List<List<Int>> = reversed.map { numberWord -> numberWord.map { 100 - it } } | |
// 6. convert all numbers to letters | |
val mappedBackToCharacters = substractedFrom100.map { numberWord -> numberWord.map { (it + 96).toChar() }.joinToString("") }.joinToString(" ") | |
System.out.println(mappedBackToCharacters) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment