| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Nov 2008
Posts: 36
|
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 /. |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Nov 2008
Posts: 36
|
:|
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;
}
|
|
|
|
|
|
|
|
|
#3 |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
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...
|
|
|
|
|
|
#4 |
|
Registered User
Join Date: Nov 2008
Posts: 36
|
I forgot it's the weekend in the normal world :| Our weekend is on Thu and Fri, sigh.
|
|
|
|
|
|
#5 |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
|
dont get too discouraged, it was a very cool challenge. just give it more time next time
![]() |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |