6
$\begingroup$

This puzzle is created by me.


String 1:

  This is an example paragraph. It contains multiple sentences.
  In addition to multiple sentences,
  it contains multiple lines, as well as indentations.

String 2:

This is an example paragraph, but changed slightly. It contains multiple sentences.
In addition to multiple sentences,
it contains multiple lines, as well as minor changes, like having no indentations.
In addition to multiple sentences, it also contains a partially repeated sentence.

The puzzle:

Find the minimum number of keystrokes to turn String 1 into String 2.

Rules:

  • Your cursor starts at the very end String 1 (after all characters).
  • You may only use the keyboard and arrow keys, no mouse / trackpad.
  • The keyboard used should be a standard, U.S. QWERTY keyboard, with no custom keys.
  • You may use common keyboard shortcuts, but they count as multiple keystrokes (e.g. CTRL + BACKSPACE counts for 2 keystrokes).
  • A common keyboard shortcut is one that works by default in all major operating systems (so no custom keybindings).
  • You may not use keyboard shortcuts specific to the text editor or application; the solution should be generic and applicable to any text editor.
  • Your clipboard is empty, but may be used.
  • Typing a character counts for 1 keystroke, even if SHIFT is used. However, if SHIFT is used in a keyboard shortcut, it counts as multiple keystrokes.
$\endgroup$
6
  • $\begingroup$ Are the indentations made of 2 spaces or 1 tab? $\endgroup$ Commented Nov 17, 2023 at 17:08
  • $\begingroup$ en.wikipedia.org/wiki/Edit_distance $\endgroup$
    – RobPratt
    Commented Nov 17, 2023 at 17:27
  • $\begingroup$ @WeatherVane In this case, each indentation is comprised of 2 spaces. $\endgroup$ Commented Nov 17, 2023 at 17:53
  • $\begingroup$ Upper limit: 443 keystrokes => 155 backspaces to clear string1 + 288 keystrokes to compose string2 (284 keystroke for letters in string2 + 4 uppercase letters that requires shift to be pressed). $\endgroup$ Commented Nov 17, 2023 at 18:01
  • 1
    $\begingroup$ @RobPratt Edit distance may be related, but those methods do not apply here. $\endgroup$ Commented Nov 17, 2023 at 22:43

1 Answer 1

6
$\begingroup$

I initially thought that copying and pasting individual words/character strings might be beneficial, but since every Ctrl + C and Ctrl + V is counted as two keypresses, it would only make sense if the word was very long.

My solution takes 141 keypresses:

Ctrl + ←Ctrl + ←

minor<space>changes,<space>like<space>having<space>no<space>

Shift + HomeCtrl + C

HomeDelDel

Ctrl + VEnd

<space>it<space> also<space>contains<space>a<space>partially<space>repeated<space>sentence.

Ctrl + HomeDelDel

Ctrl + →Ctrl + →Ctrl + →Ctrl + →Ctrl + →

,<space>but <space>changed<space>slightly

HomeDownDownDelDel

I could argue that holding Ctrl and pressing five times is really only 6 keypresses instead of 10. If that's the case, my total count is 136.

$\endgroup$
9
  • $\begingroup$ About the last paragraph rot13(pna lbh hfr nhgbercrng)? $\endgroup$ Commented Nov 17, 2023 at 19:03
  • $\begingroup$ @WeatherVane It would require awfully precise timing to end up at exactly the right location using autorepeat. $\endgroup$ Commented Nov 17, 2023 at 20:44
  • 1
    $\begingroup$ down down ctrl-v end should not work, as there is no new line below the text. Notepad does nothing on the second down-arrow, Chrome puts the cursor at the end of the line. You also appear to be copying the indentation. $\endgroup$ Commented Nov 17, 2023 at 23:11
  • 1
    $\begingroup$ As an alternative up home del del right shift+down ctrl+(c end v) should work, and may improve the count. $\endgroup$ Commented Nov 17, 2023 at 23:12
  • 1
    $\begingroup$ @CrSb0001 Really? I probably use it dozens of times a day. It's with the other cursor-control keys (Del, Ins, End, PgUp, PgDn). It takes you to the beginning of a line. Ctrl+Home takes you to the beginning of a document. Shift+Home will highlight everything between your current cursor position and the beginning of the line. $\endgroup$ Commented Nov 21, 2023 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.