Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
* [Sol5](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_01/sol5.py)
* [Sol6](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_01/sol6.py)
* [Sol7](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_01/sol7.py)
* [Sol8](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_01/sol8.py)
* Problem 02
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_02/sol1.py)
* [Sol2](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_02/sol2.py)
Expand Down
3 changes: 1 addition & 2 deletions divide_and_conquer/convex_hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def _validate_input(points):
)
elif not hasattr(points, "__iter__"):
raise ValueError(
"Expecting an iterable object "
f"but got an non-iterable type {points}"
"Expecting an iterable object " f"but got an non-iterable type {points}"
)
except TypeError as e:
print("Expecting an iterable of type Point, list or tuple.")
Expand Down
4 changes: 1 addition & 3 deletions graphs/dijkstra_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def show_graph(self):
# u -> v(w)
for u in self.adjList:
print(
u,
"->",
" -> ".join(str(f"{v}({w})") for v, w in self.adjList[u]),
u, "->", " -> ".join(str(f"{v}({w})") for v, w in self.adjList[u]),
)

def dijkstra(self, src):
Expand Down
4 changes: 1 addition & 3 deletions machine_learning/sequential_minimum_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,7 @@ def test_cancel_data():
for i in range(test_tags.shape[0]):
if test_tags[i] == predict[i]:
score += 1
print(
f"\r\nall: {test_num}\r\nright: {score}\r\nfalse: {test_num - score}"
)
print(f"\r\nall: {test_num}\r\nright: {score}\r\nfalse: {test_num - score}")
print(f"Rough Accuracy: {score / test_tags.shape[0]}")


Expand Down
47 changes: 47 additions & 0 deletions project_euler/problem_01/sol8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Problem Statement:
If we list all the natural number below 20 that are multiples of 3 or 5,
we get 3,5,6,9,10,12,15,18. The sum if these multiples is 78.

Find the sum of all the multiples of 3 or 5 below N.

"""


def solution(n, target):
"""
Efficient Solution for Sum Multiple of 3 or 5

>>> solution(3)
0
>>> solution(4)
3
>>> solution(10)
23
>>> solution(-7)
0
>>> solution(7000)
11432168
>>> solution(100000000000000000000)
2333333333333333333316666666666666666668
>>> solution(7000000000000000000000000000000)
11433333333333333333333333333332166666666666666666666666666668
>>> solution(9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)
23333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333321666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666669

Note : Non-efffcient solution display MemoryError
"""
if target > 0: # check for positive or negative
p = target // n
return (n * (p * (p + 1))) // 2
else:
return 0


if __name__ == "__main__":
N = int(input())
m = N - 1
print(solution(3, m) + solution(5, m) - solution(15, m))

# For detail explanation of the above problem head to the below link:
# https://github.com/BigOh-Koders/INCF2019/blob/master/MUL35/explanation.pdf