--- title: "Idaho Squares" id: 55196 type: "computer_media" slug: "idaho-squares" url: "http://localhost/computer_media/idaho-squares/" markdown_url: "http://localhost/computer_media/idaho-squares.md" published_at: "2024-06-20T11:49:56+00:00" modified_at: "2026-03-31T12:39:47+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2019/02/20230809-041332.jpg" excerpt: "Crack a cleverly constructed 3×3 number grid where every row sums to 27 — but four cells are hidden and only your arithmetic intuition can restore them." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Tim Hartnell" slug: "tim-hartnell" taxonomy: "indiv" url: "http://localhost/indiv/tim-hartnell/" genre: - name: "Game" slug: "game" taxonomy: "genre" url: "http://localhost/type/game/" media_contents: - id: 55220 title: "Long Island Sinclair Timex (LIST) User Group Library Tape #7" type: "computer_media" url: "http://localhost/computer_media/long-island-sinclair-timex-list-user-group-library-tape-7/" media_type: "Program" programmers: - name: "Tim Hartnell" slug: "tim-hartnell" taxonomy: "indiv" url: "http://localhost/indiv/tim-hartnell/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Idaho%20Squares%20%28198x%29%28TS2068%29%28US%29%28Program%29.zip" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/06/SCR-20260331-icmf.png" media_type_tags: "Game" --- # Idaho Squares “Idaho Squares” is a number puzzle game in which the player must reconstruct a 3×3 grid of integers by guessing missing values. The grid is generated using four random variables (A, B, C, D) constrained to be distinct, and each cell is an arithmetic combination of those variables such that every row sums to 27. The player sees blanked-out cells (stored as zeros in array B) and enters guesses one at a time; a correct guess for a cell fills it in permanently. The program tracks the number of guesses with variable J and reports how many cells are correctly placed after each guess using a simple match-count loop. From [Giant Book of Computer Games](https://archive.org/details/timhartnellvz200giantbookofgames/Tim_Hartnell_GiantBookOfCompterGames/page/n341/mode/2up) by [Tim Hartnell](http://localhost/indiv/tim-hartnell/). *** ## Program Analysis ### Program Structure The program is divided into two logical phases: initialization (the subroutine beginning at line `230`) and the main game loop (lines `30`–`200`). Control flow is straightforward: the subroutine sets up the puzzle once, and the main loop repeatedly accepts guesses and redraws the board until all nine cells are solved. 1. **Lines 5–10:** Screen setup and title display. 2. **Line 20:** Call initialization subroutine at `230`. 3. **Lines 30–200:** Main game loop — increment guess counter, clear screen, display grid, check for win, prompt for input, update board. 4. **Lines 230–470:** Initialization subroutine — allocate arrays, generate random parameters, compute grid values, blank out four cells, reset guess counter. 5. **Line 9997–9998:** Stop guard and SAVE statement. ### Grid Generation Four distinct random integers A, B, C, D are drawn from 1–9 (line `250`–`290`). The nine grid values in array `A()` are arithmetic combinations of these variables: | Cell | Formula | | --- | --- | | A(1) | A+B | | A(2) | A−(B+C) | | A(3) | A+C | | A(4) | A−B+C | | A(5) | A | | A(6) | A+B−C | | A(7) | A−C | | A(8) | A+B+C | | A(9) | A−B | Each row sums to 3A (row 1: cells 1–3 = (A+B)+(A−B−C)+(A+C) = 3A; similarly for rows 2 and 3), so for the “rows sum to 27” hint to hold, A must equal 9. However, A is drawn randomly from 1–9, meaning the row-sum property only holds when A happens to be 9 — this is a latent bug. The hint on line `151` (“Make all rows=27”) is therefore only correct in approximately 1 in 9 games. ### Variable Name Collision A significant bug exists in the initialization subroutine: the program uses both the scalar variable `A` and the array `A()` (declared at line `230`). In Sinclair BASIC, a scalar variable and an array of the same letter cannot coexist — declaring `DIM A(9)` while also using `LET A=...` causes the scalar and array to conflict. In practice, the `DIM A(9)` at line `230` is executed before `LET A=...` at line `250`, which will overwrite the array entry, leading to unpredictable behavior. The same collision applies to scalar `B` and array `B()`. ### Display Logic The 3×3 grid is printed in a single `FOR` loop (lines `70`–`110`). A newline is inserted after every third cell using the condition `3*INT(Z/3)=Z` at line `90`, which is true when Z is a multiple of 3 (i.e., Z=3, 6, 9). Blank cells are stored as `0` in array `B()` and printed as such, so the player sees a zero rather than a blank space for missing values. ### Guess Processing When the player enters a guess `X` at line `160`, the loop at lines `170`–`190` scans all nine cells. A cell is filled in only if it currently holds `0` (i.e., is still blank) AND the answer for that cell equals `X` (line `180`). This means a single guess can fill multiple cells simultaneously if more than one hidden cell has the same value — a useful shortcut for the player. ### Win Detection After each display pass, the match counter `M` is accumulated at line `100`. If `M=9` (line `130`), the player is congratulated, a beep is sounded via `BEEP 1,15`, and the program halts. The guess count displayed is `J-1` because `J` is incremented at line `30` before the win check, overcounting by one. ### Notable Idioms - The distinctness check at line `290` uses a chained `OR` condition to ensure all four random values are unique before proceeding. - `RANDOMIZE` at line `240` (with no argument) seeds the random number generator from the system clock, ensuring different puzzles each run. - The `SAVE "IDAHO SQUA" LINE 1` at line `9998` saves the program with an auto-start at line `1` (which does not exist, so execution starts at the first available line, effectively line `5`). ## Source Code ``` 5 PAPER 0: BORDER 0: INK 7 10 PRINT TAB 6;"IDAHO SQUARES" 20 GO SUB 230 30 LET J=J+1 40 CLS 50 PRINT : PRINT : PRINT TAB 3; 60 LET M=0 70 FOR Z=1 TO 9 80 PRINT B(Z);" "; 90 IF 3*INT (Z/3)=Z THEN PRINT : PRINT : PRINT TAB 3; 100 IF B(Z)=A(Z) THEN LET M=M+1 110 NEXT Z 120 PRINT 130 IF M=9 THEN PRINT "YOU'VE SOLVED IT": PRINT "IN JUST ";J-1;" GUESSES": BEEP 1,15: STOP 140 PRINT : PRINT "THIS IS GUESS NUMBER ";J 150 PRINT : PRINT "YOU HAVE ";M;" RIGHT": PRINT 151 PRINT : PRINT "Make all rows=27" 160 INPUT "ENTER YOUR GUESS ";X 170 FOR Z=1 TO 9 180 IF B(Z)=0 AND A(Z)=X THEN LET B(Z)=X 190 NEXT Z 200 GO TO 30 210 STOP 220 REM 230 DIM A(9): DIM B(9) 240 RANDOMIZE 250 LET A=INT (RND*9)+1 260 LET B=INT (RND*9)+1 270 LET C=INT (RND*9)+1 280 LET D=INT (RND*9)+1 290 IF A=B OR B=C OR A=C OR A=D OR B=D OR C=D THEN GO TO 260 300 LET A(1)=A+B 310 LET A(2)=A-(B+C) 320 LET A(3)=A+C 330 LET A(4)=A-B+C 340 LET A(5)=A 350 LET A(6)=A+B-C 360 LET A(7)=A-C 370 LET A(8)=A+B+C 380 LET A(9)=A-B 390 FOR Q=1 TO 9 400 LET B(Q)=A(Q) 410 NEXT Q 420 LET B(A)=0 430 LET B(B)=0 440 LET B(C)=0 450 LET B(D)=0 460 LET J=0 470 RETURN 9997 STOP 9998 SAVE "IDAHO SQUA" LINE 1 ```