From: "Eric I." Date: 2007-04-16T06:00:05+09:00 Subject: Re: Magic Fingers (#120) [solution] OK, I made two changes to my code. First, I don't allow a clap that ends up with the same finger counts. Second, I made it possible to clap all the fingers off of one hand to the other, leaving one hand with zero. And now it is the case where the first player is guaranteed a loss. Here's my new move table: 01 02 03 04 11 12 13 14 22 23 24 33 34 44 ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- 01: -1T1 -1T2 -1T3 +1T4 -1T1 -1T2 -1T1 +1T4 -1T2 -1T2 -1T4 -1T3 -1T4 -1T4 02: +C11 -C11 +2T3 +2T4 +C11 -C11 +2T3 +2T4 -C11 +2T3 +2T4 -C11 -C11 - C11 03: +C21 +3T2 +3T3 +3T4 -C21 +3T2 +3T3 +3T4 -C21 -C21 -C21 -C21 -C21 - C21 04: +4T1 +4T2 +4T3 +4T4 +C31 +C22 C22 +C22 C22 +C22 C22 -C22 -C22 - C22 11: +C02 +1T2 -1T3 +1T4 -1T1 +C02 -1T3 +1T4 C02 -1T2 -1T4 -1T3 +1T4 -1T4 12: +C03 -2T2 +2T3 +2T4 +C03 +2T2 +2T3 +2T4 -1T2 +2T3 +2T4 -1T3 -2T3 -1T4 13: +C22 +3T2 +3T3 +3T4 +3T1 +C22 +3T3 +1T4 C22 +C22 C22 -C22 3T3 1T4 14: +4T1 +4T2 +4T3 +4T4 +C32 -C32 -C32 +C32 -C32 -4T3 -4T2 -1T3 -4T3 -1T4 22: +C13 2T2 +2T3 +2T4 +C13 +2T2 +2T3 +2T4 2T2 +2T3 +2T4 +2T3 +2T4 2T4 23: +2T1 +3T2 +3T3 +3T4 +3T1 +3T2 +3T3 +3T4 -3T2 +3T2 -3T2 +3T3 +3T4 -2T4 24: +4T1 +4T2 +2T3 +2T4 +4T1 +4T2 +2T3 +2T4 2T2 +4T2 4T2 +4T3 +4T4 2T4 33: +C24 +3T2 +3T3 +3T4 +3T1 +3T2 +3T3 +3T4 +3T2 +3T2 +3T4 +3T3 +3T4 +3T4 34: +4T1 +4T2 +4T3 +4T4 +4T1 +4T2 +4T3 +4T4 +4T2 +4T3 +4T4 +4T3 +4T4 +4T4 44: +4T1 +4T2 +4T3 +4T4 +4T1 +4T2 +4T3 +4T4 +4T2 +4T3 +4T4 +4T3 +4T4 +4T4 Interestingly if you follow through starting at 11/11, then the first player can apparently hold off on losing for 26 turns, 13 by each player. And my replacement generate_claps method is appended below. Eric ---- Are you interested in on-site Ruby training that's been highly reviewed by former students? http://LearnRuby.com ==== # Generates an array of Procs, each able to perform a clapping move. # See the comment for generate_touches for the remaining details since # this method works analogously. def generate_claps result = [] (0..1).each do |from_hand| to_hand = 1 - from_hand (1..4).each do |fingers| result << Proc.new do |player_hands, opponent_hands| raise "do not have enough fingers on #{HandNames[from_hand]}" unless player_hands[from_hand] >= fingers raise "#{HandNames[to_hand]} would end up with five or more fingers" if !AllowClapsToZero && player_hands[to_hand] + fingers >= 5 raise "cannot end up with same number combination after clap" if player_hands[from_hand] - fingers == player_hands[to_hand] description1 = "claps to transfer #{fingers} fingers from " + "#{HandNames[from_hand]} to #{HandNames[to_hand]}" player_hands[from_hand] -= fingers player_hands[to_hand] += fingers player_hands[to_hand] = 0 if player_hands[to_hand] >= 5 description2 = "C#{player_hands[from_hand]}#{player_hands[to_hand]}" [[player_hands, opponent_hands], description1, description2] end end end result end