simple-exercises/ruby-exercises/easy-7.rb
# A magic number is a number whose digits, when added together, sum to 7, e.g., 34. Define a method that returns an array of the first n magic numbers. You may wish to write a helper method (magic_number?) that returns a boolean indicating whether a number is magic. This problem is harder than anything you'll receive on the coding assessment.
# magic_numbers(3) => [7, 16, 25]
A magic number is a number whose digits, when added together, sum to 7, e.g., 34. Define a method that returns an array of the first n magic numbers. You may wish to write a helper method (magic_number?) that returns a boolean indicating whether a number is magic. This problem is harder than anything you'll receive on the coding assessment.
A magic number is a number whose digits when added together sum to 7 e . g . 34 . Define a method that returns an array of the first n magic numbers . You may wish to write a helper method ( magic_number? ) that returns a boolean indicating whether a number is magic . This problem is harder than anything you ' ll receive on the coding assessment .
def magic_number?(n)
  string = n.to_s
  number = 0
  string.each_char do |s|
    number += s.to_i
  end
  number == 7
end
def magic_number? ( n ) string = n . to_s number = 0 string . each_char do | s | number += s . to_i end number == 7 end
A magic number is a number whose digits, when added together, sum to 7, e.g., 34.
A magic number is a number whose digits when added together sum to 7 e . g . 34 .
# convert # to string # sum each number
n
<not_specific>