Roman numeral by Hawkseye

(setq h (make-hash-table :test #'equalp))(setf (gethash "I" h) 1)(setf (gethash "V" h) 5)(setf (gethash "X" h) 10)(setf (gethash "L" h) 50)(setf (gethash "C" h) 100)(setf (gethash "D" h) 500)(setf (gethash "M" h) 1000)(handler-case (loop (let ((r (read-line))(a 0) l (f 1))(dotimes (i (length r))(push (gethash (substring r i (+ i 1)) h) l))(dotimes (i (length l))(incf a (* f (car l)))(if (and (> (length l) 1)(> (car l)(cadr l)))(setq f -1)(setq f 1))(pop l))(format t "~d~%" a)))(end-of-file (c) c))

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page