3 ms·
Yes. Another simple representation if you assume a maximum number of occurrences per letter: (defvar *alphabet* "abcdefghijklmnopqrstuvwxyz") (defconst
by bluefox 10y ago
Yes. Another simple representation if you assume a maximum number of occurrences per letter:
(defvar *alphabet* "abcdefghijklmnopqrstuvwxyz")
(defconstant capacity-in-bits 3)
(defun key (word)
(loop with key = 0
with max-occurrences = (1- (ash 1 capacity-in-bits))
for letter across *alphabet*
for i upfrom 0
for occurrences = (count letter word)
do (if (> occurrences max-occurrences)
(error "too many occurrences")
(setf (ldb (byte capacity-in-bits (* i capacity-in-bits)) key)
occurrences))
finally (return key)))