On 1/8/08, Björn Helgason <[EMAIL PROTECTED]> wrote:
> It would be really interesting to see Rogers moo functionality explained
> line by line operation by operation
>
> load 'misc' NB. needs "prompt" from "misc"
>
> display=: 1!:2&2
>
> NB. univ =: (*./@(~:"1) # ]) @ (#: i.@(*/))
> univ =: #: i.@(*/)
>
> guess =: [EMAIL PROTECTED] { ]
> score =: ; prompt@(,&' ')@":
> solved =: (('b' $~ [EMAIL PROTECTED]) -: ])&>/@[
> bull =: +/@('b'&=)@(>@{:@[) = >@[EMAIL PROTECTED] +/@(="1) ]
> NB. bc =: #@(>@{:@[) = ] +/@e."1 >@[EMAIL PROTECTED]
> bc =: #@(>@{:@[) = ] ([ +/@:([ <. -~) [EMAIL PROTECTED] {. ])&(#/.~)"1
> ],"1 >@[EMAIL PROTECTED]
> prune =: ((bull *. bc) # ]) ` (''"_) @. solved
>
> s0 =: display@('no choices left'&[)
> s1 =: display@('one choice left; it must be '&,)@":@,
> sn =: display@(,&' choices left')@":@#
> state =: [EMAIL PROTECTED](0 1 i. #) ` ] @. ('' -: ])
>
> moo1 =: ([state)@([EMAIL PROTECTED] prune ])^:(1&<@#)
> moo =: moo1^:_ @ univ
Hmm... I do not remember this code, and do not remember
its purpose, nor its domain. And, purpose and domain are
crucial for understanding code.
However, I recognize univ as the odometer function (which is
described in the J wiki). For example, if I wanted all possibilities
for lists with 2 options for the first choice, 3 for the second and 2
for the third, I might use:
univ 2 3 2
0 0 0
0 0 1
0 1 0
0 1 1
0 2 0
0 2 1
1 0 0
1 0 1
1 1 0
1 1 1
1 2 0
1 2 1
So that tells me the domain.
This suggests that moo is probably a guessing game. And a google
search for moo guessing game finds me
http://publib.boulder.ibm.com/infocenter/systems/topic/com.ibm.aix.cmds/doc/aixcmds3/moo.htm
This tells me that "bulls" means guessed numbers that are
correct in value and in the correct position, while "cows" means
guessed numbers that are correct in value but in the wrong
position.
But here I get stuck -- I do not know the "domain" expected at the
prompt, and no hints jump out at me.
Anyways, I am reluctant to spend more time reverse engineering
this program, I would prefer a few senteces of documentation.
Thanks,
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm