Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit 06dbeb3

Browse files
authored
Merge pull request #17 from codesman/travis
Updated Travis to Xcode 8 and added juliand665 entries for all challenges.
2 parents d6cefc2 + 7d86135 commit 06dbeb3

File tree

12 files changed

+200
-20
lines changed

12 files changed

+200
-20
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: objective-c
2-
osx_image: xcode7.3
2+
osx_image: xcode8.2
33

44
script:
5-
- xcodebuild -project CodeChallenge.xcodeproj -scheme CodeChallengeTests -destination 'platform=iOS Simulator,name=iPhone 6' test
5+
- xcodebuild test -scheme CodeChallengeTests -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.1'

CodeChallenge.xcodeproj/project.pbxproj

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@
3939
9489866A1BE5CFB000D34976 /* CodeChallengeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948986691BE5CFB000D34976 /* CodeChallengeType.swift */; };
4040
948986701BE5D28500D34976 /* ExampleCodeChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9489866F1BE5D28500D34976 /* ExampleCodeChallenge.swift */; };
4141
94FB98CA1BE1B5D800228845 /* TwoSumChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94FB98C91BE1B5D800228845 /* TwoSumChallenge.swift */; };
42-
43-
B98954A51E200B9700335432 /* CodesmanBulletMatchEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = B98954A41E200B9700335432 /* CodesmanBulletMatchEntry.swift */; };
4442
9572008E1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572008D1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift */; };
43+
957200991E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957200981E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift */; };
44+
9572009C1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572009B1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift */; };
45+
9572009E1E206A5E006BB4D6 /* juliand665ClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572009D1E206A5E006BB4D6 /* juliand665ClockEntry.swift */; };
46+
957200A01E206A65006BB4D6 /* juliand665TwoSumEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572009F1E206A65006BB4D6 /* juliand665TwoSumEntry.swift */; };
47+
957200A21E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957200A11E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift */; };
4548
D5D15B361E0C966A00CC9B1C /* felixdumitClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5D15B351E0C966A00CC9B1C /* felixdumitClockEntry.swift */; };
4649
/* End PBXBuildFile section */
4750

@@ -91,11 +94,12 @@
9194
948986691BE5CFB000D34976 /* CodeChallengeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodeChallengeType.swift; sourceTree = "<group>"; };
9295
9489866F1BE5D28500D34976 /* ExampleCodeChallenge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleCodeChallenge.swift; sourceTree = "<group>"; };
9396
94FB98C91BE1B5D800228845 /* TwoSumChallenge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoSumChallenge.swift; sourceTree = "<group>"; };
94-
95-
B98954A41E200B9700335432 /* CodesmanBulletMatchEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CodesmanBulletMatchEntry.swift; path = BulletMatch/CodesmanBulletMatchEntry.swift; sourceTree = "<group>"; };
96-
9797
9572008D1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = juliand665BulletMatchEntry.swift; path = BulletMatch/Entries/juliand665BulletMatchEntry.swift; sourceTree = "<group>"; };
98-
98+
957200981E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665LetterCombinationOfPhoneNumberEntry.swift; sourceTree = "<group>"; };
99+
9572009B1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665LSWRCEntry.swift; sourceTree = "<group>"; };
100+
9572009D1E206A5E006BB4D6 /* juliand665ClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665ClockEntry.swift; sourceTree = "<group>"; };
101+
9572009F1E206A65006BB4D6 /* juliand665TwoSumEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665TwoSumEntry.swift; sourceTree = "<group>"; };
102+
957200A11E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CodesmanBulletMatchEntry.swift; path = BulletMatch/Entries/CodesmanBulletMatchEntry.swift; sourceTree = "<group>"; };
99103
D5D15B351E0C966A00CC9B1C /* felixdumitClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = felixdumitClockEntry.swift; sourceTree = "<group>"; };
100104
/* End PBXFileReference section */
101105

@@ -121,6 +125,7 @@
121125
1B1F0A4C1BE7E9820030135C /* Entries */ = {
122126
isa = PBXGroup;
123127
children = (
128+
957200981E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift */,
124129
1B1F0A4D1BE7EA060030135C /* BugKrushaLetterCombinationsOfPhoneNumberEntry.swift */,
125130
809B70491BF01B68004131BE /* LoganWrightEntry.swift */,
126131
);
@@ -130,10 +135,9 @@
130135
1B49C0511E0850DD0094121E /* Entries */ = {
131136
isa = PBXGroup;
132137
children = (
138+
957200A11E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift */,
133139
1B49C04F1E0850D90094121E /* BugKrushaBulletMatchEntry.swift */,
134-
B98954A41E200B9700335432 /* CodesmanBulletMatchEntry.swift */,
135140
9572008D1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift */,
136-
137141
);
138142
name = Entries;
139143
sourceTree = "<group>";
@@ -150,6 +154,7 @@
150154
1B9E11421E006A2F00B9FA5A /* Entries */ = {
151155
isa = PBXGroup;
152156
children = (
157+
9572009D1E206A5E006BB4D6 /* juliand665ClockEntry.swift */,
153158
3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */,
154159
1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */,
155160
2EB83A7F1E03290400FAAB32 /* EthanSchatzline-ClockEntry.swift */,
@@ -261,6 +266,7 @@
261266
94350F671BE5EB38003592FB /* Entries */ = {
262267
isa = PBXGroup;
263268
children = (
269+
9572009F1E206A65006BB4D6 /* juliand665TwoSumEntry.swift */,
264270
94350F681BE5EB90003592FB /* Aranasaurus.swift */,
265271
94350F6A1BE5EBD3003592FB /* AlexPersian.swift */,
266272
94350F6F1BE5EE94003592FB /* Aryaxt.swift */,
@@ -285,6 +291,7 @@
285291
944CFCD91BE730A700FD2E41 /* LongestSubstringWithoutRepeatingCharacters */ = {
286292
isa = PBXGroup;
287293
children = (
294+
9572009A1E206A4B006BB4D6 /* Entries */,
288295
944CFCDA1BE7310B00FD2E41 /* LongestSubstringWithoutRepeatingCharactersChallenge.swift */,
289296
);
290297
path = LongestSubstringWithoutRepeatingCharacters;
@@ -299,6 +306,14 @@
299306
path = Base;
300307
sourceTree = "<group>";
301308
};
309+
9572009A1E206A4B006BB4D6 /* Entries */ = {
310+
isa = PBXGroup;
311+
children = (
312+
9572009B1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift */,
313+
);
314+
path = Entries;
315+
sourceTree = "<group>";
316+
};
302317
/* End PBXGroup section */
303318

304319
/* Begin PBXHeadersBuildPhase section */
@@ -410,23 +425,25 @@
410425
isa = PBXSourcesBuildPhase;
411426
buildActionMask = 2147483647;
412427
files = (
428+
957200A21E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift in Sources */,
413429
94350F7A1BE5F24A003592FB /* Nuudles.swift in Sources */,
430+
957200991E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift in Sources */,
414431
94350F6B1BE5EBD3003592FB /* AlexPersian.swift in Sources */,
415432
1B9E113F1E005A7C00B9FA5A /* Clock.swift in Sources */,
416433
1B9E11411E006A2B00B9FA5A /* BugKrushaClockEntry.swift in Sources */,
417434
94350F781BE5F174003592FB /* Mosab.swift in Sources */,
418-
419-
B98954A51E200B9700335432 /* CodesmanBulletMatchEntry.swift in Sources */,
420435
9572008E1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift in Sources */,
421-
422436
94FB98CA1BE1B5D800228845 /* TwoSumChallenge.swift in Sources */,
423437
7B925E521E05AFFF0009B0CD /* matthijsClockEntry.swift in Sources */,
424438
2EB83A801E03290400FAAB32 /* EthanSchatzline-ClockEntry.swift in Sources */,
439+
957200A01E206A65006BB4D6 /* juliand665TwoSumEntry.swift in Sources */,
425440
9489866A1BE5CFB000D34976 /* CodeChallengeType.swift in Sources */,
426441
1B4ECDA51E08267B00767EBD /* BulletMatch.swift in Sources */,
427442
94350F701BE5EE94003592FB /* Aryaxt.swift in Sources */,
443+
9572009C1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift in Sources */,
428444
948986701BE5D28500D34976 /* ExampleCodeChallenge.swift in Sources */,
429445
1B31586F1E02FC7E0052ACBD /* FlavioSilverioClockEntry.swift in Sources */,
446+
9572009E1E206A5E006BB4D6 /* juliand665ClockEntry.swift in Sources */,
430447
944CFCDB1BE7310B00FD2E41 /* LongestSubstringWithoutRepeatingCharactersChallenge.swift in Sources */,
431448
1B1F0A4E1BE7EA060030135C /* BugKrushaLetterCombinationsOfPhoneNumberEntry.swift in Sources */,
432449
3D00956F1E03200C004E631A /* BrandonShegaClockEntry.swift in Sources */,

CodeChallenge/Challenges/BulletMatch/BulletMatch.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class BulletChallenge: CodeChallengeType {
4848

4949
var entries: [CodeChallengeEntry<BulletChallenge>] = [
5050
bugKrushaBulletMatchEntry,
51-
codesmanBulletMatchEntry
51+
codesmanBulletMatchEntry,
5252
juliand665BulletMatchEntry,
5353
]
5454

CodeChallenge/Challenges/Clock/Clock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ struct ClockChallenge: CodeChallengeType {
3636
ethanSchatzlineClockEntry,
3737
brandonShegaClockEntry,
3838
matthijsClockEntry,
39-
felixdumitClockEntry
39+
felixdumitClockEntry,
40+
juliand665ClockEntry,
4041
]
4142

4243
func verifyOutput(_ output: (hourHandeAnlge: Int, minuteHandAngle: Int, secondHandAngle: Int), forInput input: String) -> Bool {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// juliand665ClockEntry.swift
3+
// CodeChallenge
4+
//
5+
// Created by Julian Dunskus on 06.01.17.
6+
// Copyright © 2017 iosdevelopers. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
let juliand665ClockEntry = CodeChallengeEntry<ClockChallenge>(name: "juliand665") { input in
12+
var time = input.components(separatedBy: ":").map { Int($0)! }
13+
14+
time[2] *= 6
15+
time[1] *= 6
16+
time[1] += time[2] / 60
17+
time[0] *= 30
18+
time[0] += time[1] / 12
19+
20+
return (time[0], time[1], time[2])
21+
}
22+
23+
let juliand665ClockEntryNice = CodeChallengeEntry<ClockChallenge>(name: "juliand665 (swiftier)") { input in
24+
let secs = input.components(separatedBy: ":").flatMap { Int($0) }.reduce(0) { $0 * 60 + $1 }
25+
26+
return (secs * 360 / 43200, (secs % 3600) * 360 / 3600, (secs % 60) * 360 / 60)
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// juliand665LetterCombinationOfPhoneNumberEntry.swift
3+
// CodeChallenge
4+
//
5+
// Created by Julian Dunskus on 06.01.17.
6+
// Copyright © 2017 iosdevelopers. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
let juliand665LetterCombinationOfPhoneNumberEntry = CodeChallengeEntry<LetterCombinationsOfPhoneNumberChallenge>(name: "juliand665") { input in
12+
13+
var combs: [String] = [""]
14+
15+
let expanded = input.characters.flatMap { numbersToLetters[$0] }
16+
17+
for letters in expanded {
18+
combs = combs.flatMap { prev in
19+
letters.map { prev.appending($0) }
20+
}
21+
}
22+
23+
return combs
24+
}
25+
26+
private let numbersToLetters: [Character: [String]] = [ // explicit declaration reduces compile time
27+
"0": [" "],
28+
"1": [""],
29+
"2": ["a", "b", "c"],
30+
"3": ["d", "e", "f"],
31+
"4": ["g", "h", "i"],
32+
"5": ["j", "k", "l"],
33+
"6": ["m", "n", "o"],
34+
"7": ["p", "q", "r", "s"],
35+
"8": ["t", "u", "v"],
36+
"9": ["w", "x", "y", "z"],
37+
]

CodeChallenge/Challenges/LetterCombinationsOfPhoneNumber/LetterCombinationsOfPhoneNumberChallenge.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ struct LetterCombinationsOfPhoneNumberChallenge: CodeChallengeType {
3030
let entries: [CodeChallengeEntry<LetterCombinationsOfPhoneNumberChallenge>] = [
3131
// Put your Entry instance here!
3232
bugKrushaLetterCombinationOfPhoneNumberEntry,
33-
LoganWrightLetterCombinationOfPhoneNumberEntry
33+
LoganWrightLetterCombinationOfPhoneNumberEntry,
34+
juliand665LetterCombinationOfPhoneNumberEntry
3435
]
3536

3637
func generateDataset() -> [InputType] {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// juliand665LSWRCEntry.swift
3+
// CodeChallenge
4+
//
5+
// Created by Julian Dunskus on 06.01.17.
6+
// Copyright © 2017 iosdevelopers. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
let juliand665LSWRCEntry = CodeChallengeEntry<LongestSubstringWithoutRepeatingCharactersChallenge>(name: "juliand665") { input in
12+
var chars: [Character] = []
13+
var longest = 0
14+
15+
for char in input.characters {
16+
if chars.contains(char) {
17+
chars.removeFirst(chars.index(of: char)! + 1)
18+
}
19+
chars.append(char)
20+
longest = max(longest, chars.count)
21+
}
22+
23+
return longest
24+
}

CodeChallenge/Challenges/LongestSubstringWithoutRepeatingCharacters/LongestSubstringWithoutRepeatingCharactersChallenge.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ struct LongestSubstringWithoutRepeatingCharactersChallenge: CodeChallengeType {
2222
let title = "Longest Substring Without Repeating Characters"
2323

2424
let entries: [CodeChallengeEntry<LongestSubstringWithoutRepeatingCharactersChallenge>] = [
25-
// Put your entry instance here!
25+
juliand665LSWRCEntry
2626
]
2727

2828
func generateDataset() -> [InputType] {
2929
return [
3030
"abcabcbb",
31-
"bbbbb"
31+
"bbbbb",
32+
"",
33+
"jdjekjaoefeij"
3234
]
3335
}
3436

@@ -39,6 +41,8 @@ struct LongestSubstringWithoutRepeatingCharactersChallenge: CodeChallengeType {
3941

4042
fileprivate let verificationDictionary = [
4143
"abcabcbb": 3,
42-
"bbbbb": 1
44+
"bbbbb": 1,
45+
"": 0,
46+
"jdjekjaoefeij": 6
4347
]
4448
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// juliand665TwoSumEntry.swift
3+
// CodeChallenge
4+
//
5+
// Created by Julian Dunskus on 06.01.17.
6+
// Copyright © 2017 iosdevelopers. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
let juliand665TwoSumEntryNice = CodeChallengeEntry<TwoSumChallenge>(name: "juliand665 (swiftier)") { (nums, target) in // O(log n)
12+
13+
var numbers = nums.enumerated().sorted() { $0.1 < $1.1 } // I assume the closure is making it slower
14+
var i1 = numbers.startIndex
15+
var i2 = numbers.endIndex - 1
16+
17+
// how to C
18+
while true { // solution guaranteed
19+
let n1 = numbers[i1]
20+
let n2 = numbers[i2]
21+
let sum = n1.element + n2.element
22+
if sum == target {
23+
return (n1.offset + 1, n2.offset + 1) // O(1)
24+
} else if sum < target {
25+
i1 += 1
26+
} else {
27+
i2 -= 1
28+
}
29+
}
30+
}
31+
32+
let juliand665TwoSumEntryFast = CodeChallengeEntry<TwoSumChallenge>(name: "juliand665 (swifter)") { (nums, target) in // O(log n)
33+
34+
var numbers = nums.sorted()
35+
var i1 = numbers.startIndex
36+
var i2 = numbers.endIndex - 1
37+
38+
// how to C
39+
while true { // solution guaranteed
40+
let n1 = numbers[i1]
41+
let n2 = numbers[i2]
42+
let sum = n1 + n2
43+
if sum == target {
44+
return (nums.index(of: n1)! + 1, nums.index(of: n2)! + 1) // O(n)
45+
// darn you, indices! sorting .enumerated() instead seems to be slower :(
46+
} else if sum < target {
47+
i1 += 1
48+
} else {
49+
i2 -= 1
50+
}
51+
}
52+
}
53+
54+
let juliand665TwoSumEntryUgly = CodeChallengeEntry<TwoSumChallenge>(name: "juliand665 (hardcoded)") { (nums, target) in // O(n)
55+
56+
var first: Int?
57+
58+
for (index, num) in nums.enumerated() {
59+
if num > 2 {
60+
if let first = first {
61+
return (first + 1, index + 1) // why would you not want zero-based indices?
62+
}
63+
first = index
64+
}
65+
}
66+
return nil
67+
}

CodeChallenge/Challenges/TwoSum/TwoSumChallenge.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ struct TwoSumChallenge: CodeChallengeType {
3232
ianKeenTwoSumEntry,
3333
loganTwoSumEntry,
3434
mosabTwoSumEntry,
35-
nuudlesTwoSumEntry
35+
nuudlesTwoSumEntry,
36+
juliand665TwoSumEntryFast,
37+
juliand665TwoSumEntryUgly,
3638
]
3739

3840
func generateDataset() -> [InputType] {

0 commit comments

Comments
 (0)