Dominoes: Difference between revisions

Content added Content deleted
(Added Wren)
(→‎{{header|Wren}}: Added extra credit.)
Line 615: Line 615:
=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Julia}}
{{trans|Julia}}
===Basic task===
<lang ecmascript>var tableau = [
<lang ecmascript>var tableau = [
[0, 5, 1, 3, 2, 2, 3, 1],
[0, 5, 1, 3, 2, 2, 3, 1],
Line 788: Line 789:
2025 layouts found (first one shown).
2025 layouts found (first one shown).
Took 0.217176 seconds.
Took 0.217176 seconds.
</pre>
===Extra credit===
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "./big" for BigInt
import "./fmt" for Fmt

var dominoTilingCount = Fn.new { |m, n|
var prod = 1
for (j in 1..(m/2).ceil) {
for (k in 1..(n/2).ceil) {
var cm = (Num.pi * (j / (m + 1))).cos
var cn = (Num.pi * (k / (n + 1))).cos
prod = prod * ((cm*cm + cn*cn) * 4)
}
}
return prod.floor
}

var start = System.clock
var arrang = dominoTilingCount.call(7, 8)
var perms = BigInt.factorial(28)
var flips = 2.pow(28)

Fmt.print("Arrangements ignoring values: $,i", arrang)
Fmt.print("Permutations of 28 dominos: $,i", perms)
Fmt.print("Permuted arrangements ignoring flipping dominos: $,i", perms * arrang)
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.")</lang>

{{out}}
<pre>
Arrangements ignoring values: 1,292,697
Permutations of 28 dominos: 304,888,344,611,713,860,501,504,000,000
Permuted arrangements ignoring flipping dominos: 394,128,248,414,528,672,328,712,716,288,000,000
Possible flip configurations: 268,435,456
Possible permuted arrangements with flips: 105,797,996,085,635,281,181,632,579,889,767,907,328,000,000

Took 0.00046 seconds.
</pre>
</pre>