```--_c65024c6-659c-42f6-bf9a-278d24b70900_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

I thought I solved this problem with this code :

def score(dice)
total = 0
h = Hash.new(0)
dice.each {|el| dice[el] += 1}

dice.each {|number, count|
if number == 1 and count == 3 then total = total + 1000 end
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

But now I'm getting this error : undefined method `+' for nil:NilClass

Roelof

> Date: Tue, 25 Sep 2012 23:31:12 +0900
> From: lists / ruby-forum.com
> Subject: Re: inject problem
> To: ruby-talk / ruby-lang.org
>
> The first parameter of the "inject" block is always the intermediate
> result used for the aggregation. And the second is the current element.
>
> For example:
>
> # calculate sum of 1, 2, ..., 10 (in an inefficient way)
> sum = (1..10).inject do |intermediate_sum, integer|
>   intermediate_sum + integer
> end
>
>
> count = [1, 2, 1, 1]
> hash = count.inject({}) do |intermediate_hash, number|
>   intermediate_hash[number] += 1 rescue intermediate_hash[number] = 1
>   intermediate_hash
> end
> puts hash
>
> --
> Posted via http://www.ruby-forum.com/.
>
-_c65024c6-659c-42f6-bf9a-278d24b70900_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<style><!--
.hmmessage P
{
margin:0px;