1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108  def c_recur(result, list, start, end, left): #recursive function, do not use it
if start>=end or left<=0:
result.append(tuple(list));
return;
for i in range(start, end):
list.append(i);
c_recur(result, list, i+1, end+1, left1);
list.pop();
def p_recur(result, list, marks, start, n, left): #recursive function, do not use it
if left<=0:
result.append(tuple(list));
return;
for i in range(0, n):
if not marks[i]:
marks[i]=True;
list.append(start+i);
p_recur(result, list, marks, start, n, left1);
list.pop();
marks[i]=False;
def c(k, n): #generate all kcombinations from range(0, n)
if k<=0 or n<=0 or k>n:
return [];
result=[];
c_recur(result, [], 0, nk+1, k);
return result;
def p(k, n): #generate all kpermutations from range(0, n)
if k<=0 or n<=0 or k>n:
return [];
result=[];
p_recur(result, [], [False]*n, 0, n, k);
return result;
def select(k, list): #generate all kcombinations from list
result=[]
n=len(list)
for indices in c(k, n):
l=[]
for i in indices:
l.append(list[i])
result.append(tuple(l))
return result
def permute(list): #generate all kpermutations from list
result=[]
n=len(list)
for indices in p(n, n):
l=[]
for i in indices:
l.append(list[i])
result.append(tuple(l))
return result
def diff(l1, l2): #return l1\l2
l=[]
for i in l1:
if i not in l2:
l.append(i)
return l
def factor(n): #factorize n
r=n;
i=2;
h={};
i=2;
while r>1:
while r%i==0:
r//=i;
if i not in h:
h[i]=0;
h[i]+=1;
i+=1;
return h;
def ffactor(n): #factorize n!
h={}
for i in xrange(2, n+1):
f=factor(i)
for k in f:
if k not in h:
h[k]=0
h[k]+=f[k]
return h
def gcd(m, n):
if m==0:
return n
while m!=0:
n%=m
m,n=n,m
return n

Easy Math Editor
This discussion board is a place to discuss our Daily Challenges and the math and science related to those challenges. Explanations are more than just a solution — they should explain the steps and thinking strategies that you used to obtain the solution. Comments should further the discussion of math and science.
When posting on Brilliant:
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
\(
...\)
or\[
...\]
to ensure proper formatting.2 \times 3
2^{34}
a_{i1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
There are no comments in this discussion.