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

Evolution of a Python programmer

Name: Anonymous 2007-05-25 5:34 ID:e87L90K/


#Newbie programmer
def factorial(x):
    if x == 0:
        return 1
    else:
        return x * factorial(x - 1)
print factorial(6)


#First year programmer, studied Pascal
def factorial(x):
    result = 1
    i = 2
    while i <= x:
        result = result * i
        i = i + 1
    return result
print factorial(6)


#First year programmer, studied C
def fact(x): #{
    result = i = 1;
    while (i <= x): #{
        result *= i;
        i += 1;
    #}
    return result;
#}
print(fact(6))


#First year programmer, SICP
@tailcall
def fact(x, acc=1):
    if (x > 1): return (fact((x - 1), (acc * x)))
    else:       return acc
print(fact(6))


#First year programmer, Python
def Factorial(x):
    res = 1
    for i in xrange(2, x + 1):
        res *= i
    return res
print Factorial(6)


#Lazy Python programmer
def fact(x):
    return x > 1 and x * fact(x - 1) or 1
print fact(6)


#Lazier Python programmer
f = lambda x: x and x * f(x - 1) or 1
print f(6)


#Python expert programmer
import operator as op
import functional as f
fact = lambda x: f.foldl(op.mul, 1, xrange(2, x + 1))
print fact(6)


#Python hacker
import sys
@tailcall
def fact(x, acc=1):
    if x: return fact(x.__sub__(1), acc.__mul__(x))
    return acc
sys.stdout.write(str(fact(6)) + '\n')


#EXPERT PROGRAMMER
import c_math
fact = c_math.fact
print fact(6)


#ENGLISH EXPERT PROGRAMMER
import c_maths
fact = c_maths.fact
print fact(6)


#Web designer
def factorial(x):
    #-------------------------------------------------
    #--- Code snippet from The Math Vault          ---
    #--- Calculate factorial (C) Arthur Smith 1999 ---
    #-------------------------------------------------
    result = str(1)
    i = 1 #Thanks Adam
    while i <= x:
        #result = result * i  #It's faster to use *=
        #result = str(result * result + i)
           #result = int(result *= i) #??????
        result str(int(result) * i)
        #result = int(str(result) * i)
        i = i + 1
    return result
print factorial(6)


#Unix programmer
import os
def fact(x):
    os.system('factorial ' + str(x))
fact(6)


#Windows programmer
NULL = None
def CalculateAndPrintFactorialEx(dwNumber,
                                 hOutputDevice,
                                 lpLparam,
                                 lpWparam,
                                 lpsscSecurity,
                                 *dwReserved):
    if lpsscSecurity != NULL:
        return NULL #Not implemented
    dwResult = dwCounter = 1
    while dwCounter <= dwNumber:
        dwResult *= dwCounter
        dwCounter += 1
    hOutputDevice.write(str(dwResult))
    hOutputDevice.write('\n')
    return 1
import sys
CalculateAndPrintFactorialEx(6, sys.stdout, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)


#Enterprise programmer
def new(cls, *args, **kwargs):
    return cls(*args, **kwargs)

class Number(object):
    pass

class IntegralNumber(int, Number):
    def toInt(self):
        return new (int, self)

class InternalBase(object):
    def __init__(self, base):
        self.base = base.toInt()

    def getBase(self):
        return new (IntegralNumber, self.base)

class MathematicsSystem(object):
    def __init__(self, ibase):
        Abstract

    @classmethod
    def getInstance(cls, ibase):
        try:
            cls.__instance
        except AttributeError:
            cls.__instance = new (cls, ibase)
        return cls.__instance

class StandardMathematicsSystem(MathematicsSystem):
    def __init__(self, ibase):
        if ibase.getBase() != new (IntegralNumber, 2):
            raise NotImplementedError
        self.base = ibase.getBase()

    def calculateFactorial(self, target):
        result = new (IntegralNumber, 1)
        i = new (IntegralNumber, 2)
        while i <= target:
            result = result * i
            i = i + new (IntegralNumber, 1)
        return result

print StandardMathematicsSystem.getInstance(new (InternalBase, new (IntegralNumber, 2))).calculateFactorial(new (IntegralNumber, 6))

Name: Anonymous 2007-05-25 5:36 ID:Heaven

OH JEEZ IVE NEVER SEEN THIS SORT OF THING BEFORE
WHAT A JOKE THAT ISNT TIRED

Name: Anonymous 2007-05-25 10:32 ID:K5cBcHMT

import c_math
fact = c_math.fact
print fact(6)


Wrong, that should be
from c_math import fact
print fact(6)

Name: Anonymous 2007-05-25 10:33 ID:K5cBcHMT

Also shiichan is stupid.

Name: Anonymous 2007-05-25 10:53 ID:odf/TSv6

Don't complain about the board software, it's against the rules!

Name: Anonymous 2007-05-25 11:01 ID:pMRzngc6

>>5
i completely agrMySQL Error check your synta near '''

Name: Anonymous 2007-05-25 13:04 ID:e87L90K/

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\;DELETE FROM posts' at line 1

Oops

Name: Theo 2007-05-25 13:24 ID:qTgx4ka8

Your expert python programmer uses an interesting approach, what's wrong with just

f = lambda x: reduce(int.__mul__,xrange(2,x+1),1)

Name: Anonymous 2007-05-25 13:37 ID:aoNYwVT+

the windows programmer and web designer cracked me up

Name: Anonymous 2007-05-25 13:51 ID:G7AS96Pv

Very good, sir - I laughed out loud!

Especially liked EXPERT PROGRAMMER, his ENGLISH counterpart and Web Designer.

Reading Windows Programmer and Enterprise Programmer's code made me feel a little ill.

Name: Anonymous 2007-05-25 15:35 ID:nTL0p3EM

LOL LINKED FROM REDDIT
HI REDDIT

Name: BEEKER 2007-05-25 15:49 ID:lUgnRdyT

I CREATED PYTHONG!

Name: REDDIT 2007-05-25 15:57 ID:AP+9sTRL

HELLO

Name: Anonymous 2007-05-25 16:20 ID:AnkxhxVe

>>8
Yes, that was better. With reduce vs foldl, just what you're used to, but reduce is faster, should be preferred. With int.__mul__, it restricts what you do to to ints, but then again that's what you need, so that'd be a better one.

Thanks for posting to Reddit, wow, Anonymous getting famous. Glad you liked it.

Actually, I did that in a rush, and yeah, it was after reading the evolution of a Haskell programmer. At first I wanted to mock it a bit, but by the time I was writing EXPERT PROGRAMMER I got a few ideas to make it funny.

Name: reddit 2007-05-25 16:30 ID:U3wvE5Ua

You've got a typo in the web developer one:
result str(int(result) * i)

should be
result = str(int(result) * i)

Name: Anonymous 2007-05-25 16:32 ID:Heaven

Name: Anonymous 2007-05-25 16:35 ID:Heaven

>>16
What does this have to do with the topic? Or is this just your way to say "I read reddit"?

Name: Kris 2007-05-25 16:36 ID:QlEYgv0t

!! in fortran
gamma(7)

Name: Anonymous 2007-05-25 16:40 ID:AnkxhxVe

Thanks all for your suggestions, I've fixed it:


#Newbie programmer
def factorial(x):
    if x == 0:
        return 1
    else:
        return x * factorial(x - 1)
print factorial(6)


#First year programmer, studied Pascal
def factorial(x):
    result = 1
    i = 2
    while i <= x:
        result = result * i
        i = i + 1
    return result
print factorial(6)


#First year programmer, studied C
def fact(x): #{
    result = i = 1;
    while (i <= x): #{
        result *= i;
        i += 1;
    #}
    return result;
#}
print(fact(6))


#First year programmer, SICP
@tailcall
def fact(x, acc=1):
    if (x > 1): return (fact((x - 1), (acc * x)))
    else:       return acc
print(fact(6))


#First year programmer, Python
def Factorial(x):
    res = 1
    for i in xrange(2, x + 1):
        res *= i
    return res
print Factorial(6)


#Lazy Python programmer
def fact(x):
    return x > 1 and x * fact(x - 1) or 1
print fact(6)


#Lazier Python programmer
f = lambda x: x and x * f(x - 1) or 1
print f(6)


#Python expert programmer
fact = lambda x: reduce(int.__mul__, xrange(2, x + 1), 1)
print fact(6)


#Python hacker
import sys
@tailcall
def fact(x, acc=1):
    if x: return fact(x.__sub__(1), acc.__mul__(x))
    return acc
sys.stdout.write(str(fact(6)) + '\n')


#EXPERT PROGRAMMER
from c_math import fact
print fact(6)


#BRITISH EXPERT PROGRAMMER
from c_maths import fact
print fact(6)


#Web designer
def factorial(x):
    #-------------------------------------------------
    #--- Code snippet from The Math Vault          ---
    #--- Calculate factorial (C) Arthur Smith 1999 ---
    #-------------------------------------------------
    result = str(1)
    i = 1 #Thanks Adam
    while i <= x:
        #result = result * i  #It's faster to use *=
        #result = str(result * result + i)
           #result = int(result *= i) #??????
        result = str(int(result) * i)
        #result = int(str(result) * i)
        i = i + 1
    return result
print factorial(6)


#Unix programmer
import os
def fact(x):
    os.system('factorial ' + str(x))
fact(6)


#Windows programmer
NULL = None
def CalculateAndPrintFactorialEx(dwNumber,
                                 hOutputDevice,
                                 lpLparam,
                                 lpWparam,
                                 lpsscSecurity,
                                 *dwReserved):
    if lpsscSecurity != NULL:
        return NULL #Not implemented
    dwResult = dwCounter = 1
    while dwCounter <= dwNumber:
        dwResult *= dwCounter
        dwCounter += 1
    hOutputDevice.write(str(dwResult))
    hOutputDevice.write('\n')
    return 1
import sys
CalculateAndPrintFactorialEx(6, sys.stdout, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)


#Enterprise programmer
def new(cls, *args, **kwargs):
    return cls(*args, **kwargs)

class Number(object):
    pass

class IntegralNumber(int, Number):
    def toInt(self):
        return new (int, self)

class InternalBase(object):
    def __init__(self, base):
        self.base = base.toInt()

    def getBase(self):
        return new (IntegralNumber, self.base)

class MathematicsSystem(object):
    def __init__(self, ibase):
        Abstract

    @classmethod
    def getInstance(cls, ibase):
        try:
            cls.__instance
        except AttributeError:
            cls.__instance = new (cls, ibase)
        return cls.__instance

class StandardMathematicsSystem(MathematicsSystem):
    def __init__(self, ibase):
        if ibase.getBase() != new (IntegralNumber, 2):
            raise NotImplementedError
        self.base = ibase.getBase()

    def calculateFactorial(self, target):
        result = new (IntegralNumber, 1)
        i = new (IntegralNumber, 2)
        while i <= target:
            result = result * i
            i = i + new (IntegralNumber, 1)
        return result

print StandardMathematicsSystem.getInstance(new (InternalBase, new (IntegralNumber, 2))).calculateFactorial(new (IntegralNumber, 6))

Name: Anonymous 2007-05-25 16:43 ID:qjUouPUi

You morons, you linked world4chan on the biggest gathering place of EXPERT PROGRAMMERS.  We'll be overrun by the rampant lack of interrogating for roughly an hour.

Name: Anonymous 2007-05-25 16:44 ID:odf/TSv6

Good, I was bored anyway.

Name: REDDIT 2007-05-25 17:33 ID:oZyU7L2l

Demands Lisp/Haskell versions

Name: Gdr 2007-05-25 17:35 ID:o5J3SD9D

Engineer's approach (by and large good enough):

from math import *
def fact_approx(n): return int(round(sqrt(2 * pi * n) * pow(n / exp(1), n) * (1 + 1/(12.0*n))))

Name: Anonymous 2007-05-25 17:56 ID:q7www0TP

dont forget perl:

sub fact { $_[0]<2?$_[0]:$_[0]*fact($_[0]-1) }
print fact 6;

Name: Anonymous 2007-05-25 17:57 ID:UvONqgDQ

>>1
HAHAHAHAHAHA you think you're though huh ?
ONE WORD forced indentation of the code

Name: lolz 2007-05-25 18:20 ID:Ic80xZWy

You fags are on Reddit homepage!

http://programming.reddit.com/info/1tjui/comments

Name: Anonymous 2007-05-25 18:33 ID:Sr9IzRfS

4chan? what the fuck where are all the pictures?
im going back to /b/
fucking reddit

Name: Anonymous 2007-05-25 18:43 ID:mHFMDOiL

FUCK YOU REDDIT GTFO

Name: Anonymous 2007-05-25 19:22 ID:gow7St5L

>>30
sub fact{2*(($_=pop)*atan2 1,0)**.5*$_**$_/exp}
print fact 142;

Name: Anonymous 2007-05-25 19:36 ID:Heaven

>>35
sub fact{2*(($_=pop)*atan2 1,0)**.5*(1+1/(12*$_))*$_**$_/exp}

Name: "; DELETE" 2007-05-25 20:04 ID:hn+3Jv+w

;DELETE

Name: Anonymous 2007-05-25 20:10 ID:Heaven

the only funny ones are the web developer and windows developer

this shouldn't really be on reddit

Name: Anonymous 2007-05-25 20:32 ID:fA5cFfE/

Reddit? Is this that site full of fags who have read SICP?

Name: Anonymous 2007-05-25 20:48 ID:Heaven

>>39
I think you're thinking of wikipedoland.

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