Personally, I have been baffled by a number of the choices and requirements
here. And, by this, I mean that I do not understand them.
That said, here is my current interpretation of a mix of some of the
statements expressed here, about what is being accomplished:
faces=: {&' o'@((i.3 3)e.&":"1])&.>4 80 840 8620 86420 865320
toss=: (] {~ (?@$ #)) ".bind 'faces'
Example use, with ascii box drawing enabled:
toss 2 10
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|o |o |o o|o |o |o |o |o o|o o|o o|
| o | o | o | o | o | | | | o |o o|
| o| o|o o| o| o| o| o|o o|o o|o o|
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|o |o o|o |o o|o o|o |o |o |o o|o |
| o | o | | o | | | | | | |
| o|o o| o|o o|o o| o| o| o|o o| o|
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
toss 2 10
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|o |o |o o|o |o o|o |o o|o o|o o|o |
| | | | o |o o| o | | o |o o| |
| o| o|o o| o|o o| o|o o|o o|o o| o|
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|o o|o |o o|o o|o o|o o| |o o|o o|o o|
| | | o | | | o | o | | | |
|o o| o|o o|o o|o o|o o| |o o|o o|o o|
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
Notes:
1. I spaced my pips out wider, horizontally, than the original. I think
this looks better.
2. toss has 'faces' as an implicit dependency
3. I can change the number of dice being tossed by changing the argument to
toss
In my opinion, this is not a very good design. In "real life" code, I
would either replace (". bind 'faces') with (faces) or I would make it an
argument to the function.
I could probably compress a few characters out of the definition of faces,
but it would become more mysterious if I did so.
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm