Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica: I made a program, but can't manipulate it. Please help!

  1. Feb 4, 2012 #1
    The program I wrote accepts a certain number between 3 and 18.
    Then it returns the ways this number can be obtained by throwing three dice simultaneously and adding the face values.
    I want to manipulate this number, :biggrin:
    but can't achieve it using the ordinary code of manipulation. :grumpy:

    I tried to find any error, but really wasn't able to figure out where have I gone wrong. :confused:

    Need help!

    Code (Text):


    j = 0;
    For [
          x = 1,
          x <= 6,
          x++,
          For [
                y = 1,
                y <= 6,
                y++,
                For [
                      z = 1,
                      z <= 6,
                      z++,
                      {
                       If [
                           x + y + z == 5,  (*accepts the required sum of the face values*)
                           {
                            If [
                                j + 1 <= 9,
                                Print [j + 1, ".", "   ", x , " ", y, " " , z ],
                                Print [j + 1, ".", "  ", x , " ", y, " " , z ]
                               ],
                            j++
                           }    
                          ]
                      }
                     ]
               ]
         ]

     
     
    Last edited: Feb 4, 2012
  2. jcsd
  3. Feb 4, 2012 #2

    phyzguy

    User Avatar
    Science Advisor

    You could define a function, and then evaluate it for different values, like this:

    Code (Text):


    f[w_] :=
     Module[{j = 0},
      For[x = 1, x <= 6, x++,
       For[y = 1, y <= 6, y++,
        For[z = 1, z <= 6,
         z++, {If[
           x + y + z ==
            w,(*accepts the required sum of the face values*){If[
             j + 1 <= 9, Print[j + 1, ".", "   ", x, " ", y, " ", z],
             Print[j + 1, ".", "  ", x, " ", y, " ", z]], j++}]}]]]]

    f[5]

    1.   1 1 3

    2.   1 2 2

    3.   1 3 1

    4.   2 1 2

    5.   2 2 1

    6.   3 1 1

    f[3]

    1.   1 1 1

    f[4]

    1.   1 1 2

    2.   1 2 1

    3.   2 1 1


     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica: I made a program, but can't manipulate it. Please help!
  1. Manipulate Mathematica (Replies: 1)

Loading...