Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MiningMarsh@Dell-Laptop-Gentoo:pts/1 ~ % cat dice-new.lua
- local diced={}
- function dice(s,n,k)
- local sum,i
- if n==0 then
- if s==0 then
- return 1
- else
- return 0
- end
- end
- if typename(diced[s][n]) == "number" then
- return diced[s][n]
- end
- for I = 1,k,1 do
- sum = sum + dice(s-I,n-1,k)
- end
- diced[s][n] = sum
- return sum
- end
- print(dice(15,5,5))
- print(dice(1,1,1))
- print(dice(20,1,1))
- print(dice(5,2,6))
- print(dice(50,20,20))
- MiningMarsh@Dell-Laptop-Gentoo:pts/1 ~ % lua dice-new.lua
- lua: dice-new.lua:12: attempt to index field '?' (a nil value)
- stack traceback:
- dice-new.lua:12: in function 'dice'
- dice-new.lua:22: in main chunk
- [C]: ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement