Created
June 2, 2013 18:06
-
-
Save lynaghk/5694320 to your computer and use it in GitHub Desktop.
Puzzle agent + core.logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn sublisto | |
"The sequence x appears in y." | |
[x y] | |
(fresh [a b c] | |
(appendo a x b) | |
(appendo b c y))) | |
(->> (run* [q] | |
(sublisto [:b :r :r :c] q) | |
(sublisto [:r :c :c :b] q) | |
(sublisto [:c :r :c :c] q) | |
(sublisto [:r :c :c :r] q) | |
(sublisto [:c :r :c :r :c] q) | |
;;(pred q #(< (count %) 16)) | |
;;(everyg #(membero % [:b :r :c]) q) | |
) | |
(take 4) | |
pprint) | |
;;I need to get: | |
;;[b r r c c r c r c r c c b] |
This is strange:
(defne prefixo [x y]
([() _])
([[h . xt] [h . yt]]
(prefixo xt yt)))
(defne sublisto [x y]
([() _])
([[h . xt] [h . yt]]
(prefixo xt yt))
([[h . _] [i . yt]]
(!= h i)
(sublisto x yt)))
(run* [q]
(prefixo [:b :r :r :c] q)
(sublisto [:b :r :r :c] q)
(sublisto [:r :c :c :b] q))
;;=> ()
This works
(defne gen-listo [l]
([()])
([[h . t]]
(gen-listo t)))
(defne prefixo [x y]
([() ()])
([() [h . t]])
([[xh . xt] [xh . yt]]
(prefixo xt yt)))
(defne sublisto [x y]
([[xh . xt] [xh . yt]]
(prefixo xt yt))
([_ [_ . yt]]
(sublisto x yt)))
(comment
(run 1 [q]
(gen-listo q)
(sublisto [:b :r :r :c] q)
(sublisto [:r :c :c :b] q)
(sublisto [:c :r :c :c] q)
(sublisto [:r :c :c :r] q)
(sublisto [:c :r :c :r :c] q))
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is closer to what you want: