Difference between revisions of "Programming performance/Apter K"

From HaskellWiki
Jump to navigation Jump to search
 
(Two new solutions)
Line 6: Line 6:
   
 
See http://www.nsl.com/k/gspc/gspc.k as I do not have permission to copy the source code herein.
 
See http://www.nsl.com/k/gspc/gspc.k as I do not have permission to copy the source code herein.
  +
  +
[Note added by sa, the author of the original:
  +
  +
The original solution has been replaced by two contributions from the K mailing list.
  +
  +
Solution 1:
  +
  +
c:10000.;h:p:();
  +
d:|*(" F";" ")0:1_0:`gspc.txt
  +
c+/h*{$[~0.97<y%x;[c-:m:.1*c;h,:m%y;p,:y];#i:&~1.06>y%p;[c+:y*+/h i;h[i]:p[i]:0n]];y}/d
  +
  +
Solution 2:
  +
  +
x:|1_*(" F";" ")0:`gspc.txt
  +
f:{$[y;[b[z]+:(.1*x)%z;.9*x];[z*:+/b p@:&~z<1.06*p:!b;b::p_b;x+z]]}
  +
g:{b!:b::0#0.0;(last[x]*+/b)+f/[1e4;~.97<%':x;x]}
  +
g x
  +
  +
No time estimates were given, but i'd expect something in the 10-30 minute range.]

Revision as of 03:04, 8 March 2007

Prepare yourself...

Precise details are not known about how long it took to write this. Anecdotal evidence says 15 minutes, based on an e-mail conversation with an author's acquaintance.

Code

See http://www.nsl.com/k/gspc/gspc.k as I do not have permission to copy the source code herein.

[Note added by sa, the author of the original:

The original solution has been replaced by two contributions from the K mailing list.

Solution 1:

c:10000.;h:p:(); d:|*(" F";" ")0:1_0:`gspc.txt c+/h*{$[~0.97<y%x;[c-:m:.1*c;h,:m%y;p,:y];#i:&~1.06>y%p;[c+:y*+/h i;h[i]:p[i]:0n]];y}/d

Solution 2:

x:|1_*(" F";" ")0:`gspc.txt f:{$[y;[b[z]+:(.1*x)%z;.9*x];[z*:+/b p@:&~z<1.06*p:!b;b::p_b;x+z]]} g:{b!:b::0#0.0;(last[x]*+/b)+f/[1e4;~.97<%':x;x]} g x

No time estimates were given, but i'd expect something in the 10-30 minute range.]