aboutsummaryrefslogtreecommitdiff
path: root/challenge-195/deadmarshal/lua/ch-1.lua
blob: e2b7dfcf00ea1947bd677de2775af386bf732cff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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))