in reply to Manipulating Arrays

it looks like a task for AI::Prolog...