Fsrit Propttoye: SCLABMRE

  • Thread starter Frnak Sealmbcrd Eggs Lomax
  • Start date
F

Frnak Sealmbcrd Eggs Lomax

I hvae jsut fhiseind rniedag a Shdlaost atrlcie from Mnoday, Sbepemetr
15th, aobut an ingtriniug sdtuy from Cgbdirmae Uinevtrsiy, dciinesrbg
how wodrs with thier itienrors selmrbacd can siltl be rdbaleae.
Bcaeuse of the tioeznme that I lvie in, an initettrment dfceet in my
clbae medom, and the lneiignrg atfer-ecfefts of my lsat "mohsroum
salad exntarvzagaa", I am aaylws two days bhneid on the Web.

So suentnd was I at the icoinatpimls of this study, taht I
cunlqtneesoy decedid to doetve my etrnie lfie and gtelray aeamssd
fnrtoue on cunitodcng ftrhuer rasreech and dnpeeelmvot into tihs
lifnsaevig tghlocnoey. As a cross-eeyd dxsiyelc, I konw that teshe
cilmas of svotailan are niehetr hlroyepbe nor bmobaistc
over-daaomtiazitrn.

Pnseetred hree for your rveiew, aaovpprl and disiscsuon, is our
poyptotre sytsem, caelld SLABCRME for SeCren Rslmnebeig Aacrihc
Mnoaaluptiin of BetaoLd Ecuitolon. I have scnie bugen a meosdt
sutartp based in Aceicdnt Maarnlyd, and we will soon be reeianlsg an
Olutook puglin, anolg with a sftorwae devmoeelpnt kit, and oethr
digintoasc tloos. Smoe of our tlgeocnhoy wlil nallaruty be open
sruoce, but I do ietnnd and ecpext to frutehr etnxed my hoougmuns
wtaleh by sinlelg sftorawe lcseiens and srhink wrapped ratiel pocrudt.
Psaele cactnot us for more iomrfaiontn.

I'm aslo in enpommelyt duicnssioss wtih the Tmboit; I ecepxt that he
can bosot the pmecarrofne of our pooyptrte's itmpeanetolmin
salreolefvd, at wcihh piont we will be pthincig emdbeded ssmeyts to
the mfntacuuearrs of ruoters, eiltncreoc trprwyeiets, psnreoal dtaiigl
astsntsais, eorctinlec cepmutor coltlerond tersotas, maet prbeos, RFC
1149 digtail cemara pheons, and nxet gniaoetern wopehoe csionuhs.

hinpog-to-be-deotersyd-by-moroscift-ly y'rs,
-fnark


#! /usr/bin/env python
# Author: Frank "Topsy Turvy" Lomax <[email protected]>

"""Slmbcrae the letrtes in a word.

Tihs was seen on Soalhsdt, so it msut be ture:

Ardcnoicg to resraceh at Cgmdrabie Uesnirtivy, it dsoen't matter in what odrer
the lettres in a wrod are, the olny iotrmpant tnhig is taht the fsrit and lsat
lteter be at the rhigt pcale.

The rest can be a toatl mess and you can sltil raed it wuhoitt peolbrm. This
is bseacue we do not raed eervy ltteer by it self but the wrod as a wohle.
Cireheo.
"""

import re
import sys
from random import shuffle

EMPTYSTRING = ''


def scrambleword(word):
if len(word) <= 2:
return word
middle = list(word[1:-1])
shuffle(middle)
return word[0] + EMPTYSTRING.join(middle) + word[-1]


def main():
text = sys.stdin.read()
words = re.split(r'(\W+)', text)
while words:
sys.stdout.write(scrambleword(words.pop(0)))
if words:
sys.stdout.write(words.pop(0))


if __name__ == '__main__':
main()
 
P

Peter Otten

Frank, what we are *really* waiting for, is the patch that teaches the snake
to eat the following without indigestion :)

iomrpt re
ipmort sys
from rndaom irompt sflhfue

ETIPSRYTNMG = ''


def sowrablrcemd(wrod):
if len(wrod) <= 2:
rretun wrod
middle = list(word[1:-1])
sufhfle(mdilde)
rtruen word[0] + EISYNTTRMPG.join(mildde) + word[-1]


def mian():
text = sys.sdtin.read()
wrdos = re.split(r'(\W+)', txet)
wilhe wdors:
sys.sdotut.wirte(smblarcewrod(wodrs.pop(0)))
if wodrs:
sys.sudott.wirte(wdros.pop(0))


if _nae__m_ == '_mn__ia_':
mian()

Scrambledly yours,
Peter
 
L

L. Sommerer

I hvae jsut fhiseind rniedag a Shdlaost atrlcie from Mnoday, Sbepemetr
15th, aobut an ingtriniug sdtuy from Cgbdirmae Uinevtrsiy, dciinesrbg
how wodrs with thier itienrors selmrbacd can siltl be rdbaleae.
Bcaeuse of the tioeznme that I lvie in, an initettrment dfceet in my
clbae medom, and the lneiignrg atfer-ecfefts of my lsat "mohsroum
salad exntarvzagaa", I am aaylws two days bhneid on the Web.

[snip]

I was really glad to read this post. I worked on the same little bit of
code one evening this week, but I didn't feel very good about the solution.
I haven't been coding in python long, and it was quite instructive to see
how someone else approached the same problem.

Lloyd Sommerer

(Here's what I did in case anyone's interested.)
-----------------------------------------------------
from random import shuffle

def scramble_word(MyWord):
#
# If the word includes punctuation, save the punctuation for later use,
# and remove it from the end of the word.
#
if MyWord[-1] in [".", ";", ":", "," ,"!", "?"]:
Punctuation = MyWord[-1]
MyWord = MyWord[0:-1]
else:
Punctuation = ""
#
# 1, 2 and 3 letter words don't need to be scrambled, so skip them.
#
if len(MyWord) < 4:
return MyWord + Punctuation
else:
#
# Carve out the middle and make a list out of it so we can shuffle
it
# (can't shuffle a string). Then use "reduce" to return the list as
a
# string.
#
Middle = MyWord[1:-1]
MiddleList = list(Middle)
shuffle(MiddleList)
NewMiddle = reduce(concat_letters, MiddleList)
return MyWord[0] + NewMiddle + MyWord[-1] + Punctuation

def scramble(SomeText):
ScrambledList = [scramble_word(x) for x in SomeText.split()]
return reduce(concat_words, ScrambledList)
def concat_letters(x,y):
return x+y

def concat_words(x,y):
return x+" "+y

if __name__ == '__main__':
print 'Usage: scramble("Insert some text here to scramble")'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top