diff options
| author | Abigail <abigail@abigail.be> | 2021-07-05 14:38:06 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-07-05 14:38:06 +0200 |
| commit | 78c841faea1060a3b7ea63a4316e461e490d275e (patch) | |
| tree | 92a3b40da3986775fbf1441d6424f720cbe6e3df /challenge-120/abigail/lua | |
| parent | c79281808d6b8968f5bd105536df88b345bded7d (diff) | |
| download | perlweeklychallenge-club-78c841faea1060a3b7ea63a4316e461e490d275e.tar.gz perlweeklychallenge-club-78c841faea1060a3b7ea63a4316e461e490d275e.tar.bz2 perlweeklychallenge-club-78c841faea1060a3b7ea63a4316e461e490d275e.zip | |
Solutions in 15 languages for week 120, part 1.
This is basically the same as last weeks challenge...
Diffstat (limited to 'challenge-120/abigail/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 |
