This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Implementation in JavaScript of the Python script outlined in 3Blue1Brown's video | |
// https://www.youtube.com/watch?v=X8jsijhllIA | |
function hamming(e) { | |
let t = []; | |
for (let n = 0; n < bits.length; n++) e[n] && t.push(n); // create array of the indices of only the bits that are 1 | |
return (t = t.reduce((e, t) => e ^ t)) || false && t // reduce by bitwise XOR | |
} | |
// Function takes in bit array, and returns the bit index that is wrong, or nothing if nothing is wrong | |
// Haven't tested how well it scales |