How to resolve the algorithm Non-transitive dice step by step in the Mathematica/Wolfram Language programming language
How to resolve the algorithm Non-transitive dice step by step in the Mathematica/Wolfram Language programming language
Table of Contents
Problem Statement
Let our dice select numbers on their faces with equal probability, i.e. fair dice. Dice may have more or less than six faces. (The possibility of there being a 3D physical shape that has that many "faces" that allow them to be fair dice, is ignored for this task - a die with 3 or 33 defined sides is defined by the number of faces and the numbers on each face). Throwing dice will randomly select a face on each die with equal probability. To show which die of dice thrown multiple times is more likely to win over the others:
If two dice X and Y are thrown against each other then X likely to: win, lose, or break-even against Y can be shown as: X > Y, X < Y, or X = Y respectively.
If X is the three sided die with 1, 3, 6 on its faces and Y has 2, 3, 4 on its faces then the equal possibility outcomes from throwing both, and the winners is: Both die will have the same statistical probability of winning, i.e.their comparison can be written as X = Y In mathematics transitivity are rules like: If, for example, the op, (for operator), is the familiar less than, <, and it's applied to integers we get the familiar if a < b and b < c then a < c These are an ordered list of dice where the '>' operation between successive dice pairs applies but a comparison between the first and last of the list yields the opposite result, '<'. (Similarly '<' successive list comparisons with a final '>' between first and last is also non-transitive).
Three dice S, T, U with appropriate face values could satisfy To be non-transitive.
Find all the ordered lists of three non-transitive dice S, T, U of the form S < T, T < U and yet S > U; where the dice are selected from all four-faced die , (unique w.r.t the notes), possible by having selections from the integers one to four on any dies face. Solution can be found by generating all possble individual die then testing all possible permutations, (permutations are ordered), of three dice for non-transitivity. Find lists of four non-transitive dice selected from the same possible dice from the non-stretch goal.
Show the results here, on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Non-transitive dice step by step in the Mathematica/Wolfram Language programming language
This code is written in Wolfram Language, and it's a program that generates non-transitive dice sets.
A non-transitive dice set is a set of dice that has the property that there is no die in the set that always wins against all the other dice in the set.
The program starts by defining a function called DieFight
that takes two lists of dice as input, and returns 1 if the first list of dice wins against the second list of dice, -1 if the second list of dice wins against the first list of dice, and 0 if the two lists of dice tie.
The program then generates a list of all possible sets of 4 dice, and calculates the outcome of every possible pair of dice in each set.
The program then selects the sets of dice that have the property that there is no die in the set that always wins against all the other dice in the set.
Finally, the program prints out the non-transitive dice sets that it has found.
Here is a step-by-step explanation of the code:
- The first line of the code clears all previously defined symbols.
- The second line defines the
DieFight
function. The function takes two lists of dice as input, and returns 1 if the first list of dice wins against the second list of dice, -1 if the second list of dice wins against the first list of dice, and 0 if the two lists of dice tie. - The third line of the code generates a list of all possible sets of 4 dice.
- The fourth line of the code calculates the outcome of every possible pair of dice in each set.
- The fifth line of the code selects the sets of dice that have the property that there is no die in the set that always wins against all the other dice in the set.
- The sixth line of the code prints out the non-transitive dice sets that it has found.
Source code in the wolfram programming language
ClearAll[DieFight]
DieFight[d1_List, d2_List] := Module[{sets},
sets = Tuples[{d1, d2}];
sets = sets[[All, 2]] - sets[[All, 1]];
Sign[Total[Sign[sets]]]
]
ds = DeleteDuplicates[Sort /@ Tuples[Range[4], 4]];
ssis = Subsets[Range[Length[ds]], {3}];
ssis //= Map[Permutations];
ssis //= Catenate;
ssis //= Select[DieFight[ds[[#[[1]]]], ds[[#[[2]]]]] == 1 &];
ssis //= Select[DieFight[ds[[#[[2]]]], ds[[#[[3]]]]] == 1 &];
ssis //= Select[DieFight[ds[[#[[1]]]], ds[[#[[3]]]]] == -1 &];
nontransitiveds = Map[ds[[#]] &, ssis, {2}];
Column[Row[{#1, "<", #2, " ; ", #2, "<", #3, " ; ", #1, ">", #3}] & @@@ nontransitiveds]
ssis = Subsets[Range[Length[ds]], {4}];
ssis //= Map[Permutations];
ssis //= Catenate;
ssis //= Select[DieFight[ds[[#[[1]]]], ds[[#[[2]]]]] == 1 &];
ssis //= Select[DieFight[ds[[#[[2]]]], ds[[#[[3]]]]] == 1 &];
ssis //= Select[DieFight[ds[[#[[3]]]], ds[[#[[4]]]]] == 1 &];
ssis //= Select[DieFight[ds[[#[[1]]]], ds[[#[[4]]]]] == -1 &];
nontransitiveds = Map[ds[[#]] &, ssis, {2}];
Column[Row[{#1, "<", #2, " ; ", #2, "<", #3, " ; ", #3, "<", #4, " ; ", #1, ">", #4}] & @@@ nontransitiveds]
You may also check:How to resolve the algorithm Square-free integers step by step in the Arturo programming language
You may also check:How to resolve the algorithm Named parameters step by step in the Elixir programming language
You may also check:How to resolve the algorithm Percolation/Bond percolation step by step in the Python programming language
You may also check:How to resolve the algorithm Non-continuous subsequences step by step in the C programming language
You may also check:How to resolve the algorithm Assertions step by step in the GAP programming language