Dominoes: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Added extra credit.) |
(→Extra credit: Added embedded version.) |
||
Line 790: | Line 790: | ||
Took 0.217176 seconds. |
Took 0.217176 seconds. |
||
</pre> |
</pre> |
||
===Extra credit=== |
===Extra credit (Cli)=== |
||
{{libheader|Wren-big}} |
{{libheader|Wren-big}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
Line 829: | Line 829: | ||
Took 0.00046 seconds. |
Took 0.00046 seconds. |
||
</pre> |
|||
===Extra credit (Embedded)=== |
|||
{{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. |
|||
<lang ecmascript>import "./gmp" for Mpz, Mpf |
|||
import "./fmt" for Fmt |
|||
var dominoTilingCount = Fn.new { |m, n| |
|||
var prec = 128 |
|||
var prod = Mpf.from(1, prec) |
|||
for (j in 1..(m/2).ceil) { |
|||
for (k in 1..(n/2).ceil) { |
|||
var cm = Mpf.pi(prec).mul(Mpf.from(j / (m + 1))).cos.square |
|||
var cn = Mpf.pi(prec).mul(Mpf.from(k / (n + 1))).cos.square |
|||
prod.mul(cm.add(cn).mul(4)) |
|||
} |
|||
} |
|||
return Mpz.from(prod.floor) |
|||
} |
|||
var start = System.clock |
|||
var arrang = dominoTilingCount.call(7, 8) |
|||
var perms = Mpz.new().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.00058 seconds. |
|||
</pre> |
</pre> |