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