random function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samir

    random function

    I don't know if this is easy or not, I have no clue on how to start it.

    I have Seven different states.
    I will be having a form with 7 textboxes, and I will enter 7 different
    states each time in the textbox.
    When I click on the button, it would call a function
    the function would output :
    6 different combinations of 3 states. So I would have 1-6 and for each
    would list three states I entered in the textboxes.

    Thanks alot!


  • Evertjan.

    #2
    Re: random function

    Samir wrote on 10 sep 2004 in comp.lang.javas cript:[color=blue]
    > I have Seven different states.[/color]

    you mean like:

    1 awake
    2 asleep
    3 programming
    4 working
    5 in love
    6 hungry
    7 dead

    ?
    [color=blue]
    > I will be having a form with 7 textboxes, and I will enter 7 different
    > states each time in the textbox.
    > When I click on the button, it would call a function
    > the function would output :
    > 6 different combinations of 3 states. So I would have 1-6 and for each
    > would list three states I entered in the textboxes.[/color]

    like:

    1 123
    2 124
    3 125
    4 126
    5 134
    6 132

    ?

    You cannot be awake and asleep at once.

    Seems sily to me, but probably I misunderstand you.
    Or is it "states" like in "baseball cards"?

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)

    Comment

    • Lee

      #3
      Re: random function

      Samir said:[color=blue]
      >
      >I don't know if this is easy or not, I have no clue on how to start it.
      >
      >I have Seven different states.
      >I will be having a form with 7 textboxes, and I will enter 7 different
      >states each time in the textbox.
      >When I click on the button, it would call a function
      >the function would output :
      >6 different combinations of 3 states. So I would have 1-6 and for each
      >would list three states I entered in the textboxes.[/color]


      This sounds a bit like a class assignment to me, but I'm
      avoiding starting my real work, so I'll bite:

      The way to start it is to state the problem more precisely.

      As I understand it, you're looking for a function that will
      take as input the values of seven text fields, and will
      generate six different combinations of those seven values
      taken three at a time.

      1. It's not clear how you want these combinations to be
      presented on your page.

      2. Since there are 35 possible combinations of 7 items
      taken 3 at a time, it's not clear whether you want to
      choose six of them at random, or if it's ok to use the
      same pattern each time.

      If it doesn't need to be random, here's a trivial solution in
      which combination #n contains the three sequential inputs
      beginning with input #n (looping back to the beginning at the
      end of the list of inputs.
      So if the "states" are "alpha" "beta" "gamma" "delta" ..., the
      first combination will be "alpha beta gamma", the second will
      be "beta gamma delta", etc:


      <html>
      <head>
      <title>Combinat ions</title>
      <script type="text/javascript">
      function combine(inArray ,outArray){
      for(i=0;i<6;i++ ){
      outArray[i].value="";
      var j=i;
      for(k=0;k<3;k++ ){
      outArray[i].value+=inArray[j++].value+" ";
      j%=6;
      }
      }
      }
      </script>
      </head>
      <body>
      <form>
      <input name="state" value="a" size="4">
      <input name="state" value="b" size="4">
      <input name="state" value="c" size="4">
      <input name="state" value="d" size="4">
      <input name="state" value="e" size="4">
      <input name="state" value="f" size="4">
      <input name="state" value="g" size="4">
      <br>
      <input type="button"
      value="combine"
      onclick="combin e(this.form.sta te,this.form.co m)">
      <hr>
      <input name="com" size="8"><input name="com" size="8">
      <input name="com" size="8"><input name="com" size="8">
      <input name="com" size="8"><input name="com" size="8">
      </form>
      </body>
      </html>

      Comment

      Working...