{"id":21064744,"url":"https://github.com/zmuhls/ling78100-mp2","last_synced_at":"2025-03-14T01:34:52.870Z","repository":{"id":167761730,"uuid":"232759917","full_name":"zmuhls/LING78100-MP2","owner":"zmuhls","description":"Second machine programming assignment for Methods in Computational Linguistics","archived":false,"fork":false,"pushed_at":"2020-01-09T08:43:55.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-20T20:52:39.328Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zmuhls.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-09T08:29:10.000Z","updated_at":"2020-01-09T08:45:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d862b63-6a83-49f0-adcd-034c3dc3d4fb","html_url":"https://github.com/zmuhls/LING78100-MP2","commit_stats":null,"previous_names":["zmuhls/ling78100-mp2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmuhls%2FLING78100-MP2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmuhls%2FLING78100-MP2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmuhls%2FLING78100-MP2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zmuhls%2FLING78100-MP2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zmuhls","download_url":"https://codeload.github.com/zmuhls/LING78100-MP2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243507697,"owners_count":20301880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T17:51:31.691Z","updated_at":"2025-03-14T01:34:52.844Z","avatar_url":"https://github.com/zmuhls.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"MP2: Functions\n==============\n\nThis MP consists of two parts. Both parts are also commonly used as \"screening\"\nquestions in technical interviews.\n\nFibonacci numbers\n=================\n\nThe [*Fibonacci numbers*](https://en.wikipedia.org/wiki/Fibonacci_number) are a\ninteger sequence such that each number is the sum of the two preceding numbers.\n\nBy convention, the \"zero\"th number in the sequence is 0, and the \"first\" number\nis 1, respectively. Thus the sequence is given by 0, 1, 1, 2, 3, 5, 8, 13, 21, ...\n\n### What to do\n\nWrite a function of the form:\n\n```python\ndef fib(n: int) -\u003e int:\n    pass  # FIXME.\n```\n\nwhich `return`s the `n`th Fibonacci number where `n` is a non-negative integer.\n\nThen, test it (using `assert`) for 1, 2, 3, and 100.\n\n### Test support\n\nThe 100th Fibonacci number is 354224848179261915075.\n\n### Hints\n\n-   First compute the `n`th Fibonacci number, then `return` it (don't `print`\n    it).\n-   Do not try to define this recursively; it will be too slow for `fib(100)`.\n\n### Stretch goal\n\nWrite a infinite generator function of the form:\n\n```python\nfrom typing import Iterator\n\ndef fib_generator() -\u003e Iterator[int]:\n    pass  # FIXME\n```\n\nwhich generates the infinite Fibonacci sequence. Then show it is correct up to\n100 using the following snippet:\n\n```python\ngen = fib_generator()\nfor i in range(100):\n    assert next(gen) == fib(i)\n```\n\nBigrams\n=======\n\nA *bigram* is a ordered pair of contiguous symbols (usually, but not\nnecessarily) words. For instance, the previous sentence contains bigrams such as\n`[\"of\", \"contiguous\"]`, and `[\"but\", \"not\"]`, but not `[\"is\", \"ordered\"]`\n(because those words are not contiguous) or `[\"a\", \"is\"]` (because those words\ndo not occur in that order).\n\n### What to do\n\nWrite a function of the form:\n\n```python\nfrom typing import List\n\ndef bigrams(sequence: List[str]) -\u003e List[List[str]]:\n    pass  # FIXME\n```\n\nwhich returns all bigrams (in order) from `sequence` (a list of strings). If\n`sequence` is empty, or of length one, it should return nothing, but crucially,\nyour function **should not** crash.\n\n### Test support\n\nYour implementation should pass the following assertion tests:\n\n```python\n# Empty list.\ntokens = []\nassert not bigrams(tokens)\n\n# List with one element,\ntokens = [\"Hi\"]\nassert not bigrams(tokens)\n\n# List with many elements.\ntokens = [\"Four\", \"score\", \"and\", \"seven\", \"years\"]\nassert bigrams(tokens) == [[\"Four\", \"score\"],\n                           [\"score\", \"and\"],\n                           [\"and\", \"seven\"],\n                           [\"seven\", \"years\"]]\n```\n\n### Stretch goal\n\nWrite a generator function of the form:\n\n```python\nfrom typing import List, Iterable\n\ndef ngram_generator(sequence: List[str], n: int = 2) -\u003e Iterable[List[str]]:\n    pass  # FIXME\n```\n\nwhere `n` is the \"order\" of the bigrams (e.g., n = 2 gives bigrams, n = 3 gives\ntrigrams). Then, write some basic assertion tests to show its correctness.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmuhls%2Fling78100-mp2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzmuhls%2Fling78100-mp2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzmuhls%2Fling78100-mp2/lists"}