Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#NNNGM: Another 50,000 Meows! #105

Open
hugovk opened this issue Nov 21, 2019 · 4 comments
Open

#NNNGM: Another 50,000 Meows! #105

hugovk opened this issue Nov 21, 2019 · 4 comments

Comments

@hugovk
Copy link
Member

hugovk commented Nov 21, 2019

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**5 is one character shorter than 50000
  • 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

@hugovk
Copy link
Member Author

hugovk commented Nov 21, 2019

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:]

@enkiv2
Copy link

enkiv2 commented Nov 22, 2019 via email

@iistickboy
Copy link

The punctuation really improved my reading experience. Bravo on pioneering Nano-NaNoGenMo!

@nickmontfort
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants