Price list behind API: Difference between revisions

m
→‎{{header|Phix}}: corner case, decided prices deserve 2dp, even if always ".00"
(→‎{{header|Go}}: Fixed corner case.)
m (→‎{{header|Phix}}: corner case, decided prices deserve 2dp, even if always ".00")
Line 212:
=={{header|Phix}}==
{{trans|Python}}
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>
IfWere you defined(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]
<lang Phix>constant price_list_size = 99_000 + rand(2_001) - 1,
price_list = sq_sub(sq_rand(repeat(100_000,price_list_size)),1),
delta_price = 1 -- Minimum difference between any two different prices.
Line 246 ⟶ 247:
integer partmin = partmax + delta_price
{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})
end while
Line 255 ⟶ 257:
printf(1,"Splits into %d bins of approx 5000 elements\n",{length(result)})
for i=1 to length(result) do
printf(1," From %8.1f2f ... %8.1f2f with %d items.\n",result[i])
end for
if assert(length(price_list) != =sum(vslice(result,3)),"Whoops! thenSome items missing!")</lang>
printf(1,"\nWhoops! Some items missing:\n")
end if</lang>
{{out}}
<pre>
Using 99714100957 random prices from 0 to 99999
Splits into 2021 bins of approx 5000 elements
From 0.000 ... 49774838.000 with 50004998 items.
From 49784839.000 ... 100199765.000 with 4999 items.
From 100209766.000 ... 1511414602.000 with 4999 items.
From 1511514603.000 ... 1998719575.000 with 49985000 items.
From 1998819576.000 ... 2508824515.000 with 49964998 items.
From 2508924516.000 ... 3008029476.000 with 49955000 items.
From 3008129477.000 ... 3511734386.000 with 5000 items.
From 3511834387.000 ... 4008139289.000 with 4999 items.
From 4008239290.000 ... 4508044349.000 with 5000 items.
From 4508144350.000 ... 5018149265.000 with 50004992 items.
From 5018249266.000 ... 5522354262.000 with 50004998 items.
From 5522454263.000 ... 6027159289.000 with 50004999 items.
From 6027259290.000 ... 6510264191.000 with 49995000 items.
From 6510364192.000 ... 7014069119.000 with 50004999 items.
From 7014169120.000 ... 7519574095.000 with 49974996 items.
From 7519674096.000 ... 8020379144.000 with 49984999 items.
From 8020479145.000 ... 8521084093.000 with 49994998 items.
From 8521184094.000 ... 9018288961.000 with 50004996 items.
From 9018388962.000 ... 9526894051.000 with 4999 items.
From 9526994052.000 ... 10472299038.000 with 47365000 items.
From 99039.00 ... 100955.00 with 988 items.
</pre>
 
7,805

edits