Skip to content

Instantly share code, notes, and snippets.

@sushant12
Last active November 5, 2019 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sushant12/a7c3175b3eb60c3c793656103f2551af to your computer and use it in GitHub Desktop.
Save sushant12/a7c3175b3eb60c3c793656103f2551af to your computer and use it in GitHub Desktop.
find curious numbers by string manipulation
class CuriousNumbers
attr_reader :digit, :largest_num
BASE_CURIOUS_NUMS = [0, 1, 5, 6].freeze
def initialize(digit)
@digit = digit.abs
@largest_num = ('9'*@digit).to_i
end
def execute
return [0] if digit == 0
(BASE_CURIOUS_NUMS + squared_numbers(25) + squared_numbers(36)).sort
end
private
def squared_numbers(num)
squared_number = num
arr = []
until squared_number > largest_num
arr.push(squared_number)
squared_number = squared_number ** 2
end
arr
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment