Last active
September 29, 2020 06:55
-
-
Save galvanic/4868b6c4c54e29e8fa170f2f81e33aae to your computer and use it in GitHub Desktop.
create_numbers_string.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/env/python3 | |
''' | |
use: | |
```bash | |
$ python3 create_numbers_string.py | pbcopy | |
``` | |
The second part after the pipe, pipes the stout directly into your clipboard on macOS. | |
If not on macOS, omit the part after the pipe: | |
```bash | |
$ python3 create_numbers_string.py | |
``` | |
Motivation for this script: | |
Brush up my scripting & quick clean code writing skills | |
Noticed Codility allowed personal tests to be run via a DSL where 1 line is 1 test data. | |
for the test i had this was a list of values | |
But untractable to write really big queries of 1k+ values to test performance | |
and no time to write this script during the time limit | |
note: | |
i was curious to see if there was a functional alternative to | |
`random.shuffle()` (ie. not in place) that was still performant | |
found: `random.sample(x, len(x))` | |
via url: https://stackoverflow.com/questions/17649875/why-does-random-shuffle-return-none/17649901#17649901 | |
reservations: tbh i don't know if the shuffling quality and performance | |
truly compare and are the same, but it isn't relevant for this task anyway | |
''' | |
import random | |
def main(): | |
## change this variable here: | |
numbers = list(range(-1000, 500, 40)) + \ | |
list(range(100, 200000, 33)) + \ | |
[ -1, 0, 3, 8, 99 ] | |
numbers = random.sample(numbers, len(numbers)) ## shuffles with O(N) operations | |
numbers = map(str, numbers) | |
numbers_string = ', '.join(numbers) | |
string = '[ {:s} ]'.format(numbers_string) | |
return string | |
if __name__ == '__main__': | |
string = main() | |
print(string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment