Skip to content

Commit

Permalink
[feat] add normal and hard data
Browse files Browse the repository at this point in the history
  • Loading branch information
mrs1669 committed May 15, 2024
1 parent ded2c9e commit f1a1791
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions PrimePickApp/QuizData/PrimeData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,32 @@ final class PrimeData {
return twoDigitPrimes
}

public func generateThreeDigitPrimes() -> [Int] {
var twoDigitPrimes = [Int]()
outerLoop: for num in 100..<1000 {
for i in 2..<num {
if num % i == 0 {
continue outerLoop
}
}
twoDigitPrimes.append(num)
}
return twoDigitPrimes
}

public func generateFourDigitPrimes() -> [Int] {
var twoDigitPrimes = [Int]()
outerLoop: for num in 1000..<10000 {
for i in 2..<num {
if num % i == 0 {
continue outerLoop
}
}
twoDigitPrimes.append(num)
}
return twoDigitPrimes
}

public func generateThreeOrFourDigitPrimes() -> [Int] {
var twoDigitPrimes = [Int]()
outerLoop: for num in 100..<10000 {
Expand Down
10 changes: 9 additions & 1 deletion PrimePickApp/QuizView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ struct QuizView: View {

init(difficulty: String) {
self.difficulty = difficulty
primes = primeData.generateOneOrTwoDigitPrimes()
if self.difficulty == "Easy" {
primes = primeData.generateOneOrTwoDigitPrimes()
} else if self.difficulty == "Normal" {
primes = primeData.generateThreeDigitPrimes()
} else if self.difficulty == "Hard" {
primes = primeData.generateFourDigitPrimes()
} else {
primes = []
}
}

var body: some View {
Expand Down

0 comments on commit f1a1791

Please sign in to comment.