http://www.colorless-sight.jp/wiki/?ProjectEular%2FProblem27
-- Problem 27 module Main (main) where import Array import qualified Common as C (is_prime) main :: IO () main = print $ problem27 problem27 :: Int problem27 = (fst idx) * (snd idx) where idx = find_max_idx arr arr = listArray ((-999,-999),(999,999)) [ num_primes a b | a <- [-999..999], b <- [-999..999] ] find_max_idx :: Array (Int,Int) Int -> (Int,Int) find_max_idx arr = find_max_idx_iter arr idcs idx where (idx:idcs) = indices arr find_max_idx_iter :: Array (Int,Int) Int -> [(Int,Int)] -> (Int,Int) -> (Int,Int) find_max_idx_iter arr idcs max_idx | null idcs = max_idx | arr!idx > arr!max_idx = find_max_idx_iter arr idcs' idx | otherwise = find_max_idx_iter arr idcs' max_idx where (idx:idcs') = idcs num_primes :: Int -> Int -> Int num_primes a b = num_primes_iter 0 a b num_primes_iter :: Int -> Int -> Int -> Int num_primes_iter n a b | C.is_prime (n^2 + a*n + b) = 1 + (num_primes_iter (n+1) a b) | otherwise = 0 |
最新の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
|