Click here to Skip to main content
15,399,959 members

Comments by Stuart Dootson (Top 7 by date)

Stuart Dootson 2-Dec-16 12:52pm View
   
So, I did a Haskell version of this challenge (see below) and used the Criterion benchmarking package. This produces an HTML report, showing the average times per iteration. Here's the one for my Haskell solution.:



It's a neat library/tool...
Stuart Dootson 1-Dec-16 7:52am View
   
It gets wackier - that F# code was partly developed on a Windows 10 workstation (6 core Xeon, around 3GHz - that's where my previous times are from) and partly on my (8 year old) MBP, with a 2.4GHz Core2 Duo. In OS X, with Mono and Visual Studio Code (with the Ionide extension). The power of cross-platform .NET… Anyway - my Mac gave these timings:

Tests run:       10
Iterations/test: 100
-----------------------------------------------------------------------------

Basic Test

  FsSolution - Basic : MIN: 8.4053 ms | MAX 14.0585 ms | AVG 10.4869 ms
  PreCompiledFsSolution - Basic : MIN: 7.2594 ms | MAX 10.2251 ms | AVG 8.18209 ms


Bonus Test

  FsSolution - Bonus : MIN: 8.2866 ms | MAX 11.5506 ms | AVG 9.42119 ms
  PreCompiledFsSolution - Bonus : MIN: 7.4998 ms | MAX 12.9918 ms | AVG 8.99166 ms

Tests run:       10
Iterations/test: 1000
-----------------------------------------------------------------------------

Basic Test

  FsSolution - Basic : MIN: 88.4249 ms | MAX 93.8609 ms | AVG 90.9543 ms
  PreCompiledFsSolution - Basic : MIN: 78.6023 ms | MAX 93.5715 ms | AVG 83.0625 ms


Bonus Test

  FsSolution - Bonus : MIN: 87.9642 ms | MAX 99.3946 ms | AVG 91.8193 ms
  PreCompiledFsSolution - Bonus : MIN: 78.3943 ms | MAX 98.3158 ms | AVG 83.7617 ms
Stuart Dootson 1-Dec-16 6:01am View
   
Here we go - it's a Github gist

Easiest way for you to build it is probably create a new F# Console Application in VS2015, paste the code in that gist into the source file that's created by the template and then build/run the Release variant.
Stuart Dootson 30-Nov-16 19:23pm View
   
https://gist.github.com/studoot/f883c041cf6aaeaa1a752114963c16b7 You (of course) meant the timing code - silly me posted the link to my solution code... I'll get the timing harness code posted up when I can get to it...
Stuart Dootson 30-Nov-16 11:21am View
   
Out of inerest, I converted your benchmarking code to F# to measure my F# solution & got the following timings:

Statistics
----------
Tests run:       10
Iterations/test: 100
-----------------------------------------------------------------------------
F# Solution - Basic: MIN = 2.6989, MAX = 3.2336, AVG = 2.78732
F# Solution - Bonus: MIN = 2.8122, MAX = 3.1169, AVG = 2.8664

Statistics
----------
Tests run:       10
Iterations/test: 1000
-----------------------------------------------------------------------------
F# Solution - Basic: MIN = 25.4413, MAX = 27.2665, AVG = 25.8091
F# Solution - Bonus: MIN = 28.5614, MAX = 30.4572, AVG = 29.0724
Stuart Dootson 30-Nov-16 5:25am View
   
In fact - the easiest way to accomplish this is to:

1. Change the filter to return a string option (Some string indicates that filtering was done)

2. Add a 'null' filter (always returns the input word) at the end of the filter list to ensure there's always a succeeding filter.

3. Change the filterAWord function to be:

let filterAWord (filters:(string -> string option) seq) (word:string) =
      filters
      |> Seq.map (fun filter -> filter word)
      |> Seq.find Option.isSome
      |> Option.get
Stuart Dootson 30-Nov-16 2:09am View
   
No, but they could easily do so (return tuple of bool & string?). To stop filtering once a substitutions made, I presume? If that's the case, the Seq.fold needs to become a 'Seq.map |> Seq.find' - that's lazy evaluated, so not all the filters would be processed.