Skip to content

Commit a16c534

Browse files
committed
removing boilerplate stuff
1 parent 55d99d3 commit a16c534

19 files changed

+102
-294
lines changed

Diff for: euler.xcodeproj/project.pbxproj

-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
291948DD1A54CFA500DB9AAF /* PrimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291948DC1A54CFA500DB9AAF /* PrimeTests.swift */; };
1110
291948E01A54CFDA00DB9AAF /* String+EulerKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291948DF1A54CFDA00DB9AAF /* String+EulerKit.swift */; };
1211
291948E11A54CFE200DB9AAF /* String+EulerKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291948DF1A54CFDA00DB9AAF /* String+EulerKit.swift */; };
1312
291948E31A54D04F00DB9AAF /* Sequences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291948E21A54D04F00DB9AAF /* Sequences.swift */; };
@@ -35,7 +34,6 @@
3534
29B7CDF81A579F2E00BBDCB1 /* Problem28.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B7CDF71A579F2E00BBDCB1 /* Problem28.swift */; };
3635
29B7CDF91A579F2E00BBDCB1 /* Problem28.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B7CDF71A579F2E00BBDCB1 /* Problem28.swift */; };
3736
29D1B4551A47A91F0002B363 /* BigNum.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D1B4541A47A91F0002B363 /* BigNum.swift */; };
38-
29D1B4571A47AA200002B363 /* BigNumTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29D1B4561A47AA200002B363 /* BigNumTests.swift */; };
3937
29E2E5041A599D7700124A29 /* Problem29.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29E2E5031A599D7700124A29 /* Problem29.swift */; };
4038
29E2E5051A599D7700124A29 /* Problem29.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29E2E5031A599D7700124A29 /* Problem29.swift */; };
4139
29E2E5071A59BB9B00124A29 /* Problem30.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29E2E5061A59BB9B00124A29 /* Problem30.swift */; };
@@ -58,7 +56,6 @@
5856
558C9EF919C1460700D8E04D /* Problem17.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558C9EF819C1460700D8E04D /* Problem17.swift */; };
5957
558C9EFA19C1460700D8E04D /* Problem17.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558C9EF819C1460700D8E04D /* Problem17.swift */; };
6058
558DE42A19B687CF0088B812 /* Euler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558DE42919B687CF0088B812 /* Euler.swift */; };
61-
558DE46319B6A3CB0088B812 /* EulerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558DE46219B6A3CB0088B812 /* EulerTests.swift */; };
6259
558DE46919B6A4050088B812 /* Euler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558DE42919B687CF0088B812 /* Euler.swift */; };
6360
558DE47819B6A6F00088B812 /* PalindromeTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558DE47719B6A6F00088B812 /* PalindromeTest.swift */; };
6461
558DE47A19B6B6EB0088B812 /* Stopwatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558DE47919B6B6EB0088B812 /* Stopwatch.swift */; };
@@ -116,7 +113,6 @@
116113
/* End PBXCopyFilesBuildPhase section */
117114

118115
/* Begin PBXFileReference section */
119-
291948DC1A54CFA500DB9AAF /* PrimeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrimeTests.swift; sourceTree = "<group>"; };
120116
291948DF1A54CFDA00DB9AAF /* String+EulerKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "String+EulerKit.swift"; path = "EulerKit/String+EulerKit.swift"; sourceTree = "<group>"; };
121117
291948E21A54D04F00DB9AAF /* Sequences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Sequences.swift; path = EulerKit/Sequences.swift; sourceTree = "<group>"; };
122118
291948E81A54D24100DB9AAF /* Int+EulerKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Int+EulerKit.swift"; sourceTree = "<group>"; };
@@ -132,7 +128,6 @@
132128
29B7CDF21A55E2D900BBDCB1 /* libssl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libssl.dylib; path = usr/lib/libssl.dylib; sourceTree = SDKROOT; };
133129
29B7CDF71A579F2E00BBDCB1 /* Problem28.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem28.swift; sourceTree = "<group>"; };
134130
29D1B4541A47A91F0002B363 /* BigNum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BigNum.swift; path = EulerKit/BigNum.swift; sourceTree = "<group>"; };
135-
29D1B4561A47AA200002B363 /* BigNumTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BigNumTests.swift; sourceTree = "<group>"; };
136131
29E2E5031A599D7700124A29 /* Problem29.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem29.swift; sourceTree = "<group>"; };
137132
29E2E5061A59BB9B00124A29 /* Problem30.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem30.swift; sourceTree = "<group>"; };
138133
5073322D203495D289EB5811 /* Pods-eulerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-eulerTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-eulerTests/Pods-eulerTests.debug.xcconfig"; sourceTree = "<group>"; };
@@ -151,7 +146,6 @@
151146
558DE42919B687CF0088B812 /* Euler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Euler.swift; sourceTree = "<group>"; };
152147
558DE45E19B6A3CB0088B812 /* eulerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = eulerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
153148
558DE46119B6A3CB0088B812 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
154-
558DE46219B6A3CB0088B812 /* EulerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EulerTests.swift; sourceTree = "<group>"; };
155149
558DE47719B6A6F00088B812 /* PalindromeTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PalindromeTest.swift; sourceTree = "<group>"; };
156150
558DE47919B6B6EB0088B812 /* Stopwatch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Stopwatch.swift; sourceTree = "<group>"; };
157151
55AEC16919C22A5300402275 /* Problem17Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem17Tests.swift; sourceTree = "<group>"; };
@@ -172,7 +166,6 @@
172166
55B8949D19C016F400A7E598 /* Problem15.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem15.swift; sourceTree = "<group>"; };
173167
55B8949E19C016F400A7E598 /* Problem16.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem16.swift; sourceTree = "<group>"; };
174168
55B894BF19C0174A00A7E598 /* Problem16Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem16Tests.swift; sourceTree = "<group>"; };
175-
55B894C119C01F9400A7E598 /* euclidPlayground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = euclidPlayground.playground; sourceTree = "<group>"; };
176169
55B894C219C0285400A7E598 /* Problem15Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem15Tests.swift; sourceTree = "<group>"; };
177170
55BD79B01A42882700B293C1 /* PrimeFactorsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrimeFactorsTest.swift; sourceTree = "<group>"; };
178171
55C643DD19CCB522000FD9E1 /* Problem25.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Problem25.swift; sourceTree = "<group>"; };
@@ -229,7 +222,6 @@
229222
552558BD19AEB953004B958F = {
230223
isa = PBXGroup;
231224
children = (
232-
55B894C119C01F9400A7E598 /* euclidPlayground.playground */,
233225
552558C819AEB953004B958F /* euler */,
234226
558DE45F19B6A3CB0088B812 /* eulerTests */,
235227
552558C719AEB953004B958F /* Products */,
@@ -272,9 +264,6 @@
272264
558DE45F19B6A3CB0088B812 /* eulerTests */ = {
273265
isa = PBXGroup;
274266
children = (
275-
29D1B4561A47AA200002B363 /* BigNumTests.swift */,
276-
558DE46219B6A3CB0088B812 /* EulerTests.swift */,
277-
291948DC1A54CFA500DB9AAF /* PrimeTests.swift */,
278267
55BD79B01A42882700B293C1 /* PrimeFactorsTest.swift */,
279268
558DE47719B6A6F00088B812 /* PalindromeTest.swift */,
280269
55B894C219C0285400A7E598 /* Problem15Tests.swift */,
@@ -597,7 +586,6 @@
597586
293741C11A57A85000CDF2DF /* Problem27.swift in Sources */,
598587
55B894B719C0173700A7E598 /* Problem9.swift in Sources */,
599588
558C9EFA19C1460700D8E04D /* Problem17.swift in Sources */,
600-
558DE46319B6A3CB0088B812 /* EulerTests.swift in Sources */,
601589
55B894C019C0174A00A7E598 /* Problem16Tests.swift in Sources */,
602590
291948F01A54DD2B00DB9AAF /* StringNum.swift in Sources */,
603591
299FD61D1ABE100B009804D7 /* JKBigNum.swift in Sources */,
@@ -617,14 +605,12 @@
617605
558DE46919B6A4050088B812 /* Euler.swift in Sources */,
618606
29B7CDF91A579F2E00BBDCB1 /* Problem28.swift in Sources */,
619607
55B894BD19C0173700A7E598 /* Problem15.swift in Sources */,
620-
291948DD1A54CFA500DB9AAF /* PrimeTests.swift in Sources */,
621608
55B894B219C0173700A7E598 /* Problem4.swift in Sources */,
622609
55B894B919C0173700A7E598 /* Problem11.swift in Sources */,
623610
291948EA1A54D24100DB9AAF /* Int+EulerKit.swift in Sources */,
624611
299FD6201ABE102B009804D7 /* Problem25.swift in Sources */,
625612
29E2E5081A59BB9B00124A29 /* Problem30.swift in Sources */,
626613
299FD61F1ABE1027009804D7 /* Problem24.swift in Sources */,
627-
29D1B4571A47AA200002B363 /* BigNumTests.swift in Sources */,
628614
291948E11A54CFE200DB9AAF /* String+EulerKit.swift in Sources */,
629615
55B894BE19C0173700A7E598 /* Problem16.swift in Sources */,
630616
299FD61C1ABE1005009804D7 /* BigNum.swift in Sources */,

Diff for: euler/EulerKit/BigNum.swift

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// BigNum.swift
3-
// euler
4-
//
5-
// Created by David Grandinetti on 12/21/14.
6-
// Copyright (c) 2014 David Grandinetti. All rights reserved.
7-
//
8-
91
enum BigNumSign {
102
case Negative
113
case Positive
@@ -64,13 +56,13 @@ struct BigNum : CustomDebugStringConvertible {
6456
}
6557

6658
func + (lhs: BigNum, rhs: BigNum) -> BigNum {
67-
return lhs
59+
return lhs // TODO: implement this
6860
}
6961

7062
func * (lhs: BigNum, rhs: Int) -> BigNum {
71-
return lhs
63+
return lhs // TODO: implement this
7264
}
7365

7466
func * (lhs: BigNum, rhs: BigNum) -> BigNum {
75-
return lhs
67+
return lhs // TODO: implement this
7668
}

Diff for: euler/EulerKit/Sequences.swift

+18-18
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,23 @@ extension SequenceType {
116116
}
117117

118118
struct MappingSequence<S: SequenceType, U, T where T == S.Generator.Element>: SequenceType {
119-
let sequence: S
120-
let map: (T) -> U
121-
122-
init(sequence:S, map: (T) -> U) {
123-
self.sequence = sequence
124-
self.map = map
125-
}
126-
127-
func generate() -> AnyGenerator<U> {
128-
var generator = self.sequence.generate()
129-
130-
return anyGenerator {
131-
let next = generator.next()
132-
if next != nil {
133-
return self.map(next!)
134-
}
135-
return .None
119+
let sequence: S
120+
let map: (T) -> U
121+
122+
init(sequence:S, map: (T) -> U) {
123+
self.sequence = sequence
124+
self.map = map
125+
}
126+
127+
func generate() -> AnyGenerator<U> {
128+
var generator = self.sequence.generate()
129+
130+
return anyGenerator {
131+
let next = generator.next()
132+
if next != nil {
133+
return self.map(next!)
134+
}
135+
return .None
136+
}
136137
}
137-
}
138138
}

Diff for: euler/Int+EulerKit.swift

+5-11
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ extension Int {
1313

1414
func isMultipleOfAny(nums:[Int]) -> Bool {
1515
return nums.map(isMultipleOf).reduce(false) {$0 || $1}
16-
// for i in nums {
17-
// if self.isMultipleOf(i) {
18-
// return true
19-
// }
20-
// }
21-
// return false
2216
}
2317

2418
func isDivisibleUpTo(max:Int) -> Bool {
@@ -130,25 +124,25 @@ extension Int {
130124
}
131125
return true
132126
}
133-
127+
134128
func getDigits() -> [Int] {
135129
// if the number is less than 10, just return it in an array
136130
if self < 10 {
137131
return [ self ]
138132
}
139-
133+
140134
var digits = [Int]()
141135
var tmpSelf = Int(self)
142-
136+
143137
while tmpSelf > 9 {
144138
digits.append(tmpSelf % 10)
145139
tmpSelf = tmpSelf / 10
146140
}
147141
digits.append(tmpSelf % 10)
148-
142+
149143
return Array(digits.reverse())
150144
}
151-
145+
152146
func isPandigtal(n:Int) -> Bool {
153147
let digits = self.getDigits()
154148
return Array(Set(digits)).count == n && !digits.contains(0)

Diff for: euler/JKBigNum.swift

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
//
2-
// JKBigNum.swift
3-
// euler
4-
//
5-
// Created by David Grandinetti on 12/31/14.
6-
// Copyright (c) 2014 David Grandinetti. All rights reserved.
7-
//
8-
91
import Foundation
102

113
func + (lhs:JKBigInteger, rhs:JKBigInteger) -> JKBigInteger {

Diff for: euler/Problems/Problem1.swift

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
class Problem1: EulerProblem {
2-
override func run() {
3-
//
4-
// If we list all the natural numbers below 10 that are multiples of
5-
// 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
6-
//
7-
// Find the sum of all the multiples of 3 or 5 below 1000.
8-
//
9-
10-
let sum = (1...999).filter({ $0.isMultipleOfAny([3,5]) }).reduce(0,combine: +)
1+
//
2+
// If we list all the natural numbers below 10 that are multiples of
3+
// 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
4+
//
5+
// Find the sum of all the multiples of 3 or 5 below 1000.
6+
//
117

12-
print("Sum = \(sum)")
13-
}
8+
class Problem1: EulerProblem {
9+
override func run() {
10+
let sum = (1...999).filter({ $0.isMultipleOfAny([3,5]) }).reduce(0,combine: +)
11+
print("Sum = \(sum)")
12+
}
1413
}

Diff for: euler/Problems/Problem22.swift

-8
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313
// What is the total of all the name scores in the file?
1414
//
1515

16-
//
17-
// Problem20.swift
18-
// euler
19-
//
20-
// Created by David Grandinetti on 9/14/14.
21-
// Copyright (c) 2014 David Grandinetti. All rights reserved.
22-
//
23-
2416
import Foundation
2517

2618
class Problem22: EulerProblem {

Diff for: euler/Problems/Problem3.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
let problem3num = 600851475143
1+
//
2+
// The prime factors of 13195 are 5, 7, 13 and 29.
3+
//
4+
// What is the largest prime factor of the number 600851475143 ?
5+
//
26

37
class Problem3: EulerProblem {
4-
5-
override func run() {
6-
//
7-
// The prime factors of 13195 are 5, 7, 13 and 29.
8-
//
9-
// What is the largest prime factor of the number 600851475143 ?
10-
//
11-
12-
let factors = problem3num.primeFactors()
13-
14-
print("Max prime factor of \(problem3num) is \(factors.last!)")
15-
}
8+
let problem3num = 600851475143
9+
10+
override func run() {
11+
12+
let factors = problem3num.primeFactors()
13+
14+
print("Max prime factor of \(problem3num) is \(factors.last!)")
15+
}
1616
}

Diff for: euler/Problems/Problem8.swift

+24-23
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,31 @@
66
// greatest product. What is the value of this product?
77
//
88

9-
let problem8num:String = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
10-
119
class Problem8: EulerProblem {
12-
override func run() {
13-
var digits:[Int] = []
14-
for digit in problem8num.characters {
15-
let str = String(digit)
16-
if let toInt = Int(str) {
17-
digits.append(toInt)
18-
}
19-
}
20-
21-
var maxProduct = 0
22-
for i in 0...(999-13) {
23-
var product = 1
24-
for j in 1...13 {
25-
product = product * digits[i+j]
26-
}
27-
if product > maxProduct {
28-
maxProduct = product
29-
}
10+
11+
let problem8num:String = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
12+
13+
override func run() {
14+
var digits:[Int] = []
15+
for digit in problem8num.characters {
16+
let str = String(digit)
17+
if let toInt = Int(str) {
18+
digits.append(toInt)
19+
}
20+
}
21+
22+
var maxProduct = 0
23+
for i in 0...(999-13) {
24+
var product = 1
25+
for j in 1...13 {
26+
product = product * digits[i+j]
27+
}
28+
if product > maxProduct {
29+
maxProduct = product
30+
}
31+
}
32+
33+
print("maxProduct = \(maxProduct)")
3034
}
31-
32-
print("maxProduct = \(maxProduct)")
33-
}
3435
}
3536

0 commit comments

Comments
 (0)