`
hotcharm
  • 浏览: 16555 次
  • 性别: Icon_minigender_1
  • 来自: 义乌
最近访客 更多访客>>
社区版块
存档分类
最新评论

用clojure解决 euler problem 2

 
阅读更多

问题描述:

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

解决方案:

(ns euler-problem-2.core)
(defn fibonacci-even-sum 
  [max-num]
  (loop
      [n1 1, n2 2, sum 0]
    (if (< n1  max-num)
       (if (even? n1)
         (recur n2 (+ n1 n2) (+ sum n1))
         (recur n2 (+ n1 n2)  sum) )
       sum )))
(fibonacci-even-sum 4000000)
"Elapsed time: 0.201702 msecs"

分享到:
评论

相关推荐

    欧拉公式求圆周率的matlab代码-euler:我对欧拉计画的解决方案(clojure)

    该存储库是使用Clojure解决Euler问题的支架。 它以有组织的结构生成规格和解决方案存根,从而使生活稍微好一些。 安装 如果尚未安装,则将其添加到您的路径中。 签出这个项目: $ git clone git@github....

    欧拉公式求圆周率的matlab代码-project-euler:Clojure解决Euler项目问题​​的方法

    Clojure骇客解决了Euler项目的问题。 目的是用惯用的Clojure编写功能解决方案。 用法 大多数解决方案都是完整的,并且完全独立地包含在具有“解决”功能的唯一名称空间中。 有些正在“进行中”。 执照 版权所有:...

    project-euler-clojure:我对Euler项目的Clojure解决方案

    欧拉计划 问题1-2、4、6、8-10、12、14、21、24-26、32、34、36、39、41、46、49、52、55-58、62、65的Clojure解决方案70-74、87、92、97、124、173-174、179、187、214运行解决方案使用以下命令行运行解决方案: ...

    Clojure电子书合集2(13本)

    [2013] Functional Programming Patterns in Scala and Clojure - Write Lean Programs for the JVM.(Michael Bevilacqua-Linn).[1937785475].pdf+epub.rar [2014] Clojure Cookbook - Recipes for Functional ...

    Programming Clojure 英文电子版

    Clojure's clean, careful design lets you write programs that get right to the essence of a problem, without a lot of clutter and ceremony. Clojure is Lisp reloaded. Clojure has the power inherent in...

    euler:Clojure中的Project Euler解决方案

    欧拉解决Clojure中的Euler项目问题​​的方法。 持续的爱好。执照版权所有:copyright:2012-2015 Dave Yarwood 在Eclipse Public License 1.0版下分发。

    clojure相关书籍2

    【2】clojure_programming.pdf 【3】Practical Clojure.pdf 【4】Programming Clojure with Emacs.pdf 【5】Programming Concurrency on the JVM(Java虚拟机并发编程)(英文版).pdf 【6】programming_clojure_2nd_...

    Clojure编程乐趣第2版(高清带书签).pdf

    这本书是关于编程语言Clojure的...具体而言,这本书是关于如何用Clojure的方式写Clojure代码。更确切的说,这本书是关于有经验的、成功的Clojure程序员是如何编写Clojure代码的,以及语言本身如何影响开发软件的方式。

    MiniZinc的Clojure接口库clojure2minizinc.zip

    clojure2minizinc 是一个通过 MiniZinc 解决约束满足问题的 Clojure 库。clojure2minizinc 提供一个 state-of-the-art constraint solvers (via MiniZinc) 和高级编程语言 Clojure 之间的接口。代码示例:(ns ...

    clojure-1.10.2-alpha2.jar

    Clojure还有一个特色是软件事务存储(Software Transactional Memory,STM),其支持用事务代替锁和互斥器来更新共享内存。STM还是一个有争议的技术,还需要更好的证明自己,一个简单的办法就是访问一个JVM上的实现...

    Professional.Clojure.1119267277

    CHAPTER 2 Rapid Feedback Cycles with Clojure CHAPTER 3 Web Services CHAPTER 4 Testing CHAPTER 5 Reactive Web Pages in ClojureScript CHAPTER 6 The Datomic Database CHAPTER 7 Performance

    有关JAVA的译文 Clojure:“挑战”Java编程语言

    在今后的软件设计中无论使用Clojure语言,还是坚持使用Java语言,Clojure语言都将与java做比较,哪种是设计软件的最佳方式。 Clojure语言是一个JVM(包括Groovy,Jython和JRuby等语言)的新语言,它提供了活力,...

    The Joy of Clojure, 2nd Edition

    The Joy of Clojure, Second Edition is a deep look at the Clojure language. Fully updated for Clojure 1.6, this new edition goes beyond just syntax to show you the "why" of Clojure and how to write ...

    Clojure编程乐趣

    Clojure is an opinionated language—it doesn’t try to cover all paradigms or provide every checklist bullet-point feature. Instead it provides the features needed to solve all kinds of real-world ...

    Programming Clojure 2nd pdf (第2版) 2012

    Programming Clojure 2nd pdf (第2版),最新2012年出版的,是学习clojure的必备资料。有clojure之父写序。

    Practical Clojure.pdf

    Practical Clojure Clojure语言书籍

    clojure eclipse

    clojure clojure clojureclojure clojure

    clojure相关书籍1

    【2】Clojure – Functional Programming for the JVM中文版.pdf 【3】Clojure Cookbook.pdf 【4】Clojure Data Analysis Cookbook.pdf 【5】clojure Hand book(中文).pdf 【6】Clojure in Action.pdf 【7】clojure ...

    Clojure可选类型系统TypedClojure.zip

    主要特性:从 Java 中保护你的 Clojure 程序,进行安全的互操作,正确的使用外部 Java 库。Typed Clojure 支持关键字映射的使用,类型检测器中包含有用的映射操作,包括关键字查找,添加或者移除关键字,合并映射...

Global site tag (gtag.js) - Google Analytics