Hi folks,
I finished the first prototype in F#, I will translate it to Scala at a later date.
I'm not sure if the correct result is "Trouble Foot" or "Tearful" "Bozo" :)
This style of coding isn't really helpful to those just starting FP as it is probably better to work on one idiom at a time.
open System.IO
open System.Collections.Generic
let words = Directory.GetFiles(@"C:\DLOAD\Data\Dict")
|> Seq.map (fun x -> File.ReadLines(x))
|> Seq.concat
|> Seq.map (fun x -> x.ToUpper())
|> Seq.distinct
|> Seq.groupBy (fun x -> x.Length)
|> fun xs ->
let dict = Dictionary<int,string []>()
xs |> Seq.iter (fun x -> dict.Add(fst x, snd x |> Seq.toArray))
dict
let search (start:(int*int list*string) seq) (finish:int list) =
let toString (chars:seq<char>) = new string [|for c in chars -> c|]
let merge (xs:string seq) (ys:string seq) = seq { for x in xs do for y in ys do yield x + y}
start
|> Seq.map (fun (x,y,z) -> (x,y,z |> Seq.sort |> toString))
|> Seq.map (fun (x,y,z) ->
words.[x]
|> Seq.filter (fun u -> u |> Seq.sort |> toString = z)
|> Seq.map (fun v -> y |> Seq.map (fun i -> v.[i]) |> toString))
|> Seq.fold merge (Seq.singleton "")
|> Seq.map (fun letters ->
let filter (str:string) (xs:string seq) = xs |> Seq.filter (fun x -> x |> Seq.exists (fun z -> str |> Seq.exists (fun y -> z = y) |> not) |> not)
let match' (x:string) (y:string) = Seq.zip (x |> Seq.sort) (y |> Seq.sort) |> Seq.exists (fun (x,y) -> x <> y) |> not
finish |> Seq.map (fun x -> words.[x] |> filter letters)
|> Seq.fold merge (Seq.singleton "")
|> Seq.filter (match' letters))
|> Seq.concat
|> Seq.map (fun str -> 0::finish |> Seq.pairwise |> Seq.map (fun (x,y) -> str.Substring(x,y)))
search [(5,[0;2;3],"EFNOL");(5,[2;3],"RATAO");(6,[1;4;5],"TOZALE");(6,[1;2;3],"BLOUED")] [7;4]
results:
[|seq ["TROUBLE"; "FOOT"]; seq ["FLOUTER"; "BOOT"]; seq ["FOOTLER"; "BOUT"];
seq ["TEARFUL"; "BOZO"]; seq ["FLOUTER"; "BOAZ"]|]
On Mon, Sep 5, 2011 at 7:06 PM, Matthew Moloney
<molo...@gmail.com> wrote:
Deprecating the Observer Pattern http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.pdf
On Mon, Sep 5, 2011 at 6:26 PM, Matthew Moloney
<molo...@gmail.com> wrote:
I'm here, where in Aconex? I can't find anyone else
Sent from my Windows Phone
From: Martin PauloSent: Monday, September 05, 2011 9:41 AM
To: scala-tutori...@googlegroups.com
Subject: Re: Reminder :Scala user group today
I'll be there: somewhat behind schedule with my learning, but what the :-)
BTW, if people on this tutorial group don't subscribe to the main scala user group mailing list (?), the subset of the book by Cay Horstman that TypeSafe are giving away in exchange for your e-mail address is proving to be quite useful to me (
http://www.typesafe.com/resources/scala-for-the-impatient).
Martin
On 5 September 2011 07:24, Gokul Krishnan
<goku...@gmail.com> wrote:
Hi All,
Just a reminder that the scala user group meeting is today at 6:15 at Aconex - 696 Bourke street
Cheers
Gokul
--
==================================================================
Martin Paulo, BSc.
Software Developer
Tel :
+61-3-9434 2508 (Home)
Tel : 04 205 20339 (Mobile)
Site:
http://www.thepaulofamily.net"Nobody goes there any more. It's too crowded" - Yogi Berra.