Talk:Seven-sided dice from five-sided dice: Difference between revisions

→‎J solution seems ugly: instructive version
(→‎J solution seems ugly: instructive version)
Line 10:
 
:You could use this <code>dice5</code> and either <code>dice7a</code> or <code>dice7b</code> for the main bit:
<lang j>dice5=: >:@:?@$&5 NB. [: >: ] ?@$ 5: might be easier to parse for tacit beginners?
dice7a=: 0 8 -.~ 3 >.@%~ 5 #. [: <:@dice5 2 ,~ ]
dice7b=: [: (#~ 7&>:) 3 >.@%~ [: 5&#.&.:<:@dice5 ] , 2: </lang>
Line 25:
</lang>
:...or you could create a tacit equivalent using the <code>^:</code> conjunction.--[[User:Tikkanz|Tikkanz]] 00:15, 14 September 2009 (UTC)
 
:Here is a more instructive version of the main bit of code:
<lang j>
dice5=: [: >: ] ?@$ 5: NB. makes a y shape array of 5s, "rolls" the array and increments.
rolltwice=: [: dice5 2 ,~ ] NB. rolls dice5 twice for each desired dice7 roll (y rows, 2 cols)
base5to10=: 5&#.@:<: NB. decrements and converts rows from base 5 to 10
keepgood=: #~ 21&> NB. compress out values not less than 21
groupsof3=: [: >. >: % 3: NB. increments, divides by 3 and takes ceiling
 
dice7c=: groupsof3@keepgood@base5to10@rolltwice
</lang>--[[User:Tikkanz|Tikkanz]] 01:20, 14 September 2009 (UTC)
892

edits