aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-04-15 20:14:04 +0200
committerAbigail <abigail@abigail.be>2021-04-15 20:14:04 +0200
commit3f31447acbe9b9a929319d1b691610dcbb2bc07b (patch)
treea768ce6be8b9cd782bd16a0e5ac0f3c3f1b4774e
parent4c178bd74d87439bd82eae6d35a1a4ad8f446c3d (diff)
downloadperlweeklychallenge-club-3f31447acbe9b9a929319d1b691610dcbb2bc07b.tar.gz
perlweeklychallenge-club-3f31447acbe9b9a929319d1b691610dcbb2bc07b.tar.bz2
perlweeklychallenge-club-3f31447acbe9b9a929319d1b691610dcbb2bc07b.zip
Ruby solution for week 108, part 2
-rw-r--r--challenge-108/abigail/ruby/ch-2.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-108/abigail/ruby/ch-2.rb b/challenge-108/abigail/ruby/ch-2.rb
new file mode 100644
index 0000000000..184a0dcc66
--- /dev/null
+++ b/challenge-108/abigail/ruby/ch-2.rb
@@ -0,0 +1,39 @@
+#!/usr/bin/ruby
+
+#
+# See ../README.md
+#
+
+#
+# Run as: ruby ch-2.rb
+#
+
+COUNT = 10
+PLAIN = 0
+COMPUTE = 1
+
+type = PLAIN
+
+if ARGV . length > 0 && ARGV[0] == "compute"
+then type = COMPUTE
+end
+
+if type == PLAIN
+then puts ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147");
+end
+
+if type == COMPUTE
+then bell = [[1]]
+ for x in 1 .. COUNT - 2
+ bell [x] = [bell [x - 1] [x - 1]]
+ for y in 1 .. x
+ bell [x] [y] = bell [x] [y - 1] + bell [x - 1] [y - 1]
+ end
+ end
+ print (1)
+ for x in 0 .. COUNT - 2
+ print (", ")
+ print (bell [x] [x])
+ end
+ puts ("")
+end