Skip to content

Instantly share code, notes, and snippets.

@castrors
Created June 18, 2018 13:01
Show Gist options
  • Save castrors/468d4d44c5b3103b6683b0414021a3c3 to your computer and use it in GitHub Desktop.
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
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