Al Zimmermann's contest. page 2

31 posts

Flag Post

For my own benefit, I figured out how to calculate large numbers. So, without further ado, 1000! =


pre in order to avoid massive text wall. Once I ironed out some of the kinks, the calculations all happen very fast (it only took flash 0.13 seconds to calculate that and sew it all into a string).

Flag Post

You should get a github repo and upload your code. I’d be interested.

Flag Post

For large number calculations like that, it can be convenient to use a programming language like Ruby which natively supports arbitrary-sized integer arithmetic (or some fancy name like that, basically it handles big numbers accurately).

Anyway, the line of ruby code: (1..1000).inject(:*) will give you 1000!

You can try running it here for example.

(The code just means combine all the numbers from 1 to 1000 by multiplying them)

Flag Post

Yeah, I could have used a language specifically designed to do it, but setting up everything in order to do it seemed like it would’ve been a bit of a pain.

It’s really quite simple to do, just use an array where each element is a digit in the number. It could probably be optimised quite easily by using a fixed length Vector or a Byte Array? but I was just looking for a quick solution to get it to work. I’ll post it next time I get on Kong.
It reaches its limit at around 10000! (~13 seconds) before it hits the timeout limit of 15, which can probably be circumvented somehow.

Flag Post

You can circumvent timeout limits by decomposing the operation into smaller steps and making a small step part of a loop triggered by a Event.EVENT_FRAME, as so:

		private function tick(eve:Event):void
			var deadline:int = getTimer() + updateFrequencyInMs;
			while (getTimer() < deadline)
				if (currentnode)

To provide a bit of context, that function is part of a program which runs a series of searches by taking steps in a multidimensional space of possible configurations. Like a blind man trekking through a desert searching for an oasis, if you will.

updateFrequencyInMs is the time between two frames (50, at 20 FPS, for instance), so the blind man walks a step, checks his watch, takes another, checks again, and so on, until it’s time to display the next frame or he’s found an oasis (and then the next blind man gets dropped in the desert, or the program ends if it’s out of blind men.) Not only will the program never hit the timeout limit (assuming a single step never takes anywhere close to the timeout limit, in my case I averaged 28-35000 steps per second), but every frame you can update the display to show the user exactly where the program is at, for instance by updating a TextField with the value of a few salient variables. That’s what updateFields() is for, which could just as well have been named reportProgress().

Flag Post

That sounds like a very good idea if I ever need complex calculations in games so that people don’t think the game has crashed and leave.

Anyway, here you go. It really is very simple.

public static function bigFact(i:int):String{
	var carry:int,len:int;
	var j:int,k:int;
	var numbers:Array = [1];
	for (j=2;j<i;j++){
		len = numbers.length;
		carry = 0;
			var temp:int = numbers[k]*j + carry;
			if(temp>9)carry = int(temp*0.1);
			else carry = 0;
			numbers[k]= temp - carry*10;
			numbers[len]=carry - int(carry/10)*10;
	var number:String = "";
	for(j = numbers.length-1;j>=0;j--){
		number += numbers[j];
		if(j)if(j%3==0)number += ",";
	return number;

The digits are held in the array backwards, which allows for easier flexibility and ordering. Every increment of j in the primary loop just multiplies all digits in the array by j, then puts all the carried digits at the end. Passing the final string without commas, or passing the array itself would for all types of further calculations.