hirsch-index.hs 409 B

123456789101112
  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 . zipWith (<=) [1..] . reverse . sort
  10. hindex2 = length . takeWhile (\(i, n) -> n >= i) . zip [1..] . reverse . sort