Created
March 29, 2020 13:36
-
-
Save onosi/8c474bdfd7912af81a7629fd0005e3dc to your computer and use it in GitHub Desktop.
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
# declear variables | |
numbers = [] | |
ope = ["*", "+", "-", "/", ""] | |
1000.upto(9999) do |n| | |
numbers << n | |
end | |
for num in numbers | |
a = num.to_s.chars | |
for i in ope | |
for j in ope | |
for k in ope | |
val = a[0] + i + a[1] + j + a[2] + k + a[3] | |
next unless val.length > 4 | |
next if val.include?("/0") | |
# remove octal digits | |
while val.match(/[*+\-\/]0\d+/) | |
val.gsub!(/[*+\-\/]0\d/){ |octal| octal.slice!("0") } | |
end | |
puts num if num.to_s.reverse == eval(val).to_s | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment