Riddle - Make "the sentence" appear 100 times

I want to know what the sentence is, because it’s gotta be pretty darn important to bear repeating 99 times…

I’m not confused. I use AutoCAD’s internal text editor at least as much as I use, say, Microsoft Word. For me, it is pretty standard. And my text ends up in a format usable anywhere, too.

I think the OP makes it pretty clear that:

None of those four actions are pressing ctrl-a to select all text so obviously you can’t do that, I can’t really see what the confusion is there. Also, holding down ctrl-v isn’t listed as an available action, just “Paste the copied lines”. I know the OP hasn’t returned yet but as far as I can tell any answer that does something not listed in the four actions available to you is invalid, so I would say that Lodovic has given the best answer thus far.

Ctrl-V IS pasting the copied lines. How many people actually Right-Click, scroll to Paste, and Click when they are in a hurry with a repetitive task instead of simply hitting Ctrl-V with two fingers of the left hand?

However, my ISPF solution does not violate any of the “rules” in the OP (“B” and “A” are the appropriate commands for pasting in ISPF), so we are back to about four seconds if we include typing the original sentence. :smiley:

Except the rules in the OP that specify the time required for each action.

I know that ctrl-v performs the same task, but I believe (and i’m sure the OP will correct me if this is wrong) that the idea of the question isn’t to find as many shortcuts as you can using various editors but to imagine a game with just 4 buttons to perform the 4 functions. One button to write the sentence, this costs “3”. One to copy selected lines, this costs “2”. One to paste selected lines, this costs “2”. And one to select lines, this costs “1” per line you wish to select. In my opinion anything beyond those simple tasks is outside the scope of the question.

Without looking, I came up with the same answer as Ludovic (48 seconds).
I have a feeling that’s the minimum.

I didn’t notice the exactly at first so came up with this formula that helped me -

if you have n sentences already and need at least p on the page, it will take (n + 2 + ceiling((p-n)/n)) seconds to finish.

Also, with b lines in the buffer, it takes 2*ceiling((p-n)/b), assuming no further selection.

This hits minimums in the 10-20 lines range at 29 or 30 seconds. Since 10 lines is the first value that’s near the minimum, and it also will fit exactly, it seems like the best result. With n=10, values for b that beat this are >6, so it seems unlikely that building a large buffer until you get to 10 lines will be useful.

The minimum time to get 4 lines is 12 seconds, but you get the largest buffer with the ‘write two’ method. (This is also possible to figure using p=10 above and reducing again; n=2, b=2 works best.

OK, eight seconds in ISPF.

Write the sentence (and if need be, move to the next line): 3 seconds

Type “C” on the first line: 1 second

Twiddle thumbs: 2 seconds

Type “B99” on the second line: 2 seconds

Let’s say you have n lines written on the screen. If you copy these n lines and then paste them 100/n - 1 times, it will take you the following time:
Select n lines: n seconds
Copy n lines: 2 seconds
Paste n lines 100/n - 1 times: 200/n - 2 seconds
for a total of 200/n + n seconds. This function reaches a minimum at n = 14.14, but of course you need n to be an integer factor of 100. The integer factors of 100 closest to 14.14 are n = 10 and n = 20, and in both cases you’d need 30 seconds. Now, 18 seconds (Ludovic’s solution) is the minimum number of seconds to write 10 lines, while 26 seconds is the minimum necessary to write 20 lines (W=write, S=select, C=copy, P=paste):
W2: 6 seconds
S2: 2 seconds
C2: 2 seconds
P2: 2 seconds
S4: 4 seconds
C4: 2 seconds
4xP4: 8 seconds.

Now, if you try with a value of n between 10 and 20, you won’t fall exactly on 100, and so you’ll need to add lines to reach it. For example, let’s try with n=14. Suppose you have 14 lines written on the screen:
S14: 14 seconds
C14: 2 seconds
6xP14: 12 seconds
but now you only have 98 lines written on the screen. You need 6 extra seconds (W2) to add the last two, for a total of 34 seconds, when you start with 14 lines already written. Add the time necessary to write these 14 lines and you don’t get an optimal solution. I believe (and it would be easy to check it) that the time necessary to complete the 100 lines is sufficient to make every solution with a n between 10 and 20 nonoptimal.

So it would appear that Ludovic’s solution is indeed the best. The next values of n that are integer multiples of 100 are n = 5 and n = 25, and they don’t yield optimal solutions either.

At what point does it make sense to introduce another layer of factors? For instance, if I have to repeat the sentence 1000 times, I’m not going to (say) do 20 lines, then repeat those lines 50 times. I’m probably going to use one of the methods here to get the first 100, then copy and paste that 9 more times. It seems like the number of layers in the optimal method for n lines should scale as approximately log(n), but I’m not sure what the scaling would be.

I would type 1 sentence with 300 periods.

Then I would scan/replace the periods with the actual sentence including cr lf characters.

Of course I would be disqualified also.

I made a slight mistake in my last post. If you use n = 14, after having written 98 lines, you don’t necessarily need six more seconds to write the last two. The lower bound is two seconds, and such a solution exists:
W4: 12 seconds
S4: 4 seconds
C4: 2 seconds
3xP4: 8 seconds
S14: 14 seconds
C14: 2 seconds
6xP14: 12 seconds
for a total of 54 seconds, which is still more than our optimal solution. (The way we did it is that after pasting four lines three times, we already have 16 lines written on the screen, so pasting 14 lines six times will bring us to exactly 100 lines.)

Chronos, that’s a good question. Suppose we have to write 1000 lines, as you propose. Also suppose you are at your last level, and you have n lines written on the screen. You need 2000/n + n seconds to write your 1000 lines (assuming n is a factor of 1000). The optimal n would be 20 sqrt(5), or approximately 44.72. The closest factors of 1000 are n = 40 and n = 50; and both require 90 seconds of work. I assume that n = 40 is reachable faster than n = 50, so we can again apply the algorithm to figure out how to reach it.

In general, if you need to write y lines, the optimal solution requires to copy sqrt(2y) lines sqrt(2y)/2 - 1 times. Now, writing these sqrt(2y) lines is done optimally using groups of sqrt(2sqrt(2y)) lines. (This is just a heuristic; I know we can only work with values of n that are integers and multiples of y.) The number of layers required would be the number of times we must apply the operation sqrt(2x) to y to reach our “base case”. I don’t know what the base case would be, though, especially since we deviate from our heuristic for low values of n.

Why wouldn’t you use r99 on the original line instead? That would save you acouple of seconds of moving to the nest line and typing A or B.

Bacause that WOULD be cheating. :wink:

(I considered that option, where one would only have to hit ENTER a single time, but I was afraid that would scandalize the PC users or Vi victims.)

Modified greedy algorithm. This is NOT a problem optimized for the greedy algorithm. You’d have to look at all iterations of steps if you really wanted an optimal solution. I hope I did it right.

First writing, lines : 1 cost = 3
Action Write ; 2 written 6 seconds
Action Copy 2 lines, and paste ; 4 written 12 seconds
Action Paste 2 lines ; 6 written 14 seconds
Action Paste 2 lines ; 8 written 16 seconds
Action Copy 8 lines, and paste ; 16 written 28 seconds
Action Paste 8 lines ; 24 written 30 seconds
Action Paste 8 lines ; 32 written 32 seconds
Action Paste 8 lines ; 40 written 34 seconds
Action Paste 8 lines ; 48 written 36 seconds
Action Paste 8 lines ; 56 written 38 seconds
Action Paste 8 lines ; 64 written 40 seconds
Action Paste 8 lines ; 72 written 42 seconds
Action Paste 8 lines ; 80 written 44 seconds
Action Paste 8 lines ; 88 written 46 seconds
Action Paste 8 lines ; 96 written 48 seconds
Action Paste 8 lines ; 104 written 50 seconds

Actually, I click the Paste icon. Even easier :wink:

Anyone else have the creeping feeling that we are inadvertantly helping someone get some MASSIVE extra credit in a class somewhere???

no?.. it’s just me then… dear god I’m getting paranoid…

Hi guys,

The rules of the riddle were stipulated in the OP. You had 4 main actions available to you, which I listed. The only thing I didnt clarify (until my 2nd post) was that you can move between lines at no time cost. Any answers involving doing something other than the 4 actions I listed, in a time span other than what was stipulated, do not qualify.

48 seconds appears to be the fastest.

Thanks everyone.

“All work and no play makes Jack a dull boy.”