-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7-1.cfm
More file actions
59 lines (52 loc) · 1.49 KB
/
7-1.cfm
File metadata and controls
59 lines (52 loc) · 1.49 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
54
55
56
57
58
59
<cffunction name="solve" output="false">
<cfargument name="input" required="true" />
<cfset var programNamesSeenOnRightSide = {} />
<cfset var line = '' />
<cfset var words = '' />
<cfset var programNamesOnRightSide = '' />
<cfset var programName = '' />
<cfloop list="#arguments.input#" item="line" delimiters="#Chr(10)#">
<cfset line = Trim(line) />
<cfset words = ListToArray(line, Chr(32)) />
<cfif line contains '->'>
<cfset programNamesOnRightSide = Replace(Trim(ListGetAt(line, 2, '>')), ' ', '', 'all') />
<cfloop list="#programNamesOnRightSide#" item="programName">
<cfset programNamesSeenOnRightSide[programName] = 1 />
</cfloop>
</cfif>
</cfloop>
<cfloop list="#arguments.input#" item="line" delimiters="#Chr(10)#">
<cfset line = Trim(line) />
<cfset words = ListToArray(line, Chr(32)) />
<cfif line contains '->'>
<cfset programName = ListFirst(line, ' ') />
<cfif !StructKeyExists(programNamesSeenOnRightSide, programName)>
<cfreturn programName />
</cfif>
</cfif>
</cfloop>
<cfthrow message="Did not find root program" />
</cffunction>
<cfset testCases = [
{
input = 'pbga (66)
xhth (57)
ebii (61)
havc (66)
ktlj (57)
fwft (72) -> ktlj, cntj, xhth
qoyq (66)
padx (45) -> pbga, havc, qoyq
tknk (41) -> ugml, padx, fwft
jptl (61)
ugml (68) -> gyxo, ebii, jptl
gyxo (61)
cntj (57)',
expectedOutput = 'tknk'
},
{
input = Trim(FileRead(ExpandPath('7.txt'))),
expectedOutput = 'ahnofa'
}
] />
<cfinclude template="test_runner_include.cfm" />