This file contains hidden or 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 1000 <= __return__ <= 9999 | |
''' | |
return int(yearstring) if re.match('[1-9][0-9][0-9][0-9]', yearstring) else None |
This file contains hidden or 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 hidden or 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 calculate(x: int) -> int: | |
""" | |
pre: x >= 0 | |
post: __return__ > x | |
""" | |
# crosshair: specs_complete=True | |
return x + 1 | |
def check_this(val: int) -> int: |
This file contains hidden or 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 json | |
BYTES_PER_ENTITY = 92 | |
def estimate_storage(entity_count: int) -> str: | |
""" | |
pre: 0 <= entity_count < 1000 | |
post: len(__return__) < 19 | |
""" | |
This file contains hidden or 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 json | |
BYTES_PER_ENTITY = 507 | |
def estimate_storage(entity_count: int) -> str: | |
""" | |
pre: 0 <= entity_count < 1000 | |
post: len(__return__) < 19 | |
""" | |
This file contains hidden or 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 hidden or 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 split(file_id): | |
try: | |
session = Session() | |
file = session.query(File).filter(File.file_id == file_id).first() | |
extract_pages, total_pages = get_pages(file.filepath, file.pages) | |
( | |
filenames, | |
filepaths, |
This file contains hidden or 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
_ONE_HUNDRED_HASHES = [(k*13 ^ k) % 100 for k in range(100)] | |
def lookup_hash(n: int) -> int: | |
''' | |
pre: 0 <= n < 100 | |
post: __return__ != 40 | |
''' | |
return _ONE_HUNDRED_HASHES[_ONE_HUNDRED_HASHES[_ONE_HUNDRED_HASHES[n]]] |
This file contains hidden or 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 hidden or 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