Tech Interview Question Tip – AS3 – Compute Factorial Iterative and Recursive
package
{
import flash.display.Sprite;
/**
* ...
* @author Jeff Fulton
*/
public class ComputeFactorial extends Sprite
{
/*In mathematics, the factorial of a positive integer n,[1]
* denoted by n!, is the product of all positive integers
* less than or equal to n.
* There are two methods. Recursion is the classic method
* Code Complete says that recursion is a improper method
* Second version is the code complete iteration version
*/
public function ComputeFactorial()
{
//recusrive methos
trace ("recursive:",recursiveFactorial(3));
trace ("iterative:",iterativeFactorial(3));
}
private function recursiveFactorial(num:int):int {
if (num <= 1) {
return(1);
}else {
return (num * recursiveFactorial(num - 1));
}
}
private function iterativeFactorial(num:int):int {
var result:int = 1;
for (var factor:int = 2; factor <= num; factor++) {
result = result * factor;
}
return result;
}
}
}
Emanuele shows you how to make a complete Flash Tetris Game
Check out his Kung Fu.
AtariMania adds the Complete Set Of Page 6 Magazine Issues
Page 6 was a great UK-based magazine for Atari personal computers. Check out the scans.
Just Plain Awesome
TrueTv’s 21 strangest Conspiracy Theories
The 8bitrocket Daily Inter-Web Mash-up Briefing is compiled and edited by both Jeff D. Fulton and Steve A. Fulton. We cover the world of retro games, new games, indie games, Flash / Web games, game coding, the toy industry, and anything else we find cool. Send news items that you would like covered to info[at]8bitrocket[dot]com
Leave a comment