This isn't the one..

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent dc6f9e07c7
commit 4014ee0343
  1. BIN
      C++ProjectTemplate
  2. 89
      main.cpp

Binary file not shown.

@ -29,27 +29,58 @@ std::vector<int>factor(int numb){
}
struct factorNumber{
void SetupOffsets(){
void SetupOffsets(int initial){
offsets.push_back({23,0});
offsets.push_back({19,0});
offsets.push_back({13,0});
offsets.push_back({17,0});
for (int i=0;i<offsets.size();i++){
offsets[i].second=initial%offsets[i].first;
}
}
std::vector<int>factors;
std::vector<std::pair<int,int>>factors;
std::vector<std::pair<int,int>>offsets;
factorNumber(int numb){
SetupOffsets();
SetupOffsets(numb);
std::vector<int>tmp=factor(numb);
for (int j=0;j<tmp.size();j++){
for (int i=0;i<factors.size();i++){
if (factors[i].first==tmp[j]){
factors[i].second++;
goto nextfactor;
}
}
factors.push_back({tmp[j],1});
nextfactor:;
}
}
factorNumber&operator=(int numb){
factors.clear();
offsets.clear();
SetupOffsets();
factors=factor(numb);
SetupOffsets(numb);
std::vector<int>tmp=factor(numb);
for (int j=0;j<tmp.size();j++){
for (int i=0;i<factors.size();i++){
if (factors[i].first==tmp[j]){
factors[i].second++;
goto nextfactor;
}
}
factors.push_back({tmp[j],1});
nextfactor:;
}
return*this;
}
factorNumber&operator+=(int numb){
for (int i=0;i<offsets.size();i++){
std::pair<int,int>&offset=offsets[i];
for (int j=0;j<factors.size();j++){
if (factors[j].first==offset.first){
factors[j].second+=(offset.second+numb)/offset.first;
goto addOffset;
}
}
addOffset:
offset.second=(offset.second+numb)%offset.first;
}
return*this;
@ -58,11 +89,12 @@ struct factorNumber{
std::vector<int>factors=factor(numb);
for (int i=0;i<factors.size();i++){
for (int j=0;j<this->factors.size();j++){
if (this->factors[j]==factors[i]){
if (this->factors[j].first==factors[i]){
this->factors[j].second++;
goto gonext;
}
}
this->factors.push_back(factors[i]);
this->factors.push_back({factors[i],1});
gonext:;
}
return*this;
@ -70,22 +102,28 @@ struct factorNumber{
int operator%(int numb){
for (int i=0;i<offsets.size();i++){
if (offsets[i].first==numb){
if (offsets[i].second==0) {
for (int j=0;j<factors.size();j++){
if (factors[j]==numb){
return 0;
}
}
//std::cout<<"Not divisible!"<<std::endl;
return -1;
} else {
return offsets[i].second;
}
return offsets[i].second;
}
}
for (int j=0;j<factors.size();j++){
if (factors[j].first!=1&&(factors[j].first==numb||factors[j].second%numb==0)){
return 0;
}
}
std::cout<<"No divisibility information for modulus "<<numb<<" !! THIS SHOULDN'T BE HAPPENING !!"<<std::endl;
return -1; //This shouldn't happen??
}
friend std::ostream&operator<<(std::ostream&out,factorNumber&rhs){
out<<"Factors:"<<std::endl;
for (int i=0;i<rhs.factors.size();i++){
out<<" "<<rhs.factors[i].first<<" x"<<rhs.factors[i].second<<std::endl;
}
std::cout<<"Offsets:"<<std::endl;
for (int i=0;i<rhs.offsets.size();i++){
out<<" "<<rhs.offsets[i].first<<": "<<rhs.offsets[i].second<<std::endl;
}
return out;
}
};
struct Monkey{
@ -116,6 +154,20 @@ int main()
monkeys.push_back({{79, 60, 97},'*',-1,13,1,3});
monkeys.push_back({{74},'+',3,17,0,1});
/*
factorNumber test(17);
test=84075;
for (int i=0;i<77;i++){
test*=23;
}
std::cout<<test<<std::endl;
std::cout<<test%59<<std::endl;
std::cout<<test%19<<std::endl;
std::cout<<test%23<<std::endl;
std::cout<<test%13<<std::endl;
std::cout<<test%17<<std::endl;*/
for (int round=0;round<10000;round++){
for (int i=0;i<monkeys.size();i++){
Monkey&m=monkeys[i];
@ -164,5 +216,6 @@ int main()
std::cout<<((long)monkeys[0].inspAmt*(long)monkeys[1].inspAmt)<<std::endl;
return 0;
}

Loading…
Cancel
Save