Skip to content

Instantly share code, notes, and snippets.

View PineappleRind's full-sized avatar
🙃

pr PineappleRind

🙃
View GitHub Profile
@PineappleRind
PineappleRind / hamming.js
Created February 14, 2022 16:43
Dynamic JavaScript function for hamming codes
// 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