5 ms·
How about this Python solution: z="0123456789" print map(lambda x:int("".join(x))+1,zip(sorted(zip(*z)[0]*100), sorted(zip(*z)[0]*10)*10,
by BobKabob 16y ago
How about this Python solution:
z="0123456789"
print map(lambda x:int("".join(x))+1,zip(sorted(zip(*z)[0]*100),
sorted(zip(*z)[0]*10)*10,
zip(*z)[0]*100))
Only downside is that it prints as a list (so it has the format of [1,2,3..])
- patrickyeon 16y ago('\n').join(map(str, [1,2,3]))
- BobKabob 16y agoEven better Python variation: Prints 1 to 1000 and quits: from __future__ import print_function z="0123456789" map(print,map(lambda x: int("".join(x))+1,zip(sorted(z*100), sorted(z*10)*10, z*100))) The way it works is to create 3 strings, one for each digit-place. The first digit, when counting from 000 to 999, is 100 zeros, followed by 100 ones, followed by 100 twos, etc. That is represented by sorted(z*100) The middle digit is 10 zeros, 10 ones, etc... and repeat this 10 times. So this is sorted(z*10)*10. The least significant digit is represented by a string that just counts and starts over. it's 1000 characters long: "0123456789012345..." and represented by z*100. I define an unnamed function (using lambda), that does the following: Join the three digits, make it an int, and add 1. So the result of this is a list of numbers from 1 to 1000. In other words, map(lambda x: int("".join(x))+1,zip(sorted(z*100), sorted(z*10)*10, z*100))) is about the same as if I just used range(1,1001) Then I map it to the new print function that is available in Python 3.0, or with the import statement. A simpler version would use range, but that seems a little too simple: from __future__ import print_function map(print,range(1,1000)) Now that I think about it, this last one is the right answer!