Editorial for Andyman's Golf Course - Hole 1 - One Hundred
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
30 bytes
A simple for loop can be used to achieve this as follows:
for i in range(1,101):print(i)
29 bytes
We can achieve a 1-byte saving by unpacking the range()
function. Unpacking however would cause everything to be on one line, and so we need to separate each one by a space.
print(*range(1,101),sep='\n')
26 bytes
The next optimization is utilizing the map()
function in Python. This simply applies a function to an iterable, such as what range()
returns.
Interestingly, the print()
function can be used as the function to apply, however upon testing it won't output anything. The map must first be unpacked into something like a list or tuple, and so simply calling it won't do anything.
[*map(print,range(1,101))]
25 bytes
The final optimization (which leads to the very likely the most optimized solution) is unpacking into a tuple as such:
*map(print,range(1,101)),
Comments