Skip to content

Instantly share code, notes, and snippets.

@pony012
Created May 15, 2011 20:06
Show Gist options
  • Save pony012/973485 to your computer and use it in GitHub Desktop.
Save pony012/973485 to your computer and use it in GitHub Desktop.
genetica
#include <iostream>
using namespace std;
bool isprime(int n);
int main(){
int n,i,j;
cin>>n;
fflush(stdin);
char cpadre[n],cmadre[n],temp;
short int padre[n],madre[n],hijo[n];
cin.getline(cpadre,n+1);
fflush(stdin);
cin.getline(cmadre,n+1);
fflush(stdin);
for(i=0;i<n;i++){
temp=cpadre[i];
padre[i]=atoi(&temp);
temp=cmadre[i];
madre[i]=atoi(&temp);
}
for(i=0; i<n; i+=4){
hijo[i]=isprime(padre[i]+padre[i+2])?padre[i]:padre[i+2];
hijo[i+1]=isprime(madre[i]+madre[i+2])?madre[i]:madre[i+2];
hijo[i+2]=isprime(padre[i+1]+padre[i+3])?padre[i+1]:padre[i+3];
hijo[i+3]=isprime(madre[i+1]+madre[i+3])?madre[i+1]:madre[i+3];
}
for(i=0; i<n; i++)
cout<<hijo[i];
}
bool isprime(int n){
int i=2;
for(i; i<n; i++)
if(n%i==0) return 0;
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment