From bf5a1921e776a81a6f97835f6fb9ed98d77b91b9 Mon Sep 17 00:00:00 2001 From: Ambesawi Date: Thu, 12 Oct 2023 21:06:26 +0000 Subject: [PATCH] 0-minoperations.py --- 0-minoperations.py | 28 ++++++++++++++++++++++ 0x02-minimum_operations/0-minoperations.py | 28 ++++++++++++++++++++++ 0x02-minimum_operations/README.md | 1 + 3 files changed, 57 insertions(+) create mode 100644 0-minoperations.py create mode 100644 0x02-minimum_operations/0-minoperations.py create mode 100644 0x02-minimum_operations/README.md 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