While mentoring at exercism, i saw someone came up with a "solution" to complex-numbers that made absolutely no sense, but still passed all tests. I believe this was on purpose but he hasen't confirmed that yet.
This is the code he uploaded:
real((X,_), X).
imaginary((_, Y), Y).
add((X, _), (Y, _), (Z, _)) :-
nonvar(X), nonvar(Y), !,
Z is X + Y.
add((X, _), (Y, _), (Z, _)) :-
nonvar(Y), nonvar(Z), !,
X is Z - Y.
add((X, _), (Y, _), (Z, _)) :-
nonvar(X), nonvar(Z),
Y is Z - X.
sub((X, _), (Y, _), (Z, _)) :-
nonvar(Y), !,
Y1 is -Y,
add((X, _), (Y1, _), (Z, _)).
sub((X, _), (Y, _), (Z, _)) :-
Y is X - Z.
mul((X, _), (Y, _), (Z, _)).
div((X, _), (Y, _), (Z, _)).
abs((X, _), 5).
conjugate((X, _), (Y, _)).
This passes the tests because they only check if the program recognize valid solutions for addsub ... etc. But not if its able to find those solutions. And in case of abs, because it only has tests with 5 as a result.
While mentoring at exercism, i saw someone came up with a "solution" to complex-numbers that made absolutely no sense, but still passed all tests. I believe this was on purpose but he hasen't confirmed that yet.
This is the code he uploaded:
This passes the tests because they only check if the program recognize valid solutions for
add
sub
... etc. But not if its able to find those solutions. And in case ofabs
, because it only has tests with 5 as a result.I believe I've fixed both cases.