on 62336b9 help sign in
4 files changed+8−28
since splitsnapshots
unifiedsplit
Truther.xcodeproj/project.pbxproj+1−1 Truther/Operator.swift+1−1 README.md → Truther/README.md+6−7 Truther/Truther.swift−19
Truther.xcodeproj/project.pbxproj+1−1
@@ -48,7 +48,6 @@
4848 097824ED1F87E21400064ADB = {
4949 isa = PBXGroup;
5050 children = (
51− 0915F8131F8907DB00D96279 /* README.md */,
5251 097824F81F87E21400064ADB /* Truther */,
5352 097824F71F87E21400064ADB /* Products */,
5453 );
@@ -67,6 +66,7 @@
6766 children = (
6867 097824F91F87E21400064ADB /* main.swift */,
6968 097825001F87E23000064ADB /* Truther.swift */,
69+ 0915F8131F8907DB00D96279 /* README.md */,
7070 091685E21F8834C800CC8645 /* Formatter.swift */,
7171 097825021F87E48500064ADB /* Operator.swift */,
7272 );
Truther/Operator.swift+1−1
@@ -44,7 +44,7 @@ enum Operator {
4444 case .f7:
4545 return {$0 || $1}
4646 case .f8:
47− return {!($0 || $1)}
47+ return {!($0 && $1)}
4848 case .f9:
4949 return {$0 == $1}
5050 case .f10:
README.md → Truther/README.mdrenamed+6−7
@@ -2,7 +2,6 @@
22
33Makes a truth table for the given boolean function
44
5−*All operators have equal precedence and are left-associative*
65
76## Usage
87
@@ -25,13 +24,13 @@ a | b | c | F
2524
2625## Available functions
2726
28−- `+` `or`
29−- `(+)` `xor` `/=`
30−- `*` `and` `&`
27+- `+`/`or`
28+- `(+)`/`xor`/`/=`
29+- `*`/`and`/`&`
3130- `=>`
3231- `=/>`
3332- `<=`
3433- `</=`
35−- `o` `nor`
36−- `=` `<=>`
37−- `|` `nand`
34+- `o`/`nor`
35+- `=`/`<=>`
36+- `|`/`nand`
Truther/Truther.swift−19
@@ -45,12 +45,6 @@ struct Formula {
4545 return startingLeft
4646 }
4747 var ns = s.trimmingCharacters(in: .whitespaces)
48− if ns == "0" {
49− return .constant(false)
50− }
51− if ns == "1" {
52− return .constant(true)
53− }
5448 if ns.trimmingCharacters(in: .whitespaces).reduce(true, {$0 && CharacterSet.letters.contains($1.unicodeScalars.first!)}) {
5549 vars.insert(String(s))
5650 return .variable(String(s))
@@ -65,16 +59,6 @@ struct Formula {
6559 print("Internal error: weird variable name first charecter \(ns.first!)")
6660 exit(1)
6761 }
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− }
7862 var i = ns.startIndex
7963 while i < ns.endIndex {
8064 if !CharacterSet.letters.contains(ns[i].unicodeScalars.first!) {
@@ -139,7 +123,6 @@ private func extractBrackets(from s: String) -> (wasInside: Substring, after: Su
139123private typealias Variable = String
140124private indirect enum FormulaElement {
141125 case variable(Variable)
142− case constant(Bool)
143126 case operation(FormulaElement, Operator, FormulaElement)
144127 func evaluate(with variables: [Variable: Bool]) -> Bool {
145128 switch self {
@@ -152,8 +135,6 @@ private indirect enum FormulaElement {
152135 }
153136 case .operation(let l, let op, let r):
154137 return op.value(l.evaluate(with: variables), r.evaluate(with: variables))
155− case .constant(let b):
156− return b
157138 }
158139 }
159140}