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 @@
n `nthRoot` x = fst $ until (uncurry(==)) (\(_,x0) -> (x0,((n-1)*x0+x/x0**(n-1))/n)) (x,x/n)

View file

@ -0,0 +1,28 @@
nthRoot :: Double -> Double -> Double
nthRoot n x =
fst $
until
(uncurry (==))
(((,) <*> ((/ n) . ((+) . (pn *) <*> (x /) . (** pn)))) . snd)
(x, x / n)
where
pn = pred n
-------------------------- TESTS --------------------------
main :: IO ()
main =
putStrLn $
fTable
"Nth roots:"
(\(a, b) -> show a ++ " `nthRoot` " ++ show b)
show
(uncurry nthRoot)
[(2, 2), (5, 34), (10, 734 ^ 10), (0.5, 7)]
-------------------- FORMAT OF RESULTS --------------------
fTable :: String -> (a -> String) -> (b -> String) -> (a -> b) -> [a] -> String
fTable s xShow fxShow f xs =
let w = maximum (length . xShow <$> xs)
rjust n c = drop . length <*> (replicate n c ++)
in unlines $
s : fmap (((++) . rjust w ' ' . xShow) <*> ((" -> " ++) . fxShow . f)) xs