Given keyboard with 4 keys (A, ctrl+A, ctrl+C, ctrl+V), find max number of letters you can type with the given number of keystrokes

#!/usr/bin/env python
 
def maxkeys(n, table):
    if n <= 6:
        table.extend(range(n + 1))
    else:
        maxkeys(n - 1, table)
        table.append(max([v * (n - x - 1) for x, v in enumerate(table) if x <= n - 3]))


t = []
maxkeys(22, t)
print(t)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s