--- title: "Treasure Chests of NIM" id: 80623 type: "computer_media" slug: "treasure-chests-of-nim" url: "http://localhost/computer_media/treasure-chests-of-nim/" markdown_url: "http://localhost/computer_media/treasure-chests-of-nim.md" published_at: "2026-11-26T10:48:19+00:00" modified_at: "2026-11-26T10:48:19+00:00" featured_image: url: "http://localhost/wp-content/uploads/2026/11/treasure-chest-of-nim-1.png" excerpt: "Take the last treasure chest before the computer does: NIM for the TS1000." post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" model: - name: "Sinclair ZX81" slug: "zx81" taxonomy: "model" url: "http://localhost/model/zx81/" - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" indiv: - name: "Mark Charlton" slug: "mark-charlton" taxonomy: "indiv" url: "http://localhost/indiv/mark-charlton/" genre: - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_type: "Program" programmers: - name: "Mark Charlton" slug: "mark-charlton" taxonomy: "indiv" url: "http://localhost/indiv/mark-charlton/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Treasure%20Chests%20of%20NIM%20%281984%29%28Charlton%2C%20Mark%29%28TS1000%29%28Program%29.zip" mediadate: "1984" images: - url: "http://localhost/wp-content/uploads/2026/11/treasure-chest-of-nim-1.png" - url: "http://localhost/wp-content/uploads/2026/11/treasure-chest-of-nim-2.png" - url: "http://localhost/wp-content/uploads/2026/11/treasure-chest-of-nim-3.png" - url: "http://localhost/wp-content/uploads/2026/11/treasure-chest-of-nim-4.png" - url: "http://localhost/wp-content/uploads/2026/11/treasure-chest-of-nim-5.png" article_media: - id: 42549 title: "The Treasure Chest of NIM" type: "article" url: "http://localhost/article/the-treasure-chest-of-nim/" media_type_tags: "Game" license: false --- # Treasure Chests of NIM NIM with a row of treasure chests for the ZX81 or TS1000. The game starts with 10 to 24 chests and a random first player; you and the computer take turns removing 1, 2 or 3 chests (keys 1, 2 or 3), and whoever takes the last chest wins. The computer plays the winning strategy, leaving a multiple of four whenever it can. From the book Games for Your T-S 1000 by Mark Charlton (Dell). Dick Wagner typed it in for The Plotter and explained the one change the TS2068 needs: count the keys from CODE 48 instead of 28 in line 60. The listing and this download are the TS1000 version; it needs 2K. Two corrections were needed for it to run. Line 105 was printed as GOSUB with no line number; it is GOSUB 240, the chest-removing subroutine that line 165 also calls. And when the computer moved first with a multiple of four chests, the program stopped with error 2 at line 150 because R had no value; a new line 25 LET R=1 gives it one. Both are readings of the author’s intent, not printed anywhere. Published in The Plotter November 1984 ([The Treasure Chest of NIM](https://timexsinclair.com/article/the-treasure-chest-of-nim/)). ## Source Code ``` 10 RAND 15 LET P=INT (RND*15)+10 20 PRINT AT 0,0;"$▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒"( TO P); AT 5,5;P;" CCHESTS" 25 LET R=1 30 IF RND <.5 THEN GOTO 120 40 PRINT AT 8,0;" " 50 PRINT AT 12,0;"HOW MANY CHESTS WILL YOU REMOVE?" 60 LET R=CODE INKEY$-28 70 IF R<1 OR R>3 THEN GOTO 60 80 PRINT AT 12,0;" ";AT 9,0;" " 90 LET P=P-R 100 PRINT AT 5,5;P;" CHEST";"S" AND P<>1;" LEFT ";AT 8,0;"YOU REMOVED ";R; 105 GOSUB 240 110 IF P<1 THEN GOTO 220 120 LET N=INT (P/4)*4 130 IF P <>N THEN LET R=P-N 150 LET P=P-R 160 PRINT AT 9,0;"I REMOVED ";R 165 GOSUB 240 170 PRINT AT 5,5;P;" CHEST";"S" AND P<>1;" LEFT " 180 IF P<1 THEN GOTO 200 190 GOTO 40 200 PRINT AT 0,0;"$$$ I WIN $$$ " 210 STOP 220 PRINT AT 0,0;"$$$ YOU WIN $ $$" 230 STOP 240 FOR A=1 TO 10 250 PRINT AT 0,P;"▒▒▒"( TO R);AT 0,P;" "( TO R) 260 NEXT A 270 RETURN 300 SAVE "NIM" 310 RUN ```