## Welcome to BrainDen.com - Brain Teasers Forum

 Welcome to BrainDen.com - Brain Teasers Forum. Like most online communities you must register to post in our community, but don't worry this is a simple free process. To be a part of BrainDen Forums you may create a new account or sign in if you already have an account. As a member you could start new topics, reply to others, subscribe to topics/forums to get automatic updates, get your own profile and make new friends. Of course, you can also enjoy our collection of amazing optical illusions and cool math games. If you like our site, you may support us by simply clicking Google "+1" or Facebook "Like" buttons at the top. If you have a website, we would appreciate a little link to BrainDen. Thanks and enjoy the Den :-)
Guest Message by DevFuse

# Broken keyboard

12 replies to this topic

Senior Member

• Members
• 1702 posts
• Gender:Female

Posted 06 April 2014 - 02:00 AM

Imagine you have a special keyboard with the following keys:

1. A
2. Ctrl+A
3. Ctrl+C
4. Ctrl+V

where CTRL+A, CTRL+C, CTRL+V each acts as one function key for “Select All”, “Copy”, and “Paste” operations respectively.

If you can only press the keyboard for N times (with the above four keys), please write a program to produce maximum numbers of A. If possible, please also print out the sequence of keys.

That is to say, the input parameter is N (No. of keys that you can press), the output is M (No. of As that you can produce).

Example:-
For N = 8 the answer is M = 9, where S = { A, A, A, CTRL+A, CTRL+C, CTRL+V, CTRL+V, CTRL+V }.

For N = 9 the answer is M = 12, where S = { A, A, A, CTRL+A, CTRL+C, CTRL+V, CTRL+V, CTRL+V, CTRL+V }.

• 1

### #2 Joe's Student

Joe's Student

Senior Member

• Members
• 787 posts

Posted 07 April 2014 - 04:11 AM

A quick solution. Bear in mind it's 4am here and this is my first post on BD in years, so forgive the terrible formatting!

Spoiler for Not sure about an actual code, but it'll look something like this.

• 0

### #3 bonanova

bonanova

bonanova

• Moderator
• 5918 posts
• Gender:Male
• Location:New York

Posted 07 April 2014 - 08:24 AM

A quick solution. Bear in mind it's 4am here and this is my first post on BD in years, so forgive the terrible formatting!

Spoiler for Not sure about an actual code, but it'll look something like this.

Hi JS, and welcome (back) to the Den!

I was thinking along the same lines

Spoiler for But

• 0
The greatest challenge to any thinker is stating the problem in a way that will allow a solution.
- Bertrand Russell

### #4 Joe's Student

Joe's Student

Senior Member

• Members
• 787 posts

Posted 07 April 2014 - 01:48 PM

Hi JS, and welcome (back) to the Den!

I was thinking along the same lines

Spoiler for But

Woke up this morning and came here to post exactly this! Beat me to it! I'll work some more on it

• 0

### #5 Joe's Student

Joe's Student

Senior Member

• Members
• 787 posts

Posted 07 April 2014 - 05:08 PM

Spoiler for More thoughts

Also excuse the messiness again, working on it whilst I'm writing is never a good idea! Btw, is there a neat way of indicating the less-than-or-equal symbol?

Edited by Joe's Student, 07 April 2014 - 05:10 PM.

• 0

Senior Member

• Members
• 1702 posts
• Gender:Female

Posted 07 April 2014 - 06:03 PM

I am unsure about neat but since these are integers

Spoiler for you could...

• 0

### #7 LVan Toren

LVan Toren

Newbie

• Members
• 13 posts

Posted 14 April 2014 - 04:14 PM

Spoiler for More thoughts

Also excuse the messiness again, working on it whilst I'm writing is never a good idea! Btw, is there a neat way of indicating the less-than-or-equal symbol?

Spoiler for Some remarks

• 0

### #8 LVan Toren

LVan Toren

Newbie

• Members
• 13 posts

Posted 14 April 2014 - 04:36 PM

Spoiler for a solution

• 0

### #9 LVan Toren

LVan Toren

Newbie

• Members
• 13 posts

Posted 14 April 2014 - 04:44 PM

Spoiler for list of N and M, another puzzle

• 0

### #10 Joe's Student

Joe's Student

Senior Member

• Members
• 787 posts

Posted 15 April 2014 - 01:18 AM

I believe we have different interpretations of the mechanics of this problem.

Spoiler for Some remarks

This wasn't my understanding. I assumed that the first Ctrl+V replaces the three typed A's since they're still selected, much like everyday word-processing software. In otherwords:

- Ctrl+A selects
- Ctrl+C copies
- The three A's are still selected
- Ctrl+V replaces the selected A's with pasted ones.

That was the basis for my work, though your interpretation may well be correct. Maybe BMAD could clarify exactly how the process works?

Edit: From BMAD's examples it looks to be the case that the typed A's are indeed replaced. However, your interpretation would make an equally interesting puzzle!

Edited by Joe's Student, 15 April 2014 - 01:28 AM.

• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users