Ruby koan 182 Greed骰子游戏 - 得到一个神秘的错误

goz*_*ozu 0 ruby

我正在做边缘小屋学习红宝石,而我却被贪婪的koan(182-183)卡住了一个神秘的错误.这里列出了规则

我知道我的代码是......令人印象深刻,我想我一旦我的逻辑声音(它可能不是)就重构它.

我感谢任何帮助.

def score(dice)
  score = 0
  if dice == []
    return score
  end

  dice = dice.sort
  dice = [1,1,4,5,6]
  count = [0,0,0,0,0,0]
  score = 0
  dice.each do |face|
    if    face == 1
        count[0]++
    elsif face == 2 # this is line 45 with reported error
        count[1]++
    elsif face == 3
        count[2]++
    elsif face == 4
        count[3]++
    elsif face == 5
        count[4]++
    elsif face == 6
        count[5]++
    end
  end
  if count[0] >= 3
    score+= 1000
    count[0] = count[0] - 3
  elsif count[4] >= 3
    score+= 500
    count[4] = count[4] - 3
  end
  score+= count[0] * 100
  count [0] = 0
  score+= count[4] * 50
  count [4] = 0

  if count[1] >= 3
    score+= 200
  elsif count[2] >= 3
    score+= 300
  elsif count[3] >= 3
    score+= 400
  elsif count[5] >= 3
    score+= 600
  end

  #check if there are three 1 at the beginning
  #if not, check if we have three 2
  # You need to write this method
end
Run Code Online (Sandbox Code Playgroud)

有关信息,我收到此错误:

 /Users/gozulin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': /Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:45: syntax error, unexpected keyword_elsif (SyntaxError)
    elsif face == 2
         ^
/Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:47: syntax error, unexpected keyword_elsif
    elsif face == 3
         ^
/Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:49: syntax error, unexpected keyword_elsif
    elsif face == 4
         ^
/Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:51: syntax error, unexpected keyword_elsif
    elsif face == 5
         ^
/Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:53: syntax error, unexpected keyword_elsif
    elsif face == 6
         ^
/Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:55: syntax error, unexpected keyword_end
/Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:84: class definition in method body
/Users/gozulin/Sites/ruby_koans/koans/about_scoring_project.rb:122: syntax error, unexpected $end, expecting keyword_end
    from /Users/gozulin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from path_to_enlightenment.rb:24:in `<main>'
rake aborted!
Command failed with status (1): [/Users/gozulin/.rvm/rubies/ruby-1.9.2-p290...]
Run Code Online (Sandbox Code Playgroud)

Ern*_*est 5

Ruby不支持C风格增量:++.

使用 count[0] += 1

如果你有某种"神秘"错误,你也应该看看解释器指向你的位置,而且还要看上面的一行.