Skip to content

Instantly share code, notes, and snippets.

@jurandysoares
Last active March 9, 2024 01:04
Show Gist options
  • Save jurandysoares/ad2ba39cb98ce83569099b472afef222 to your computer and use it in GitHub Desktop.
Save jurandysoares/ad2ba39cb98ce83569099b472afef222 to your computer and use it in GitHub Desktop.
Gustavo Fontoura's tables written in Markdown by a Python script

Fontables: Fontoura's tables

1 3 5 7
9 11 13 15
17 19 21 23
25 27 29 31
2 3 6 7
10 11 14 15
18 19 22 23
26 27 30 31
4 5 6 7
12 13 14 15
20 21 22 23
28 29 30 31
8 9 10 11
12 13 14 15
24 25 26 27
28 29 30 31
16 17 18 19
20 21 22 23
24 25 26 27
28 29 30 31
_MDOWN_HEADER = '''\
| | | | |
|--|--|--|--|'''
class Fontables:
def __init__(self) -> None:
self._bin_nums: list[str] = [f'{n:05b}' for n in range(1, 32)]
self._elements_at: dict[int, list[int]] = {}
for pos in range(4, -1, -1):
self._elements_at[pos] = [int(n, 2) for n in self._bin_nums if n[pos]=='1' ]
self._fontables: dict[int, list[list[int]]] = {}
for pos, elements in self._elements_at.items():
self._fontables[pos] = [elements[i*4: i*4+4] for i in range(4)]
@property
def binary_numbers(self):
return self._bin_nums[::1]
@property
def elements(self):
return self._elements_at.copy()
@property
def tables(self):
return self._fontables.copy()
def markdown_table(self, pos: int) -> str:
assert 0<=pos<5
lines = [ ('|'+'|'.join([f'{n:>2}' for n in line])+'|') for line in self.tables[pos]]
lines.insert(0, _MDOWN_HEADER)
return '\n'.join(lines)
if __name__ == '__main__':
ft = Fontables()
with open(file='fontables.md', mode='w', encoding='utf-8') as fobj:
fobj.write("# Fontables: Fontoura's tables\n\n")
for n in range(4, -1, -1):
fobj.write(ft.markdown_table(n))
fobj.write('\n\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment