From 3f31447acbe9b9a929319d1b691610dcbb2bc07b Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 15 Apr 2021 20:14:04 +0200 Subject: Ruby solution for week 108, part 2 --- challenge-108/abigail/ruby/ch-2.rb | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 challenge-108/abigail/ruby/ch-2.rb 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 -- cgit