blob: e26463cb68f65ee0eeae5b789098a73beba53da7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/usr/bin/ruby
#
# See ../README.md
#
#
# Run as: ruby ch-1.rb < input-file
#
ARGF . each_line do
| line |
parts = line . strip() . split (/\/+/)
parts2 = []
parts . each do
| part |
if part == "" or part == "." # Skip empty parts and current directory
next
end
if part == ".." # Remove parent directory
parts2 . pop
next
end
parts2 . push (part) # Add part
end
puts ("/" + parts2 . join("/")) # Print result
end
|