I don't like telling people how to solve their problem; it feels like doing their homework even if it isn't homework. Far better to teach them some resources so they can solve their own problem, today, tomorrow and next week.
Some thoughts about that
- you can't teach resources, however, you can teach skills :)
- you can't teach while ignoring the question asked
- you can't teach while being vague, anecdotally platitudinous
- you can't teach something already learned
Ok, well, actually you can teach by doing all that, but only that sundialsvc4 is super fantastic problem solver with help from state-machine logic.
:(
The OP had almost working code, sample input data, and used code tags!
The OP already did everything suggested sundialsvc4 and more, only missing unpack.