// file: main_02_MENT.cpp // THIS IS C++, use clang++ #include #include "../../helpers/println.hpp" struct PascalString{ int length; // number of chars used char characters[256]; // chars of some character string }; void printPascalString(PascalString string) { for(int i = 0; i <= string.length; ++i) { print(string.characters[i]); } println(""); } PascalString dualOr(PascalString a, PascalString b) { PascalString longString = a.length >= b.length ? a : b; PascalString shortString = a.length >= b.length ? b : a; PascalString result = {longString.length}; /* for(int i = longString.length; i >= 0; --i) { if(i >= shortString.length) result.characters[i] = '0'; else result.characters[i] = shortString.characters[i]; } */ for(int i = 0; i < longString.length; i++) { if(i <= shortString.length) { result.characters[i] = longString.characters[i]; //println("lang ", longString.characters[i]); } else{ result.characters[i] = longString.characters[i] | shortString.characters[i]; //println("beides ", shortString.characters[i] | longString.characters[i]); } } return result; } int main(int argc, char** argv, char** envp) { printPascalString(dualOr({2, '0', '1'}, {2, '1', '0'})); printPascalString(dualOr({2, '0', '1'}, {3, '1', '1', '1'})); printPascalString(dualOr({3, '1', '1', '1'}, {4, '1', '1', '0', '1'})); printPascalString(dualOr({3, '0', '0', '0'}, {5, '1', '1', '0', '1', '0'})); printPascalString(dualOr({3, '0', '1', '1'}, {6, '1', '1', '0', '1', '0', '1'})); printPascalString(dualOr({2, '0', '1'}, {6, '1', '1', '0', '1', '0', '1'})); printPascalString(dualOr({2, '1', '1'}, {6, '1', '0', '0', '1', '0', '0'})); return 0; }