Skip to content

Instantly share code, notes, and snippets.

View okevese's full-sized avatar

Oke Vese okevese

  • Port Harcourt, Nigeria
View GitHub Profile
@hokevins
hokevins / REACTO - Palindrome Chain Length Problem.md
Created March 2, 2018 01:19
REACTO - Palindrome Chain Length Problem

REACTO - Palindrome Chain Length Problem

(From Codewars: 5kyu problem.)

Number is a palindrome if it is equal to the number with digits in reversed order. For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes.

Write a method palindrome_chain_length which takes a positive number and returns the number of special steps needed to obtain a palindrome. The special step is: "reverse the digits, and add to the original number". If the resulting number is not a palindrome, repeat the procedure with the sum until the resulting number is a palindrome.

If the input number is already a palindrome, the number of steps is 0.