|
@@ -1,19 +1,37 @@
|
|
|
|
+(ns automata.rules)
|
|
|
|
|
|
|
|
+(def rule-order [
|
|
|
|
+ [true true true]
|
|
|
|
+ [true true false]
|
|
|
|
+ [true false true]
|
|
|
|
+ [true false false]
|
|
|
|
+ [false true true]
|
|
|
|
+ [false true false]
|
|
|
|
+ [false false true]
|
|
|
|
+ [false false false]
|
|
|
|
+ ])
|
|
|
|
|
|
-(defn temp-rule [one two three] true)
|
|
|
|
|
|
+(def preset-rules {
|
|
|
|
+ :110 "01101110"
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+(def string-to-rule
|
|
|
|
+ (memoize (fn [binary-string]
|
|
|
|
+ (let [bools (map #(if (= % "1") true false) binary-string)
|
|
|
|
+ cases (zipmap rule-order bools)]
|
|
|
|
+ (fn [one two three] (cases [one two three]))))))
|
|
|
|
|
|
(defn proc
|
|
(defn proc
|
|
- ([line]
|
|
|
|
|
|
+ ([line rule]
|
|
(if (empty? line)
|
|
(if (empty? line)
|
|
[]
|
|
[]
|
|
- (proc false (first line) (second line) (drop 2 line) [])))
|
|
|
|
- ([one two three r acc]
|
|
|
|
- (let [rule temp-rule]
|
|
|
|
- (if (nil? two)
|
|
|
|
- (conj acc (rule false one false))
|
|
|
|
- (if (nil? three)
|
|
|
|
- (conj acc (rule one two false))
|
|
|
|
- (proc two three (first r) (rest r) (conj acc (rule one two three))))))))
|
|
|
|
|
|
+ (proc rule false (first line) (second line) (drop 2 line) [])))
|
|
|
|
+ ([rule one two three r acc]
|
|
|
|
+ (if (nil? two)
|
|
|
|
+ (conj acc (rule false one false))
|
|
|
|
+ (if (nil? three)
|
|
|
|
+ (conj acc (rule one two false))
|
|
|
|
+ (proc rule two three (first r) (rest r) (conj acc (rule one two three)))))))
|
|
|
|
|
|
|
|
|
|
|
|
|