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,15 @@
tau :: Integral a => a -> a
tau n | n <= 0 = error "Not a positive integer"
tau n = go 0 (1, 1)
where
yo i = (i, i * i)
go r (i, ii)
| n < ii = r
| n == ii = r + 1
| 0 == mod n i = go (r + 2) (yo $ i + 1)
| otherwise = go r (yo $ i + 1)
isTau :: Integral a => a -> Bool
isTau n = 0 == mod n (tau n)
main = print . take 100 . filter isTau $ [1..]

View file

@ -0,0 +1,33 @@
import Data.List (group, scanl)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
----------------------- TAU NUMBERS ----------------------
tauNumbers :: [Int]
tauNumbers =
filter
((0 ==) . (rem <*> (length . divisors)))
[1 ..]
--------------------------- TEST -------------------------
main :: IO ()
main =
let xs = take 100 $ fmap show tauNumbers
w = length $ last xs
in (putStrLn . unlines) $
unwords . fmap (justifyRight w ' ')
<$> chunksOf 10 xs
------------------------- GENERIC ------------------------
divisors :: Int -> [Int]
divisors =
foldr
(flip ((<*>) . fmap (*)) . scanl (*) 1)
[1]
. group
. primeFactors
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)