Solved some logic and codes problems