Skip to content

Instantly share code, notes, and snippets.

View pschanely's full-sized avatar

Phillip Schanely pschanely

View GitHub Profile
@pschanely
pschanely / main.py
Created April 26, 2024 23:52
Shared via CrossHair Playground
def collatz(n: int) -> int:
'''
post: __return__ == 1
'''
if n == 4:
return 1
if n % 2 == 0:
return collatz(n/2)
else:
@pschanely
pschanely / main.py
Created April 22, 2024 23:46
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ > 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created April 16, 2024 14:50
Shared via CrossHair Playground
import re
from typing import Optional
def parse_year(yearstring: str) -> Optional[int]:
'''
Something is wrong with this year parser! Can you guess what it is?
post: __return__ is None or 1000 <= __return__ <= 9999
'''
return int(yearstring) if re.match('[1-9][0-9][0-9][0-9]', yearstring) else None
@pschanely
pschanely / main.py
Created April 10, 2024 07:57
Shared via CrossHair Playground
def check_prime_number(number: int) -> bool:
"""
pre: number > 0
post: implies(forall([number % i != 0 for i in range(2, number)]) and number != 1, __return__)
"""
if number < 2:
return False
for i in range(2, number ** 0.5 + 1):
if number % i == 0:
return False
@pschanely
pschanely / main.py
Created April 9, 2024 05:56
Shared via CrossHair Playground
import re
from typing import Optional
def parse_year(yearstring: str) -> Optional[int]:
'''
Something is wrong with this year parser! Can you guess what it is?
post: __return__ is None or 1000 <= __return__ <= 9999
'''
return int(yearstring) if re.match('[1-9][0-9][0-9][0-9]', yearstring) else None
@pschanely
pschanely / main.py
Created April 7, 2024 07:48
Shared via CrossHair Playground
def func_source(x: list[int]) -> list[int]:
return [x[0], -1]
def func_sink(x: list[int]) -> bool:
return x[1] > 0
def func_safe(x: list[int]) -> list[int]:
return [x[0], 1]
def func_1(x: list[int]) -> list[int]:
@pschanely
pschanely / main.py
Created April 3, 2024 09:09
Shared via CrossHair Playground
import collections.abc
def contains_key(s: "collections.abc.Set"):
"""post: True"""
return "key" in s
def contains_key2(s: set):
"""post: True"""
return "key" in s
@pschanely
pschanely / main.py
Created April 1, 2024 16:09
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created March 23, 2024 14:16
Shared via CrossHair Playground
from typing import List
def average(numbers: List[float]) -> float:
'''
pre: len(numbers) >= 0
post: min(numbers) <= __return__ <= max(numbers)
'''
return sum(numbers) / len(numbers)
@pschanely
pschanely / main.py
Created March 21, 2024 23:44
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10