Advertisement
Guest User

AOC2020Day24inGWBASIC

a guest
Dec 24th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 10 DIM A%(140,140): CI=0: SX=70: SY=70
  2. 20 PRINT "Loading data...": GOSUB 60: PRINT "Part 1:";: GOSUB 140: PRINT N
  3. 30 FOR R=1 TO 100: PRINT R;":";: GOSUB 170: PRINT "Done";: GOSUB 140: PRINT N
  4. 40 NEXT: PRINT "Part 2:";N: END
  5. 50 REM *************************
  6. 60 OPEN "I", 1, "data24.txt": WHILE NOT EOF(1): LINE INPUT #1,S$: CX=SX: CY=SY
  7. 70 FOR I = 1 TO LEN(S$): C$ = MID$(S$,I,1)
  8. 80 IF C$="e" THEN CX=CX+1: GOTO 120
  9. 90 IF C$="w" THEN CX=CX-1: GOTO 120
  10. 100 IF C$="s" THEN CY=CY+1: CX=CX-1 ELSE CY=CY-1
  11. 110 I=I+1: C$ = MID$(S$,I,1): IF C$="e" THEN CX=CX+1
  12. 120 NEXT I: A%(CX,CY) = 1 - A%(CX,CY): PRINT ".";: WEND: PRINT: RETURN
  13. 130 REM *************************
  14. 140 N=0: FOR Y=0 TO 140: FOR X=0 TO 140: IF A%(X,Y) MOD 2=1 THEN N=N+1
  15. 150 NEXT: NEXT: RETURN
  16. 160 REM *************************
  17. 170 FOR Y=1 TO 139: FOR X=1 TO 139: N = 0
  18. 180 FOR DX=-1 TO 1: FOR DY=-1 TO 1: IF DX<>DY THEN N=N+(A%(X+DX,Y+DY) MOD 2)
  19. 190 NEXT: NEXT: IF N=2 OR (N=1 AND A%(X,Y)=1) THEN A%(X,Y)=A%(X,Y)+256
  20. 200 NEXT: NEXT: FOR Y=1 TO 139: FOR X=1 TO 139: A%(X,Y)=A%(X,Y)\256: NEXT: NEXT
  21. 210 RETURN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement