Skip to main content
deleted 5 characters in body
Source Link
Rhaixer
  • 2.5k
  • 13
  • 36

Python, 44 39 65 40 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because mathcatOP didn't say that 0's had to be prefixed to the parity bits, but doesn't matter since Neil found a shorter solution.

lambda m,n:m+bin(m.count('1')+2**n)[-n:] 

Python, 44 39 65 40 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because mathcat didn't say that 0's had to be prefixed to the parity bits, but doesn't matter since Neil found a shorter solution.

lambda m,n:m+bin(m.count('1')+2**n)[-n:] 

Python, 44 39 65 40 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because OP didn't say that 0's had to be prefixed to the parity bits, but doesn't matter since Neil found a shorter solution.

lambda m,n:m+bin(m.count('1')+2**n)[-n:] 
added 34 characters in body
Source Link
Rhaixer
  • 2.5k
  • 13
  • 36

Python, 44 39 65 6540 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because mathcat didn't say that 0's had to be prefixed to the parity bits, but doesn't matter since Neil found a shorter solution.

deflambda p(m,n):x=binm+bin(m.count('1')%2**n+2**n)[2:];return m+"0"*(n[-len(x))+xn:] 

Python, 44 39 65 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because mathcat didn't say that 0's had to be prefixed to the parity bits.

def p(m,n):x=bin(m.count('1')%2**n)[2:];return m+"0"*(n-len(x))+x 

Python, 44 39 65 40 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because mathcat didn't say that 0's had to be prefixed to the parity bits, but doesn't matter since Neil found a shorter solution.

lambda m,n:m+bin(m.count('1')+2**n)[-n:] 
destroyed explanation, rewrote entire code
Source Link
Rhaixer
  • 2.5k
  • 13
  • 36

Python, 44 39 3965 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because mathcat didn't say that 0's had to be prefixed to the parity bits.

lambdadef p(m,n):m+binx=bin(m.count('1')%2**n)[2:]];return m+"0"*(n-len(x))+x 

Explanation:

lambda Create a lambda function m, n with m, n as arguments : and return m+ the binary string with bin( the binary representation of m.count('1') the count of 1 in m %2**n modulo 2 pow n )[2:] while excluding '0b' 

Python, 44 39 bytes

m should be a binary string, while n an int.

lambda m,n:m+bin(m.count('1')%2**n)[2:] 

Explanation:

lambda Create a lambda function m, n with m, n as arguments : and return m+ the binary string with bin( the binary representation of m.count('1') the count of 1 in m %2**n modulo 2 pow n )[2:] while excluding '0b' 

Python, 44 39 65 bytes

m should be a binary string, while n an int.

Had to add 26 bytes all because mathcat didn't say that 0's had to be prefixed to the parity bits.

def p(m,n):x=bin(m.count('1')%2**n)[2:];return m+"0"*(n-len(x))+x 
added 590 characters in body
Source Link
Rhaixer
  • 2.5k
  • 13
  • 36
Loading
Source Link
Rhaixer
  • 2.5k
  • 13
  • 36
Loading