The Way 2 Inner Peace.

欧拉项目第12题.
丘奇数

欧拉项目第28题.

Qians posted @ 2012年11月15日 11:02 in scheme with tags projecteuler racket , 1518 阅读

https://projecteuler.net/problem=28

#lang racket

;give a n 
;output the outermost diagonal numbers of the n x n spiral form
(define (outermost n)
  (if (= n 1)
      (list 1)
      (build-list 4 (λ(x) 
                        (+ (* (sub1 n)(add1 x))
                           (sqr(- n 2)))))))

(define (build-diagonal n)
  (define (iter i r)
    (if (> i n)
        r
        (iter (+ 2 i)
              (append r (outermost i)))))
  (iter 1 '()))

(display (apply + (build-diagonal 1001)))

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter