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

Updated Travis to Xcode 8 #17

Merged
merged 4 commits into from
Jan 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: objective-c
osx_image: xcode7.3
osx_image: xcode8.2

script:
- xcodebuild -project CodeChallenge.xcodeproj -scheme CodeChallengeTests -destination 'platform=iOS Simulator,name=iPhone 6' test
- xcodebuild test -scheme CodeChallengeTests -destination 'platform=iOS Simulator,name=iPhone 6,OS=10.1'
39 changes: 28 additions & 11 deletions CodeChallenge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
9489866A1BE5CFB000D34976 /* CodeChallengeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948986691BE5CFB000D34976 /* CodeChallengeType.swift */; };
948986701BE5D28500D34976 /* ExampleCodeChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9489866F1BE5D28500D34976 /* ExampleCodeChallenge.swift */; };
94FB98CA1BE1B5D800228845 /* TwoSumChallenge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94FB98C91BE1B5D800228845 /* TwoSumChallenge.swift */; };

B98954A51E200B9700335432 /* CodesmanBulletMatchEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = B98954A41E200B9700335432 /* CodesmanBulletMatchEntry.swift */; };
9572008E1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572008D1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift */; };
957200991E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957200981E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift */; };
9572009C1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572009B1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift */; };
9572009E1E206A5E006BB4D6 /* juliand665ClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572009D1E206A5E006BB4D6 /* juliand665ClockEntry.swift */; };
957200A01E206A65006BB4D6 /* juliand665TwoSumEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9572009F1E206A65006BB4D6 /* juliand665TwoSumEntry.swift */; };
957200A21E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957200A11E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift */; };
D5D15B361E0C966A00CC9B1C /* felixdumitClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5D15B351E0C966A00CC9B1C /* felixdumitClockEntry.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -91,11 +94,12 @@
948986691BE5CFB000D34976 /* CodeChallengeType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CodeChallengeType.swift; sourceTree = "<group>"; };
9489866F1BE5D28500D34976 /* ExampleCodeChallenge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleCodeChallenge.swift; sourceTree = "<group>"; };
94FB98C91BE1B5D800228845 /* TwoSumChallenge.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoSumChallenge.swift; sourceTree = "<group>"; };

B98954A41E200B9700335432 /* CodesmanBulletMatchEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CodesmanBulletMatchEntry.swift; path = BulletMatch/CodesmanBulletMatchEntry.swift; sourceTree = "<group>"; };

9572008D1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = juliand665BulletMatchEntry.swift; path = BulletMatch/Entries/juliand665BulletMatchEntry.swift; sourceTree = "<group>"; };

957200981E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665LetterCombinationOfPhoneNumberEntry.swift; sourceTree = "<group>"; };
9572009B1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665LSWRCEntry.swift; sourceTree = "<group>"; };
9572009D1E206A5E006BB4D6 /* juliand665ClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665ClockEntry.swift; sourceTree = "<group>"; };
9572009F1E206A65006BB4D6 /* juliand665TwoSumEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = juliand665TwoSumEntry.swift; sourceTree = "<group>"; };
957200A11E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CodesmanBulletMatchEntry.swift; path = BulletMatch/Entries/CodesmanBulletMatchEntry.swift; sourceTree = "<group>"; };
D5D15B351E0C966A00CC9B1C /* felixdumitClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = felixdumitClockEntry.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -121,6 +125,7 @@
1B1F0A4C1BE7E9820030135C /* Entries */ = {
isa = PBXGroup;
children = (
957200981E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift */,
1B1F0A4D1BE7EA060030135C /* BugKrushaLetterCombinationsOfPhoneNumberEntry.swift */,
809B70491BF01B68004131BE /* LoganWrightEntry.swift */,
);
Expand All @@ -130,10 +135,9 @@
1B49C0511E0850DD0094121E /* Entries */ = {
isa = PBXGroup;
children = (
957200A11E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift */,
1B49C04F1E0850D90094121E /* BugKrushaBulletMatchEntry.swift */,
B98954A41E200B9700335432 /* CodesmanBulletMatchEntry.swift */,
9572008D1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift */,

);
name = Entries;
sourceTree = "<group>";
Expand All @@ -150,6 +154,7 @@
1B9E11421E006A2F00B9FA5A /* Entries */ = {
isa = PBXGroup;
children = (
9572009D1E206A5E006BB4D6 /* juliand665ClockEntry.swift */,
3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */,
1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */,
2EB83A7F1E03290400FAAB32 /* EthanSchatzline-ClockEntry.swift */,
Expand Down Expand Up @@ -261,6 +266,7 @@
94350F671BE5EB38003592FB /* Entries */ = {
isa = PBXGroup;
children = (
9572009F1E206A65006BB4D6 /* juliand665TwoSumEntry.swift */,
94350F681BE5EB90003592FB /* Aranasaurus.swift */,
94350F6A1BE5EBD3003592FB /* AlexPersian.swift */,
94350F6F1BE5EE94003592FB /* Aryaxt.swift */,
Expand All @@ -285,6 +291,7 @@
944CFCD91BE730A700FD2E41 /* LongestSubstringWithoutRepeatingCharacters */ = {
isa = PBXGroup;
children = (
9572009A1E206A4B006BB4D6 /* Entries */,
944CFCDA1BE7310B00FD2E41 /* LongestSubstringWithoutRepeatingCharactersChallenge.swift */,
);
path = LongestSubstringWithoutRepeatingCharacters;
Expand All @@ -299,6 +306,14 @@
path = Base;
sourceTree = "<group>";
};
9572009A1E206A4B006BB4D6 /* Entries */ = {
isa = PBXGroup;
children = (
9572009B1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift */,
);
path = Entries;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -410,23 +425,25 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
957200A21E206A94006BB4D6 /* CodesmanBulletMatchEntry.swift in Sources */,
94350F7A1BE5F24A003592FB /* Nuudles.swift in Sources */,
957200991E206A35006BB4D6 /* juliand665LetterCombinationOfPhoneNumberEntry.swift in Sources */,
94350F6B1BE5EBD3003592FB /* AlexPersian.swift in Sources */,
1B9E113F1E005A7C00B9FA5A /* Clock.swift in Sources */,
1B9E11411E006A2B00B9FA5A /* BugKrushaClockEntry.swift in Sources */,
94350F781BE5F174003592FB /* Mosab.swift in Sources */,

B98954A51E200B9700335432 /* CodesmanBulletMatchEntry.swift in Sources */,
9572008E1E1F19F9006BB4D6 /* juliand665BulletMatchEntry.swift in Sources */,

94FB98CA1BE1B5D800228845 /* TwoSumChallenge.swift in Sources */,
7B925E521E05AFFF0009B0CD /* matthijsClockEntry.swift in Sources */,
2EB83A801E03290400FAAB32 /* EthanSchatzline-ClockEntry.swift in Sources */,
957200A01E206A65006BB4D6 /* juliand665TwoSumEntry.swift in Sources */,
9489866A1BE5CFB000D34976 /* CodeChallengeType.swift in Sources */,
1B4ECDA51E08267B00767EBD /* BulletMatch.swift in Sources */,
94350F701BE5EE94003592FB /* Aryaxt.swift in Sources */,
9572009C1E206A4B006BB4D6 /* juliand665LSWRCEntry.swift in Sources */,
948986701BE5D28500D34976 /* ExampleCodeChallenge.swift in Sources */,
1B31586F1E02FC7E0052ACBD /* FlavioSilverioClockEntry.swift in Sources */,
9572009E1E206A5E006BB4D6 /* juliand665ClockEntry.swift in Sources */,
944CFCDB1BE7310B00FD2E41 /* LongestSubstringWithoutRepeatingCharactersChallenge.swift in Sources */,
1B1F0A4E1BE7EA060030135C /* BugKrushaLetterCombinationsOfPhoneNumberEntry.swift in Sources */,
3D00956F1E03200C004E631A /* BrandonShegaClockEntry.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion CodeChallenge/Challenges/BulletMatch/BulletMatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class BulletChallenge: CodeChallengeType {

var entries: [CodeChallengeEntry<BulletChallenge>] = [
bugKrushaBulletMatchEntry,
codesmanBulletMatchEntry
codesmanBulletMatchEntry,
juliand665BulletMatchEntry,
]

Expand Down
3 changes: 2 additions & 1 deletion CodeChallenge/Challenges/Clock/Clock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ struct ClockChallenge: CodeChallengeType {
ethanSchatzlineClockEntry,
brandonShegaClockEntry,
matthijsClockEntry,
felixdumitClockEntry
felixdumitClockEntry,
juliand665ClockEntry,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think Swift supported trailing commas in array literals, but I see this builds and runs so 👍

]

func verifyOutput(_ output: (hourHandeAnlge: Int, minuteHandAngle: Int, secondHandAngle: Int), forInput input: String) -> Bool {
Expand Down
27 changes: 27 additions & 0 deletions CodeChallenge/Challenges/Clock/Entries/juliand665ClockEntry.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// juliand665ClockEntry.swift
// CodeChallenge
//
// Created by Julian Dunskus on 06.01.17.
// Copyright © 2017 iosdevelopers. All rights reserved.
//

import Foundation

let juliand665ClockEntry = CodeChallengeEntry<ClockChallenge>(name: "juliand665") { input in
var time = input.components(separatedBy: ":").map { Int($0)! }

time[2] *= 6
time[1] *= 6
time[1] += time[2] / 60
time[0] *= 30
time[0] += time[1] / 12

return (time[0], time[1], time[2])
}

let juliand665ClockEntryNice = CodeChallengeEntry<ClockChallenge>(name: "juliand665 (swiftier)") { input in
let secs = input.components(separatedBy: ":").flatMap { Int($0) }.reduce(0) { $0 * 60 + $1 }

return (secs * 360 / 43200, (secs % 3600) * 360 / 3600, (secs % 60) * 360 / 60)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// juliand665LetterCombinationOfPhoneNumberEntry.swift
// CodeChallenge
//
// Created by Julian Dunskus on 06.01.17.
// Copyright © 2017 iosdevelopers. All rights reserved.
//

import Foundation

let juliand665LetterCombinationOfPhoneNumberEntry = CodeChallengeEntry<LetterCombinationsOfPhoneNumberChallenge>(name: "juliand665") { input in

var combs: [String] = [""]

let expanded = input.characters.flatMap { numbersToLetters[$0] }

for letters in expanded {
combs = combs.flatMap { prev in
letters.map { prev.appending($0) }
}
}

return combs
}

private let numbersToLetters: [Character: [String]] = [ // explicit declaration reduces compile time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to update the README for Swift 3, but this should be fileprivate. Don't worry about changing it @juliand665, I'll do it when I update the README, but just wanted to point it out here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I take that back... I always forget that private is more restrictive than fileprivate, so nevermind! No changes needed :)

"0": [" "],
"1": [""],
"2": ["a", "b", "c"],
"3": ["d", "e", "f"],
"4": ["g", "h", "i"],
"5": ["j", "k", "l"],
"6": ["m", "n", "o"],
"7": ["p", "q", "r", "s"],
"8": ["t", "u", "v"],
"9": ["w", "x", "y", "z"],
]
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ struct LetterCombinationsOfPhoneNumberChallenge: CodeChallengeType {
let entries: [CodeChallengeEntry<LetterCombinationsOfPhoneNumberChallenge>] = [
// Put your Entry instance here!
bugKrushaLetterCombinationOfPhoneNumberEntry,
LoganWrightLetterCombinationOfPhoneNumberEntry
LoganWrightLetterCombinationOfPhoneNumberEntry,
juliand665LetterCombinationOfPhoneNumberEntry
]

func generateDataset() -> [InputType] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// juliand665LSWRCEntry.swift
// CodeChallenge
//
// Created by Julian Dunskus on 06.01.17.
// Copyright © 2017 iosdevelopers. All rights reserved.
//

import Foundation

let juliand665LSWRCEntry = CodeChallengeEntry<LongestSubstringWithoutRepeatingCharactersChallenge>(name: "juliand665") { input in
var chars: [Character] = []
var longest = 0

for char in input.characters {
if chars.contains(char) {
chars.removeFirst(chars.index(of: char)! + 1)
}
chars.append(char)
longest = max(longest, chars.count)
}

return longest
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ struct LongestSubstringWithoutRepeatingCharactersChallenge: CodeChallengeType {
let title = "Longest Substring Without Repeating Characters"

let entries: [CodeChallengeEntry<LongestSubstringWithoutRepeatingCharactersChallenge>] = [
// Put your entry instance here!
juliand665LSWRCEntry
]

func generateDataset() -> [InputType] {
return [
"abcabcbb",
"bbbbb"
"bbbbb",
"",
"jdjekjaoefeij"
]
}

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

fileprivate let verificationDictionary = [
"abcabcbb": 3,
"bbbbb": 1
"bbbbb": 1,
"": 0,
"jdjekjaoefeij": 6
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// juliand665TwoSumEntry.swift
// CodeChallenge
//
// Created by Julian Dunskus on 06.01.17.
// Copyright © 2017 iosdevelopers. All rights reserved.
//

import Foundation

let juliand665TwoSumEntryNice = CodeChallengeEntry<TwoSumChallenge>(name: "juliand665 (swiftier)") { (nums, target) in // O(log n)

var numbers = nums.enumerated().sorted() { $0.1 < $1.1 } // I assume the closure is making it slower
var i1 = numbers.startIndex
var i2 = numbers.endIndex - 1

// how to C
while true { // solution guaranteed
let n1 = numbers[i1]
let n2 = numbers[i2]
let sum = n1.element + n2.element
if sum == target {
return (n1.offset + 1, n2.offset + 1) // O(1)
} else if sum < target {
i1 += 1
} else {
i2 -= 1
}
}
}

let juliand665TwoSumEntryFast = CodeChallengeEntry<TwoSumChallenge>(name: "juliand665 (swifter)") { (nums, target) in // O(log n)

var numbers = nums.sorted()
var i1 = numbers.startIndex
var i2 = numbers.endIndex - 1

// how to C
while true { // solution guaranteed
let n1 = numbers[i1]
let n2 = numbers[i2]
let sum = n1 + n2
if sum == target {
return (nums.index(of: n1)! + 1, nums.index(of: n2)! + 1) // O(n)
// darn you, indices! sorting .enumerated() instead seems to be slower :(
} else if sum < target {
i1 += 1
} else {
i2 -= 1
}
}
}

let juliand665TwoSumEntryUgly = CodeChallengeEntry<TwoSumChallenge>(name: "juliand665 (hardcoded)") { (nums, target) in // O(n)

var first: Int?

for (index, num) in nums.enumerated() {
if num > 2 {
if let first = first {
return (first + 1, index + 1) // why would you not want zero-based indices?
}
first = index
}
}
return nil
}
4 changes: 3 additions & 1 deletion CodeChallenge/Challenges/TwoSum/TwoSumChallenge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ struct TwoSumChallenge: CodeChallengeType {
ianKeenTwoSumEntry,
loganTwoSumEntry,
mosabTwoSumEntry,
nuudlesTwoSumEntry
nuudlesTwoSumEntry,
juliand665TwoSumEntryFast,
juliand665TwoSumEntryUgly,
]

func generateDataset() -> [InputType] {
Expand Down