xxxxxxxxxx
90
let input = ["010000010010","011001011100","110011011101","110100100001","000110011110","110101000101","100110111001","110000000000","100101100111","001001011000","010010011010","001110111000","001011111010","110010111011","001001010101","111111011111","101001001110","011001000101","001001111100","000101110000","101000101101","101000011101","011011001111","010100011001","100010001000","100010111010","000110101100","100101010111","110111101111","011101111001","111001110110","101101000000","010010111101","111101111101","010000001110","000111111001","010111100101","011101100000","001011011111","111010000110","111010001001","000000010111","001110011110","100011100010","111110010111","100111111111","100000011011","000110111101","010100010111","110000011111","011011011001","101110011100","010110001111","101010111001","100010011111","011110110101","001001101010","000001001000","101101011000","101100001111","000110000011","011011100001","010011100001","101111011100","110110100000","010100010000","110111111000","110000110111","011000000101","001100011111","111000011010","000110101010","011000101001","110010100110","100011111010","011111000111","010001100101","101000011110","011110010010","111001100000","000011011010","000011111110","101001001001","100110010010","110101010111","010011111000","010111001111","010101001011","111001010100","011001011001","110011110111","110001001011","101101001011","000110010111","110110111010","001001100110","111010011011","001101000101","100110001011","010000101000","101111001011","110011011110","011110111001","101100000010","010101101101","010100001010","000111010101","001100000111","010001010010","001110000110","000001010000","100010000101","010010101101","011000110110","111111100000","111111010011","010100010001","101011000010","111010101000","011010001010","111001000001","111010010000","101010101100","101011110110","110010100010","011001001100","100100111010","101011011101","110000001000","010011011101","000011011000","101100101111","110001111111","110010010010","001011011010","110101111110","110000111010","011100011110","110110001000","000101000001","100000010100","110000110000","110000101100","101101000001","110011101001","101110010101","110101110101","000110100000","100111101111","111101011001","110001111101","100010100001","101011111100","000011010111","110100110101","111100010100","011001110011","010000110000","110110011100","001000110101","010001111111","001000000110","101001001100","011000001011","101101010110","101100011101","001111001010","110011000010","010110111001","000011000000","011110100000","111001001010","110010100101","110001101001","001100110100","110100011111","100010001001","100101001010","110001011000","111110011111","001001000010","101011001010","110111111001","101000000111","000110000000","110011110000","111001011110","110000010010","010000101101","010010100101","011110010000","010011100011","111011100110","001001000011","110000010101","010010010100","110100100111","111111010110","111001110010","110100010010","011111111010","110000011011","001011000101","101010000010","000111100011","010000110110","111111011001","100001001001","111010011100","001111110000","010111111001","101101000111","100110011111","000000100111","111001111010","100001110000","010110101101","111111111110","101101011010","101101000011","010011001001","111111000010","011110000010","101110101101","110010110010","101111100101","101011100000","000001110111","010011011000","010011000101","101101010000","111011110111","100111111010","000001110010","010011110100","011100001010","101101001111","011101100001","001111001011","000000010101","000100110101","100111001011","000111011001","100010011110","111100100101","011010111001","011011111101","010100111011","010100110100","101111111001","110001100110","110001110001","010110100011","111111110100","011101000010","011111101111","001101001011","001010100110","111001010000","111111100110","001101001100","010110011010","011101111000","101000010111","100110010101","011000111010","011100010011","110011000111","001101010101","101110001101","000001011100","001011100111","111111010101","000110010110","100110000011","011000111011","111001011111","100001010000","001000100011","011011111111","111001001110","000001010111","001001001111","001001100010","111100101110","101101100100","000111101010","011101101110","101111001000","010101110111","100001011111","011110011111","010111010000","101100110100","001110011010","000110001100","110100101011","101010001101","010100001101","111101011111","011110111111","110100001001","101010000001","110100011001","100011011011","101001111111","111101100011","100101001100","000010101011","101111010010","100001110111","010000011100","011101110100","100000001111","100010110111","101011110101","000001000111","010011110110","000001000010","101010010010","100111110101","000010001111","001110000100","110100001101","011001001011","000100110000","000000011101","011011100000","011000001110","000011101111","110111010101","011000001010","010001111101","011111011001","001010111011","010000011111","001100000011","110110001110","100000000010","010101011010","101001100110","000110011001","110101001110","100111000111","111101101100","100101111011","011111100000","000000101011","001111011110","101100100100","010010110001","000110110001","011100111001","001011000100","111100001101","100010001101","010101010111","001011101110","110111101110","000010000101","101111001111","101110000000","010000011110","101111000101","000101001011","011101000100","001001111110","001001111111","100111000110","000101110010","011001001111","100000111110","101000001100","001110010001","010101011111","010110001101","000001000101","010100111101","100000101010","111111111101","011111001101","111000001111","100100001011","101111010011","111111110111","100101111111","100111100111","011000110111","011010000001","010010110000","111000110100","111100010110","100010100111","011010111111","110101100011","001111100001","101001011110","100011110011","100111110111","100000100100","111010110011","001011100101","101101010001","111010111110","000100010110","111101001111","101001001111","000001010101","111011101001","010101111111","111110101000","101101111011","010100001100","101011110001","010011101111","011001001001","001000001001","100100011111","010111100001","111101011110","110011110101","100101000010","100011110001","000111111010","010001011111","011110011011","100100000000","011010011001","010001100000","011111001100","101011000110","110100101110","101000111011","011011001000","100111000010","101110011101","000110000001","001101001101","100110011000","011110111010","110101010000","100100111000","011111000011","111101010101","100011101100","000101110100","010110101010","101001111110","011100010110","001100010100","010101110001","100101110111","110110100101","100011000011","100101000101","001111110011","101100010111","001011110101","001010110001","110000010011","100111100100","100110110010","101101110110","000100101011","101111100100","011010110110","101110010111","000010101110","001000000111","100000110110","001000000000","111011101000","111011011001","000011111011","000010101101","011100111011","000111010000","000010110001","011100110101","001111110111","000110100011","010010001010","010100000001","111101101101","010010010011","110101100100","011001010100","100101110100","110111011100","110001110011","011011001011","110011011011","101110101111","111011000001","110010001111","000001000000","101101111100","000111000001","000001011001","110100110000","110101011100","010110011000","010110010000","010110000011","010010010000","100001100010","011110110001","111100101010","101111111010","101010110001","000110011011","010110000001","001110111001","000111101011","010110110110","000000000101","000100010000","110000010000","001011011101","011111000101","001110101010","101110110111","110101110111","101111000110","110110000011","110001110010","011111101000","010111100110","011100111111","111101100100","110111110100","100010010000","110101000111","111000000111","111111011010","100001111010","010011011100","011011100101","110100101000","001101110010","000010110100","110001010101","100000011100","101101100111","011100111110","111110001110","010011101101","001001001110","011001100001","001010010100","010011010011","001111100010","001110001100","011011010010","010100000100","011010010011","101110011010","001111101000","001110011011","000001111110","110110101001","101000000110","000010000111","100111111001","110111001101","110101101011","110101100110","101010110011","000110100001","110011100100","001011101101","011001001010","100101100110","010001100001","110110001101","100111011001","100100111100","000001111010","110000111011","110101100000","001111111111","010010100110","001011111100","111011000110","101011010110","001100011110","010010010001","011001110111","110110110001","010110100000","110010011001","001111000001","100100010100","000001111100","000011101001","101001110010","011100000111","001000011110","010001111100","010010110100","110000111000","100100001100","010111100010","010010001000","100110001110","111101110100","011111011000","001000110000","000010100000","010111000000","001111101110","000111110101","001000001011","111100001001","011010011111","011101101111","000101011011","000100000101","001000010101","000011000001","011011010100","011101100101","000010110111","001101000011","000111001000","001010000111","111010101110","100001111111","101101110000","010111011101","111010111000","011111000110","011100001011","101011100110","011011100100","010010000001","001100101011","000110111010","010110011101","010100101101","100001100101","011011010111","111010111001","111000001010","100101011110","001000011001","101001101001","011111000001","010010111110","101110110110","111110010011","100111011100","001100100011","100010101100","111100001110","010101101111","010001000111","110101111010","011100100101","110001010011","000011100001","001010111001","011100011010","010101010101","001011000000","101011110111","011001110010","010000001011","000011100010","010010000011","011001111010","000101011100","111010000101","001011111011","011011101101","100100110111","111000101010","100001110101","101110010100","000001100111","101001101111","100000001100","110000101000","110111011010","010001001010","000100000001","110110101011","011111101011","101001100010","000111100001","010010001011","101001010110","011011100011","000111011101","100000100101","000010100011","111010001011","111110111111","101000111000","110100100011","010001110010","001000010000","111101011011","110100011011","010101100110","010001101111","001111011111","101111110110","011011101111","000010101111","000000110011","011011000111","010001000110","010111101111","110101011111","001001000111","011011001110","100111110110","111100100001","111010100010","010010000010","000111110111","111101000100","000011110011","111000101111","110010011111","000001101001","001110101001","011111101110","110111010010","011100110010","100011000111","000000010011","011011111100","011110010101","110111101011","011001111101","010101010110","011110011001","111100011100","011001010001","000110110101","000111010010","101011101011","101010100000","011101011001","001110111111","011011010110","110111100001","100011111011","001010011101","111001101101","011100001000","011010011100","100111010011","000010010110","010110010001","111010010110","111111110101","100011000101","011010001001","111010001010","000100000110","011010001000","100110101001","010111111011","010111100011","011101010100","101000011001","101001110111","111001010101","100110111111","111010110110","100000011000","110010100001","001110011111","010001011010","011100100011","010111011110","100110110100","111000001000","110110101000","000000001111","010111101010","000100000100","111000110010","011111110011","001100100001","010100000111","111010100111","010001101110","101111110010","011111000100","101100111110","010111101100","011110111000","110001000100","011101000111","011011101000","000100100110","100110100110","000000001011","010101001111","110001000001","100011010011","101000100011","011011010011","100010001110","100111101001","101111111111","111010011001","011000010100","110101011101","100110101011","010000011001","010011011001","010101000101","010100011111","100111001000","111110100011","000110010010","000000010010","101110001100","111010000011","100001001000","000011010101","000100011000","001111111100","011110101000","101111011111","100000111011","101001100011","001001100100","000100010100","010111101101","101001111010","011000101011","111011010010","011001101001","011101010110","011011110011","010010101010","001111010100","100000010110","001101000111","000010101010","110010001001","011001111100","000100001000","010111001011","101111100111","100111100011","100001010101","100111011011","100101000110","011010100110","100011101110","111010110010","010000100000","100100110110","011001101101","011111100100","101100101101","101010110100","101001000111","110100010100","011101001000","101110101100","111100010001","001101011101","111111110110","101110001011","001100101111","110000001010","110011001000","011100000110","011001101000","001100001011","111000111011","111100000111","010000000001","000101011111","001000101110","101101101011","111111110010","111000001110","110101111100","101100010011","010011110111","100100010111","111001101001","101000001011","110001110111","100011111100","000101011110","011000101000","001010011110","100111111110","100000111010","001111010101","011111010100","001101101100","010011111001","001010101100","001110111101","000101010000","100101101011","010100101010","000000001001","010011000100","010001000100","110101100101","110011011111","100001010111","111111011000","010111111100","111000101000","101011101100","111111011100","001110110100","000010100010","111101110001","101011000000","101101000101","110000000100","110111111101","101110100110","111011000000","001011010000","100100101001","111110101010","111011110011","111000000011","000101101001","110100011100","111101000000","100000100001","010110001011","001100111011","110000100010","111001010111","100100001111","110111111110","010111000101","110000010111","100011010000","101010110111","011100101110","001110001000","110011100001","100101001110","110110110110","101110001001","011011001001","110000101101","001000001101","001000000010","110110010000","011110001100","100001011101","000001010100","010100111110","101110111111","101010101110","001100010000","100000001011","010011101100","101011011001","111100000000","011011110001","001110001110","010100100101","111011101100","011110101101","010110100010","101010001111","110110000101","101000110110","101101001110","111111101111","001001110010","001001011010","111100100110","000101010011","100100001000","110111010000","010010001111","000000100101","001101110100","101010110010","011110010111","100011001110","111011010011","110011111001","110100100100","110101001000","110001111011","010110001100","011110111100","010100000101"]
function setup() {
createCanvas(400, 400);
calc2(input);
}
function draw() {
background(220);
}
function calc2(input) {
let o = JSON.parse(JSON.stringify(input));
let c = JSON.parse(JSON.stringify(input));
let ox = find(o, true);
let co = find(c, false);
print(ox, co);
console.log(parseInt(ox, 2) * parseInt(co, 2));
}
function find(a, c) {
let idx = 0;
while(a.length > 1) {
let i = [];
let o = [];
let num = 0
for(let j = 0; j < a.length; j ++) {
if(a[j][idx] == "1") {
num ++;
i.push(a[j]);
} else {
o.push(a[j]);
}
}
if(c) {
if(num >= a.length/2) {
a = i;
} else {
a = o;
}
} else {
if(num < a.length/2) {
a = i;
} else {
a = o;
}
}
idx ++;
}
return a[0];
}
// part 1
// 010111011111 101000100000
// 3895776
function calc(input) {
let num1s = [0,0,0,0,0,0,0,0,0,0,0,0]
for(let i = 0; i < input.length; i++) {
for(let j = 0; j < input[0].length; j ++) {
if(input[i][j] == "1") {
num1s[j] ++;
}
}
}
return num1s;
// let g = "";
// let e = "";
// for(let i = 0; i < num1s.length; i ++) {
// if(num1s[i] > input.length/2) {
// g += "1";
// e += "0";
// } else {
// g += "0";
// e += "1";
// }
// }
// console.log(g, e);
// console.log(parseInt(g, 2) * parseInt(e, 2));
}