Advertisement
Guest User

AOC2020Day8inGWBASIC

a guest
Dec 8th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  10 DIM oc$(1000), of%(1000), v%(1000)
  2.  20 OPEN "I", 1, "data08.txt"
  3.  30 FOR i = 0 TO 1000
  4.  40 IF EOF(1) GOTO 70
  5.  50 oc$(i) = INPUT$(3, # 1): INPUT #1, of%(i)
  6.  60 NEXT i
  7.  70 ic = i
  8.  80 PRINT "Part 1"
  9.  90 GOSUB 500
  10. 100 PRINT "Final value of accumulator:"; r
  11. 200 PRINT "Part 2"
  12. 210 FOR i = 0 TO ic - 1
  13. 220 IF oc$(i) = "acc" THEN GOTO 280
  14. 230 PRINT "Changing instruction"; i; "...";
  15. 240 IF oc$(i) = "nop" THEN oc$(i) = "jmp": GOSUB 500: oc$(i) = "nop"
  16. 250 IF oc$(i) = "jmp" THEN oc$(i) = "nop": GOSUB 500: oc$(i) = "jmp"
  17. 260 IF c = 1 GOTO 290
  18. 270 PRINT "Loop detected."
  19. 280 NEXT i
  20. 290 PRINT "Program finished!"
  21. 300 PRINT "Final accumulator value:"; r
  22. 310 END
  23. 500 FOR j = 0 TO 1000: v%(j) = 0: NEXT j
  24. 510 ip = 0: acc = 0
  25. 520 IF v%(ip) THEN c = 0: r = acc: RETURN
  26. 530 IF ip >= ic THEN c = 1: r = acc: RETURN
  27. 540 v%(ip) = -1
  28. 550 IF oc$(ip) = "jmp" THEN ip = ip + of%(ip) - 1
  29. 560 IF oc$(ip) = "acc" THEN acc = acc + of%(ip)
  30. 570 ip = ip + 1
  31. 580 GOTO 520
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement