aboutsummaryrefslogtreecommitdiff
path: root/challenge-332/hvukman/lua/332_p1.lua
blob: 35b39a5b30746865f8ef19440481ff3ca42323cc (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
27
28
29
30
31
32
33
34
35
36
37
38
39
function Split(inputstr, sep)
  if sep == nil then
    sep = "%s"
  end
  local t = {}
  for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
    table.insert(t, str)
  end
  return t
end

function Bindate(inp)
  local newdate = Split(inp,"-")
  for k,v in ipairs(newdate) do
      
      local n = tonumber(v)
      local bin = {}
      while n>0 do
          table.insert(bin,n&1)
          n = n >> 1
      end
      
      for i=#bin, 1, -1 do
        io.write(bin[i])
      end
      
      if k~=#newdate then
        io.write("-")
      end
    

  end
  print("")
end

Bindate("2025-07-26")
Bindate("2000-02-02")
Bindate("2024-12-31")