Guest User

Untitled

a guest
Mar 14th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.48 KB | None | 0 0
  1. let memoize f =
  2.     let dict = new System.Collections.Generic.Dictionary<_,_>()
  3.     fun n ->
  4.         match dict.TryGetValue(n) with
  5.         | (true, v) -> v
  6.         | _ ->
  7.             let temp = f(n)
  8.             dict.Add(n, temp)
  9.             temp
  10.  
  11.  
  12. let rec isConcat l = memoize(fun (s:string) ->
  13.     match s with
  14.     | "" -> true
  15.     | x -> l |> List.exists (fun (w:string) -> x.Length >= w.Length && s.EndsWith w && (isConcat l (x.Substring(0,x.Length-w.Length)))
  16.     ))
Advertisement
Add Comment
Please, Sign In to add comment