Lah numbers: Difference between revisions
m
→{{header|Haskell}}: Restored OP's formatting style.
m (→{{header|Haskell}}: Pruning of some minor redundancy) |
m (→{{header|Haskell}}: Restored OP's formatting style.) |
||
Line 467:
<lang haskell>import Text.Printf (printf)
import Control.Monad (when)
factorial :: Integral n => n -> n
:: Integral n▼
factorial 0 = 1
factorial n = product [1
lah n k
| k == 1 = factorial n
| k == n = 1
| k > n = 0
| k < 1 || n < 1 = 0
| otherwise = f n `div` f k `div` factorial (n - k)
where
f = (*) =<< (^ 2) . factorial . pred
printLah :: (Word, Word) -> IO ()
printLah (n, k) = do
when (k == 0) (printf "\n%3d" n)
printf "%11d" (lah n k)
main :: IO ()
main = do
Line 496 ⟶ 492:
mapM_ (printf "%11d") zeroToTwelve
mapM_ printLah $ (,) <$> zeroToTwelve <*> zeroToTwelve
printf "\nMaximum value from the L(100, *) row:\n%d\n"
▲ zeroToTwelve = [0 .. 12]</lang>
{{out}}
<pre>Unsigned Lah numbers: L(n, k):
|