RosettaCodeData/Task/Price-fraction/Maple/price-fraction.maple
2023-07-01 13:44:08 -04:00

18 lines
604 B
Text

priceFraction := proc(price)
local values, standard, newPrice, i;
values := [0, 0.06, 0.11, 0.16, 0.21, 0.26, 0.31, 0.36, 0.41, 0.46, 0.51, 0.56, 0.61,
0.66, 0.71, 0.76, 0.81, 0.86, 0.91, 0.96, 1.01];
standard := [0.10, 0.18, 0.26, 0.32, 0.38, 0.44, 0.50, 0.54, 0.58, 0.62, 0.66, 0.70,
0.74, 0.78, 0.82, 0.86, 0.90, 0.94, 0.98, 1.00];
for i to numelems(standard) do
if price >= values[i] and price < values[i+1] then
newPrice := standard[i];
end if;
end do;
printf("%f --> %.2f\n", price, newPrice);
end proc:
randomize():
for i to 5 do
priceFraction (rand(0.0..1.0)());
end do;