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 9211719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:21:38+00:00 2026-06-18T01:21:38+00:00

I just try to solve problem #45 from project-euler using ruby. I know the

  • 0

I just try to solve problem #45 from project-euler using ruby. I know the approach. But I wrote the code, It doesn’t run. I am new to ruby, I don’t know why there has to be so many “end” keyword at the back(Or else the terminal will complain)

Here is the code:

class Test
    def initialize()

    end

    def Triangle(n)
        if 1 + 8*n < 0 then
            return false
        else
            i1 = 0.5 * (-1 + Math.sqrt(1 + 8*n))
            i2 = 0.5 * (-1 - Math.sqrt(1 + 8*n))
            cut_i1 = i1.to_i
            cut_i2 = i2.to_i
            if (cut_i1 == i1) & (i1 > 0)
                return true
            else if (cut_i2 == i1) & (i2 > 0)
                return true
            else
                return false
            end
        end
    end

    def Pentagonal(n)
        delta = 1 + 24*n
        if delta < 0 then
            return false
        else
            r1 = (1.0/6) * (1 + Math.sqrt(delta))
            r2 = (1.0/6) * (1 - Math.sqrt(delta))
            cut_r1 = r1.to_i
            cut_r2 = r2.to_i
            if (cut_r1 == r1) & (r1 > 0)
                return true
            else if (cut_r2 == r1) & (r2 > 0)
                return true
            else
                return false
            end
        end
    end 

    def Hexagonal(n)
        delta = 1 + 8*n
        if delta < 0 then
            return false
        else
            r1 = 0.25 * (1 + Math.sqrt(delta))
            r2 = 0.25 * (1 - Math.sqrt(delta))
            cut_r1 = r1.to_i
            cut_r2 = r2.to_i
            if (cut_r1 == r1) & (r1 > 0)
                return true
            else if (cut_r2 == r1) & (r2 > 0)
                return true
            else
                return false
            end
        end
    end
end
for i in (1...100)
    o = Test.new
    print o.Triangle(i)
end

end
end
end

What’s happening. Every time I run the program from the terminal. It shows nothing….

  • 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-18T01:21:39+00:00Added an answer on June 18, 2026 at 1:21 am

    It’s because you are using else if instead of elsif. Compare:

    if cond
      # do something
    elsif another_cond
      # do something else
    end
    
    
    if cond
      # do something
    else
      if another_cond
        # do something else
      end
    end
    

    With that in mind, your program does not do what you think it should. Fix the elsif‘s and see.

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

Sidebar

Related Questions

I decided to try project euler problem 17 today, and I quickly wrote a
I need to solve this problem. I started my project from the wrong concept
I looked here to try and solve my problem. It is similar but I
So I managed to solve a problem of retrieving information from the bundle, but
i use below code - Just try again. - to prevent deadlock. it seems
I just follow this DIHQuickStart , try to import data to solr from mysql.
Just wrote a web service and try to return columns of a sharepoint list
Background: I have a situation similar to this but the solution there doesn't solve
I just come across a challenging problem (from programming competition practice) that contain recursive
I'm just starting to try develop an kinect application. The problem is when I'm

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.