{"id":18034712,"url":"https://github.com/yuanqing/code-problems","last_synced_at":"2025-07-22T17:04:48.968Z","repository":{"id":29889641,"uuid":"33435113","full_name":"yuanqing/code-problems","owner":"yuanqing","description":":camel: Working through code problems in OCaml","archived":false,"fork":false,"pushed_at":"2021-01-30T07:39:45.000Z","size":70,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-20T09:59:10.667Z","etag":null,"topics":["algorithms","ocaml","puzzles"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuanqing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-05T08:30:18.000Z","updated_at":"2022-09-06T16:50:01.000Z","dependencies_parsed_at":"2022-08-23T05:00:18.242Z","dependency_job_id":null,"html_url":"https://github.com/yuanqing/code-problems","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yuanqing/code-problems","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcode-problems","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcode-problems/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcode-problems/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcode-problems/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuanqing","download_url":"https://codeload.github.com/yuanqing/code-problems/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuanqing%2Fcode-problems/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266535695,"owners_count":23944275,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["algorithms","ocaml","puzzles"],"created_at":"2024-10-30T11:13:29.397Z","updated_at":"2025-07-22T17:04:48.932Z","avatar_url":"https://github.com/yuanqing.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# code-problems [![Build Status](https://img.shields.io/travis/yuanqing/code-problems.svg?branch=master\u0026style=flat)](https://travis-ci.org/yuanqing/code-problems)\n\n\u003e Working through code problems in [OCaml](https://ocaml.org/).\n\nOr, [parlour tricks](https://signalvnoise.com/posts/3071-why-we-dont-hire-programmers-based-on-puzzles-api-quizzes-math-riddles-or-other-parlor-tricks) for the technical interview rigmarole.\n\n- [Problems](#problems)\n  - [Data structures and algorithms](#i-data-structures-and-algorithms)\n  - [Puzzles](#ii-puzzles)\n- [Style guide](#style-guide)\n- [Usage](#usage)\n- [Known issues](#known-issues)\n- [Credit](#credit)\n- [License](#license)\n\n## Problems\n\nAll the problems are in [`src/`](src), and loosely organised into categories below.\n\nEach problem comprises a brief description, a solution program, and a test. (See [Usage](#usage) for instructions on how to build and run the tests.)\n\n### I. Data structures and algorithms\n\n#### Array/list\n\n- [Binary search](src/binary_search)\n- [Linked list](src/linked_list)\n\n#### Math\n\n- [Factorial](src/factorial)\n- [Fibonacci](src/fibonacci)\n- [Prime number](src/prime_number)\n\n#### Queue\n\n- [Queue](src/queue)\n- [Queue using stacks](src/queue_using_stacks)\n\n#### Sorting\n\n- [Bubble sort](src/bubble_sort)\n- [Insertion sort](src/insertion_sort)\n- [Merge sort](src/merge_sort)\n- [Quick sort](src/quick_sort)\n- [Selection sort](src/selection_sort)\n\n#### Stack\n\n- [Stack](src/stack)\n- [Stack using queues](src/stack_using_queues)\n\n#### Tree\n\n- [Binary search tree](src/binary_search_tree)\n- [Tree traversal](src/tree_traversal)\n\n### II. Puzzles\n\n#### Array/list\n\n- [Array pair sum](src/array_pair_sum)\n- [Even-occurring element](src/even_occurring_element)\n- [Integer difference](src/integer_difference)\n- [Largest continuous sum](src/largest_continuous_sum)\n- [Longest common prefix](src/longest_common_prefix)\n- [Longest words](src/longest_words)\n- [Missing element](src/missing_element)\n- [Odd-occurring element](src/odd_occurring_element)\n- [Sum of list plus one](src/sum_of_list_plus_one)\n- [Sum of multiples](src/sum_of_multiples)\n\n#### String\n\n- [Anagram detection](src/anagram_detection)\n- [Balanced brackets](src/balanced_brackets)\n- [Byte format](src/byte_format)\n- [Combine two strings](src/combine_two_strings)\n- [CSV parse](src/csv_parse)\n- [First non-repeated character](src/first_non_repeated_character)\n- [Integer length](src/integer_length)\n- [Largest palindrome](src/largest_palindrome)\n- [Money format](src/money_format)\n- [Number format](src/number_format)\n- [Remove duplicate characters](src/remove_duplicate_characters)\n- [Reverse words](src/reverse_words)\n- [String format](src/string_format)\n- [String permutations](src/string_permutations)\n- [String rotation](src/string_rotation)\n\n#### Other\n\n- [Once](src/once)\n- [Queen threatens king](src/queen_threatens_king)\n\n## Style guide\n\n### General practices\n\n- Only use the [OCaml standard library](http://caml.inria.fr/pub/docs/manual-ocaml/libref/index.html).\n- Memoise/cache all the things! (Or at least when we [absolutely must do so](src/fibonacci/fibonacci.ml#L2-L6), anyway.) The [`Hashtbl`](http://caml.inria.fr/pub/docs/manual-ocaml/libref/Hashtbl.html) module is your friend.\n- Top-level functions should not be recursive. Instead, [use an auxiliary recursive function](src/binary_search/binary_search.ml#L2) inside the top-level function.\n- If we\u0026rsquo;re writing a recursive function (which is probably most of the time), try as far as possible to write it such that it is [tail recursive](src/tree_traversal/tree_traversal.ml#L5-L27).\n- For readability, annotate the arguments and return type of all top-level functions.\n- Short-circuit execution by [throwing an exception](src/balanced_brackets/balanced_brackets.ml#L25-L36).\n- Avoid [mutable variables](https://ocaml.org/learn/tutorials/pointers.html) if possible.\n\n### Naming conventions\n\nUse short variable names if we are dealing with very few variables, or if the meaning is obvious (or can be intuitively inferred). Some general conventions:\n\n- Auxiliary function \u0026mdash; `aux`\n- List \u0026mdash; `xs` (or `ys`, `zs`)\n- Items in a list \u0026mdash; `x` (or `y`, `z`)\n- List for accumulating values \u0026mdash; `acc`\n- Binary tree \u0026mdash; value `v` (or `w`) with a `l` subtree and a `r` subtree\n- String \u0026mdash; `str`\n- Integer \u0026mdash; `n` (or `m`)\n- Length of a string or list \u0026mdash; `len`\n\nIf there is ambiguity (eg. when we are dealing with many variables of the same type), use more descriptive names in `snake_case`.\n\n## Usage\n\n### Pre-requisites\n\n- [OCaml](https://ocaml.org/) 4.02\n- [OPAM](https://opam.ocaml.org) 1.2.0\n\n### Set up\n\nFirst, install [ocamlfind](https://opam.ocaml.org/packages/ocamlfind/ocamlfind.1.5.5/), [oUnit](https://opam.ocaml.org/packages/ounit/ounit.2.0.0/) (for tests), and [Bisect](https://opam.ocaml.org/packages/bisect/bisect.1.3/) (for test coverage) with OPAM:\n\n```\n$ opam install ocamlfind ounit bisect\n```\n\nThen, grab this repository:\n\n```\n$ git clone https://github.com/yuanqing/code-problems\n```\n\n### Run all the tests\n\n```\n$ cd code-problems/src\n$ make\n```\n\nUse `make coverage` to run the tests and generate coverage reports (output to `coverage/`).\n\n### Run a particular test\n\n\u0026hellip;for example, for the [binary search](src/binary_search) problem:\n\n```\n$ make binary_search/test\n```\n\nUse `make binary_search/coverage` to run the test and generate coverage reports (output to `coverage/`).\n\n### Clean\n\nTo remove all compiled files and other debris:\n\n```\n$ make clean\n```\n\n## Known issues\n\n- The [Bisect](http://bisect.x9c.fr) test coverage does not appear to be completely accurate.\n\n## Credit\n\nThe bulk of the problems are from the [**code-problems**](https://github.com/blakeembrey/code-problems) project maintained by [Blake Embrey](https://github.com/blakeembrey).\n\nAll solution programs in this repository were written by [me](https://github.com/yuanqing).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fcode-problems","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuanqing%2Fcode-problems","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuanqing%2Fcode-problems/lists"}