 # aoc-2020-10

Dec 11th, 2020 (edited)
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. 'AoC-2020, day 10
2. DIM n(100) AS LONG
3. OPEN "C:\day10.txt" FOR INPUT AS #1
4. 'OPEN "C:\test10.txt" FOR INPUT AS #1
5. nums = 0: WHILE NOT EOF(1): nums = nums + 1: INPUT #1, n(nums): WEND
6.
7. 'ynzesort the list
8. FOR i = 1 TO nums - 1
9.   FOR j = i + 1 TO nums
10.     IF n(i) > n(j) THEN temp = n(i): n(i) = n(j): n(j) = temp
11.   NEXT
12. NEXT
13. max = n(nums): nums = nums + 1: n(nums) = max + 3
14.
15. 'compute distances
16. FOR i = 1 TO nums
17.   d = n(i) - n(i - 1)
18.   IF d = 1 THEN d1 = d1 + 1
19.   IF d = 3 THEN d3 = d3 + 1
20. NEXT
21. PRINT "pt1:"; d1; " * "; d3; " = "; d1 * d3
22.
23. 'count paths to the end from each node, starting from the end node and working back
24. 'for each node the number of paths is simply the sum of paths, of each node within reach
25. DIM c(100) AS _INTEGER64
26. FOR i = nums TO 0 STEP -1
27.   IF n(i) = max + 3 THEN c(i) = 1
28.   FOR j = 1 TO 3
29.     IF i + j <= nums THEN
30.       IF n(i + j) - n(i) <= 3 THEN c(i) = c(i) + c(i + j)
31.     END IF
32.   NEXT
33. NEXT
34. PRINT "pt2:"; c(0)