Logic, Math and Programming exercise