hirsch-index.hs 431 B

1234567891011121314
  1. import Data.List --sort und reverse
  2. hIndex :: (Num a, Ord a) => [a] -> a
  3. hIndex l = helper (reverse (sort l)) 0
  4. where helper [] acc = acc
  5. helper (z:ls) acc
  6. | z > acc = helper ls (acc + 1)
  7. | otherwise = acc
  8. -- Alternativ
  9. hindex1 = length . takeWhile id .
  10. zipWith (<=) [1..] . reverse . sort
  11. hindex2 = length . takeWhile (\(i, n) -> n >= i) .
  12. zip [1..] . reverse . sort