|
||
Title: copy paste problem Post by alexeigor on Jan 20th, 2011, 8:39am 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 |
||
Title: Re: copy paste problem Post by towr on Jan 20th, 2011, 9:52am [hide]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); } [/hide] |
||
Title: Re: copy paste problem Post by birbal on Jan 25th, 2011, 5:20am on 01/20/11 at 09:52:27, towr wrote:
Nice solution :). Can you explain how did you reach at this solution ? ( As in by mere observation of the series or any mathematical way ? ) |
||
Title: Re: copy paste problem Post by towr on Jan 25th, 2011, 9:04am By mere observation. For good measure, it really ought to be proved correct. Maybe I'll get around to that eventually. |
||
Title: Re: copy paste problem Post by birbal on Jan 27th, 2011, 4:28am i think we can form a recurrence relation and solve it. Need to work out what exactly is to be done. |
||
Title: Re: copy paste problem Post by Grimbal on Jan 28th, 2011, 8:40am 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. |
||
Title: Re: copy paste problem Post by towr on Jan 28th, 2011, 11:48am 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). |
||
Powered by YaBB 1 Gold - SP 1.4! Forum software copyright © 2000-2004 Yet another Bulletin Board |