aboutsummaryrefslogtreecommitdiff
path: root/challenge-108/abigail/ruby/ch-2.rb
blob: 184a0dcc6635b11aef5a87f1651021f7e98b7c29 (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
28
29
30
31
32
33
34
35
36
37
38
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