HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Quicksilver #3: Multiples (more time)

10-29-2006, 07:19 PM#1
Vexorian
Rules
  • One week to solve.
  • Submit solutions to the pastebin, make sure to have a [quicksilver] prefix.
  • I will test each submission against a big set of test cases.
  • 3 fastest solutions (those which take the least time) win. (It is not a solution if it doesn't show the correct result for any test case)
    • 1st place: 20 rep
    • 2nd place: 15 rep
    • 3rd place: 10 rep
  • If you use global variables in your submission include them in a globals block.
  • Your submission should not get into the op limit in any case, in order to override the limit, you cannot use TriggerSleepAction nor PolledWait, you have to use ExecuteFunc/TriggerExecute. It CAN get into the op limit if you call the function twice, but an instance of the function should never get into the limit.

#3 - Multiples
You simply need to make a function:

function TotalMultiples takes string digits, integer d returns integer

digits: an string with 1 to 7 characters : "0" , "1", "2", "3", "4", "5", "6", "7", "8", "9" (only digits)
d: an integer number ( 1<=d<=50 )

You just have to return the number of possible permutations of digits that are multiples of d.


TotalMultiples("12345", 1) : 120
TotalMultiples("000" , 5) : 1
TotalMultiples("1234511",1) : 840
TotalMultiples("234", 6) : 4

TotalMultiples("1234321", 50) : 0
TotalMultiples("1234501", 50) : 60
TotalMultiples("4949" , 49 ) : 1
10-30-2006, 03:28 PM#2
Vexorian
fixed bugs and added some big testcases
10-30-2006, 11:00 PM#3
iNfraNe
How do you keep coming up with these problems :)
10-31-2006, 12:48 AM#4
SeasonsOfLove
"TotalMultiples("4949" , 49 ) : 1" Is wrong. 49 and 4949 are both divisible by 49. That's 2 that it's divisible by already.
10-31-2006, 01:54 AM#5
Vexorian
but you can't form 49, it must have all the digits , that's what a permutation is
10-31-2006, 01:57 AM#6
SeasonsOfLove
Oh, oops. You're right. =P
10-31-2006, 08:04 AM#7
Jazradel
My god, I actually understand what your talking about her. Should have an entry fairly quickly.
10-31-2006, 10:09 AM#8
Anitarf
Considering the maximum number of permutations is fairly low, I'm wondering if designing an efficient brute force algorithm isn't the best way to go here.
10-31-2006, 11:08 AM#9
MaD[Lion]
this is actually very simple, but require a bit big loop. Unless one can find a formula for it :P
10-31-2006, 11:36 AM#10
AceHart
Hm... my guess would be that Vexorian is getting tired of having to deal with more than two submissions...

Well, there's still some time left.
And, I don't think the deadline will be shortened this time
10-31-2006, 12:41 PM#11
iNfraNe
Quote:
Originally Posted by MaD[Lion]
this is actually very simple, but require a bit big loop. Unless one can find a formula for it :P
That is ofcourse the problem once again.
10-31-2006, 03:46 PM#12
Captain Griffen
Quote:
Originally Posted by Anitarf
Considering the maximum number of permutations is fairly low, I'm wondering if designing an efficient brute force algorithm isn't the best way to go here.

Millions of possible inputs.
10-31-2006, 03:52 PM#13
blu_da_noob
What? Number of inputs is irrelevant. That maximum number of permutations of a 7 digit string is 7!, or 5040 (I think, that's by mental arithematic).
10-31-2006, 04:29 PM#14
Captain Griffen
Yes, and you can have over a million inputs of strings.
10-31-2006, 04:33 PM#15
blu_da_noob
That's totally irrelevant? For any given input you have a maximum of 5040 numbers to check. How many different inputs you can receive has nothing to do with the speed of the algorithm.