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

Commit eb3d688

Browse files
authored
Merge pull request #6 from BrandonShega/master
Challenge complete
2 parents 17e65cf + 3c30980 commit eb3d688

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

CodeChallenge.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1B9E113F1E005A7C00B9FA5A /* Clock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B9E113E1E005A7C00B9FA5A /* Clock.swift */; };
1313
1B9E11411E006A2B00B9FA5A /* BugKrushaClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */; };
1414
1B9E11461E006F0800B9FA5A /* ClockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B9E11451E006F0800B9FA5A /* ClockTests.swift */; };
15+
3D00956F1E03200C004E631A /* BrandonShegaClockEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */; };
1516
809B704A1BF01B68004131BE /* LoganWrightEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 809B70491BF01B68004131BE /* LoganWrightEntry.swift */; };
1617
9272E1AF1BD7F6560030B403 /* CodeChallenge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9272E1A41BD7F6560030B403 /* CodeChallenge.framework */; };
1718
9272E1E41BDED71C0030B403 /* LongestSubstringWithoutRepeatingCharactersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9272E1E31BDED71C0030B403 /* LongestSubstringWithoutRepeatingCharactersTests.swift */; };
@@ -50,6 +51,7 @@
5051
1B9E113E1E005A7C00B9FA5A /* Clock.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Clock.swift; sourceTree = "<group>"; };
5152
1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BugKrushaClockEntry.swift; sourceTree = "<group>"; };
5253
1B9E11451E006F0800B9FA5A /* ClockTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClockTests.swift; sourceTree = "<group>"; };
54+
3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrandonShegaClockEntry.swift; sourceTree = "<group>"; };
5355
809B70491BF01B68004131BE /* LoganWrightEntry.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoganWrightEntry.swift; sourceTree = "<group>"; };
5456
9272E1A41BD7F6560030B403 /* CodeChallenge.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CodeChallenge.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5557
9272E1AE1BD7F6560030B403 /* CodeChallenge.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CodeChallenge.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -108,6 +110,7 @@
108110
children = (
109111
1B9E11401E006A2B00B9FA5A /* BugKrushaClockEntry.swift */,
110112
1B31586E1E02FC7E0052ACBD /* FlavioSilverioClockEntry.swift */,
113+
3D00956E1E03200C004E631A /* BrandonShegaClockEntry.swift */,
111114
);
112115
path = Entries;
113116
sourceTree = "<group>";
@@ -362,6 +365,7 @@
362365
1B31586F1E02FC7E0052ACBD /* FlavioSilverioClockEntry.swift in Sources */,
363366
944CFCDB1BE7310B00FD2E41 /* LongestSubstringWithoutRepeatingCharactersChallenge.swift in Sources */,
364367
1B1F0A4E1BE7EA060030135C /* BugKrushaLetterCombinationsOfPhoneNumberEntry.swift in Sources */,
368+
3D00956F1E03200C004E631A /* BrandonShegaClockEntry.swift in Sources */,
365369
94350F741BE5F04A003592FB /* IanKeen.swift in Sources */,
366370
94350F761BE5F0F6003592FB /* Logan.swift in Sources */,
367371
94350F721BE5EF9F003592FB /* BugKrusha.swift in Sources */,

CodeChallenge/Challenges/Clock/Clock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ struct ClockChallenge: CodeChallengeType {
3232

3333
var entries: [CodeChallengeEntry<ClockChallenge>] = [
3434
bugKrushaClockEntry,
35-
FlavioSilverioClockEntry
35+
FlavioSilverioClockEntry,
36+
brandonShegaClockEntry
3637
]
3738

3839
func verifyOutput(_ output: (hourHandeAnlge: Int, minuteHandAngle: Int, secondHandAngle: Int), forInput input: String) -> Bool {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Foundation
2+
3+
let brandonShegaClockEntry = CodeChallengeEntry<ClockChallenge>(name: "brandonshega") { input in
4+
let df = DateFormatter()
5+
df.dateFormat = "HH:MM:SS"
6+
guard let date = df.date(from: input) else { return (0, 0, 0) }
7+
let dateComps = Calendar.current.dateComponents([.hour, .minute, .second], from: date)
8+
return dateComps.handsInAngles
9+
}
10+
11+
fileprivate extension DateComponents {
12+
var hoursToAngle: Int {
13+
guard let hour = hour else { return 0 }
14+
return hour * 30
15+
}
16+
17+
var minutesToAngle: Int {
18+
guard let minute = minute else { return 0 }
19+
return minute * 6
20+
}
21+
22+
var secondsToAngle: Int {
23+
guard let second = second else { return 0 }
24+
return second * 6
25+
}
26+
27+
var handsInAngles: (Int, Int, Int) {
28+
return (hoursToAngle, minutesToAngle, secondsToAngle)
29+
}
30+
}

0 commit comments

Comments
 (0)