Thursday, February 7, 2013

Typoglycemia

Typoglycemia is the name given to an internet meme that went around a few years ago, purporting to demonstrate that "readers can understand the meaning of words in a sentence even when the interior letters of each word are scrambled".

Can you read this?

...it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoatnt tihng is taht the frist and lsat ltteer be in the rghit pclae.

Well, perhaps it isn't completely true, but it at least is mostly true. How about an implementation of this in Factor?

We will start by building a word to "misspell" a string that is at least four letters long (ignoring any punctuation at the end) and randomizing all the characters except the first and last:

: misspell-word ( word -- word' )
    dup [ ",'.:;!?" member? not ] find-last drop 0 or
    dup 2 > [
        dupd head-slice dup [ Letter? ] all?
        [ rest-slice randomize ] when drop
    ] [ drop ] if ;

Next, we will "misspell" a line of text:

: misspell-line ( line -- line' )
    [ blank? ] split-when [ misspell-word ] map " " join ;

Finally, misspelling a block of text:

: misspell ( string -- string' )
    string-lines [ misspell-line ] map "\n" join ;

You can try it to show it works:

IN: scratchpad "this really works!" misspell .
"this relaly wroks!"

Maybe it would be easier to read if we just randomly swap two letters in the middle of each word, rather than fully randomizing it?

2 comments:

Zeev said...

I believe that if you replace letters that stick up with other letters that stick up, replace letters that stick down with other letters that stick down and replace normal height letters with normal height letters, the shape of the word will remain unchanged. This should enable it to be recognized by the pattern matching algorithm in your head.

Unknown said...

I have no problem to read the modified text at all. Almost as fast as the unmodified version.