This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Curious Number | |
# 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 | |
#Q. Complete the code to return all the curious numbers for n digit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Curious Number | |
# 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 | |
#Q. Complete the code to return all the curious numbers for n digit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Curious Number | |
# 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 | |
#Q. Complete the code to return all the curious numbers for n digit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Curious Number | |
# 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 | |
#Q. Complete the code to return all the curious numbers for n digit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#require 'byebug' | |
class HappyNumberEngine | |
attr_accessor :visited_numbers | |
def initialize | |
@visited_numbers = [] # the container that collects the visited number. | |
end | |
def happy_number_minner(num) | |
if need_squared?(num) # checking if squaring needed . Allow squaring except for 1. |