Advertisement
Guest User

Nunki3’s AHK day 5

a guest
Dec 5th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. FileRead, Input, 5.txt
  2.  
  3. ;1
  4. stacks := MakeStacks(Input)
  5. for i, line in StrSplit(Input, "`r`n") {
  6.     aLine := StrSplit(line, A_Space)
  7.     if (aLine[1] = "move") {
  8.         Loop, % aLine[2]
  9.             stacks[aLine[6]].Push(stacks[aLine[4]].Pop())
  10.     }
  11. }
  12. top := ""
  13. for i, stack in stacks
  14.     top .= stack[stack.MaxIndex()]
  15. MsgBox, % top
  16.  
  17. ;2
  18. stacks := MakeStacks(Input)
  19. for i, line in StrSplit(Input, "`r`n") {
  20.     aLine := StrSplit(line, A_Space)
  21.     if (aLine[1] = "move") {
  22.         des := stacks[aLine[6]].Length() + 1
  23.         Loop, % aLine[2]
  24.             stacks[aLine[6]].InsertAt(des, stacks[aLine[4]].Pop())
  25.     }
  26. }
  27. top := ""
  28. for i, stack in stacks
  29.     top .= stack[stack.MaxIndex()]
  30. MsgBox, % top
  31.  
  32. MakeStacks(Input) {
  33.     stacks := []
  34.     for i, line in StrSplit(StrSplit(Input, "`r`n 1 ")[1], "`r`n`") {
  35.         Loop, % Ceil(StrLen(line)/4)
  36.             {
  37.             char := SubStr(line, 2 + (4 * (A_Index-1)), 1)
  38.             if (char != A_Space) {
  39.                 if !stacks[A_Index]
  40.                     stacks[A_Index] := []
  41.                 stacks[A_Index].InsertAt(1, char)
  42.             }
  43.         }
  44.     }
  45.     Return stacks
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement