I'm quickly coming to the conclusion that I can't be a programmer. Despite taking ample notes and practicing everything in Ruby Koans up to this point on top of going through the Ruby course on Codecademy three times and currently making my way through Chris Pine's book averaging 6hrs a day studying...this current Koan is an exercise in frustration and the realization that not everyone can be a programmer.
The exercise is as follows
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used to calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
# * A set of three numbers (other than ones) is worth 100 times the
# number. (e.g. three fives is 500 points).
#
# * A one (that is not part of a set of three) is worth 100 points.
#
# * A five (that is not part of a set of three) is worth 50 points.
#
# * Everything else is worth 0 points.
#
#
# Examples:
#
# score([1,1,1,5,1]) => 1150 points
# score([2,3,4,6,2]) => 0 points
# score([3,4,5,3,3]) => 350 points
# score([1,5,1,2,4]) => 250 points
#
# More scoring examples are given in the tests below:
#
# Your goal is to write the score method.
def score(dice)
end
So looking at everything on first glance, I'm assuming the test will provide the random num functionality via dice
? Or do I need to write that myself? Now I have to limit the range the dice rolls? Then all I have to do is get the numbers and put them into an array but only up to 5 positions (so like while array has 5 or less entries?
I then need to define how the point system works. So something like score[0] = 100, score[2]= 200
? But now I've hardcoded the scores, what if the first position isn't a 1 but is a 5? Then the number would be 50. So how about an if/else statement? something like
if score[0] == 1
point = 100
elsif score[0] == 5
point = 50
else point = 0
Then I repeat this for positions [1]-[4]?
Despite wanting to very badly, I don't want to simply google the answer, I'd rather get some kind of direction for lack of a better word.
Hopefully this isn't too general of a question but how do you even approach something like this? Perhaps I should go through Pine's book from beginning to end first before tackling this?