DEV Community

Discussion on: Daily Challenge #183 - Automorphic Numbers

Collapse
 
candidateplanet profile image
lusen / they / them πŸ³οΈβ€πŸŒˆπŸ₯‘

Python

def auto_morphic(num):
  return str(num*num)[-1] == str(num)[-1]
Collapse
 
candidateplanet profile image
lusen / they / them πŸ³οΈβ€πŸŒˆπŸ₯‘

More tests:

print(auto_morphic(13), False)
print(auto_morphic(25), True)
print(auto_morphic(6), True)
print(auto_morphic(625), True)
print(auto_morphic(225), True)
print(auto_morphic(1), True)
print(auto_morphic(2), False)
print(auto_morphic(3), False)
print(auto_morphic(4), False)
print(auto_morphic(5), True)
print(auto_morphic(6), True)
print(auto_morphic(7), False)
print(auto_morphic(8), False)
print(auto_morphic(9), False)
print(auto_morphic(10), True)
print(auto_morphic(11), True)
print(auto_morphic(12), False)
Collapse
 
j_saikiranreddy profile image
J.SaiKiranReddy

11 should be false?

Thread Thread
 
candidateplanet profile image
lusen / they / them πŸ³οΈβ€πŸŒˆπŸ₯‘

11 * 11 is 121, which ends in 1 hence return True.

Thread Thread
 
candidateplanet profile image
lusen / they / them πŸ³οΈβ€πŸŒˆπŸ₯‘

oops - i interpreted the problem incorrectly as only the one’s digits needing to match.