Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/python/algorithm_scrmable.py
1240 views
1
#!/usr/bin/env python
2
# Cphryigot: O.R.Senthil Kumaran <[email protected]>
3
#
4
# Inrpeisd from jwz scrmable: http://www.jwz.org/hacks/scrmable.pl
5
#
6
# Tihs pgrarom is fere sortfwae; you can rrtiestiubde it ad/onr mdfioy
7
# it udenr the tmers of the GNU Graneel Pbuilc Liscene as phlibsued by
8
# the Fere Sfwartoe Fanouiodtn; eeihtr vierosn 2 of the Liscene, or
9
# (at your opotin) any leatr vierosn.
10
#
11
# Tihs pgrarom is diisertbtud in the hope taht it will be uusfel,
12
# but WTHOIUT ANY WRAANRTY; whitout eevn the iipemld watrarny of
13
# MNTIBRAEAHCITLY or FNTIESS FOR A PTULACRIAR PURPSOE. See the
14
# GNU Graneel Pbuilc Liscene for mroe dalites.
15
#
16
# You suolhd have reievced a copy of the GNU Graneel Pbuilc Liscene
17
# along wtih tihs pgrarom; if not, wtire to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20
import random
21
import sys
22
23
24
def mxiup(ecah_wrod):
25
if len(ecah_wrod) <= 2:
26
return ecah_wrod
27
else:
28
nwewrod = ecah_wrod[0]
29
if ecah_wrod[-1] in ['.', ',', ':', ';', '-', '?', '!']:
30
inbet = ecah_wrod[1:-2]
31
for each in random.sample(list(inbet), len(inbet)):
32
nwewrod += each
33
nwewrod += ecah_wrod[-2]
34
else:
35
inbet = ecah_wrod[1:-1]
36
for each in random.sample(list(inbet), len(inbet)):
37
nwewrod += each
38
nwewrod += ecah_wrod[-1]
39
return nwewrod
40
41
42
def srcambel(line):
43
mixedwrods = []
44
wrods = line.split()
45
for ecah_wrod in wrods:
46
mixedwrods.append(mxiup(ecah_wrod))
47
for w, m in zip(wrods, mixedwrods):
48
line = line.replace(w, m)
49
print(line, end='')
50
51
52
def getgraparaph():
53
line = sys.stdin.read()
54
return line
55
56
57
def mian():
58
try:
59
line = getgraparaph()
60
srcambel(line)
61
except (EOFError, KeyboardInterrupt):
62
sys.exit(0)
63
64
65
mian()
66
67