diff --git a/0-minoperations.py b/0-minoperations.py new file mode 100644 index 0000000..b95880d --- /dev/null +++ b/0-minoperations.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +""" +In a text file, there is a single character H. Your text editor +can execute only two operations in this file: `Copy All` and `Paste`. + +@TODO: + Deines a method that calculates the fewest number of operations + needed to result in exactly n H characters in the file. +""" + + +def minOperations(n): + """ + Calculates the fewest number of operations + needed to result in exactly n H characters in the file. + Args: + n (int): length of letter `H` required in the file + Returns: + (int): number of minimum operations if possible otherwise 0 + """ + minimumOperations = 2 + totalOperations = 0 + while n > 1: + while n % minimumOperations == 0: + totalOperations += minimumOperations + n /= minimumOperations + minimumOperations += 1 + return totalOperations diff --git a/0x02-minimum_operations/0-minoperations.py b/0x02-minimum_operations/0-minoperations.py new file mode 100644 index 0000000..b95880d --- /dev/null +++ b/0x02-minimum_operations/0-minoperations.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 +""" +In a text file, there is a single character H. Your text editor +can execute only two operations in this file: `Copy All` and `Paste`. + +@TODO: + Deines a method that calculates the fewest number of operations + needed to result in exactly n H characters in the file. +""" + + +def minOperations(n): + """ + Calculates the fewest number of operations + needed to result in exactly n H characters in the file. + Args: + n (int): length of letter `H` required in the file + Returns: + (int): number of minimum operations if possible otherwise 0 + """ + minimumOperations = 2 + totalOperations = 0 + while n > 1: + while n % minimumOperations == 0: + totalOperations += minimumOperations + n /= minimumOperations + minimumOperations += 1 + return totalOperations diff --git a/0x02-minimum_operations/README.md b/0x02-minimum_operations/README.md new file mode 100644 index 0000000..32b06df --- /dev/null +++ b/0x02-minimum_operations/README.md @@ -0,0 +1 @@ +this is alx project for intervew \ No newline at end of file