Author |
Topic: copy paste problem (Read 1748 times) |
|
alexeigor
Newbie


Posts: 45
|
 |
copy paste problem
« on: Jan 20th, 2011, 8:39am » |
Quote Modify
|
Write a program to print the sequence of keystrokes such that it generates the maximum number of character 'A's. You are allowed to use only 4 keys: A, Ctrl+A, Ctrl+C and Ctrl+V. Only N keystrokes are allowed. All Ctrl+ characters are considered as one keystroke, so Ctrl+A is one keystroke. For example, the sequence A, Ctrl+A, Ctrl+C, Ctrl+V generates two A's in 4 keystrokes. * Ctrl+A is Select All * Ctrl+C is Copy * Ctrl+V is Paste
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
    
 Some people are average, some are just mean.
Gender: 
Posts: 13730
|
 |
Re: copy paste problem
« Reply #1 on: Jan 20th, 2011, 9:52am » |
Quote Modify
|
function foo(n) { a = [0,1,2,3,4,5,6,9,12,16,20,27,36,48,64,81]; if ( n <= 15 ) return a[n]; else n -= 11; d = n % 5; f = (n-d)/5; return a[d+11] << (2*f); }
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
birbal
Full Member
  

Gender: 
Posts: 250
|
 |
Re: copy paste problem
« Reply #2 on: Jan 25th, 2011, 5:20am » |
Quote Modify
|
on Jan 20th, 2011, 9:52am, towr wrote:function foo(n) { a = [0,1,2,3,4,5,6,9,12,16,20,27,36,48,64,81]; if ( n <= 15 ) return a[n]; else n -= 11; d = n % 5; f = (n-d)/5; return a[d+11] << (2*f); } |
| Nice solution . Can you explain how did you reach at this solution ? ( As in by mere observation of the series or any mathematical way ? )
|
|
IP Logged |
The only thing we have to fear is fear itself!
|
|
|
towr
wu::riddles Moderator Uberpuzzler
    
 Some people are average, some are just mean.
Gender: 
Posts: 13730
|
 |
Re: copy paste problem
« Reply #3 on: Jan 25th, 2011, 9:04am » |
Quote Modify
|
By mere observation. For good measure, it really ought to be proved correct. Maybe I'll get around to that eventually.
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
birbal
Full Member
  

Gender: 
Posts: 250
|
 |
Re: copy paste problem
« Reply #4 on: Jan 27th, 2011, 4:28am » |
Quote Modify
|
i think we can form a recurrence relation and solve it. Need to work out what exactly is to be done.
|
|
IP Logged |
The only thing we have to fear is fear itself!
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
    

Gender: 
Posts: 7527
|
 |
Re: copy paste problem
« Reply #5 on: Jan 28th, 2011, 8:40am » |
Quote Modify
|
One thing still bothers me. As I know it, - ctrl-C copies the selected text to the paste buffer without unselecting it - ctrl-V replaces the selected text with the paste buffer So, the sequence A, ctrl-A, ctrl-C leaves one A selected, and ctrl-V replaces it with the A from the paste buffer. It doesn't result in 2 A's. I daily duplicate lines of text by selecting the lines and pressing ctrl-C, ctrl-V, ctrl-V. The first ctrl-V having the effect of unselecting the selection.
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
    
 Some people are average, some are just mean.
Gender: 
Posts: 13730
|
 |
Re: copy paste problem
« Reply #6 on: Jan 28th, 2011, 11:48am » |
Quote Modify
|
It would depend on the editor. In any case, you can consider that you are given 4 operations to work with, and "replace" is not among them (nor implied by their description).
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
|