Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.91 KB | None | 0 0
  1. [<EntryPoint>]
  2. let main argv =
  3.  
  4.     let numbers = [ 1; 7; 7; 9; 9; 3 ]
  5.     let series = [ (0, 1); (1, 2); (3, 2); (5, 1) ]
  6.  
  7.     let calculateSeries data =
  8.         let rec traverseData data origin start count = seq {
  9.             match data with
  10.             | [] -> yield (start, count)
  11.             | h::t ->
  12.                 if origin = h then
  13.                     yield! traverseData t origin start (count + 1)
  14.                 else
  15.                     yield (start, count)
  16.                     yield! traverseData t h (start + count) 1
  17.         }
  18.         match data with
  19.         | [] -> []
  20.         | h::t -> traverseData data h 0 0 |> List.ofSeq
  21.        
  22.     let printIntervalInfo (start, count) = printfn "%d %d" start count
  23.  
  24.     printfn "etalon series"
  25.     series |> List.iter printIntervalInfo
  26.  
  27.     printfn "computed series"
  28.     numbers |> calculateSeries |> List.iter printIntervalInfo
  29.        
  30.     0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement