sandglass by

let () =
  let s = read_line () in
  let n = String.length s in
  for i = 0 to n - 1 do
    let t = String.copy s in
    let d = (if i < n / 2 then i else n - i - 1) in
    for j = 0 to d - 1 do
      t.[j] <- ' ';
      t.[n - j - 1] <- ' '
    done;
    t.[1] <- s.[1];
    t.[n - 2] <- s.[n - 2];
    print_endline t
  done

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page