Problem 128
コンテンツ
http://projecteuler.net/index.php?section=problems&id=128
六角形の絵を描いて考えてみると、調べるべき場所が案外少ないことに気づく。
import Number import Data.Maybe import Control.Arrow top n | all isPrime around = Just $ 2+3*n*(n-1) | otherwise = Nothing where around = [6*n-1,12*n+5,6*n+1] topRight n | all isPrime around = Just $ 1+3*n*(n+1) | otherwise = Nothing where around = [6*n-1,6*n+5,12*n-7] pd = catMaybes.flat.map (top&&&topRight) $ [1..] where flat = concatMap ((a,b)->[a,b]) main = print$pd!!1999
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)