aboutsummaryrefslogtreecommitdiff
path: root/challenge-085/tyler-wardhaugh/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-085/tyler-wardhaugh/lua/ch-2.lua')
-rwxr-xr-xchallenge-085/tyler-wardhaugh/lua/ch-2.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/challenge-085/tyler-wardhaugh/lua/ch-2.lua b/challenge-085/tyler-wardhaugh/lua/ch-2.lua
new file mode 100755
index 0000000000..6af287ab8d
--- /dev/null
+++ b/challenge-085/tyler-wardhaugh/lua/ch-2.lua
@@ -0,0 +1,22 @@
+#!/usr/bin/env lua
+
+local t2 = {}
+
+function t2.has_power_expr(n)
+ local endpoint = function(x) return 1 + math.floor(math.log(n, x)) end
+ for a = 2,endpoint(2) do
+ for b = 2,endpoint(a) do
+ if n == a ^ b then
+ return 1
+ end
+ end
+ end
+
+ return 0
+end
+
+function t2.run(args)
+ print(t2.has_power_expr(tonumber(args[1])))
+end
+
+return t2