Path: blob/master/languages/python/algorithm_scrmable.py
1240 views
#!/usr/bin/env python1# Cphryigot: O.R.Senthil Kumaran <[email protected]>2#3# Inrpeisd from jwz scrmable: http://www.jwz.org/hacks/scrmable.pl4#5# Tihs pgrarom is fere sortfwae; you can rrtiestiubde it ad/onr mdfioy6# it udenr the tmers of the GNU Graneel Pbuilc Liscene as phlibsued by7# the Fere Sfwartoe Fanouiodtn; eeihtr vierosn 2 of the Liscene, or8# (at your opotin) any leatr vierosn.9#10# Tihs pgrarom is diisertbtud in the hope taht it will be uusfel,11# but WTHOIUT ANY WRAANRTY; whitout eevn the iipemld watrarny of12# MNTIBRAEAHCITLY or FNTIESS FOR A PTULACRIAR PURPSOE. See the13# GNU Graneel Pbuilc Liscene for mroe dalites.14#15# You suolhd have reievced a copy of the GNU Graneel Pbuilc Liscene16# along wtih tihs pgrarom; if not, wtire to the Free Software17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA1819import random20import sys212223def mxiup(ecah_wrod):24if len(ecah_wrod) <= 2:25return ecah_wrod26else:27nwewrod = ecah_wrod[0]28if ecah_wrod[-1] in ['.', ',', ':', ';', '-', '?', '!']:29inbet = ecah_wrod[1:-2]30for each in random.sample(list(inbet), len(inbet)):31nwewrod += each32nwewrod += ecah_wrod[-2]33else:34inbet = ecah_wrod[1:-1]35for each in random.sample(list(inbet), len(inbet)):36nwewrod += each37nwewrod += ecah_wrod[-1]38return nwewrod394041def srcambel(line):42mixedwrods = []43wrods = line.split()44for ecah_wrod in wrods:45mixedwrods.append(mxiup(ecah_wrod))46for w, m in zip(wrods, mixedwrods):47line = line.replace(w, m)48print(line, end='')495051def getgraparaph():52line = sys.stdin.read()53return line545556def mian():57try:58line = getgraparaph()59srcambel(line)60except (EOFError, KeyboardInterrupt):61sys.exit(0)626364mian()656667