mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-19 10:48:58 +08:00
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@ -2,20 +2,20 @@ from bisect import bisect
|
||||
from itertools import accumulate
|
||||
|
||||
|
||||
def fracKnapsack(vl, wt, W, n):
|
||||
def frac_knapsack(vl, wt, w, n):
|
||||
"""
|
||||
>>> fracKnapsack([60, 100, 120], [10, 20, 30], 50, 3)
|
||||
>>> frac_knapsack([60, 100, 120], [10, 20, 30], 50, 3)
|
||||
240.0
|
||||
"""
|
||||
|
||||
r = list(sorted(zip(vl, wt), key=lambda x: x[0] / x[1], reverse=True))
|
||||
vl, wt = [i[0] for i in r], [i[1] for i in r]
|
||||
acc = list(accumulate(wt))
|
||||
k = bisect(acc, W)
|
||||
k = bisect(acc, w)
|
||||
return (
|
||||
0
|
||||
if k == 0
|
||||
else sum(vl[:k]) + (W - acc[k - 1]) * (vl[k]) / (wt[k])
|
||||
else sum(vl[:k]) + (w - acc[k - 1]) * (vl[k]) / (wt[k])
|
||||
if k != n
|
||||
else sum(vl[:k])
|
||||
)
|
||||
|
Reference in New Issue
Block a user