Skip to content

Instantly share code, notes, and snippets.

@yosupo06
Created December 6, 2015 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosupo06/eb09ac73335ff7ba51da to your computer and use it in GitHub Desktop.
Save yosupo06/eb09ac73335ff7ba51da to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cassert>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
bool a, b, c, d, e, f, g, h, i, j, k;
void ref() {
e = a | !d;
f = !e | !b;
g = c | d;
h = !b | !d;
i = !b | !h;
j = !d | !h;
k = !i | !j;
}
void debug() {
printf("%d %d %d %d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h, i, j, k);
}
char get() {
char u = 0;
if (b) u++;
u *= 2;
if (d) u++;
u *= 2;
if (!e) u++;
u *= 2;
if (!f) u++;
u *= 2;
if (!g) u++;
u *= 2;
if (!k) u++;
return u;
}
int main() {
a = b = c = d = false;
// a = c = false;
// b = d = true;
ref();
string s;
char back = '@';
for (int i = 0; i < 10; i++) {
if (back == 'Y') {
a = false;
c = true;
} else {
a = ((i & 1) != 0);
c = ((i & 2) != 0);
}
ref();
// debug();
back = 32+get();
cout << back << endl;
s += back;
b = a; d = c;
ref();
// debug();
s += 32+get();
cout << (char)(32+get()) << endl;
}
cout << s << endl;
return 0;
}
import std.file;
import std.stdio;
import std.conv;
void pr(ubyte v) {
auto sv = to!string(v, 2).dup.reverse;
write(sv);
foreach (i; 0..8-sv.length) {
write("0");
}
writeln();
}
ubyte nex(ubyte v) {
ubyte l = v & 0x0f, r = (v >> 4) & 0x0f;
l++;
l &= 0x0f;
if (l == 15) {
r++;
r &= 0x0f;
}
return cast(ubyte)(l | (r << 4));
}
int main(string[] argv) {
auto inf = File(argv[1], "rb");
auto ouf = File(argv[2], "wb");
ubyte v = 0;
while (true) {
ubyte nv = 0;
nv |= ((v >> 0) & 0x01) << 7; //q7
nv |= ((v >> 1) & 0x01) << 0; //q0
nv |= ((v >> 2) & 0x01) << 1; //q1
nv |= ((v >> 3) & 0x01) << 2;
nv |= ((v >> 4) & 0x01) << 3;
nv |= ((v >> 5) & 0x01) << 4;
nv |= ((v >> 6) & 0x01) << 5;
nv |= ((v >> 7) & 0x01) << 6; //q6
ubyte[] u = new ubyte[](1);
u = inf.rawRead(u);
if (!u.length) break;
u[0] ^= nv;
ouf.rawWrite(u);
v = 0;
foreach (i; 0..nv) {
v = nex(v);
}
pr(v);
v = nex(v);
v = nex(v);
v = nex(v);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment