This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collatz(n: int) -> int: | |
''' | |
post: __return__ == 1 | |
''' | |
if n == 4: | |
return 1 | |
if n % 2 == 0: | |
return collatz(n/2) | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ > 0 | |
''' | |
return 2 * n + 10 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ != 0 | |
''' | |
return 2 * n + 10 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def make_bigger(n: int) -> int: | |
''' | |
post: __return__ != 0 | |
''' | |
return 2 * n + 10 | |
NewerOlder