Home > Computer Science, Programming > The Best BF Program I’ve Ever Written

The Best BF Program I’ve Ever Written

I wrote a BF program which calculates every prime number from 2 to 100. This is it:


[-]++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++[>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[->>+>+>+>+<<<<<]>>>>>[-<<<<<+>>>>>][-]++[->+>+>+>+<<<<]>>>>[-<<<<+>>>>]<[<<<<->>>>-]<<<<[<[-]>[-]>>>>>[-]>[-]>>>>>>>>>>[-]<<<<<<<<<<<<<<<<<<[->+>+>>>>>+>+<<<<<<<<]>>>>>>>>[-<<<<<<<<+>>>>>>>>][-]>[-]>[-]>[-]>[-]<<<<<<<<<<<[->>>>>>>+>>+<<<<<<<<<]>>>>>>>>>[-<<<<<<<<<+>>>>>>>>>]<<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>][-]>[-]>[-]>[-]<<<<<[->>+<<]>>[<[->>+>+<<<]>>>[-<<<+>>>]<[>+<<-[>>[-]>+<<<-]>>>[-<<<+>>>]<[<-[<<<->>>[-]]+>-]<-]<<<+>>]<[-]>[-]>[-]>[-]>[-]<<<<<[->+<]>>[-]>[-]<<[->+>+<<]<<<<-[>>>>>>[-<<+>+>]<<[->>+<<]<<<<-]>>>>>>[-]<[-<+>]<[<<<<<<<<->>>>>>>>-]<<<<[-]<<<<[->>>>+<<<<]>>>>[>>>>>>>>>>>>>+<<<<<<<<<<<<<[-]][-]>[-]>[-]<<<+[->+>+>+<<<]>>>[-<<<+>>>]<[<<<<->>>>-]>>>>>>>>>>>>[->+>+<<]>>[-<<+>>]<-[<<<<<<<<<<<<<<<<<[-]>>>>>>>>>>>>>>>>>+]<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>[<<<<<<<<<<<<<<<<<<.>>>>>>>>>>>>>>>>>>[-]]<<<<<<<<<<<<<<<<<<<<+>-]

Since I’m using a slow Python interpreter, it takes a long time to finish. But it still works.

Advertisements
  1. November 9, 2009 at 6:38 pm

    I’m lost.

    for understanding, can you make a BF program that takes the number at cell-0, and change it to the next prime number up (as actual value, not as printable text)?

    • November 9, 2009 at 8:24 pm

      That would require some major modifications. But you can see it as a number if you go to your interpreter and change

      putchar(*data_pointer);

      into

      printf("%d ", *data_pointer);

      This will print it as an integer instead of a character.

      • November 10, 2009 at 10:34 am

        That’s not what I’m asking for.

        I just want the BF algorithm.

  2. November 10, 2009 at 5:12 pm

    [-]++++++++++++++++++++++++++++++++>>>>>>>>>>>>>>>>>>>>[-]+[<<<<<<<<<<<<<<<<<<<>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<>+>+>+>+<<<<>>>>[-<<<<>>>>][-]++[->+>+>+>+<<<>>>[-<<<>>>]<[<<<>>>-]<<<<[[-]>>>>>[-]>[-]>>>>>>>>>>[-]<<<<<<<<<<<<<<<<<+>+>>>>>+>+<<<<<<<>>>>>>>[-<<<<<<<>>>>>>>][-]>[-]>[-]>[-]>[-]<<<<<<<<<<>>>>>>+>>+<<<<<<<<>>>>>>>>[-<<<<<<<<>>>>>>>>]<<<<>>>+>+<<<<>>>>[-<<<<>>>>][-]>[-]>[-]>[-]<<<<>+<>[>+>+<<>>[-<<>>]+<>[-]>+<<>>[-<<>>]<[<-[<<>>[-]]+>-]<-]<<>][-]>[-]>[-]>[-]<<<<+>[-]>[-]<+>+<<]<<<>>>>>[-<+>]<>+<<]<<<>>>>>[-]<[-]<[<<<<<<<>>>>>>>-]<<<<[-]<<<>>>+<<<>>>[>>>>>>>>>>>>>+<<<<<<<<<<<<[-]>[-]<<+>+>+<<>>[-<<>>]<[<<<>>>-]>>>>>>>>>>>>[->+>+<>[-<>]<-[<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>+]<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<<<<<<.

    All those +'s at the beginning indicate the first number you want to input. Right now it's 32.

    • November 11, 2009 at 8:49 pm

      I have a feeling something is being lost in the commentation because there’s a bunch of <<<>>>.

      Can you try uploading it as a .txt file on you main site?

      • November 12, 2009 at 9:00 am

        It looks fine to me. There are supposed to be a lot of arrows.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: