From 0eb81ab51e46adb88b26183aa9e727aedd2e3e4b Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Sat, 4 Dec 2021 06:55:17 +0000 Subject: day 4: generator --- 4gen.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 4gen.py diff --git a/4gen.py b/4gen.py new file mode 100644 index 0000000..bc54c17 --- /dev/null +++ b/4gen.py @@ -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)) -- cgit v1.2.3-54-g00ecf