aboutsummaryrefslogtreecommitdiff
path: root/challenge-104/abigail/lua
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-03-16 19:08:19 +0100
committerAbigail <abigail@abigail.be>2021-03-16 19:08:19 +0100
commitbe0d6759e0fad80c6f151604b9c88f7b58a26146 (patch)
tree1bc7768dbcca7eeaa045e4f20433fd09ed083ba4 /challenge-104/abigail/lua
parent3ac90c70798226e6fe697dfc481adc361c63c190 (diff)
downloadperlweeklychallenge-club-be0d6759e0fad80c6f151604b9c88f7b58a26146.tar.gz
perlweeklychallenge-club-be0d6759e0fad80c6f151604b9c88f7b58a26146.tar.bz2
perlweeklychallenge-club-be0d6759e0fad80c6f151604b9c88f7b58a26146.zip
Lua solution for week 104, part 2
Diffstat (limited to 'challenge-104/abigail/lua')
-rw-r--r--challenge-104/abigail/lua/ch-2.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-104/abigail/lua/ch-2.lua b/challenge-104/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..70d1a3905d
--- /dev/null
+++ b/challenge-104/abigail/lua/ch-2.lua
@@ -0,0 +1,35 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua
+--
+
+local tokens = 12
+local max_take = 3
+
+while tokens > 0
+do local s = ""
+ if not (tokens == 1)
+ then s = "s"
+ end
+ io . write ("How many tokens do you take? ")
+ io . write (string . format ("(%2d token%s are left) ", tokens, s))
+
+ local take = tonumber (io . read ("*l"))
+
+ if take and 1 <= take and take <= max_take
+ then local takes = max_take + 1 - take
+ local s = ""
+ if not (takes == 1)
+ then s = "s"
+ end
+ io . write (string . format ("Computer takes %d token%s\n", takes, s))
+ tokens = tokens - (max_take + 1)
+ end
+end
+
+io . write ("Computer wins\n")