##C++, The Scientist This one tries to, with the history of what the majority chose per round in `wave` (`majority()` gives the majority's choice on a round), fit a wave to the data, of wavelength `2*period` and phase `phase`. Thus, given `0,1,1,1,0,1,0,1,1,1,0,0,0,1,0` it selects `period=3, phase=5` (`maxat=={3,5}`): its scores become `9 3 11 5 5 3 5 7 9 7 7 7 7 7 7`. It loops over all possible periods and if, for that period, the score is higher than for the current maximum, it stores `{period,phase}` for which that occurred. It then extrapolates the found wave to the next round and takes the predicted majority. <!-- language: lang-cpp --> #include <iostream> #include <utility> #include <cstdlib> #include <cstring> #if 0 #define DBG(st) {st} #else #define DBG(st) #endif #define WINDOW (700) using namespace std; int majority(const char *r){ int p=0,a=0,b=0; while(true){ if(r[p]=='1')a++; else if(r[p]=='0')b++; else break; p++; } return a>b; } int main(int argc,char **argv){ if(argc==1){ cout<<(rand()%2?"good":"evil")<<endl; return 0; } DBG(cerr<<"WINDOW="<<WINDOW<<endl;) int nump,numr; nump=strchr(argv[1],',')-argv[1]; numr=(strlen(argv[1])+1)/(nump+1); int fromround=numr-30; if(fromround<0)fromround=0; int period,r; int *wave=new int[WINDOW]; bool allequal=true; DBG(cerr<<"wave: ";) for(r=fromround;r<numr;r++){ wave[r-fromround]=majority(argv[1]+r*(nump+1)); if(wave[r-fromround]!=wave[0])allequal=false; DBG(cerr<<wave[r]<<" ";) } DBG(cerr<<endl;) if(allequal){ DBG(cerr<<"All equal!"<<endl;) if(wave[numr-1]==1)cout<<"evil"<<endl; //choose for minority else cout<<"good"<<endl; return 0; } int score,*scores=new int[WINDOW]; int max=0; //some score will always get above 0, because if some score<0, the inverted wave will be >0. int phase,phasemax; pair<int,int> maxat(-1,-1); //period, phase DBG(cerr<<"scores: ";) for(period=1;period<=WINDOW;period++){ scores[period-1]=0; phasemax=-1; for(phase=0;phase<2*period;phase++){ score=0; for(r=fromround;r<numr;r++){ if(wave[r]==1-(r+phase)%(2*period)/period)score++; else score--; } if(score>scores[period-1]){ scores[period-1]=score; phasemax=phase; } } if(scores[period-1]>max){ max=scores[period-1]; maxat.first=period; maxat.second=phasemax; } DBG(cerr<<scores[period-1]<<" ";) } DBG(cerr<<"(max="<<max<<" at {"<<maxat.first<<","<<maxat.second<<"})"<<endl;) DBG(cerr<<" max: ("<<numr<<"+"<<maxat.second<<")%(2*"<<maxat.first<<")/"<<maxat.first<<"=="<<((numr+maxat.second)%(2*maxat.first)/maxat.first)<<endl;) if(1-(numr+maxat.second)%(2*maxat.first)/maxat.first==1)cout<<"evil"<<endl; //choose for minority else cout<<"good"<<endl; delete[] wave; delete[] scores; return 0; } Compile with `g++ -O3 -std=c++11 -o Scientist Scientist.cpp` (you don't need warnings, so no `-Wall`) and run with `Scientist.exe` (possibly including the argument of course). If you ask really nicely I can provide you with a Windows executable. Oh, and don't dare messing with the input format. It'll do strange things otherwise. **EDIT:** Apparently, the previous version ran out of time around 600 rounds into the game. This shouldn't do that. Its time consumption is controlled by the `#define WINDOW (...)` line, more is slower but looks further back.