This repository was archived by the owner on Aug 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Updated Travis to Xcode 8 #17
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
CodeChallenge/Challenges/Clock/Entries/juliand665ClockEntry.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
37 changes: 37 additions & 0 deletions
37
...tterCombinationsOfPhoneNumber/Entries/juliand665LetterCombinationOfPhoneNumberEntry.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I take that back... I always forget that |
||
"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"], | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
.../Challenges/LongestSubstringWithoutRepeatingCharacters/Entries/juliand665LSWRCEntry.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
CodeChallenge/Challenges/TwoSum/Entries/juliand665TwoSumEntry.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 👍