|
| 1 | +# MIT License |
| 2 | +# |
| 3 | +# Copyright (c) 2021 [FacuFalcone] |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +from Permutations.Factorial import Factorial as F |
| 24 | + |
| 25 | + |
| 26 | +def SimpleCombinatory(): |
| 27 | + """ |
| 28 | + Calculate the simple combination of K elements from N total elements. |
| 29 | + Only Nature is important. |
| 30 | + """ |
| 31 | + try: |
| 32 | + print("\n###### Simple Combinatory #######") |
| 33 | + print("C(n, k)") |
| 34 | + numberN = int(input("Value for n: ")) |
| 35 | + numberK = int(input("Value for k: ")) |
| 36 | + n = F(numberN) |
| 37 | + k = F(numberK) * F((numberN - numberK)) |
| 38 | + print(f"Simple Combination of C({numberN},{numberK}): ") |
| 39 | + print(f"Formula: {n}! / ( {k}! * ({n-k})! )") |
| 40 | + print(f"Result: {n/k}") |
| 41 | + except Exception as e: |
| 42 | + print(f"Error: {e}") |
| 43 | + |
| 44 | + |
| 45 | +def CompoundCombinatory(): |
| 46 | + """ |
| 47 | + Calculate the simple combination of K elements from N total elements, being able to repeat. |
| 48 | + Only Nature is important. |
| 49 | + """ |
| 50 | + print("\n###### Compound Combinatory #######") |
| 51 | + try: |
| 52 | + print("C'(n, k)") |
| 53 | + numberN = int(input("Value for n: ")) |
| 54 | + numberK = int(input("Value for k: ")) |
| 55 | + n = numberN + numberK - 1 |
| 56 | + k = F(numberN - 1) * F(numberK) |
| 57 | + print(f"Compound Combination of C'({numberN},{numberK}):") |
| 58 | + print(f"Formula: ({numberN} + {numberK} - 1) / ({numberN} - 1)!{numberK}!") |
| 59 | + print(f"Result: {F(n)/k}") |
| 60 | + except Exception as e: |
| 61 | + print(f"Error: {e}") |
0 commit comments