Price list behind API: Difference between revisions

→‎{{header|Wren}}: Didn't satisfy the task requirements previously.
(Added Wren)
(→‎{{header|Wren}}: Didn't satisfy the task requirements previously.)
Line 171:
 
var rand = Random.new()
var minDelta = 1
 
var getMaxPrice = Fn.new { |prices| Nums.max(prices) }
Line 178 ⟶ 179:
var get5000 = Fn.new { |prices, min, max, n|
var count = getPrangeCount.call(prices, min, max)
var delta = ((max - min) / 2).floor
while (count != n && delta >= 0minDelta/2) {
max = ((count > n) ? max-delta : max+delta).floor
count = getPrangeCount.call(prices, min, max)
delta = (delta / 2).floor
}
return [max, count]
Line 201 ⟶ 202:
return res
}
var numPrices = 1e5rand.int(99000, 101001)
var maxPrice = 1e5
var prices = List.filled(numPrices, 0) // list of prices
Line 225 ⟶ 226:
Sample run:
<pre>
Using 10000099756 items with prices from 0 to 99998:
Split into 20 bins of approx 5000 elements:
From 0 to 50434964 with 5000 items
From 50444965 to 10102 9992 with 50015000 items
From 10103 9993 to 1519215063 with 5000 items
From 1519315064 to 2032020130 with 5000 items
From 2032120131 to 2536825063 with 4998 items
From 2536925064 to 3037630014 with 50034998 items
From 3037730015 to 3542235002 with 50015000 items
From 3542335003 to 4033740030 with 50015000 items
From 4033840031 to 4529945058 with 5000 items
From 4530045059 to 5038950199 with 50014999 items
From 5039050200 to 5540255133 with 49984999 items
From 5540355134 to 6038260139 with 50014997 items
From 6038360140 to 6533065097 with 49995000 items
From 6533165098 to 7027869972 with 50014999 items
From 7027969973 to 7528574932 with 49995000 items
From 7528674933 to 8033680041 with 5000 items
From 8033780042 to 8528985214 with 5000 items
From 8529085215 to 9029190241 with 50004999 items
From 9029290242 to 9505295353 with 50015000 items
From 9505395354 to 99998 with 49964767 items
</pre>
9,482

edits