a million characters

dannyb21892 May 1st, 2018 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Answer: Every 29/30 (or 0.966) seconds, re-copy the current total and hold paste
  3. I started with the given assumptions:
  4. 0.5 second initial delay on held-key repress
  5. 1/30 of a second held-key repress rate
  6. 1 second to press the key combo to re-copy the whole page and paste
  8. I wrote the code on the following page to simulate the game for many different timings for when to stop holding a key, and when to spend the one second to re-copy the page:
  10. The result was that the following sequence generates the fastest possible road to a million:
  12. 1) Hold down the "i" key for 0.966 seconds, This should type 16 i's (one on initial key press, and then one more every 0.033 seconds beginning 0.5 seconds after the initial press).
  13. 2) Spend one second to enact the copy/paste combo: ctrl+a, ctrl+c, -> arrow, ctr+v.
  14. 3) Hold down that final ctrl+v from step 2 for 0.966 seconds. This should paste the initial 16 i's from step one 16 times. After the 0.966 seconds are up repeat steps 2 and 3.
  16. Following this method, one million characters will be reached in 8.866 seconds.
  18. The reason I think this turned out to be the best strategy is that holding a key for 0.966 seconds turns out to be 16 repeated key presses, and 16 is a number which, when multiplied repeatedly, gives a number very close to a million in only 5 steps.  If we were to hold the initial "i" key for up to 32 presses instead to arrive at a similar result in only 4 steps, the extra 16/30 of a second that it takes to hold the "i" key does not outweigh the time that we could have spent increasing our copy buffer instead. Similarly, using 15 presses requires 6 multiplication steps to reach a million, and using 17 uses 5 but overshoots a million unnecessarily.
  20. It should be noted that it is possible on a mac to turn the held key repeat rate to 33.3 times per second, and reduce the initial repeat delay from 0.5 seconds to 0.225 seconds. In this instance, the optimal 16 key presses before reaching the buffer switch is achieved after only 0.645 seconds of holding a key press (as opposed to 0.966 seconds with the given settings), and so this becomes the optimal time to switch from holding the key to recopying the page. Feel free to change the constants at the top of the code page to see for yourself that 0.645 is indeed the answer when these constants are used. The total time to reach a million characters in this case is only 7.255 seconds. This is about 1.6 seconds less than the answer with the old settings (8.866 seconds) due to five iterations of saving 0.275 seconds on the held key repeat delay, as well as five iterations of saving 0.046 seconds on each held-key phase before switching from held key to refreshing the copy buffer.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand