Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Typoglycemia Fun

by reasonablekeith (Deacon)
on May 20, 2005 at 09:09 UTC ( #458882=snippet: print w/ replies, xml ) Need Help??

Description: There is an eamil which fatlos anorud from time to tmie saying that, beacuse of the way the haumn brian redas wrdos as a wohle, taht the oderr of inividudal letetrs isn't taht imatrpont. The only caveat benig taht the the frist and lsat leettrs must be in the correct potision. Awyany, I thugoht I'd konck up a perl sprcit to test tihs, and what do you know, it works. But only to a pinot. The exmpale eaiml is clarely tuend, and any hrad to raed wrods seem to have been pleyad arnuod wtih. Tihs is more noibctale for the lngoer wdors, whree a two chaatrcer laed-in and lead-out smees to hlep maesivsly.

The oehtr thnig I noctied was that if you ceatre a new wrod afetr the shfulifng, then you only see that new word, wihch makes tngihs a bit cofnisung. Ejony.

PS. I wdolun't try and run peldroc thruogh it, that gets _very_ coufinsng.

#!/perl -w
use strict;

# shuffle function from List::Util
sub shuffle (@) {
  my @a=\(@_);
  my $n;
  my $i=@_;
  map {
    $n = rand($i--);
    (${$a[$n]}, $a[$n] = $a[$i])[0];
  } @_;
}


while (<DATA>) {
    my $line = $_;
    my $line_copy = $line;
    while ($line =~ m/(\w+)/g) {
        next if length($1) < 4;
        my $start_offset = pos($line) - length($1) +1;
        my $word_middle_length = length($1) - 2;

        # force two character lead-in and lead-out
        if ($word_middle_length > 4) {
            $word_middle_length -= 2;
            $start_offset++;
        }
        my $word_middle = substr($line, $start_offset, $word_middle_le
+ngth);
        my $shuffled_word_middle = join('', shuffle( split(//, $word_m
+iddle) ) );
        substr($line_copy, $start_offset, $word_middle_length) = $shuf
+fled_word_middle;
    }
    print $line_copy;
}



__DATA__
There is an email which floats around from time to time saying that, b
+ecause of the way
the human brain reads words as a whole, that the order of individual l
+etters isn't that 
important. The only caveat being that the the first and last letters m
+ust be in the 
correct position. Anyway, I thought I'd knock up a perl script to test
+ this, and what do
you know, it works. But only to a point. The example email is clearly 
+tuned, and any
hard to read words seem to have been played around with. This is more 
+noticable for the
longer words, where a two character lead-in and lead-out seems to help
+ massively.

The other thing I noticed was that if you create a new word after the 
+shuffling, then
you only see that new word, which makes things a bit confusing. Enjoy.

PS. I wouldn't try and run perldoc through it, that gets _very_ confus
+ing.
Comment on Typoglycemia Fun
Download Code
Re: Typoglycemia Fun
by pelagic (Curate) on May 20, 2005 at 09:14 UTC
    vrey fnnuy idened!

    pelagic
Re: Typoglycemia Fun
by shenme (Priest) on May 20, 2005 at 20:07 UTC
    I'd seen references to the idea, and had had no problems reading the shuffles, until 'fatlos', which totally threw me. I'm thinking that words that have two internal vowels together suffer much more than other words. Even 'smees' is kinda hard. Who knows what _could_ have happened to 'caveat' if it had been shuffled - 'cvaaet'?

      Yeah, I had trouble reading "fatlos" too. I'm thinking it's probably because the word is "float", so it should probably be shuffled as such, so it should start with an 'f' and end with a 'ts', not just an 's'. (No, I'm not saying the code should be changed or anything, that's just why I think 'fatlos' was so hard for me to read (actually, I just looked at the cleartext, 'cause I didn't understand it right away.))

      -Bryan

        I wonder which would be better? Keeping closing consanant groups together (e.g. ts, ly, ck, etc.) or keeping the syllable count the same? Or both?

        Hmmm. Something to play with this weekend.

        Jack

Re: Typoglycemia Fun
by tcf03 (Deacon) on May 21, 2005 at 02:25 UTC
    or for the web-venturous
    #!/usr/bin/perl -T use strict; use warnings; #use diagnostics; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); # Clean up our UNIX environment # for more infor read perldoc perlsec $ENV{'PATH'} = '/awiopt/radio:/tmp'; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Flush the output buffer $|++; my @text; # shuffle function from List::Util sub shuffle (@) { my @a=\(@_); my $n; my $i=@_; map { $n = rand($i--); (${$a[$n]}, $a[$n] = $a[$i])[0]; } @_; } print header; print start_html(-title=>"Fun with Typoglycemia", -BGCOLOR=>"#cccc99" ), "\n"; print "<tt><center>\n"; print h3("Fun", "With", "Typoglycemia"),"\n"; print "</center>\n"; print hr,"\n"; print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" wid +th=\"70%\" align=\"center\">\n\n"; print "<tr align=\"center\" bgcolor=\"#999966\">\n <th>Typoglycemic Text</th>\n </tr>\n"; print "<td>\n"; if ( defined (param('TEXT')) ) { # $/=undef; @text=param('TEXT'); for (@text) { my $line = $_; my $line_copy = $line; while ($line =~ m/(\w+)/g) { next if length($1) < 4; my $start_offset = pos($line) - length($1) +1; my $word_middle_length = length($1) - 2; # force two character lead-in and lead-out if ($word_middle_length > 4) { $word_middle_length -= 2; $start_offset++; } my $word_middle = substr($line, $start_offset, $word_middle_le +ngth); my $shuffled_word_middle = join('', shuffle( split(//, $word_m +iddle) ) ); substr($line_copy, $start_offset, $word_middle_length) = $shuf +fled_word_middle; } print "$line_copy\n"; } } print "</td>\n"; print "</table>\n"; print br,br; print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" wid +th=\"70%\" align=\"center\">\n\n"; print "<tr align=\"center\" bgcolor=\"#999966\">\n <th>Enter your text</th>\n </tr>\n"; print "</table>\n"; print br,br; print start_form; print "<center>\n"; print textarea('TEXT',"", 15, 80), "\n",br; print submit; print end_form; print "</center>\n",br; print "\n\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" hei +ght=\"20\" width=\"70%\" align=\"center\">\n\n"; print "<tr align=\"center\" bgcolor=\"#999966\">\n <td> </td>\n </tr>\n"; print "</table>\n",br; print end_html;

    I couldn't resist...
    Ted
    --
    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
      --Ralph Waldo Emerson
Re: Typoglycemia Fun
by jZed (Prior) on May 21, 2005 at 03:48 UTC
    For a scholarly analysis of the "jumbled spelling" urban legend which has been floating around the net for a few years, see this article on jumbled spelling from a Cambridge linguist which also includes a few other scripts which do similar things to yours. The issue has come up here at PerlMonks before and there were a few other scripts posted. I tried some searches but wasn't able to find it.

    update Ah, found it. (The previous PM posting on a jumbled spelling generator).

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://458882]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-25 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls