RosettaCodeData/Task/Floyds-triangle/AWK/floyds-triangle.awk

16 lines
375 B
Awk
Raw Permalink Normal View History

2013-06-05 21:47:54 +00:00
#!/bin/awk -f
2013-04-10 21:29:02 -07:00
BEGIN {
2013-06-05 21:47:54 +00:00
if (rows !~ /^[0-9]+$/ || rows < 0) {
print "invalid rows or missing from command line"
print "syntax: awk -v rows=14 -f floyds_triangle.awk"
exit 1
}
for (row=cols=1; row<=rows; row++ cols++) {
width[row] = length(row + (rows * (rows-1))/2)
for (col=1; col<=cols; col++)
printf("%*d%c", width[col], ++n, row == col ? "\n" : " ")
}
2013-04-10 21:29:02 -07:00
}