El Noguer

Joaquim Perez i Noguer

El llenguatge de programació Brainfuck

Filed under: Ciència i tecnologia — Joaquim Perez Noguer at 8:57 am on Divendres, juliol 20, 2012

El llenguatges de programació més estrany de tots Brainfuck:

brainfuck command C equivalent
(Program Start) char array[30000];
char *ptr=array;
> ++ptr;
< --ptr;
+ ++*ptr;
- --*ptr;
. putchar(*ptr);
, *ptr=getchar();
[ while (*ptr) {
] }

En Brainfuck el programa típic Hello world que mostra per pantalla el text “Hello world” quedaria així:

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

 

Tot i així Brainfuck no és l’únic en la seva espècie, a Rosettacode.org, que vol ser la pedra Rosetta dels llenguatges de programació, descobreixo llenguatges tan curiosos com aquests:

el llenguatge J:

bubbleSort=:  (([ (<. , >.) {.@]) , }.@])/^:_

el llenguatge PicoLisp:

(de bubbleSort (Lst)
   (use Chg
      (loop
         (off Chg)
         (for (L Lst (cdr L) (cdr L))
            (when (> (car L) (cadr L))
               (xchg L (cdr L))
               (on Chg) ) )
         (NIL Chg Lst) ) ) )

el llenguatge Ursala:

#import nat
 
bubblesort "p" = @iNX ^=T ^llPrEZryPrzPlrPCXlQ/~& @l ~&aitB^?\~&a "p"?ahthPX/~&ahPfatPRC ~&ath2fahttPCPRC
 
#cast %nL
 
example = bubblesort(nleq) <362,212,449,270,677,247,567,532,140,315>

i el llenguatge Perl (molt famós però també força complicat de llegir si no es coneix):

sub bubble_sort (@a is rw) {
    for ^@a -> $i {
        for $i ^..^ @a -> $j {
            @a[$j] < @a[$i] and @a[$i, $j] = @a[$j, $i];
        }
    }
}

 

 

 

 



No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>