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.
I respond with a resounding "What?". Man do I feel stupid. Oh well I lost that one…and the game.
What do you mean "taking into account 90 degree rotations"?
Added clarification about the rotation
fn=1
fns=1fint=36limit=100fail=0while!(fint=fn)and(fail=0){fns++fn*=fnsif(fns=limit)or(fint<fn){fail=1}}That is for the first one. :pEDIT: yeah after going to do something else I came back and realized that :p if you don't care about limits and the integer is a reasonable number then you can get rid of the limit stuff and leave it asfn=1 //reset factorial numberfns=1 //reset factorial number sequencefint=8139 //random positive integer number (round(random(9000)))fail=0 //reset failwhile!(fint=fn)and(fail=0){ //checks if hasn't failed and whether factorial number matches the random integer numberfns++ //goes to next factorial number sequence (adds 1)fn*=fns //multiplies by next factorial number sequenceif(fint<fn){fail=1} //checks if factorial number has already passed random positive integer number}here is a clean versionfn=1 fns=1 fint=(positive integer) fail=0 while!(fint=fn)and(fail=0){ fns++ fn*=fnsif(fint<fn){fail=1}}Meow: Your thing could run forever :P
Yeah, your code is a bit hard to follow but I can at least see you understand the proper solution.
for the second one assuming you can store that many variables.
mydsl=ds_list_create()repeat(1000000){ds_list_add(mydsl,inputfunction)}ds_list_sort(mydsl,1)seq=0repeat(1000000){draw_text(0,seq*16,ds_list_find_value(mydsl,seq))seq++}maybe input function is something like round(random(100))here is the meaningmydsl=ds_list_create() //creates ds_list for storing list of numbersrepeat(1000000){ //repeats for 1million variablesds_list_add(mydsl,inputfunction)} //adds a variable to the list using the inputfunction as the numberds_list_sort(mydsl,1) //sorts the list in ascending orderseq=0 //sets list sequence numberrepeat(1000000){ //repeats million times for million numbersdraw_text(0,seq*16,ds_list_find_value(mydsl,seq))//draws numbers 16 pixels from each of their origions with the variable recieved for the sequence.seq++ //adds one to sequence}clean versionmydsl=ds_list_create()repeat(1000000){ds_list_add(mydsl,round(random(100)))}ds_list_sort(mydsl,1) seq=0repeat(1000000){draw_text(0,seq*16,ds_list_find_value(mydsl,seq)) seq++}EDIT: going to bed and haven't tried number 3 yet :pFor the record, ds_list_sort has really bad performance for 1 million items. Sk8 has given me a better answer for #2. Number 3 very well may be NP (google it).
can I see sk8's answer later *zzzz*
My version of #1: