-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-2.cfm
More file actions
47 lines (44 loc) · 978 Bytes
/
1-2.cfm
File metadata and controls
47 lines (44 loc) · 978 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
44
45
46
47
<cffunction name="solve" output="false">
<cfargument name="input" required="true" />
<cfset var inputLength = Len(arguments.input) />
<cfset var offset = inputLength / 2 />
<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 = '1212',
expectedOutput = 6
},
{
input = '1221',
expectedOutput = 0
},
{
input = '123425',
expectedOutput = 4
},
{
input = '123123',
expectedOutput = 12
},
{
input = '12131415',
expectedOutput = 4
},
{
input = Trim(FileRead(ExpandPath('1.txt'))),
expectedOutput = 1292
}
] />
<cfinclude template="test_runner_include.cfm" />