Compare commits

...

6 Commits

Author SHA1 Message Date
simin75simin
8d3c97e5c7
Merge cb2ad85223 into f3f32ae3ca 2024-11-22 13:57:14 +01:00
pre-commit-ci[bot]
f3f32ae3ca
[pre-commit.ci] pre-commit autoupdate (#12385)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.3 → v0.7.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.3...v0.7.4)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-18 22:07:12 +01:00
Christian Clauss
e3bd7721c8
validate_filenames.py Shebang python for Windows (#12371) 2024-11-15 14:59:14 +01:00
pre-commit-ci[bot]
e3f3d668be
[pre-commit.ci] pre-commit autoupdate (#12370)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.2 → v0.7.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.2...v0.7.3)
- [github.com/abravalheri/validate-pyproject: v0.22 → v0.23](https://github.com/abravalheri/validate-pyproject/compare/v0.22...v0.23)

* Update sudoku_solver.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2024-11-11 21:05:50 +01:00
simin75simin
cb2ad85223 updating DIRECTORY.md 2024-10-16 14:02:34 +00:00
siminsimin
fac0d7dba8 Compute the area of a polygon. 2024-10-16 22:02:13 +08:00
5 changed files with 35 additions and 4 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.7.4
hooks:
- id: ruff
- id: ruff-format
@ -42,7 +42,7 @@ repos:
pass_filenames: false
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.22
rev: v0.23
hooks:
- id: validate-pyproject

View File

@ -457,6 +457,7 @@
## Geometry
* [Geometry](geometry/geometry.py)
* [Shoelace](geometry/shoelace.py)
## Graphics
* [Bezier Curve](graphics/bezier_curve.py)

View File

@ -172,7 +172,7 @@ def solved(values):
def from_file(filename, sep="\n"):
"Parse a file into a list of strings, separated by sep."
return open(filename).read().strip().split(sep) # noqa: SIM115
return open(filename).read().strip().split(sep)
def random_puzzle(assignments=17):

30
geometry/shoelace.py Normal file
View File

@ -0,0 +1,30 @@
def area_of_polygon(xs: list[float], ys: list[float]) -> float:
"""
Compute the area of a polygon. The polygon has to be planar and simple
(not self-intersecting). The vertices have to be ordered in the
counter-clockwise direction.
https://en.wikipedia.org/wiki/Shoelace_formula
Args:
xs: list of x coordinates of the polygon vertices in counter-clockwise order
ys: list of y coordinates of the polygon vertices in counter-clockwise order
Returns:
area of the polygon
>>> from math import isclose
>>> xs = [1, 3, 7, 4, 8]
>>> ys = [6, 1, 2, 4, 5]
>>> isclose(area_of_polygon(xs, ys), 16.5)
True
"""
return 0.5 * sum(
(ys[i] + ys[(i + 1) % len(ys)]) * (xs[i] - xs[(i + 1) % len(xs)])
for i in range(len(xs))
)
if __name__ == "__main__":
import doctest
doctest.testmod()

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!python
import os
try: