Last active
October 5, 2021 19:22
-
-
Save Benjiko99/d38be6e3c834d928a9ad209ae65ef314 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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