[PYTHON] Mathematical puzzle to train the programmer's brain Q01 "Palindrome in decimal"

Code

def kai(i): #Determine if it is a palindrome
    return str(i)[::-1] == str(i)
    
dec = 11
while not(kai(dec) and kai(bin(dec)[2:]) and kai(oct(dec)[2:])):
    dec += 2 #You only have to search for odd numbers (see text)
print(dec)

Supplement

n-ary

Binary 0bNN Eighth number 0oNN Hexagon 0xNN

Convert to binary bin (NN) Convert to octal number oct (NN) Convert to hexadecimal hex (NN)

Convert binary numbers to decimal numbers int (BIN, 2) Convert 8 to decimal int (OCT, 2) Convert hexadecimal to decimal int (HEX, 2)

Reverse the string

str[::-1]

Reference https://redcat-prog.hatenadiary.org/entry/20111104/1320395840

Recommended Posts

Mathematical puzzle to train the programmer's brain Q01 "Palindrome in decimal"
Mathematical puzzle to train the programmer's brain Q04 Carving a stick
Mathematical puzzle to train the programmer's brain Q03 Turn the card over
Mathematical puzzle to train the programmer's brain Q06 (modified version) Collatz's prediction
Mathematical puzzles that train the programmer's brain Q08 Excellent cleaning robot
Mathematical puzzles that train the programmer's brain Q05 Still paying cash?
People memorize learned knowledge in the brain, how to memorize learned knowledge in machine learning
Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
Paper: Music processing in the brain
Programming to fight in the world-Chapter 4
Cython to try in the shortest
Programming to fight in the world ~ 5-2
I tried to train the RWA (Recurrent Weighted Average) model in Keras