aboutsummaryrefslogtreecommitdiff
path: root/challenge-112/abigail/lua
diff options
context:
space:
mode:
authordms061 <dms7225@psu.edu>2021-05-16 18:47:40 -0400
committerdms061 <dms7225@psu.edu>2021-05-16 18:47:40 -0400
commit0602d0d635835efc141bf1a89f604cd3156ecd3e (patch)
treea3cf4fbbe6f6378b1e7f0180ab722010493d6c7d /challenge-112/abigail/lua
parent111673b82066733c69a62c8f1030da605767aaf8 (diff)
parentfa969a62c402d6220e260e0f302c80e9b6133c90 (diff)
downloadperlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.tar.gz
perlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.tar.bz2
perlweeklychallenge-club-0602d0d635835efc141bf1a89f604cd3156ecd3e.zip
Merge branch 'manwar:master' into challenge112
Diffstat (limited to 'challenge-112/abigail/lua')
-rw-r--r--challenge-112/abigail/lua/ch-1.lua35
-rw-r--r--challenge-112/abigail/lua/ch-2.lua16
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-112/abigail/lua/ch-1.lua b/challenge-112/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..2d866dd9bf
--- /dev/null
+++ b/challenge-112/abigail/lua/ch-1.lua
@@ -0,0 +1,35 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+for line in io . lines () do
+ --
+ -- Split into parts
+ --
+ local parts = {}
+ for part in line : gmatch ("[^/]+") do
+ table . insert (parts, part)
+ end
+ --
+ -- Copy to new structure
+ --
+ local parts2 = {}
+ for index, part in ipairs (parts) do
+ if part == "." then -- Current directory -> skip
+ goto continue
+ end
+ if part == ".." then -- Parent direction -> pop from new structure
+ table . remove (parts2)
+ goto continue
+ end
+ table . insert (parts2, part) -- Else, copy
+ ::continue::
+ end
+ print ("/" .. table . concat (parts2, "/")) -- And print
+end
diff --git a/challenge-112/abigail/lua/ch-2.lua b/challenge-112/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..8932952bbd
--- /dev/null
+++ b/challenge-112/abigail/lua/ch-2.lua
@@ -0,0 +1,16 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+local SQRT5 = math . sqrt (5)
+local PHI = (1 + SQRT5) / 2
+
+for line in io . lines () do
+ print (math . floor (0.5 + PHI ^ (tonumber (line) + 1) / SQRT5))
+end