Kaprekar's Number

Note: This problem needs knowledge of topics you haven't covered yet. Reading List

Problem Statement

9 is a Kaprekar number since
9 ^ 2 = 81 and 8 + 1 = 9

297 is also Kaprekar number since
297 ^ 2 = 88209 and 88 + 209 = 297.

In short, for a Kaprekar number k with n-digits, if you square it and add the right n digits to the left n or n-1 digits, the resultant sum is k.

Find if a given number is a Kaprekar number.


Use Fixnum.to_s to convert the number into a string to do digit operations.
Use String.to_i to convert back to integer.

Output Window

Reading list for this problem

You are yet to work on:

Congratulations, guest!

% of the book completed