Skip to content

Instantly share code, notes, and snippets.


Peilonrayz/ Secret

Last active Oct 5, 2020
What would you like to do?
Infinate product
import matplotlib.pyplot as plt
import numpy as np
from graphtimer import flat, Plotter, TimerNamespace, MultiTimer
from itertools import count, product, islice, chain
def Stefan_Pochmann(alphabet):
yield ''
for prefix in Stefan_Pochmann(alphabet):
for character in alphabet:
yield prefix + character
def Ivo_Merchiers(lib):
for length in count(0):
for combination in product(lib, repeat=length):
yield ''.join(combination)
def Ivo_Merchiers_chain(lib):
join = ''.join
return chain.from_iterable(
map(join, product(lib, repeat=length))
for length in count(0)
def main():
fns = [Stefan_Pochmann, Ivo_Merchiers, Ivo_Merchiers_chain]
alphabets = (
('lib', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz°!"§$%&/()=ß´`+#-.,><@€|^~–{[]}ÄÖÜäöü'),
('abc', 'abc'),
fig, axs = plt.subplots(ncols=2, sharex=True, sharey=True, subplot_kw={'xscale': 'log', 'yscale': 'log'})
for graph, (title, alphabet) in zip(iter(flat(axs)), alphabets):
its = zip(*(fn(alphabet) for fn in fns))
same = all(
all(v == i for i in vs)
for v, *vs in islice(its, 10**6)
print(title, same)
np.logspace(1, 6),
setup='from itertools import islice\nfrom collections import deque',
stmt=f'deque(islice(fn({alphabet!r}), args[0]), 0)',
args_conv=lambda i: int(i),
.plot(graph, title=title)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment