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.119 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.118 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.117 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.116 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.115 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.114 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.113 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.111 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.110 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.109 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.108 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.107 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.106 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.105 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.104 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.103 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.102 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.101 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.100 tracks/elisp/exercises/robot-name/example.el
trackler-2.2.1.99 tracks/elisp/exercises/robot-name/example.el