From 5af854f4892557e1f1de653b46402cbfd7baaff9 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 10 May 2021 21:06:57 +0200 Subject: Lua solutions for week 112 --- challenge-112/abigail/lua/ch-1.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-112/abigail/lua/ch-1.lua (limited to 'challenge-112/abigail/lua/ch-1.lua') 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 -- cgit