Posts Tagged ‘scheme’

Euler Problem 1

Monday, November 3rd, 2008

I’ve decided to do a series of posts with my solutions to the Euler problems. They’ll be tagged with “euler”, and once I figure out how I’ll stop them from showing up on the main page.

This is the first Euler Problem
  1. (define sum
  2.   (lambda (x) (apply + x)))
  3. (define product
  4.   (lambda x (apply * x)))
  5. (define sum-1-to-n
  6.   (lambda (x) (* (/ 1 2) x (+ x 1))))
  7. (define (1+ x) (+ x 1))
  8. (define (-1+ x) (- x 1))
  9.  
  10. (let
  11.     ((smalllist '(3 5 6 9 10 12 15))
  12.      (num15s (quotient 1000 15)))
  13.   "(* num15s 15) -> 990, so we add the last few by hand"
  14.   (+ (* 15
  15.         (length smalllist)
  16.         (sum-1-to-n (-1+ num15s)))
  17.      (* num15s (sum smalllist))
  18.      993 995 996 999))