from util import * def p1(): # Language rule 1, n is less than or equal to 2 n = 2 # Language rule 2, m is less than or equal to n m = n strings = [] # Language rule 3, n and m are both non-negative integers for i in range(0, n + 1): for j in range(0, m + 1): if j > i: continue strings.append('0' * j + '1' * i) return strings def p2(): possible_n = [2, 3, 4, 5, 6] strings = [] for i in possible_n: integer_divisors = [] for j in range(1, i + 1): if i % j == 0: integer_divisors.append(j) for j in integer_divisors: strings.append('a' * j + 'b' * i) return strings def p3(): possible_n = [1, 2, 3] strings = [] for i in possible_n: an = i bn = 2 * i - 1 cn = 3 * i - 2 strings.append('a' * an + 'b' * bn + 'c' * cn) return strings def p4(): alphabet = ['a', 'b'] # include empty string strings = get_all_strings_with_a_given_alphabet_and_length(alphabet, 3) def is_palindrome(s): return s == s[::-1] strings = list(filter(is_palindrome, strings)) return strings def main(): print_strings(p1()) print_strings(p2()) print_strings(p3()) print_strings(p4()) if __name__ == '__main__': main()