diff options
Diffstat (limited to 'challenge-195/deadmarshal/lua/ch-1.lua')
| -rw-r--r-- | challenge-195/deadmarshal/lua/ch-1.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-195/deadmarshal/lua/ch-1.lua b/challenge-195/deadmarshal/lua/ch-1.lua new file mode 100644 index 0000000000..e2b7dfcf00 --- /dev/null +++ b/challenge-195/deadmarshal/lua/ch-1.lua @@ -0,0 +1,26 @@ +#!/usr/bin/env lua + +local function has_dups(n) + assert(type(n) == 'number','n must be a number!') + if n > 9999999999 then return true end + local hash = {} + while n ~= 0 do + if(hash[n%10] ~= nil) then return true end + hash[n%10] = 1 + n = n // 10 + end + return false +end + +local function special_integers(n) + assert(type(n) == 'number','n must be a number!') + local count = 0 + for i=1, n do + if not has_dups(i) then count = count + 1 end + end + return count +end + +print(special_integers(15)) +print(special_integers(35)) + |
