Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 BF programming challenge
Index -> Contests
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
beard0




PostPosted: Fri Nov 26, 2004 2:43 pm   Post subject: BF programming challenge

Want to learn a new language? What if you heard that it has only 9, 1-character commands? The language is BF. Here is an explanation of the language:
Quote:
A BF program operates on a simple 1-dimensional array of memory cells. There is a "pointer" to a current memory cell. In "vanilla" BF, this array has a size of 30,000, and each cell is an 8-bit integer - that is, it stores a value from 0-255. Incrementing a cell with a value of 255 wraps around to 0, likewise, decrementing a cell with a value of 0 wraps around to 255. All cells are initially set to 0, and the pointer points to the left most cell. The BF program consists of a string. Each character can be one of 9 commands:

> move the pointer one cell to the right
< move the pointer one cell to the left
+ increment the current cell by 1
- decrement the current cell by 1
[ skips ahead to the matching "]" IF the current cell contains 0
] returns to the matching "[" IF the current cell DOES NOT contain 0
. outputs the character with the ASCII value of the current cell
, sets the current cell to the ASCII value of the input character
# ends the program. (This is not necessary; the program will terminate at the end, but it can be useful)

All other characters are comments and are duly ignored.
Note: If you attempt to move the pointer past the edge of the array, your program will crash.

Some sample programs:

Program 1:

Output:
Hello World!
++++++++[>++++[>++>+++>+++>+<<<<-]>+>->+>>+[<]<-]>>.>
>---.+++++++..+++.>.<<-.>.+++.------.--------.>+.>++.

Program2:
++[>+++++++++++++<-]
>>>++++++++[<++++++++>-]<+
<[->.+<]
++++++++++.
#
Output:
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Program 3:
[+[>uh-oh<]+]------outer[+>------inner[+>-----<]<]>>.<++++++++++.#
Output:
L


So, the challenge is to learn the language, and write a program in it with the least number of charcters possible. The program should accept two 1 digit numbers as input, multiply them, and then display the answer. You do not need to display prompts. You may force your output to be two digits. (i.e. if 2 and 3 are entered, both "6" and "06" are acceptable outputs)

Here is a BF environment that I made in turing to enable you to test your programs as you go. Be careful: it will not warn you about overwriting files, or saving your work.



BF Editor.zip
 Description:
My BF interpreter/environment.
I included the turing file so that you could see what I have done, however, you will not be able to run the turing file because I make updates to my GUI library every time I make a GUI program to suit my needs. The executa

Download
 Filename:  BF Editor.zip
 Filesize:  402.7 KB
 Downloaded:  232 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Contests
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: