I was just reading the Wikipedia page on Typoglycemia:
... readers can understand the meaning of words in a sentence even when the interior letters of each word are scrambled ...
and wanted to know how that text can be produced with Mathematica.
My code is given below, but it does not check if the first or last character is not a letter.
How would you solve this?
text = "In a publication of New Scientist you could randomise all the \
letters,keeping the first two and last two the same,and readability \
would hardly be affected.My analysis did not come to much because the \
theory at the time was for shape and sequence recognition.Saberi's \
work suggests we may have some powerful parallel processors at \
work.The reason for this is surely that identifying content by \
parallel processing speeds up recognition.We only need the first and \
last two letters to spot changes in meaning.";
words = StringSplit[text];
randomWords = Array[0 &, Length[words]];
numWords = Length[randomWords];
getRandomWord[x_] := Module[
{word = x},
wordLength = Length[word];
firstLetter = StringTake[word, 1];
lastLetter = StringTake[word, -1];
restString = StringTake[word, {2, wordLength - 2}];
randomLetters = RandomSample[StringPartition[restString, 1]];
result = StringJoin[firstLetter, randomLetters, lastLetter]
];
Table[
word = words[[count]];
wordLength = StringLength[word];
If[wordLength < 3, randomWords[[count]] = word,
randomWords[[count]] = getRandomWord[word]],
{count, 1, numWords}
];
randomText = StringRiffle[randomWords]
"In a pbilcituaon of New Snscetiit you could ridnomsae all the \
liteepsr,eknetg the fisrt two and last two the sa,anmed rteiaiadbly \
wluod hladry be adMf.etecfy ayaisnls did not cmoe to much bacusee the \
torhey at the tmie was for spahe and snquecee rbgtnSi.oeein'iocars \
work sugtgess we may hvae some pewfroul parealll prrsocoses at \
whrkT.oe rosean for this is srluey that iydeintfnig cenotnt by \
pleaalrl piernocssg spdees up rongiecWt.ione olny need the first and \
lsat two letters to spot chgeans in mgaenin."