Nth root: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
m →‎{{header|Haskell}}: Small reduction.
Hout (talk | contribs)
m →‎{{header|Haskell}}: Minor update to format of output.
Line 1,492:
(((,) <*> ((/ n) . ((+) . ((n - 1) *) <*> (x /) . (** (n - 1))))) . snd)
(x, x / n)
 
 
-- TESTS ------------------------ TESTS --------------------------
main :: IO ()
main =
Line 1,503 ⟶ 1,504:
(uncurry nthRoot)
[(2, 2), (5, 34), (10, 734 ^ 10), (0.5, 7)]
 
 
-- FORMAT OF RESULTS ------------------ FORMAT OF RESULTS --------------------
fTable :: String -> (a -> String) -> (b -> String) -> (a -> b) -> [a] -> String
fTable s xShow fxShow f xs =
Line 1,510 ⟶ 1,512:
rjust n c = drop . length <*> (replicate n c ++)
in unlines $
s : fmap (((++) . rjust w ' ' . xShow) <*> ((" -> " ++) . fxShow . f)) xs</lang>
{{Out}}
<pre>Nth roots:
2.0 `nthRoot` 2.0 -> 1.414213562373095
5.0 `nthRoot` 34.0 -> 2.0243974584998847
10.0 `nthRoot` 4.539004352165717e28 -> 734.0
0.5 `nthRoot` 7.0 -> 49.0</pre>
 
=={{header|HicEst}}==