#include <iostream>
#include <string>
#include <cstdint>
class CastSpells{
std::string Words;
public:
CastSpells(char* str) :Words(str){}
CastSpells& operator ()(){
std::cout << Words << std::endl;
return *this;
}
};
typedef std::pair<std::uint16_t, std::uint16_t> Pair16;
Pair16 FullAdder(std::uint16_t A, std::uint16_t B, std::uint16_t C){//ここからパクった。良いページだ。ttp://www.mech.tohoku-gakuin.ac.jp/rde/contents/course/mechatronics/digital.html
int S1 = A ^ B;
int C1 = A & B;
int S = S1 ^ C;
int C2 = S1 & C;
int Co = C1 | C2;
return std::make_pair(S,Co);
}
std::uint16_t AddOne(std::uint16_t N){
int i = 0;
int B = 1;
int R = 0;
Pair16 Pa;
//0
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=1;
//1
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=2;
//2
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=3;
//3
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=4;
//4
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=5;
//5
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=6;
//6
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=7;
//7
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=8;
//8
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=9;
//9
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=10;
//10
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=11;
//11
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=12;
//12
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=13;
//13
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=14;
//114
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=15;
//15
Pa = FullAdder(N&(1 << i), B&(1 << i), Pa.second<<1);
R |= Pa.first;
i=0;
return R;
}
int main(){
CastSpells CS("Hello World!!");
CS()()()()()()()();//おまけ!
std::cout << "---------------" <<std::endl ;
int N = 8;
for (int i = 0; i < 65535; i++){
if (i + 1 != AddOne(i)){
std::cout << "this logic is broken!";
return -1;
}
}
std::cout << "Logic test Passed!" <<std::endl ;
for (int i = 0; i < N; i = AddOne(i)){
std::cout << "Hello World!" << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8Y3N0ZGludD4KCmNsYXNzIENhc3RTcGVsbHN7CglzdGQ6OnN0cmluZyBXb3JkczsKCnB1YmxpYzoKCUNhc3RTcGVsbHMoY2hhciogc3RyKSA6V29yZHMoc3RyKXt9CgoJQ2FzdFNwZWxscyYgb3BlcmF0b3IgKCkoKXsKCQlzdGQ6OmNvdXQgPDwgV29yZHMgPDwgc3RkOjplbmRsOwoJCXJldHVybiAqdGhpczsKCX0KfTsKdHlwZWRlZiBzdGQ6OnBhaXI8c3RkOjp1aW50MTZfdCwgc3RkOjp1aW50MTZfdD4gUGFpcjE2OwpQYWlyMTYgRnVsbEFkZGVyKHN0ZDo6dWludDE2X3QgQSwgc3RkOjp1aW50MTZfdCBCLCBzdGQ6OnVpbnQxNl90IEMpey8v44GT44GT44GL44KJ44OR44Kv44Gj44Gf44CC6Imv44GE44Oa44O844K444Gg44CCdHRwOi8vd3d3Lm1lY2gudG9ob2t1LWdha3Vpbi5hYy5qcC9yZGUvY29udGVudHMvY291cnNlL21lY2hhdHJvbmljcy9kaWdpdGFsLmh0bWwKCglpbnQgUzEgPSBBIF4gQjs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