function y=final_state_3(i,a)
	b=[ 1 1 0 1 0 0 0 0 0;
		1 1 1 0 1 0 0 0 0;
		0 1 1 0 0 1 0 0 0;
		1 0 0 1 1 0 1 0 0;
		0 1 0 1 1 1 0 1 0;	# in matrix b, b(i,j)=1 iff button i is toggled on pressing button j
		0 0 1 0 1 1 0 0 1;
		0 0 0 1 0 0 1 1 0;
		0 0 0 0 1 0 1 1 1;
		0 0 0 0 0 1 0 1 1];

	initial=i(:);			# converts initial matrix i of order 3*3 into order 9*1
	action=a(:);			# converts action matrix a of order 3*3 into order 9*1
	x=b*action+initial; 	
	y=[ 0 0 0;
		0 0 0;
		0 0 0];
	for i=1:9
		y(i)=rem(x(i),2);	#converts back x of order 9*1 into y matrix of order 3*3 and takes modulo with 2
	endfor

	return;

endfunction