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

  • SEARCH
  • Home
  • 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 7944789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:39:28+00:00 2026-06-04T00:39:28+00:00

The challenge is to find the smallest integer foo for which: foo % 1..20

  • 0

The challenge is to find the smallest integer foo for which:

foo % 1..20 == 0

My current attempt is brute force

until foo % 1.upto(20) == 0 do
    foo++
end

This outputs the error unexpected keyword end. But if I don’t put the end keyword into irb the code never runs, because the block isn’t closed.

I made an empty test case to see where my error lays

until foo % 1.upto(20) == 0 do
end

This throws a new error: enumerator can't be coerced to a fixnum. I imagine this means you can’t directly perform modulus upon a range and expect a neat boolean result for the whole range. But I don’t know where to go from here.

My first attempts forewent brute force in favor of an attempt at something more efficient/elegant/to-the-point and were as follows:

foo = 1
1.upto(20) {|bar| foo *= bar unless foo % i == 0}

gave the wrong answer. I don’t understand why, but I’m also interested in why

foo = 1
20.downto(1) {|bar| foo *= bar unless foo % i == 0}

outputs a different answer.

EDIT: I would have used for loops (I got my feet wet with programming in ActionScript) but they do not work how I expect in ruby.

  • 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-06-04T00:39:30+00:00Added an answer on June 4, 2026 at 12:39 am

    If this were me, I’d define a function to test the condition:

    def mod_test(num)
      test = (1..20).map {|i| num % i == 0}
      test.all? # all are true
    end
    

    and then a loop to try different values:

    foo = 20
    until mod_test(foo) do
      foo += 20
    end
    

    (Thanks to Dylan for the += 20 speedup.)

    I’m sure that there’s a clever way to use the knowledge of foo % 10 == 0 to also imply that foo % 5 == 0 and foo % 2 == 0, and perform only tests on prime numbers between 1 and 20, and probably even use that information to construct the number directly — but my code ran quickly enough.

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

Sidebar

Related Questions

This is a challenge question / problem. Hope you find it interesing. Scenario: You
I'm writing a Clojure implementation of this coding challenge , attempting to find the
My challenge here is to search a webpage to attempt to find all of
Challenge: I have this code that fails to compile. Can you figure out what's
So here’s the challenge. Given 2 integers named a and b: // Find the
This application is the first application challenge on the site hackthissite.org. The idea is
This is a challenge for any Javascript/jQuery ninjas out there: What is the best
I'm facing a new challenge here. I can't seem to find precedence for replication
In my current rails program when I use something like user = User.find(10) When
I came across this File parsing programming challenge today and found it quite interesting.

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.