[Haskell-beginners] Project euler question
David McBride
toad3k at gmail.com
Wed May 21 21:10:41 UTC 2014
For what it is worth, I'm getting the same answer as you are.
> head $ drop (1000000-1) $ sort $ Data.List.permutations [0..9]
[2,7,8,3,9,1,5,4,6,0]
>(sort $ Data.List.permutations [0..9]) !! (1000000-1)
[2,7,8,3,9,1,5,4,6,0]
I guess either euler is wrong or we are both crazy.
On Wed, May 21, 2014 at 4:09 PM, martin <martin.drautzburg at web.de> wrote:
> Hello all,
>
> I tried to solve Problem 24 (https://projecteuler.net/problem=24) and
> came up with the following solution:
>
> import Data.List.Ordered
> import Data.Char
>
> elems = [0,1,2,3,4,5,6,7,8,9] :: [Int]
>
> x = do
> a <- elems
> b <- elems `without` [a]
> c <- elems `without` [a,b]
> d <- elems `without` [a,b,c]
> e <- elems `without` [a,b,c,d]
> f <- elems `without` [a,b,c,d,e]
> g <- elems `without` [a,b,c,d,e,f]
> h <- elems `without` [a,b,c,d,e,f,g]
> i <- elems `without` [a,b,c,d,e,f,g,h]
> j <- elems `without` [a,b,c,d,e,f,g,h,i]
> return [a,b,c,d,e,f,g,h,i,j]
>
> without a b = minus a ( sort b)
>
> solution = filter isDigit $ show $ (x !! 1000001)
> -- "2783915640"
>
> PE tells me that this is wrong, and I peeked the correct answer, which is
> 2783915460 (the 4 and 6 are swapped). So I
> tried to find out where the correct answer is in my list x and added
>
> y = filter (\(x,y) -> x == "2783915460") $ zip (map (filter isDigit .
> show) x) [1..]
> -- [("2783915460",1000000)]
>
> How can that be? "solution" tells me that the millionth element is
> "2783915640" but "y" tells me that "2783915460" is at
> the millionth position? I just cannot see it.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140521/3409f02c/attachment.html>
More information about the Beginners
mailing list