Skip to content

Instantly share code, notes, and snippets.

@patrickclery
Created December 28, 2019 22:52
Show Gist options
  • Save patrickclery/0a18682b36423d469fd32effb74a52df to your computer and use it in GitHub Desktop.
Save patrickclery/0a18682b36423d469fd32effb74a52df to your computer and use it in GitHub Desktop.
Write a Ruby program to output the lowest 10 positive integers where the sum of the digits of each integer equals 10 and that contain the number 7 as one of the digits. For instance: The integer 1171 - its digits add up to 10 and it contains a 7
###############################################################################
# Write a Ruby program to output the lowest 10 positive integers where the sum of the digits of each integer equals 10 and that contain the number 7 as one of the digits. For instance: The integer 1171 - its digits add up to 10 and it contains a 7
class App
def self.call
found_numbers = []
1.upto(Float::INFINITY) do |num|
next unless num.to_s.match(/7/)
found_numbers << num if num.to_s.split('').map(&:to_i).sum === 10
break if found_numbers.size == 10
end
puts "Here are the first 10 positive integers whose digits add up to 10 and contain a 7:"
puts found_numbers.join(', ')
end
end
App.call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment