📜 ⬆️ ⬇️

Evolution of the Python programmer

Beginning


  1. def factorial ( x ) :
  2. if x == 0 :
  3. return 1
  4. else :
  5. return x * factorial ( x - 1 )
  6. print factorial ( 6 )


Programmer for a year (previously studied Pascal)


  1. def factorial ( x ) :
  2. result = 1
  3. i = 2
  4. while i < = x:
  5. result = result * i
  6. i = i + 1
  7. return result
  8. print factorial ( 6 )



Programmer for a year (Previously studied C)


  1. def fact ( x ) : # {
  2. result = i = 1 ;
  3. while ( i < = x ) : # {
  4. result * = i ;
  5. i + = 1 ;
  6. #}
  7. return result ;
  8. #}
  9. print ( fact ( 6 ) )

')

Programmer for a year (read SICP )


  1. @tailcall
  2. def fact ( x, acc = 1 ) :
  3. if ( x > 1 ) : return ( fact ( ( x - 1 ) , ( acc * x ) ) )
  4. else : return acc
  5. print ( fact ( 6 ) )


Programmer for a year in Python (previously studied 1C)


  1. def ObrabotkaObchisleniya ( ) :
  2. //
  3. return 0
  4. def Soobschit ( TekstSoobscheniya ) :
  5. print TekstSoobscheniya
  6. def Faktorial ( Znacheniye ) :
  7. Return Znacheniye * Faktorial ( Znacheniye- 1 )
  8. Soobschit ( Faktorial ( 6 ) )
  9. Sutki = 84000


Learning Python and sometimes Brainfuck


  1. import os
  2. def fact ( x ) :
  3. file = open ( "code.b" , 'w' )
  4. file . write ( "> ++++++++++ >>> +> + [>>> + [- [<<<<< [+ <<<<<] >> [[-]> [< <+> +> -] <[> + <-] <[> + <- [> + <- [> + <- [> + <- [> + <- [> + <- [> + <- [> + <- [> + <- [> [-] >>>> +> + <<<<<< - [> + <-]]]]]]]]]]> [<+> -] + >>>>>] <<<<< [<<<<<] >>>>>>> [>>>>>] ++ [- <<<< >>> ]> > -] + >>>>>] <[> ++ <-] <<<< [<[> + <-] <<<<] >> [-> [-] ++++++ [ <++++++++> -] >>>>] <<<<< [<[> +> + << -]>. <<<<<]>. >>>>] " )
  5. file . close ( )
  6. # todo: implement x parameter
  7. os . system ( '/ usr / bin / bf code.b' )
  8. fact ( 6 )


Programmer for a year in Python


  1. def Factorial ( x ) :
  2. res = 1
  3. for i in xrange ( 2 , x + 1 ) :
  4. res * = i
  5. return res
  6. print Factorial ( 6 )


Lazy Python'shchik


  1. def fact ( x ) :
  2. return x > 1 and x * fact ( x - 1 ) or 1
  3. print fact ( 6 )


Very lazy Python'shchik


  1. f = lambda x: x and x * f ( x - 1 ) or 1
  2. print f ( 6 )


Python'shchik - expert


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


Python's hacker


  1. import sys
  2. @tailcall
  3. def fact ( x, acc = 1 ) :
  4. if x: return fact ( x. __sub__ ( 1 ) , acc. __mul__ ( x ) )
  5. return acc
  6. sys . stdout . write ( str ( fact ( 6 ) ) + ' \ n '


Software expert


  1. from c_math import fact
  2. print fact ( 6 )


English expert programmer


  1. from c_maths import fact
  2. print fact ( 6 )


Web Programmer


  1. def factorial ( x ) :
  2. # -------------------------------------------------
  3. # --- Snippet of factorial calculation ---
  4. # --- Use at your own risk (c) Vasily Pupkin 2010 ---
  5. # -------------------------------------------------
  6. result = str ( 1 )
  7. i = 1 # Thanks for the hack Ivan
  8. while i < = x:
  9. #result = result * i # Probably better to use * =
  10. #result = str (result * result + i)
  11. #result = int (result * = i) # ??????
  12. result = str ( int ( result ) * i )
  13. #result = int (str (result) * i) # log
  14. i = i + 1
  15. return result
  16. print factorial ( 6 )


Unix programmer


  1. import os
  2. def fact ( x ) :
  3. os . system ( 'factorial' + str ( x ) )
  4. fact ( 6 )


Windows programmer


  1. NULL = None
  2. def CalculateAndPrintFactorialEx ( dwNumber,
  3. hOutputDevice,
  4. lpLparam
  5. lpWparam
  6. lpsscSecurity,
  7. * dwReserved ) :
  8. if lpsscSecurity ! = NULL:
  9. return NULL #Not implemented
  10. dwResult = dwCounter = 1
  11. while dwCounter < = dwNumber:
  12. dwResult * = dwCounter
  13. dwCounter + = 1
  14. hOutputDevice. write ( str ( dwResult ) )
  15. hOutputDevice. write ( ' \ n ' )
  16. return 1
  17. import sys
  18. CalculateAndPrintFactorialEx ( 6 , sys . Stdout , NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )


Programmer of a large office


  1. def new ( cls, * args, ** kwargs ) :
  2. return cls ( * args, ** kwargs )
  3. class Number ( object ) :
  4. pass
  5. class IntegralNumber ( int , Number ) :
  6. def toInt ( self ) :
  7. return new ( int , self )
  8. class InternalBase ( object ) :
  9. def __init__ ( self , base ) :
  10. self . base = base. toInt ( )
  11. def getBase ( self ) :
  12. return new ( IntegralNumber, self . base )
  13. class MathematicsSystem ( object ) :
  14. def __init__ ( self , ibase ) :
  15. Abstract
  16. @ classmethod
  17. def getInstance ( cls, ibase ) :
  18. try :
  19. cls .__ instance
  20. except AttributeError :
  21. cls .__ instance = new ( cls, ibase )
  22. return cls .__ instance
  23. class StandardMathematicsSystem ( MathematicsSystem ) :
  24. def __init__ ( self , ibase ) :
  25. if ibase. getBase ( ) ! = new ( IntegralNumber, 2 ) :
  26. raise NotImplementedError
  27. self . base = ibase. getBase ( )
  28. def calculateFactorial ( self , target ) :
  29. result = new ( IntegralNumber, 1 )
  30. i = new ( IntegralNumber, 2 )
  31. while i < = target:
  32. result = result * i
  33. i = i + new ( IntegralNumber, 1 )
  34. return result
  35. print StandardMathematicsSystem. getInstance ( new ( InternalBase, new ( IntegralNumber, 2 ) ) ) . calculateFactorial ( new ( IntegralNumber, 6 ) )


And what type do you belong to, % username% ?

upd .: I wonder who quietly in a mean-spirited karma merges? Kohl have an objection - have the courage to express it in the comments.

Source: https://habr.com/ru/post/112292/


All Articles