Last active
May 13, 2018 02:32
-
-
Save f4ww4z/2bdf3aa02ef8da94f57f8c027adad078 to your computer and use it in GitHub Desktop.
Pattern / "problem solving"
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>) = bintang(4) | |
fun bintang(n: Int) { | |
for (i in n downTo 0) printBintang(n, i) | |
for (i in 1..n) printBintang(n, i) | |
} | |
fun printBintang(n: Int, rentang: Int) { | |
space(n - rentang) | |
if (rentang == 0) { | |
println('*') | |
} else { | |
print('*') | |
space(rentang * 2 - 1) | |
println('*') | |
} | |
} | |
fun space(n: Int) { | |
for (i in 1..n) print(' ') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment