Created
May 13, 2010 15:10
-
-
Save spariev/399923 to your computer and use it in GitHub Desktop.
This file contains 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
(declare occurs-memo) | |
(defn occurs-naive | |
[pattern ss] | |
(cond | |
(= 0 (count pattern)) 1 | |
(= 0 (count ss)) 0 | |
true (if (= (first pattern) (first ss)) | |
(+ (occurs-memo (rest pattern) (rest ss)) | |
(occurs-memo pattern (rest ss))) | |
(recur pattern (rest ss))))) | |
(def occurs-memo | |
(memoize occurs-naive)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment