Skip to content

Instantly share code, notes, and snippets.

@shankar524
Created January 24, 2019 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankar524/f13dacfa644edf30a18e9855aea88d30 to your computer and use it in GitHub Desktop.
Save shankar524/f13dacfa644edf30a18e9855aea88d30 to your computer and use it in GitHub Desktop.
Curious Number A n-digit number is said to be curious if the last n digits of its square are the same as the original number. For example, 25^2 = 625 and 76^2 = 5776. (Curious numbers are also known as automorphic numbers.) An example of 9 digit number: 212890625^2 = 45322418212890625 Write a program to find all Curious Numbers of 1 to 10 digits.
def square(number=0)
number ** 2
end
def is_curious_number(number)
diff = square(number) - number
last_digits=diff % (10**(number.digits.count))
if(last_digits==0)
return true
else
return false
end
end
#checking
puts is_curious_number(25) #=>true
puts is_curious_number(26) #=>false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment