More than-- one --obvious way to play code golf

Anyone for code golf?

The challenge here is:

  • In an interactive Python console, display the entirety of The Zen of Python, then below that, display only its thirteenth aphorism on its own line. It’s fine for that line to have quote delimiters around it in the output.
    So, which is the thirteenth aphorism? Well it’s the-- obvious --one. :grin:

As we know, the most obvious rule in code golf is to try to create the shortest possible source code that satisfies the posed challenge. However, if an aphorism need not abide strictly by its own advice, we needn’t either! :grin:

And so, another way to play here will be to simply achieve the prescribed output by having the most fun. So, there will be at least two winners-- one being the shortest solution --and the other being the one that was the most fun to create. But how will we know which one provided its author the most fun? --well, we might not know for sure, but we can each decide privately by ourselves which one is the winner in that regard. :smiley: The time frame is open-ended, so there will be no need to declare ultimate winners. That might evolve as time goes on.

How to proceed:

  • Strive for and post a short solution, but you are each also highly encouraged to post one or more solutions that are not necessarily the shortest, but that you had fun creating. You are not required to blur or otherwise obscure your posted solutions.

Here’s my own solution in the console, at 69 characters (EDIT: 70 characters):

import this;''.join([this.d.get(c,c) for c in this.s.split('\n')[14]])

Have fun!

I can go 1 better:

import this as t;''.join([t.d.get(c,c)for c in t.s.split('\n')[14]])
1 Like

… Thanks, and if you had fun doing it, you might be the winner, thus far, in both regards! :grin:

import this as t;l=t.s.split('\n')[14];''.join(map(t.d.get,l,l))
1 Like

Thanks for the 62 chars, and if you enjoyed it, we now have two contenders in the “had fun” category! :grin:

Oops, was just told it was really 64 chars, so now I must save face by claiming there is more than one obvious way to count! :grin:

It’s 70. How do you count?

I must be using a zero-based method. :grin: Would anyone like to volunteer to take over the counting?

Have edited it in the original post to 70.

You can eliminate one space in that one.

import this as t;''.join(map(t.d.get,t.s,t.s))[456:525]
3 Likes

Try from this import*.

2 Likes

50…

1 Like

I’m guessing you used the suggestion from /u/stephan2 of importing everything as in:

from this import*;''.join(map(d.get,s,s))[456:525]
3 Likes

43 in Python 2 (and maybe old Python 3?):

import this;this.s[456:525].encode('rot13')
1 Like

Is there any version of Python in which this contains The Zen text unencoded?

Apparently not.

1 Like

Thanks, that’s interesting.

One of the comments within:

simple is better then complex ???

Evidently, some have not yet figured out from carefully and lightheartedly reading the entirety of The Zen that it incorporates, in part, Tim’s sense of humor. :grin:

1 Like

Actually the history even shows a Simple is better than complex commit, but it was swiftly reverted. (It used s.decode('rot_13').)

1 Like

Thanks, the history is interesting.

Not short (66) but fun:

__builtins__.print=lambda s,p=print:p(s[456:525:p(s)]);import this
2 Likes