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.
@kenon the first works out with numbers 1+ but not 0 :p but I guess you don't need zero since it's neutral.
EDIT: on #3 do you mean they can't overlap? or can't be right next to each other :p0 isn't positive :D
But 0!=1.For formality sakes.@Meow: Overlap.al gore rhythms
Okay, here's the basic factorial algorithm:
._.
Brain input failed…
Please stand by.I have a headache now… I think i would need to consult a book for these…
@Gamer3D: Yours can be very swift indeed, but modulo is slower than division :|
But the main thing is it can identify as soon as it has a term that does not go in side with it. Either way, meow's is technically faster than both.Modulo is just as fast as division for integers. Since you're using GM though, I can't promise anything
There is the question of which kind of efficiency though. Processing or memory? 2 could be done with Radix sort, but that might be a bit of memory@G3D Why are you exiting after return?