fork download
  1. open System
  2.  
  3. let folder state x =
  4. match state with
  5. | (zeros, others) ->
  6. match x with
  7. | 0 -> (0::zeros, others)
  8. | n -> (zeros, n::others)
  9.  
  10. let zerosFirst xs =
  11. match List.fold folder ([], []) xs with
  12. | (zeros, others) -> List.append zeros others
  13.  
  14. let xs = [ 5; 0; 0; -4; 5; 0; 3; 3; 5; 0; -2; 0; 0 ]
  15. zerosFirst xs |> printfn "%A"
Success #stdin #stdout 0.19s 12872KB
stdin
Standard input is empty
stdout
[0; 0; 0; 0; 0; 0; -2; 5; 3; 3; 5; -4; 5]