aboutsummaryrefslogtreecommitdiffstats
path: root/day10/both.bas
blob: d3de1414fe7de462e9c853d9796202a0d4779cd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
REM Advent of Code 2022: Day 10, both parts
REM Written in Applesoft BASIC

 10  GR 
 20 CX = 0
 22 CY = 14
 24 AD = 0
 26 X = 1
 28 CC = 1
 38 ST = 0
 40 D = 0
 42 SC = 1
 44 SM = 20
 50  PRINT  CHR$ (4),"OPEN INPUT"
 60  PRINT  CHR$ (4),"READ INPUT"
 70  ONERR  GOTO 1000

REM Read the next input line into S$.

 100 S$ = ""
 110  GET C$
 120  IF C$ < " " GOTO 200
 130 S$ = S$ + C$
 140  GOTO 110

REM Parse into instruction letter ("a" or "n") and addx parameter N.

 200 L =  LEN (S$)
 205  IF L = 0 GOTO 1000
 208  PRINT "> ";S$
 210 II$ =  LEFT$ (S$,1)
 220  IF L < 6 THEN N = 0
 230  IF L > 5 THEN N =  VAL ( RIGHT$ (S$,L - 5))
 240 D = 0
 250 AD = 0

REM Update the "CRT" based on X-position and X-register.

 300  COLOR= 0
 310  IF  ABS (X - CX) < 2 THEN  COLOR= CX / 5 + 1
 320  PLOT CX,CY
 330 CX = CX + 1
 340  IF CX > 39 THEN CX = 0:CY = CY + 1

REM Run the next cycle. AD != 0 on 2nd cycle of addx.

 400 CC = CC + 1
 410  IF AD = 0 GOTO 450
 420 X = X + AD
 430 AD = 0
 440 D = 1
 445  GOTO 500
 450  IF II$ = "a" THEN AD = N
 460  IF II$ = "n" THEN D = 1

REM Update strength counter, and strength total if necessary.
REM Otherwise, GOTO 100 for next instruction or 300 for next addx cycle.

 500 SC = SC + 1
 510  IF SC < SM GOTO 530
 515 SM = SM + 40
 520 ST = ST + CC * X
 530  IF D = 1 GOTO 100
 550  GOTO 300

REM End of input: print strength and exit.

 1000  PRINT "STRENGTH: ";ST
 1010  PRINT  CHR$ (4),"CLOSE"
 1020  END