Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Truncatable-primes/Haskell/truncatable-primes-1.hs
Normal file
14
Task/Truncatable-primes/Haskell/truncatable-primes-1.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import Data.Numbers.Primes(primes, isPrime)
|
||||
import Data.List
|
||||
import Control.Arrow
|
||||
|
||||
primes1e6 = reverse. filter (notElem '0'. show) $ takeWhile(<=1000000) primes
|
||||
|
||||
rightT, leftT :: Int -> Bool
|
||||
rightT = all isPrime. takeWhile(>0). drop 1. iterate (`div`10)
|
||||
leftT x = all isPrime. takeWhile(<x).map (x`mod`) $ iterate (*10) 10
|
||||
|
||||
main = do
|
||||
let (ltp, rtp) = (head. filter leftT &&& head. filter rightT) primes1e6
|
||||
putStrLn $ "Left truncatable " ++ show ltp
|
||||
putStrLn $ "Right truncatable " ++ show rtp
|
||||
3
Task/Truncatable-primes/Haskell/truncatable-primes-2.hs
Normal file
3
Task/Truncatable-primes/Haskell/truncatable-primes-2.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
*Main> main
|
||||
Left truncatable 998443
|
||||
Right truncatable 739399
|
||||
8
Task/Truncatable-primes/Haskell/truncatable-primes-3.hs
Normal file
8
Task/Truncatable-primes/Haskell/truncatable-primes-3.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
digits = [1..9] :: [Integer]
|
||||
smallPrimes = filter isPrime digits
|
||||
pow10 = iterate (*10) 1
|
||||
mul10 = (pow10!!). length. show
|
||||
righT = (+) . (10 *)
|
||||
lefT = liftM2 (.) (+) ((*) . mul10)
|
||||
|
||||
primesTruncatable f = iterate (concatMap (filter isPrime.flip map digits. f)) smallPrimes
|
||||
5
Task/Truncatable-primes/Haskell/truncatable-primes-4.hs
Normal file
5
Task/Truncatable-primes/Haskell/truncatable-primes-4.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
*Main> maximum $ primesTruncatable righT !! 5
|
||||
739399
|
||||
|
||||
*Main> maximum $ primesTruncatable lefT !! 5
|
||||
998443
|
||||
Loading…
Add table
Add a link
Reference in a new issue