Non-transitive dice: Difference between revisions
Content added Content deleted
(→{{header|Python}}: some cleanup; one bug fix to prevent sub loops in longer sequences that's not possible in examples required by task) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 87: | Line 87: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
< |
<syntaxhighlight lang="algol68"># iterates through all possible dice # |
||
PROC iterate = (PROC(INT, []INT)VOID f)VOID: |
PROC iterate = (PROC(INT, []INT)VOID f)VOID: |
||
BEGIN |
BEGIN |
||
Line 179: | Line 179: | ||
FI |
FI |
||
OD |
OD |
||
OD</ |
OD</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>3 dice: |
<pre>3 dice: |
||
Line 193: | Line 193: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
===The task (4 sided die)=== |
===The task (4 sided die)=== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Non-transitive dice. Nigel Galloway: August 9th., 2020 |
// Non-transitive dice. Nigel Galloway: August 9th., 2020 |
||
let die=[for n0 in [1..4] do for n1 in [n0..4] do for n2 in [n1..4] do for n3 in [n2..4]->[n0;n1;n2;n3]] |
let die=[for n0 in [1..4] do for n1 in [n0..4] do for n2 in [n1..4] do for n3 in [n2..4]->[n0;n1;n2;n3]] |
||
Line 200: | Line 200: | ||
let n4=seq{for d1 in die do for d2 in N.[d1] do for d3 in N.[d2] do for d4 in N.[d3] do if List.contains d1 N.[d4] then yield (d1,d2,d3,d4)} |
let n4=seq{for d1 in die do for d2 in N.[d1] do for d3 in N.[d2] do for d4 in N.[d3] do if List.contains d1 N.[d4] then yield (d1,d2,d3,d4)} |
||
n3|>Seq.iter(fun(d1,d2,d3)->printfn "%A<%A; %A<%A; %A>%A\n" d1 d2 d2 d3 d1 d3) |
n3|>Seq.iter(fun(d1,d2,d3)->printfn "%A<%A; %A<%A; %A>%A\n" d1 d2 d2 d3 d1 d3) |
||
n4|>Seq.iter(fun(d1,d2,d3,d4)->printfn "%A<%A; %A<%A; %A<%A; %A>%A" d1 d2 d2 d3 d3 d4 d1 d4)</ |
n4|>Seq.iter(fun(d1,d2,d3,d4)->printfn "%A<%A; %A<%A; %A<%A; %A>%A" d1 d2 d2 d3 d3 d4 d1 d4)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 216: | Line 216: | ||
===Extra credit (6 sided die)=== |
===Extra credit (6 sided die)=== |
||
;Sides numbered 1..6 |
;Sides numbered 1..6 |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Non-transitive diceNigel Galloway: August 9th., 2020 |
// Non-transitive diceNigel Galloway: August 9th., 2020 |
||
let die=[for n0 in [1..6] do for n1 in [n0..6] do for n2 in [n1..6] do for n3 in [n2..6] do for n4 in [n3..6] do for n5 in [n4..6]->[n0;n1;n2;n3;n4;n5]] |
let die=[for n0 in [1..6] do for n1 in [n0..6] do for n2 in [n1..6] do for n3 in [n2..6] do for n4 in [n3..6] do for n5 in [n4..6]->[n0;n1;n2;n3;n4;n5]] |
||
Line 222: | Line 222: | ||
let n3=[for d1 in die do for d2 in N.[d1] do for d3 in N.[d2] do if List.contains d1 N.[d3] then yield (d1,d2,d3)] |
let n3=[for d1 in die do for d2 in N.[d1] do for d3 in N.[d2] do if List.contains d1 N.[d3] then yield (d1,d2,d3)] |
||
let d1,d2,d3=List.last n3 in printfn "Solutions found = %d\nLast solution found is %A<%A; %A<%A; %A>%A" (n3.Length) d1 d2 d2 d3 d1 d3 |
let d1,d2,d3=List.last n3 in printfn "Solutions found = %d\nLast solution found is %A<%A; %A<%A; %A>%A" (n3.Length) d1 d2 d2 d3 d1 d3 |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 230: | Line 230: | ||
</pre> |
</pre> |
||
;Sides numbered 1..7 |
;Sides numbered 1..7 |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Non-transitive diceNigel Galloway: August 9th., 2020 |
// Non-transitive diceNigel Galloway: August 9th., 2020 |
||
let die=[for n0 in [1..7] do for n1 in [n0..7] do for n2 in [n1..7] do for n3 in [n2..7] do for n4 in [n3..7] do for n5 in [n4..7]->[n0;n1;n2;n3;n4;n5]] |
let die=[for n0 in [1..7] do for n1 in [n0..7] do for n2 in [n1..7] do for n3 in [n2..7] do for n4 in [n3..7] do for n5 in [n4..7]->[n0;n1;n2;n3;n4;n5]] |
||
Line 236: | Line 236: | ||
let n3=[for d1 in die do for d2 in N.[d1] do for d3 in N.[d2] do if List.contains d1 N.[d3] then yield (d1,d2,d3)] |
let n3=[for d1 in die do for d2 in N.[d1] do for d3 in N.[d2] do if List.contains d1 N.[d3] then yield (d1,d2,d3)] |
||
let d1,d2,d3=List.last n3 in printfn "Solutions found = %d\nLast solution found is %A<%A; %A<%A; %A>%A" (n3.Length) d1 d2 d2 d3 d1 d3 |
let d1,d2,d3=List.last n3 in printfn "Solutions found = %d\nLast solution found is %A<%A; %A<%A; %A>%A" (n3.Length) d1 d2 d2 d3 d1 d3 |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 245: | Line 245: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: grouping io kernel math math.combinatorics math.ranges |
||
prettyprint sequences ; |
prettyprint sequences ; |
||
Line 269: | Line 269: | ||
"All ordered lists of 4 non-transitive dice with 4 sides:" print |
"All ordered lists of 4 non-transitive dice with 4 sides:" print |
||
4 4 find-non-transitive .</ |
4 4 find-non-transitive .</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 292: | Line 292: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 399: | Line 399: | ||
fmt.Println(a) |
fmt.Println(a) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 419: | Line 419: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">{-# language LambdaCase #-} |
||
import Data.List |
import Data.List |
||
import Control.Monad |
import Control.Monad |
||
Line 445: | Line 445: | ||
(a:as) <- go (n-1) |
(a:as) <- go (n-1) |
||
b <- filter (< a) dice |
b <- filter (< a) dice |
||
return (b:a:as)</ |
return (b:a:as)</syntaxhighlight> |
||
<pre>*Main> mapM_ print $ nonTrans (dices 4) 3 |
<pre>*Main> mapM_ print $ nonTrans (dices 4) 3 |
||
Line 467: | Line 467: | ||
Implementation (rotations of results here are also solutions): |
Implementation (rotations of results here are also solutions): |
||
< |
<syntaxhighlight lang="j">NB. unique list of all y faced dice |
||
udice=: {{ 1+~./:~"1 (#: ,@i.)y#y }} |
udice=: {{ 1+~./:~"1 (#: ,@i.)y#y }} |
||
Line 481: | Line 481: | ||
r=. ; extend^:(x-1)&.> i.#ud |
r=. ; extend^:(x-1)&.> i.#ud |
||
ud{~ ~.((i.<./)|.])"1 r #~ lt{~({:,&.>{.)|:r |
ud{~ ~.((i.<./)|.])"1 r #~ lt{~({:,&.>{.)|:r |
||
}}</ |
}}</syntaxhighlight> |
||
Here, <tt>extend</tt> takes a list of die sequences and appends each possibility of a new die where the new die is not less than the last die in the sequence. So, <tt>r</tt> is all such lists of length x. We discard the cases where the last element of the list is not less than the first, rotate each dice index list into canonical order, discard duplicates, and then use these indices to select the associated dice. |
Here, <tt>extend</tt> takes a list of die sequences and appends each possibility of a new die where the new die is not less than the last die in the sequence. So, <tt>r</tt> is all such lists of length x. We discard the cases where the last element of the list is not less than the first, rotate each dice index list into canonical order, discard duplicates, and then use these indices to select the associated dice. |
||
Line 487: | Line 487: | ||
Task examples: |
Task examples: |
||
< |
<syntaxhighlight lang="j"> 3 cycles 4 |
||
1 1 4 4 |
1 1 4 4 |
||
2 2 2 4 |
2 2 2 4 |
||
Line 495: | Line 495: | ||
2 2 2 4 |
2 2 2 4 |
||
2 2 3 3 |
2 2 3 3 |
||
1 3 3 3</ |
1 3 3 3</syntaxhighlight> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="java">import java.util.ArrayList; |
||
import java.util.HashSet; |
import java.util.HashSet; |
||
import java.util.List; |
import java.util.List; |
||
Line 604: | Line 604: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Number of eligible 4-faced dice: 35 |
<pre>Number of eligible 4-faced dice: 35 |
||
Line 621: | Line 621: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="julia">import Base.>, Base.< |
||
using Memoize, Combinatorics |
using Memoize, Combinatorics |
||
Line 697: | Line 697: | ||
@time testnontransitivedice(5) |
@time testnontransitivedice(5) |
||
@time testnontransitivedice(6) |
@time testnontransitivedice(6) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
All possible 1..3 3-sided dice |
All possible 1..3 3-sided dice |
||
Line 779: | Line 779: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="scala">fun fourFaceCombos(): List<Array<Int>> { |
||
val res = mutableListOf<Array<Int>>() |
val res = mutableListOf<Array<Int>>() |
||
val found = mutableSetOf<Int>() |
val found = mutableSetOf<Int>() |
||
Line 880: | Line 880: | ||
println(a.joinToString(", ", "[", "]") { it.joinToString(", ", "[", "]") }) |
println(a.joinToString(", ", "[", "]") { it.joinToString(", ", "[", "]") }) |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Number of eligible 4-faced dice: 35 |
<pre>Number of eligible 4-faced dice: 35 |
||
Line 896: | Line 896: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[DieFight] |
||
DieFight[d1_List, d2_List] := Module[{sets}, |
DieFight[d1_List, d2_List] := Module[{sets}, |
||
sets = Tuples[{d1, d2}]; |
sets = Tuples[{d1, d2}]; |
||
Line 924: | Line 924: | ||
nontransitiveds = Map[ds[[#]] &, ssis, {2}]; |
nontransitiveds = Map[ds[[#]] &, ssis, {2}]; |
||
Column[Row[{#1, "<", #2, " ; ", #2, "<", #3, " ; ", #3, "<", #4, " ; ", #1, ">", #4}] & @@@ nontransitiveds]</ |
Column[Row[{#1, "<", #2, " ; ", #2, "<", #3, " ; ", #3, "<", #4, " ; ", #1, ">", #4}] & @@@ nontransitiveds]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{1,1,4,4}<{2,2,2,4} ; {2,2,2,4}<{1,3,3,3} ; {1,1,4,4}>{1,3,3,3} |
<pre>{1,1,4,4}<{2,2,2,4} ; {2,2,2,4}<{1,3,3,3} ; {1,1,4,4}>{1,3,3,3} |
||
Line 937: | Line 937: | ||
=={{header|MiniZinc}}== |
=={{header|MiniZinc}}== |
||
===The model=== |
===The model=== |
||
<syntaxhighlight lang="minizinc"> |
|||
<lang MiniZinc> |
|||
%Non transitive dice. Nigel Galloway, September 14th., 2020 |
%Non transitive dice. Nigel Galloway, September 14th., 2020 |
||
int: die; int: faces; set of int: values; |
int: die; int: faces; set of int: values; |
||
Line 947: | Line 947: | ||
constraint pN(g[die,1..faces],g[1,1..faces]); |
constraint pN(g[die,1..faces],g[1,1..faces]); |
||
output[join(" ",[show(g[n,1..faces])++"<"++show(g[n+1,1..faces]) | n in 1..die-1])," "++show(g[die,1..faces])++">"++show(g[1,1..faces])]; |
output[join(" ",[show(g[n,1..faces])++"<"++show(g[n+1,1..faces]) | n in 1..die-1])," "++show(g[die,1..faces])++">"++show(g[1,1..faces])]; |
||
</syntaxhighlight> |
|||
</lang> |
|||
===The task(4 sided die)=== |
===The task(4 sided die)=== |
||
;3 die values=1..4 |
;3 die values=1..4 |
||
Line 1,205: | Line 1,205: | ||
{{trans|Python}} |
{{trans|Python}} |
||
{{libheader|itertools}} |
{{libheader|itertools}} |
||
<syntaxhighlight lang="nim"> |
|||
<lang Nim> |
|||
import algorithm, sequtils, sets, strformat |
import algorithm, sequtils, sets, strformat |
||
import itertools |
import itertools |
||
Line 1,337: | Line 1,337: | ||
echo &"\n More verbose comparison of last non-transitive result:" |
echo &"\n More verbose comparison of last non-transitive result:" |
||
echo " ", verboseDiceCmp(nonTrans[^1]) |
echo " ", verboseDiceCmp(nonTrans[^1]) |
||
echo "\n ===="</ |
echo "\n ===="</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,393: | Line 1,393: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
Line 1,542: | Line 1,542: | ||
} |
} |
||
main();</ |
main();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Number of eligible 4-faced dice: 35 |
<pre>Number of eligible 4-faced dice: 35 |
||
Line 1,558: | Line 1,558: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<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;">"0.8.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (added sq_cmp() builtin that returns nested -1/0/+1 compare() results, just like the existing sq_eq() does for equal().)</span> |
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"0.8.2"</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (added sq_cmp() builtin that returns nested -1/0/+1 compare() results, just like the existing sq_eq() does for equal().)</span> |
||
Line 1,778: | Line 1,778: | ||
<span style="color: #000000;">show_dice</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">find_non_trans</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> |
<span style="color: #000000;">show_dice</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">find_non_trans</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #000000;">0</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;">"%s\n\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;">t0</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;">"%s\n\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;">t0</span><span style="color: #0000FF;">))</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,852: | Line 1,852: | ||
With the recent optimisations I can just about stretch to power(924,3), but I think I was right to skip power(924,4) above, it would probably take over two and a half ''days''.<br> |
With the recent optimisations I can just about stretch to power(924,3), but I think I was right to skip power(924,4) above, it would probably take over two and a half ''days''.<br> |
||
I have also estimated that power(3003,3) (ie 1..9 on the sides) would probably take around 4 hours (assuming such attempts didn't run out of memory). |
I have also estimated that power(3003,3) (ie 1..9 on the sides) would probably take around 4 hours (assuming such attempts didn't run out of memory). |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #000000;">t0</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> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span> |
||
<span style="color: #000000;">mx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">6</span> |
<span style="color: #000000;">mx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">6</span> |
||
Line 1,866: | Line 1,866: | ||
<span style="color: #000000;">show_dice</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">find_non_trans</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span> |
<span style="color: #000000;">show_dice</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">find_non_trans</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dice</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span><span style="color: #000000;">3</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;">"%s\n\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;">t0</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;">"%s\n\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;">t0</span><span style="color: #0000FF;">))</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,929: | Line 1,929: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
Trivial rotations of the same loop are not shown. |
Trivial rotations of the same loop are not shown. |
||
< |
<syntaxhighlight lang="python">from itertools import combinations_with_replacement as cmbr |
||
from time import time |
from time import time |
||
Line 1,960: | Line 1,960: | ||
print(f'\t{i + 1}*{loop_len} solutions, e.g. {" > ".join(x)} > [loop]') |
print(f'\t{i + 1}*{loop_len} solutions, e.g. {" > ".join(x)} > [loop]') |
||
t, t0 = time(), t |
t, t0 = time(), t |
||
print(f'\ttime: {t - t0:.4f} seconds\n')</ |
print(f'\ttime: {t - t0:.4f} seconds\n')</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>4-sided, markings 1234, loop length 3: |
<pre>4-sided, markings 1234, loop length 3: |
||
Line 1,979: | Line 1,979: | ||
===Alternative=== |
===Alternative=== |
||
< |
<syntaxhighlight lang="python">from collections import namedtuple |
||
from itertools import permutations, product |
from itertools import permutations, product |
||
from functools import lru_cache |
from functools import lru_cache |
||
Line 2,053: | Line 2,053: | ||
print('\n More verbose comparison of last non_transitive result:') |
print('\n More verbose comparison of last non_transitive result:') |
||
print(' ', verbose_dice_cmp(non_trans[-1])) |
print(' ', verbose_dice_cmp(non_trans[-1])) |
||
print('\n ====')</ |
print('\n ====')</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,114: | Line 2,114: | ||
=={{header|R}}== |
=={{header|R}}== |
||
It would not be difficult to adapt this code to meet the stretch goal, but readability would suffer. |
It would not be difficult to adapt this code to meet the stretch goal, but readability would suffer. |
||
< |
<syntaxhighlight lang="rsplus">findNonTrans <- function() |
||
{ |
{ |
||
diceSet <- unique(t(apply(expand.grid(1:4, 1:4, 1:4, 1:4), 1, sort))) #By construction, each row is a unique dice. |
diceSet <- unique(t(apply(expand.grid(1:4, 1:4, 1:4, 1:4), 1, sort))) #By construction, each row is a unique dice. |
||
Line 2,149: | Line 2,149: | ||
} |
} |
||
} |
} |
||
findNonTrans()</ |
findNonTrans()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,171: | Line 2,171: | ||
Thanks to Thundergnat for the nice "less-is-more" tweaks now the 4 dice portion takes around 10 (down from 17 ) minutes to run .. |
Thanks to Thundergnat for the nice "less-is-more" tweaks now the 4 dice portion takes around 10 (down from 17 ) minutes to run .. |
||
{{trans|Go}} |
{{trans|Go}} |
||
<lang |
<syntaxhighlight lang="raku" line># 20201225 Raku programming solution |
||
my @dicepool = ^4 xx 4 ; |
my @dicepool = ^4 xx 4 ; |
||
Line 2,206: | Line 2,206: | ||
say +@output, " ordered lists of $_ non-transitive dice found, namely:"; |
say +@output, " ordered lists of $_ non-transitive dice found, namely:"; |
||
.say for @output; |
.say for @output; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Number of eligible 4-faced dice : 35 |
<pre>Number of eligible 4-faced dice : 35 |
||
Line 2,221: | Line 2,221: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-sort}} |
{{libheader|Wren-sort}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/sort" for Sort |
||
var fourFaceCombs = Fn.new { |
var fourFaceCombs = Fn.new { |
||
Line 2,311: | Line 2,311: | ||
it = findIntransitive4.call(combs) |
it = findIntransitive4.call(combs) |
||
System.print("\n%(it.count) ordered lists of 4 non-transitive dice found, namely:") |
System.print("\n%(it.count) ordered lists of 4 non-transitive dice found, namely:") |
||
System.print(it.join("\n"))</ |
System.print(it.join("\n"))</syntaxhighlight> |
||
{{out}} |
{{out}} |