Question
PYTHON CODE Part A - Palindromic Bitlists Write a function palindrome binary(n) which returns a list of bitlists of length n, where every bitlist is
PYTHON CODE
Part A - Palindromic Bitlists
Write a function palindrome binary(n) which returns a list of bitlists of length n, where every bitlist is a palindrome. The returned list of bitlists must be in lexicographical order (think about the order of your options). You must use backtracking to solve this problem (i.e. do not use brute force).
Calling (palindrome_binary, 1) will return [[0],[1]]
Calling (palindrome_binary(3)) will return [[0,0,0],[0,1,0], [1,0,1], [1,1,1]]
Calling (palindrome_binary(5)) will return [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [1, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1]]
Calling (palindrome_binary(2)) will return [[0,0],[1,1]]
Calling (palindrome_binary(4)) will return [[0,0,0,0],[0,1,1,0], [1,0,0,1], [1,1,1,1]]
Do not use bin or zfill function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started