Skip to content

Instantly share code, notes, and snippets.

@sarum9in
Created November 8, 2014 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarum9in/3d158f7640878783111b to your computer and use it in GitHub Desktop.
Save sarum9in/3d158f7640878783111b to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from pprint import pprint
a = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
p = '?????о???????????????????????????'
#p = '????????д??????о??п??????????????'
#p = 'с??????????????т?о???????????????'
def dsum(d):
return sum(b for a, b in d.items())
def freq(s):
d = {c: 0 for c in a}
for c in s:
y = c.lower()
if y in a:
d[y] = d[y] + 1
n = dsum(d)
for c in d.keys():
d[c] /= n
return d
def dfreq(s):
d = dict()
pr = None
for c in s:
y = c.lower()
if y in a:
if pr is not None:
f = pr + y
if f in d:
d[f] = d[f] + 1
else:
d[f] = 1
pr = y
else:
pr = None
n = dsum(d)
for c in d.keys():
d[c] /= n
return d
def lst(d):
return sorted(list(d.items()), key=lambda x: x[1])
def lfreq(*args, **kwargs):
return lst(freq(*args, **kwargs))
def ldfreq(*args, **kwargs):
return lst(dfreq(*args, **kwargs))
def tprint(s):
for c in s:
y = c.lower()
if y in a:
j = a.index(y)
print(p[j], end='')
else:
print(c, end='')
print()
#tprint(s)
v = True
def convert(w, h, s):
r = [['?' for x in range(h)] for y in range(w)]
for i in range(w):
if len(s) == 0:
break
for j in range(h):
if len(s) == 0:
break
r[i][j] = s[0]
s = s[1:]
if v:
pprint(r)
g = ''
for j in range(h):
for i in range(w):
g += r[i][j]
return g
for w in range(1, 15):
for h in [15]:
print(w, h, '', end='\n' if v else '')
if v:
print(s)
m = w * h
l = s
while len(l) > m:
g = l[:m]
l = l[m:]
print(convert(w, h, g), end='\n' if v else '')
print(convert(w, h, l))
if v:
print()
print()
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment