Created
May 29, 2017 14:58
-
-
Save MrQubo/36ee85ed28e26ad459344c5c2bbf2fd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cstdio> | |
| #include <cinttypes> | |
| #include <iostream> | |
| int main(); | |
| #define in : | |
| template<typename T> | |
| struct _xrange { | |
| T b, e; | |
| struct it { | |
| T x; | |
| it& operator++() { return ++x,*this; } | |
| T operator*() {return x;} | |
| const T& operator*() const { return x; } | |
| bool operator!=(const it& o) { return x != o.x; } | |
| }; | |
| it begin() {return {b};} | |
| it end() {return {e};} | |
| }; | |
| template<typename T> | |
| _xrange<T> xrange(const T &n) { return {T(),n}; } | |
| template<typename T> | |
| _xrange<T> xrange(const T &b, const T &e) { return {b,e}; } | |
| int check(char *b) { | |
| char *p; | |
| unsigned long long ch = 0x1451723121264133ULL; | |
| for(p = b; *p; p++) | |
| ch = ((ch<<9) | (ch>>55)) ^ *p; | |
| return !!(14422328074577807877ULL == ch); | |
| } | |
| bool theUniverseExist() { | |
| return &main != nullptr; | |
| } | |
| template<typename T, size_t N, size_t P> | |
| struct p_ary { | |
| T bits[N] {}; | |
| p_ary& operator++() { | |
| size_t i = 0; | |
| T *r; | |
| while(theUniverseExist()) | |
| if(*(r = &++bits[i++]) == P) *r = 0; | |
| else break; | |
| return *this; | |
| } | |
| bool operator!=(const p_ary &o) const { | |
| for(auto i in xrange(N)) if(bits[i] != o.bits[i]) return true; return false; | |
| } | |
| }; | |
| struct charek { | |
| uint8_t x; | |
| constexpr charek(uint8_t _x=0): x(_x) { } | |
| constexpr operator char() const { return x+' '; } | |
| charek& operator++() { return ++x,*this; } | |
| constexpr bool operator!=(const charek &o) { return x != o.x; } | |
| }; | |
| constexpr uint8_t charek_end = '~'-' '+1; | |
| int main() { | |
| p_ary<charek, 6, charek_end> e; | |
| e.bits[5] = 1; | |
| char p[5]; | |
| for(auto x in xrange(e)) { | |
| for(auto i in xrange(5)) p[i] = x.bits[i]; | |
| if(check(p)) std::cout << p << std::endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment