Ruby Basic Exercises: Check two given integers, each in the range 10..99, return true if there is a digit that appears in both numbers
Ruby Basic: Exercise-51 with Solution
Write a Ruby program to check two given integers, each in the range 10..99, return true if there is a digit that appears in both numbers.
def check_num(a, b) a_digit = a%10 b_digit = b%10; a /= 10; b /= 10; return (a == b || a == b_digit || a_digit == b || a_digit == b_digit) end print check_num(9, 12),"\n" print check_num(15, 51),"\n" print check_num(12, 23)
false true true
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to check two given integers and return the larger value. However if the two values have the same remainder when divided by 5 then return the smaller value and if the two values are the same, return 0.
Next: Write a Ruby program to check three given integers and return their sum. However, If one of the values is the same as another of the values, it does not count towards the sum.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework