on 4e2fd2c help sign in
Truther/Operator.swift+1−1
since splitsnapshots
unifiedsplit
@@ -44,7 +44,7 @@ enum Operator {
44 case .f7:
44 case .f7:
45 return {$0 || $1}
45 return {$0 || $1}
46 case .f8:
46 case .f8:
47− return {!($0 || $1)}
47+ return {!($0 && $1)}
48 case .f9:
48 case .f9:
49 return {$0 == $1}
49 return {$0 == $1}
50 case .f10:
50 case .f10:
Truther/Truther.swift−19
@@ -45,12 +45,6 @@ struct Formula {
45 return startingLeft
45 return startingLeft
46 }
46 }
47 var ns = s.trimmingCharacters(in: .whitespaces)
47 var ns = s.trimmingCharacters(in: .whitespaces)
48− if ns == "0" {
49− return .constant(false)
50− }
51− if ns == "1" {
52− return .constant(true)
53− }
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!)")
66 exit(1)
60 exit(1)
67 }
61 }
68− switch ns.first! {
69− case "0":
70− ns = ns.dropFirst().trimmingCharacters(in: .whitespaces)
71− return "0"
72− case "1":
73− ns = ns.dropFirst().trimmingCharacters(in: .whitespaces)
74− return "1"
75− default:
76− break
77− }
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)
142− case constant(Bool)
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 {
152 }
135 }
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):
156− return b
157 }
138 }
158 }
139 }
159}
140}