Skip to content

Instantly share code, notes, and snippets.

@trendsetter37
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trendsetter37/5241d2740eab615ad5e0 to your computer and use it in GitHub Desktop.
Save trendsetter37/5241d2740eab615ad5e0 to your computer and use it in GitHub Desktop.
Game of Thrones Warmup I on hackerRanck
(defparameter *letter-hash* (make-hash-table :size 100000))
(defvar even-length)
(defvar number-of-odds 0)
(defun string-to-list (&key word)
"Will set the even/odd param as well"
(setq even-length (evenp (length word)))
(loop for letter across word collect letter))
(defun anagram (hashtable)
"Determine whether or not the string is
a palidrome"
(if even-length
(progn
(loop for value being the hash-values of hashtable do
(if (oddp value) (incf number-of-odds)))
(if (> number-of-odds 0) (format t "NO~%") (format t "YES~%")))
(progn
(loop for value being the hash-values of hashtable do
(if (oddp value) (incf number-of-odds)))
(if (= number-of-odds 1) (format t "YES~%") (format t "NO~%")))))
(defun hash-string (string-to-be-hashed);; comes in the form of a list
(loop for i in string-to-be-hashed do
(if (nth-value 1 (gethash i *letter-hash*))
(incf (gethash i *letter-hash*))
(setf (gethash i *letter-hash*) 1))))
;; This is here as a utility during dev work
(defun print-hash-entries (*hash*)
"This function is included in this to aid in
developement. It is not used during the normal
operation of the script on HackerRank
(print-hash-entries *hash-table*)
This will print all of the key value pairs in the
hash-table provided"
(loop for key being the hash-keys of *hash*
using (hash-value value)
do (format t "The value of key ~s is ~d~%" key value)))
(hash-string (string-to-list :word (read-line)))
(anagram *letter-hash*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment