Horse racing: Difference between revisions

Content added Content deleted
No edit summary
m (syntax highlighting fixup automation)
Line 82: Line 82:
=={{header|Go}}==
=={{header|Go}}==
{{trans|Wren}}
{{trans|Wren}}
<lang go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 177: Line 177:
sec := t - float64(min)*60
sec := t - float64(min)*60
fmt.Printf("\nTime %d minute %3.1f seconds\n", min, sec)
fmt.Printf("\nTime %d minute %3.1f seconds\n", min, sec)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 200: Line 200:
=={{header|Julia}}==
=={{header|Julia}}==
{{trans|Go}}
{{trans|Go}}
<lang julia>function main()
<syntaxhighlight lang="julia">function main()
# ratings on past form, assuming a rating of 100 for horse A
# ratings on past form, assuming a rating of 100 for horse A
a = 100
a = 100
Line 262: Line 262:


main()
main()
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Race 4
Race 4
Line 283: Line 283:
=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Wren}}
{{trans|Wren}}
<lang Nim>import algorithm, math, strformat, strutils
<syntaxhighlight lang="nim">import algorithm, math, strformat, strutils


# Ratings on past form, assuming a rating of 100 for horse A.
# Ratings on past form, assuming a rating of 100 for horse A.
Line 341: Line 341:
var min = int(t / 60)
var min = int(t / 60)
var sec = t mod 60
var sec = t mod 60
echo &"\nTime {min} minute {sec:.1f} seconds"</lang>
echo &"\nTime {min} minute {sec:.1f} seconds"</syntaxhighlight>


{{out}}
{{out}}
Line 362: Line 362:
=={{header|Perl}}==
=={{header|Perl}}==
{{trans|Raku}}
{{trans|Raku}}
<lang perl>use strict;
<syntaxhighlight lang="perl">use strict;
use warnings;
use warnings;


Line 402: Line 402:
}
}


print for sort @predictions;</lang>
print for sort @predictions;</syntaxhighlight>
{{out}}
{{out}}
<pre> 1 i Iphigenia in Brooklyn 8.11 0.0 filly 1:35.4
<pre> 1 i Iphigenia in Brooklyn 8.11 0.0 filly 1:35.4
Line 418: Line 418:
Disclaimer: I know nothing about horse racing, all calculations were reverse-engineered from those in the Go entry.<br>
Disclaimer: I know nothing about horse racing, all calculations were reverse-engineered from those in the Go entry.<br>
Made table-based so you can plug in different races and adjustments, but any horse appearing in more than one race input would too in the output.
Made table-based so you can plug in different races and adjustments, but any horse appearing in more than one race input would too in the output.
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<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;">"1.0.1"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">// [else sort_columns() needs a deep_copy()]</span>
<span style="color: #7060A8;">requires</span> <span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.1"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">// [else sort_columns() needs a deep_copy()]</span>
Line 482: Line 482:
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">60</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">60</span><span style="color: #0000FF;">))</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nTime %s %s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nTime %s %s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">})</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
<pre>
<pre>
Line 504: Line 504:
=={{header|Raku}}==
=={{header|Raku}}==
I know nothing about horse racing and/or handicapping. This is mostly a straightforward translation of the logic from Go though I did take certain liberties with formatting and layout.
I know nothing about horse racing and/or handicapping. This is mostly a straightforward translation of the logic from Go though I did take certain liberties with formatting and layout.
<lang perl6>my %card;
<syntaxhighlight lang="raku" line>my %card;
%card<a> = { name => 'Alberta Clipper', :sex<M>, rating => 100 };
%card<a> = { name => 'Alberta Clipper', :sex<M>, rating => 100 };
%card<b> = { name => 'Beetlebaum', :sex<F>, rating => %card<a><rating> - 8 - 2*2 };
%card<b> = { name => 'Beetlebaum', :sex<F>, rating => %card<a><rating> - 8 - 2*2 };
Line 540: Line 540:
printf "%2d %s %-22s %.2f %.1f %-6s %s\n", $position, .key, .value<name>, .value<weight>,
printf "%2d %s %-22s %.2f %.1f %-6s %s\n", $position, .key, .value<name>, .value<weight>,
.value<back>, .value<sex> eq 'M' ?? 'colt' !! 'filly', .value.<time>.polymod(60 xx*).reverse.join: ':';
.value<back>, .value<sex> eq 'M' ?? 'colt' !! 'filly', .value.<time>.polymod(60 xx*).reverse.join: ':';
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Pos Horse Name Weight Back Sex Time
<pre>Pos Horse Name Weight Back Sex Time
Line 556: Line 556:
=={{header|Vlang}}==
=={{header|Vlang}}==
{{trans|go}}
{{trans|go}}
<lang vlang>struct Kv {
<syntaxhighlight lang="vlang">struct Kv {
key string
key string
value []f64
value []f64
Line 651: Line 651:
sec := t - f64(min)*60
sec := t - f64(min)*60
println("\nTime $min minute ${sec:3.1f} seconds")
println("\nTime $min minute ${sec:3.1f} seconds")
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>Same as go entry</pre>
<pre>Same as go entry</pre>
Line 657: Line 657:
=={{header|Wren}}==
=={{header|Wren}}==
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/fmt" for Fmt
<syntaxhighlight lang="ecmascript">import "/fmt" for Fmt


// ratings on past form, assuming a rating of 100 for horse A
// ratings on past form, assuming a rating of 100 for horse A
Line 721: Line 721:
var min = (t/60).floor
var min = (t/60).floor
var sec = t % 60
var sec = t % 60
System.print("\nTime %(min) minute %(sec) seconds")</lang>
System.print("\nTime %(min) minute %(sec) seconds")</syntaxhighlight>


{{out}}
{{out}}