4clojure 题解Fibonacci Sequence

作者: admin 日期: 2017-12-27 16:46:43 人气: - 评论: 0

返回指定长度的斐波那契数列

Write a function which returns the first X fibonacci numbers.

test not run
(= (__ 3) '(1 1 2))
test not run
(= (__ 6) '(1 1 2 3 5 8))
test not run
(= (__ 8) '(1 1 2 3 5 8 13 21))






还是递归

(fn d
([x] (d x '(1 1)))
([x y]
(let [rev (reverse y)
a (first rev)
b (second rev)
c (+ a b)
n (reverse (conj  (reverse y) c))
]
(if (> x 3)
(d (dec x) n)
n
)
)))


相关内容

发表评论
更多 网友评论0 条评论)
暂无评论

Copyright © 2012-2014 我的代码板 Inc. 保留所有权利。

页面耗时0.0243秒, 内存占用1.83 MB, 访问数据库13次

闽ICP备15009223号-1