aboutsummaryrefslogtreecommitdiff
path: root/challenge-207/roger-bell-west/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-207/roger-bell-west/lua/ch-2.lua')
-rwxr-xr-xchallenge-207/roger-bell-west/lua/ch-2.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-207/roger-bell-west/lua/ch-2.lua b/challenge-207/roger-bell-west/lua/ch-2.lua
new file mode 100755
index 0000000000..75e9bc7e26
--- /dev/null
+++ b/challenge-207/roger-bell-west/lua/ch-2.lua
@@ -0,0 +1,30 @@
+#! /usr/bin/lua
+
+function h_index(c0)
+ local c = c0
+ table.sort(c, function(a, b) return b < a end)
+ local h = 0
+ for i, x in ipairs(c) do
+ if i <= x then
+ h = i
+ else
+ break
+ end
+ end
+ return h
+end
+
+if h_index({10, 8, 5, 4, 3}) == 4 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+io.write(" ")
+
+if h_index({25, 8, 5, 3, 3}) == 3 then
+ io.write("Pass")
+else
+ io.write("FAIL")
+end
+print("")
+