An Algorithm for Three-input Majority Logic Design