title: ruby: Struggling with recursion
body: <p>I'm supposed to create a method in ruby that will take in a structured,multi-dimensioned array, such as:</p>
  
  <pre><code>my_arr = [
  [ [['Armando', 'P'], ['Dave', 'S']], [['Richard', 'R'], ['Michael', 'S']] ],
  [ [['Allen', 'S'], ['Omer', 'P']], [['David E.', 'R'], ['Richard X.', 'P']] ]
  ]
  </code></pre>
  
  <p>This array is supposed to represent a tournament of Rock, paper &amp; scissors, the number of players will always be 2^n and no repetitions (of players) are made.</p>
  
  <p>The code I wrote is as follows:</p>
  
  <pre><code>class WrongNumberOfPlayersError &lt; StandardError ; end
  class NoSuchStrategyError &lt; StandardError ; end
  
  def rps_game_winner(game)
    raise WrongNumberOfPlayersError unless game.length == 2
    valid = ["r","p","s"]
    a1=[(game[0][1]).downcase]
    a2=[(game[1][1]).downcase]
    raise NoSuchStrategyError unless (valid &amp; a1) &amp;&amp; (valid &amp; a2)
  
    return (game[0]) if a1 === a2
    case (a1[0])
    when "r"
      case (a2[0])
      when "p"
        return (game[1])
      else 
        return (game[0])
      end
    when "p"
      case (a2[0])
      when "s"
        return (game[1])
      else
        return (game[0])
      end
    when "s"
      case (a2[0])
      when "r"
        return (game[1])
      else 
        return (game[0])
      end
    end
  end
  
  def rps_tournament_winner(tournament)
    if tournament[0][0].is_a?(Array)
      rps_tournament_winner(tournament[0])
    elsif tournament[1][0].is_a?(Array)
      rps_tournament_winner(tournament[1])
    else
      rps_game_winner(tournament)
    end
  end
  </code></pre>
  
  <p><strong>So my problem is that given the use of array i mentioned earlier being passed to <code>rps_tournament_winner</code> <code>Dave</code> always wins instead of <code>Richard</code> and i haven't been able to figure out where i went wrong.</strong></p>
  
  <p>Ty for reading the wall of text/code :)</p>