Skip to content

Instantly share code, notes, and snippets.

@agoodkind
Created June 19, 2018 18:02
Show Gist options
  • Save agoodkind/bbc25c713b54f0a29b292084c265da88 to your computer and use it in GitHub Desktop.
Save agoodkind/bbc25c713b54f0a29b292084c265da88 to your computer and use it in GitHub Desktop.
def colorfulNumbers(A):
numbers = set()
stringifiedNumber = str(A)
case = addDigits(numbers, stringifiedNumber)
if case is 0:
return case
# print(numbers)
lengthOfNumber = len(stringifiedNumber)
case = calculateNumbers(numbers, lengthOfNumber, stringifiedNumber)
# print(numbers)
return case #base case
def addDigits(numbers, stringifiedNumber):
for digit in stringifiedNumber:
if digit in numbers:
return 0
else:
numbers.add(digit)
def calculateNumbers(numbers, length, stringifiedNumber):
for i in range(2, length+1):
for j in range(0, length-i+1):
current = stringifiedNumber[j:j+i] #j + i = j + 2 = 0 + 2 = 2
# print(current)
product = calculateProducts(current)
# print(current)
# print(product)
if product in numbers:
# print(product)
return 0
else:
numbers.add(product)
return 1
def calculateProducts(num):
# print(num)
product = 1
for k in num:
product *= int(k) # this should be the current character not the whole number
return str(product)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment