aboutsummaryrefslogtreecommitdiff
path: root/challenge-112/abigail/lua/ch-1.lua
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-05-17 16:50:52 +0800
committer冯昶 <seaker@qq.com>2021-05-17 16:50:52 +0800
commit52b089976d2ad69babbca7efe0e290da1883c919 (patch)
tree0008e0f7693348515fe816f9840a3920df830647 /challenge-112/abigail/lua/ch-1.lua
parent39771602bbd0b42d1b5c1bb50049b84536243683 (diff)
parentc3cd45087006d3f63b05219b8280a25dc1ea7ba9 (diff)
downloadperlweeklychallenge-club-52b089976d2ad69babbca7efe0e290da1883c919.tar.gz
perlweeklychallenge-club-52b089976d2ad69babbca7efe0e290da1883c919.tar.bz2
perlweeklychallenge-club-52b089976d2ad69babbca7efe0e290da1883c919.zip
Merge remote-tracking branch 'upstream/master'
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