Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:37:25+00:00 2026-05-16T23:37:25+00:00

So, I’m a total nuby working through http://www.rubykoans.com/ and I’m stuck on about_scoring_project.rb. This

  • 0

So, I’m a total nuby working through http://www.rubykoans.com/ and I’m stuck on about_scoring_project.rb. This is my stab at the score method.

def score(dice)
  score = 0;
  if dice.respond_to?("include?") then
    # add 1000 points if rolled 3 ones
    score += 1000 if dice.include?([1, 1, 1])

    # add 100 points times die face value if rolled 3 of a number between 2 and 6
    (2...6).each do |die|
        score += die*100 if dice.include?([die, die, die])

      # award points for each 1 or 5 not a part of a set of 3
      leftovers = dice - [1,1,1]
      leftovers -= [5,5,5]
      leftovers.each do |leftover|
        score += 100 if leftover == 1
        score += 50 if leftover == 5
      end
    end
  end
  score
end

class AboutScoringAssignment < EdgeCase::Koan
  def test_score_examples
    assert_equal 1150, score([1,1,1,5,1])
    assert_equal 0, score([2,3,4,6,2])
    assert_equal 350, score([3,4,5,3,3])
    assert_equal 250, score([1,5,1,2,4])
  end
end

In the call to score from the first assert_equal, I would expect dice.include?([1,1,1]) to evaluate to true, but it’s evaluating to nil (and score is returning 0 instead of 1150).

I tried this separately…

require 'test/unit'

class EnumerableTests < Test::Unit::TestCase
  def test_include
    my_enumerable = [1,1,1,5,1]
    assert true, my_enumerable.include?([1,1,1])    
  end
end

…and the test passes, so I don’t know why I’m getting nil in my score method.

Anybody see what I’m doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:37:25+00:00Added an answer on May 16, 2026 at 11:37 pm

    Minor nitpick: Array#include? always returns true or false, never nil.

    To answer your question: x.include?(y) tests whether y is an element of x, not whether it’s a subarray.

    [1,1,1,5,1].include?([1,1,1]) returns false because [1,1,1] is not an element of the array [1,1,1,5,1]. [[1,1,1],[5,1]].include?([1,1,1])) would return true.

    There is no method in ruby that checks whether an array is a subarray of a another array, but you can easily write it as arr1.each_cons(arr2.size).include?(arr2) (needs require 'enumerator' in 1.8.6). This is O(arr1.size*arr2.size) though.

    If you want it in O(arr1.size + arr2.size), you can implement the Knuth-Morris-Pratt algorithm (which is meant to find substrings, but works equally well for finding subarrays as they are essentially the same thing).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.