Comment detail

ビンゴの結果を整形表示 (Nested Flatten)

	
 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
修正。
|> String.concat "\n"
じゃなくて
|> String.concat "\n\n"
としないとお題のようにならないですね。

Index

Feed

Other

Link

Pathtraq

loading...