19
\$\begingroup\$

The book Green Eggs and Ham by Dr. Seuss is famous for only having 50 different words in the entire story of the book.

Your task is to create a sequence of keystrokes that will result in the entire text of Green Eggs and Ham when applied to an empty file in the vim text editor, starting in normal mode with all default settings. Your keystrokes must not load any other files as part of their operation - all text must be generated within the editor itself.

Your final buffer must look exactly like this file, although it can remain in whichever mode it ends up being in (you don't have to have a final <Esc> to return it to normal mode).

Chorded keystrokes like <C-o> or using Shift to type a capital letter count as a single keystroke.

The sequence of the fewest keystrokes to achieve this goal wins.

\$\endgroup\$
12
  • \$\begingroup\$ If somebody wants to create the Emacs equivalent of this question, they can. I'm not familiar enough with Emacs to know if it would make for an interesting question at all. \$\endgroup\$
    – Joe Z.
    Dec 9, 2013 at 3:46
  • \$\begingroup\$ Also, "with all default settings" means that you aren't allowed to load settings from a .vimrc file. \$\endgroup\$
    – Joe Z.
    Dec 9, 2013 at 3:47
  • \$\begingroup\$ Based on your "canonical" insert-entire-file answer, I take it the mode you leave the editor in after the insertion doesn't matter. Maybe this should be explicitly specified to clarify (i.e. you don't have to <Esc> out from insert-mode). \$\endgroup\$
    – FireFly
    Dec 9, 2013 at 15:26
  • \$\begingroup\$ Yeah, you don't have to <Esc> out from insert mode, but you do have to start in normal. \$\endgroup\$
    – Joe Z.
    Dec 9, 2013 at 19:48
  • \$\begingroup\$ As I see it, this question is on the edge of being off-topic. It's not a codegolf, it's a vimgolf (there is a page for that, a good one. Anyone interested should take a look). I also find the text to be too long, making it very time consuming to golf. \$\endgroup\$
    – shiona
    Dec 9, 2013 at 20:41

2 Answers 2

10
\$\begingroup\$

1864 keystrokes

Somebody could probably write some code that produces a more optimal solution, but this beats the reference case for now. This is a damn mess, and I am ashamed I did it by hand.

First, we enter insert mode.

i

Then all this

That ]! That ]!
IDNlike that ]!

Do Y like$?

|;].
IDNlike$.

WPY LTB or tB?

IZ LTB or tB.
IZ LTanywB.
IDNlike$.
|;].

WPY LTin a h@?
WPY LT=a m@?

|in a h@.
|=a m@.
|B or tB.
|.
IDNlike$.
|;].

WPY ETin a box?
WPY ET=a fox?

Not_a box. Not =a fox.
Not_a h@. Not =a m@.
IZ ETB or tB.
IZ ETanywB.
IZ eat$.
|;].

WPY? CPY? In a car?
Eat them! Eat them! B they are.

IZ,X,_a car.

You may LT. You will see.
You may LTin a tree!

IZ,X_a tree.
Not_a car! You let me be.

|in a box.
|=a fox.
|in a h@.
|=a m@.
|B or tB.
|.
IDNlike$.
|;].

AQ! AQ! AQ! AQ!
CPY;wPY;on aQ?

Not_aQ! Not_a tree!
Not_a car! Sam! Let me be!

IZ,X,_a box.
IX,Z;=a fox.
:=a m@.
:in a h@.
:B or tB.
:anywB.
IDNlike$.
|;].

Say! In +? B_+!
WPY;cPY,_+?

IZ,X,_+.

WPY;cPY,_the rain?


IZ,X,_the rain.
Not_+. Not on aQ.
Not_a car. Not_a tree.
|;Sam;Y see.
Not_a h@. Not_a box.
Not =a m@. Not =a fox.
:B or tB.
|!

You do not like$?
|;].

CPY;wPY;=a g^?

IZ,X;=a g^!

WPY;cPY;on a b^?

IX,Z;on a b^.
IWN,WN;=a g^.

:in the rain.
:on aQ.
Not_+! Not_a tree!
Not_a car! You let me be!
|in a box.
|=a fox.
:in a h@.
|=a m@.
|B or tB.
|!

IDNlike$!
|;].

You do not LT. So Y say.
Try them! Try them! & Y may.
Try them and Y may;I say.

Sam! If Y will let me be,
I will try them. You will see.

Say! I like$!
I do! I LT;]!
& I wPETin a b^.
& I wPET=a g^.

!ETin the rain.
&_+. & on aQ.
&_a car. &_a tree.
They are so good;so good;Y see!

So I will ETin a box.
!ET=a fox.
!ETin a h@.
!ET=a m@.
!ETB and tB.
Say! I will ETanywB!

I do so like$!

Thank Y! Thank Y;]!

Hit escape to enter command mode. And unravel the compressed stuff. Order matters, as I've compressed some compressed text.

<Esc>
%s/|/|anywB/g
%s/:/IWNET/g
%s/|/IDNLT/g
%s/Z/ wPnot/g
%s/X/ cPnot/g
%s/&/And/g
%s/+/the dark/g
%s/@/ouse/g
%s/^/oat/g
%s/Y/you/g
%s/IDN/I do not /g
%s/LT/like them /g
%s/]/Sam-I-am/g
%s/ET/eat them /g
%s/WN/ will not/g
%s/$/ green eggs and ham/g
%s/P/ould /g
%s/!/And I will /g
%s/Q/ train/g
%s/B/here/g
%s/_/ in /g
%s/=/with /g
%s/;/, /g
\$\endgroup\$
5
  • \$\begingroup\$ you got the wrong substitution for eat them, it's backwards. and you can cut the leading colons by using ed mode which stays in command mode after commands. \$\endgroup\$
    – hildred
    Dec 9, 2013 at 23:31
  • \$\begingroup\$ @hildred I actually started with the full text, did a global replace and added the full text to compressed text to another file. Must have forgotten to reverse that one :( \$\endgroup\$
    – user8777
    Dec 9, 2013 at 23:42
  • \$\begingroup\$ If you replace so good;so good; with <Esc>2aso good;<Esc>a, you can save three keystrokes. Also, replace iThat ]! That]!<Enter> at the beginning with 2iThat ]! <Esc>xo for another three. \$\endgroup\$
    – Joe Z.
    Dec 10, 2013 at 1:16
  • \$\begingroup\$ Also, since DN doesn't appear elsewhere, you can remove the I from IDN and I do not in the replace statement with those two expressions in it. \$\endgroup\$
    – Joe Z.
    Dec 11, 2013 at 0:04
  • \$\begingroup\$ And, replace all instances of IDNlike$!<Enter>|;]. with 1 and input %s/1/IDNlike$!\n|;]./g to save about 20 keystrokes or so. \$\endgroup\$
    – Joe Z.
    Dec 11, 2013 at 0:07
6
\$\begingroup\$

3,470 keystrokes

i<entire text of file>

The text file is 3,469 characters long, so typing "i" to put it in insert mode and typing out each character individually will take 3,470 keystrokes.

\$\endgroup\$
4
  • \$\begingroup\$ Lol @ pure brute force \$\endgroup\$
    – Cruncher
    Dec 9, 2013 at 16:21
  • \$\begingroup\$ This is intended mostly as a last-place reference solution more than anything. \$\endgroup\$
    – Joe Z.
    Dec 9, 2013 at 20:07
  • \$\begingroup\$ yet it's currently the best contestant as well :-) (no, I'm not going to participate; sorry) \$\endgroup\$ Dec 9, 2013 at 20:14
  • \$\begingroup\$ You more of an Emacs person? :-) \$\endgroup\$
    – Joe Z.
    Dec 9, 2013 at 20:15

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.