If I'm not mistaken, the original output is O(n^2) in quantity of chars, and as output time is proportional to the length of the output, that makes the output time also O(n^2) here too.
So I guess this only looks like it's reduced to linear because the output here is very small. For large n it would become obvious. jan On 24/06/2021, Avi Gross via Python-list <python-list@python.org> wrote: > 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....@python.org> On > Behalf Of Michael F. Stemper > Sent: Wednesday, June 23, 2021 10:23 AM > To: python-list@python.org > Subject: Re: Optimizing Small Python Code > > On 23/06/2021 08.17, Stefan Ram wrote: >> "Avi Gross" <avigr...@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 > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list