All problems
Hamming Ball Volume
Problem
Return the number of binary words of length n within Hamming distance t of a fixed word, which is the sum of C(n, k) for k from 0 to t. Values of t above n are clamped to n. Return the count as an integer, and return 0 when t is negative.
Hint
A word at distance k differs in exactly C(n, k) patterns.
Test cases
case 1
in: [7,1]
expected: 8
case 2
in: [7,0]
expected: 1
case 3
in: [5,5]
expected: 32
case 4
in: [3,2]
expected: 7
case 5
in: [10,2]
expected: 56
Starter codePython
import math
def hamming_ball_volume(n, t):
# Your code here
pass5 test cases · run your code against them in the editor