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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:24:23+00:00 2026-06-01T17:24:23+00:00

I am trying to create a ruby program where three numbers are entered and

  • 0

I am trying to create a ruby program where three numbers are entered and their sum is taken but if any numbers are the same they don’t count toward the sum.
example (4,5,4) = 5
My problem is with my expressions. If i enter the same number I get multiple output for various combination. example enter 5,5,5 = 15,5,0

if a != b or c then
  puts a+b+c
elsif b != a or c then
  puts a+b+c
elsif c != a or b then 
  puts a+b+c
end

if a == b then
  puts c
elsif a == c then
  puts b
elsif b == c then
  puts a
end

if a == b and c then
  puts 0
elsif b == a and c then
  puts 0
elsif c == a and b then
  puts 0
end
  • 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-01T17:24:24+00:00Added an answer on June 1, 2026 at 5:24 pm

    Solving it with two beautiful self explanatory one-liners

    array = [a,b,c]
    
    array = array.keep_if {|item| array.count(item) == 1 }
    array.inject(0){|sum,item| sum + item}
    

    -The first line creates an array with your parameters.
    -The second line only keep the items whose count equals to 1 (remove the ones that appear more than one time), and store that on the array.
    -The third line sums all the remaining elements.

    Voilà, the ruby way 🙂

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

Sidebar

Related Questions

I'm trying to create a very simple Hello, world program in RoR, but when
I am trying to create a simple SSL client and server in Ruby. But
I have been trying to create a Ruby program that will be running online
I'm following this guide: http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html and I'm trying to create my first ruby program.
I'm trying to create a ruby gem for rails out of a plugin I've
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I'm new to Ruby on Rails, and I'm trying to create a bass guitar
I'm trying to figure out a way to take a Ruby array and create
I'm trying, for the first time, to create a GUI in Ruby using Tk.
I'm trying create a template with django but when I execute this sentences in

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.