Skip to content

Instantly share code, notes, and snippets.

@xy4n
Last active October 16, 2015 18:59
Show Gist options
  • Save xy4n/1d8488d72945df92e00b to your computer and use it in GitHub Desktop.
Save xy4n/1d8488d72945df92e00b to your computer and use it in GitHub Desktop.
#lang racket
(define (count-divisors n [count 0] [start 1])
(cond
[(> start (sqrt n)) (* 2 count)]
[(= start (sqrt n)) (+ (* 2 count) 1)]
[(zero? (remainder n start)) (count-divisors n (+ count 1) (+ start 1))]
[else (count-divisors n count (+ start 1))]))
(define (triangle-number n)
(if (<= n 1)
n
(+ n (triangle-number (- n 1)))))
(define (euler12 [n 1])
(if (> (count-divisors (triangle-number n)) 500)
(triangle-number n)
(euler12 (+ n 1))))
(println (euler12))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment