Question
The instructions for this assignment is very vague and I need help fixing and finishing the rest. The code should be in python and not
The instructions for this assignment is very vague and I need help fixing and finishing the rest. The code should be in python and not that advanced. This is all the information I have, sorry
import sys
''' provided strings are immutable, but lists are mutable replace(s,i,c) turns string s into a list, replaces s[i] with c, then turns the list back into a string and returns it ''' def replace(s,i,c): s=list(s) s[i]=c s = ''.join(s) return s
''' return a string with n c-s ''' def stringn(n,c): str = ""; for i in range(0, n): str += i i += 1 return str
''' given bit string bs of size n, return the next (boolean increment) e.g. '00000' -> '00001' '01011' -> '01100' '11111' -> '00000' ''' def next(bs,n): '''use replace''' x = list(bs) for i in range(bs): if(x[i] == '0'): x[i] = '1' break else: x[i] = '0' i -=1 return x
''' return the set of all length n>=2 bitstrings that start with '11' or end with '1' ''' def s11x1(n): if(n <= 3): return ('1' * n) return ('1' * n)
''' return the set of all length n>=2 bitstrings that start with '11' ''' def s11x(n): return "0"
''' return the set of all length n>=2 bitstrings that end with '1' ''' def sx1(n): return "0"
''' provided ''' if __name__ == "__main__": # sets of bit strings size n n = int(sys.argv[1]) if n<2: print( 'argument must be>= 2' ) sys.exit() s3 = s11x1(n) print( 'len(s3) =', len(s3) ) s2 = s11x(n) print( 'len(s2) =', len(s2) ) s1 = sx1(n) print( 'len(s1) =', len(s1) ) print( 'len(s1&s2):', len(s1&s2) ) print( 's3 == s2|s1:', s3 == s2|s1 ) print( 'len(s3) == len(s2)+len(s1)-len(s2&s1):', len(s3) == len(s2)+len(s1)-len(s2&s1) )
Here is the expected output for 2 when ran through
len(s3) = 2
len(s2) = 1
len(s1) = 2
len(s1 & s2): 1
s3 == s2 | s1: True
len(s3) == len(s2) + len(s1) - len(s2&s1): True
Here is the expected output for 6 when ran through
len(s3) = 40
len(s2) = 16
len(s1) = 32
len(s1&s2): 8
s3 == s2 | s1: True
len(s3) == len(s2) + len(s1) - len(s2&s1): True
Here is the expected output for 7 when ran through
len(s3) = 80
len(s2) = 32
len(s1) = 64
len(s1&s2): 16
s3 == s2 | s1: True
len(s3) == len(s2) + len(s1) - len(s2&s1): True
Here is the expected output for 10 when ran through
len(s3) = 640
len(s2) = 256
len(s1) = 512
len(s1&s2): 128
s3 == s2 | s1: True
len(s3) == len(s2) + len(s1) - len(s2&s1): True
Here is the expected output for 15 when ran through
len(s3) = 20480
len(s2) = 8192
len(s1) = 16384
len(s1&s2): 4096
s3 == s2 | s1: True
len(s3) == len(s2) + len(s1) - len(s2&s1): True
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