Skip to content

Commit b33ae00

Browse files
authored
Merge pull request #1 from TheAlgorithms/master
Create CONTRIBUTING.md (TheAlgorithms#864)
2 parents bb29dc5 + c2552cd commit b33ae00

File tree

102 files changed

+2042
-633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2042
-633
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ ENV/
8989
# Rope project settings
9090
.ropeproject
9191
.idea
92-
.DS_Store
92+
.DS_Store
93+
.try

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ install:
1616
- pip install flake8 # pytest # add another testing frameworks later
1717
before_script:
1818
# stop the build if there are Python syntax errors or undefined names
19-
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
19+
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
2020
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
2121
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
2222
script:

CONTRIBUTING.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Contributing guidelines
2+
3+
## Before contributing
4+
5+
Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before sending your pull requests, make sure that you **read the whole guidelines**. If you have any doubt on the contributing guide, please feel free to [state it clearly in an issue](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms).
6+
7+
## Contributing
8+
9+
### Contributor
10+
11+
We are very happy that you consider implementing algorithms and data structure for others! This repository is referenced and used by learners from all over the globe. Being one of our contributors, you agree and confirm that:
12+
13+
- your did your work - no plagiarism allowed
14+
- Any plagiarized work will not be merged.
15+
- your work will be distributed under [MIT License](License) once your pull request is merged
16+
- you submitted work fulfils or mostly fulfils our styles and standards
17+
18+
**New implementation** is welcome! For example, new solutions for a problem, different representations for a graph data structure or algorithm designs with different complexity.
19+
20+
**Improving comments** and **writing proper tests** are also highly welcome.
21+
22+
### Contribution
23+
24+
We appreciate any contribution, from fixing a grammar mistake in a comment to implementing complex algorithms. Please read this section if you are contributing your work.
25+
26+
#### Coding Style
27+
28+
We want your work to be readable by others; therefore, we encourage you to note the following:
29+
30+
- Please write in Python 3.x.
31+
32+
- If you know [PEP 8](https://www.python.org/dev/peps/pep-0008/) already, you will have no problem in coding style, though we do not follow it strictly. Read the remaining section and have fun coding!
33+
34+
- Always use 4 spaces to indent.
35+
36+
- Original code submission requires comments to describe your work.
37+
38+
- More on comments and docstrings:
39+
40+
The following are considered to be bad and may be requested to be improved:
41+
42+
```python
43+
x = x + 2 # increased by 2
44+
```
45+
46+
This is too trivial. Comments are expected to be explanatory. For comments, you can write them above, on or below a line of code, as long as you are consistent within the same piece of code.
47+
48+
*Sometimes, docstrings are avoided.* This will happen if you are using some editors and not careful with indentation:
49+
50+
```python
51+
"""
52+
This function sums a and b
53+
"""
54+
def sum(a, b):
55+
return a + b
56+
```
57+
58+
However, if you insist to use docstrings, we encourage you to put docstrings inside functions. Also, please pay attention to indentation to docstrings. The following is acceptable in this case:
59+
60+
```python
61+
def sumab(a, b):
62+
"""
63+
This function sums two integers a and b
64+
Return: a + b
65+
"""
66+
return a + b
67+
```
68+
69+
- `lambda`, `map`, `filter`, `reduce` and complicated list comprehension are welcome and acceptable to demonstrate the power of Python, as long as they are simple enough to read.
70+
71+
- This is arguable: **write comments** and assign appropriate variable names, so that the code is easy to read!
72+
73+
- Write tests to illustrate your work.
74+
75+
The following "testing" approaches are not encouraged:
76+
77+
```python
78+
input('Enter your input:')
79+
# Or even worse...
80+
input = eval(raw_input("Enter your input: "))
81+
```
82+
83+
Please write down your test case, like the following:
84+
85+
```python
86+
def sumab(a, b):
87+
return a + b
88+
# Write tests this way:
89+
print(sumab(1,2)) # 1+2 = 3
90+
print(sumab(6,4)) # 6+4 = 10
91+
# Or this way:
92+
print("1 + 2 = ", sumab(1,2)) # 1+2 = 3
93+
print("6 + 4 = ", sumab(6,4)) # 6+4 = 10
94+
```
95+
96+
- Avoid importing external libraries for basic algorithms. Use those libraries for complicated algorithms.
97+
98+
#### Other Standard While Submitting Your Work
99+
100+
- File extension for code should be `.py`.
101+
102+
- Please file your work to let others use it in the future. Here are the examples that are acceptable:
103+
104+
- Camel cases
105+
- `-` Hyphenated names
106+
- `_` Underscore-separated names
107+
108+
If possible, follow the standard *within* the folder you are submitting to.
109+
110+
- If you have modified/added code work, make sure the code compiles before submitting.
111+
112+
- If you have modified/added documentation work, make sure your language is concise and contains no grammar mistake.
113+
114+
- Add a corresponding explanation to [Algorithms-Explanation](https://github.com/TheAlgorithms/Algorithms-Explanation) (Optional but recommended).
115+
116+
- Most importantly,
117+
118+
- **be consistent with this guidelines while submitting.**
119+
- **join** [Gitter](https://gitter.im/TheAlgorithms) **now!**
120+
- Happy coding!
121+
122+
123+
124+
Writer [@poyea](https://github.com/poyea), Jun 2019.

Graphs/graph_list.py

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

Graphs/prim.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
"""
2+
Prim's Algorithm.
3+
4+
Determines the minimum spanning tree(MST) of a graph using the Prim's Algorithm
5+
6+
Create a list to store x the vertices.
7+
G = [vertex(n) for n in range(x)]
8+
9+
For each vertex in G, add the neighbors:
10+
G[x].addNeighbor(G[y])
11+
G[y].addNeighbor(G[x])
12+
13+
For each vertex in G, add the edges:
14+
G[x].addEdge(G[y], w)
15+
G[y].addEdge(G[x], w)
16+
17+
To solve run:
18+
MST = prim(G, G[0])
19+
"""
20+
21+
import math
22+
23+
24+
class vertex():
25+
"""Class Vertex."""
26+
27+
def __init__(self, id):
28+
"""
29+
Arguments:
30+
id - input an id to identify the vertex
31+
32+
Attributes:
33+
neighbors - a list of the vertices it is linked to
34+
edges - a dict to store the edges's weight
35+
"""
36+
self.id = str(id)
37+
self.key = None
38+
self.pi = None
39+
self.neighbors = []
40+
self.edges = {} # [vertex:distance]
41+
42+
def __lt__(self, other):
43+
"""Comparison rule to < operator."""
44+
return (self.key < other.key)
45+
46+
def __repr__(self):
47+
"""Return the vertex id."""
48+
return self.id
49+
50+
def addNeighbor(self, vertex):
51+
"""Add a pointer to a vertex at neighbor's list."""
52+
self.neighbors.append(vertex)
53+
54+
def addEdge(self, vertex, weight):
55+
"""Destination vertex and weight."""
56+
self.edges[vertex.id] = weight
57+
58+
59+
def prim(graph, root):
60+
"""
61+
Prim's Algorithm.
62+
63+
Return a list with the edges of a Minimum Spanning Tree
64+
65+
prim(graph, graph[0])
66+
"""
67+
A = []
68+
for u in graph:
69+
u.key = math.inf
70+
u.pi = None
71+
root.key = 0
72+
Q = graph[:]
73+
while Q:
74+
u = min(Q)
75+
Q.remove(u)
76+
for v in u.neighbors:
77+
if (v in Q) and (u.edges[v.id] < v.key):
78+
v.pi = u
79+
v.key = u.edges[v.id]
80+
for i in range(1, len(graph)):
81+
A.append([graph[i].id, graph[i].pi.id])
82+
return(A)

License renamed to LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 The Algorithms
3+
Copyright (c) 2019 The Algorithms
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Maths/lucasSeries.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Lucas Sequence Using Recursion
2+
3+
def recur_luc(n):
4+
if n == 1:
5+
return n
6+
if n == 0:
7+
return 2
8+
return (recur_luc(n-1) + recur_luc(n-2))
9+
10+
limit = int(input("How many terms to include in Lucas series:"))
11+
print("Lucas series:")
12+
for i in range(limit):
13+
print(recur_luc(i))

Project Euler/Problem 01/sol5.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a=3
2+
result=0
3+
while a=<1000:
4+
if(a%3==0 and a%5==0):
5+
result+=a
6+
elif(a%15==0):
7+
result-=a
8+
print(result)

0 commit comments

Comments
 (0)