Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FileRead, Input, 5.txt
- ;1
- stacks := MakeStacks(Input)
- for i, line in StrSplit(Input, "`r`n") {
- aLine := StrSplit(line, A_Space)
- if (aLine[1] = "move") {
- Loop, % aLine[2]
- stacks[aLine[6]].Push(stacks[aLine[4]].Pop())
- }
- }
- top := ""
- for i, stack in stacks
- top .= stack[stack.MaxIndex()]
- MsgBox, % top
- ;2
- stacks := MakeStacks(Input)
- for i, line in StrSplit(Input, "`r`n") {
- aLine := StrSplit(line, A_Space)
- if (aLine[1] = "move") {
- des := stacks[aLine[6]].Length() + 1
- Loop, % aLine[2]
- stacks[aLine[6]].InsertAt(des, stacks[aLine[4]].Pop())
- }
- }
- top := ""
- for i, stack in stacks
- top .= stack[stack.MaxIndex()]
- MsgBox, % top
- MakeStacks(Input) {
- stacks := []
- for i, line in StrSplit(StrSplit(Input, "`r`n 1 ")[1], "`r`n`") {
- Loop, % Ceil(StrLen(line)/4)
- {
- char := SubStr(line, 2 + (4 * (A_Index-1)), 1)
- if (char != A_Space) {
- if !stacks[A_Index]
- stacks[A_Index] := []
- stacks[A_Index].InsertAt(1, char)
- }
- }
- }
- Return stacks
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement