Created
May 11, 2021 17:24
-
-
Save t-eckert/3096966b95cb8a2d8854f65de064dc37 to your computer and use it in GitHub Desktop.
Same digits
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
""" | |
Given an integer n, return true if n^3 and n have the same set of digits. | |
""" | |
def same_digits(n: int) -> bool: | |
return set(str(n)) == set(str(n**3)) | |
def print_and_assert(expected, actual): | |
print("expected = " + str(expected)) | |
print("actual = " + str(actual) + "\n") | |
assert expected == actual | |
if __name__ == "__main__": | |
print_and_assert(True, same_digits(1)) | |
print_and_assert(True, same_digits(10)) | |
print_and_assert(True, same_digits(251894)) | |
print_and_assert(False, same_digits(251895)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment