1
+ <cfset x = 0 />
2
+ <cfset y = 0 />
3
+ <cfset houses = {' 0,0' : true } />
4
+ <cfloop file =" input.txt" characters =" 1" index =" c" >
5
+ <cfswitch expression =" #c #" >
6
+ <cfcase value =" ^" ><cfset y ++ /></cfcase >
7
+ <cfcase value =" >" ><cfset x ++ /></cfcase >
8
+ <cfcase value =" v" ><cfset y -- /></cfcase >
9
+ <cfcase value =" <" ><cfset x -- /></cfcase >
10
+ </cfswitch >
11
+ <cfset houses [' #x #,#y #' ] = true />
12
+ </cfloop >
13
+ <cfoutput >
14
+ Day 3-1: Total houses visited by santa: #houses .count () #
15
+ </cfoutput >
16
+
17
+
18
+ <cfset houses = {
19
+ santa : { position : ' 0,0' }
20
+ ,robo : { position : ' 0,0' }
21
+ ,visited : {' 0,0' : true }
22
+ } />
23
+ <cfset who = ' robo' />
24
+ <cfloop file =" input.txt" characters =" 1" index =" c" >
25
+ <cfset who = IIF (who EQ ' robo' ,DE (' santa' ),DE (' robo' )) />
26
+ <cfset x = houses [who ].position .listFirst () />
27
+ <cfset y = houses [who ].position .listLast () />
28
+ <cfswitch expression =" #c #" >
29
+ <cfcase value =" ^" ><cfset y ++ /></cfcase >
30
+ <cfcase value =" >" ><cfset x ++ /></cfcase >
31
+ <cfcase value =" v" ><cfset y -- /></cfcase >
32
+ <cfcase value =" <" ><cfset x -- /></cfcase >
33
+ </cfswitch >
34
+ <cfset houses .visited [' #x #,#y #' ] = true />
35
+ <cfset houses [who ].position = ' #x #,#y #' />
36
+ </cfloop >
37
+ <cfoutput >
38
+ Day 3-2: Total houses visited by santa+robo: #houses .visited .count () #
39
+ </cfoutput >
0 commit comments