I’m totally stuck on this one. Can one of you fine scholars help?

Basically, I have a list with a length of 16, consisting of 0s and 1s.

It’s hard to explain, but for every 1 in the list, I want to replace it with the total of all subsequent 1s, until I hit a 0.

I know that sounds confusing. Here’s an example:

If I have the list

1 1 1 0 0 1 1 0 1 0 0 0 1 1 1 0

it would look at the first digit, see that it’s a 1, then look at the 2nd digit, see that it’s a 1, then look at the 3rd digit, see that it’s a 1, then look at the 4th digit, see that it’s a 0.

Once it finds a 0 it stops looking, totals up the 1s, and replaces the first item it the list with that number.

Then it repeats for each subsequent digit in the list

Sounds ridiculous, right?

The resulting list would be:

3 2 1 0 0 2 1 0 1 0 0 0 3 2 1 0

I’ve tried for the last couple hours, but I have no idea how to do this. Recursive stuff like this doesn’t seem to be Max’s forte.

Any help would be greatly appreciated!

– Pasted Max Patch, click to expand. –

]]>