aboutsummaryrefslogtreecommitdiff
path: root/challenge-108/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-108/abigail/lua/ch-2.lua')
-rw-r--r--challenge-108/abigail/lua/ch-2.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/challenge-108/abigail/lua/ch-2.lua b/challenge-108/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..37f067c465
--- /dev/null
+++ b/challenge-108/abigail/lua/ch-2.lua
@@ -0,0 +1,41 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua
+--
+
+local COUNT = 10
+local PLAIN = 0
+local COMPUTE = 1
+
+local type = PLAIN
+if #arg >= 1 and arg [1] == "compute"
+then type = COMPUTE
+end
+
+if type == PLAIN
+then print ("1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147")
+end
+
+if type == COMPUTE
+then local bell = {}
+ bell [0] = {}
+ bell [0] [0] = 1
+ for x = 1, COUNT - 2
+ do bell [x] = {}
+ bell [x] [0] = bell [x - 1] [x - 1]
+ for y = 1, x
+ do bell [x] [y] = bell [x] [y - 1] + bell [x - 1] [y - 1]
+ end
+ end
+
+ io . write (1)
+ for x = 0, COUNT - 2
+ do io . write (", " .. bell [x] [x])
+ end
+ io . write ("\n")
+end