--_0f1251f3-5eb1-4ebc-ae6c-123942915b2d_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Thanks but I did not solve my problem.

Here is the whole script :

require File.expand_path(File.dirname(__FILE__) + '/edgecase')

# 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)
  total = 0 
  h = Hash.new(0)
  dice.each {|el| h[el] += 1} 

 dice.each {|number, count|
   if number == 1 and count == 6 then return 2000 end
   if number != 1 and count == 3 then total = total + 100 * count end
   if number != 1 and count == 6 then return 600 end
   if number == 1 and (count > 3) then total = total + ( 100 + ( count - 3)) end
   if number == 1 and (count < 3) then total = total   + 100 * count end
   if number == 5 and (count > 3) then total = total + ( 50 * (count -3)) end
   if number == 5 and (count < 3) then total = total +  50 * count end
    }

end
  

class AboutScoringProject < EdgeCase::Koan
  def test_score_of_an_empty_list_is_zero
    assert_equal 0, score([])
  end

  def test_score_of_a_single_roll_of_5_is_50
    assert_equal 50, score([5])
  end

  def test_score_of_a_single_roll_of_1_is_100
    assert_equal 100, score([1])
  end

  def test_score_of_multiple_1s_and_5s_is_the_sum_of_individual_scores
    assert_equal 300, score([1,5,5,1])
  end

  def test_score_of_single_2s_3s_4s_and_6s_are_zero
    assert_equal 0, score([2,3,4,6])
  end

  def test_score_of_a_triple_1_is_1000
    assert_equal 1000, score([1,1,1])
  end

  def test_score_of_other_triples_is_100x
    assert_equal 200, score([2,2,2])
    assert_equal 300, score([3,3,3])
    assert_equal 400, score([4,4,4])
    assert_equal 500, score([5,5,5])
    assert_equal 600, score([6,6,6])
  end

  def test_score_of_mixed_is_sum
    assert_equal 250, score([2,5,2,2,3])
    assert_equal 550, score([5,5,5,5])
  end

end

And I now get this error: <0> expected but was  <[]>.
When I make that one a comment :

def test_score_of_an_empty_list_is_zero

    #assert_equal 0, score([])

  end

Then I see this error appear : 

The answers you seek...
  undefined method `>' for nil:NilClass

Please meditate on the following code:
  ./about_scoring_project.rb:43:in `score'
  ./about_scoring_project.rb:37:in `each'
  ./about_scoring_project.rb:37:in `score'
  ./about_scoring_project.rb:56:in `test_score_of_a_single_roll_of_5_is_50'
  /home/roelof/koans/edgecase.rb:398:in `send'
  /home/roelof/koans/edgecase.rb:398:in `meditate'
  /home/roelof/koans/edgecase.rb:470:in `walk'
  /home/roelof/koans/edgecase.rb:481:in `each_step'
  /home/roelof/koans/edgecase.rb:479:in `each'
  /home/roelof/koans/edgecase.rb:479:in `each_step'
  path_to_enlightenment.rb:38:in `each_with_index'
  /home/roelof/koans/edgecase.rb:478:in `each'
  /home/roelof/koans/edgecase.rb:478:in `each_with_index'
  /home/roelof/koans/edgecase.rb:478:in `each_step'
  /home/roelof/koans/edgecase.rb:476:in `catch'
  /home/roelof/koans/edgecase.rb:476:in `each_step'
  /home/roelof/koans/edgecase.rb:469:in `walk'
  /home/roelof/koans/edgecase.rb:491
  path_to_enlightenment.rb:38


So something is not well here ?

Roelof



> Date: Wed, 26 Sep 2012 03:26:55 +0900
> From: lists / ruby-forum.com
> Subject: Re: inject problem
> To: ruby-talk / ruby-lang.org
> 
> Roelof Wobben wrote in post #1077503:
> >   h = Hash.new(0)
> >   dice.each {|el| dice[el] += 1}
> > [...]
> > But now I'm getting this error : undefined method `+' for nil:NilClass
> 
> You want h[el] += 1, not dice[el] += 1. See the original code by Jesų¸.
> 
> -- 
> Posted via http://www.ruby-forum.com/.
 		 	   		  -_0f1251f3-5eb1-4ebc-ae6c-123942915b2d_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Thanks but I did not solve my problem.<br><br>Here is the whole script :<br><br>require File.expand_path(File.dirname(__FILE__) + '/edgecase')<br><br># Greed is a dice game where you roll up to five dice to accumulate<br># points.&nbsp; The following "score" function will be used to calculate the<br># score of a single roll of the dice.<br>#<br># A greed roll is scored as follows:<br>#<br># * A set of three ones is 1000 points<br>#<br># * A setf three numbers (other than ones) is worth 100 times the<br>#&nbsp;&nbsp; number. (e.g. three fives is 500 points).<br>#<br># * A one (that is not part of a set of three) is worth 100 points.<br>#<br># * A five (that isot part of a set of three) is worth 50 points.<br>#<br># * Everything else is worth 0 points.<br>#<br>#<br># Examples:<br>#<br># score([1,1,1,5,1]) =&gt; 1150 points<br># score([2,3,4,6,2]) =&gt; 0 points<br># score([3,4,5,3,3]) =&gt; 350 points<br># score([1,5,1,2,4]) =&gt; 250 points<br>#<br># More scoring examples are given in the tests below:<br>#<br># Your goal is to write the score method.<br><br>def score(dice)<br>&nbsp; total = 0 <br>&nbsp; h = Hash.new(0)<br>&nbsp; dice.each {|el| h[el] += 1} <br><br>&nbsp;dice.each {|number, count|<br>&nbsp;&nbsp; if number == 1 and count == 6 then return 2000 end<br>&nbsp;&nbsp; if number != 1 and count == 3 then total = total + 100 * count end<br>&nbsp;&nbsp; if number != 1 and count == 6 then return 600 end<br>&nbsp;&nbsp; if number ==nd (count &gt; 3) then total = total + ( 100 + ( count - 3)) end<br>&nbsp;&nbsp; if number == 1 and (count &lt; 3) then total = total&nbsp;&nbsp; + 100 * count end<br>&nbsp;&nbsp; if number == 5 and (count &gt; 3) then total = total + ( 50 * (count -3)) end<br>&nbsp;&nbsp; if number == 5 and (count &lt; 3) then total = total +&nbsp; 50 * count end<br>&nbsp;&nbsp;&nbsp; }<br><br>end<br>&nbsp; <br><br>class AboutScoringProject &lt; EdgeCase::Koan<br>&nbsp; defest_score_of_an_empty_list_is_zero<br>&nbsp;&nbsp;&nbsp; assert_equal 0, score([])<br>&nbsp; end<br><br>&nbsp; def test_score_of_a_single_roll_of_5_is_50<br>&nbsp;&nbsp;&nbsp; assert_equal 50, score([5])<br>&nbsp; end<br><br>&nbsp; def test_score_of_a_single_roll_of_1_is_100<br>&nbsp;&nbsp;&nbsp; assert_equal 100, score([1])<br>&nbsp; end<br><br>&nbsp; def test_score_of_multiple_1s_and_5s_is_the_sum_of_individual_scores<br>&nbsp;&nbsp;&nbsp; assert_equal 300, score([1,5,5,1])<br>&nbsp; end<br><br>&nbsp; def test_score_of_single_2s_3s_4s_and_6s_are_zero<br>&nbsp;&nbsp;&nbsp; assert_equal 0, score([2,3,4,6])<br>&nbsp; end<br><br>&nbsp; def test_score_of_a_triple_1_is_1000<br>&nbsp;&nbsp;&nbsp; assert_equal 1000, score([1,1,1])<br>&nbsp; end<br><br>&nbsp; def test_score_of_other_triples_is_100x<br>&nbsp;&nbsp;&nbsp; assert_equal 200, score([2,2,2])<br>&nbsp;&nbsp;&nbsp; assert_equal 300, score([3,3,3])<br>&nbsp;&nbsp;&nbsp; assert_equal 400, score([4,4,4])<br>&nbsp;&nbsp;&nbsp; assert_equal 500, score([5,5,5])<br>&nbsp;&nbsp;&nbsp; assert_equal 600, score([6,6,6])<br>&nbsp; end<br><br>&nbsp; def test_score_of_mixed_is_sum<br>&nbsp;&nbsp;&nbsp; assert_equal 250, score([2,5,2,2,3])<br>&nbsp;&nbsp;&nbsp; assert_equal 550, score([5,5,5,5])<br>&nbsp; end<br><br>end<br><br>And I now get this error: &lt;0&gt; expected but was&nbsp; &lt;[]&gt;.<br>When I make that one a comment :<br><br>def test_score_of_an_empty_list_is_zero<br>
&nbsp;&nbsp;&nbsp; #assert_equal 0, score([])<br>
&nbsp; end<br><br>Then I see this error appear : <br><br>The answers you seek...<br>&nbsp; undefined method `&gt;' for nil:NilClass<br><br>Please meditate on the following code:<br>&nbsp; ./about_scoring_project.rb:43:in `score'<br>&nbsp; ./about_scoring_project.rb:37:in `each'<br>&nbsp;/about_scoring_project.rb:37:in `score'<br>&nbsp; ./about_scoring_project.rb:56:in `test_score_of_a_single_roll_of_5_is_50'<br>&nbsp; /home/roelof/koans/edgecase.rb:398:in `send'<br>&nbsp; /home/roelof/koans/edgecase.rb:398:in `meditate'<br>&nbsp; /home/roelof/koans/edgecase.rb:470:in `walk'<br>&nbsp; /home/roelof/koans/edgecase.rb:481:in `each_step'<br>&nbsp; /home/roelof/koans/edgecase.rb:479:in `each'<br>&nbsp; /home/roelof/koans/edgecase.rb:479:in `each_step'<br>&nbsp; path_to_enlightenment.rb:38:in `each_with_index'<br>&nbsp; /home/roelof/koans/edgecase.rb:478:in `each'<br>&nbsp; /home/roelof/koans/edgecase.rb:478:in `each_with_index'<br>&nbsp; /home/roelof/koans/edgecase.rb:478:in `each_step'<br>&nbsp; /home/roelof/koans/edgecase.rb:476:in `catch'<br>&nbsp; /home/roelof/koans/edgecase.rb:476:in `each_step'<br>&nbsp; /home/roelof/koans/edgecase.rb:469:in `walk'<br>&nbsp; /home/roelof/koans/edgecase.rb:491<br>&nbsp; path_to_enlightenment.rb:38<br><br><br>So something is not well here ?<br><br>Roelof<br><br><br><br><div><div id="SkyDrivePlaceholder"></div>&gt; Date:ed, 26 Sep 2012 03:26:55 +0900<br>&gt; From: lists / ruby-forum.com<br>&gt; Subject: Re: inject problem<br>&gt; To: ruby-talk / ruby-lang.org<br>&gt; <br>&gt; Roelof Wobben wrote in post #1077503:<br>&gt; &gt;  3D Hash.new(0)<br>&gt; &gt;   dice.each {|el| dice[el] += 1}<br>&gt; &gt; [...]<br>&gt; &gt; But now I'm getting this error : undefined method `+' for nil:NilClass<br>&gt; <br>&gt; You want h[el] += 1, not dice[el] += 1. See the original code by Jesų¸.<br>&gt; <br>&gt; -- <br>&gt; Posted via http://www.ruby-forum.com/.<br></div> 		 	   </div></body>
</html>-_0f1251f3-5eb1-4ebc-ae6c-123942915b2d_--