xxxxxxxxxx
166
var arr = [20, 21, 22, 23, 24, 25, 26];
var offset = 20;
var tw;
function setup() {
createCanvas(400, 400);
tw = ((width-offset)/arr.length)-offset;
console.log(tw);
console.log(arr);
}
function mousePressed() {
var loc=mouseX-offset;
loc/=(offset+tw);
arr[int(loc)]++;
}
function draw() {
background(220);
textSize(tw);
textAlign(LEFT);
fill(0,0,0);
for(var i=0;i<arr.length;++i)
text(arr[i], (i+1)*offset + i*tw, height/2);
var sum=0;
for(var x in arr) sum=sum+int(arr[x]);
textAlign(CENTER, CENTER);
text(sum, width/2, offset);
fill(255,0,0);
var lsum=arr[0];
var rsum=0;
for(var i=0;i<int((arr.length-1)/2);++i) {
lsum+=arr[i+1];
rsum+=arr[arr.length-i-1];
if(lsum<=rsum) {
rect(offset, height*0.85, (i+2)*(offset+tw), height*0.05);
rect(width-(i+1)*(offset+tw), height*0.85, (i+1)*(offset+tw), height*0.05);
break;
}
}
if(!check2())
check3();
}
var poss2 = [
[0,0,1,0,1,1,1],
[0,0,1,1,0,1,1],
[0,0,1,1,1,0,1],
[0,1,0,0,1,1,1],
[0,1,0,1,0,1,1],
[0,1,0,1,1,0,1],
[0,1,0,1,1,1,0],
[0,1,1,0,0,1,1],
[0,1,1,0,1,0,1],
[0,1,1,0,1,1,0],
[0,1,1,1,0,0,1],
[0,1,1,1,0,1,0],
[1,0,0,0,1,1,1],
[1,0,0,1,0,1,1],
[1,0,0,1,1,0,1],
[1,0,0,1,1,1,0],
[1,0,1,0,0,1,1],
[1,0,1,0,1,0,1],
[1,0,1,0,1,1,0],
[1,0,1,1,0,0,1],
[1,0,1,1,0,1,0],
[1,0,1,1,1,0,0],
[1,1,0,0,0,1,1],
[1,1,0,0,1,0,1],
[1,1,0,0,1,1,0],
[1,1,0,1,0,0,1],
[1,1,0,1,0,1,0],
[1,1,0,1,1,0,0],
[1,1,1,0,0,0,1],
[1,1,1,0,0,1,0],
[1,1,1,0,1,0,0],
];
// var poss2 = [
// [0,1,0,1,1,1],
// [0,1,1,0,1,1],
// [0,1,1,1,0,1],
// [1,0,0,1,1,1],
// [1,0,1,0,1,1],
// [1,0,1,1,0,1],
// [1,0,1,1,1,0],
// [1,1,0,0,1,1],
// [1,1,0,1,0,1],
// [1,1,0,1,1,0],
// [1,1,1,0,0,1],
// [1,1,1,0,1,0],
// ];
function check2() {
for(var i=0;i<arr.length-3;++i) {
if(arr[i]+arr[i+3]==arr[i+1]+arr[i+2]) {
fill(0,255,0);
ellipse((i+1)*offset + i*tw, height*0.4, tw/2, tw/2);
ellipse((i+4)*offset + (i+3)*tw, height*0.4, tw/2, tw/2);
fill(255,0,0);
ellipse((i+2)*offset + (i+1)*tw, height*0.4, tw/2, tw/2);
ellipse((i+3)*offset + (i+2)*tw, height*0.4, tw/2, tw/2);
return true;
}
}
for(var i=0;i<poss2.length;++i) {
var c=0;
var sum1=0, sum2=0;
for(var j=0;j<7;++j) {
if(poss2[i][j]==1) {
if(c==0||c==3) sum1+=arr[j];
else sum2+=arr[j];
c++;
}
}
if(sum1==sum2) {
c=0;
for(var j=0;j<7;++j) {
if(poss2[i][j]==1) {
if(c==0||c==3) fill(0,255,0);
else fill(255,0,0);
ellipse((j+1)*offset + j*tw, height*0.4, tw/2, tw/2);
c++;
}
}
return true;
}
}
return false;
}
var poss3 = [[1,0,0,0,1,1],
[1,0,0,1,0,1],
[1,0,0,1,1,0],
[1,0,1,0,0,1],
[1,1,0,0,0,1]];
function check3() {
//for(var l=0; l<7;++l) {
for(var i in poss3) {
var pos=poss3[i];
var sum1=0, sum2=0;
var p=0;
for(var x=0; x<6; ++x) {
//if(p==l) p++;
if(pos[p]==1) sum1+=int(arr[p]);
else sum2+=int(arr[p]);
p++;
}
if(sum1==sum2) {
p=0;
for(var x=0; x<6; ++x) {
//if(p==l) p++;
if(pos[p]==1) fill(0,255,0);
else fill(255,0,0);
ellipse((p+1)*offset + p*tw, height*0.4, tw/2, tw/2);
}
break;
}
}
//}
}