Price fraction: Difference between revisions
Content added Content deleted
m (fixed a typo.) |
(Added Maple implementation.) |
||
Line 1,692: | Line 1,692: | ||
Random value: 0.36528313938816 |
Random value: 0.36528313938816 |
||
Adjusted price: 0.54</pre> |
Adjusted price: 0.54</pre> |
||
=={{header|Maple}}== |
|||
<lang maple>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;</lang> |
|||
{{out}} |
|||
<pre>0.524386 --> 0.66 |
|||
0.887957 --> 0.94 |
|||
0.670196 --> 0.78 |
|||
0.875601 --> 0.94 |
|||
0.540447 --> 0.66</pre> |
|||
=={{header|Mathematica}}== |
=={{header|Mathematica}}== |