I’m currently processing all my blog posts — cleaning things here and there. And so I was thinking that a lot of code snippets I post on this blog could be rendered as Gist, as Hugo offers a nice shortcode for that specific purpose. So here we go:
#lang racket | |
;; Euler problem 15 | |
(define (reduce f xs) | |
(and (not (empty? xs)) (foldl f (first xs) (rest xs)))) | |
(define (f n) | |
(reduce (lambda (x y) (* x y)) (range 1 (add1 n)))) | |
(define (sol-015 [n 20]) | |
(ceiling (/ (f (* n 2)) (f n) (f n)))) |
Compare to the original version.