ITeye博客

2012 年文章归档

共 12 篇文章

用clojure解决euler problem 12

问题描述: The sequence of triangle numbers is generated by adding the natural numbers. So the 7thtriangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1 : 1 3 : 1,3 6 :…

2012-07-13 21:00

用clojure解决 euler problem 11

问题描述: In the 20 20 grid below, four numbers along a diagonal line have been marked in red. 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 52 70 95 23 04 60 11 42 69 2…

2012-07-12 10:16

用clojure解决euler problem 10

问题描述: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 解决方案: (ns euler-problem-10.core (:use [clojure.contrib.math])) (defn prime? [num] (every? #(or (> (rem num %) 0) (= num %)) (apply list (range 2 (inc (ceil (sqrt num))))))) ;(prime? 9) (def…

2012-07-09 21:01

用clojure解决euler problem 9

问题描述: A Pythagorean triplet is a set of three natural numbers, a b c , for which, a 2+ b 2= c 2 For example, 32+ 42= 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc . 解决方案: (ns euler-problem-9.core) (defn square [n] (* n n)) (defn pyth…

2012-07-08 22:25

用clojure解决euler problem 8

问题描述: Find the greatest product of five consecutive digits in the 1000-digit number. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 6689664895…

2012-07-08 21:06

用clojure解决euler problem 7

问题描述: By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? 解决方案: (ns euler-problem-7.core (:use [clojure.contrib.math])) (defn prime? [num] (every? #(> (rem num %) 0) (apply list (range 2 (inc (ceil (sqrt num))))))) …

2012-07-08 20:39

用clojure解决 euler problem 6

问题描述: The sum of the squares of the first ten natural numbers is, 12+ 22+ ... + 102= 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2= 552= 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 3…

2012-07-08 13:37

用clojure解决euler problem 5

问题描述: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that isevenly divisibleby all of the numbers from 1 to 20? 即求1到20的所有数的最小公倍数。 解决方案: (ns euler-problem-5.core (:use clojure.contrib.math)) (defn smalle…

2012-07-08 10:43

用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? […

2012-07-07 21:12

用clojure解决euler problem 3

问题描述: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? (ns euler-problem-3.core) (defn largest-prime-factor [number] (loop [current-num number,n 2,lpf 2] (if (>= lpf current-num) lpf (if (zero? (rem current-num n)) (recur (/ current-num n…

2012-07-06 20:47

用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 e…

2012-07-06 12:47

用clojure解决 euler problem 1

问题描述: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. 解决方案1: (defn sum-3-or-5-multiple-below [x] "If we list all the natural numbers below 10 that are multiples …

2012-07-05 22:10