<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: bf code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 16 Aug 2008 20:22:16 GMT</pubDate>
    <description>DZone Snippets: bf code</description>
    <item>
      <title>bell.bf</title>
      <link>http://snippets.dzone.com/posts/show/3539</link>
      <description>// Sounds the system bell&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;URL: http://snippets.dzone.com/posts/show/3539&lt;br /&gt;&lt;br /&gt;add seven&lt;br /&gt;while not zero&lt;br /&gt;	putchar&lt;br /&gt;	minus one&lt;br /&gt;&lt;br /&gt;+++++++[.-]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Feb 2007 00:57:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3539</guid>
      <author>mcandre (Andrew Pennebaker)</author>
    </item>
    <item>
      <title>rot13.bf</title>
      <link>http://snippets.dzone.com/posts/show/3538</link>
      <description>// ROT13 in Brainfuck&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;URL: http://snippets.dzone.com/posts/show/3538&lt;br /&gt;&lt;br /&gt;+[,+[-[&gt;+&gt;+&lt;&lt;-]&gt;[&lt;+&gt;-]+&gt;&gt;++++++++[&lt;--------&gt;-]&lt;-[&lt;[-]&gt;&gt;&gt;+[&lt;+&lt;+&gt;&gt;-]&lt;[&gt;+&lt;-]&lt;[&lt;++&gt;&lt;br /&gt;&gt;&gt;+[&lt;+&lt;-&gt;&gt;-]&lt;[&gt;+&lt;-]]&gt;[&lt;]&lt;]&gt;&gt;[-]&lt;&lt;&lt;[[-]&lt;[&gt;&gt;+&gt;+&lt;&lt;&lt;-]&gt;&gt;[&lt;&lt;+&gt;&gt;-]&gt;&gt;++++++++[&lt;-------&lt;br /&gt;-&gt;-]&lt;-&gt;&gt;++++[&lt;++++++++&gt;-]&lt;-&lt;[&gt;&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pubDate>
      <guid>http://snippets.dzone.com/posts/show/3538</guid>
      <author>mcandre (Andrew Pennebaker)</author>
    </item>
    <item>
      <title>bf.py</title>
      <link>http://snippets.dzone.com/posts/show/3536</link>
      <description>// Brainfuck Interpreter&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env python&lt;br /&gt;&lt;br /&gt;"""A Brainfuck interpreter"""&lt;br /&gt;&lt;br /&gt;__author__="Andrew Pennebaker (andrew.pennebaker@gmail.com)"&lt;br /&gt;__date__="18 Nov 2005 - 27 Feb 2006"&lt;br /&gt;__copyright__="Copyright 2006 Andrew Pennebaker"&lt;br /&gt;__license__="GPL"&lt;br /&gt;__version__="0.5"&lt;br /&gt;__URL__="http://snippets.dzone.com/posts/show/3536"&lt;br /&gt;&lt;br /&gt;from aio import chomp&lt;br /&gt;&lt;br /&gt;import sys&lt;br /&gt;from getopt import getopt&lt;br /&gt;&lt;br /&gt;tape=[0]*100&lt;br /&gt;address=0&lt;br /&gt;&lt;br /&gt;def sublevel(toplevel):&lt;br /&gt;	i=0&lt;br /&gt;&lt;br /&gt;	# until a balanced-bracket code block is found, add a character&lt;br /&gt;&lt;br /&gt;	while toplevel[0:i+1].count("[")!=toplevel[0:i+1].count("]"): i+=1&lt;br /&gt;&lt;br /&gt;	return toplevel[1:i]&lt;br /&gt;&lt;br /&gt;def run(instructions):&lt;br /&gt;	global tape&lt;br /&gt;	global address&lt;br /&gt;&lt;br /&gt;	position=0&lt;br /&gt;	while position&lt;len(instructions):&lt;br /&gt;		cmd=instructions[position]&lt;br /&gt;&lt;br /&gt;		if cmd=="&lt;": address-=1&lt;br /&gt;		elif cmd=="&gt;": address+=1&lt;br /&gt;		elif cmd=="+": tape[address]+=1&lt;br /&gt;		elif cmd=="-": tape[address]-=1&lt;br /&gt;		elif cmd==".": sys.stdout.write(chr(tape[address]))&lt;br /&gt;		elif cmd==",":&lt;br /&gt;			try: tape[address]=ord(sys.stdin.read(1))&lt;br /&gt;			except: tape[address]=-1&lt;br /&gt;		elif cmd=="[":&lt;br /&gt;			level=sublevel(instructions[position:])&lt;br /&gt;			while tape[address]!=0: run(level)&lt;br /&gt;&lt;br /&gt;			position+=len(level)+1&lt;br /&gt;&lt;br /&gt;		position+=1&lt;br /&gt;&lt;br /&gt;def usage():&lt;br /&gt;	print "Usage: %s [options] &lt;sourcefile&gt;" % (sys.argv[0])&lt;br /&gt;	print "--help (usage)"&lt;br /&gt;&lt;br /&gt;	sys.exit()&lt;br /&gt;&lt;br /&gt;def main():&lt;br /&gt;	systemArgs=sys.argv[1:] # ignore program name&lt;br /&gt;&lt;br /&gt;	live=False&lt;br /&gt;&lt;br /&gt;	optlist=[]&lt;br /&gt;	args=[]&lt;br /&gt;&lt;br /&gt;	try:&lt;br /&gt;		optlist, args=getopt(systemArgs, None, ["help"])&lt;br /&gt;	except Exception, e:&lt;br /&gt;		usage()&lt;br /&gt;&lt;br /&gt;	live=len(args)&lt;1&lt;br /&gt;&lt;br /&gt;	for option, value in optlist:&lt;br /&gt;		if option=="--help":&lt;br /&gt;			usage()&lt;br /&gt;&lt;br /&gt;	if live:&lt;br /&gt;		print "--BF Interpreter 0.5--"&lt;br /&gt;		print "  Type exit to exit."&lt;br /&gt;&lt;br /&gt;		line="not exit"&lt;br /&gt;		while line!="exit":&lt;br /&gt;			sys.stdout.write("% ")&lt;br /&gt;			line=chomp(sys.stdin.readline())&lt;br /&gt;&lt;br /&gt;			if line.count("[")!=line.count("]"):&lt;br /&gt;				raise "Unbalanced brackets"&lt;br /&gt;			else:&lt;br /&gt;				run(line)&lt;br /&gt;	else:&lt;br /&gt;		src=args[0]&lt;br /&gt;&lt;br /&gt;		srcfile=open(src, "r")&lt;br /&gt;		code="".join(srcfile.readlines())&lt;br /&gt;		srcfile.close()&lt;br /&gt;&lt;br /&gt;		if code.count("[")!=code.count("]"):&lt;br /&gt;			raise "Unbalanced brackets"&lt;br /&gt;		else:&lt;br /&gt;			run(code)&lt;br /&gt;&lt;br /&gt;if __name__=="__main__":&lt;br /&gt;	try:&lt;br /&gt;		main()&lt;br /&gt;	except KeyboardInterrupt, e:&lt;br /&gt;		pass&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Feb 2007 00:52:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3536</guid>
      <author>mcandre (Andrew Pennebaker)</author>
    </item>
  </channel>
</rss>
