Created
June 17, 2015 03:37
-
-
Save tjwei/ffc1b5cad0be74e542e1 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <map> | |
#include <fstream> | |
int main(int argc, char **argv) { | |
std::map<int,unsigned char> cells; | |
std::ifstream is(argv[1], std::ifstream::binary); | |
auto loop = [&](int s, char x, char y, int cnt=0) -> bool { | |
while(cnt >= 0 && is.seekg(s, is.cur)) | |
[&](int d){cnt += (d == x) - (d == y);}(is.get()); | |
}; | |
for(int p=0;!is.eof();) { | |
auto c = is.get(); | |
p += (c == '>') - (c == '<'); | |
cells[p] += (c == '+') - (c == '-'); | |
c=='.' && std::cout << cells[p]; | |
c==',' && (cells[p] = std::cin.get()); | |
c=='[' && !cells[p] && loop(0, '[', ']'); | |
c==']' && cells[p] && loop(-2, ']', '['); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment