Skip to content

Commit

Permalink
1st commit on 118_lua
Browse files Browse the repository at this point in the history
  • Loading branch information
stuart-little committed Jul 8, 2021
1 parent 16d0a5b commit 2f9fad0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions challenge-118/stuart-little/lua/ch-1.lua
@@ -0,0 +1,11 @@
#!/usr/bin/env lua

-- run <script> <number>

inpt = tonumber(arg[1])
rev = 0
while inpt > 0 do
rev = (rev << 1) + (inpt & 1)
inpt = inpt >> 1
end
print(tostring(rev) == arg[1] and 1 or 0)
22 changes: 22 additions & 0 deletions challenge-118/stuart-little/lua/ch-2.lua
@@ -0,0 +1,22 @@
#!/usr/bin/env lua

--[[
run <script> <space-separated treasure spots, encoded as letter-digit>
e.g. <script> a2 b1 b2 b3 c4 e6
--]]
tour={"a8", "c7", "e6", "g5", "h3", "g1", "e2", "c1", "a2", "b4", "d3", "f2", "h1", "g3", "f1", "d2", "b1", "a3", "c2", "e1", "f3", "h2", "g4", "e3", "g2", "f4", "d5", "c3", "d1", "b2", "a4", "b6", "c4", "e5", "d7", "f8", "h7", "f6", "h5", "g7", "e8", "d6", "e4", "c5", "a6", "b8", "c6", "d4", "b5", "a7", "c8", "e7", "g8", "h6", "f5", "h4", "g6", "h8", "f7", "d8", "b7", "a5", "b3", "a1"}
spots={}
for _,spot in ipairs(arg) do
spots[spot:lower()]=1
end
for _,pos in ipairs(tour) do
if not next(spots) then
os.exit()
end
if spots[pos] then
spots[pos]=nil
end
print(pos)
end

0 comments on commit 2f9fad0

Please sign in to comment.