Simplified and partially rewritten.

OK, so maybe more than partially. You were missing the edge condition (literally). Every time you map a row of triples to the next row the first and last values are lost. For example a 3-element row (0 1 0) might map to (1), but then you need to put something back in to pad it out to it's correct size (concat [0] intermediate-result [0]) or whatever.