Ad
  • Custom User Avatar

    It seems that Haskell solutions will certainly time out, even though the solution is translated from a nice Python version..

    It really upset me. But how can I optimize my code?

    (I use Data.Vector and expect that it will makes the my code faster.)

    {-# OPTIONS_GHC -optc-O3 #-}
    module LastDigit (lastDigit) where
    import qualified Data.Vector as V
    lastDigit :: [Integer] -> Integer
    lastDigit xs = (V.foldr' (\x acc -> x ^ (if acc < 4 then acc else acc `mod` 4 + 4)) 1 $ V.fromList xs) `mod` 10
    
  • Custom User Avatar

    Thanks a lot! I've understand it now.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution