-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path18-2.cfm
More file actions
58 lines (51 loc) · 1.73 KB
/
18-2.cfm
File metadata and controls
58 lines (51 loc) · 1.73 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
<cffunction name="solve" output="false">
<cfargument name="input" required="true" />
<cfset var threadNames = [] />
<cfset var threadName = '' />
<cfset request.queueFromProgram0ToProgram1 = CreateObject('component', 'Queue').init() />
<cfset request.queueFromProgram1ToProgram0 = CreateObject('component', 'Queue').init() />
<cfset threadName = 'program0-' & CreateUUID() />
<cfset ArrayAppend(threadNames, threadName) />
<cfthread action="run" name="#threadName#" input="#arguments.input#">
<cfset CreateObject('component', 'Day18Part2Program').runAndReturnNumSentValues(
input = attributes.input,
outQueue = request.queueFromProgram0ToProgram1,
inQueue = request.queueFromProgram1ToProgram0,
initialRegisterValues = { p = 0 }
) />
</cfthread>
<cfset threadName = 'program1-' & CreateUUID() />
<cfset ArrayAppend(threadNames, threadName) />
<cfthread action="run" name="#threadName#" input="#arguments.input#">
<cfset request.numSentValues = CreateObject('component', 'Day18Part2Program').runAndReturnNumSentValues(
input = attributes.input,
outQueue = request.queueFromProgram1ToProgram0,
inQueue = request.queueFromProgram0ToProgram1,
initialRegisterValues = { p = 1 }
) />
</cfthread>
<cfthread action="join" name="#ArrayToList(threadNames)#" />
<cfloop array="#threadNames#" item="threadName">
<cfif cfthread[threadName].status neq 'COMPLETED'>
<cfdump var="#cfthread[threadName]#" abort="true" />
</cfif>
</cfloop>
<cfreturn request.numSentValues />
</cffunction>
<cfset testCases = [
{
input = 'snd 1
snd 2
snd p
rcv a
rcv b
rcv c
rcv d',
expectedOutput = 3
},
{
input = Trim(FileRead(ExpandPath('18.txt'))),
expectedOutput = 5969
}
] />
<cfinclude template="test_runner_include.cfm" />