Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > Community Boards > Just for Kicks Challenges

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-15-2008, 05:55 AM   #1
ljuwaidah
Registered User
 
Join Date: Nov 2008
Posts: 36
Smile Divide function

Hi,

I started a challenge like this one on some other forum but many people found it too hard so it didn't go so well, let's hope it goes well this time

It's pretty simple: Create a divide function and optimize it!

Have fun,

I'll post my code soon (I have it already).

[Edit:] You have to do this without using the divide operator /.
ljuwaidah is offline   Reply With Quote
Old 11-16-2008, 06:10 AM   #2
ljuwaidah
Registered User
 
Join Date: Nov 2008
Posts: 36
Default

:|
Code:
private function init():void {
    number.text = divide(12, 7).toString();
}

private function divide(num1:Number, num2:Number):Number
{
    var places:int = 0;
    var tempRes:Number;
    var ltCounter:int = 0;
    var temp:Number;
    var point:Boolean = false;
    var container:String = "";
    var counter:int;
    var result:Number;

    while(num1 % int(num1))
    {
        num1 *= 10;
        places++;
    }
    while(num2 % int(num2))
    {
        num2 *= 10;
        places++;
    }

    tempRes = num1;

    while(tempRes != 0 && ltCounter <= 17)
    {
        temp = tempRes;
        if(temp < num2)
        {
            temp *= 10;
            if(!point)
            {
                if(container == "")
                {
                    container += "0";
                } 
                container += ".";
                point = true;
            }
        }
        counter = 0;
        while(temp >= num2)
        {
            temp -= num2;
            counter++;
        }
        container += counter.toString();
        tempRes = temp;
        ltCounter++;
    }
    result = parseFloat(container);
    result *= Math.pow(10, places); 
    return result;
}
ljuwaidah is offline   Reply With Quote
Old 11-16-2008, 09:26 AM   #3
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

you gotta give people more that a saturday night to do this... not nearly enough people visit this part of the forum on normal days much less weekends...
pj-co is offline   Reply With Quote
Old 11-16-2008, 09:43 AM   #4
ljuwaidah
Registered User
 
Join Date: Nov 2008
Posts: 36
Default

I forgot it's the weekend in the normal world :| Our weekend is on Thu and Fri, sigh.
ljuwaidah is offline   Reply With Quote
Old 11-16-2008, 10:31 AM   #5
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

dont get too discouraged, it was a very cool challenge. just give it more time next time
pj-co is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
one template, many looks? subquark ActionScript 1.0 (and below) 1161 09-03-2009 04:45 PM
a function receiving a movieClip KaizerKaizer Simple Stuff (Newbies) 10 07-14-2008 01:35 PM
too much knowledge required to take advantage of the beauty of extending classes dsdsdsdsd ActionScript 3.0 4 03-17-2008 09:53 AM
Ease parameter Clutchplate Simple Stuff (Newbies) 8 03-16-2007 12:21 PM
flash movie plays in browser too slow m1cky ActionScript 2.0 7 01-11-2005 09:11 PM


All times are GMT. The time now is 08:23 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.