16 lines
627 B
JavaScript
16 lines
627 B
JavaScript
curve = (state)=>(state + "0" + state.split("").reverse().map((char)=>((char == "0") ? "1" : "0")).join(""));
|
|
curveLoop = (str, len)=>{
|
|
next = curve(str);
|
|
console.log(next.length);
|
|
return (next.length >= len) ? (next.substr(0, len)) : curveLoop(next, len);
|
|
};
|
|
checksum = (str)=>(str.split("").reduce((a, b, i, arr)=>{
|
|
if(i%2 == 0){
|
|
a.push([b, arr[i+1]]);
|
|
}
|
|
return a;
|
|
}, [])).map((pair)=>((pair[0] == pair[1]) ? "1" : "0")).join("");
|
|
checksumLoop = (str) => {var sum = checksum(str); return (sum.length%2 == 0) ? (checksumLoop(sum)) : (sum)}
|
|
|
|
console.log(checksumLoop(curveLoop("01000100010010111", 35651584)));
|