-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13-2.cfm
More file actions
53 lines (49 loc) · 1.2 KB
/
13-2.cfm
File metadata and controls
53 lines (49 loc) · 1.2 KB
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
<cffunction name="solve" output="false">
<cfargument name="input" required="true" />
<cfset var firewall = {} />
<cfset var maxDepth = 0 />
<cfset var line = '' />
<cfset var words = '' />
<cfset var depth = '' />
<cfloop list="#arguments.input#" item="line" delimiters="#Chr(10)#">
<cfset words = ListToArray(Trim(line), Chr(32)) />
<cfset depth = Replace(words[1], ':', '') />
<cfset firewall[depth] = words[2] />
<cfset maxDepth = Max(maxDepth, depth) />
</cfloop>
<cfset var tick = '' />
<cfset var myPos = '' />
<cfset var delay = -1 />
<cfset var hit = true />
<cfloop condition="hit">
<cfset delay++ />
<cfset myPos = -1 />
<cfset hit = false />
<cfset tick = delay />
<cfloop condition="myPos lt maxDepth">
<cfset myPos++ />
<cfif StructKeyExists(firewall, myPos)>
<cfif tick % (firewall[myPos] * 2 - 2) eq 0>
<cfset hit = true />
<cfbreak />
</cfif>
</cfif>
<cfset tick++ />
</cfloop>
</cfloop>
<cfreturn delay />
</cffunction>
<cfset testCases = [
{
input = '0: 3
1: 2
4: 4
6: 4',
expectedOutput = 10
},
{
input = Trim(FileRead(ExpandPath('13.txt'))),
expectedOutput = 3913186
}
] />
<cfinclude template="test_runner_include.cfm" />