project-euler / project-euler / 17.lisp

(defun string-list-len (l)
  (apply #'+ (mapcar #'length l)))

(defun f-up-to-nine () 
  (list "one" "two" "three" "four" "five" "six" "seven" "eight" "nine"))

(defun f-ten-to-19 ()
  (list "ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen" 
        "sixteen" "seventeen" "eighteen" "nineteen"))

(defun f-tens ()
  (list "twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty" "ninety"))

(defun f-hundreds ()
  (mapcar (lambda (s) (concatenate 'string s "hundred")) (f-up-to-nine)))

(defun total ()
  (let ((up-to-nine (string-list-len (f-up-to-nine)))
        (ten-to-19 (string-list-len (f-ten-to-19)))
        (tens (string-list-len (f-tens)))
        (hundreds (string-list-len (f-hundreds)))
        )

    (+ (* up-to-nine 9 10) ; the digits of the non-teens
       (* ten-to-19 10) ; the digits of the teens
       (* tens 10 10) ; the digits of the tens 
       (* hundreds 100) ; the digits of the hundreds.
       (* (length "and") 99 9) ; the digits of the "and" of the hundreds"
       (length "onethousand")
       )))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.