Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Gapful-numbers/Haskell/gapful-numbers-1.hs
Normal file
14
Task/Gapful-numbers/Haskell/gapful-numbers-1.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{-# LANGUAGE NumericUnderscores #-}
|
||||
|
||||
gapful :: Int -> Bool
|
||||
gapful n = n `rem` firstLastDigit == 0
|
||||
where
|
||||
firstLastDigit = read [head asDigits, last asDigits]
|
||||
asDigits = show n
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn $ "\nFirst 30 Gapful numbers >= 100 :\n" ++ r 30 [100,101..]
|
||||
putStrLn $ "\nFirst 15 Gapful numbers >= 1,000,000 :\n" ++ r 15 [1_000_000,1_000_001..]
|
||||
putStrLn $ "\nFirst 10 Gapful numbers >= 1,000,000,000 :\n" ++ r 10 [1_000_000_000,1_000_000_001..]
|
||||
where r n = show . take n . filter gapful
|
||||
33
Task/Gapful-numbers/Haskell/gapful-numbers-2.hs
Normal file
33
Task/Gapful-numbers/Haskell/gapful-numbers-2.hs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import Data.List (intercalate)
|
||||
import Data.List.Split (chunksOf)
|
||||
|
||||
---------------------- GAPFUL NUMBERS --------------------
|
||||
|
||||
isGapful :: Int -> Bool
|
||||
isGapful =
|
||||
(0 ==)
|
||||
. (<*>)
|
||||
rem
|
||||
(read . (<*>) [head, last] . pure . show)
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_
|
||||
(putStrLn . showSample)
|
||||
[ "First 30 gapful numbers >= 100",
|
||||
"First 15 Gapful numbers >= 1000000",
|
||||
"First 10 Gapful numbers >= 1000000000"
|
||||
]
|
||||
|
||||
showSample :: String -> String
|
||||
showSample k =
|
||||
let ws = words k
|
||||
in k <> ":\n\n"
|
||||
<> unlines
|
||||
( fmap (intercalate ", " . fmap show) $
|
||||
chunksOf 5 $
|
||||
take
|
||||
(read (ws !! 1))
|
||||
[read (ws !! 5) :: Int ..]
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue