Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Cyclops-numbers/Haskell/cyclops-numbers.hs
Normal file
47
Task/Cyclops-numbers/Haskell/cyclops-numbers.hs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import Control.Monad (replicateM)
|
||||
import Data.Numbers.Primes (isPrime)
|
||||
|
||||
--------------------- CYCLOPS NUMBERS --------------------
|
||||
|
||||
cyclops :: [Integer]
|
||||
cyclops = [0 ..] >>= go
|
||||
where
|
||||
go 0 = [0]
|
||||
go n =
|
||||
(\s -> read s :: Integer)
|
||||
<$> (fmap ((<>) . (<> "0")) >>= (<*>))
|
||||
(replicateM n ['1' .. '9'])
|
||||
|
||||
blindPrime :: Integer -> Bool
|
||||
blindPrime n =
|
||||
let s = show n
|
||||
m = quot (length s) 2
|
||||
in isPrime $
|
||||
(\t -> read t :: Integer)
|
||||
(take m s <> drop (succ m) s)
|
||||
|
||||
palindromic :: Integer -> Bool
|
||||
palindromic = ((==) =<< reverse) . show
|
||||
|
||||
-------------------------- TESTS -------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
(putStrLn . unlines)
|
||||
[ "First 50 Cyclops numbers – A134808:",
|
||||
unwords (show <$> take 50 cyclops),
|
||||
"",
|
||||
"First 50 Cyclops primes – A134809:",
|
||||
unwords $ take 50 [show n | n <- cyclops, isPrime n],
|
||||
"",
|
||||
"First 50 blind prime Cyclops numbers – A329737:",
|
||||
unwords $
|
||||
take
|
||||
50
|
||||
[show n | n <- cyclops, isPrime n, blindPrime n],
|
||||
"",
|
||||
"First 50 prime palindromic cyclops numbers – A136098:",
|
||||
unwords $
|
||||
take
|
||||
50
|
||||
[show n | n <- cyclops, isPrime n, palindromic n]
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue