Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Perfect-shuffle/F-Sharp/perfect-shuffle.fs
Normal file
15
Task/Perfect-shuffle/F-Sharp/perfect-shuffle.fs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
let perfectShuffle xs =
|
||||
let h = (List.length xs) / 2
|
||||
xs
|
||||
|> List.mapi (fun i x->(if i<h then i * 2 else ((i-h) * 2) + 1), x)
|
||||
|> List.sortBy fst
|
||||
|> List.map snd
|
||||
|
||||
let orderCount n =
|
||||
let xs = [1..n]
|
||||
let rec spin count ys =
|
||||
if xs=ys then count
|
||||
else ys |> perfectShuffle |> spin (count + 1)
|
||||
xs |> perfectShuffle |> spin 1
|
||||
|
||||
[ 8; 24; 52; 100; 1020; 1024; 10000 ] |> List.iter (fun n->n |> orderCount |> printfn "%d %d" n)
|
||||
Loading…
Add table
Add a link
Reference in a new issue