Euler problems/121 to 130
From HaskellWiki
(Removing category tags. See Talk:Euler_problems) |
|||
| Line 48: | Line 48: | ||
Solution: | Solution: | ||
<haskell> | <haskell> | ||
| - | problem_124 = | + | import List |
| + | primes :: [Integer] | ||
| + | primes = 2 : filter ((==1) . length . primeFactors) [3,5..] | ||
| + | |||
| + | primeFactors :: Integer -> [Integer] | ||
| + | primeFactors n = factor n primes | ||
| + | where | ||
| + | factor _ [] = [] | ||
| + | factor m (p:ps) | p*p > m = [m] | ||
| + | | m `mod` p == 0 = p : factor (m `div` p) (p:ps) | ||
| + | | otherwise = factor m ps | ||
| + | problem_124=snd$(!!9999)$sort[(product$nub$primeFactors x,x)|x<-[1..100000]] | ||
| + | |||
</haskell> | </haskell> | ||
Revision as of 08:02, 10 December 2007
Contents |
1 Problem 121
Investigate the game of chance involving coloured discs.
Solution:
problem_121 = undefined
2 Problem 122
Finding the most efficient exponentiation method.
Solution using a depth first search, pretty fast :
import Data.List import Data.Array.Diff import Control.Monad depthAddChain 12 branch mins = mins depthAddChain d branch mins = foldl' step mins $ nub $ filter (> head branch) $ liftM2 (+) branch branch where step da e | e > 200 = da | otherwise = case compare (da ! e) d of GT -> depthAddChain (d+1) (e:branch) $ da // [(e,d)] EQ -> depthAddChain (d+1) (e:branch) da LT -> da baseBranch = [2,1] baseMins :: DiffUArray Int Int baseMins = listArray (1,200) $ 0:1: repeat maxBound problem_122 = sum . elems $ depthAddChain 2 baseBranch baseMins
3 Problem 123
Determining the remainder when (pn ā 1)n + (pn + 1)n is divided by pn2.
Solution:
problem_123 = undefined
4 Problem 124
Determining the kth element of the sorted radical function.
Solution:
import List primes :: [Integer] primes = 2 : filter ((==1) . length . primeFactors) [3,5..] primeFactors :: Integer -> [Integer] primeFactors n = factor n primes where factor _ [] = [] factor m (p:ps) | p*p > m = [m] | m `mod` p == 0 = p : factor (m `div` p) (p:ps) | otherwise = factor m ps problem_124=snd$(!!9999)$sort[(product$nub$primeFactors x,x)|x<-[1..100000]]
5 Problem 125
Finding square sums that are palindromic.
Solution:
problem_125 = undefined
6 Problem 126
Exploring the number of cubes required to cover every visible face on a cuboid.
Solution:
problem_126 = undefined
7 Problem 127
Investigating the number of abc-hits below a given limit.
Solution:
problem_127 = undefined
8 Problem 128
Which tiles in the hexagonal arrangement have prime differences with neighbours?
Solution:
problem_128 = undefined
9 Problem 129
Investigating minimal repunits that divide by n.
Solution:
problem_129 = undefined
10 Problem 130
Finding composite values, n, for which nā1 is divisible by the length of the smallest repunits that divide it.
Solution:
problem_130 = undefined
