Skip to content

Commit

Permalink
0-minoperations.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambesawi committed Oct 12, 2023
1 parent 4bb3a64 commit bf5a192
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 0-minoperations.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions 0x02-minimum_operations/0-minoperations.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions 0x02-minimum_operations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is alx project for intervew

0 comments on commit bf5a192

Please sign in to comment.