DayByDay/Parent/ParentGate.swift
24 lines · 618 bytes
1//
2// ParentGate.swift
3// DayByDay
4//
5
6import Foundation
7
8/// A sum a 4–5 year old can't read or solve, asked before grown-up screens.
9nonisolated struct ParentGateChallenge: Equatable {
10 static let holdDuration: Double = 2
11
12 let a: Int
13 let b: Int
14
15 var answer: Int { a + b }
16
17 static func random(using rng: inout some RandomNumberGenerator) -> ParentGateChallenge {
18 ParentGateChallenge(a: Int.random(in: 6...9, using: &rng), b: Int.random(in: 6...9, using: &rng))
19 }
20
21 func accepts(_ input: String) -> Bool {
22 Int(input.trimmingCharacters(in: .whitespaces)) == answer
23 }
24}