I'm playing the Game of Nim with a colleague.  He's an old hand and knows
all the patterns by heart.  I do not.  I can't beat him.

But I can do this:

        winNim =: (* 0&<)@(- (~:"1 ~:/)&.#:)

So if you have a Nim board like this:
        
        1 1 1 1 1
         1 1 1 1 
          1 1 1 
           1 1
            1

You can win like this:

           winNim 5 4 3 2 1
        1 0 1 0 1

That is, remove one stick from the pile of 5, or the pile of 3, or the pile
of 1.

A bandaid for my pride.

-Dan


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to