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.

Part1.hs 880B

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