Print maximum number of A’s using given four keys in Python
In this tutorial, we will learn how to print the maximum numbers of A’s in python, Let’s get started!
Imagine you have an uncommon console with the accompanying keys:
Key 1: Prints ‘A’ on screen
Key 2: (Ctrl+A): Select All
Key 3: (Ctrl+C): Copy
Key 4: (Ctrl+V): Print
On the off chance that we will just press the console for N times (with the over four keys), we need to deliver the greatest quantities of A’s. In other words, the info boundary is N (No. of keys that we press), the yield is M (No. of As that we can create).
Examples:-
Input: N = 4 Output: 4(A, A, A, A)
We can get 4 A’s on-screen by squeezing the previously mentioned key grouping.
Input: N = 6 Output: 6 (A, A, A, Ctrl-A, Ctrl C, Ctrl V)
We can get 6 A’s on-screen by squeezing the previously mentioned key grouping.
Input: N = 12 Output: 36 (A, A, A, A, Ctrl-A, Ctrl C, Ctrl V, Ctrl V, Ctrl-A, Ctrl C, Ctrl V , Ctrl V)
We can get 12 A’s on-screen by squeezing the previously mentioned key grouping.
There are some points to be noted before further processing
- For Number less then 7, the output is Number itselffor any keystroke n, we will need to choose between
- press Ctrl+V once after copying the A’s obtained by n-3 keystrokes.
- press Ctrl+V twice after copying the A’s obtained by n-4 keystrokes.
- press Ctrl+V thrice after copying the A’s obtained by n-5 keystrokes.
Let’s code now
#length string for N keystrokes def max_a(N): if (N <= 6): # For Number less then 7, the output is Number itself return N store = [0] * N # An array to store result for n in range(1, 7): store[n - 1] = n for n in range(7, N + 1): store[n - 1] = max(1 * store[n - 3],2 * store[n - 4],3 * store[n - 5],4 * store[n - 6]); return store[N - 1]
Now let’s run our program and check if it works
N= 10
max_a(10)
20
N = 15
max_a(15)
81
Now as we can see our program worked let’s create a loop to find out “The most extreme number of A’s in N keystrokes”
if __name__ == "__main__": for N in range(20,26): print("The most extreme number of A's in", N, " keystrokes is ", max_a(N))
The most extreme number of A's in 20 keystrokes is 324 The most extreme number of A's in 21 keystrokes is 432 The most extreme number of A's in 22 keystrokes is 576 The most extreme number of A's in 23 keystrokes is 768 The most extreme number of A's in 24 keystrokes is 1024 The most extreme number of A's in 25 keystrokes is 1296
I hope you liked it
Here is my other work please have a look
Leave a Reply