Difference between revisions of "Euler problems/171 to 180"

From HaskellWiki
Jump to navigation Jump to search
(add problem 176)
(add problem 172)
Line 12: Line 12:
 
Solution:
 
Solution:
 
<haskell>
 
<haskell>
  +
factorial n = product [1..toInteger n]
problem_172 = undefined
 
  +
  +
fallingFactorial x n = product [x - fromInteger i | i <- [0..toInteger n - 1] ]
  +
  +
choose n k = fallingFactorial n k `div` factorial k
  +
  +
-- how many numbers can we get having d digits and p positions
  +
p172 0 _ = 0
  +
p172 d p
  +
| p < 4 = d^p
  +
| otherwise =
  +
(p172' p) + p*(p172' (p-1)) + (choose p 2)*(p172' (p-2)) + (choose p 3)*(p172' (p-3))
  +
where
  +
p172' = p172 (d-1)
  +
  +
problem_172= (p172 10 18) * 9 `div` 10
 
</haskell>
 
</haskell>
   

Revision as of 03:08, 1 February 2008

Problem 171

Finding numbers for which the sum of the squares of the digits is a square.

Solution:

problem_171 = undefined

Problem 172

Investigating numbers with few repeated digits.

Solution:

factorial n = product [1..toInteger n]

fallingFactorial x n = product [x - fromInteger i | i <- [0..toInteger n - 1] ]

choose n k = fallingFactorial n k `div` factorial k

-- how many numbers can we get having d digits and p positions
p172 0 _ = 0
p172 d p 
    | p < 4 = d^p
    | otherwise = 
        (p172' p) +  p*(p172' (p-1)) + (choose p 2)*(p172' (p-2)) + (choose p 3)*(p172' (p-3))
    where
    p172' = p172 (d-1)
 
problem_172= (p172 10 18) * 9 `div` 10

Problem 173

Using up to one million tiles how many different "hollow" square laminae can be formed? Solution:

problem_173=
    let c=div (10^6) 4
        xm=floor$sqrt $fromIntegral c
        k=[div c x|x<-[1..xm]]
    in  sum k-(div (xm*(xm+1)) 2)

Problem 174

Counting the number of "hollow" square laminae that can form one, two, three, ... distinct arrangements.

Solution:

problem_174 = undefined

Problem 175

Fractions involving the number of different ways a number can be expressed as a sum of powers of 2. Solution:

sternTree x 0=[]
sternTree x y=
    m:sternTree y n  
    where
    (m,n)=divMod x y
findRat x y
    |odd l=take (l-1) k++[last k-1,1]
    |otherwise=k
    where
    k=sternTree x y
    l=length k
p175 x y= 
    init$foldl (++) "" [a++","|
    a<-map show $reverse $filter (/=0)$findRat x y]
problems_175=p175 123456789 987654321
test=p175 13 17

Problem 176

Rectangular triangles that share a cathetus. Solution:

--k=47547 
--2*k+1=95095 = 5*7*11*13*19
lst=[5,7,11,13,19]
primes=[2,3,5,7,11]
problem_176 =
    product[a^b|(a,b)<-zip primes (reverse n)]
    where
    la=div (last lst+1) 2
    m=map (\x->div x 2)$init lst
    n=m++[la]

Problem 177

Integer angled Quadrilaterals.

Solution:

problem_177 = undefined

Problem 178

Step Numbers Solution:

problem_178 = undefined

Problem 179

Consecutive positive divisors. Solution:

problem_179 = undefined

Problem 180

Solution:

problem_180 = undefined