Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'AoC-2020, day 10
- DIM n(100) AS LONG
- OPEN "C:\day10.txt" FOR INPUT AS #1
- 'OPEN "C:\test10.txt" FOR INPUT AS #1
- nums = 0: WHILE NOT EOF(1): nums = nums + 1: INPUT #1, n(nums): WEND
- 'ynzesort the list
- FOR i = 1 TO nums - 1
- FOR j = i + 1 TO nums
- IF n(i) > n(j) THEN temp = n(i): n(i) = n(j): n(j) = temp
- NEXT
- NEXT
- max = n(nums): nums = nums + 1: n(nums) = max + 3
- 'compute distances
- FOR i = 1 TO nums
- d = n(i) - n(i - 1)
- IF d = 1 THEN d1 = d1 + 1
- IF d = 3 THEN d3 = d3 + 1
- NEXT
- PRINT "pt1:"; d1; " * "; d3; " = "; d1 * d3
- 'count paths to the end from each node, starting from the end node and working back
- 'for each node the number of paths is simply the sum of paths, of each node within reach
- DIM c(100) AS _INTEGER64
- FOR i = nums TO 0 STEP -1
- IF n(i) = max + 3 THEN c(i) = 1
- FOR j = 1 TO 3
- IF i + j <= nums THEN
- IF n(i + j) - n(i) <= 3 THEN c(i) = c(i) + c(i + j)
- END IF
- NEXT
- NEXT
- PRINT "pt2:"; c(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement