Skip to content

Commit 3efca15

Browse files
committed
moved files
combined combinations with permutations, moved stata_python into main folder
1 parent 77a74d1 commit 3efca15

File tree

4 files changed

+23
-71
lines changed

4 files changed

+23
-71
lines changed
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,28 @@
44
55
@author: rayde
66
"""
7+
78
'''
8-
Two ways to manually code combinatorics in python without replacement.
9+
Get all the possible permutations for a set of objects.
10+
'''
11+
12+
from itertools import product
13+
import pandas as pd
14+
15+
def perm_possible(items, repeat=5):
16+
perm = product(items, repeat)
17+
return [i for i in list(perm)]
18+
19+
perm = perm_possible([0,1])
20+
21+
922

10-
This isn't from leetcode, but an exercise in combinatorics from math for data science
11-
specialization on Coursera.
1223
'''
24+
Two ways to manually code combinatorics in python without replacement.
1325
26+
'''
1427

28+
#Method 1
1529
n=8
1630
count = 0
1731

@@ -23,17 +37,20 @@
2337

2438
print(count)
2539

40+
#Method 2
2641
#C(n,r)=n!/(n−r)!r!
2742

2843
def combinatorics(n, k):
44+
45+
# Calculate n-factorial
2946
n_list = list(range(2, n))
3047
n_list.reverse()
3148
n_factorial = n
3249

3350
for each in n_list:
3451
n_factorial = n_factorial*(each)
3552

36-
53+
# Calculate n minus k factorial
3754
n_r = n-k
3855

3956
n_r_list = list(range(2, n_r))
@@ -44,11 +61,13 @@ def combinatorics(n, k):
4461
for each in n_r_list:
4562
n_r_factorial = each*n_r_factorial
4663

64+
# Calculate k factorial
4765
k_list = list(range(2, k))
4866
k_list.reverse()
4967
k_factorial = k
5068

5169
for each in k_list:
5270
k_factorial = k_factorial*(each)
5371

72+
# Plug into formula and return
5473
return n_factorial/(n_r_factorial*k_factorial)

nasdaq_calendars.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

permutations.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)