module Main (main) where
import System(getArgs)
import Char(isLower,toLower)
import List(nub)
-- partitions of `n' with `howmany' terms, *excluding* ones. This is
-- because we are going to multiple the terms together at the end, and
-- the partition of n with x ones is, from the multiplicative
-- standpoint, equal to the one-less partition of n-x. This means, of
-- course, that we need the partition of n-x, but we look for those
-- anyway (at least we look for partitions of 20 <= n <= 26, having
-- made the reasonable assumption that below that we won't be finding
-- any serious contenders). This results in a tremendous speed gain.
partitions n 1 = [[n]]
partitions n howmany = acc 2 []
where
acc i parts
| i >= 1 + (n `div` howmany) = parts
| otherwise = acc (i + 1) parts++([i:pts | pts <- partitions (n - i) (howmany - 1)])
listlcm = foldl lcm 1
listmax = foldl max 0
maxmultpart n = listmax [listmax [(listlcm part) | part <- partitions outof x] | x <- [1..n], outof <- [20..26]]
main = do
args <- getArgs
if length args < 2 || length args > 3
then error "Usage: korn firstname [middlename] lastname."
else do
let allargs = nub (map toLower (concat args))
if not (all isLower allargs)
then error "Names may only contain characters a-zA-Z."
else putStrLn (show (maxmultpart (length allargs)))