でかいXを出力する
30分プログラム、その756。
anarchy golf - Xにインスパイアされて、でっかいXを出力してみました。
使い方
- print (x 3); x x x x x x x x x x x x xval it = () : unit
ソースコード
open String; fun repeat _ 0 = [] | repeat c n = List.tabulate (n, (fn _ => c)); fun make_string c n = String.implode (repeat c n); fun range from to = if from = to then [] else from :: range (from + 1) to; fun row n = let val m = 2 * n + 1 val mid = make_string #" " m in "x" ^ mid ^ "x" end; fun padding width str = let val n = (width - String.size str) div 2 val pad = make_string #" " n in pad ^ str ^ pad end; fun x n = let val downside = List.map row (range 0 n) val upside = List.rev downside val width = 2 * n + 1 val big_x = List.map (padding width) (upside @ [ "x" ] @ downside) in String.concatWith "\n" big_x end;