Skip to content

Instantly share code, notes, and snippets.

@t-eckert
Created May 11, 2021 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t-eckert/3096966b95cb8a2d8854f65de064dc37 to your computer and use it in GitHub Desktop.
Save t-eckert/3096966b95cb8a2d8854f65de064dc37 to your computer and use it in GitHub Desktop.
Same digits
"""
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