Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions PYTHON/ProblemsAndSolutions/collatz_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# collatz_sequence.py
"""
Description:
This is a mathematical phenomenon whereby starting with any number,
it will always stop at 1 using the following mathematical concepts.
base number = ?
if the base number is even; divide it by 2, and the answer,
reassign it to the base number
else 3 * base number + 1
For more explanation:
Collatz conjecture. (2022, October 9). In Wikipedia. https://en.wikipedia.org/wiki/Collatz_conjecture
"""


def collatz(number: int) -> int:
# It stops when the number equals 1.
while number != 1:
if number % 2 == 0:
number //= 2
else:
number = 3 * number + 1
print(number, end=" ")


response: int = int(input("Enter a number: ").strip())
collatz(response)
Empty file.
17 changes: 17 additions & 0 deletions PYTHON/ProblemsAndSolutions/factorial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# fibonacci.py
"""
Factorial is a mathematical function of f(n!):
Mathematical formulae: n * (n - 1)!
Further explanation: Factorial. (2022, October 4).
In Wikipedia. https://en.wikipedia.org/wiki/Factorial
"""


def factorial(starting_number: int) -> int:
if starting_number == 0 or starting_number == 1:
return 1

# This is a recursive call: where it multiplies the previous with now - 1
fib = starting_number * factorial(starting_number - 1)
return fib

Empty file.