1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
#include <iostream>
#include <bitset>
using namespace std;
template <int size>
void inc(bitset<size>& a){
for(int n = 0;n < size;n++){
if(a[n] == 0){
a.flip(n);
break;
}
else{
a.flip(n);
}
}
}
template <int bigger,int smaller,int newSize = bigger + 1>
bitset<newSize> add(bitset<bigger> a,bitset<smaller> b){
bitset<newSize> result = 0;
for(bitset<bigger> track = 0;track != a;inc<bigger>(track)){
inc<newSize>(result);
}
for(bitset<smaller> track = 0;track != b;inc<smaller>(track)){
inc<newSize>(result);
}
return result;
}
template <int bigger,int smaller,int newSize = bigger + smaller>
bitset<newSize> multiply(bitset<bigger> a,bitset<smaller> b){
bitset<newSize> result = 0;
for(bitset<smaller> track = 0;track != b;inc<smaller>(track)){
result = add<newSize,bigger,newSize> (result,a);
}
return result;
}
template <int bSize,int eSize,int newSize = (bSize*eSize) + 1>
bitset<newSize> power(bitset<bSize> base,bitset<eSize> exponent){
bitset<newSize> result = 0;
result = add<newSize,bSize,newSize> (result,base);
for(bitset<eSize> track = 1;track != exponent;inc<eSize>(track)){
result = multiply<newSize,bSize,newSize> (result,base);
}
return result;
}
template <int size>
void dec(bitset<size>& a){
for(int n = 0;n < size;n++){
a.flip(n);
if(a[n] == 0){
break;
}
}
}
template <int bigger,int smaller,int newSize = bigger>
bitset<newSize> subtract(bitset<bigger> a,bitset<smaller> b){
bitset<newSize> result = 0;
result = add<newSize,bigger,newSize> (result,a);
for(bitset<smaller> track = 0;track != b;inc(track)){
dec(result);
}
return result;
}
template <int nA,int nB>
bool lessthan(bitset<nA> a,bitset<nB> b){
int aTotal = 0;
int bTotal = 0;
int aLastSet = 0;
int bLastSet = 0;
for(int n = 0;n < a.size();n++){
if(a[n] == 1){
aLastSet = n;
}
aTotal += a[n];
}
for(int n = 0;n < b.size();n++){
if(b[n] == 1){
bLastSet = n;
}
bTotal += b[n];
}
if(aLastSet < bLastSet){
return true;
}
if(aLastSet == bLastSet){
if(aTotal < bTotal){
return true;
}
return false;
}
return false;
}
template <int bigger,int smaller,int newSize = bigger>
bitset<newSize> divide(bitset<bigger> a,bitset<smaller> b){
for(bitset<newSize> track = 0;track != a;inc<newSize>(track)){
a = subtract<bigger,smaller> (a,b);
if(lessthan<smaller,bigger>(b,a) ){
inc<newSize>(track);
return track;
}
}
}
template <int bigger,int smaller,int newSize = bigger>
bitset<newSize> modulo(bitset<bigger> value,bitset<smaller> modder){
for(bitset<newSize> result = 0; ;inc<newSize> (result)){
}
}
int main(){
cout << "Hello, world!\n";
bitset<1536> p = 0;
bitset<1536> q = 0;
bitset<3072> n = 0;
bitset<1024> e = 0;
bitset<3072> d = 0;
}
|