pgm 12.6 -- use N rather than N-1 as upper bound with pointer arithmetic because it's safe and a bit simpler