Thursday, 12 August 2010
97
Again this one is too easy in haskell, although this isn't the best solution, it's very simple.
module P97 where bigprime :: Integer bigprime = 1 + 28433 * 2^7830457 p97 = reverse . take 10 . reverse $ show bigprime
Wednesday, 11 August 2010
#38
Incredibly simple for haskell (and quick)
module P48 where p48 :: Integer -> String p48 n = reverse . take 10 . reverse . show $ foldr (\x a -> a + (x^x)) 0 [1..n]then call p48 1000.
Sunday, 25 October 2009
#33
This can be found using a simple list comprehension. Just then multiply and collect.
let s = [(a,b) | a<-[10..99], b<-[a+1..99], a*mod b 10 == b*div a 10, a`mod`10==b`div`10]There are only 4 entries so this can be done by hand :)
#28
This problem can be solved by thought rather than brute force. Looking at the diagonals as 4 separate sums, the four diagonals form four number sequences which when summed give the value of the kth ring to be 4[(2k+1)^2-3k] (k>=1, k=0 is the first 1x1 grid).
Determining the link betweem the grid size and k was also trival, the ring size is 2k+1. Hence for a 1001x1001 grid, k = 500. We can simply sum the answer over t=1..k+1 to get the solution, and add one for the central 1.
Determining the link betweem the grid size and k was also trival, the ring size is 2k+1. Hence for a 1001x1001 grid, k = 500. We can simply sum the answer over t=1..k+1 to get the solution, and add one for the central 1.
let fk k = 4*((2*k+1)^2-3*k) let s = 1 + (sum . map fk $ [1..500])
#29
This problem can be solved trivially in haskell with a single line or so if you use Sets
let s = Data.Set.fromList [a^b | a<-[2..100], b<-[2..100]And then we just take the set size.
Friday, 16 October 2009
#25
There is no need for any code here as you can do it by math only. Given then we know formula for the fibonacci numbers is Fn = (1/sqrt5) * (phi^n + phi^-n), we can set Fn = 10^999 and then use logarithms to solve for n. (Where of course phi = (1+sqrt(5))/2).
n = (ln(sqrt5) + 1000ln(10)) / ln (phi)This will give us the "n" required to be just exactly equal to that number, we need to round and we get the answer.
Subscribe to:
Posts (Atom)