-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay15Generator.cfc
More file actions
36 lines (28 loc) · 1.45 KB
/
Day15Generator.cfc
File metadata and controls
36 lines (28 loc) · 1.45 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
<cfcomponent output="false">
<cffunction name="init" access="public" output="false">
<cfargument name="startingValue" type="numeric" required="true" />
<cfargument name="factor" type="numeric" required="true" />
<cfset variables.math = CreateObject('java', 'java.lang.Math') />
<cfset variables.value = CreateObject('java', 'java.lang.Long').init(arguments.startingValue) />
<cfset variables.factor = CreateObject('java', 'java.lang.Long').init(arguments.factor) />
<cfset variables.divisor = CreateObject('java', 'java.lang.Long').init('2147483647') />
<cfreturn this />
</cffunction>
<cffunction name="next" access="public" returntype="numeric" output="false">
<!--- Digging down into Java seems to be the only way to make this work on Adobe ColdFusion.
Doing a straigh-forward ((value * factor) % divisor) results in:
"Cannot convert the value 1.8360891185E10 to an integer because it cannot fit inside an integer."
Lucee works either way. --->
<cfset variables.value = math.floorMod(math.multiplyExact(variables.value, variables.factor), variables.divisor) />
<cfreturn variables.value />
</cffunction>
<cffunction name="nextMultipleOf" access="public" returntype="numeric" output="false">
<cfargument name="multipleOf" type="numeric" required="true" />
<cfloop condition="true">
<cfset next() />
<cfif variables.value % arguments.multipleOf eq 0>
<cfreturn variables.value />
</cfif>
</cfloop>
</cffunction>
</cfcomponent>