https://www.colorless-sight.jp:443/wiki/?ProjectEular%2FProblem22
-- Problem 22 module Main (main) where import qualified List (sort) import qualified Char (ord) main :: IO () main = do names_str <- getContents print $ problem22 $ to_names names_str problem22 :: [String] -> Int problem22 names = sum $ zipWith (*) (map worth (List.sort names)) [1..(length names)] worth :: String -> Int worth name = sum $ map (\c -> Char.ord c - Char.ord 'A' + 1) name to_names :: String -> [String] to_names str = concat $ (map (map rm_quote . (wordsBy ',')) . lines) str -- not good... rm_quote :: String -> String rm_quote = tail . init -- see: implementation of words wordsBy :: Char -> String -> [String] wordsBy c s = case dropWhile (== c) s of "" -> [] s' -> w : wordsBy c s'' where (w, s'') = break (== c) s' |
最新の20件2023-08-12
2022-12-28
2017-08-15
2014-01-31
2014-01-29
2013-06-04
2012-11-23
2010-08-01
2010-07-24
Tweet
|