-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15-1.cfm
More file actions
34 lines (30 loc) · 1.11 KB
/
15-1.cfm
File metadata and controls
34 lines (30 loc) · 1.11 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
<cfsetting requesttimeout="3600" />
<cffunction name="solve" output="false">
<cfargument name="input" required="true" />
<cfset var startingValueA = Trim(ListGetAt(arguments.input, 5, ' #Chr(10)#')) />
<cfset var startingValueB = Trim(ListGetAt(arguments.input, 10, ' #Chr(10)#')) />
<cfset var generatorA = CreateObject('component', 'Day15Generator').init(startingValue = startingValueA, factor = 16807) />
<cfset var generatorB = CreateObject('component', 'Day15Generator').init(startingValue = startingValueB, factor = 48271) />
<cfset var matches = 0 />
<cfset var i = '' />
<cfloop from="1" to="40000000" index="i">
<cfif BitAnd(generatorA.next(), 65535) eq BitAnd(generatorB.next(), 65535) >
<cfset matches++ />
<cflog file="AdventOfCode" text="Pair #i# matches - Number of matches: #matches#" />
</cfif>
</cfloop>
<cfreturn matches />
</cffunction>
<cfset testCases = [
{
input = 'Generator A starts with 65
Generator B starts with 8921
',
expectedOutput = 588
},
{
input = Trim(FileRead(ExpandPath('15.txt'))),
expectedOutput = 567
}
] />
<cfinclude template="test_runner_include.cfm" />