Advertisement
Guest User

Nope.avi

a guest
Oct 13th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. MiningMarsh@Dell-Laptop-Gentoo:pts/1 ~ % cat dice-new.lua
  2. local diced={}
  3.  
  4. function dice(s,n,k)
  5.         local sum,i
  6.         if n==0 then
  7.                 if s==0 then
  8.                         return 1
  9.                 else
  10.                         return 0
  11.                 end
  12.         end
  13.         if typename(diced[s][n]) == "number" then
  14.                 return diced[s][n]
  15.         end
  16.         for I = 1,k,1 do
  17.                 sum = sum + dice(s-I,n-1,k)
  18.         end
  19.         diced[s][n] = sum
  20.         return sum
  21. end
  22.  
  23. print(dice(15,5,5))
  24. print(dice(1,1,1))
  25. print(dice(20,1,1))
  26. print(dice(5,2,6))
  27. print(dice(50,20,20))
  28. MiningMarsh@Dell-Laptop-Gentoo:pts/1 ~ % lua dice-new.lua
  29. lua: dice-new.lua:12: attempt to index field '?' (a nil value)
  30. stack traceback:
  31.         dice-new.lua:12: in function 'dice'
  32.         dice-new.lua:22: in main chunk
  33.         [C]: ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement