Price fraction: Difference between revisions

Updated D entry
m (Added Raven code for Price fraction)
(Updated D entry)
Line 713:
 
=={{header|D}}==
<lang d>import std.stdio, std.range;
 
double priceRounder(in double price) pure nothrow
Line 719:
assert(price >= 0 && price <= 1.0);
} body {
enumstatic immutable cin = [.06, .11, .16, .21, .26, .31, .36, .41, .46, .51,
.56, .61, .6646, .7151, .7656, .8161, .8666, .9171, .9676, 1.01];81,
enum cout = [.10, .18, .26, .32, .38, .44, .5086, .5491, .5896, 1.6201],
.66, .70, cout = [.7410, .7818, .8226, .8632, .9038, .9444, .9850, 1.00];54,
.58, .62, .66, .70, .74, .78, .82, .86,
foreach (i, p; cin)
.90, .94, .98, 1.00];
if (p >= price)
return cout[icin.assumeSorted.lowerBound(price).length];
assert(0);
}
 
void main() {
foreach (const price; [0.7388727, 0.8593103, 0.826687, 0.3444635])
writeln(priceRounder(price)).priceRounder.writeln;
}</lang>
{{out}}