Price list behind API: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Fixed corner case.) |
m (→{{header|Phix}}: corner case, decided prices deserve 2dp, even if always ".00") |
||
Line 212: | Line 212: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
Note that defaulted arguments of the form mx=get_max_price() are not currently supported, hence a slightly hacky workaround.<br> |
Note that defaulted arguments of the form mx=get_max_price() are not currently supported, hence a slightly hacky workaround, of -1 then -1==>get_max_price().<br> |
||
Were you (or I) to define constant mp = get_max_price(), then mx=mp style parameter defaulting would be fine. |
|||
<lang Phix>requires("0.8.3") -- [assert() now accepts a 3rd param] |
|||
constant price_list_size = 99_000 + rand(2_001) - 1, |
|||
price_list = sq_sub(sq_rand(repeat(100_000,price_list_size)),1), |
price_list = sq_sub(sq_rand(repeat(100_000,price_list_size)),1), |
||
delta_price = 1 -- Minimum difference between any two different prices. |
delta_price = 1 -- Minimum difference between any two different prices. |
||
Line 246: | Line 247: | ||
integer partmin = partmax + delta_price |
integer partmin = partmax + delta_price |
||
{partmax, partcount} = get_5k(partmin, mx, num) |
{partmax, partcount} = get_5k(partmin, mx, num) |
||
assert(partcount>0,"Price list from %.2f has too many same price",{partmin}) |
|||
result = append(result,{partmin, partmax, partcount}) |
result = append(result,{partmin, partmax, partcount}) |
||
end while |
end while |
||
Line 255: | Line 257: | ||
printf(1,"Splits into %d bins of approx 5000 elements\n",{length(result)}) |
printf(1,"Splits into %d bins of approx 5000 elements\n",{length(result)}) |
||
for i=1 to length(result) do |
for i=1 to length(result) do |
||
printf(1," From %8. |
printf(1," From %8.2f ... %8.2f with %d items.\n",result[i]) |
||
end for |
end for |
||
assert(length(price_list)==sum(vslice(result,3)),"Whoops! Some items missing!")</lang> |
|||
printf(1,"\nWhoops! Some items missing:\n") |
|||
end if</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Using |
Using 100957 random prices from 0 to 99999 |
||
Splits into |
Splits into 21 bins of approx 5000 elements |
||
From |
From 0.00 ... 4838.00 with 4998 items. |
||
From |
From 4839.00 ... 9765.00 with 4999 items. |
||
From |
From 9766.00 ... 14602.00 with 4999 items. |
||
From |
From 14603.00 ... 19575.00 with 5000 items. |
||
From |
From 19576.00 ... 24515.00 with 4998 items. |
||
From |
From 24516.00 ... 29476.00 with 5000 items. |
||
From |
From 29477.00 ... 34386.00 with 5000 items. |
||
From |
From 34387.00 ... 39289.00 with 4999 items. |
||
From |
From 39290.00 ... 44349.00 with 5000 items. |
||
From |
From 44350.00 ... 49265.00 with 4992 items. |
||
From |
From 49266.00 ... 54262.00 with 4998 items. |
||
From |
From 54263.00 ... 59289.00 with 4999 items. |
||
From |
From 59290.00 ... 64191.00 with 5000 items. |
||
From |
From 64192.00 ... 69119.00 with 4999 items. |
||
From |
From 69120.00 ... 74095.00 with 4996 items. |
||
From |
From 74096.00 ... 79144.00 with 4999 items. |
||
From |
From 79145.00 ... 84093.00 with 4998 items. |
||
From |
From 84094.00 ... 88961.00 with 4996 items. |
||
From |
From 88962.00 ... 94051.00 with 4999 items. |
||
From |
From 94052.00 ... 99038.00 with 5000 items. |
||
From 99039.00 ... 100955.00 with 988 items. |
|||
</pre> |
</pre> |
||