Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Finding Frobenius Number of a Set
- testSet = [6, 9, 20] # Set to test
- def findGCF(s): # Finds greatest common factor of a list
- factors = list(range(1,max(s)+1))
- for i in s:
- temp = []
- for f in factors:
- temp.append(f)
- for k in temp:
- if i%k!=0:
- factors.remove(k)
- return max(factors)
- print("These numbers can\'t be created with the numbers in your set:")
- gcf = findGCF(testSet)
- if gcf>1:
- print("Any number that is not divisible by %s" % gcf)
- for i in range(len(testSet)):
- testSet[i]/=gcf
- consecPoss = 0
- num = 0
- impossNums = []
- while consecPoss < min(testSet):
- impossible = True
- num+=1
- if num < min(testSet):
- impossNums.append(num)
- else:
- for n in testSet:
- if (num >= n) and ((num - n) not in impossNums):
- impossible = False
- if impossible:
- impossNums.append(num)
- consecPoss = 0
- else:
- consecPoss += 1
- for i in impossNums:
- printNum = i*gcf
- print(printNum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement