Algorithms!

Posted by ludamad on Dec. 11, 2008, 8:32 p.m.

Alright 64Digits, show me your stuff. I will describe three programming situations, and you will describe, or write, the most efficient algorithm for each situation. Most efficient answer wins. Anything goes, but no punches below the belt.

You can give me your answer in words, or give it to me in any language if you feel that is easier.

All questions have been devised by me, although they aren't that original.

Situation 1:

You are given a positive integer and must find out if it can be created by the factorial of a positive, integer number.

Details:

A factorial of a positive integer number is the number multiplied by all integers below it.

Situation 2:

You are given a million integers in the range 0 to 100. You must output them numerically sorted, least to greatest.

Details: Assume the integers are coming from some input function, and you are printing your result in some output function.

Situation 3:

You are given the 2D dimensions of a box, and then the dimensions of a smaller box. Taking into account 90 degree rotations (that is, exchanging the width and height of the smaller box), what is the largest amount of smaller boxes that can fit in the area of the bigger box?

Details:

Your algorithm should waste as little space as possible. No two smaller boxes are allowed to touch. No smaller box is allowed to go out of the bounds of the bigger box.

Do any of the situations you please, I will announce winners by situation next blog.

Comments

ludamad 16 years ago

Yes I noticed that G3D.

s 16 years ago

Shocking, given a trivial code similar algorithms are developed. Who'd of thunk?

sirxemic 16 years ago

Let's introduce a new language in this blog! Pascal!

Quote:
function IsFactorial ( n: Integer ): Boolean;

var

i: Integer;

n: Integer;

begin

IsFactorial := True;

i := 2;

while (n > 1) and IsFactorial do begin

if n mod i <> 0 then

IsFactorial := False

else

n := n div i;

Inc ( i );

end;

end.