2019
2019 copied to clipboard
#NNNGM: Another 50,000 Meows!
Prologue
The source code for 50,000 Meows from 2014 is way too long:
- 2,606 characters!
- Plus 3,305 for tests! (To practice TDD)
We can do better than that!
Nano-NaNoGenMo
Especially for Nano-NaNoGenMo or #NNNGM:
I have declared that November will also be the month in which people write computer programs that are at most 256 characters, and which generate 50,000 word or more novels. These can use Project Gutenberg files, as they are named on that site, as input.
(This quote is 253 characters.)
Basic version
26 characters
p -c 'print("meow "*9**5)'
Preview
meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow meow
Is it cheating I have p aliased to python? Maybe, but I'm going to say it's not as I already set up like that and it wasn't done just for NNNGM, and it wouldn't exceed the 256 limit anyway.
Why 9**5 and not 50000?
9**5is one character shorter than50000- 9⁵ == 59,049
- 59,049 >= 50,000
Full output
Better version
92 characters
The basic version is clearly nonsense, as there's no punctuation. This one makes much more sense.
p -c 'import random as r;print(" meow".join([r.choice(",:;.?!") for _ in range(9**5)])[2:])'
Preview
meow! meow! meow? meow: meow! meow. meow: meow! meow? meow, meow? meow, meow; meow: meow! meow; meow; meow: meow! meow? meow! meow. meow! meow: meow? meow? meow! meow. meow; meow! meow? meow, meow, meow, meow; meow? meow: meow. meow! meow, meow, meow: meow. meow? meow? meow, meow: meow? meow: meow: meow: meow. meow: meow: meow, meow! meow? meow. meow: meow; meow! meow: meow? meow! meow?
Much better!
Full output
The rules of #NNNGM say nothing of counting including the interpreter, the p -c bit. So, assuming you're already at a Python IDLE prompt, the source code is much shorter.
Basic version
12 characters
"meow "*9**5
Better version
78 characters
import random as r;" meow".join([r.choice(",:;.?!") for _ in range(9**5)])[2:]
43 characters of shell:
for i in {1..25000};do echo meow{?,.};done
Requires a ksh-compatible shell. I'm sure it can be done shorter with some cleverness.
On Thu, Nov 21, 2019 at 5:36 PM Hugo van Kemenade [email protected] wrote:
The rules of #NNNGM say nothing of counting including the interpreter, the p -c bit. So, assuming you're already at a Python IDLE prompt, the source code is much shorter. Basic version 12 characters
"meow "*9**5
Better version 78 characters
import random as r;" meow".join([r.choice(",:;.?!") for _ in range(9**5)])[2:]
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NaNoGenMo/2019/issues/105?email_source=notifications&email_token=AADXUGKLR5Y3MCXLA3PJNBLQU4ENXA5CNFSM4JQI4KRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEE34P7Y#issuecomment-557303807, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADXUGMP4JN53S7MNAN5JWDQU4ENXANCNFSM4JQI4KRA .
The punctuation really improved my reading experience. Bravo on pioneering Nano-NaNoGenMo!
Hooray!
You don't need the space between -c and ' by the way.
I think it's stylish to have your #NNNGM code runnable on the command line. But actually it doesn't have to be, according to me. When I first blogged about this, I just wrote:
write computer programs that are at most 256 characters, and which generate 50,000 word or more novels. These can use Project Gutenberg files, as they are named on that site, as input. Or, they can run without using any input.
You could have a 256-character .py file if you like.
In this case I do like the golfing of the program, but I like this final version the best even though it adds four unnecessary charcaters:
python -c'print("meow "*9**5)'|cat