Hey everyone I have a problem in solving this assignment for my university Prolog class, if anyone can help me I will be grateful
Thanks in advance.
Hey everyone I have a problem in solving this assignment for my university Prolog class, if anyone can help me I will be grateful
Odd, that an exercise with a cut operator is provided as a first assignment, for bidirectional use of predicates.
Have a look at Markus Trishka’s online book: The Power of Prolog
To get some hints how to get started with Prolog.
maybe something like this?
symetric_encryp_decryp( 0, 1, 1 ):-!.
symetric_encryp_decryp( 1, 0, 1 ):-!.
symetric_encryp_decryp( 0, 0, 0 ):-!.
symetric_encryp_decryp( 1, 1, 0 ):-!.
xor( [ ], [ ], [ ] ):- !.
xor([ Xbit | Rest_text], [Ybit | Rest_key ], [Result_bit | Result_rest ] ):-
symetric_encryp_decryp( Xbit, Ybit, Result_bit ),
xor( Rest_text, Rest_key , Result_rest ).
test:-
xor( [1,1] , [0,1], Z ),
write("result encrypt "), write_term( Z, [] ), nl,
xor( Z , [0,1], Y ),
write("result decrypt "), write_term( Y, [] ), nl.
I think you can get rid of every single of the five (5) cuts in this code snippet without changing the behaviour of the program on SWI-Prolog.
It is a small mystery how and why you’d use the cut operator or append/3 to program this. Could you provide any additional info on that? Maybe there is something in this “SEAR module” (??) that would provide hints?
through Visual Prolog i am used to placing cuts everywhere to make minimum backtracks
it seems that in this case, the cuts don’t add anything that indexing already determined – i guess, because the encrypt relationship is functional in both/all directions …
Thanks for your reply, can you elaborate your answer in plain English, so I can understand how it is solved. Again, thanks!