RosettaCodeData/Task/Floyds-triangle/CLU/floyds-triangle.clu
2023-07-01 13:44:08 -04:00

32 lines
871 B
Text

floyd = cluster is triangle
rep = null
width = proc (n: int) returns (int)
w: int := 1
while n >= 10 do
w := w + 1
n := n / 10
end
return (w)
end width
triangle = proc (rows: int) returns (string)
ss: stream := stream$create_output()
maxno: int := rows * (rows+1)/2
num: int := 1
for row: int in int$from_to(1, rows) do
for col: int in int$from_to(1, row) do
stream$putright(ss, int$unparse(num), 1 + width(maxno-rows+col))
num := num + 1
end
stream$putl(ss, "")
end
return (stream$get_contents(ss))
end triangle
end floyd
start_up = proc ()
po: stream := stream$primary_output()
stream$putl(po, floyd$triangle(5))
stream$putl(po, floyd$triangle(14))
end start_up