Предполагая, что предикаты findall, length, nth0 существуют в вашей реализации пролога:
(Ниже приведен след от пролога)
A = [3,6,7,9],
B = [2,6,4,9],
findall(Y, ((nth0(X, A, Y), nth0(X, B, Y))), Y),
length(Y, LenY),
write(LenY), write(' Bulls Found').
[trace] ?- A = [3,6,7,9],
B = [2,6,4,9],
findall(Y, ((nth0(X, A, Y), nth0(X, B, Y))), Y),
length(Y, LenY),
write(LenY), write(' Bulls Found').
Call: (7) _G2814=[3, 6, 7, 9] ? creep
Exit: (7) [3, 6, 7, 9]=[3, 6, 7, 9] ? creep
Call: (7) _G2829=[2, 6, 4, 9] ? creep
Exit: (7) [2, 6, 4, 9]=[2, 6, 4, 9] ? creep
^ Call: (7) findall(_G2834, (nth0(_G2832, [3, 6, 7, 9], _G2834), nth0(_G2832, [2, 6, 4, 9], _G2834)), _G2834) ? creep
Call: (13) lists:nth0(_G2832, [3, 6, 7, 9], _G2834) ? creep
Exit: (13) lists:nth0(0, [3, 6, 7, 9], 3) ? creep
Call: (13) lists:nth0(0, [2, 6, 4, 9], 3) ? creep
Fail: (13) lists:nth0(0, [2, 6, 4, 9], 3) ? creep
Redo: (13) lists:nth0(_G2832, [3, 6, 7, 9], _G2834) ? creep
Exit: (13) lists:nth0(1, [3, 6, 7, 9], 6) ? creep
Call: (13) lists:nth0(1, [2, 6, 4, 9], 6) ? creep
Exit: (13) lists:nth0(1, [2, 6, 4, 9], 6) ? creep
Redo: (13) lists:nth0(_G2832, [3, 6, 7, 9], _G2834) ? creep
Exit: (13) lists:nth0(2, [3, 6, 7, 9], 7) ? creep
Call: (13) lists:nth0(2, [2, 6, 4, 9], 7) ? creep
Fail: (13) lists:nth0(2, [2, 6, 4, 9], 7) ? creep
Redo: (13) lists:nth0(_G2832, [3, 6, 7, 9], _G2834) ? creep
Exit: (13) lists:nth0(3, [3, 6, 7, 9], 9) ? creep
Call: (13) lists:nth0(3, [2, 6, 4, 9], 9) ? creep
Exit: (13) lists:nth0(3, [2, 6, 4, 9], 9) ? creep
^ Exit: (7) findall([6, 9], user: (nth0(_G2832, [3, 6, 7, 9], [6, 9]), nth0(_G2832, [2, 6, 4, 9], [6, 9])), [6, 9]) ? creep
Call: (7) length([6, 9], _G2848) ? creep
Exit: (7) length([6, 9], 2) ? creep
Call: (7) write(2) ? creep
2
Exit: (7) write(2) ? creep
Call: (7) write(' Bulls Found') ? creep
Bulls Found
Exit: (7) write(' Bulls Found') ? creep
A = [3, 6, 7, 9],
B = [2, 6, 4, 9],
Y = [6, 9],
LenY = 2.