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
| # This algorithm only works upto 23 digits. | |
| # As I found 10**9942066 is the maximum calculation ruby can perform without overflowing into infinity | |
| # ie, any number greater than 109942066 will overflow to infinity. | |
| class CuriousNumber | |
| def calculate(i) | |
| a = 5**(2**i) % 10**i | |
| b = (10**i)+1 - a |
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' | |
| puts "Enter a number:" | |
| number = gets.chomp.to_i | |
| #method takes sum of square and an array | |
| def happy square_sum, array=[] | |
| #gets individual number in an array | |
| num = square_sum.digits |