Well this died, but for anyone interested here is my solution: http://bpaste.net/show/141114/
Here is my original solution: http://bpaste.net/show/141115/
------
So here is an experiment for anyone bored looking for something to do:
I post random programming challenges to be solved in lua, you post your implementation (preferably via pastebin).
I will try to wait for a few solutions before putting up a new challenge.
I shall check solutions on my machine and post the names of those who solved them correctly by order of how long their algorithm takes.
Here is problem 1:
Create a function dice(s,n,k) that returns the number of unique rolls that you can make with n number of dice, where each dice has k sides (so if k is six, that means your dice has 6 sides, starting with 1, ending at 6) where all the dice added up gives you s. The order of the dice does matter, a roll of 2 1 1 is different than a roll of 1 1 2, for example.
A few sample runs:
dice(15, 5, 5) -> 381
dice(1, 1, 1) -> 1
dice(20, 1, 1) -> 0
dice(5, 2, 6) -> 4
dice(50, 20, 20) -> 18851284297384
Heres a function (not in lua) that requires quite a fast computer:
dice(s, n, k)= dice(s, n, k)
recusion is fine right? not sure if it has any bugs though.
I figured we might as well use that one to start since I already know two fast solutions, and it happens to be a fun one to solve.
If no one wants to do it in lua I can change it to be any language, but I figured that since TPT uses lua, why not lua?
Local diced = {}
function dice(s,n,k)
local sum,i
If n=0
if s=0
Return 1
Else
Return 0
End
end
If typename(diced[s][n]) == "number"
Return diced[s][n]
End
For I = 1 to k
Sum = sum + dice(s-I,n-1,k)
End
Diced[s][n] = sum
Return sum
end
Sorry, I am not on my computer, cannot test, please correct the syntax for me, thanks.
What is my score?