Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- I have to find the 3 digits A,B and C, so the number:
- ABC = 100A + 10B + C = A! + B! + C!
- Example: For A = 2, B = 5, C = 6, we want: 256 = 2! + 5! + 6!, which is not true
- Note: NONE OF THE 3 DIGITS (A, B and C) IS EQUAL TO 0
- '''
- # Factorial Function
- def factorial(n):
- if n >= 1:
- return n * factorial(n-1)
- return 1
- # MAIN FUNCTION
- print("I have to find the 3 digits A,B and C, so the number:")
- print("ABC = 100A + 10B + C = A! + B! + C!")
- print("Example: For A = 2, B = 5, C = 6, we want: 256 = 2! + 5! + 6!, which is not true")
- print("Note: NONE OF THE 3 DIGITS (A, B and C) IS EQUAL TO 0")
- print()
- print()
- counterOfArrangements = 0
- threeDigitNumberIJK = 0
- sum = 0
- solutionList = []
- counterWhenIJKBiggerThanSumOfFactorials = 0
- for i in range(1, 10):
- for j in range(1, 10):
- for k in range(1, 10):
- counterOfArrangements += 1
- threeDigitNumberIJK = 100 * i + 10 * j + k
- sum = factorial(i) + factorial(j) + factorial(k)
- # IF I FIND AN ARRANGEMENT = SOLUTION OF THE PROBLEM
- if threeDigitNumberIJK == sum:
- print(str(counterOfArrangements) + ": " + str(threeDigitNumberIJK) + " = " + str(sum) + " , SOLUTION")
- solutionList.append(i)
- solutionList.append(j)
- solutionList.append(k)
- # ELIF - CASE (When (ABC = 100A + 10B + C) > A! + B! + C!)
- elif threeDigitNumberIJK > sum:
- print(str(counterOfArrangements) + ": " + str(threeDigitNumberIJK) + " > " + str(sum) + " , NOT SOLUTION")
- counterWhenIJKBiggerThanSumOfFactorials += 1
- # ELSE - CASE
- else:
- print(str(counterOfArrangements) + ": " + str(threeDigitNumberIJK) + " < " + str(sum) + " , NOT SOLUTION")
- # Printing out the solutions and the statistics of the survey
- # 1. Firstly, I will find out how many solutions are there
- # I remember that my solutionList is in the following form:
- # solutionList = [solution1I, solution1J, solution1K, solution2I, solution2J, solution2K, ......, solutionNI, solutionNJ, solutionNK]
- # The length can be divided with 3 - Solutions are sets of 3 consecutive numbers in the list
- print()
- print()
- step = 3
- for i in range(0, len(solutionList), step):
- print("Solution " + str(i+1) + ": Numbers " + str(solutionList[i]) + ", " + str(solutionList[i+1]) + ", " + str(solutionList[i+2]))
- # print("Because: " + str(100 * solutionList[i] + 10 * solutionList[i+1] + solutionList[i+2]) + " = " + str(solutionList[i]) + "! + " + str(solutionList[i+1]) + "! + " + str(solutionList[i+2]) + " = " + str(factorial(solutionList[i]))) + " + " + str(solutionList[i+2] + " = " + str(factorial(solutionList[i+1])) + " + " + str(solutionList[i+2]) + " = " + str(factorial(solutionList[i+2])))
- first = solutionList[i]
- second = solutionList[i+1]
- third = solutionList[i+2]
- print(" Because: " + str(100 * first + 10 * second + third) + " = " + str(first) + "! + " + str(second) + "! + " + str(third) + "! = " + str(factorial(first)) + " + " + str(factorial(second)) + " + " + str(factorial(third)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement