This file contains 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 | |
semiPrime :: Int -> Bool | |
semiPrime list = 2 == (length $ primeFactors list) | |
semiPrimesBelow :: Int -> Int | |
semiPrimesBelow n = length $ filter semiPrime [1..n-1] | |
main = putStrLn $ show $ semiPrimesBelow (10^8) |
This file contains 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
moddule = 10 ^ 8 | |
lastDigits x = x `mod` moddule | |
fastPow :: Integer -> Integer -> Integer -> Integer | |
fastPow base 1 m = mod base m | |
fastPow base pow m | even pow = mod ((fastPow base (div pow 2) m) ^ 2) m | |
| odd pow = mod ((fastPow base (div (pow-1) 2) m) ^ 2 * base) m | |
tetration a 1 = lastDigits a | |
tetration a k = lastDigits ( fastPow a' (tetration a' k') moddule) |
This file contains 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 Roman | |
import System.Environment | |
import Data.Char (toUpper) | |
import Control.Arrow ((&&&)) | |
redundantChars :: String -> Int | |
redundantChars = (\(x,y) -> length x - length y) . (id &&& (toRoman . fromRoman)) | |
main = do | |
romans <- getContents |
This file contains 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 (nub, sort) | |
import Data.Numbers.Primes | |
import Control.Arrow ((&&&)) | |
radical :: Integer -> Integer | |
radical = product . nub . primeFactors | |
radicalsSortedBelow :: Integer -> [Integer] | |
radicalsSortedBelow = map snd . sort . map ((&&&) radical id) . enumFromTo 1 |
This file contains 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.Monad (replicateM, join) | |
import Data.List (nub, sort, group) | |
import Control.Arrow ((&&&), (***)) | |
import Numeric (showFFloat) | |
allVariantsNumber :: Integer | |
allVariantsNumber = 4^9 * 6^6 | |
groupVariants :: [[Integer]] -> [(Integer,Integer)] | |
groupVariants = map ((&&&) head (toInteger . length)) . group . sort . map sum |
This file contains 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 |
This file contains 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 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 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 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)] |
OlderNewer