1. 15 points

// keep_indices(P, L) keeps the indices of all elements in a list satisfying P

keep_indices(P, L) = keep_indices(P, 0, L);

// We use an auxiliary function that counts upward in indices as it 
// decimates the list.  The second argument is the counter.

// For the empty list, there is nothing to keep.

keep_indices(P, N, []) => [];

// If the first element satisfies P, then we start the list with that
// element's index, and continue recursively.

keep_indices(P, N, [A | L]) => P(A) ? [N | keep_indices(P, N+1, L)];

// If the first element does not, then continue recursively.

keep_indices(P, N, [A | L]) => keep_indices(P, N+1, L);