Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Price-fraction/D/price-fraction.d
Normal file
19
Task/Price-fraction/D/price-fraction.d
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import std.stdio, std.range;
|
||||
|
||||
double priceRounder(in double price) pure nothrow
|
||||
in {
|
||||
assert(price >= 0 && price <= 1.0);
|
||||
} body {
|
||||
static immutable cin = [.06, .11, .16, .21, .26, .31, .36, .41,
|
||||
.46, .51, .56, .61, .66, .71, .76, .81,
|
||||
.86, .91, .96, 1.01],
|
||||
cout = [.10, .18, .26, .32, .38, .44, .50, .54,
|
||||
.58, .62, .66, .70, .74, .78, .82, .86,
|
||||
.90, .94, .98, 1.00];
|
||||
return cout[cin.assumeSorted.lowerBound(price).length];
|
||||
}
|
||||
|
||||
void main() {
|
||||
foreach (const price; [0.7388727, 0.8593103, 0.826687, 0.3444635])
|
||||
price.priceRounder.writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue