class ALU {

	public String claAdder (String operand1, String operand2, char c) {
		StringBuilder result = new StringBuilder();
		BiFunction<Character, Character, Integer> pi = (x,y)->charOp(booleanOr, x, y)=='1' ? 1 :0;
		BiFunction<Character, Character, Integer> gi = (x,y)->charOp(booleanAnd, x, y)=='1' ? 1 :0;
		
		int p1 = pi.apply(operand1.charAt(3), operand2.charAt(3));
		int g1 = gi.apply(operand1.charAt(3), operand2.charAt(3));
		int p2 = pi.apply(operand1.charAt(2), operand2.charAt(2));
		int g2 = gi.apply(operand1.charAt(2), operand2.charAt(2));
		int p3 = pi.apply(operand1.charAt(1), operand2.charAt(1));
		int g3 = gi.apply(operand1.charAt(1), operand2.charAt(1));
		int p4 = pi.apply(operand1.charAt(0), operand2.charAt(0));
		int g4 = gi.apply(operand1.charAt(0), operand2.charAt(0));
		
		int c1= g1 | (p1 & c);
		int c2 =g2 | (p2 & g1) | (p2&p1 & c);
		int c3=g3|(p3 &g2) | (p3&p2&g1) | (p3&p2&p1&c);
		int c4=g4|(p4 & g3)|(p4&p3&g2) | (p4&p3&p2&g1) | (p4&p3&p2&p1&c);
		
		result.append(c4);
		result.append(fullAdder(operand1.charAt(0), operand2.charAt(0) , c3==1 ? '1' : '0').charAt(1));
		result.append(fullAdder(operand1.charAt(1), operand2.charAt(1) , c2==1 ? '1' : '0').charAt(1));
		result.append(fullAdder(operand1.charAt(2), operand2.charAt(2) , c1==1 ? '1' : '0').charAt(1));
		result.append(fullAdder(operand1.charAt(3), operand2.charAt(3) , c).charAt(1));	
		return result.toString();
	}

}