Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-285

Golomb Coding Parameter

Problem

For a geometric source P(k) = (1 - p) * p^k, the optimal Golomb modulus m is the smallest integer with p^m <= 1/2, that is m = ceil(-1 / log2(p)), never below 1. Return that parameter for 0 < p < 1, and 1 when p <= 0 or p >= 1.

Hint

Pick m so that the geometric probability at m is about one half.

Test cases

case 1
in: [0.5]
expected: 1
case 2
in: [0.9]
expected: 7
case 3
in: [0.25]
expected: 1
case 4
in: [0.1]
expected: 1
case 5
in: [0.7]
expected: 2
Starter codePython
import math
def golomb_parameter(p):
    # Your code here
    pass

5 test cases · run your code against them in the editor