Cambridge Transposition
Ruby - 50 48 chars, plus -p
command line parameter.
gsub(/(?<=\w)\w+(?=\w)/){[*$&.chars].shuffle*''}
Thanks @primo for -2 char.
Test
➜ codegolf git:(master) ruby -p 9261-cambridge-transposition.rb < 9261.in
Acdrcinog to a racreseher at Cagribmde Ursvetniiy, it dsoen't mttaer in waht odrer the leertts in a word are, the olny ionarpmtt tnhig is that the fsirt and last letetr be at the rghit pcale. The rset can be a taotl mses and you can slitl raed it wthiuot perlbom. Tihs is buaecse the hmuan mind does not raed ervey lteetr by ietlsf but the word as a wlhoe.
PHP 84 bytes
<?for(;$s=fgets(STDIN);)echo preg_filter('/\w\K\w+(?=\w)/e','str_shuffle("\0")',$s);
Using a regex to capture words that are at least 4 3 letters long†, and shuffling the inner characters. This code can handle input with multiple lines as well.
If only one line of input is required (as in the example), this can be reduced to 68 bytes
<?=preg_filter('/\w\K\w+(?=\w)/e','str_shuffle("\0")',fgets(STDIN));
† There's only one letter in the middle, so it doesn't matter if you shuffle it.
Python, 118
Python is terribly awkward for things like this!
from random import*
for w in raw_input().split():l=len(w)-2;print l>0and w[0]+''.join((sample(w[1:-1],l)))+w[-1]or w,
Bonus
I tried some other things that I thought would be clever, but you have to import all sorts of things, and a lot of methods don't have return values, but need to be called separately as its own statement. The worst is when you need to convert the string to a list and then join
ing it back to a string again.
Anyways, here are some of the things that I tried:
Regex!import re,random
def f(x):a,b,c=x.group(1,2,3);return a+''.join(random.sample(b,len(b)))+c
print re.sub('(\w)(\w+)(\w)',f,raw_input())
Permutations!
import itertools as i,random as r
for w in raw_input().split():print''.join(r.choice([x for x in i.permutations(w)if w[0]+w[-1]==x[0]+x[-1]])),
You can't shuffle a partition of a list directly and shuffle
returns None
, yay!
from random import*
for w in raw_input().split():
w=list(w)
if len(w)>3:v=w[1:-1];shuffle(v);w[1:-1]=v
print ''.join(w),