diff options
Diffstat (limited to 'challenge-120/abigail/lua/ch-1.lua')
| -rw-r--r-- | challenge-120/abigail/lua/ch-1.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-120/abigail/lua/ch-1.lua b/challenge-120/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..0d5896f59c --- /dev/null +++ b/challenge-120/abigail/lua/ch-1.lua @@ -0,0 +1,27 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +for line in io . lines () do + num = tonumber (line) + out = 0 + for i = 0, 7 do + bit = math . floor ((num - (num % (2 ^ i))) / (2 ^ i)) % 2 + if bit == 1 + then + if i % 2 == 1 + then + out = out + 2 ^ (i - 1) + else + out = out + 2 ^ (i + 1) + end + end + end + print (out) +end |
