pszczyg

Untitled

Aug 4th, 2016
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. #light
  2. open System
  3. open System.Linq
  4. open System.IO
  5. open Microsoft.FSharp.Linq
  6.  
  7. let allowedChars = [|'a'; 'b'; 'o'; 'n'; 'i'; 'm'; 't'|]
  8. let dictionaryPath = "C:\\slowa.txt"
  9.  
  10. let is_allowed_word word (allowedChars : char[]) =
  11.     word |> Array.forall (fun letter -> allowedChars.Contains(letter))
  12.  
  13. let findFunc = File.ReadAllLines(dictionaryPath)
  14.                 |> Array.filter (fun word -> is_allowed_word (word.ToArray()) allowedChars)
  15.                 |> Array.sortByDescending (fun w -> w.Length)
  16.  
  17. let findFuncCSharpLike = File.ReadAllLines(dictionaryPath)
  18.                         .Where(fun word -> (word.All(fun letter -> allowedChars.Contains(letter))))
  19.                         .OrderByDescending(fun w -> w.Length)
  20. [<EntryPoint>]
  21. let main argv =
  22.     findFunc |> Seq.iter(fun w-> printfn "%s" w)
  23.     System.Console.ReadKey() |> ignore
  24.     0
Add Comment
Please, Sign In to add comment