If I ask another time, will I get a third answer?
If we take it as read then that A is really the low four bits of the parameter input, and B is really the high four bits of that parameter, do you understand:
(1) How to build the parameter input out of A and B?
(2) How to compute Y given the parameter input and S? (Note: this part is writing function(a,s).)
(3) How to write a loop to get A or B through all of its possible values?
(4) How to set up the loops in (3) to get the specific values of the input parameter that you're supposed to get in your examples?