Skip to content

Instantly share code, notes, and snippets.

@OrigamiTech
Created January 21, 2011 15:02
Show Gist options
  • Save OrigamiTech/789790 to your computer and use it in GitHub Desktop.
Save OrigamiTech/789790 to your computer and use it in GitHub Desktop.
using System;using System.Runtime.InteropServices;
namespace BrainFrack{
class Program{
static unsafe void Main(string[]args){
string c=Console.ReadLine();
int s=30000;
byte* p=(byte*)Marshal.AllocCoTaskMem(s);
for(int i=0;i<s;i++)*p++=0;
p-=s;
Console.Clear();
b(c,ref p);
Console.ReadLine();
}
static unsafe void b(string c,ref byte*p){
for (int i=0;i<c.Length;i++)
switch (c[i]){
case'>':p++;break;
case'<':p--;break;
case'+':(*p)++;break;
case'-':(*p)--;break;
case'.':Console.Write((char)*p);break;
case',':*p = (byte)Console.ReadKey(true).KeyChar;break;
case'[':b(c.Substring(i+1),ref p);while(c[++i]!=']');break;
case']':if(*p==0)return;i=-1;break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment