Skip to content

Problem 4

October 31, 2009

I could see that the problem 4 of the Euler project could be solve with a brute force function.

Since one needed to calculate the product of two 3-digit numbers, I created two lists of all possible 3-digit numbers, and tried all combinations. Here is my implementation:

import List

palindrome = [ n*m | n <- [100..999], m <- [100..999], show (n*m) == reverse (show (n*m)) ]

lpal = (last . sort) palindrome

GHCi took about 2 seconds (and a lot of bytes!) in my computer to figure out the result.

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: