Results 1 to 6 of 6

Thread: Can you point me to a script that does this?

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default Can you point me to a script that does this?

    Okay, I may be asking a lot here....

    I have 5 sentences, of 5 words each. I am to make one sentence of 5 words using only one word from each original sentence.

    I have searched the web for hours trying to find a program that would allow me to input the 25 words and rearrange them for me.

    If possible I would love someone to point the way to such a program, or maybe even write one????

    This is for a game, nothing major, but with (5!)3125 choices (375000 approximate options) you can see why I would rather NOT do this with pen and paper....

    Thanks to anyone who can help!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Something like:
    Code:
    <script type="text/javascript">
    var sentences = new Array();
    sentences[0] = "Hello my name is John"; // apologies for lack of punctuation :p
    sentences[1] = "Won't it be hot tomorrow";
    sentences[2] = "Who turned the light on";
    sentences[3] = "I think it might be";
    sentences[4] = "I'm running out of ideas";
    
    var tot = "";
    
    for(var i=0;i<sentences.length;i++) {
      var words = new Array();
      words = sentences[i].split(" ");
      var word = words[Math.floor(Math.random() * words.length)];
      if(i != 0) word = " " + (word == "I" ? word : word.toLowerCase());
      else {
        var firstChar = word.charAt(0).toUpperCase();
        word = firstChar + word.substr(1);
      }
      tot += word;
    }
    tot += ".";
    // The final sentence is stored at "tot."
    </script>
    ? I hope you're not expecting actual grammar or punctuation or anything
    Last edited by Twey; 10-11-2005 at 04:48 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I worked it out this way, put this in the body of your page:

    Code:
    <script type="text/javascript">
    //Randomizing Unit Courtesy of Mike Winter as seen at:
    //http://www.dynamicdrive.com/forums/showthread.php?p=8442
    function random(n) {
      return Math.floor((Math.random() % 1) * n);
    }
    
    Array.prototype.shuffle = function() {var i = this.length;
      while(i--) {this.swap(i, random(i + 1));}
    };
    Array.prototype.swap = function(x, y) {
      var t = this[x]; this[x] = this[y]; this[y] = t;
    };
    //End Randomizing Unit
    var endSen=''
    sens=new Array();
    //set sentences below
    sens[0]="five words in a row"
    sens[1]="fish do not use cars"
    sens[2]="birds are on the fly"
    sens[3]="animals have many friends too"
    sens[4]="who asked you the question"
    for (var i_tem = 0; i_tem < sens.length; i_tem++){
    sens[i_tem]=sens[i_tem].split(' ')
    endSen+=sens[i_tem][random(5)]+' '
    }
    endSen=endSen.split(' ')
    endSen.shuffle();
    endSen=endSen.join(' ')
    if(endSen.charAt(0)==' ')
    endSen=endSen.substr(1)
    endSen=endSen.charAt(0).toUpperCase()+endSen.substr(1)
    document.write(endSen+'.')
    
    </script>
    Last edited by jscheuer1; 10-11-2005 at 04:58 PM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Talking

    You guys are AWESOME!!!!!!!

    Thanks a lot! And no punctuation and grammar are not important. Working on them now!

    This place is so awesome!

    Thanks again!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    And no punctuation and grammar are not important. Working on them now!
    That might be quite difficult. Punctuation support is conceivable, but to get actual grammar you'd have to have a list of every single possible word and its grammatical type.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Wink

    Well apparently the "answer" is just 5 of those 25 words, in a random (and semi-sensible) order, so I am guessing we do not change the words at all. so "called" would stay "called" and not be changed to "calls" or "calling"

    So as far as I am concerned this script works perfect!

    Thanks again!
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •