module Euler.Problems.Problem46
( answer
, goldbachNumbers
, squareDoubles
) where
import Euler.Prelude
import Euler.Util.List (adjustEach)
import Euler.Util.Prime (isPrime, primes)
import qualified Euler.Util.FrontierSearch as FS
import qualified Euler.Util.Inf as Inf
import qualified Data.List as List
import qualified Data.List.Ordered as OL
answer :: Integer
answer =
List.head . List.filter (not . isPrime) $ OL.minus [3, 5..] goldbachNumbers
goldbachNumbers :: Integral a => [a]
goldbachNumbers =
FS.searchValues FS.Conf
{ FS.start = [[Inf.fromList primes, Inf.fromList squareDoubles]]
, FS.next = adjustEach $ Inf.fromList . List.tail . Inf.toList
, FS.nodeValue = List.sum . (List.head . Inf.toList <$>)
}
squareDoubles :: Integral a => [a]
squareDoubles =
List.scanl1 (+) [2, 6 ..]