diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 06:55:17 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-04 06:55:17 +0000 |
commit | 0eb81ab51e46adb88b26183aa9e727aedd2e3e4b (patch) | |
tree | 4a4ac63445570b72a6a1d94cfec0eb40a3cdbac5 | |
parent | e3c33a5247332f083af8a84a0c3e6fc6650e8845 (diff) | |
download | aoc2021-0eb81ab51e46adb88b26183aa9e727aedd2e3e4b.tar.gz aoc2021-0eb81ab51e46adb88b26183aa9e727aedd2e3e4b.tar.xz aoc2021-0eb81ab51e46adb88b26183aa9e727aedd2e3e4b.zip |
day 4: generator
-rw-r--r-- | 4gen.py | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -0,0 +1,28 @@ +from math import log10, ceil +from random import shuffle, sample + +BOARD_SIDE = 15 +BOARD_COUNT = BOARD_SIDE * BOARD_SIDE * 4 +NUMS = BOARD_COUNT + +nums = list(range(NUMS)) +shuffle(nums) + +print(','.join(str(n) for n in nums)) +print() + +align = ceil(log10(NUMS)) + +boards = [] +for b in range(BOARD_COUNT): + bnums = sample(nums, BOARD_SIDE * BOARD_SIDE) + rows = [] + for y in range(BOARD_SIDE): + row = [] + for x in range(BOARD_SIDE): + n = bnums.pop() + row.append(f'{n:>{align}}') + rows.append(' '.join(str(n) for n in row)) + boards.append('\n'.join(rows)) + +print('\n\n'.join(boards)) |