Sha256: 1910ee577ff7561733c8b4ebc01a72342b8f1a3653a6224c6a4b7a43b195f0de

Contents?: true

Size: 1.18 KB

Versions: 396

Compression:

Stored size: 1.18 KB

Contents

;;; robot-name.el --- Robot Name (exercism)

;;; Commentary:
;;
;; Build a robot with a name like AA000, that can be reset
;; to a new name. Instructions are in README.md
;;

;;; Code:

(defun rand-alpha-char ()
  "Return a random alphabetic character as a string."
  (let* ((char-list (number-sequence ?A ?Z))
         (char-int (nth (random (length char-list)) char-list)))
    (string char-int)))

(defun rand-digit-char ()
  "Return a random digit [0-9] as a string."
  (int-to-string (random 10)))

(defun random-robot-name ()
  "Create a random robot name with 2 alpha chars and 3 digits."
  (concat (rand-alpha-char)
          (rand-alpha-char)
          (rand-digit-char)
          (rand-digit-char)
          (rand-digit-char)))

(defun build-robot ()
  "Build a new robot with a random name."
  (let ((new-robot (make-hash-table :test 'equal)))
    (puthash "name" (random-robot-name) new-robot)
    new-robot))

(build-robot)

(defun robot-name (robot)
  "Get the ROBOT's name."
  (gethash "name" robot))

(defun reset-robot (robot)
  "Reset the name of ROBOT.  Factory reset!"
  (setf robot (puthash "name" (random-robot-name) robot))
  robot)


(provide 'robot-name)
;;; robot-name.el ends here

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.179 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.178 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.177 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.176 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.175 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.174 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.173 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.172 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.171 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.170 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.169 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.167 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.166 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.165 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.164 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.163 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.162 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.161 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.160 tracks/elisp/exercises/robot-name/example.el