Price list behind API: Difference between revisions

m
syntax highlighting fixup automation
(Added 11l)
m (syntax highlighting fixup automation)
Line 18:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V price_list_size = random:(99'000 .< 101'000)
V price_list = (0 .< price_list_size).map(i -> random:(100'000))
 
Line 57:
 
I price_list.len != sum(result.map((mn, mx, count) -> count))
print("\nWhoops! Some items missing:")</langsyntaxhighlight>
 
{{out}}
Line 87:
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 176:
fmt.Println("Something went wrong - grand total of", total, "doesn't equal", numPrices, "\b!")
}
}</langsyntaxhighlight>
 
{{out}}
Line 206:
=={{header|Julia}}==
{{trans|Python}}
<langsyntaxhighlight lang="julia"># Sample price generation
const price_list_size = rand(99000:100999)
const price_list = rand(0:99999, price_list_size)
Line 253:
 
testpricelist()
</langsyntaxhighlight>{{out}}
<pre>
Using 100299 random prices from 0 to 99990.
Line 282:
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import math, strformat
 
const MinDelta = 1.0
Line 340:
 
if total != numPrices:
echo &"Something went wrong: grand total of {total} doesn't equal {numPrices}!"</langsyntaxhighlight>
 
{{out}}
Line 368:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use List::Util <min max shuffle>;
Line 415:
$max = $actualMax if $max > $actualMax;
printf " From %6d to %6d with %4d items\n", $min, $max, $subtotal
}</langsyntaxhighlight>
{{out}}
<pre>Using 100047 items with prices from 0 to 10000:
Line 444:
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.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"0.8.3"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- [assert() now accepts a 3rd param]</span>
Line 492:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">price_list</span><span style="color: #0000FF;">)==</span><span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">vslice</span><span style="color: #0000FF;">(</span><span style="color: #000000;">result</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)),</span><span style="color: #008000;">"Whoops! Some items missing!"</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 521:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import random
 
#%%Sample price generation
Line 567:
 
if len(price_list) != sum(count for mn, mx, count in result):
print("\nWhoops! Some items missing:")</langsyntaxhighlight>
 
{{out}}
Line 595:
=={{header|Raku}}==
{{trans|Go}}
<syntaxhighlight lang="raku" perl6line># 20210208 Raku programming solution
 
my \minDelta = 1;
Line 641:
printf " From %6d to %6d with %4d items\n", $min, $max, $subtotal
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 673:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "random" for Random
import "/math" for Nums
import "/fmt" for Fmt
Line 729:
if (total != numPrices) {
System.print("Something went wrong - grand total of %(total) doesn't equal %(numPrices)!")
}</langsyntaxhighlight>
 
{{out}}
10,333

edits