Skip to content

Instantly share code, notes, and snippets.

@jen6
Created May 17, 2017 11:02
Show Gist options
  • Save jen6/e8235169246be802c79dfd87c1123c0b to your computer and use it in GitHub Desktop.
Save jen6/e8235169246be802c79dfd87c1123c0b to your computer and use it in GitHub Desktop.
#include <iostream>
static int w[] = {20,20,20};
static int x0 = 1;
const int kwAdd = 5;
bool twoPercep(int x1, int x2)
{
int x[3] = {0,};
x[0] = x0;
x[1] = x1;
x[2] = x2;
int sum = 0;
for(int i =0; i < 3; ++i) {
sum += w[i] * x[i];
}
if(sum < 0)
return false;
else
return true;
}
int main() {
int test[4][3] = {
{0, 0, 0},
{0, 1, 0},
{1, 0, 0},
{1, 1, 1}
};
bool result[4] = {0, 0, 0, 0};
auto checkIt = [&]() {
for(int i = 0; i < 4; ++i){
if(!result[i])
return false;
}
return true;
};
while(true){
for(int i = 0; i < 4; ++i) {
if(test[i][2] == twoPercep(test[i][0], test[i][1]))
result[i] = true;
else
result[i] = false;
}
if(checkIt())
break;
for(int i = 0; i < 4; ++i) {
if(!result[i]){
w[0] -= kwAdd;
w[1] -= kwAdd * test[i][0];
w[2] -= kwAdd * test[i][1];
}
else {
w[0] += 1;
w[1] += test[i][0];
w[2] += test[i][1];
}
}
for(int i = 0; i < 3; ++i)
std::cout << "w" << i << " : " << w[i] << std::endl;
std::cout << "--------------------------" << std::endl;
}
std::cout << "---------result--------------" << std::endl;
for(int i = 0; i < 3; ++i)
std::cout << "w" << i << " : " << w[i] << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment