Created
November 6, 2021 17:06
-
-
Save vijfhoek/d5337a44f20bbf1a5903c958a006f3ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| identification division. | |
| program-id. aoc03part1. | |
| data division. | |
| working-storage section. | |
| 01 ws-input pic x(10000). | |
| 01 ws-char pic x. | |
| 01 ws-i pic 9(10) value 1. | |
| *Initialize 3-digit numerics for the x and y coordinates | |
| 01 ws-x pic 9(3) value 100. | |
| 01 ws-y pic 9(3) value 100. | |
| 01 ws-santa-x pic 9(3) value 100. | |
| 01 ws-santa-y pic 9(3) value 100. | |
| 01 ws-robo-x pic 9(3) value 100. | |
| 01 ws-robo-y pic 9(3) value 100. | |
| *200 by 200 1-digit table (array) for storing house encounters | |
| 01. | |
| 05 occurs 200 times. | |
| 10 occurs 200 times. | |
| 15 ws-houses pic 9 value 0. | |
| 01 ws-count pic 9(10) value 1. | |
| procedure division. | |
| main-para. | |
| move 1 to ws-houses(100, 100). | |
| accept ws-input. | |
| perform loop-para with test after until ws-char = ' '. | |
| display ws-count. | |
| stop run. | |
| santa-para. | |
| if ws-char = 'v' | |
| add 1 to ws-santa-y. | |
| if ws-char = '^' | |
| subtract 1 from ws-santa-y. | |
| if ws-char = '>' | |
| add 1 to ws-santa-x. | |
| if ws-char = '<' | |
| subtract 1 from ws-santa-x. | |
| robo-para. | |
| if ws-char = 'v' | |
| add 1 to ws-robo-y. | |
| if ws-char = '^' | |
| subtract 1 from ws-robo-y. | |
| if ws-char = '>' | |
| add 1 to ws-robo-x. | |
| if ws-char = '<' | |
| subtract 1 from ws-robo-x. | |
| loop-para. | |
| move ws-input(ws-i:ws-i) to ws-char. | |
| if function mod(ws-i, 2) = 1 then | |
| perform santa-para | |
| move ws-santa-x to ws-x | |
| move ws-santa-y to ws-y | |
| else | |
| perform robo-para | |
| move ws-robo-x to ws-x | |
| move ws-robo-y to ws-y | |
| end-if. | |
| if ws-houses(ws-x, ws-y) = 0 then | |
| add 1 to ws-count | |
| move 1 to ws-houses(ws-x, ws-y) | |
| end-if. | |
| add 1 to ws-i. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment