ビンゴの結果を整形表示
Posted feedbacks - OCaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #light
let rec bingo n = shuffle [1..n]
and shuffle ls =
let rnd = new System.Random()
List.sort (fun x y-> rnd.Next(-1,2)) ls
let printLine ln n =
let rec len (m:int) = ( m.ToString() ).Length
and mk (m:int) = (String.make ((len n) - (len m)) ' ') ^ m.ToString()
and (|SplitAt|) m xs = List.partition (fun (x,i) -> i <= m) xs
and mkLns c = function
| [] -> []
| SplitAt c (head,tail) -> (List.unzip head)::mkLns (c+ln) tail
and concatMap f xs = String.concat " " <| List.map f xs
and bs = mkLns ln (List.zip (bingo n) [1..n])
[for (xs,ids) in bs -> (concatMap mk xs) ^ "\n" ^ (concatMap mk ids)]
|> String.concat "\n"
|> printf "%s\n"
let bingoPr = fun n -> printLine 10 n
|



raynstard
#3403()
Rating1/1=1.00
「重複無し乱数」で作ったbingo関数の結果を下のように「何番目の乱数か」とセットにして10個ずつ折り返して表示するコードを書いてください。
[ reply ]