Personal tools

Euler problems/51 to 60

From HaskellWiki

< Euler problems(Difference between revisions)
Jump to: navigation, search
m
m (Corrected the links to the Euler project)
Line 1: Line 1:
 
[[Category:Programming exercise spoilers]]
 
[[Category:Programming exercise spoilers]]
== [http://projecteuler.net/index.php?section=problems&id=51 Problem 51] ==
+
== [http://projecteuler.net/index.php?section=view&id=51 Problem 51] ==
 
Find the smallest prime which, by changing the same part of the number, can form eight different primes.
 
Find the smallest prime which, by changing the same part of the number, can form eight different primes.
   
Line 8: Line 8:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=52 Problem 52] ==
+
== [http://projecteuler.net/index.php?section=view&id=52 Problem 52] ==
 
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order.
 
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order.
   
Line 21: Line 21:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=53 Problem 53] ==
+
== [http://projecteuler.net/index.php?section=view&id=53 Problem 53] ==
 
How many values of C(n,r), for 1 ≤ n ≤ 100, exceed one-million?
 
How many values of C(n,r), for 1 ≤ n ≤ 100, exceed one-million?
   
Line 32: Line 32:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=54 Problem 54] ==
+
== [http://projecteuler.net/index.php?section=view&id=54 Problem 54] ==
 
How many hands did player one win in the game of poker?
 
How many hands did player one win in the game of poker?
   
Line 40: Line 40:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=55 Problem 55] ==
+
== [http://projecteuler.net/index.php?section=view&id=55 Problem 55] ==
 
How many Lychrel numbers are there below ten-thousand?
 
How many Lychrel numbers are there below ten-thousand?
   
Line 52: Line 52:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=56 Problem 56] ==
+
== [http://projecteuler.net/index.php?section=view&id=56 Problem 56] ==
 
Considering natural numbers of the form, a<sup>b</sup>, finding the maximum digital sum.
 
Considering natural numbers of the form, a<sup>b</sup>, finding the maximum digital sum.
   
Line 62: Line 62:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=57 Problem 57] ==
+
== [http://projecteuler.net/index.php?section=view&id=57 Problem 57] ==
 
Investigate the expansion of the continued fraction for the square root of two.
 
Investigate the expansion of the continued fraction for the square root of two.
   
Line 74: Line 74:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=58 Problem 58] ==
+
== [http://projecteuler.net/index.php?section=view&id=58 Problem 58] ==
 
Investigate the number of primes that lie on the diagonals of the spiral grid.
 
Investigate the number of primes that lie on the diagonals of the spiral grid.
   
Line 82: Line 82:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=59 Problem 59] ==
+
== [http://projecteuler.net/index.php?section=view&id=59 Problem 59] ==
 
Using a brute force attack, can you decrypt the cipher using XOR encryption?
 
Using a brute force attack, can you decrypt the cipher using XOR encryption?
   
Line 90: Line 90:
 
</haskell>
 
</haskell>
   
== [http://projecteuler.net/index.php?section=problems&id=60 Problem 60] ==
+
== [http://projecteuler.net/index.php?section=view&id=60 Problem 60] ==
 
Find a set of five primes for which any two primes concatenate to produce another prime.
 
Find a set of five primes for which any two primes concatenate to produce another prime.
   

Revision as of 13:51, 20 July 2007

Contents

1 Problem 51

Find the smallest prime which, by changing the same part of the number, can form eight different primes.

Solution:

problem_51 = undefined

2 Problem 52

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits in some order.

Solution:

problem_52 = head [n | n <- [1..],
                   digits (2*n) == digits (3*n),
                   digits (3*n) == digits (4*n),
                   digits (4*n) == digits (5*n),
                   digits (5*n) == digits (6*n)]
    where digits = sort . show

3 Problem 53

How many values of C(n,r), for 1 ≤ n ≤ 100, exceed one-million?

Solution:

problem_53 = length [n | n <- [1..100], r <- [1..n], n `choose` r > 10^6]
    where n `choose` r
           | r > n || r < 0 = 0
           | otherwise      = foldl (\z j -> z*(n-j+1) `div` j) n [2..r]

4 Problem 54

How many hands did player one win in the game of poker?

Solution:

problem_54 = undefined

5 Problem 55

How many Lychrel numbers are there below ten-thousand?

Solution:

problem_55 = length $ filter isLychrel [1..9999]
    where isLychrel n = all notPalindrome (take 50 (tail (iterate revadd n)))
          notPalindrome s = (show s) /= reverse (show s)
          revadd n = n + rev n
              where rev n = read (reverse (show n))

6 Problem 56

Considering natural numbers of the form, ab, finding the maximum digital sum.

Solution:

problem_56 = maximum [dsum (a^b) | a <- [1..99], b <-[1..99]]
    where dsum 0 = 0
          dsum n = let ( d, m ) = n `divMod` 10 in m + ( dsum d )

7 Problem 57

Investigate the expansion of the continued fraction for the square root of two.

Solution:

problem_57 = length $ filter topHeavy $ take 1000 convergents 
    where topHeavy r = numDigits (numerator r) > numDigits (denominator r)
          numDigits = length . show
          convergents = iterate next (3%2)
          next r = 1 + 1/(1+r)

8 Problem 58

Investigate the number of primes that lie on the diagonals of the spiral grid.

Solution:

problem_58 = undefined

9 Problem 59

Using a brute force attack, can you decrypt the cipher using XOR encryption?

Solution:

problem_59 = undefined

10 Problem 60

Find a set of five primes for which any two primes concatenate to produce another prime.

Solution:

problem_60 = undefined