Talk:Seven-sided dice from five-sided dice: Difference between revisions
Content added Content deleted
(J suggestions) |
|||
Line 8: | Line 8: | ||
I'd really like someone knowledgeable to look and make J solution more elegant. This straightforward solution doesn't look very good. [[User:Avmich|Avmich]] 21:03, 13 September 2009 (UTC) |
I'd really like someone knowledgeable to look and make J solution more elegant. This straightforward solution doesn't look very good. [[User:Avmich|Avmich]] 21:03, 13 September 2009 (UTC) |
||
:You could use this <code>dice5</code> and either <code>dice7a</code> or <code>dice7b</code> for the main bit: |
|||
<lang j>dice5=: >:@:?@$&5 |
|||
dice7a=: 0 8 -.~ 3 >.@%~ 5 #. [: <:@dice5 2 ,~ ] |
|||
dice7b=: [: (#~ 7&>:) 3 >.@%~ [: 5&#.&.:<:@dice5 ] , 2: </lang> |
|||
:Then it's just a question on ensuring that you've got enough rolls. You could use the following explicit: |
|||
<lang j> |
|||
dice7=: monad define |
|||
res=. 0$0 |
|||
while. y > #res do. |
|||
res=. res, dice7a >. 0.75 * y |
|||
end. |
|||
y {. res |
|||
) |
|||
</lang> |
|||
:...or you could create a tacit equivalent using the <code>^:</code> conjunction.--[[User:Tikkanz|Tikkanz]] 00:15, 14 September 2009 (UTC) |