Thread: Brainf#@k: an impossible program?

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    465

    Brainf#@k: an impossible program?

    I have been playing around with the language Brainf#@k and have programmed a few novelty things with it all of them simple but still challenging. I have been trying at this one but I can't figure out how. I'm trying to have the program insert a blank piece of memory after every 8 characters of input. So far I have this:

    Code:
    >++++++++[>,[<]>-[>]<]>>
    It will insert a blank piece of memory after the first 8 characters of input or skip a piece of memory however you want to look at it. My problem is getting this cycle to recur. I don't see how I could reset the 2nd memory block to 8 so it can happen again without actually copy and pasting the code many times. Can anyone help me out here?
    My computer is awesome.

  2. #2
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Why not just do the following?
    Code:
    +[,>,>,>,>,>,>,>,>>+]
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Heh, thanks. A fairly simple solution. I guess I was thinking too deeply into it.
    My computer is awesome.

  4. #4
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    If you want a more general solution, to say, increase the number from 8 up to anything less than 256, you should probably walk the counter with you (and walk a value N with you, too).

    Code:
    *set the pointer over the cell containing the number N*
    *let's number this cell number 0*
    *loop forever*
    [
    >[-]>[-]<<[->+>+<<] **copy cell 0 into 1 and 2
    
    * We'll use cell 1 to count down to zero * cell 2 to keep track of N *
    * and we'll march the cells rightwards *
    
    > * put ptr on counting cell *
    [   * While count hasn't reached zero *
    -   * decrement counter *
    <,> * read input char * ptr back on counter *
    >  * ptr moves to cell that contains N *
    >[-]<[>+<-] * move N one cell over * emptying current cell *
    <
    [>+<-] * move counter one cell over * emptying counter cell *
    * ptr is now on counter cell *
    ]
    * counter has now reached zero *
    * move to the cell containing N *
    >
    * we've skipped the counter cell, which is now zero *
    * now we're back on the cell containing N * just like at the top of the loop *
    ]
    Here it is, more compressed.

    Code:
    [>[-]>[-]<<[->+>+<<]>[-<,>>>[-]<[>+<-]<[>+<-]]>]
    I haven't tested this, so see if it works :-)
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    I tried to make a program that counts how many characters of input has been given. The issue I had with that is that if you just increment a certain piece of memory for each character received as input then there is the task of converting it to ascii values so you can display it.
    My computer is awesome.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program quits unexpected
    By skelesp in forum C Programming
    Replies: 34
    Last Post: 12-10-2008, 09:10 AM
  2. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  3. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  4. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM