aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-03-17 20:08:55 +0100
committerAbigail <abigail@abigail.be>2021-03-17 20:14:49 +0100
commitde5f61d242597618622ab9d377d7fa6eca0f8c02 (patch)
tree63f4d3a1fdf32a105ae07b53c81145e5d9c64919
parentc585402ac87611b8f92cae30fbe3e8e6be6f4394 (diff)
downloadperlweeklychallenge-club-de5f61d242597618622ab9d377d7fa6eca0f8c02.tar.gz
perlweeklychallenge-club-de5f61d242597618622ab9d377d7fa6eca0f8c02.tar.bz2
perlweeklychallenge-club-de5f61d242597618622ab9d377d7fa6eca0f8c02.zip
BASIC solution for week 104, part 2
-rw-r--r--challenge-104/abigail/README.md1
-rw-r--r--challenge-104/abigail/basic/ch-2.bas54
-rw-r--r--challenge-104/abigail/t/ctest.ini3
3 files changed, 58 insertions, 0 deletions
diff --git a/challenge-104/abigail/README.md b/challenge-104/abigail/README.md
index 8e80c0dd38..e85ff0d471 100644
--- a/challenge-104/abigail/README.md
+++ b/challenge-104/abigail/README.md
@@ -92,6 +92,7 @@ After the third move, we print that the computer has won.
### Solutions
* [AWK](awk/ch-2.awk)
* [Bash](bash/ch-2.sh)
+* [BASIC](basic/ch-2.bas)
* [Befunge-93](befunge/ch-2.bf93)
* [C](c/ch-2.c)
* [Lua](lua/ch-2.lua)
diff --git a/challenge-104/abigail/basic/ch-2.bas b/challenge-104/abigail/basic/ch-2.bas
new file mode 100644
index 0000000000..5cb6804e97
--- /dev/null
+++ b/challenge-104/abigail/basic/ch-2.bas
@@ -0,0 +1,54 @@
+0100 REM
+0101 REM See ../README.md
+0102 REM
+
+0200 REM
+0201 REM Run as: basic.pl ch-2.bas
+0202 REM
+
+1000 LET tokens = 12
+1010 LET maxtake = 3
+
+1100 REM
+1101 REM Print the prompt
+1102 REM
+
+1110 PRINT "How many tokens do you take? (";
+1120 IF tokens < 10 THEN PRINT " ";
+1130 PRINT tokens;
+1140 PRINT "tokens are left) ";
+
+
+1200 REM
+1201 REM Read input and validate. Not going to work well if
+1202 REM anything non-numeric is given as input.
+1203 REM
+
+1210 INPUT ""; take
+1220 IF take < 1 THEN 1100
+1230 IF take > maxtake THEN 1100
+
+1300 REM
+1301 REM Calculate the amount of tokens the computer is
+1302 REM going to take, and print it.
+1303 REM
+
+1310 LET takes = maxtake + 1
+1315 LET takes = takes - take
+1320 PRINT "Computer takes ";
+1330 PRINT takes;
+1340 IF takes = 1 THEN PRINT "token"
+1345 IF takes > 1 THEN PRINT "tokens"
+
+1400 REM
+1401 REM Update the number of tokens, and check whether we're done.
+1402 REM
+
+1410 tokens = tokens - 4
+1420 IF tokens <> 0 THEN 1100
+
+1500 REM
+1501 REM We have won the game!
+1502 REM
+
+1510 PRINT "Computer wins"
diff --git a/challenge-104/abigail/t/ctest.ini b/challenge-104/abigail/t/ctest.ini
index 493973a0f9..941a6250ed 100644
--- a/challenge-104/abigail/t/ctest.ini
+++ b/challenge-104/abigail/t/ctest.ini
@@ -30,3 +30,6 @@
[1-1]
no_input = 1
+
+[challenges/2/basic]
+remove_pattern = [ ][?]