Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Placate vifon
  • Loading branch information
zaeph committed Sep 22, 2021
1 parent b32f822 commit df82636
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 01/02.el
Expand Up @@ -65,6 +65,20 @@
do (throw 'difference nil)
finally return t))))

;; Do it with maps because vifon sucks
(defun ctci/check-permutation-with-maps (&rest strs)
(when (->> (mapcar #'length strs)
(cl-every #'=))
(let* ((sorted-strs (mapcar (lambda (str)
(seq-sort #'< str))
strs))
(str1 (pop sorted-strs)))
(catch 'difference
(not (while sorted-strs
(let ((str2 (pop sorted-strs)))
(unless (string= str1 str2)
(throw 'difference nil)))))))))

;;----------------------------------------------------------------------------
;; Alternatives
;;----------------------------------------------------------------------------
Expand Down Expand Up @@ -113,4 +127,5 @@
(ctci/check-permutation-deftest "reduce")
(ctci/check-permutation-deftest "non-modularised-signature")
(ctci/check-permutation-deftest "rest")
(ctci/check-permutation-deftest "with-maps")
(ctci/check-permutation-deftest)

0 comments on commit df82636

Please sign in to comment.