以下代码将实现您想要的功能
(defn get-pins [observed]
(let [num (count observed)
keypad {\1 [1 2 4] \2 [2 1 5 3] \3 [3 2 6]
\4 [4 1 5 7] \5 [5 2 6 8 4] \6 [6 3 5 9]
\7 [7 4 8] \8 [8 5 9 0 7] \9 [9 6 8] \0 [0 8]}
observed-map (zipmap [:a :b :c :d] (map keypad observed))]
(for [a (:a observed-map)
b (or (:b observed-map) [nil])
c (or (:c observed-map) [nil])
d (or (:d observed-map) [nil])]
(str a b c d))))
[nil]
值将产生一个只有一个“迭代”(值为nil
)的迭代,当对它调用str
时将产生一个空字符串。