Created
November 12, 2023 11:25
-
-
Save micedreams/c2fb4d66b2fd36bf92816abd499a661f to your computer and use it in GitHub Desktop.
palindrome
This file contains 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
output = (0..).reduce([]) do |accumulator, number| | |
binary = number.to_s(2) | |
reverse_binary = binary.reverse.sub!(/^0*/, "") | |
accumulator << number if binary == reverse_binary && number.to_s == number.to_s.reverse | |
break accumulator if accumulator.count >= 10 | |
accumulator | |
end | |
puts output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment