Skip to content

Instantly share code, notes, and snippets.

@phi16
Created February 5, 2016 17:26
Show Gist options
  • Save phi16/95147ce7bf67501c5b36 to your computer and use it in GitHub Desktop.
Save phi16/95147ce7bf67501c5b36 to your computer and use it in GitHub Desktop.
#include<iostream>
struct Status{
int buf[256];
int pos;
Status():pos(0){}
Status add(){
buf[pos]++;
return *this;
}
Status sub(){
buf[pos]--;
return *this;
}
Status let(){
pos--;
return *this;
}
Status rit(){
pos++;
return *this;
}
Status get(){
char p;
std::cin.get(p);
buf[pos]=p;
return *this;
}
Status put(){
std::cout<<char(buf[pos]);
return *this;
}
};
template<class T,class U> struct add{
Status operator ()(Status s){
return U()(T()(s).add());
}
};
template<class T,class U> struct sub{
Status operator ()(Status s){
return U()(T()(s).sub());
}
};
template<class T,class U> struct let{
Status operator ()(Status s){
return U()(T()(s).let());
}
};
template<class T,class U> struct rit{
Status operator ()(Status s){
return U()(T()(s).rit());
}
};
template<class T,class U> struct lop{
Status operator ()(Status s){
s=T()(s);
while(s.buf[s.pos]){
s=U()(s);
}
return s;
}
};
template<class T,class U> struct get{
Status operator ()(Status s){
return U()(T()(s).get());
}
};
template<class T,int N> struct put{
Status operator ()(Status s){
s=T()(s);
for(int i=0;i<9-N;i++)s=s.put();
return s;
}
};
template<class T,int N=9> struct Brainfuck{
Brainfuck<T,N-1> _;
template<class U,int M> Brainfuck<add<put<T,N>,put<U,M> > > operator + (Brainfuck<U,M>){
return Brainfuck<add<put<T,N>,put<U,M> > >();
}
template<class U,int M> Brainfuck<sub<put<T,N>,put<U,M> > > operator - (Brainfuck<U,M>){
return Brainfuck<sub<put<T,N>,put<U,M> > >();
}
template<class U,int M> Brainfuck<let<put<T,N>,put<U,M> > > operator < (Brainfuck<U,M>){
return Brainfuck<let<put<T,N>,put<U,M> > >();
}
template<class U,int M> Brainfuck<rit<put<T,N>,put<U,M> > > operator > (Brainfuck<U,M>){
return Brainfuck<rit<put<T,N>,put<U,M> > >();
}
template<class U,int M> Brainfuck<get<put<T,N>,put<U,M> > > operator , (Brainfuck<U,M>){
return Brainfuck<get<put<T,N>,put<U,M> > >();
}
template<class U,int M> Brainfuck<lop<put<T,N>,put<U,M> > > operator [] (Brainfuck<U,M>){
return Brainfuck<lop<put<T,N>,put<U,M> > >();
}
Status operator ()(){
return T()(Status());
}
};
template<class T> struct Brainfuck<T,0>{
template<class U,int M> Brainfuck<add<put<T,0>,put<U,M> > > operator + (Brainfuck<U,M>){
return Brainfuck<add<put<T,0>,put<U,M> > >();
}
template<class U,int M> Brainfuck<sub<put<T,0>,put<U,M> > > operator - (Brainfuck<U,M>){
return Brainfuck<sub<put<T,0>,put<U,M> > >();
}
template<class U,int M> Brainfuck<let<put<T,0>,put<U,M> > > operator < (Brainfuck<U,M>){
return Brainfuck<let<put<T,0>,put<U,M> > >();
}
template<class U,int M> Brainfuck<rit<put<T,0>,put<U,M> > > operator > (Brainfuck<U,M>){
return Brainfuck<rit<put<T,0>,put<U,M> > >();
}
template<class U,int M> Brainfuck<get<put<T,0>,put<U,M> > > operator , (Brainfuck<U,M>){
return Brainfuck<get<put<T,0>,put<U,M> > >();
}
template<class U,int M> Brainfuck<lop<put<T,0>,put<U,M> > > operator [] (Brainfuck<U,M>){
return Brainfuck<lop<put<T,0>,put<U,M> > >();
}
Status operator ()(){
return T()(Status());
}
};
struct t{
Status operator ()(Status s){
return s;
}
};
Brainfuck<t> _;
int main(){
(_+_+_+_+_+_+_+_+_+_[_>_+_+_+_+_+_+_+_+_>_+_+_+_+_+_+_+_+_+_+_+_>_+_+_+_+_+_<_<_<_-_]>_._>_+_+_._+_+_+_+_+_+_+_._._+_+_+_._>_-_._-_-_-_-_-_-_-_-_-_-_-_-_._<_+_+_+_+_+_+_+_+_._-_-_-_-_-_-_-_-_._+_+_+_._-_-_-_-_-_-_._-_-_-_-_-_-_-_-_._>_+_._)();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment