my solution to knr problems