aboutsummaryrefslogtreecommitdiff
path: root/challenge-112/abigail/lua/ch-1.lua
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-12 09:31:36 +0100
committerGitHub <noreply@github.com>2021-05-12 09:31:36 +0100
commitf9cc77c8dcd87a9b530814b96b41c9c187d8214b (patch)
tree26322ea6c4bf7f962529510bd82f31e27bc02f59 /challenge-112/abigail/lua/ch-1.lua
parent56dff1e5a018f8d2ca229494d30d56294c677a40 (diff)
parent7545df1494144c724111ae198f7ba8caae9e3e03 (diff)
downloadperlweeklychallenge-club-f9cc77c8dcd87a9b530814b96b41c9c187d8214b.tar.gz
perlweeklychallenge-club-f9cc77c8dcd87a9b530814b96b41c9c187d8214b.tar.bz2
perlweeklychallenge-club-f9cc77c8dcd87a9b530814b96b41c9c187d8214b.zip
Merge pull request #4067 from Abigail/abigail/week-112
Abigail/week 112
Diffstat (limited to 'challenge-112/abigail/lua/ch-1.lua')
-rw-r--r--challenge-112/abigail/lua/ch-1.lua35
1 files changed, 35 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