Walkthrough

Solutions

def sum_to(int)
  sum = 0
  current_num = 1

  while current_num < int + 1
    sum = sum + current_num
    current_num = current_num + 1
  end

  sum
end

def e_words(str)
  words = str.split
  count = 0

  i = 0
  while i < words.length
    word = words[i]

    if word[-1] == "e"
      count = count + 1
    end

    i = i + 1
  end

  count
end

def magic_number?(n)
  string_digits = n.to_s.split("")
  sum = 0

  i = 0
  while i < string_digits.length
    digit = string_digits[i]
    sum = sum + digit.to_i
    i = i + 1
  end

  sum == 7 # will either return true or false
end

def magic_numbers(n)
  magic_numbers_array = []
  current_num = 1

  while magic_numbers_array.length < n # keep incrementing until desired length (n) reached
    if magic_number?(current_num)
      magic_numbers_array << current_num
    end
    current_num = current_num + 1
  end

  magic_numbers_array
end

results matching ""

    No results matching ""