Skip to content

Instantly share code, notes, and snippets.

@Benjiko99
Last active October 5, 2021 19:22
Show Gist options
  • Save Benjiko99/d38be6e3c834d928a9ad209ae65ef314 to your computer and use it in GitHub Desktop.
Save Benjiko99/d38be6e3c834d928a9ad209ae65ef314 to your computer and use it in GitHub Desktop.
import java.util.Scanner
fun main(args: Array<String>) {
val inputReader = Scanner(System.`in`)
val input = inputReader.nextLine()
val sizeOfStairs = input.toInt()
StaircaseBuilder()
.build(sizeOfStairs)
.print()
}
class StaircaseBuilder() {
fun build(size: Int): Staircase {
var stairs = Array<Step>(size) { i ->
Step(width=i+1)
}
return Staircase(stairs)
}
}
class Staircase(var stairs: Array<Step>) {
fun print() {
for (step in stairs)
System.out.println(step.renderMirrored(stairs.size))
}
}
class Step(val width: Int) {
val HASH = '#'
val SPACE = ' '
fun renderMirrored(staircaseWidth: Int): String {
var output = ""
for (i in 1..staircaseWidth) {
if (i <= staircaseWidth - width)
output += SPACE
else
output += HASH
}
return output
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment