-
Notifications
You must be signed in to change notification settings - Fork 0
/
09B-solution.basic
156 lines (141 loc) · 8.2 KB
/
09B-solution.basic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
REM DIM d(191,261):REM -47 to 144, -65 to 196
MODE 4
VDU 19,1,3;0;
offsetx=47:offsety=65
DIM kx(9),ky(9)
REM DIM vx(9),vy(9)
maxx=0:maxy=0
cmd$=""
REM plot starting point
GCOL 0,1:PLOT 69,offsety*4,offsetx*4
REPEAT
IF cmd$="" THEN READ cmd$
c$=LEFT$(cmd$,1)
steps=VAL(MID$(cmd$,2,2))
cmd$=RIGHT$(cmd$,LEN(cmd$)-3)
IF c$="L" THEN PROCmove(-1,0,steps)
IF c$="R" THEN PROCmove(1,0,steps)
IF c$="U" THEN PROCmove(0,1,steps)
IF c$="D" THEN PROCmove(0,-1,steps)
UNTIL c$="*"
GCOL 3,1
FOR Y%=0 TO maxy STEP 4
FOR X%=0 TO maxx STEP 4
IF POINT(X%,Y%)=1 THEN C%=C%+1
NEXT
MOVE 0,Y%:DRAW maxx,Y%
NEXT
FOR Y%=0 TO maxy STEP 4
MOVE 0,Y%:DRAW maxx,Y%
NEXT
P."Outcome: ";C%
END
DEFPROCmove(dx,dy,steps)
M%=M%+1
REM visualise
REM GCOL 3,1
REM vy(0)=(offsetx+kx(0))*4:REM reversed
REM vx(0)=(offsety+ky(0))*4:REM reversed
REM vy(9)=(offsetx+kx(9))*4:REM reversed
REM vx(9)=(offsety+ky(9))*4:REM reversed
REM MOVE vx(0),vy(0):DRAW vx(9),vy(9)
FOR S%=1 TO steps
kx(0)=kx(0)+dx:ky(0)=ky(0)+dy
FOR K%=1 TO 9
P.TAB(0,0);M%;".";S%;"/";steps;": ";STRING$(K%,".");STRING$(10-K%," ")
PROCfollow(K%)
NEXT
REM plot the tail for real
px=(offsety+ky(9))*4:py=(offsetx+kx(9))*4:REM reversed (for space)
IF px<0 OR py<0 THEN P."too low":END
IF px>1279 OR py>1023 P."too high":END
IF px>maxx THEN maxx=px
IF py>maxy THEN maxy=py
PLOT 69,px,py
NEXT
REM remove visualisation
REM MOVE vx(0),vy(0):DRAW vx(9),vy(9)
ENDPROC
DEFPROCfollow(K%)
H%=K%-1
xdiff=kx(H%)-kx(K%)
ydiff=ky(H%)-ky(K%)
REM move in the correct direction for a gap of 2 spaces
IF xdiff>1 THEN kx(K%)=kx(K%)+1
IF xdiff<-1 THEN kx(K%)=kx(K%)-1
IF ydiff>1 THEN ky(K%)=ky(K%)+1
IF ydiff<-1 THEN ky(K%)=ky(K%)-1
REM additional move to ensure we go diagonally when 2:1 away
IF (ABS(ydiff)>1) AND xdiff=1 THEN kx(K%)=kx(K%)+1
IF (ABS(ydiff)>1) AND xdiff=-1 THEN kx(K%)=kx(K%)-1
IF (ABS(xdiff)>1) AND ydiff=1 THEN ky(K%)=ky(K%)+1
IF (ABS(xdiff)>1) AND ydiff=-1 THEN ky(K%)=ky(K%)-1
ENDPROC
D. "L01R01L01U01R02U01D02R02U01D02U02L02D01U01D02L02D01L02D02L01U02R02L01D02L02R02D02L01U01R01"
D. "U01L01D01R01U02D02R01U01R01L01U01R01D01L01U01R01D01U01D01U01R02L02D02L02R01U02L02R01U01R02"
D. "D02R02L02U02R02D02R01U01L02R01U01D02U02D01R02L02D02L02R02U01R02L02D02L01D01R02L01U02R01U02"
D. "D01U02D01L01R02D02R02U02R01U02R02U01R01D02U02R02U01R02D02R01L01U03L02U01L02U01D01U02D01U02"
D. "R02L01U03R01U01R03L03D03L02U01D03U01R01L01R02L01R03L03D01R02L03U03D01L02U02D02L02U01R01L02"
D. "R03L03D03R02D03U01L03R01U02L01D03L01U01D03L03U02D01U02L03R01U02D02R03D03U02D03L03R03L01U03"
D. "L01D01L02D02R01L03R02L03R03L01D01U03L02R02L02D03U03L03U03D01U02R02U01D03L03R01L03U03D01L03"
D. "D02R01U01R01D02L02U01L02R02L02D03U03D04L03D04R03L02U03R03U01R04U02D01R03L01R01D03R02D01R02"
D. "L02U02D01R01U02R03L02D01U03R02D04L03U01R01D02U01R03L04D02L01U03L02U03R01D01L02R04D04U01R03"
D. "U03R01U03L02U03L02D04U01R01L02R02D02L02D02U04D04L02U02D03L04U04D04R01D04R01D01L01R01L01D02"
D. "L04D02R03L01D02U03L02U03R04D04U01L01U04L04U03D02R03L01D03U03R01L03U01D01R01U03R02L01D01L03"
D. "U01D01L02R03U04L05D05R05D03U03D01L05R02U01L02D01L01D04R01U01L01U01D03L04D01U05L01R05L02R04"
D. "D05U02D03U04L01R02U04L04D03R01U01R03D03U05L03D03U05R04L01D04U01L01R04D05L05D03R05U03R02D02"
D. "U02D05R05D05R02D05U02D02R01L05D02U02R05U01D05U05L02D05L01R04U04D01L05U04L01R03L03R03L03D03"
D. "R04U05L02D03U02L01R05U01L03U04L04D04R01D04R05D05U05R05L03D03U02R05U05R02D05R01U02D05L03R05"
D. "U05R04D06L04U04L06R02L04U05L01U06D04R03U02R01D05L04U02R06U01L02D06U01R02L03R02L05U01R03D03"
D. "L04R05U01D03R06D05R04D03U02D04R05U04R02L02U05D05U06D04U05L05R01D03R03L03D03L03U06R05D06U05"
D. "L01R04L01U04L05D05U04D03R03L04R04U06L05D02U03R04U05L05D06R05D05L03U06L03U05D02U04R04U03D01"
D. "R02L06R02L03U05L01R04D02U05D02R04U06R06L06U06L04R05D03U01D06L01D03L04D06U03D02L02U05D02U05"
D. "D06R04D01U01D05U01L07U03R03U05D02R07D06L07R06L03R03U01L04D04L06R01U04L03R03D03L02D07U07D07"
D. "R02L06D02R06D06U05L04U03D06U03D01L07U07L04R03D06U02L06D03U07D02R07D04L04R04U02D03U02L04R04"
D. "L04D06R04U01R07D07U07R06D04U02D04L05U04D06R04U02R01U04D05R01D07R04U01D04U06L06R01D01R01D06"
D. "R06D03U01D05R04L01D06R06L08U01D07R04L02R06U07L02D05R06D03L04R05U07L03U08L01U06L08R07D02U03"
D. "R04L08D04L01U01D07U08R07D02L05U06D07R04L01R03U01R02U01D07R06U07D06L02D08U04R08L05D06L07U07"
D. "R08L05D05R04L05U08D04U06D02U05R07L08U07R03L08R06D04R02D06R05D02U06L04U08R03U01L06R01L03R01"
D. "U03L08D05U06L08D06R02U06R04L08D01R06D08U06D06L03U04D02L02D07L05U03R08D06R05L08U05L09R07D05"
D. "R02U05L03D09R04U01L03R05L07R08D01U04L04R03U08L08D08U09R06U03R02U08D09R03L02U09R09L08D02R01"
D. "L08U07R03L01R09L04R02U03D08R05U09L09R01D05R05U04L09R06D05L02R06U01D05L03R01U05R04D04U08D02"
D. "U06R06U05R03U05R05L08D09L07R01U07R05U06R08U02R02U08R07D03R06L08R04L08R08U08R03L03U01L09D09"
D. "R09U04R01L03D04U05R07D06L09U07L04R08U08D04L05D09U02D09R04D08R08D08U09L06R06L02U09L04U10L01"
D. "R10D03U06R05D03R04L04U07D09R02D10U09L07D04R02L10D05R05U09R04L07R05D03R06D08R06D10R07U04D05"
D. "U06L03D03U10R10U10D09R06D02R09D08R07U10R04U06R07U02R05U06L04U08L06D08R02U02L04U04R05U10D08"
D. "U07R05D03L02R09U10L01U05L01D03L09R09U02D03U08R10L02U09D04U04D10L04D03R03L02U08L04D06R02L03"
D. "D06L04D05L07U09L03D04R06L10U05L03R03D06U01L03R05D08R11U02L11R07U08R04D04U06D04U09D05R09D09"
D. "U06D01U03L04U03D11U11R04L03U05D01R04U06D04U03D08L07R08L09R03D04U06L02U06R03D08R01L05U08D03"
D. "R08L08U03R02U11L09U04D10L07D01U02D07R04L02U08L05U05D01L11R04L07U02D09L04U11R08L01D10U05R04"
D. "L08U08D11U08D03R04U08R02U03R09D04L02D04L04U04R05U04L10U04L04R08D05L02U05D09U10D06R09D04R10"
D. "U04D12R07L12R08L11U01D04L01D07R01L05R09L03D07L02R06U02D02U09L04U11D04R07D07L11U11L01D09U06"
D. "R03D03L09R07L06D06R11D10U11R01U02R09L06U07D05U07R04U12R02D01L07R05D06R01D11R09L06U11D07L07"
D. "R09L07D12U07D12R03L02R10D01L09R03D06R11U02L02U03R03L06U03R01L05R07U02D08L09U07L09D12U03D09"
D. "U01L10D09L11U06R09U10L05R11U03R09D12U01D11R12U01D07L01U07L05U08L02R06U13R03D08U02L05U07L07"
D. "U13L03R05D01L09U02L07R09U12R09L13R01U11R04U06D06R13D13U05L09U02D09R12D13U09D10U11R11U12D05"
D. "L01R02U02D05U01D08R08L01U09L11D10R01D06U05D11L13D02R01L01R07L01U02D06U04L07U08D07L11U05D05"
D. "R01D06R01U09L11D06U10D10R02U13L05U09L13U07L03D09L13R05L05U05L13U10L01R10L08R13U13R07D06R04"
D. "L05U03D06R13U09L10U13R03D08L08U05L09U04D11L14U11R01D07U04R11U03R02U11L06R02D05L01U01L11R05"
D. "U10D12R03L06R03D09L04D11L11D04R10D03L12D08U07R02D01L05U11L09R04U04D11R09D03U06L04U04L08U06"
D. "L14R13D05R05U05R02U08L12R02U12D04R03L05D11R07U09D10L01D04U04D01R09L10R11L08D10R10L03R01L09"
D. "D04L08R07U12R05L10R07U06R07U08D01U01L01R02D14U04D05R02D01R05D06R03L12U11D01L07R10U02R06U11"
D. "R12U02R04L01D07U02D09U12D11U02L04R10U13R02L08R13L11R13L13R05D02U10D14L08U11R01L15U13L04D09"
D. "L01U14R10D02R15L12R15U15L03U01L01R09D11L09D03U12R01D07L08R10D02L04D02U12D12L15U03D13U13D03"
D. "R04L07D06U07D07R02D02R10L12U14D01U05L08R01U05D08U01D15U13L15R01L10U14D15R10L13D08L07U11R07"
D. "U10D15L01U05L02R06L04U15R13U04R07U04R10L03U10R10D13R11L12D12U07R08D14L04R04L08D06R08L05U06"
D. "L07U14D14R14L09D05U14R16L04R14U03D10L05R09D04R14L16D13L04R13D05R05U01R06L15D16R15D11R11D06"
D. "U07L10D07U12R06L02U07L08U14L05U06L10R16L13D13U07R09L08U03D06R02L04R15D12U07D04U02L10D04L11"
D. "D12R05L13U16L12R03L16R14L08R07U07L07D12R02D05R14U09D15U02L10D01U13L02R13D05U01D02L07D14U12"
D. "D08U10L03R01U14R08L12R08U02R01D14U05D11R16U01R13D02U14R11D12U17R12L06U04R16D04R02D01U06D11"
D. "R08L07R03U03L14R11L09U09L02R06U11R09L15U07R06D15U11L05U02R08D13L05U06R13D15U11L10R16L14U15"
D. "R03L09U11L06R07L06D16U08R02U14D14R15D02L16D14U17D06L16D07R02U17D02U02D15U05R09L10D16U01L05"
D. "U06R10D11R01U07R13U06R02L11D13U08D04R15U08R14L17U05L12U11L14R12L02D10L14D10L11U15D07U05R10"
D. "U04R14U03D09L06D10L01U04L15R04U13D18R15L03U17R05L03D03L01U10L03R05U13D02R17D03U04L15D05L18"
D. "U07D07U10L18D14U18L11D03L15D14L16R02D08L12U11R12D02L03R12U07L09D08U07L10D02U10D16L17R13L12"
D. "R18L06U02D06L15D08U14R12L08R06L17U05D04L08U16R08U12L01R06D11L10U13R04L09R07D01L17R04L13R08"
D. "D14U03R10L18R11U03D05U02L14R12D12R11U05D17R02D06L13D04L05R07U07L12D16U06L01R18D04R11D10L11"
D. "D02L01D05U02R19D10U14R01U11R15D02L15U19R03L02D12R02L15R08D03R08D11R17D05R16L08R12L05R14D03"
D. "R19D04R18L04U12D07L08R11U14L12U17L01D05R08L18U16L15D13U18R11L07R19L15U10L04R09U07R08L16R08"
D. "L17D08L17D18U09D02L06U06L07D18R01U13L02U01R08U11D14R06U13R02D11L05U12D07U04R04D19R17L10U05"
D. "L01U04L06D11L16D09R16L03R01D03L05U18D13R10U05D04U17R04D18U01"
D. "*00"