Sign in to follow this  
Followers 0
Toady

Sentence scrambler

7 posts in this topic

#1 ·  Posted (edited)

Aoccdrnig to a rscheearch at an Elingsh uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht frist and lsat ltteer is at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae we do not raed ervey lteter by it slef but the wrod as a wlohe..

Looky.. :whistle:

I know its old, so please don't post unless you have something useful to say, thanks.

#include <GuiConstants.au3>

$GUI = GUICreate("Sentence scramble",300,300,-1,-1)
GUICtrlCreateLabel("Enter a sentence",20,10,100)
$input_sentence = GUICtrlCreateInput("",20,30,260,100, $ES_MULTILINE)
$button = GUICtrlCreateButton("Scramble Sentence",90,260,120,30)
$output_sentence = GUICtrlCreateEdit("",20,150,260,100, $ES_READONLY)
GUISetState(@SW_SHOW,$GUI)

While 1
    $msg = GUIGetMsg()
    Select 
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button
            Local $sentence = GUICtrlRead($input_sentence)
            If $sentence <> "" Then
                GUICtrlSetData($output_sentence,"")
                GUICtrlSetData($output_sentence,_Sentence_Scramble($sentence))
            Else
                MsgBox(0,"No sentence entered","Enter a sentence")
            EndIf
    EndSelect
WEnd

Func _Sentence_Scramble($sentence)
    Local $randomList
    Local $scrambled_Sentence
    $randomList = StringSplit($sentence," ")
    For $i = 1 To $randomList[0] 
        $scrambled_Sentence &= _Word_Randomize($randomList[$i]) & " "
    Next
    Return StringTrimRight($scrambled_Sentence,1)
EndFunc

Func _Word_Randomize($word)
    If StringLen($word) < 4 Then Return $word
    Local $literal
    For $i = 2 To Int(StringLen($word) / 2)
        $literal = $literal & StringMid($word, StringLen($word) - _ 
        $i + 1, 1) & StringMid($word, $i, 1)
    Next
    If Mod(StringLen($word), 2) Then
        $literal = $literal & StringMid($word, $i, 1)
    EndIf
    Return StringLeft($word,1) & $literal & StringRight($word,1)
EndFunc
Edited by Toady

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Share this post


Link to post
Share on other sites



Looky.. :whistle:

#include <GuiConstants.au3>

$GUI = GUICreate("Sentence scramble",300,300,-1,-1)
GUICtrlCreateLabel("Enter a sentence",20,10,100)
$input_sentence = GUICtrlCreateInput("",20,30,260,100, $ES_MULTILINE)
$button = GUICtrlCreateButton("Scramble Sentence",90,260,120,30)
$output_sentence = GUICtrlCreateEdit("",20,150,260,100, $ES_READONLY)
GUISetState(@SW_SHOW,$GUI)

While 1
    $msg = GUIGetMsg()
    Select 
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button
            Local $sentence = GUICtrlRead($input_sentence)
            If $sentence <> "" Then
                GUICtrlSetData($output_sentence,"")
                GUICtrlSetData($output_sentence,_Sentence_Scramble($sentence))
            Else
                MsgBox(0,"No sentence entered","Enter a sentence")
            EndIf
    EndSelect
WEnd

Func _Sentence_Scramble($sentence)
    Local $randomList
    Local $scrambled_Sentence
    $randomList = StringSplit($sentence," ")
    For $i = 1 To $randomList[0] 
        $scrambled_Sentence &= _Word_Randomize($randomList[$i]) & " "
    Next
    Return StringTrimRight($scrambled_Sentence,1)
EndFunc

Func _Word_Randomize($word)
    If StringLen($word) < 4 Then Return $word
    Local $literal
    For $i = 2 To Int(StringLen($word) / 2)
        $literal = $literal & StringMid($word, StringLen($word) - _ 
        $i + 1, 1) & StringMid($word, $i, 1)
    Next
    If Mod(StringLen($word), 2) Then
        $literal = $literal & StringMid($word, $i, 1)
    EndIf
    Return StringLeft($word,1) & $literal & StringRight($word,1)
EndFunc
this is old i saw this like 2 years ago

on a diffeenty site

Share this post


Link to post
Share on other sites

this is old i saw this like 2 years ago

on a diffeenty site

Scrambled sentences are easier to understand then Ashley's. (Oh snap)

I aylaws leovd tshee tshgin.

Share this post


Link to post
Share on other sites

You are right. I was easily able to read that first paragraph. Good job!


[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Mnoodiitfaics to tihs pohneenmon hvae been persoopd - taht is, the mroe ceotmapclid (drae: lroeng) the wdors aer, the lses llieky taht you wlil slulcuefssy be albe to deehcpir tehm on the fsirt psas thhgruo. I am ulnbae to fnid the pgae at the mtonme, but if I reebmmer cyolrtrce, it had snoimhetg to do wtih the pnleamcet of vloews tuhorhogut the wdors as wlel.

Translation:

Modifications to this phenomenon have been proposed - that is, the more complicated (read: longer) the words are, the less likely that you will sucessfully be able to decipher them on the first pass through. I am unable to find the page at the moment, but if I remember correctly, it had something to do with the placement of vowels throughout the words as well.

It would be very interesting, if we could reinvent or find the rules they proposed, to modify this script with the new 'rules' and see if it passes or fails as above...

However, very cool script! :whistle:

Edit: Haven't found the original page I was looking for, but there's a pretty good discussion of this phenomenon and possible reasons for it at http://www.languagehat.com/archives/000840.php. My favorite part was this:

"Artichoking to a reindeerwash at Cartilage Unfamiliarity, it dentis't molar in wheat oater the ladybugs in a weed ate, the ozzy insideout thong is twit the foist and list louvre be at the ranft pekoe. The raft can be a Tyrol MIDI and you can shell rind it whippet pogrom. Toes is buncombe the harem mood digs not road energy ladder by insectivore, but the wild as a wookiee."

Edited by james3mg

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0