Price fraction: Difference between revisions

added Ursala
(added ocaml)
(added Ursala)
Line 577:
.0491907 -> 0.10
</pre>
 
=={{header|Ursala}}==
<lang Ursala>#import flo
 
le = <0.06,.11,.16,.21,.26,.31,.36,.41,.46,.51,.56,.61,.66,.71,.76,.81,.86,.91,.96,1.01>
out = <0.10,.18,.26,.32,.38,.44,.50,.54,.58,.62,.66,.70,.74,.78,.82,.86,.90,.94,.98,1.>
 
price_fraction = fleq@rlPlX*|rhr\~&p(le,out)</lang>
main points:
* <code>~&p(le,out)</code> zips the pair of lists <code>le</code> and <code>out</code> into a list of pairs
* A function of the form <code>f\y</code> applied to an argument <code>x</code> evaluates to <code>f(x,y)</code>
* A function of the form <code>f*|</code> applied to a pair <code>(x,y)</code> where <code>y</code> is a list, makes a list of pairs with <code>x</code> on the left of each item and an item of <code>y</code> on the right. Then it applies <code>f</code> to each pair, makes a list of the right sides of those for which <code>f</code> returned true, and makes a separate list of the right sides of those for which <code>f</code> returned false.
* The suffix <code>rhr</code> after the <code>*|</code> operator extracts the right side of the head of the right list from the result.
* The operand to the <code>*|</code> operator, <code>fleq@rlPlX</code> is the less-or-equal predicate on floating point numbers, composed with the function <code>~&rlPlX</code> which transforms a triple <code>(u,(v,w))</code> to <code>(v,u)</code>
 
test program:
<lang Ursala>#cast %eL
 
test = price_fraction* <0.34,0.070145,0.06,0.05,0.50214,0.56,1.,0.99,0.>
</lang>
output:
<pre><
5.000000e-01,
1.800000e-01,
1.800000e-01,
1.000000e-01,
6.200000e-01,
7.000000e-01,
1.000000e+00,
1.000000e+00,
1.000000e-01></pre>
Anonymous user