Jump to content

Dominoes: Difference between revisions

m
syntax highlighting fixup automation
m (Promote to full task)
m (syntax highlighting fixup automation)
Line 21:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Dominoes: Nigel Galloway. November 17th., 2021.
let cP (n:seq<uint64 list * uint64>) g=seq{for y,n in n do for g in g do let l=n^^^g in if n+g=l then yield (g::y,l)}
Line 36:
2;1;4;3;3;4;6;6;
6;4;5;1;5;4;1;4|]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 53:
6 4+5 1+5 4 1+4
</pre>
<langsyntaxhighlight lang="fsharp">
solve [|5;6;2;0;0;4;1;4;
3;6;1;3;0;4;2;2;
Line 61:
4;4;1;3;6;6;0;2;
1;2;6;2;6;5;0;4|]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 80:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">const tableau = [
0 5 1 3 2 2 3 1;
0 5 5 0 5 2 4 6;
Line 166:
printlayout(first(lays))
println(length(lays), " layouts found.")
</langsyntaxhighlight>{{out}}
<pre>
0+5 1+3 2 2+3 1
Line 202:
</pre>
===Extra credit task ===
<langsyntaxhighlight lang="julia">""" From https://en.wikipedia.org/wiki/Domino_tiling#Counting_tilings_of_regions
The number of ways to cover an m X n rectangle with m * n / 2 dominoes, calculated
independently by Temperley & Fisher (1961) and Kasteleyn (1961), is given by
Line 228:
println("Possible flip configurations: $flips")
println("Possible permuted arrangements with flips: ", flips * arrang * perms)
</langsyntaxhighlight>{{out}}
<pre>
Arrangements ignoring values: 1292697
Line 238:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[VisualizeState]
VisualizeState[sol_List, tab_List] := Module[{rects},
rects = Apply[Rectangle[#1 - {1, 1} 0.5, #2 + {1, 1} 0.5] &, sol[[All, 2]], {1}];
Line 289:
sols = FindSolutions[tab];
Length[sols]
VisualizeState[sols[[1]], tab]</langsyntaxhighlight>
{{out}}
<pre>1
Line 297:
 
===Extra credit task ===
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[DominoTilingCount]
DominoTilingCount[m_, n_] := Module[{},
Round[Product[
Line 312:
Print["Permuted arrangements ignoring flipping dominos: ", arrangements*permutations]
Print["Possible flip configurations: ", flips]
Print["Possible permuted arrangements with flips: ", flips*arrangements*permutations]</langsyntaxhighlight>
{{out}}
<pre>Arrangements ignoring values: 1292697
Line 321:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Dominoes
Line 385:
find( $x + 1, $y, $new );
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 423:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 579:
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #000000;">unpack</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"05132231 05505246 43036620 06235126 11300245 21433466 64515414"</span><span style="color: #0000FF;">))</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rand_grid</span><span style="color: #0000FF;">())</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 638:
===Extra credit===
Pretty dumb brute force approach, dreadfully slow.
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- too slow</span>
<span style="color: #008080;">enum</span> <span style="color: #000000;">IGNORE</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">CONSIDER</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">NOSYM</span>
Line 688:
<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;">"Arrangements ignoring symmetry: %g\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">count</span><span style="color: #0000FF;">(</span><span style="color: #000000;">NOSYM</span><span style="color: #0000FF;">))</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 697:
=== Much faster ===
{{trans|Wren}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 727:
<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;">"Possible permuted arrangements with flips: %s\n"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">mpz_get_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">perms</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #004600;">true</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;">"Took %s\n"</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">start</span><span style="color: #0000FF;">))</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 741:
{{trans|Julia}}
===Basic task===
<langsyntaxhighlight lang="ecmascript">var tableau = [
[0, 5, 1, 3, 2, 2, 3, 1],
[0, 5, 5, 0, 5, 2, 4, 6],
Line 877:
System.print("%(lays.count) layout%(pl) found%(fo).")
System.print("Took %(System.clock - start) seconds.\n")
}</langsyntaxhighlight>
 
{{out}}
Line 918:
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "./big" for BigInt
import "./fmt" for Fmt
 
Line 943:
Fmt.print("Possible flip configurations: $,i", flips)
Fmt.print("Possible permuted arrangements with flips: $,i", perms * flips * arrang)
System.print("\nTook %(System.clock - start) seconds.")</langsyntaxhighlight>
 
{{out}}
Line 958:
{{libheader|Wren-gmp}}
This is just to give what will probably be a rare outing to the Mpf class though (despite their usage in the Julia example) we don't need 'big floats' here, just 'big ints'. Slightly slower than the Wren-cli example as a result.
<langsyntaxhighlight lang="ecmascript">import "./gmp" for Mpz, Mpf
import "./fmt" for Fmt
 
Line 984:
Fmt.print("Possible flip configurations: $,i", flips)
Fmt.print("Possible permuted arrangements with flips: $,i", perms * flips * arrang)
System.print("\nTook %(System.clock - start) seconds.")</langsyntaxhighlight>
 
{{out}}
10,327

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.