File tree 2 files changed +40
-0
lines changed
2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1
1
# pycodes
2
+
2
3
Códigos de Exemplo em Python
3
4
4
5
Repositório criado para hospedagem de códigos, testes e experimentos.
6
+
7
+ ## Arquivo fatorial_pd
8
+
9
+ Modelo de fatorial
Original file line number Diff line number Diff line change
1
+ import timeit
2
+ import time
3
+
4
+ def fat (n ):
5
+ if n <= 1 :
6
+ return 1
7
+ if not hasattr (fat , 'cache' ):
8
+ fat .cache = {}
9
+ if n in fat .cache :
10
+ return fat .cache [n ]
11
+ result = n * fat (n - 1 )
12
+ fat .cache [n ] = result
13
+ return result
14
+
15
+ def exec2n (n ):
16
+ print (f'Fatorial de { n } ' )
17
+ t1 = timeit .default_timer ()
18
+ res = fat (n )
19
+ t2 = timeit .default_timer ()
20
+ print (' - Resultado:' , res )
21
+ print (' - Tempo:' , round ((t2 - t1 ), 5 ))
22
+ return res
23
+
24
+
25
+ print ('Rodando pela primeira vez:' )
26
+ exec2n (100 )
27
+ print ()
28
+ exec2n (102 )
29
+ print ()
30
+ print ()
31
+
32
+ print ('Rodando pela segunda vez:' )
33
+ exec2n (100 )
34
+ print ()
35
+ exec2n (102 )
You can’t perform that action at this time.
0 commit comments