Programming performance/JN K

From HaskellWiki
< Programming performance
Revision as of 18:08, 9 March 2007 by Jn (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Submission in K. Start to finish time: 17 minutes.
RaymondH showed me his, so this might not be entirely originial.
I tried not to look at any of the K solutions.

/ parse quotes
D:|1_*("    F  ";" ")0:`:gspc.txt

/ Cash and Portfolio (price -> quantity)
C:10000.00; P:(`u#0#0.)!0#0.

/ Trading strategy
T:{if[~.97<x%y; P[x]+:(b:C%10)%x; C-:b]; C+:x*+/P p:p@&~1.06>x%p:!P; P[p]:0.}

/ run strategy on each pair (current and previous) of prices
(*D)T':D;

/ Sell off remaining
C+:+/.:[P]**|D