Epic interview question

Terminal number parser.