Personal tools

Euler problems/21 to 30

From HaskellWiki

< Euler problems(Difference between revisions)
Jump to: navigation, search
m (EulerProblems/21 to 30 moved to Euler problems/21 to 30)
([http://projecteuler.net/index.php?section=problems&id=29 Problem 29]: a solution)
Line 75: Line 75:
  
 
== [http://projecteuler.net/index.php?section=problems&id=29 Problem 29] ==
 
== [http://projecteuler.net/index.php?section=problems&id=29 Problem 29] ==
How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
+
How many distinct terms are in the sequence generated by a<sup>b</sup> for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
  
 
Solution:
 
Solution:
 
<haskell>
 
<haskell>
problem_29 = undefined
+
problem_29 = length . group . sort $ [a^b | a <- [2..100], b <- [2..100]]
 
</haskell>
 
</haskell>
  

Revision as of 06:43, 30 March 2007

Contents

1 Problem 21

Evaluate the sum of all amicable pairs under 10000.

Solution:

problem_21 = undefined

2 Problem 22

What is the total of all the name scores in the file of first names?

Solution:

-- apply to a list of names
problem_22 :: [String] -> Int
problem_22 = sum . zipWith (*) [ 1 .. ] . map score
    where score = sum . map ( subtract 64 . ord )

3 Problem 23

Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

Solution:

problem_23 = undefined

4 Problem 24

What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

Solution:

perms [] = [[]]
perms xs = do
    x <- xs
    map ( x: ) ( perms . delete x $ xs )
 
problem_24 = ( perms "0123456789" ) !! 999999

5 Problem 25

What is the first term in the Fibonacci sequence to contain 1000 digits?

Solution:

valid ( i, n ) = length ( show n ) == 1000
 
problem_25 = fst . head . filter valid . zip [ 1 .. ] $ fibs
    where fibs = 1 : 1 : 2 : zipWith (+) fibs ( tail fibs )

6 Problem 26

Find the value of d < 1000 for which 1/d contains the longest recurring cycle.

Solution:

problem_26 = undefined

7 Problem 27

Find a quadratic formula that produces the maximum number of primes for consecutive values of n.

Solution:

problem_27 = undefined

8 Problem 28

What is the sum of both diagonals in a 1001 by 1001 spiral?

Solution:

problem_28 = undefined

9 Problem 29

How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?

Solution:

problem_29 = length . group . sort $ [a^b | a <- [2..100], b <- [2..100]]

10 Problem 30

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

Solution:

problem_30 = undefined