blob: a129db19e406f3cb015d5bd3cadec85e6e6df189 (
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
|
#!/opt/local/bin/lua
--
-- See ../README.md
--
--
-- Run as: lua ch-1.lua < input-file
--
--
-- Find the binary representation of a number.
-- Note that the function return a string in reverse order;
-- this will do for our purpose as we want a palindrome anyway.
--
function dec2bin (dec)
local bin = {}
while dec > 0 do
bin [#bin + 1] = dec % 2
dec = math . floor (dec / 2)
end
return table . concat (bin)
end
for line in io . lines () do
bin = dec2bin (tonumber (line))
if bin == string . reverse (bin) then
print (1)
else
print (0)
end
end
|