Skip to content

Commit

Permalink
python/difference-of-squares: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 16, 2024
1 parent cce41d9 commit 3ca6246
Show file tree
Hide file tree
Showing 15 changed files with 612 additions and 7 deletions.
1 change: 1 addition & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
- [reverse-string](./reverse-string/README.md)
- [roman-numerals](./roman-numerals/README.md)
- [scrabble-score](./scrabble-score/README.md)
- [difference-of-squares](./difference-of-squares/README.md)
1 change: 1 addition & 0 deletions python/difference-of-squares/.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!coverage.py: This is a private format, don't read it directly!{"arcs":{"/home/vpayno/git_vpayno/exercism-workspace/python/difference-of-squares/test/__init__.py":[[0,0],[0,-1]],"/home/vpayno/git_vpayno/exercism-workspace/python/difference-of-squares/difference_of_squares.py":[[0,1],[1,4],[4,14],[14,24],[24,-1],[24,31],[4,11],[11,-4],[14,21],[21,-14],[31,-24]]}}
34 changes: 34 additions & 0 deletions python/difference-of-squares/.coverage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" ?>
<coverage branch-rate="1" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.8571" lines-covered="6" lines-valid="7" timestamp="1713242888288" version="4.5.4">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/vpayno/git_vpayno/exercism-workspace/python/difference-of-squares</source>
</sources>
<packages>
<package branch-rate="1" complexity="0" line-rate="0.8571" name=".">
<classes>
<class branch-rate="1" complexity="0" filename="difference_of_squares.py" line-rate="0.8571" name="difference_of_squares.py">
<methods/>
<lines>
<line hits="0" number="0"/>
<line hits="1" number="4"/>
<line hits="1" number="11"/>
<line hits="1" number="14"/>
<line hits="1" number="21"/>
<line hits="1" number="24"/>
<line hits="1" number="31"/>
</lines>
</class>
</classes>
</package>
<package branch-rate="1" complexity="0" line-rate="1" name="test">
<classes>
<class branch-rate="1" complexity="0" filename="test/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
</classes>
</package>
</packages>
</coverage>
2 changes: 2 additions & 0 deletions python/difference-of-squares/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
omit = __init__.py, *_test.py
1 change: 1 addition & 0 deletions python/difference-of-squares/.pylintrc
7 changes: 6 additions & 1 deletion python/difference-of-squares/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ Finding the best algorithm for the problem is a key skill in software engineerin

### Based on

Problem 6 at Project Euler - https://projecteuler.net/problem=6
Problem 6 at Project Euler - https://projecteuler.net/problem=6

### My Solution

- [my solution](./difference_of_squares.py)
- [run-tests](./run-tests-python.txt)
33 changes: 27 additions & 6 deletions python/difference-of-squares/difference_of_squares.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
def square_of_sum(number):
pass
"""Python Difference of Squares Exercism"""


def sum_of_squares(number):
pass
def square_of_sum(number: int) -> int:
"""Calculates the square of sum.
:param number: int
:return: int
"""

def difference_of_squares(number):
pass
return (number * (number + 1) // 2) ** 2


def sum_of_squares(number: int) -> int:
"""Calculates the sum of squares.
:param number: int
:return: int
"""

return (number * (number + 1) * (2 * number + 1)) // 6


def difference_of_squares(number: int) -> int:
"""Calculates the difference of squares.
:param number: int
:return: int
"""

return square_of_sum(number) - sum_of_squares(number)
31 changes: 31 additions & 0 deletions python/difference-of-squares/difference_of_squares.py,cover
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
> """Python Difference of Squares Exercism"""


> def square_of_sum(number: int) -> int:
> """Calculates the square of sum.

> :param number: int
> :return: int
> """

> return (number * (number + 1) // 2) ** 2


> def sum_of_squares(number: int) -> int:
> """Calculates the sum of squares.

> :param number: int
> :return: int
> """

> return (number * (number + 1) * (2 * number + 1)) // 6


> def difference_of_squares(number: int) -> int:
> """Calculates the difference of squares.

> :param number: int
> :return: int
> """

> return square_of_sum(number) - sum_of_squares(number)
5 changes: 5 additions & 0 deletions python/difference-of-squares/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
pythonpath = .
addopts = --doctest-modules
markers =
task: exercise task/step
Loading

0 comments on commit 3ca6246

Please sign in to comment.