• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to solve this equation?

Explorer ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

can anybody help me, solve this problem in as3 ?

x+y+z=8000;

0.17*x + 0.35*y +0.08*z =960

thanks very much!!!

TOPICS
ActionScript

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

I kinda wanna lean on rusty learning and say it can't be solved... three unknowns requires three equations. 

As far as solving it with AS3, what do you mean?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 24, 2012 May 24, 2012

Copy link to clipboard

Copied

thanks for reply.somebody   like the following equation

1、x+y+z=100

2、3x+8y+1/3z=100,

used  code like this to solving the equation,but, i din't understand how to do it !!!

Sub xxx()

Dim x%, y%, z%, i%, k%

For i = 0 To 33

    For j = 0 To 12

        For k = 0 To 300 Step 3

            If i + j + k = 100 And 3 * i + 8 * j + 1 / 3 * k = 100 Then

                MsgBox "x=" & i & "y=" & j & "z=" & k

            End If

        Next k, j, i

End Sub

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2012 May 25, 2012

Copy link to clipboard

Copied

AS3 for the above is

for (var i:int = 0; i < 33; i++)

{

          for (var j:int = 0; j < 12; j++)

          {

                    for (var k:int = 0; k < 300; k += 3)

                    {

                              if ((i + j + k == 100) && (3*i + 8*j + k/3) == 100)

                              {

                                        trace("x=", i, ", y=", j, ", z=", k);

                              }

                    }

          }

}

trace("done");

note 3 unknowns with 2 equations gives 2 solutions

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 25, 2012 May 25, 2012

Copy link to clipboard

Copied

thanks.

but i means that how to used this code to solve my problem ??this is the key question!!!

2012-05-25

方林勇

发件人:_spoboyle

发送时间:2012-05-25 16:05

主题:[Action Script 3] How to solve this equation?

收件人:"fanglinyong"<fanglinyong_81@163.com>

抄送:

Re: How to solve this equation?

created by _spoboyle in Action Script 3 - View the full discussion

AS3 for the above is

for (var i:int = 0; i < 33; i++)

{

for (var j:int = 0; j < 12; j++)

{

for (var k:int = 0; k < 300; k += 3)

{

if ((i + j + k == 100) && (3i + 8j + k/3) == 100)

{

trace("x=", i, ", y=", j, ", z=", k);

}

}

}

}

trace("done");

Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:

To unsubscribe from this thread, please visit the message page at . In the Actions box on the right, click the Stop Email Notifications link.

Start a new discussion in Action Script 3 by email or at Adobe Forums

For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 25, 2012 May 25, 2012

Copy link to clipboard

Copied

LATEST

this gives a little more explanation, although doesn't actually complete for me there are too many permitations

you are also going to have to worry about the number representation issue using floating points numbers

it might be better to convert the second equations to something equivalent which uses ints

package

{

          import flash.display.Sprite;

          public class Main extends Sprite

          {

                    //x+y+z=8000;

                    //0.17 * x + 0.35 * y +0.08 * z = 960

                    public function Main()

                    {

                              // consider each equation in the form a.x + b.y + c.z = d

                              // we have 3 unknowns x, y, z so we need 3 nested for loops to run over all possibilities

                              // then the maximum value x can be is d/a

                              // maximum y = d/b

                              // maximum z = d/c

                              // now if we have 2 equations we need to take the maximum for each known from either equation

                              // so in your case with maximum x is the maximum of 8000/1 and 960/0.17 =

                              // maximum y is the maximum of 8000/1 and 960/0.35

                              // maximum z is the maximum of 8000/1 and 960/0.08

                              // all these maximums should be rounded down to the nearest integer

                              //max x = 8000

                              //max y = 8000

                              //max z = 12000

                              //we use these maximum values for the nested for loop limits

                              var maxX:int = Math.max(8000 / 1, 960 / 0.17);

                              var maxY:int = Math.max(8000 / 1, 960 / 0.35);

                              var maxZ:int = Math.max(8000 / 1, 960 / 0.08);

                              trace("max values: ", maxX, maxY, maxZ);

                              for (var i:int = 0; i < maxX; i++)

                              {

                                        for (var j:int = 0; j < maxY; j++)

                                        {

                                                  for (var k:int = 0; k < maxZ; k++)

                                                  {

                                                            // this if statement is a representation of if the values for x, y and z we are trying

                                                            // actually solve the equations

                                                            // so in your case use the following

                                                            if ((i + j + k == 8000) && (0.17*i + 0.35*j + 0.08*k) == 960)

                                                            {

                                                                      trace("x=", i, ", y=", j, ", z=", k);

                                                            }

                                                  }

                                        }

                              }

                              trace("done");

                    }

          }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines