Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Part2.hs 793B

123456789101112131415161718192021222324
  1. module Day5.Part2 (
  2. execute9001Operation,
  3. day5_2
  4. ) where
  5. import qualified Data.Sequence as S
  6. import Data.Foldable (toList)
  7. import Day5.Shared
  8. execute9001Operation :: Row -> Operation -> Row
  9. execute9001Operation row op
  10. = updatedRow
  11. where
  12. originStack = row `S.index` asInt (from op)
  13. targetStack = row `S.index` asInt (to op)
  14. movedContent = take (count op) $ content originStack
  15. updatedOrigin = Stack (drop (count op) $ content originStack)
  16. updatedTarget = Stack (movedContent ++ content targetStack)
  17. updatedRow = S.update (asInt $ to op) updatedTarget $ S.update (asInt $ from op) updatedOrigin row
  18. day5_2 :: String -> String
  19. day5_2 input = toList . findTopOfStacks $ foldl execute9001Operation row operations
  20. where
  21. (row, operations) = parseInput input