num(1..5). top5(5..9). top(9). top5num(1..X-4,5..X) :- num(X-4..X), top5(1..5), top(X).