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

19 lines
571 B
Text

(defun flotri (n)
(let* ((last (trunc (* n (+ n 1)) 2))
(colw (mapcar [chain tostring length]
(range (- last n -1) last)))
(x 0))
(each ((r (range* 0 n)))
(each ((c (range 0 r)))
(format t " ~*a" [colw c] (inc x)))
(put-line))))
(defun usage (msg)
(put-line `error: @msg`)
(put-line `usage:\n@(ldiff *full-args* *args*) <smallish-positive-integer>`)
(exit 1))
(tree-case *args*
((num blah . etc) (usage "too many arguments"))
((num) (flotri (int-str num)))
(() (usage "need an argument")))