Floyd's triangle   lists the natural numbers in a right triangle aligned to the left where

 the first row is   1     (unity)
 successive rows start towards the left with the next number followed by successive naturals listing one more number than the line above.


The first few lines of a Floyd triangle looks like this:

 1
 2  3
 4  5  6
 7  8  9 10
11 12 13 14 15



Task

 Write a program to generate and display here the first   n   lines of a Floyd triangle. 
(Use   n=5   and   n=14   rows).
 Ensure that when displayed in a mono-space font, the numbers line up in vertical columns as shown and that only one space separates numbers of the last row.


let ( |> ) f g x = g (f x)
let rec last = function x::[] -> x | _::tl -> last tl | [] -> raise Not_found
let rec list_map2 f l1 l2 =
  match (l1, l2) with
  | ([], _) | (_, []) -> []
  | (x::xs, y::ys) -> (f x y) :: list_map2 f xs ys
 
let floyd n =
  let rec aux acc cur len i j =
    if (List.length acc) = n then (List.rev acc) else
      if j = len
      then aux ((List.rev cur)::acc) [] (succ len) i 0
      else aux acc (i::cur) len (succ i) (succ j)
  in
  aux [] [] 1 1 0
 
let print_floyd f =
  let lens = List.map (string_of_int |> String.length) (last f) in
  List.iter (fun row ->
    print_endline (
      String.concat " " (
        list_map2 (Printf.sprintf "%*d") lens row))
  ) f
 
let () =
  print_floyd (floyd (int_of_string Sys.argv.(1)))