krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

DayByDay/Parent/ParentGate.swift

main
daybyday/DayByDay/Parent/ParentGate.swift history · blame · raw

24 lines · 618 bytes

2 symbols in this file
 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}