2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 14:28:05 +02:00
LaTeX-examples/documents/Programmierparadigmen/scripts/haskell/hirsch-index.hs

12 lines
409 B
Haskell
Raw Normal View History

2014-03-18 19:31:04 +01:00
import Data.List --sort und reverse
hIndex :: (Num a, Ord a) => [a] -> a
hIndex l = helper (reverse (sort l)) 0
where helper [] acc = acc
helper (z:ls) acc
| z > acc = helper ls (acc + 1)
| otherwise = acc
-- Alternativ
hindex1 = length . takeWhile id . zipWith (<=) [1..] . reverse . sort
hindex2 = length . takeWhile (\(i, n) -> n >= i) . zip [1..] . reverse . sort