Skip to content

Commit

Permalink
Merge pull request #43 from shilokuma-inc/feat/data_normal_hard
Browse files Browse the repository at this point in the history
【FEAT】Normal用とHard用のデータもリスト表示
  • Loading branch information
mrs1669 committed May 15, 2024
2 parents 8b981d5 + f1a1791 commit b35df20
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
10 changes: 3 additions & 7 deletions PrimePickApp/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ struct MainView: View {
.font(.headline)
.padding()

Button(action: {
// Hardボタンのアクション
}) {
NavigationLink(destination: QuizView(difficulty: "Hard")) {
Text("Hard")
.padding()
.frame(maxWidth: .infinity)
Expand All @@ -36,9 +34,7 @@ struct MainView: View {
.padding(.horizontal, 50)
.padding(.bottom, 10)

Button(action: {
// Normalボタンのアクション
}) {
NavigationLink(destination: QuizView(difficulty: "Normal")) {
Text("Normal")
.padding()
.frame(maxWidth: .infinity)
Expand All @@ -49,7 +45,7 @@ struct MainView: View {
.padding(.horizontal, 50)
.padding(.bottom, 10)

NavigationLink(destination: QuizView()) {
NavigationLink(destination: QuizView(difficulty: "Easy")) {
Text("Easy")
.padding()
.frame(maxWidth: .infinity)
Expand Down
52 changes: 52 additions & 0 deletions PrimePickApp/QuizData/PrimeData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,56 @@ 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 {
for i in 2..<num {
if num % i == 0 {
continue outerLoop
}
}
twoDigitPrimes.append(num)
}
return twoDigitPrimes
}

public func generateFiveOrSixDigitPrimes() -> [Int] {
var twoDigitPrimes = [Int]()
outerLoop: for num in 10000..<1000000 {
for i in 2..<num {
if num % i == 0 {
continue outerLoop
}
}
twoDigitPrimes.append(num)
}
return twoDigitPrimes
}
}
17 changes: 14 additions & 3 deletions PrimePickApp/QuizView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import SwiftUI
struct QuizView: View {
let primeData = PrimeData()
var primes: [Int]
init() {
primes = primeData.generateOneOrTwoDigitPrimes()
let difficulty: String

init(difficulty: String) {
self.difficulty = difficulty
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 All @@ -23,5 +34,5 @@ struct QuizView: View {
}

#Preview {
QuizView()
QuizView(difficulty: "Easy")
}

0 comments on commit b35df20

Please sign in to comment.