Created
March 25, 2023 21:45
-
-
Save esshka/2b2556d9123366a239b2678806345941 to your computer and use it in GitHub Desktop.
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 is-merge [s part1 part2] | |
(let [s-len (count s) | |
p1-len (count part1) | |
p2-len (count part2)] | |
(if (> s-len (+ p1-len p2-len)) | |
false | |
(loop [s-idx 0 | |
p1-idx 0 | |
p2-idx 0] | |
(if (= s-idx s-len) | |
true | |
(if (and (< p1-idx p1-len) (= (nth s s-idx) (nth part1 p1-idx))) | |
(recur (inc s-idx) (inc p1-idx) p2-idx) | |
(if (and (< p2-idx p2-len) (= (nth s s-idx) (nth part2 p2-idx))) | |
(recur (inc s-idx) p1-idx (inc p2-idx)) | |
false))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment