Skip to content

Instantly share code, notes, and snippets.

@onemouth
Created January 12, 2016 00:04
Show Gist options
  • Select an option

  • Save onemouth/f34e7714176854904ef9 to your computer and use it in GitHub Desktop.

Select an option

Save onemouth/f34e7714176854904ef9 to your computer and use it in GitHub Desktop.
(defn veckey-to-set [veckey]
(reduce (fn [[column set-key] k]
(if (contains? set-key k)
[column set-key]
[(conj column k) (conj set-key k)]))
[[] #{}]
veckey))
(defn handle-rest-char [set-key]
(let [char-seq (map char (range (int \A) (inc (int \Z))))]
(reduce #(if (contains? set-key %2) %1 (conj %1 %2)) [] char-seq)))
(defn take-every-n [start n coll]
(let [length (dec (count coll))]
(loop [idx start
result []
]
(cond
(<= idx length) (recur (+ idx n) (conj result (get coll idx)))
:else result))))
(defn trasform-key [key]
(let [vec-key (into [] key)
[first-column set-key] (veckey-to-set vec-key)
rest-chars (handle-rest-char set-key)
sorted-key (sort-by second (map-indexed vector first-column))
]
;[first-column set-key rest-chars sorted-key]
(take-every-n 0 5 rest-chars)
)
)
(trasform-key "SECRET")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment