-
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
1 parent
5b03d35
commit 2657f85
Showing
1 changed file
with
26 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,26 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Minimum Operations | ||
""" | ||
|
||
|
||
def minOperations(n): | ||
""" | ||
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. | ||
Given a number n, write a method that calculates the fewest number of | ||
operations needed to result in exactly n H characters in the file. | ||
""" | ||
if n <= 1: | ||
return 0 | ||
|
||
for i in range(2, n + 1): | ||
if n % i == 0: | ||
return minOperations(int(n / i)) + i | ||
return n | ||
|
||
|
||
# print(f"Min number of operations to reach {4} char: {minOperations(4)}") | ||
# print(f"Min number of operations to reach {12} char: {minOperations(12)}") | ||
# print(f"Min number of operations to reach {9} char: {minOperations(9)}") |