Euler problems/111 to 120
From HaskellWiki
m (Corrected links to the Euler project) |
|||
| Line 21: | Line 21: | ||
Solution: | Solution: | ||
<haskell> | <haskell> | ||
| - | problem_113 = | + | import Array |
| + | |||
| + | mkArray b f = listArray b $ map f (range b) | ||
| + | |||
| + | digits = 100 | ||
| + | |||
| + | inc = mkArray ((1, 0), (digits, 9)) ninc | ||
| + | dec = mkArray ((1, 0), (digits, 9)) ndec | ||
| + | |||
| + | ninc (1, _) = 1 | ||
| + | ninc (l, d) = sum [inc ! (l-1, i) | i <- [d..9]] | ||
| + | |||
| + | ndec (1, _) = 1 | ||
| + | ndec (l, d) = sum [dec ! (l-1, i) | i <- [0..d]] | ||
| + | |||
| + | problem_113 = sum [inc ! i | i <- range ((digits, 0), (digits, 9))] | ||
| + | + sum [dec ! i | i <- range ((1, 1), (digits, 9))] | ||
| + | - digits*9 -- numbers like 11111 are counted in both inc and dec | ||
| + | - 1 -- 0 is included in the increasing numbers | ||
</haskell> | </haskell> | ||
| + | Note: inc and dec contain the same data, but it seems clearer to duplicate them. | ||
== [http://projecteuler.net/index.php?section=view&id=114 Problem 114] == | == [http://projecteuler.net/index.php?section=view&id=114 Problem 114] == | ||
Revision as of 22:22, 15 August 2007
Contents |
1 Problem 111
Search for 10-digit primes containing the maximum number of repeated digits.
Solution:
problem_111 = undefined
2 Problem 112
Investigating the density of "bouncy" numbers.
Solution:
problem_112 = undefined
3 Problem 113
How many numbers below a googol (10100) are not "bouncy"?
Solution:
import Array mkArray b f = listArray b $ map f (range b) digits = 100 inc = mkArray ((1, 0), (digits, 9)) ninc dec = mkArray ((1, 0), (digits, 9)) ndec ninc (1, _) = 1 ninc (l, d) = sum [inc ! (l-1, i) | i <- [d..9]] ndec (1, _) = 1 ndec (l, d) = sum [dec ! (l-1, i) | i <- [0..d]] problem_113 = sum [inc ! i | i <- range ((digits, 0), (digits, 9))] + sum [dec ! i | i <- range ((1, 1), (digits, 9))] - digits*9 -- numbers like 11111 are counted in both inc and dec - 1 -- 0 is included in the increasing numbers
Note: inc and dec contain the same data, but it seems clearer to duplicate them.
4 Problem 114
Investigating the number of ways to fill a row with separated blocks that are at least three units long.
Solution:
problem_114 = undefined
5 Problem 115
Finding a generalisation for the number of ways to fill a row with separated blocks.
Solution:
problem_115 = undefined
6 Problem 116
Investigating the number of ways of replacing square tiles with one of three coloured tiles.
Solution:
problem_116 = undefined
7 Problem 117
Investigating the number of ways of tiling a row using different-sized tiles.
Solution:
problem_117 = undefined
8 Problem 118
Exploring the number of ways in which sets containing prime elements can be made.
Solution:
problem_118 = undefined
9 Problem 119
Investigating the numbers which are equal to sum of their digits raised to some power.
Solution:
problem_119 = undefined
10 Problem 120
Finding the maximum remainder when (a − 1)n + (a + 1)n is divided by a2.
Solution:
problem_120 = undefined
Categories: Programming exercise spoilers | Tutorials | Code
