-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4-2.cfm
More file actions
70 lines (64 loc) · 1.65 KB
/
4-2.cfm
File metadata and controls
70 lines (64 loc) · 1.65 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
59
60
61
62
63
64
65
66
67
68
69
70
<cffunction name="solve">
<cfargument name="input" required="true" />
<cfset var line = '' />
<cfset var word = '' />
<cfset var newInput = '' >
<cfset var newLine = '' />
<cfset var letters = '' />
<cfset var sortedWord = '' />
<cfloop list="#arguments.input#" item="line" delimiters="#Chr(10)#">
<cfset line = Trim(line) />
<cfset newLine = '' />
<cfloop list="#line#" item="word" delimiters=" ">
<!--- ListSort with an empty string as delimiter does not work as expected on Adobe ColdFusion. --->
<cfset letters = ListToArray(word, '') />
<cfset ArraySort(letters, 'text', 'asc') />
<cfset sortedWord = ArrayToList(letters, '') />
<cfset newLine = ListAppend(newLine, sortedWord, ' ') />
</cfloop>
<cfset newInput &= newLine & Chr(10) />
</cfloop>
<cfset var numValid = 0 />
<cfset var hasDupe = false />
<cfloop list="#newInput#" item="line" delimiters="#Chr(10)#">
<cfset line = Trim(line) />
<cfset hasDupe = false />
<cfloop list="#line#" item="word" delimiters=" ">
<cfif ListValueCount(line, word, ' ') gte 2>
<cfset hasDupe = true />
<cfbreak />
</cfif>
</cfloop>
<cfif !hasDupe>
<cfset numValid++ />
</cfif>
</cfloop>
<cfreturn numValid />
</cffunction>
<cfset testCases = [
{
input = 'abcde fghij',
expectedOutput = 1
},
{
input = 'abcde xyz ecdab',
expectedOutput = 0
},
{
input = 'a ab abc abd abf abj',
expectedOutput = 1
},
{
input = 'iiii oiii ooii oooi oooo',
expectedOutput = 1
},
{
input = 'oiii ioii iioi iiio',
expectedOutput = 0
},
{
input = Trim(FileRead(ExpandPath('4.txt'))),
expectedOutput = 119
}
] />
<cfinclude template="test_runner_include.cfm" />