This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PECore (eulerTotient) | |
import Data.Numbers.Primes | |
import Control.Arrow ((&&&)) | |
eulerChains :: Integer -> Integer | |
eulerChains 1 = 1 | |
eulerChains n = 1 + eulerChains (eulerTotient n) | |
main = print . sum . map fst . filter ( (== 25) . snd ) . map ((&&&) id eulerChains) . takeWhile (<40000000) $ primes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Numbers.Primes | |
import Data.List (group, sort) | |
import Control.Arrow ((&&&)) | |
sumOfDivisors :: Integer -> Integer | |
sumOfDivisors n = (-n +) . product . map ( productOfPowers . (&&&) head length ) . group . primeFactors $ n | |
where | |
productOfPowers :: (Integer, Int) -> Integer | |
productOfPowers (base, power) = sum [ base ^ powers | powers <- [0..power] ] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Array | |
pentagonals :: [Int] | |
pentagonals = [ n*(3*n-1) `div` 2 | n <- pentagonalIndices ] | |
where | |
pentagonalIndices :: [Int] | |
pentagonalIndices = concatMap (\x -> [x,-x]) [1..] | |
partition :: Array Int Integer | |
partition = listArray (0, 100000) $ 1 : 1 : map partition' [2..] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Arrow (second) | |
class Fluffy f where | |
furry :: (a -> b) -> f a -> f b | |
-- Exercise 1 | |
-- Relative Difficulty: 1 | |
instance Fluffy [] where | |
furry _ [] = [] | |
furry f xs = foldr ((:) . f) [] xs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
possibleTriangles :: Integer -> Int | |
possibleTriangles n = length . filter (\x -> length x == 1) . group . sort . concat $ [ [s,2*s..n] | i <- [1,3..(upperBound n)] | |
, j <- [2,4..(upperBound n)-i] | |
, gcd i j == 1 | |
, let s = abs (j*j - i*i) + 2*i*j + i*i + j*j ] | |
upperBound :: Integer -> Integer | |
upperBound = truncate . sqrt . fromIntegral |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (find, partition) | |
import Control.Monad (replicateM, join) | |
import Control.Arrow ((***)) | |
import Data.Maybe (fromJust) | |
import BooleanMatrixCore | |
{-- Matrix researches --} | |
pairsFromRclass :: (Int, Int) -> [(BooleanMatrix, BooleanMatrix)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Numbers.Primes | |
main = print . fst . head . dropWhile (\x -> snd x < (10^10)) . map (\(n,p) -> (n, (2 * p * n)) ) $ zip [2..] primes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Numbers.Primes | |
import Control.Arrow ((***)) | |
import Control.Monad (join) | |
import Data.List (group) | |
main = print . length . filter (==True) . map (uncurry (==) . join (***) (product . map ((1+) . length) . group . primeFactors)) $ [(x,x+1) | x <- [1..(10^7)]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List.Split (splitPlaces) | |
import Data.List (permutations, sort, nub) | |
import Data.Numbers.Primes | |
import Data.Bits | |
import Data.Digits | |
import Data.Char (digitToInt) | |
listToNum :: [Int] -> Integer | |
listToNum = toInteger . foldl1 ((+).(*10)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (find) | |
import Control.Monad (replicateM) | |
import Data.Maybe (fromJust) | |
import Numeric (showFFloat) | |
isSquare :: Integer -> Bool | |
isSquare x = x'*x' == x | |
where x' = truncate $ sqrt (fromIntegral x :: Double) | |
sew :: [Integer] -> Integer |