@@ -45,12 +45,6 @@ struct Formula {
45 return startingLeft
45 return startingLeft
47 var ns = s.trimmingCharacters(in: .whitespaces)
47 var ns = s.trimmingCharacters(in: .whitespaces)
49− return .constant(false)
52− return .constant(true)
54 if ns.trimmingCharacters(in: .whitespaces).reduce(true, {$0 && CharacterSet.letters.contains($1.unicodeScalars.first!)}) {
48 if ns.trimmingCharacters(in: .whitespaces).reduce(true, {$0 && CharacterSet.letters.contains($1.unicodeScalars.first!)}) {
55 vars.insert(String(s))
49 vars.insert(String(s))
56 return .variable(String(s))
50 return .variable(String(s))
@@ -65,16 +59,6 @@ struct Formula {
65 print("Internal error: weird variable name first charecter \(ns.first!)")
59 print("Internal error: weird variable name first charecter \(ns.first!)")
70− ns = ns.dropFirst().trimmingCharacters(in: .whitespaces)
73− ns = ns.dropFirst().trimmingCharacters(in: .whitespaces)
78 var i = ns.startIndex
62 var i = ns.startIndex
79 while i < ns.endIndex {
63 while i < ns.endIndex {
80 if !CharacterSet.letters.contains(ns[i].unicodeScalars.first!) {
64 if !CharacterSet.letters.contains(ns[i].unicodeScalars.first!) {
@@ -139,7 +123,6 @@ private func extractBrackets(from s: String) -> (wasInside: Substring, after: Su
139private typealias Variable = String
123private typealias Variable = String
140private indirect enum FormulaElement {
124private indirect enum FormulaElement {
141 case variable(Variable)
125 case variable(Variable)
143 case operation(FormulaElement, Operator, FormulaElement)
126 case operation(FormulaElement, Operator, FormulaElement)
144 func evaluate(with variables: [Variable: Bool]) -> Bool {
127 func evaluate(with variables: [Variable: Bool]) -> Bool {
145 switch self {
128 switch self {
@@ -152,8 +135,6 @@ private indirect enum FormulaElement {
153 case .operation(let l, let op, let r):
136 case .operation(let l, let op, let r):
154 return op.value(l.evaluate(with: variables), r.evaluate(with: variables))
137 return op.value(l.evaluate(with: variables), r.evaluate(with: variables))
155− case .constant(let b):