Я был на пути к просветлению на ruby коанах, но передо мной возникло непреодолимое препятствие. В проекте about_scoring_project я получаю некоторые синтаксические ошибки в строках, в которых я поставил end
к предыдущему for
.
C:/Ruby27-x64/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
: C:/Users/Psico/Downloads/rubykoans/koans/about_scoring_project.rb:62: syntax error, unexpected `end' (SyntaxError)
end
^~~
C:/Users/Psico/Downloads/rubykoans/koans/about_scoring_project.rb:74: syntax error, unexpected `end'
end
Я попытался удалить эти концы, но затем я получил ожидаемое " конец "ошибка.
Мой код выглядит следующим образом:
class DiceError < StandardError
end
def score(dice)
# You need to write this method
totalScore = 0
numbers = {1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0}
for elem in dice
unless (elem >= 1 && elem <= 6)
raise DiceError, "#{elem} is not a number of a six faced dice"
end
numbers[elem] += 1
end
valuesArray = numbers.values
indexCounter = 0
for elem in valuesArray ## conta pontos de triplas #TODO passar para uma função separada
if elem >= 3
if indexCounter == 0
totalScore += 1000
else
totalScore += 100 * (indexCounter + 1)
end
valuesArray[indexCounter] = elem - 3
end
indexCounter++
end
indexCounter = 0 #zera o contador
singlesPoints = Hash.new(0)
singlesPoints[0] = 100
singlesPoints[4] = 50
for elem in valuesArray
if elem > 0
totalScore += singlesPoints[indexCounter] * elem
end
valuesArray[indexCounter] = 0 #garante que no fim o vetor de valores seja todo igual a 0
indexCounter++
end
puts("#{numbers}")
return totalScore
end