Skip to content

Instantly share code, notes, and snippets.

@micedreams
Created November 12, 2023 11:25
Show Gist options
  • Save micedreams/c2fb4d66b2fd36bf92816abd499a661f to your computer and use it in GitHub Desktop.
Save micedreams/c2fb4d66b2fd36bf92816abd499a661f to your computer and use it in GitHub Desktop.
palindrome
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