Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Cuban-primes/Haskell/cuban-primes-1.hs
Normal file
15
Task/Cuban-primes/Haskell/cuban-primes-1.hs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import Data.Numbers.Primes (isPrime)
|
||||
import Data.List (intercalate)
|
||||
import Data.List.Split (chunksOf)
|
||||
import Text.Printf (printf)
|
||||
|
||||
cubans :: [Int]
|
||||
cubans = filter isPrime . map (\x -> (succ x ^ 3) - (x ^ 3)) $ [1 ..]
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
mapM_ (\row -> mapM_ (printf "%10s" . thousands) row >> printf "\n") $ rows cubans
|
||||
printf "\nThe 100,000th cuban prime is: %10s\n" $ thousands $ cubans !! 99999
|
||||
where
|
||||
rows = chunksOf 10 . take 200
|
||||
thousands = reverse . intercalate "," . chunksOf 3 . reverse . show
|
||||
6
Task/Cuban-primes/Haskell/cuban-primes-2.hs
Normal file
6
Task/Cuban-primes/Haskell/cuban-primes-2.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
cubans :: [Int]
|
||||
cubans =
|
||||
[ x
|
||||
| n <- [1 ..]
|
||||
, let x = (succ n ^ 3) - (n ^ 3)
|
||||
, isPrime x ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue