Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,26 @@
{-# LANGUAGE TupleSections #-}
import Control.Monad (join)
import Data.List (partition, sortOn)
import Data.Ord (comparing)
------------------- SQUARE BUT NOT CUBE ------------------
isCube :: Int -> Bool
isCube n = n == round (fromIntegral n ** (1 / 3)) ^ 3
both, only :: [Int]
(both, only) = partition isCube $ join (*) <$> [1 ..]
--------------------------- TEST -------------------------
main :: IO ()
main =
(putStrLn . unlines) $
uncurry ((<>) . show)
<$> sortOn
fst
( ((," (also cube)") <$> take 3 both)
<> ((,"") <$> take 30 only)
)

View file

@ -0,0 +1,21 @@
import Control.Monad (join)
------------------- SQUARE BUT NOT CUBE ------------------
cubeRoot :: Int -> Int
cubeRoot = round . (** (1 / 3)) . fromIntegral
isCube :: Int -> Bool
isCube = (==) <*> ((^ 3) . cubeRoot)
--------------------------- TEST -------------------------
main :: IO ()
main =
(putStrLn . unlines) $
((<>) . show <*> cubeNote)
<$> take 33 (join (*) <$> [1 ..])
cubeNote :: Int -> String
cubeNote x
| isCube x = " (also cube of " <> show (cubeRoot x) <> ")"
| otherwise = []

View file

@ -0,0 +1,18 @@
isCube :: Int -> Bool
isCube =
(==)
<*> ((^ 3) . round . (** (1 / 3)) . fromIntegral)
squares :: Int -> Int -> [Int]
squares m n = (>>= id) (*) <$> [m .. n]
--------------------------- TEST -------------------------
main :: IO ()
main =
(putStrLn . unlines) $
(<>) . show <*> label <$> squares 1 33
label :: Int -> String
label n
| isCube n = " (also cube)"
| otherwise = ""