Optimizing Small Python Code

Avi Gross avigross at verizon.net
Wed Jun 23 21:56:59 EDT 2021


Yes, I agree that if you do not need to show your work to a human, then the
problem specified could be solved beforeand and a simple print statement
would suffice.

Ideally you want to make a problem harder such as by specifying an N that
varies then testing it with an arbitrary N.

But I suggest the item below is not minimal. You can store the printout more
compactly as the only symbols out put are tabs, newlines and seven digits.
If your language supported some function that expanded a binary string that
used say 4 bytes per symbol so it could be printed, or accepted a compressed
form of the string and uncompressed it, you might have code like:

print(unzip("n*n&&S!~se"))

-----Original Message-----
From: Python-list <python-list-bounces+avigross=verizon.net at python.org> On
Behalf Of Michael F. Stemper
Sent: Wednesday, June 23, 2021 10:23 AM
To: python-list at python.org
Subject: Re: Optimizing Small Python Code

On 23/06/2021 08.17, Stefan Ram wrote:
> "Avi Gross" <avigross at verizon.net> writes:
>> This can be made a one-liner too! LOL!
> 
> print( '1\n      0\n2\n      0\n      1\n3\n      0\n      1\n      2\n4\n
0\n      1\n      2\n      3\n5\n      0\n      1\n      2\n      3\n
4\n6\n      0\n      1\n      2\n      3\n      4\n      5\n' )

Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). That
deserves a Turing award or something.

--
Michael F. Stemper
You can lead a horse to water, but you can't make him talk like Mr. Ed by
rubbing peanut butter on his gums.
--
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list