Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Ref: https://gist.github.com/aycabta/9088471
- int r, a;
- P(y, x) { // referential transparent
- return (y * 2 + 1) << x;
- }
- // position of lowest 1-bit
- // Z(0b1) = 0, Z(0b10) = 1
- Z(x) { // referential transparent
- int pos = 0;
- while((x & 1) == 0) {
- x >>= 1;
- pos++;
- }
- return pos;
- }
- // cut last 100... (bin) off
- // L(0b101011000000) = 0b10101
- L(x) { // referential transparent
- return x >> (Z(x) + 1);
- }
- S(v, y, c, t)
- {
- int f = L(t);
- int x = r;
- if (f != 2) {
- if (f > 2) {
- if(f == v) return y;
- if(f > v) return t - c;
- /*(f < v)*/ return t;
- } else {
- t = S(4, 13, -4, y);
- return P(f, P(S(v, y, c, L(x)), S(v + 2, t, c, Z(x))));
- }
- } else {
- A(S(v, y, c, L(x)), S(v, y, c, Z(x)));
- }
- }
- A(y, x) {
- if (L(y) != 1) {
- return 5 << P(y, x);
- } else {
- return S(4, x, 4, Z(r));
- }
- }
- D(x) {
- int c = 0;
- int t = 7;
- int u = 14;
- while (1) {
- if (x) D(x - 1);
- x >>= 1;
- if (x & 1) break;
- int d = L(L(D(x)));
- int f = L(r);
- x = L(r);
- if (c == r && L(u) == 0 && L(r) == f) {
- x >>= 1;
- if (x & 1) {
- u = S(4, d, 4, r);
- t = A(t, d);
- x >>= 1;
- if ((f >> 1) & x & 1) {
- c = P(d, c);
- t = S(4, 13, -4, t);
- u = S(4, 13, -4, u);
- }
- }
- };
- if (c) {
- x >>= 1;
- if (x & 1) {
- x >>= 1;
- if(~u & 2 | x & 1) {
- u = 1 << P(L(c), u);
- t = P(u, P(L(c), t));
- } else {
- t = P(0, P(L(c), t));
- }
- c = r;
- }
- }
- x >>= 1;
- if (u >> 1 & x & 1) {
- c = P(t, c);
- u = S(4, 13, -4, t);
- t = 9;
- }
- }
- return a = P(P(t, P(u, P(x, c))), a);
- }
- main() {
- return D(D(D(D(D(99)))));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement