--- Day 5: Christmas Ornament Quality Control ---
You've spent the last night staring at the (gingerbread) ceiling, reassessing your life in terms of PJ and AJ; Pre-Jollyscript and After-Jollyscript. It is, in fact, the only language optimised for festive efficiency. Your life will never be the same. Perhaps you can put it on your CV?
It isn't long before Patch comes barging in again -- in his festiveness he trips, falls, during the fall trips again, and somehow inverts the original falling operation. You have seen JollyScript now. Nothing can phase you.
"Great job yesterday -- I was really pulling my ears over that microservice!" Patch beams.
"Now, if you don't mind, for your next task! We at the North Pole (famously) believe in objective morality. Naughty, Nice, all things can be boiled down to a binary! No exceptions!"
He proceeds to somehow pull a bauble larger than his head out of his pocket. But you have seen JollyScript now. Nothing can phase you.
"The same goes for our Christmas ornaments, we need to send only the Nicest to our retail partners. Of course the only way to assess these ornaments' Niceness is to compare them to each other -- and what better way than a trial by combat?"
"Santa's getting a little antsy about wastage though, something something 'microplastics' 'sustainability' 'our continent is literally melting' yadda yadda. Can you assess how many ornaments are getting trashed in our quality control process?"
As per tradition, the Ornament Quality Control department positions ornaments in a line, and shoots them in a random direction towards each other -- either left or right. Each ornament has a direction and a Niceness, and all move at the same speed. When two ornaments collide, they abide by the following rules:
You will be given a list of integers representing the ornaments. The absolute value of the integer represents the Niceness of the ornament, and the sign represents the direction it's been shot in.
For example, if the input ornaments list is [20,7,-8]
:
[20]
, and the amount of ornaments destroyed is 2
.The input file will be formatted as follows:
N
.n
.
You need to calculate how many ornaments are destroyed in each quality control run: the answer is the total number of destroyed ornaments across all quality control runs.