Created
January 21, 2011 15:02
-
-
Save OrigamiTech/789790 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
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