Write a function to check three given integers and return their sum. However, If one of the values is the same as another of the values, then both the values are not counted in the sum. In Ruby language.
![**Title:** Ruby Function for Integer Sum with Duplicate Check
**Task Description:**
Create a function in Ruby to process three given integers and return their sum. The function should check for any duplicate values among the three integers. If any two values are the same, neither of them should be included in the sum calculation.
**Instructions:**
- Write a function that accepts three integer arguments.
- Evaluate the integers to check if any are equal.
- Exclude any duplicates from the sum.
- Return the calculated sum.
**Example:**
Suppose the integers are 3, 3, and 5. Since the first two integers are duplicates, they are not counted, and only the third integer, 5, is summed, resulting in a total sum of 5.
**Implementation Tips:**
Consider edge cases such as when all three integers are the same or when there are no duplicates. Efficiently handle the logic for checking duplicates and calculating the sum.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0f88b6f9-a9e1-460c-a343-1ec6e31556e6%2Fca2ca206-7972-4c12-b610-f9ddc60a29da%2F7re5ovu_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
#function to check three integers and return their sum
def check_sum(num1, num2, num3)
#Check numbers
if num1==num2 && num2==num3
#if all numbers are same return 0 as sum
return 0
elsif num1==num2
#if num1 and num2 is same return num3 as sum
return num3
elsif num1==num3
#if num1 and num3 is same return num2 as sum
return num2
elsif num2==num3
#if num2 and num3 is same return num1 as sum
return num1
else
#if all number is different return their sum
return num1+num2+num3
end
end
#test code
print "Sum(6,6,6): ",check_sum(6, 6, 6),"\n"
print "Sum(6,6,4): ",check_sum(6, 6, 4),"\n"
print "Sum(6,3,6): ",check_sum(6, 3, 6),"\n"
print "Sum(2,6,6): ",check_sum(2, 6, 6),"\n"
print "Sum(2,3,4): ",check_sum(2, 3, 4),"\n"
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)