63 (but less fun):
__builtins__.print=lambda s,p=print:p(s+s[455:525]);import this
63 (but less fun):
__builtins__.print=lambda s,p=print:p(s+s[455:525]);import this
Fun because …
Explicit is better than implicit.
… but …
Implicit is more fun than explicit.
… and it works beautifully, even displaying the aphorism of interest without quote delimiters.
107
import io,sys;s=sys.stdout;sys.stdout=c=io.StringIO();import this;a=c.getvalue();print(a+a[456:525],file=s)
Thanks for your solutions, everyone. I hope you’ve had fun.
This is my first time posing a code golf challenge here. If I were to do that again, it would include specifications regarding how submissions targeting different versions of Python would be considered, and that Python extensions should not be used. However, extensions did not seem to be a factor here.
On Tuesday, December 10, 2024, at some convenient time during that date here in the New York area, I’ll acknowledge two shortest solutions, that is the shortest that targeted Python 2.x, and the shortest that can execute using late Python 3.x versions such as Python 3.13.
Regarding who will have had the most fun, you can privately judge that, with my not being in a position to measure it.
At this time, you can still post submissions, but be sure to specify a targeted Python version, and also feel free to submit ones that were fun, but not necessarily short.
Of course, I would also be happy to receive advice from seasoned code golf players regarding what kinds of information to specify when posing a code golf challenge.
Thanks! Nice fun solution that displays the “preferably only one
” aphorism without quote delimiters.
The time for announcements has arrived.
A mere 17 minutes after my submission via the original post, @MRAB bested it by submitting a slightly shorter one, quickly knocking mine out of the running.
The shortest solution that targeted the most recent Python 3.x versions, with 50 characters, was developed by @dg-pb after a nudge from @Stefan2 regarding how to shave down @dg-pb’s previous solution. We’ll also thank @aroberge for then stating that one explicitly. @dg-pb did confirm with me that the following is, in fact, an accurate representation of the code:
from this import*;''.join(map(d.get,s,s))[456:525]
---------|---------|---------|---------|---------|
I had not placed a restriction on what versions of Python could be targeted here, so @Stefan2 was able to develop the following solution targeting Python 2 with a really brief 43 characters, making it the shortest of all the submissions:
import this;this.s[456:525].encode('rot13')
---------|---------|---------|---------|---
Solutions that were developed mainly for fun rather than for brevity were also invited. @Stefan2 explicitly offered two solutions for fun, with this one of them being designated as the most fun:
__builtins__.print=lambda s,p=print:p(s[456:525:p(s)]);import this
---------|---------|---------|---------|---------|---------|------
Although the above was not submitted for brevity, we can note that it weighed in at 66 characters.
As an honorable mention, we’ll also note an additional one by @dg-pb, viewable here, that can be recognized as having been composed for fun by virtue of its length of 107 characters.
Thanks to you all for playing!