Compare commits

...

6 Commits

Author SHA1 Message Date
Reeka
c3aa695f1c
Merge 7800f1e645 into f3f32ae3ca 2024-11-21 21:38:24 +05:30
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
pre-commit-ci[bot]
7800f1e645 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-25 19:37:30 +00:00
Harsh Gupta
32634eff5a Add doctests for sum_of_arithmetic_series function 2024-10-26 00:52:18 +05:30
4 changed files with 41 additions and 22 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

@ -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):

View File

@ -1,23 +1,42 @@
# DarkCoder
def sum_of_series(first_term: int, common_diff: int, num_of_terms: int) -> float:
# Reeka
def sum_of_ap_series(a: int, d: int, n: int) -> int:
"""
Find the sum of n terms in an arithmetic progression.
Calculates the sum of the first 'n' terms of an arithmetic progression (AP)
series with the first term 'a' and common difference 'd'.
>>> sum_of_series(1, 1, 10)
55.0
>>> sum_of_series(1, 10, 100)
49600.0
Parameters:
a (int): The first term of the AP.
d (int): The common difference between terms.
n (int): The number of terms to sum.
Returns:
int: The sum of the first 'n' terms of the AP.
Examples:
>>> sum_of_ap_series(1, 1, 5) # Sum of first 5 natural numbers
15
>>> sum_of_ap_series(2, 3, 4) # Sum of 2, 5, 8, 11
26
>>> sum_of_ap_series(5, 0, 3) # Sum of 5, 5, 5
15
>>> sum_of_ap_series(1, 2, 1) # Single term AP series
1
>>> sum_of_ap_series(1, -1, 5) # Decreasing AP series
-5
>>> sum_of_ap_series(1, 1, -5) # Negative 'n' should raise an error
Traceback (most recent call last):
...
ValueError: Number of terms 'n' must be a positive integer
>>> sum_of_ap_series(1, 1, 0) # Zero terms should also raise an error
Traceback (most recent call last):
...
ValueError: Number of terms 'n' must be a positive integer
"""
total = (num_of_terms / 2) * (2 * first_term + (num_of_terms - 1) * common_diff)
# formula for sum of series
return total
if n <= 0:
raise ValueError("Number of terms 'n' must be a positive integer")
# Formula for the sum of an AP series: S_n = n/2 * (2a + (n-1) * d)
return n * (2 * a + (n - 1) * d) // 2
def main():
print(sum_of_series(1, 1, 10))
if __name__ == "__main__":
import doctest
doctest.testmod()
# Reeka

View File

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