Skip to content

Instantly share code, notes, and snippets.

@metatoaster
Last active December 18, 2022 05:03
Show Gist options
  • Save metatoaster/ee2149d76bd029253b18ea9cae4471d0 to your computer and use it in GitHub Desktop.
Save metatoaster/ee2149d76bd029253b18ea9cae4471d0 to your computer and use it in GitHub Desktop.
from random import shuffle
W = 8
H = 8
B = 10
A = W * H
S = A - B
line = [1] * B + [0] * S
shuffle(line)
checkidxs = [
[chk for chk in [
idx - H - 1 if (idx - 1) // W == idx // W else -1,
idx - H,
idx - H + 1 if (idx + 1) // W == idx // W else -1,
idx - 1 if (idx - 1) // W == idx // W else -1,
idx + 1 if (idx + 1) // W == idx // W else -1,
idx + H - 1 if (idx - 1) // W == idx // W else -1,
idx + H,
idx + H + 1 if (idx + 1) // W == idx // W else -1,
] if -1 < chk < A] for idx in range(A)
]
scoreline = [
sum(line[chk] for chk in checkidx)
if not line[chk] else
-1
for chk, checkidx in enumerate(checkidxs)
]
scoregrid = [scoreline[i:i+W] for i in range(0, A, W)]
symbol = [
':zero:',
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:',
':bomb:',
]
discogrid = '\n'.join(
''.join('||' + symbol[j] + '||' for j in scoreline[i:i+W])
for i in range(0, A, W))
print(''.join([symbol[int(i)] for i in str(B)]), ':bomb:')
print(discogrid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment