Compare commits

...

22 Commits

Author SHA1 Message Date
DIVYASREE S
cea18ff69b
Merge 8ad73811e5 into e3bd7721c8 2024-11-18 17:13:04 +05:30
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]
3e9ca92ca9
[pre-commit.ci] pre-commit autoupdate (#12349)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.1 → v0.7.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.1...v0.7.2)
- [github.com/tox-dev/pyproject-fmt: v2.4.3 → v2.5.0](https://github.com/tox-dev/pyproject-fmt/compare/v2.4.3...v2.5.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-04 21:09:03 +01:00
DIVYASREE S
8ad73811e5
Delete blockchain/proof_of_work.py 2024-10-10 22:04:33 +05:30
pre-commit-ci[bot]
44cb9a30f7 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-10 16:33:40 +00:00
DIVYASREE S
f55f9aba89
Updated proof_of_work.py 2024-10-10 22:03:33 +05:30
DIVYASREE S
9aa315441b
Updated proof_of_work.py 2024-10-10 22:01:48 +05:30
DIVYASREE S
390cd7e12e
Updated proof_of_work.py 2024-10-10 22:00:17 +05:30
pre-commit-ci[bot]
bbe09d7c4c [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-10 16:22:37 +00:00
DIVYASREE S
5a7b2ffbba
Updated proof_of_work.py 2024-10-10 21:52:14 +05:30
pre-commit-ci[bot]
bd89e9705f [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-10 16:20:58 +00:00
DIVYASREE S
374cbc2bf9
Created proof_of_work.py 2024-10-10 21:50:01 +05:30
DIVYASREE S
e14f6d5122
Updated proof_of_stake.py 2024-10-10 21:46:12 +05:30
pre-commit-ci[bot]
8b9ff8d4f3 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-10 16:12:09 +00:00
DIVYASREE S
df4c444095
Created and updated proof_of_stake.py 2024-10-10 21:40:33 +05:30
DIVYASREE S
b1c7d37812
Delete blockchain/proof_of_stake.py 2024-10-10 21:39:40 +05:30
pre-commit-ci[bot]
2046ea45bc [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-10 16:03:51 +00:00
DIVYASREE S
82064e3a23
Changes to proof_of_stake.py 2024-10-10 21:32:04 +05:30
pre-commit-ci[bot]
d770fa5bf5 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-10 15:54:31 +00:00
DIVYASREE S
28df0f3c9b
Updated proof_of_stake.py 2024-10-10 21:17:13 +05:30
DIVYASREE S
f467cec98a
Created proof_of_stake.py 2024-10-10 21:12:51 +05:30
4 changed files with 45 additions and 5 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
rev: v0.7.3
hooks:
- id: ruff
- id: ruff-format
@ -29,7 +29,7 @@ repos:
- tomli
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.4.3"
rev: "v2.5.0"
hooks:
- id: pyproject-fmt
@ -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

@ -0,0 +1,40 @@
import random
class Validator:
def __init__(self, name: str, stake: int) -> None:
"""
Initializes a new validator with a given name and stake.
Args:
name (str): The name of the validator.
stake (int): The amount of stake the validator has.
"""
self.name = name
self.stake = stake
def choose_validator(validators: list[Validator]) -> Validator:
"""
Selects a validator to create the next block based on the weight of their stake.
The higher the stake, the greater the chance to be selected.
Args:
validators (list[Validator]): A list of Validator objects.
Returns:
Validator: The selected validator based on weighted random selection.
Example:
>>> validators = [Validator("Alice", 50), Validator("Bob", 30)]
>>> chosen = choose_validator(validators)
>>> isinstance(chosen, Validator)
True
"""
total_stake = sum(v.stake for v in validators)
weighted_validators = [(v, v.stake / total_stake) for v in validators]
selected = random.choices(
[v[0] for v in weighted_validators], weights=[v[1] for v in weighted_validators]
)
return selected[0]

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,4 +1,4 @@
#!/usr/bin/env python3
#!python
import os
try: