Log In · Register

 
Project Euler
mipadi
post Apr 16 2008, 12:16 PM
Post #1


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



Hey, does anyone here participate in Project Euler?
 
 
Start new topic
Replies
mipadi
post Jul 20 2009, 07:58 AM
Post #2


Senior Member
******

Group: Administrator
Posts: 2,648
Joined: Apr 2008
Member No: 639,265



Spoiler Alert

I'm particularly proud of this piece of code that I used to solve Problem 53:

CODE
-- The standard combinatoric "n choose r" equation
nCr n r = (fac n) `div` ((fac r) * (fac (n - r)))

-- The standard factorial equation
fac n | n == 0    = 1
      | otherwise = n * fac (n - 1)

-- A function for counting the occurrences of values >1,000,000 in a list
-- that is appropriate for foldl
countMillion n x | x > 1000000 = n + 1
                 | otherwise   = n

-- Performs the calculation
doIt = foldl countMillion 0 xs
  where
    xs = [nCr n r | n <- [23..100], r <- [1..n]]
 

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: