Forgot to post the solution here. I tried to solve the part 2 in code and I couldn't find any way of doing it. As usual got the hint from R website and went ahead on manual way.
Swift solution
funcpartOne(){letcomputer=Opcode.init(input)varresult:String=""varoutputs:[Int]=[]while!computer.done{outputs.append(computer.run())}outputs.map{result.append(Character(UnicodeScalar($0)!))}letgrid=result.split(separator:"\n").map{$0.map{$0}}varsum=0forrowin1..<(grid.count-1){forcolumnin1..<(grid[row].count-1){ifgrid[row][column]=="#"{ifgrid[row][column-1]=="#"&&grid[row][column+1]=="#"&&grid[row-1][column]=="#"&&grid[row+1][column]=="#"{sum+=row*column}}}}print(grid)print("Part 1 answer is :\(sum)")}funcpartTwo(){varscanLine=""letrules="""
A,B,B,A,B,C,A,C,B,C
L,4,L,6,L,8,L,12
L,8,R,12,L,12
R,12,L,6,L,6,L,8
y\n
""".map{Int($0.asciiValue!)}varrulesIndex=-1vardustCollected=0input[0]=2letcomputer=Opcode.init(input)while!computer.done{rulesIndex+=1computer.inputIds.append(rules[rulesIndex])letvalue=computer.run()dustCollected=value}print("Part 2 answer is :\(dustCollected)")}partOne()partTwo()
Forgot to post the solution here. I tried to solve the part 2 in code and I couldn't find any way of doing it. As usual got the hint from R website and went ahead on manual way.
Swift solution
Opcode and input can be found here