You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6 KiB
QBasic

2 years ago
REM Advent of Code 2022: Day 5, part 2
REM Written in Applesoft BASIC
10 DIM ST$(9)
20 FOR I = 0 TO 8:ST$(I) = "": NEXT I
30 HOME
40 ONERR GOTO 900
2 years ago
60 PRINT CHR$ (4),"OPEN INPUT"
70 PRINT CHR$ (4),"READ INPUT"
90 J = 1
91 K = 0
92 L = 0
93 DIM AC(3):AC(0) = 0:AC(1) = 0:AC(2) = 0
94 V = 0
100 GET C$: GET D$
110 CV = ASC (C$)
120 IF CV > 47 AND CV < 58 GOTO 300
130 IF J > 0 THEN J = J - 1: GOTO 100
140 IF CV < > 32 THEN ST$(K) = C$ + ST$(K)
150 J = 3
160 K = K + 1
170 IF K > 8 THEN K = 0
180 GOTO 100
300 FOR I = 0 TO 8
310 GOSUB 700
2 years ago
320 NEXT I
330 CL = 0
340 GET C$: GET Z$
350 IF CL = 13 AND ASC (C$) = 13 GOTO 400
360 CL = ASC (C$)
370 GOTO 340
400 GET C$: GET Z$
410 CV = ASC (C$)
420 IF CV < 48 OR CV > 57 GOTO 400
430 V = V * 10 + CV - 48
440 GET C$: GET Z$
445 CV = ASC (C$)
450 IF CV > 47 AND CV < 58 GOTO 430
460 AC(L) = V
465 V = 0
470 L = L + 1
480 IF L < 3 GOTO 400
490 AC(1) = AC(1) - 1
495 AC(2) = AC(2) - 1
500 Z$ = RIGHT$ (ST$(AC(1)),AC(0))
510 ST$(AC(2)) = ST$(AC(2)) + Z$
520 Z = LEN (ST$(AC(1)))
530 IF AC(0) = Z THEN ST$(AC(1)) = "": GOTO 600
540 ST$(AC(1)) = LEFT$ (ST$(AC(1)),Z - AC(0))
600 I = AC(1): GOSUB 700
610 I = AC(2): GOSUB 700
2 years ago
630 L = 0
640 GOTO 400
700 X = I * 4 + 1
705 Y = 25
706 LE = LEN (ST$(I))
708 IF LE = 0 GOTO 780
710 FOR Z = 1 TO 24 - LE
712 VTAB Z
714 HTAB X
716 PRINT " ";
718 NEXT Z
720 FOR Z = 1 TO LE
730 VTAB Y - 1
735 HTAB X
740 PRINT "["; MID$ (ST$(I),Z,1);"]";
750 Y = Y - 1
760 IF Y = 1 THEN RETURN
770 NEXT Z
780 RETURN
2 years ago
900 PRINT CHR$ (4),"CLOSE"
910 END