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

Challenge complete #6

Merged
merged 2 commits into from
Dec 15, 2016
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: 4 additions & 0 deletions CodeChallenge.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
1B9E113F1E005A7C00B9FA5A /* Clock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B9E113E1E005A7C00B9FA5A /* Clock.swift */; };
1B9E11411E006A2B00B9FA5A /* BugKrushaClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */; };
1B9E11461E006F0800B9FA5A /* ClockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B9E11451E006F0800B9FA5A /* ClockTests.swift */; };
3D00956F1E03200C004E631A /* BrandonShegaClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */; };
809B704A1BF01B68004131BE /* LoganWrightEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 809B70491BF01B68004131BE /* LoganWrightEntry.swift */; };
9272E1AF1BD7F6560030B403 /* CodeChallenge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9272E1A41BD7F6560030B403 /* CodeChallenge.framework */; };
9272E1E41BDED71C0030B403 /* LongestSubstringWithoutRepeatingCharactersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9272E1E31BDED71C0030B403 /* LongestSubstringWithoutRepeatingCharactersTests.swift */; };
Expand Down Expand Up @@ -50,6 +51,7 @@
1B9E113E1E005A7C00B9FA5A /* Clock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Clock.swift; sourceTree = "<group>"; };
1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BugKrushaClockEntry.swift; sourceTree = "<group>"; };
1B9E11451E006F0800B9FA5A /* ClockTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClockTests.swift; sourceTree = "<group>"; };
3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrandonShegaClockEntry.swift; sourceTree = "<group>"; };
809B70491BF01B68004131BE /* LoganWrightEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoganWrightEntry.swift; sourceTree = "<group>"; };
9272E1A41BD7F6560030B403 /* CodeChallenge.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CodeChallenge.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9272E1AE1BD7F6560030B403 /* CodeChallenge.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CodeChallenge.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -108,6 +110,7 @@
children = (
1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */,
1B31586E1E02FC7E0052ACBD /* FlavioSilverioClockEntry.swift */,
3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */,
);
path = Entries;
sourceTree = "<group>";
Expand Down Expand Up @@ -362,6 +365,7 @@
1B31586F1E02FC7E0052ACBD /* FlavioSilverioClockEntry.swift in Sources */,
944CFCDB1BE7310B00FD2E41 /* LongestSubstringWithoutRepeatingCharactersChallenge.swift in Sources */,
1B1F0A4E1BE7EA060030135C /* BugKrushaLetterCombinationsOfPhoneNumberEntry.swift in Sources */,
3D00956F1E03200C004E631A /* BrandonShegaClockEntry.swift in Sources */,
94350F741BE5F04A003592FB /* IanKeen.swift in Sources */,
94350F761BE5F0F6003592FB /* Logan.swift in Sources */,
94350F721BE5EF9F003592FB /* BugKrusha.swift in Sources */,
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 @@ -32,7 +32,8 @@ struct ClockChallenge: CodeChallengeType {

var entries: [CodeChallengeEntry<ClockChallenge>] = [
bugKrushaClockEntry,
FlavioSilverioClockEntry
FlavioSilverioClockEntry,
brandonShegaClockEntry
]

func verifyOutput(_ output: (hourHandeAnlge: Int, minuteHandAngle: Int, secondHandAngle: Int), forInput input: String) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

let brandonShegaClockEntry = CodeChallengeEntry<ClockChallenge>(name: "brandonshega") { input in
let df = DateFormatter()
df.dateFormat = "HH:MM:SS"
guard let date = df.date(from: input) else { return (0, 0, 0) }
let dateComps = Calendar.current.dateComponents([.hour, .minute, .second], from: date)
return dateComps.handsInAngles
}

fileprivate extension DateComponents {
var hoursToAngle: Int {
guard let hour = hour else { return 0 }
return hour * 30
}

var minutesToAngle: Int {
guard let minute = minute else { return 0 }
return minute * 6
}

var secondsToAngle: Int {
guard let second = second else { return 0 }
return second * 6
}

var handsInAngles: (Int, Int, Int) {
return (hoursToAngle, minutesToAngle, secondsToAngle)
}
}