-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-1.cfm
More file actions
43 lines (40 loc) · 913 Bytes
/
1-1.cfm
File metadata and controls
43 lines (40 loc) · 913 Bytes
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
<cffunction name="solve" output="false">
<cfargument name="input" required="true" />
<cfset var inputLength = Len(arguments.input) />
<cfset var offset = 1 />
<cfset var sum = 0 />
<cfset var pos = '' />
<cfset var currentDigit = '' />
<cfset var otherDigit = '' />
<cfloop from="1" to="#inputLength#" index="pos">
<cfset currentDigit = Mid(input, pos, 1) />
<cfset otherDigit = Mid(input, (pos + offset - 1) mod inputLength + 1, 1) />
<cfif currentDigit eq otherDigit>
<cfset sum += currentDigit />
</cfif>
</cfloop>
<cfreturn sum />
</cffunction>
<cfset testCases = [
{
input = '1122',
expectedOutput = 3
},
{
input = '1111',
expectedOutput = 4
},
{
input = '1234',
expectedOutput = 0
},
{
input = '91212129',
expectedOutput = 9
},
{
input = Trim(FileRead(ExpandPath('1.txt'))),
expectedOutput = 1393
}
] />
<cfinclude template="test_runner_include.cfm" />