All problems
Code Rate from Codewords
Problem
For a possibly nonlinear binary code with M codewords of block length n, the rate is log2(M) / n bits per channel use. Return that rate for M >= 1 and n >= 1, so a code with a single codeword has rate 0.0.
Hint
log2(M) is the number of message bits the codebook can carry.
Test cases
case 1
in: [16,7]
expected: 0.5714285714285714
case 2
in: [8,3]
expected: 1
case 3
in: [2,5]
expected: 0.2
case 4
in: [1,4]
expected: 0
Starter codePython
import math
def code_rate_from_codewords(m, n):
# Your code here
pass4 test cases · run your code against them in the editor