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

用clojure解决 euler problem 4

 
阅读更多

问题描述:

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is

9009 = 91×99.

Find the largest palindrome made from the product of two 3-digit numbers.

解决方案:

(ns euler-problem-4.core
  (:use clojure.contrib.math))

(defn palindromic-number?
  [number]
  (loop
      [number-string (str number)]
    (if (or (empty? number-string) (= (count number-string) 1))
      true
      (if(= (first number-string) (last number-string))
        (recur (drop-last (rest number-string)))
        false))))

(defn largest-palindromic-3-digit
  []
  (loop
      [a 100, b 100, lpn 1]
    (if (and (= 999 a) (= 999 b))
     (if (palindromic-number? (* a b))
          (max (* a b) lpn)
           lpn)    
      (if (= a 999)
        (if (palindromic-number? (* a b))
          (recur 100 (inc b) (max (* a b) lpn))
          (recur 100 (inc b) lpn))
        (if (palindromic-number? (* a b))
          (recur (inc a) b (max (* a b) lpn))
          (recur (inc a) b lpn))))))

(largest-palindromic-3-digit)
答案:906609


分享到:
评论

相关推荐

    欧拉公式求圆周率的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运行解决方案使用以下命令行运行解决方案: ...

    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版下分发。

    Professional.Clojure.1119267277

    Clear, practical Clojure for the professional programmer Professional Clojure is the experienced developer's guide to functional programming using the Clojure language. Designed specifically to meet ...

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

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

    4clojure-solutions:我对 4clojure 问题的解决方案

    4clojure解决方案对问题的解决方案。 不是最惯用的 Clojure 代码,但到底是什么 - 它有效! :grinning_face:小费不要复制/粘贴解决方案,而是在理解所遵循的方法后尝试自己编写。 使用这些解决方案来找出算法而不是...

    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 ...

    4clojure:我在 4clojure.com 上的解决方案

    4clojure 我在 4clojure.com 上的解决方案

    Practical Clojure.pdf

    Practical Clojure Clojure语言书籍

    clojure相关书籍1

    【1】[Clojure编程乐趣](The Joy of Clojure).pdf ...【4】Clojure Data Analysis Cookbook.pdf 【5】clojure Hand book(中文).pdf 【6】Clojure in Action.pdf 【7】clojure in small pieces.pdf 以上7本书的电子版

    clojure eclipse

    clojure clojure clojureclojure clojure

    Clojure可选类型系统TypedClojure.zip

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

    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 ...

    Clojure编程乐趣]+clojure_programming.pdf

    Clojure编程乐趣和clojure_programming.pdf两本书

    tools.analyzer, 用于Clojure代码的分析器,用Clojure编写,并在EDN中生成 AST.zip

    tools.analyzer, 用于Clojure代码的分析器,用Clojure编写,并在EDN中生成 AST tools.analyzer主机无关Clojure代码的分析器,用Clojure编写,并在EDN中生成 AST 。我在 2015年12月的ClojureX上讨论了 tools.analyzer...

    clojure相关书籍2

    【4】Programming Clojure with Emacs.pdf 【5】Programming Concurrency on the JVM(Java虚拟机并发编程)(英文版).pdf 【6】programming_clojure_2nd_edition.pdf 【7】Storm实时数据处理.pdf 【8】The Joy of ...

    Mastering.Clojure.1785

    Chapter 4. Metaprogramming with Macros Chapter 5. Composing Transducers Chapter 6. Exploring Category Theory Chapter 7. Programming with Logic Chapter 8. Leveraging Asynchronous Tasks Chapter 9. ...

Global site tag (gtag.js) - Google Analytics