wu :: forums
« wu :: forums - copy paste problem »

Welcome, Guest. Please Login or Register.
May 7th, 2024, 12:50pm

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: towr, SMQ, ThudnBlunder, Grimbal, Eigenray, Icarus, william wu)
   copy paste problem
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: copy paste problem  (Read 1724 times)
alexeigor
Newbie
*





   


Posts: 45
copy paste problem  
« on: Jan 20th, 2011, 8:39am »
Quote Quote Modify 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: male
Posts: 13730
Re: copy paste problem  
« Reply #1 on: Jan 20th, 2011, 9:52am »
Quote Quote Modify 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: male
Posts: 250
Re: copy paste problem  
« Reply #2 on: Jan 25th, 2011, 5:20am »
Quote Quote Modify 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 Smiley. 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: male
Posts: 13730
Re: copy paste problem  
« Reply #3 on: Jan 25th, 2011, 9:04am »
Quote Quote Modify 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: male
Posts: 250
Re: copy paste problem  
« Reply #4 on: Jan 27th, 2011, 4:28am »
Quote Quote Modify 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: male
Posts: 7527
Re: copy paste problem  
« Reply #5 on: Jan 28th, 2011, 8:40am »
Quote Quote Modify 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: male
Posts: 13730
Re: copy paste problem  
« Reply #6 on: Jan 28th, 2011, 11:48am »
Quote Quote Modify 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
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board