News for hackers. Stuff that matters.
Re:Spark by Mgccl on Tuesday November 15, 2011 @06:07AM (#3237819)
Just did a Haskell version of spark. It supports in 9 lines of code (exclude comment + empty line) Double instead of just Int. Negative numbers.

https://github.com/Mgccl/mgccl-haskell/blob/master/random/sp...

Re:Spark by jcromartie on Tuesday November 15, 2011 @08:42AM (#3238140)
Same features. 4 SLoC of Ruby :)

https://gist.github.com/1367091

Re:Spark by silvestrov on Tuesday November 15, 2011 @09:43AM (#3238315)
'floor' on last line should be changed to 'round'.

  ▁▁▁▁▁▁▂▂▂▂▂▂▃▃▃▃▃▃▅▅▅▅▅▅▆▆▆▆▆▆▇ = floor
  ▁▁▁▂▂▂▂▂▂▃▃▃▃▃▃▅▅▅▅▅▅▆▆▆▆▆▆▇▇▇▇ = round
Re:Spark by jcromartie on Tuesday November 15, 2011 @09:44AM (#3238319)
Thanks! Much better.
Re:Spark by jodrellblank on Tuesday November 15, 2011 @10:31AM (#3238518)
And here's a PowerShell version. (Use PowerShell ISE as PowerShell normal prompt doesn't support unicode).

http://pastie.org/2867807

[edit: updated, careless variable rename, thanks jcromartie]

Re:Spark by jcromartie on Tuesday November 15, 2011 @11:15AM (#3238707)
$stats should be $minmax
Re:Spark by tanoku on Tuesday November 15, 2011 @10:00PM (#3241528)
I made my own Sparks in C. They look like Sparks.

https://gist.github.com/1368661

Re:Spark by ranza on Tuesday November 15, 2011 @02:18PM (#3239680)
My horrible php version :) https://gist.github.com/1368025
Re:Spark by tome on Tuesday November 15, 2011 @07:58AM (#3238043)
I really like your version. Very neat!
Re:Spark by ocharles on Tuesday November 15, 2011 @01:28PM (#3239407)
Here's a Haskell version that uses a single loop to do the normalizing, and has a main that doesn't use do syntax. This was mostly a nice little brainteaser:

https://gist.github.com/1367709

mapNormalize takes a function, and produces a function that runs that function with the normalized input. It runs in a single iteration, rather than 2 maps. Credit to `dylex` for much hand holding on a single iteration normalizer :)

Re:Spark by ddfisher on Tuesday November 15, 2011 @09:31PM (#3241453)
Because Haskell is evaluated lazily, two maps doesn't imply two iterations over the data. In this case, I would expect only one pass through the data for both of the maps. Out of curiosity, I did a quick criterion benchmark for both functions. Here's the result on a list of 100 elements:

  benchmarking spark_mggcl
  mean: 49.29483 us, lb 48.77776 us, ub 50.25594 us, ci 0.950
  std dev: 3.495423 us, lb 2.140951 us, ub 6.373469 us, ci 0.950

  benchmarking spark_ocharles
  mean: 60.12347 us, lb 58.95586 us, ub 61.48084 us, ci 0.950
  std dev: 6.434853 us, lb 5.529613 us, ub 7.824865 us, ci 0.950 
The simpler version appears to be faster.

(As an aside, is there something in particular you dislike about do syntax? I find that it often makes things more readable, though slightly more verbose.)

Re:Spark by ocharles on Wednesday November 16, 2011 @05:47AM (#3242613)
I am aware of that, as I said this was more a mental exercise. normalizeMap is harder to understand, but it was interesting to write - it wasn't meant to be a stab at your code or claim it's better :)

In terms of do syntax, I try and avoid that because I find it detracts from the overall flow of data. With: "putStrLn . spark . map read =<< getArgs" I find it easy to see that main doesn't do much other than transform the users input. maybe a personal preference thing though...

Re:Spark by Mgccl on Tuesday November 15, 2011 @12:40PM (#3239162)
Updated. thx to gwern. Now I know the existence of hlint.

Now, without the type declaration, white space, comments, it's only 6 lines, and looks even better. :)