-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
this is alx project for intervew |