aboutsummaryrefslogtreecommitdiff
path: root/challenge-112/abigail/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-112/abigail/ruby')
-rw-r--r--challenge-112/abigail/ruby/ch-1.rb27
-rw-r--r--challenge-112/abigail/ruby/ch-2.rb17
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-112/abigail/ruby/ch-1.rb b/challenge-112/abigail/ruby/ch-1.rb
new file mode 100644
index 0000000000..e26463cb68
--- /dev/null
+++ b/challenge-112/abigail/ruby/ch-1.rb
@@ -0,0 +1,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
diff --git a/challenge-112/abigail/ruby/ch-2.rb b/challenge-112/abigail/ruby/ch-2.rb
new file mode 100644
index 0000000000..003d99288f
--- /dev/null
+++ b/challenge-112/abigail/ruby/ch-2.rb
@@ -0,0 +1,17 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-2.rb < input-file
+#
+
+SQRT5 = Math . sqrt 5
+PHI = (1 + SQRT5) / 2
+
+ARGF . each_line do
+ | n |
+ puts ((PHI ** (n . to_i + 1) / SQRT5) . round)
+end