mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Compare commits
7 Commits
24b83e8e59
...
1a7c711881
Author | SHA1 | Date | |
---|---|---|---|
|
1a7c711881 | ||
|
f3f32ae3ca | ||
|
e3bd7721c8 | ||
|
e3f3d668be | ||
|
3e9ca92ca9 | ||
|
ce15f5921f | ||
|
d9f2f9fb1e |
|
@ -16,7 +16,7 @@ repos:
|
|||
- id: auto-walrus
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.7.1
|
||||
rev: v0.7.4
|
||||
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
|
||||
|
||||
|
|
|
@ -9,6 +9,16 @@ def is_monotonic(nums: list[int]) -> bool:
|
|||
True
|
||||
>>> is_monotonic([1, 3, 2])
|
||||
False
|
||||
>>> is_monotonic([1,2,3,4,5,6,5])
|
||||
False
|
||||
>>> is_monotonic([-3,-2,-1])
|
||||
True
|
||||
>>> is_monotonic([-5,-6,-7])
|
||||
True
|
||||
>>> is_monotonic([0,0,0])
|
||||
True
|
||||
>>> is_monotonic([-100,0,100])
|
||||
True
|
||||
"""
|
||||
return all(nums[i] <= nums[i + 1] for i in range(len(nums) - 1)) or all(
|
||||
nums[i] >= nums[i + 1] for i in range(len(nums) - 1)
|
||||
|
@ -21,3 +31,7 @@ if __name__ == "__main__":
|
|||
print(is_monotonic([1, 2, 2, 3])) # Output: True
|
||||
print(is_monotonic([6, 5, 4, 4])) # Output: True
|
||||
print(is_monotonic([1, 3, 2])) # Output: False
|
||||
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!python
|
||||
import os
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user