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
Let’s first write a function to check the outputs. Since it’s quite simple, I’ll
use the example from the problem definition and a couple of corner cases:
(defnspy [x] (prn x) x)
(defnseqs-match? [a b]
;; we don't care about size because the input might be an infinite seq
(every? (partial apply =) (zipmap a b)))
(defncheck-fn [f]
(doseq [{:keys [testcase expected]} [{:testcase [3 [:a:b:c:d:e:f:g]], :expected [:a:b:d:e:g]}
{:testcase [3 [:a:b:c:d:e:f:g:h:i]], :expected [:a:b:d:e:g:h]}
{:testcase [3 [:a:b]], :expected [:a:b]}
{:testcase [3 (range)], :expected [01346791012]}
{:testcase [3 []], :expected []}]
:let [actual (apply f testcase)]]
(if (seqs-match? actual expected)
(println"Match!")
(do (println"Mismatch :(")
(println (str" Expected: " (pr-str expected)))
(println (str" Actual : " (pr-str actual)))))))
The simplest way I could think of was indexing the collection and filtering it:
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
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
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
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
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
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
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
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
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
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