learning lisp

master
Evan Hemsley 2016-10-18 23:02:57 -07:00
parent d496e33cc1
commit 57eb8dab59
2 changed files with 8 additions and 0 deletions

3
lisp/euler.lisp Normal file
View File

@ -0,0 +1,3 @@
(defun range (min max) (loop for n from min below max by 1 collect n))
(defun sum (list) (apply '+ list))
(defun select (expr list) (remove-if-not expr list))

5
lisp/euler001.lisp Normal file
View File

@ -0,0 +1,5 @@
(load "euler.lisp")
(defun is_multiple_of_3_or_5 (n) (or (eq 0 (mod n 3)) (eq 0 (mod n 5))))
(defun multiples_of_3_or_5 (n) (select #'is_multiple_of_3_or_5 (range 1 n)))
(defun result (n) (sum (multiples_of_3_or_5 n)))