June,

        You might be interested in the game Moo which was
discussed by Roger Hui in 1992 in a J context. That was an
time for J so the code may have features no longer
available.

http://groups.google.com/group/comp.lang.apl/browse_thread/thread/9dcba42ebb27b210/7c9404635d9c370f?q=moo&rnum=1#7c9404635d9c370f

(B=)

On Fri, 16 Jun 2006, June Kim wrote:

+ Hello
+
+ There is a game called number baseball game. One person holds secret
+ his/her own n-digit number. The other player guesses the number with
+ many trials of n-digit numbers.
+
+ Strike is when the same digit is in the same position between the
+ answer and the guess numbers. Ball is when the same digit is in a
+ different position between the answer and the guess numbers.
+
+ For example, when the answer is 123 and the guess is 923, it is 2
+ strike and no ball.
+
+ It becomes tricky when there are multiple of the same digits. For
+ example when the answer is 998 and the guess is 129, it's no strike
+ and 1 ball(it's counting the possible pair). When the answer is 912
+ and the guess is 998, it is 1 strike and no ball.
+
+ Here is my solution:
+
+ score=: strike, ball
+ ball=: findall - strike
+ strike=: +/@:=
+ findall=: +/@(<./"1@:(+/"1)@(~.@, =/ ,:))
+
+ assert 1 0 -: 1 2 3 score 9 8 3
+ assert 2 0 -: 1 2 3 score 1 9 3
+ assert 0 1 -: 1 2 3 score 9 8 1
+ assert 0 2 -: 1 2 3 score 3 9 1
+
+ assert 1 0 -: 9 8 7 score 9 9 1
+ assert 0 2 -: 9 9 1 score 1 2 9
+
+ I am satisfied with "strike" verb but not with "findall" verb. Could
+ you come up with a more elegant and simpler verb?
+ ----------------------------------------------------------------------
+ For information about J forums see http://www.jsoftware.com/forums.htm
+

(B=) <----------my "sig"

Brian Schott
Atlanta, GA, USA
schott DOT bee are eye eh en AT gee em ae eye el DOT com
http://schott.selfip.net/~brian/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to