Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Non-transitive-dice/Factor/non-transitive-dice.factor
Normal file
25
Task/Non-transitive-dice/Factor/non-transitive-dice.factor
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
USING: grouping io kernel math math.combinatorics math.ranges
|
||||
prettyprint sequences ;
|
||||
|
||||
: possible-dice ( n -- seq )
|
||||
[ [1,b] ] [ selections ] bi [ [ <= ] monotonic? ] filter ;
|
||||
|
||||
: cmp ( seq seq -- n ) [ - sgn ] cartesian-map concat sum ;
|
||||
|
||||
: non-transitive? ( seq -- ? )
|
||||
[ 2 clump [ first2 cmp neg? ] all? ]
|
||||
[ [ last ] [ first ] bi cmp neg? and ] bi ;
|
||||
|
||||
: find-non-transitive ( #sides #dice -- seq )
|
||||
[ possible-dice ] [ <k-permutations> ] bi*
|
||||
[ non-transitive? ] filter ;
|
||||
|
||||
! Task
|
||||
"Number of eligible 4-sided dice: " write
|
||||
4 possible-dice length . nl
|
||||
|
||||
"All ordered lists of 3 non-transitive dice with 4 sides:" print
|
||||
4 3 find-non-transitive . nl
|
||||
|
||||
"All ordered lists of 4 non-transitive dice with 4 sides:" print
|
||||
4 4 find-non-transitive .
|
||||
Loading…
Add table
Add a link
Reference in a new issue