xxxxxxxxxx
fun main() {
print("Please enter size of triangle: ")
var size = readLine()!!.toInt()
//right triangle
//PSEUDO CODE
/*
For every “row” in the range of 1 and N
if true (its always true)
then for every “column” in the range of 1 and number of rows
If false print new line and loop around to beginning
if true
Column equals 1 or column equals row or row equals N
If true print number of “whatever”
if false print “space”
Both true and false will loop around after “for every “column” in the range of 1 and number of rows”
*/
for (row in 1..size) {
for (col in 1..row) {
if (col == 1 || col == row || row == size) {
print("*")
} else {
print(" ")
}
}
println()
}
println()
//number triangle
//PSEUDO CODE
/*For every “row” in the range of 1 and N
if true (its always true)
then for every “column” in the range of 1 and number of rows
If true print “whatever”, looping around to after “for every “column” in the range of 1 and number of rows”
If false print new line and loop to beginning
*/
for (row in 1..size) {
for (col in 1..row) {
print("$col")
}
println()
}
println()
//reversed triangle
//PSEUDO CODE
/*
For every “row” in the range of 1 and N
if true (its always true)
then for every “column” in the range of 1 and number of rows
If true print a “space” and loop around
If false for every “column” in the range of 1 and number of rows that is true
Then if row equals N or column equals 1 or column equals row and if true print “whatever” if false print a “space” both will result in looping around
If false print new line and loop around to beginning
*/
for (row in 1..size) {
for (col in row..size) {
print(" ")
}
for (col in 1..row) {
if (row == size || col == 1 || col == row) {
print("*")
} else {
print(" ")
}
}
println()
}
println()
//upside down reversed number triangle, just for fun
//PSEUDO CODE
/*
For every number in the progression from whatever value down to the specified value
if true (its always true)
then for every “column” in the range of number of rows and N
If true print a “space” and loop around
If false for every “column” in the range of 1 and number of rows that is true
Then if row equals N or column equals 1 or column equals row and if true print “whatever” if false print a “space” both will result in looping around
If false print new line and loop around to beginning
*/
for (row in size downTo 1) {
for (col in row..size) {
print(" ")
}
for (col in 1..row) {
if (row == size || col == 1 || col == row) {
print("$col")
} else {
print(" ")
}
}
println()
}
}