Skip to content

Instantly share code, notes, and snippets.

@guibou
Created March 10, 2021 19:22
Show Gist options
  • Select an option

  • Save guibou/ce98dc4d8e7b7c39b86c9dabd679955e to your computer and use it in GitHub Desktop.

Select an option

Save guibou/ce98dc4d8e7b7c39b86c9dabd679955e to your computer and use it in GitHub Desktop.
{-# OPTIONS -Wall #-}
queueTime :: [Int] -> Int -> Int
queueTime l n = go (take n l) (drop n l) 0
where
go [] [] res = res
go workers remains res = let
faster = minimum workers
workers' = filter(/= 0) $ map (subtract faster) workers
l' = workers' ++ remains
in go (take n l') (drop n l') (res + faster)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment