Created
June 18, 2018 13:01
-
-
Save castrors/468d4d44c5b3103b6683b0414021a3c3 to your computer and use it in GitHub Desktop.
That's the solution for the DiamondPrint problem: http://exercism.io/exercises/kotlin/diamond/readme
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
class DiamondPrinter { | |
fun printToList(char: Char): List<String> { | |
val size = ('A'..char).count() * 2 - 1 | |
val half = size / 2 | |
return (0..half).map { lineIndex -> | |
StringBuilder("".padStart(size)) | |
.apply { | |
setCharAt(half + lineIndex, 'A' + lineIndex) | |
setCharAt(half - lineIndex, 'A' + lineIndex) | |
}.toString() | |
}.let { it + it.reversed().drop(1) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment