├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .gitignore ├── .replit ├── LICENSE ├── README.md ├── exercises ├── 001_tail.md ├── 002_tail_penultimate.md ├── 003_nth_element.md ├── 004_length_of_list.md ├── 005_reverse_list.md ├── 006_palindrome.md ├── 007_flatten_list.md ├── 008_remove_duplicates.md ├── 009_pack_duplicates.md ├── 010_run_length_encoding.md ├── 011_modified_run_length.md ├── 012_run_length_decoding.md ├── 013_run_decoding_direct.md ├── 014_duplicate_elements.md ├── 015_replicate_elements.md ├── 016_drop_elements.md ├── 017_split_list.md ├── 018_extract_slice.md ├── 019_rotate_list.md ├── 020_remove_nth_element.md ├── 021_insert_element.md ├── 022_create_list.md ├── 023_extract_random.md ├── 024_lotto.md ├── 025_generate_permutations.md ├── 026_generate_combinations.md ├── 027_group_elements.md ├── 028_sort_list.md ├── 031_is_prime.md ├── 032_gcd.md ├── 033_is_coprime.md ├── 034_euler_totient.md ├── 035_prime_factor.md ├── 036_prime_factor_2.md ├── 037_euler_totent_improved.md ├── 038_compare_totient.md ├── 039_list_prime.md ├── 040_goldbach_conjecture.md ├── 041_goldbach_composition.md ├── 046_truth_table.md ├── 048_truth_table_2.md ├── 049_gray_code.md ├── 050_huffman_code.md ├── 055_balanced_btree.md ├── 056_symmetric_btree.md ├── 057_bst.md ├── 058_generate_and_test.md ├── 059_height_balanced_btree.md ├── 060_height_balanced_btree_2.md ├── 061A_count_leaves.md ├── 061B_collect_leaves.md ├── 062A_collect_nodes.md ├── 062B_collect_nodes_2.md ├── 063_create_btree.md ├── 064_btree_layout_1.md ├── 065_btree_layout_2.md ├── 066_btree_layout_3.md ├── 067_string_of_btree.md ├── 068_sort_btree.md ├── 069_dotstring_of_btree.md ├── 070A_create_mtree.md ├── 070B_count_mtree_nodes.md ├── 071_internal_path.md ├── 072_bottom_up_seq.md ├── 073_lisp_of_mtree.md ├── 080_conversions.md ├── 081_node_path.md ├── 082_node_cycle.md ├── 083_spanning_trees.md ├── 084_minimal_splanning_tree.md ├── 085_graph_isomorphism.md ├── 086_node_degree.md ├── 087_depth_first_traversal.md ├── 088_connected_components.md ├── 089_bipartite_graphs.md ├── 090_generate_graph.md ├── 091_eight_queens.md ├── 092_knights_tour.md ├── 093_von_koch.md ├── 094_arithmetic_puzzle.md ├── 095_english_number_words.md ├── 096_syntax_checker.md ├── 097_sudoku.md ├── 098_nonograms.md ├── 099_crosswords.md ├── diag.md ├── dune └── stream.md ├── jupyter ├── .ocamlinit ├── 001_tail.ipynb ├── 002_tail_penultimate.ipynb ├── 003_nth_element.ipynb ├── 004_length_of_list.ipynb ├── 005_reverse_list.ipynb ├── 006_palindrome.ipynb ├── 007_flatten_list.ipynb ├── 008_remove_duplicates.ipynb ├── 009_pack_duplicates.ipynb ├── 010_run_length_encoding.ipynb ├── 011_modified_run_length.ipynb ├── 012_run_length_decoding.ipynb ├── 013_run_decoding_direct.ipynb ├── 014_duplicate_elements.ipynb ├── 015_replicate_elements.ipynb ├── 016_drop_elements.ipynb ├── 017_split_list.ipynb ├── 018_extract_slice.ipynb ├── 019_rotate_list.ipynb ├── 020_remove_nth_element.ipynb ├── 021_insert_element.ipynb ├── 022_create_list.ipynb ├── 023_extract_random.ipynb ├── 024_lotto.ipynb ├── 025_generate_permutations.ipynb ├── 026_generate_combinations.ipynb ├── 027_group_elements.ipynb ├── 028_sort_list.ipynb ├── 031_is_prime.ipynb ├── 032_gcd.ipynb ├── 033_is_coprime.ipynb ├── 034_euler_totient.ipynb ├── 035_prime_factor.ipynb ├── 036_prime_factor_2.ipynb ├── 037_euler_totent_improved.ipynb ├── 039_list_prime.ipynb ├── 040_goldbach_conjecture.ipynb ├── 041_goldbach_composition.ipynb ├── 046_truth_table.ipynb ├── 048_truth_table_2.ipynb ├── 049_gray_code.ipynb ├── 050_huffman_code.ipynb ├── 055_balanced_btree.ipynb ├── 056_symmetric_btree.ipynb ├── 057_bst.ipynb ├── 058_generate_and_test.ipynb ├── 059_height_balanced_btree.ipynb ├── 060_height_balanced_btree_2.ipynb ├── 061A_count_leaves.ipynb ├── 061B_collect_leaves.ipynb ├── 062A_collect_nodes.ipynb ├── 062B_collect_nodes_2.ipynb ├── 063_create_btree.ipynb ├── 064_btree_layout_1.ipynb ├── 065_btree_layout_2.ipynb ├── 066_btree_layout_3.ipynb ├── 067_string_of_btree.ipynb ├── 068_sort_btree.ipynb ├── Dockerfile └── tests │ ├── .ocamlinit │ ├── 001.ml │ ├── 002.ml │ ├── 003.ml │ ├── 004.ml │ ├── 005.ml │ ├── 006.ml │ ├── 007.ml │ ├── 008.ml │ ├── 009.ml │ ├── 010.ml │ ├── 011.ml │ ├── 012.ml │ ├── 013.ml │ ├── 014.ml │ ├── 015.ml │ ├── 016.ml │ ├── 017.ml │ ├── 018.ml │ ├── 019.ml │ ├── 020.ml │ ├── 021.ml │ ├── 022.ml │ ├── 023.ml │ ├── 024.ml │ ├── 025.ml │ ├── 026.ml │ ├── 027.ml │ ├── 028.ml │ ├── 031.ml │ ├── 032.ml │ ├── 033.ml │ ├── 034.ml │ ├── 035.ml │ ├── 036.ml │ ├── 037.ml │ ├── 039.ml │ ├── 040.ml │ ├── 041.ml │ ├── 046.ml │ ├── 048.ml │ ├── 049.ml │ ├── 050.ml │ ├── 055.ml │ ├── 056.ml │ ├── 057.ml │ ├── 058.ml │ ├── 059.ml │ ├── 060.ml │ ├── 061A.ml │ ├── 061B.ml │ ├── 062A.ml │ ├── 062B.ml │ ├── 063.ml │ ├── 064.ml │ ├── 065.ml │ ├── 066.ml │ ├── 067.ml │ ├── 068.ml │ └── dune ├── learn-ocaml-repository ├── Dockerfile.app └── exercises │ ├── .DS_Store │ ├── 001 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 002 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 003 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 004 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 005 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 006 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 007 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 008 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 009 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 010 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 011 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 012 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 013 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 014 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 015 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 016 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 017 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 018 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 019 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 020 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 021 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 022 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 023 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 024 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 025 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 026 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 027 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 028 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 031 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 032 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 033 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 034 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 035 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 036 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 037 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 039 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 040 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 041 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 046 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 048 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 049 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 050 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 055 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 056 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 057 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 058 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 059 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 060 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 063 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 064 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 065 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 066 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 067 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ ├── 068 │ ├── descr.md │ ├── meta.json │ ├── prelude.ml │ ├── prepare.ml │ ├── solution.ml │ ├── template.ml │ └── test.ml │ └── index.json ├── practice ├── 001 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 002 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 003 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 004 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 005 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 006 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 007 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 008 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 009 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 010 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 011 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 012 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 013 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 014 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 015 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 016 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 017 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 018 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── answer2 │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 019 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 020 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 021 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 022 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── answer2 │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 023 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 024 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 025 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 026 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 027 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 028 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 031 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 032 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 033 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 034 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 035 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 036 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 037 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 039 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 040 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 041 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 046 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 048 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 049 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 050 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 055 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 056 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 057 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 058 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 059 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 060 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 061A │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 061B │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 062A │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 062B │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 063 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 064 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 065 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 066 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 067 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 068 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ ├── statement.md │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 070A │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 070B │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 071 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 072 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 073 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 081 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 082 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 091 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 095 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── 096 │ ├── answer │ │ ├── impl.ml │ │ └── test │ │ │ ├── dune │ │ │ └── run.ml │ ├── dune │ ├── dune-project │ ├── ex.ml │ └── work │ │ ├── impl.ml │ │ └── test │ │ ├── dune │ │ └── run.ml ├── Makefile ├── README.md ├── dune ├── dune-project └── index.md ├── replit.nix └── scripts ├── convert_structure.sh ├── convert_to_notebooks.py ├── extract_statements.sh ├── learn_ocaml.py ├── setup_codespaces.sh └── setup_exercise.sh /.replit: -------------------------------------------------------------------------------- 1 | compile = ["dune", "build"] 2 | run = ["dune", "test"] 3 | entrypoint = "lib/task.ml" 4 | hidden = ["_build"] 5 | 6 | [languages.OCaml] 7 | pattern = "**/*.{ml,mli}" 8 | 9 | [languages.OCaml.languageServer] 10 | start = "ocamllsp" 11 | 12 | [nix] 13 | channel = "stable-23_11" 14 | -------------------------------------------------------------------------------- /exercises/dune: -------------------------------------------------------------------------------- 1 | (mdx 2 | (files *.md)) 3 | -------------------------------------------------------------------------------- /jupyter/.ocamlinit: -------------------------------------------------------------------------------- 1 | #use "topfind";; 2 | #require "alcotest";; 3 | -------------------------------------------------------------------------------- /jupyter/tests/.ocamlinit: -------------------------------------------------------------------------------- 1 | #use "topfind";; 2 | #require "alcotest";; 3 | -------------------------------------------------------------------------------- /jupyter/tests/001.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (option int)) "last of empty list" None (last []) 2 | let _ = Alcotest.(check (option string)) "last of non-empty list" (Some "d") (last ["a"; "b"; "c"; "d"]) -------------------------------------------------------------------------------- /jupyter/tests/002.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (option (pair string string))) "last_two of single-element list" None (last_two ["a"]) 2 | let _ = Alcotest.(check (option (pair string string))) "last_two of non-empty list" (Some ("c", "d")) (last_two ["a"; "b"; "c"; "d"]) 3 | -------------------------------------------------------------------------------- /jupyter/tests/003.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (option string)) "last of empty list" None (last []) 2 | let _ = Alcotest.(check (option string)) "last of non-empty list" (Some "d") (last ["a"; "b"; "c"; "d"]) 3 | -------------------------------------------------------------------------------- /jupyter/tests/004.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check int) "length of empty list" 0 (length []) 2 | let _ = Alcotest.(check int) "length of non-empty list" 3 (length ["a"; "b"; "c"]) 3 | -------------------------------------------------------------------------------- /jupyter/tests/005.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list string)) "rev of empty list" [] (rev []) 2 | let _ = Alcotest.(check (list string)) "rev of non-empty list" ["c"; "b"; "a"] (rev ["a"; "b"; "c"]) 3 | -------------------------------------------------------------------------------- /jupyter/tests/008.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list string)) "compress non-empty list" 2 | ["a"; "b"; "c"; "a"; "d"; "e"] 3 | (compress ["a"; "a"; "a"; "a"; "b"; "c"; "c"; "a"; "a"; "d"; "e"; "e"; "e"; "e"]) 4 | 5 | let _ = Alcotest.(check (list string)) "compress empty list" [] (compress []) 6 | -------------------------------------------------------------------------------- /jupyter/tests/009.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list (list string))) "pack example" 2 | [["a"; "a"; "a"; "a"]; ["b"]; ["c"; "c"]; ["a"; "a"]; ["d"; "d"]; ["e"; "e"; "e"; "e"]] 3 | (pack ["a"; "a"; "a"; "a"; "b"; "c"; "c"; "a"; "a"; "d"; "d"; "e"; "e"; "e"; "e"]) 4 | -------------------------------------------------------------------------------- /jupyter/tests/014.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list string)) "duplicate non-empty list" 2 | ["a"; "a"; "b"; "b"; "c"; "c"; "c"; "c"; "d"; "d"] 3 | (duplicate ["a"; "b"; "c"; "c"; "d"]) 4 | 5 | let _ = Alcotest.(check (list string)) "duplicate empty list" 6 | [] 7 | (duplicate []) 8 | -------------------------------------------------------------------------------- /jupyter/tests/023.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check int) "random select 3" 2 | 3 3 | (List.length (rand_select ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"] 3)) 4 | 5 | let _ = Alcotest.(check int) "random select 5" 6 | 5 7 | (List.length (rand_select ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"] 5)) 8 | -------------------------------------------------------------------------------- /jupyter/tests/024.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list int)) "lotto_select nil" 2 | [] 3 | (lotto_select 0 0) 4 | 5 | let _ = Alcotest.(check (list int)) "lotto_select cons" 6 | [20; 28; 45; 16; 24; 38] (* Note: this specific output is assumed for demonstration; actual output may vary *) 7 | (lotto_select 6 49) 8 | -------------------------------------------------------------------------------- /jupyter/tests/026.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list (list string))) "extract nil" 2 | [[]] 3 | (extract 0 ["a"]) 4 | 5 | let _ = Alcotest.(check (list (list string))) "extract cons" 6 | [["a"; "b"]; ["a"; "c"]; ["a"; "d"]; ["b"; "c"]; ["b"; "d"]; ["c"; "d"]] 7 | (extract 2 ["a"; "b"; "c"; "d"]) 8 | -------------------------------------------------------------------------------- /jupyter/tests/032.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check int) "gcd_13_0" 13 (gcd 13 0) 2 | let _ = Alcotest.(check int) "gcd_20536_7826" 2 (gcd 20536 7826) 3 | -------------------------------------------------------------------------------- /jupyter/tests/033.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check bool) "coprime numbers" true (coprime 13 27) 2 | let _ = Alcotest.(check bool) "not coprime numbers" false (coprime 20536 7826) 3 | -------------------------------------------------------------------------------- /jupyter/tests/034.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check int) "phi of 10" 4 (phi 10) 2 | let _ = Alcotest.(check int) "phi of 1 (edge case)" 1 (phi 1) 3 | let _ = Alcotest.(check int) "phi of a prime number" 12 (phi 13) 4 | -------------------------------------------------------------------------------- /jupyter/tests/035.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list int)) "prime factors of 315" [3; 3; 5; 7] (factors 315) 2 | let _ = Alcotest.(check (list int)) "prime factors of 1 (edge case)" [] (factors 1) 3 | let _ = Alcotest.(check (list int)) "prime factors of a prime number" [13] (factors 13) 4 | -------------------------------------------------------------------------------- /jupyter/tests/040.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (pair int int)) "goldbach of 4" 2 | (2, 2) 3 | (goldbach 4) 4 | 5 | let _ = Alcotest.(check (pair int int)) "goldbach of 28" 6 | (5, 23) 7 | (goldbach 28) 8 | -------------------------------------------------------------------------------- /jupyter/tests/041.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list (pair int (pair int int)))) "goldbach_list from 9 to 20" 2 | [(10, (3, 7)); (12, (5, 7)); (14, (3, 11)); (16, (3, 13)); (18, (5, 13)); (20, (3, 17))] 3 | (goldbach_list 9 20) 4 | -------------------------------------------------------------------------------- /jupyter/tests/050.ml: -------------------------------------------------------------------------------- 1 | let _ = Alcotest.(check (list (pair string string))) "Huffman code test" 2 | [("a", "0"); ("c", "100"); ("b", "101"); ("f", "1100"); ("e", "1101"); ("d", "111")] 3 | (huffman [("a", 45); ("b", 13); ("c", 12); ("d", 16); ("e", 9); ("f", 5)]) 4 | -------------------------------------------------------------------------------- /jupyter/tests/dune: -------------------------------------------------------------------------------- 1 | (test 2 | (name 001) 3 | (libraries alcotest)) 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/.DS_Store -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/001/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Write a function `last : 'a list -> 'a option` that returns the last element of a list 4 | 5 | ```ocaml 6 | # last ["a" ; "b" ; "c" ; "d"];; 7 | - : string option = Some "d" 8 | # last [];; 9 | - : 'a option = None 10 | ``` 11 | ${tex`t`} -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/001/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Tail of a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/001/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/001/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/001/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/001/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/001/solution.ml: -------------------------------------------------------------------------------- 1 | let rec last = function 2 | | [] -> None 3 | | [ x ] -> Some x 4 | | _ :: t -> last t 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/001/template.ml: -------------------------------------------------------------------------------- 1 | let last _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/002/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Find the last but one (last and penultimate) elements of a list. 4 | 5 | ```ocaml 6 | # last_two ["a"; "b"; "c"; "d"];; 7 | - : (string * string) option = Some ("c", "d") 8 | # last_two ["a"];; 9 | - : (string * string) option = None 10 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/002/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Last Two Elements of a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/002/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/002/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/002/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/002/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/002/solution.ml: -------------------------------------------------------------------------------- 1 | let rec last_two = function 2 | | [] | [_] -> None 3 | | [x; y] -> Some (x,y) 4 | | _ :: t -> last_two t 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/002/template.ml: -------------------------------------------------------------------------------- 1 | let last_two _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/003/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "N'th Element of a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/003/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/003/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/003/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/003/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/003/solution.ml: -------------------------------------------------------------------------------- 1 | let rec at k = function 2 | | [] -> None 3 | | h :: t -> if k = 0 then Some h else at (k - 1) t 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/003/template.ml: -------------------------------------------------------------------------------- 1 | let nth _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/004/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Length of a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/004/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/004/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/004/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/004/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/004/solution.ml: -------------------------------------------------------------------------------- 1 | let length list = 2 | let rec aux n = function 3 | | [] -> n 4 | | _ :: t -> aux (n + 1) t 5 | in 6 | aux 0 list 7 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/004/template.ml: -------------------------------------------------------------------------------- 1 | let length _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/005/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Reverse a list. 4 | 5 | OCaml standard library has `List.rev` but we ask that you reimplement 6 | it. 7 | 8 | 9 | ```ocaml 10 | # rev ["a"; "b"; "c"];; 11 | - : string list = ["c"; "b"; "a"] 12 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/005/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Reverse a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/005/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/005/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/005/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/005/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/005/solution.ml: -------------------------------------------------------------------------------- 1 | let rev list = 2 | let rec aux acc = function 3 | | [] -> acc 4 | | h :: t -> aux (h :: acc) t 5 | in 6 | aux [] list 7 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/005/template.ml: -------------------------------------------------------------------------------- 1 | let rev _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/006/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Find out whether a list is a palindrome. 4 | 5 | **Hint:** A palindrome is its own reverse. 6 | 7 | ```ocaml 8 | # is_palindrome ["x"; "a"; "m"; "a"; "x"];; 9 | - : bool = true 10 | # not (is_palindrome ["a"; "b"]);; 11 | - : bool = true 12 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/006/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Palindrome" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/006/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/006/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/006/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/006/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/006/solution.ml: -------------------------------------------------------------------------------- 1 | let is_palindrome list = 2 | list = List.rev list 3 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/006/template.ml: -------------------------------------------------------------------------------- 1 | let is_palindrome _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/007/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Flatten a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/007/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a node = 2 | | One of 'a 3 | | Many of 'a node list 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/007/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/007/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/007/solution.ml: -------------------------------------------------------------------------------- 1 | let flatten list = 2 | let rec aux acc = function 3 | | [] -> acc 4 | | One x :: t -> aux (x :: acc) t 5 | | Many l :: t -> aux (aux acc l) t 6 | in 7 | List.rev (aux [] list) 8 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/007/template.ml: -------------------------------------------------------------------------------- 1 | let flatten _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/007/test.ml: -------------------------------------------------------------------------------- 1 | open Test_lib 2 | open Report 3 | 4 | let () = 5 | set_result @@ 6 | ast_sanity_check code_ast @@ fun () -> 7 | [ 8 | Message ([ Text "That was easy!" ], Success 1) 9 | ] 10 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/008/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Eliminate consecutive duplicates of list elements. 4 | 5 | ```ocaml 6 | # compress ["a"; "a"; "a"; "a"; "b"; "c"; "c"; "a"; "a"; "d"; "e"; "e"; "e"; "e"];; 7 | - : string list = ["a"; "b"; "c"; "a"; "d"; "e"] 8 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/008/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Eliminate Duplicates" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/008/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/008/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/008/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/008/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/008/solution.ml: -------------------------------------------------------------------------------- 1 | let rec compress = function 2 | | a :: (b :: _ as t) -> if a = b then compress t else a :: compress t 3 | | smaller -> smaller 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/008/template.ml: -------------------------------------------------------------------------------- 1 | let compress _ = failwith "Not yet implemented" 2 | 3 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/009/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Pack Consecutive Duplicates" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/009/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/009/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/009/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/009/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/009/template.ml: -------------------------------------------------------------------------------- 1 | let pack _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/010/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Run-Length Encoding" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/010/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/010/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/010/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/010/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/010/template.ml: -------------------------------------------------------------------------------- 1 | let encode _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/011/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Modified Run-Length Encoding" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/011/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a rle = 2 | | One of 'a 3 | | Many of int * 'a 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/011/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/011/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/011/template.ml: -------------------------------------------------------------------------------- 1 | let encode _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/011/test.ml: -------------------------------------------------------------------------------- 1 | open Test_lib 2 | open Report 3 | 4 | let () = 5 | set_result @@ 6 | ast_sanity_check code_ast @@ fun () -> 7 | [ 8 | Message ([ Text "That was easy!" ], Success 1) 9 | ] 10 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/012/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Decode a Run-Length Encoded List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/012/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a rle = 2 | | One of 'a 3 | | Many of int * 'a 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/012/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/012/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/012/template.ml: -------------------------------------------------------------------------------- 1 | let decode _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/012/test.ml: -------------------------------------------------------------------------------- 1 | open Test_lib 2 | open Report 3 | 4 | let () = 5 | set_result @@ 6 | ast_sanity_check code_ast @@ fun () -> 7 | [ 8 | Message ([ Text "That was easy!" ], Success 1) 9 | ] 10 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/013/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Run-Length Encoding of a List (Direct Solution)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/013/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a rle = 2 | | One of 'a 3 | | Many of int * 'a 4 | 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/013/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/013/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/013/template.ml: -------------------------------------------------------------------------------- 1 | let encode _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/014/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Duplicate the elements of a list. 4 | 5 | ```ocaml 6 | # duplicate ["a"; "b"; "c"; "c"; "d"];; 7 | - : string list = ["a"; "a"; "b"; "b"; "c"; "c"; "c"; "c"; "d"; "d"] 8 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/014/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Duplicate the Elements of a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/014/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/014/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/014/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/014/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/014/solution.ml: -------------------------------------------------------------------------------- 1 | let rec duplicate = function 2 | | [] -> [] 3 | | h :: t -> h :: h :: duplicate t 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/014/template.ml: -------------------------------------------------------------------------------- 1 | let duplicate _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/015/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Replicate the elements of a list a given number of times. 4 | 5 | ```ocaml 6 | # replicate ["a"; "b"; "c"] 3;; 7 | - : string list = ["a"; "a"; "a"; "b"; "b"; "b"; "c"; "c"; "c"] 8 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/015/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Replicate the Elements of a List a Given Number of Times" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/015/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/015/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/015/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/015/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/015/template.ml: -------------------------------------------------------------------------------- 1 | let replicate _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/016/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Drop every N'th element from a list. 4 | 5 | ```ocaml 6 | # drop ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"] 3;; 7 | - : string list = ["a"; "b"; "d"; "e"; "g"; "h"; "j"] 8 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/016/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Drop Every N'th Element From a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/016/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/016/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/016/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/016/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/016/solution.ml: -------------------------------------------------------------------------------- 1 | let drop list n = 2 | let rec aux i = function 3 | | [] -> [] 4 | | h :: t -> if i = n then aux 1 t else h :: aux (i + 1) t in 5 | aux 1 list 6 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/016/template.ml: -------------------------------------------------------------------------------- 1 | let drop _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/017/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Split a List Into Two Parts; The Length of the First Part Is Given" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/017/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/017/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/017/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/017/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/017/solution.ml: -------------------------------------------------------------------------------- 1 | let split list n = 2 | let rec aux i acc = function 3 | | [] -> List.rev acc, [] 4 | | h :: t as l -> if i = 0 then List.rev acc, l 5 | else aux (i - 1) (h :: acc) t 6 | in 7 | aux n [] list 8 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/017/template.ml: -------------------------------------------------------------------------------- 1 | let split _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/018/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Extract a Slice From a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/018/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/018/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/018/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/018/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/018/solution.ml: -------------------------------------------------------------------------------- 1 | let slice list i k = 2 | List.filteri (fun index _ -> index >= i && index <= k) list 3 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/018/template.ml: -------------------------------------------------------------------------------- 1 | let slice _ _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/019/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Rotate a list N places to the left. 4 | 5 | ```ocaml 6 | # rotate ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"] 3;; 7 | - : string list = ["d"; "e"; "f"; "g"; "h"; "a"; "b"; "c"] 8 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/019/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Rotate a List N Places to the Left" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/019/prelude.ml: -------------------------------------------------------------------------------- 1 | let split list n = 2 | let rec aux i acc = function 3 | | [] -> List.rev acc, [] 4 | | h :: t as l -> if i = 0 then List.rev acc, l 5 | else aux (i - 1) (h :: acc) t in 6 | aux n [] list 7 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/019/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/019/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/019/solution.ml: -------------------------------------------------------------------------------- 1 | let rotate list n = 2 | let len = List.length list in 3 | (* Compute a rotation value between 0 and len - 1 *) 4 | let n = if len = 0 then 0 else (n mod len + len) mod len in 5 | if n = 0 then list 6 | else let a, b = split list n in b @ a 7 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/019/template.ml: -------------------------------------------------------------------------------- 1 | let rotate _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/020/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Remove the K'th element from a list. 4 | 5 | The first element of the list is numbered 0, the second 1,... 6 | 7 | ```ocaml 8 | # remove_at 1 ["a"; "b"; "c"; "d"];; 9 | - : string list = ["a"; "c"; "d"] 10 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/020/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Remove the K'th Element From a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/020/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/020/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/020/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/020/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/020/solution.ml: -------------------------------------------------------------------------------- 1 | let rec remove_at n = function 2 | | [] -> [] 3 | | h :: t -> if n = 0 then t else h :: remove_at (n - 1) t 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/020/template.ml: -------------------------------------------------------------------------------- 1 | let remove_at _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/021/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Insert an Element at a Given Position Into a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/021/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/021/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/021/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/021/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/021/solution.ml: -------------------------------------------------------------------------------- 1 | let rec insert_at x n = function 2 | | [] -> [x] (* Insert at the end if the list is empty or n is beyond the list length *) 3 | | h :: t as l -> if n = 0 then x :: l else h :: insert_at x (n - 1) t 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/021/template.ml: -------------------------------------------------------------------------------- 1 | let insert_at _ _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/022/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | If first argument is greater than second, produce a list in decreasing 4 | order. 5 | 6 | ```ocaml 7 | # range 4 9;; 8 | - : int list = [4; 5; 6; 7; 8; 9] 9 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/022/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Create a List Containing All Integers Within a Given Range" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/022/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/022/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/022/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/022/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/022/solution.ml: -------------------------------------------------------------------------------- 1 | let range a b = 2 | let rec aux a b = 3 | if a > b then [] else a :: aux (a + 1) b 4 | in 5 | if a > b then List.rev (aux b a) else aux a b 6 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/022/template.ml: -------------------------------------------------------------------------------- 1 | let range _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/023/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Extract a Given Number of Randomly Selected Elements From a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/023/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/023/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/023/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/023/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/023/template.ml: -------------------------------------------------------------------------------- 1 | let rand_select _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/024/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Draw N different random numbers from the set `1..M`. 4 | 5 | The selected numbers shall be returned in a list. 6 | 7 | ```ocaml 8 | # lotto_select 6 49;; 9 | - : int list = [20; 28; 45; 16; 24; 38] 10 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/024/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "\"Lotto: Draw N Different Random Numbers From the Set 1..M\"" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/024/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/024/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/024/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/024/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/024/template.ml: -------------------------------------------------------------------------------- 1 | let lotto_select _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/024/test.ml: -------------------------------------------------------------------------------- 1 | open Test_lib 2 | open Report 3 | 4 | let () = 5 | set_result @@ 6 | ast_sanity_check code_ast @@ fun () -> 7 | [ 8 | Message ([ Text "That was easy!" ], Success 1) 9 | ] 10 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/025/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Generate a random permutation of the elements of a list. 4 | 5 | ```ocaml 6 | # permutation ["a"; "b"; "c"; "d"; "e"; "f"];; 7 | - : string list = ["c"; "d"; "f"; "e"; "b"; "a"] 8 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/025/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Generate a Random Permutation of the Elements of a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/025/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/025/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/025/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/025/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/025/template.ml: -------------------------------------------------------------------------------- 1 | let permutation _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/025/test.ml: -------------------------------------------------------------------------------- 1 | open Test_lib 2 | open Report 3 | 4 | let () = 5 | set_result @@ 6 | ast_sanity_check code_ast @@ fun () -> 7 | [ 8 | Message ([ Text "That was easy!" ], Success 1) 9 | ] 10 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/026/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Generate the Combinations of K Distinct Objects Chosen From the N Elements of a List" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/026/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/026/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/026/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/026/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/026/solution.ml: -------------------------------------------------------------------------------- 1 | let rec extract k list = 2 | if k <= 0 then [[]] 3 | else match list with 4 | | [] -> [] 5 | | h :: tl -> 6 | let with_h = List.map (fun l -> h :: l) (extract (k - 1) tl) in 7 | let without_h = extract k tl in 8 | with_h @ without_h 9 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/026/template.ml: -------------------------------------------------------------------------------- 1 | let extract _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/027/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Group the Elements of a Set Into Disjoint Subsets" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/027/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/027/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/027/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/027/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/027/template.ml: -------------------------------------------------------------------------------- 1 | let group _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/028/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Sorting a List of Lists According to Length of Sublists" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/028/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/028/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/028/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/028/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/028/template.ml: -------------------------------------------------------------------------------- 1 | let length_sort _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/031/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Determine whether a given integer number is prime. 4 | 5 | ```ocaml 6 | # not (is_prime 1);; 7 | - : bool = true 8 | # is_prime 7;; 9 | - : bool = true 10 | # not (is_prime 12);; 11 | - : bool = true 12 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/031/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Determine Whether a Given Integer Number Is Prime" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/031/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/031/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/031/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/031/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/031/solution.ml: -------------------------------------------------------------------------------- 1 | let is_prime n = 2 | let n = abs n in 3 | let rec is_not_divisor d = 4 | d * d > n || (n mod d <> 0 && is_not_divisor (d + 1)) in 5 | n > 1 && is_not_divisor 2 6 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/031/template.ml: -------------------------------------------------------------------------------- 1 | let is_prime _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/032/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Determine the greatest common divisor of two positive integer numbers. 4 | 5 | Use Euclid's algorithm. 6 | 7 | ```ocaml 8 | # gcd 13 27;; 9 | - : int = 1 10 | # gcd 20536 7826;; 11 | - : int = 2 12 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/032/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Determine the Greatest Common Divisor of Two Positive Integer Numbers" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/032/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/032/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/032/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/032/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/032/solution.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = 2 | if b = 0 then a else gcd b (a mod b) 3 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/032/template.ml: -------------------------------------------------------------------------------- 1 | let gcd _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/033/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "Determine Whether Two Positive Integer Numbers Are Coprime" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/033/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/033/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/033/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/033/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/033/solution.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = 2 | if b = 0 then a else gcd b (a mod b) 3 | 4 | let coprime a b = gcd a b = 1 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/033/template.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = 2 | if b = 0 then a else gcd b (a mod b) 3 | 4 | let coprime _ _ = failwith "Not yet implemented" 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/034/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Calculate Euler's Totient Function \u03a6(m)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/034/prelude.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = if b = 0 then a else gcd b (a mod b) 2 | let coprime a b = gcd a b = 1 3 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/034/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/034/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/034/template.ml: -------------------------------------------------------------------------------- 1 | let phi _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/035/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Construct a flat list containing the prime factors in ascending order. 4 | 5 | 6 | ```ocaml 7 | # factors 315;; 8 | - : int list = [3; 3; 5; 7] 9 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/035/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Determine the Prime Factors of a Given Positive Integer" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/035/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/035/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/035/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/035/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/035/solution.ml: -------------------------------------------------------------------------------- 1 | (* Recall that d divides n iff [n mod d = 0] *) 2 | let factors n = 3 | let rec aux d n = 4 | if n = 1 then [] else 5 | if n mod d = 0 then d :: aux d (n / d) else aux (d + 1) n 6 | in 7 | aux 2 n 8 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/035/template.ml: -------------------------------------------------------------------------------- 1 | let factors _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/036/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Determine the Prime Factors of a Given Positive Integer (2)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/036/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/036/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/036/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/036/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/036/template.ml: -------------------------------------------------------------------------------- 1 | let factors _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/037/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Calculate Euler's Totient Function \u03a6(m) (Improved)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/037/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/037/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/037/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/037/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/037/template.ml: -------------------------------------------------------------------------------- 1 | let phi _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/039/descr.md: -------------------------------------------------------------------------------- 1 | # Statement 2 | 3 | Given a range of integers by its lower and upper limit, construct a list 4 | of all prime numbers in that range. 5 | 6 | ```ocaml 7 | # List.length (all_primes 2 7920);; 8 | - : int = 1000 9 | ``` -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/039/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 1, 5 | "title": "A List of Prime Numbers" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/039/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/039/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/039/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/039/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/039/template.ml: -------------------------------------------------------------------------------- 1 | let all_primes _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/040/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Goldbach's Conjecture" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/040/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/040/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/040/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/040/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/040/template.ml: -------------------------------------------------------------------------------- 1 | let goldbach _ = failwith "goldbach not implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/041/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "A List of Goldbach Compositions" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/041/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/041/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/041/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/041/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/041/template.ml: -------------------------------------------------------------------------------- 1 | let goldbach_list _ = failwith "goldbach_list not implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/046/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Truth Tables for Logical Expressions (2 Variables)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/046/prelude.ml: -------------------------------------------------------------------------------- 1 | type bool_expr = 2 | | Var of string 3 | | Not of bool_expr 4 | | And of bool_expr * bool_expr 5 | | Or of bool_expr * bool_expr 6 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/046/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/046/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/046/template.ml: -------------------------------------------------------------------------------- 1 | let table2 _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/048/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Truth Tables for Logical Expressions" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/048/prelude.ml: -------------------------------------------------------------------------------- 1 | type bool_expr = 2 | | Var of string 3 | | Not of bool_expr 4 | | And of bool_expr * bool_expr 5 | | Or of bool_expr * bool_expr -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/048/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/048/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/048/template.ml: -------------------------------------------------------------------------------- 1 | let table _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/049/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Gray Code" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/049/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/049/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/049/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/049/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/049/template.ml: -------------------------------------------------------------------------------- 1 | let gray _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/050/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 3, 5 | "title": "Huffman Code" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/050/prelude.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/050/prelude.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/050/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/050/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/050/template.ml: -------------------------------------------------------------------------------- 1 | let huffman _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/055/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Construct Completely Balanced Binary Trees" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/055/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/055/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/055/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/055/template.ml: -------------------------------------------------------------------------------- 1 | let cbal_tree _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/056/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Symmetric Binary Trees" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/056/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/056/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/056/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/056/template.ml: -------------------------------------------------------------------------------- 1 | let is_symmetric _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/057/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Binary Search Trees (Dictionaries)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/057/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/057/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/057/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/057/template.ml: -------------------------------------------------------------------------------- 1 | let construct _ = failwith "Not yet implemented" 2 | 3 | let is_symmetric _ = failwith "Not yet implemented" 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/058/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Generate-and-Test Paradigm" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/058/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/058/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/058/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/058/template.ml: -------------------------------------------------------------------------------- 1 | let sym_cbal_trees _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/059/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Construct Height-Balanced Binary Trees" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/059/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/059/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/059/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/059/template.ml: -------------------------------------------------------------------------------- 1 | let hbal_tree _ = failwith "Not yet implemented" 2 | 3 | let tree_height _ = failwith "Not yet implemented" 4 | 5 | let add_trees_with _ = failwith "Not yet implemented" 6 | 7 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/060/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Construct Height-Balanced Binary Trees With a Given Number of Nodes" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/060/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let max_nodes h = 1 lsl h - 1 -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/060/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/060/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/060/template.ml: -------------------------------------------------------------------------------- 1 | let hbal_tree_nodes _ = failwith "Not yet implemented" 2 | 3 | let min_nodes _ = failwith "Not yet implemented" 4 | 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/063/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Construct a Complete Binary Tree" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/063/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/063/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/063/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/063/template.ml: -------------------------------------------------------------------------------- 1 | let complete_binary_tree _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/064/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Layout a Binary Tree (1)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/064/prelude.ml: -------------------------------------------------------------------------------- 1 | 2 | type 'a binary_tree = 3 | | Empty 4 | | Node of 'a * 'a binary_tree * 'a binary_tree 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/064/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/064/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/064/template.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let layout_binary_tree_1 _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/065/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Layout a Binary Tree (2)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/065/prelude.ml: -------------------------------------------------------------------------------- 1 | 2 | type 'a binary_tree = 3 | | Empty 4 | | Node of 'a * 'a binary_tree * 'a binary_tree 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/065/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/065/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/065/template.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let layout_binary_tree_2 _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/066/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 3, 5 | "title": "Layout a Binary Tree (3)" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/066/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/066/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/066/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/066/template.ml: -------------------------------------------------------------------------------- 1 | let layout_binary_tree_3 _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/067/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "A String Representation of Binary Trees" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/067/prelude.ml: -------------------------------------------------------------------------------- 1 | 2 | type 'a binary_tree = 3 | | Empty 4 | | Node of 'a * 'a binary_tree * 'a binary_tree 5 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/067/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/067/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/067/template.ml: -------------------------------------------------------------------------------- 1 | let string_of_tree _ = failwith "Not yet implemented" 2 | let tree_of_string _ = failwith "Not yet implemented" 3 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/067/test.ml: -------------------------------------------------------------------------------- 1 | open Test_lib 2 | open Report 3 | 4 | let () = 5 | set_result @@ 6 | ast_sanity_check code_ast @@ fun () -> 7 | [ 8 | Message ([ Text "That was easy!" ], Success 1) 9 | ] 10 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/068/meta.json: -------------------------------------------------------------------------------- 1 | { 2 | "learnocaml_version": "1", 3 | "kind": "exercise", 4 | "stars": 2, 5 | "title": "Preorder and Inorder Sequences of Binary Trees" 6 | } -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/068/prelude.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/068/prepare.ml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/divyankachaudhari/ocaml-practice-exercises/c5caae6d81e2b0dbe33f879c793b25ee83dae23f/learn-ocaml-repository/exercises/068/prepare.ml -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/068/template.ml: -------------------------------------------------------------------------------- 1 | let preorder _ = failwith "Not yet implemented" 2 | let inorder _ = failwith "Not yet implemented" 3 | let pre_in_tree _ = failwith "Not yet implemented" 4 | -------------------------------------------------------------------------------- /learn-ocaml-repository/exercises/068/test.ml: -------------------------------------------------------------------------------- 1 | open Test_lib 2 | open Report 3 | 4 | let () = 5 | set_result @@ 6 | ast_sanity_check code_ast @@ fun () -> 7 | [ 8 | Message ([ Text "That was easy!" ], Success 1) 9 | ] 10 | -------------------------------------------------------------------------------- /practice/001/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec last = function 2 | | [] -> None 3 | | [ x ] -> Some x 4 | | _ :: t -> last t 5 | -------------------------------------------------------------------------------- /practice/001/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/001/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/001/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/001/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/001/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Write a function `last : 'a list -> 'a option` that returns the last element of a list 3 | 4 | ```ocaml 5 | # last ["a" ; "b" ; "c" ; "d"];; 6 | - : string option = Some "d" 7 | # last [];; 8 | - : 'a option = None 9 | ``` 10 | -------------------------------------------------------------------------------- /practice/001/work/impl.ml: -------------------------------------------------------------------------------- 1 | let last _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/001/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/001/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/002/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec last_two = function 2 | | [] | [_] -> None 3 | | [x; y] -> Some (x,y) 4 | | _ :: t -> last_two t 5 | -------------------------------------------------------------------------------- /practice/002/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/002/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/002/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/002/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/002/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Find the last but one (last and penultimate) elements of a list. 3 | 4 | ```ocaml 5 | # last_two ["a"; "b"; "c"; "d"];; 6 | - : (string * string) option = Some ("c", "d") 7 | # last_two ["a"];; 8 | - : (string * string) option = None 9 | ``` 10 | -------------------------------------------------------------------------------- /practice/002/work/impl.ml: -------------------------------------------------------------------------------- 1 | let last_two _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/002/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/002/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/003/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec at k = function 2 | | [] -> None 3 | | h :: t -> if k = 0 then Some h else at (k - 1) t 4 | -------------------------------------------------------------------------------- /practice/003/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/003/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/003/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/003/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/003/work/impl.ml: -------------------------------------------------------------------------------- 1 | let nth _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/003/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/003/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/004/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let length list = 2 | let rec aux n = function 3 | | [] -> n 4 | | _ :: t -> aux (n + 1) t 5 | in 6 | aux 0 list 7 | -------------------------------------------------------------------------------- /practice/004/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/004/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/004/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/004/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/004/work/impl.ml: -------------------------------------------------------------------------------- 1 | let length _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/004/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/004/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/005/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rev list = 2 | let rec aux acc = function 3 | | [] -> acc 4 | | h :: t -> aux (h :: acc) t 5 | in 6 | aux [] list 7 | -------------------------------------------------------------------------------- /practice/005/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/005/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/005/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/005/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/005/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Reverse a list. 3 | 4 | OCaml standard library has `List.rev` but we ask that you reimplement 5 | it. 6 | 7 | 8 | ```ocaml 9 | # rev ["a"; "b"; "c"];; 10 | - : string list = ["c"; "b"; "a"] 11 | ``` 12 | -------------------------------------------------------------------------------- /practice/005/work/impl.ml: -------------------------------------------------------------------------------- 1 | let rev _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/005/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/005/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/006/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let is_palindrome list = 2 | list = List.rev list 3 | -------------------------------------------------------------------------------- /practice/006/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/006/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/006/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/006/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/006/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Find out whether a list is a palindrome. 3 | 4 | **Hint:** A palindrome is its own reverse. 5 | 6 | ```ocaml 7 | # is_palindrome ["x"; "a"; "m"; "a"; "x"];; 8 | - : bool = true 9 | # not (is_palindrome ["a"; "b"]);; 10 | - : bool = true 11 | ``` 12 | -------------------------------------------------------------------------------- /practice/006/work/impl.ml: -------------------------------------------------------------------------------- 1 | let is_palindrome _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/006/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/006/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/007/answer/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a node = 2 | | One of 'a 3 | | Many of 'a node list 4 | 5 | let flatten list = 6 | let rec aux acc = function 7 | | [] -> acc 8 | | One x :: t -> aux (x :: acc) t 9 | | Many l :: t -> aux (aux acc l) t 10 | in 11 | List.rev (aux [] list) 12 | -------------------------------------------------------------------------------- /practice/007/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/007/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/007/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/007/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/007/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a node = 2 | | One of 'a 3 | | Many of 'a node list 4 | 5 | let flatten _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/007/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/007/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/008/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec compress = function 2 | | a :: (b :: _ as t) -> if a = b then compress t else a :: compress t 3 | | smaller -> smaller 4 | -------------------------------------------------------------------------------- /practice/008/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/008/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/008/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/008/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/008/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Eliminate consecutive duplicates of list elements. 3 | 4 | ```ocaml 5 | # compress ["a"; "a"; "a"; "a"; "b"; "c"; "c"; "a"; "a"; "d"; "e"; "e"; "e"; "e"];; 6 | - : string list = ["a"; "b"; "c"; "a"; "d"; "e"] 7 | ``` 8 | -------------------------------------------------------------------------------- /practice/008/work/impl.ml: -------------------------------------------------------------------------------- 1 | let compress _ = failwith "Not yet implemented" 2 | 3 | -------------------------------------------------------------------------------- /practice/008/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/008/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/009/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/009/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/009/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/009/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/009/work/impl.ml: -------------------------------------------------------------------------------- 1 | let pack _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/009/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/009/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/010/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/010/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/010/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/010/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/010/work/impl.ml: -------------------------------------------------------------------------------- 1 | let encode _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/010/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/010/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/011/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/011/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/011/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/011/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/011/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a rle = 2 | | One of 'a 3 | | Many of int * 'a 4 | 5 | let encode _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/011/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/011/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/012/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/012/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/012/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/012/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/012/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a rle = 2 | | One of 'a 3 | | Many of int * 'a 4 | 5 | let decode _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/012/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/012/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/013/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/013/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/013/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/013/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/013/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a rle = 2 | | One of 'a 3 | | Many of int * 'a 4 | 5 | let encode _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/013/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/013/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/014/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec duplicate = function 2 | | [] -> [] 3 | | h :: t -> h :: h :: duplicate t 4 | -------------------------------------------------------------------------------- /practice/014/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/014/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/014/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/014/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/014/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Duplicate the elements of a list. 3 | 4 | ```ocaml 5 | # duplicate ["a"; "b"; "c"; "c"; "d"];; 6 | - : string list = ["a"; "a"; "b"; "b"; "c"; "c"; "c"; "c"; "d"; "d"] 7 | ``` 8 | -------------------------------------------------------------------------------- /practice/014/work/impl.ml: -------------------------------------------------------------------------------- 1 | let duplicate _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/014/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/014/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/015/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/015/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/015/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/015/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/015/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Replicate the elements of a list a given number of times. 3 | 4 | ```ocaml 5 | # replicate ["a"; "b"; "c"] 3;; 6 | - : string list = ["a"; "a"; "a"; "b"; "b"; "b"; "c"; "c"; "c"] 7 | ``` 8 | -------------------------------------------------------------------------------- /practice/015/work/impl.ml: -------------------------------------------------------------------------------- 1 | let replicate _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/015/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/015/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/016/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let drop list n = 2 | let rec aux i = function 3 | | [] -> [] 4 | | h :: t -> if i = n then aux 1 t else h :: aux (i + 1) t in 5 | aux 1 list 6 | -------------------------------------------------------------------------------- /practice/016/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/016/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/016/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/016/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/016/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Drop every N'th element from a list. 3 | 4 | ```ocaml 5 | # drop ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"; "i"; "j"] 3;; 6 | - : string list = ["a"; "b"; "d"; "e"; "g"; "h"; "j"] 7 | ``` 8 | -------------------------------------------------------------------------------- /practice/016/work/impl.ml: -------------------------------------------------------------------------------- 1 | let drop _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/016/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/016/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/017/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let split list n = 2 | let rec aux i acc = function 3 | | [] -> List.rev acc, [] 4 | | h :: t as l -> if i = 0 then List.rev acc, l 5 | else aux (i - 1) (h :: acc) t 6 | in 7 | aux n [] list 8 | -------------------------------------------------------------------------------- /practice/017/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/017/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/017/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/017/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/017/work/impl.ml: -------------------------------------------------------------------------------- 1 | let split _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/017/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/017/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/018/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let slice list i k = 2 | List.filteri (fun index _ -> index >= i && index <= k) list 3 | -------------------------------------------------------------------------------- /practice/018/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/018/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/018/answer2/impl.ml: -------------------------------------------------------------------------------- 1 | let slice list start stop = 2 | let rec aux i = function 3 | | [] -> [] 4 | | x :: xs when i >= start && i <= stop -> x :: (aux (i + 1) xs) 5 | | _ :: xs -> aux (i + 1) xs 6 | in aux 0 list 7 | -------------------------------------------------------------------------------- /practice/018/answer2/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/018/answer2/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/018/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/018/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/018/work/impl.ml: -------------------------------------------------------------------------------- 1 | let slice _ _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/018/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/018/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/019/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/019/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/019/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/019/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/019/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Rotate a list N places to the left. 3 | 4 | ```ocaml 5 | # rotate ["a"; "b"; "c"; "d"; "e"; "f"; "g"; "h"] 3;; 6 | - : string list = ["d"; "e"; "f"; "g"; "h"; "a"; "b"; "c"] 7 | ``` 8 | -------------------------------------------------------------------------------- /practice/019/work/impl.ml: -------------------------------------------------------------------------------- 1 | let rotate _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/019/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/019/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/020/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec remove_at n = function 2 | | [] -> [] 3 | | h :: t -> if n = 0 then t else h :: remove_at (n - 1) t 4 | -------------------------------------------------------------------------------- /practice/020/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/020/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/020/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/020/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/020/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Remove the K'th element from a list. 3 | 4 | The first element of the list is numbered 0, the second 1,... 5 | 6 | ```ocaml 7 | # remove_at 1 ["a"; "b"; "c"; "d"];; 8 | - : string list = ["a"; "c"; "d"] 9 | ``` 10 | -------------------------------------------------------------------------------- /practice/020/work/impl.ml: -------------------------------------------------------------------------------- 1 | let remove_at _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/020/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/020/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/021/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec insert_at x n = function 2 | | [] -> [x] (* Insert at the end if the list is empty or n is beyond the list length *) 3 | | h :: t as l -> if n = 0 then x :: l else h :: insert_at x (n - 1) t 4 | -------------------------------------------------------------------------------- /practice/021/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/021/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/021/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/021/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/021/work/impl.ml: -------------------------------------------------------------------------------- 1 | let insert_at _ _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/021/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/021/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/022/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let range a b = 2 | let rec aux a b = 3 | if a > b then [] else a :: aux (a + 1) b 4 | in 5 | if a > b then List.rev (aux b a) else aux a b 6 | -------------------------------------------------------------------------------- /practice/022/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/022/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/022/answer2/impl.ml: -------------------------------------------------------------------------------- 1 | (* Tail recursive Implementation *) 2 | let range a b = 3 | let rec aux acc high low = 4 | if high >= low then 5 | aux (high :: acc) (high - 1) low 6 | else acc 7 | in 8 | if a < b then aux [] b a else List.rev (aux [] a b) 9 | -------------------------------------------------------------------------------- /practice/022/answer2/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/022/answer2/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/022/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/022/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/022/statement.md: -------------------------------------------------------------------------------- 1 | 2 | If first argument is greater than second, produce a list in decreasing 3 | order. 4 | 5 | ```ocaml 6 | # range 4 9;; 7 | - : int list = [4; 5; 6; 7; 8; 9] 8 | ``` 9 | -------------------------------------------------------------------------------- /practice/022/work/impl.ml: -------------------------------------------------------------------------------- 1 | let range _ _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/022/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/022/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/023/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/023/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/023/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/023/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/023/work/impl.ml: -------------------------------------------------------------------------------- 1 | let rand_select _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/023/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/023/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/024/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/024/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/024/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/024/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/024/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Draw N different random numbers from the set `1..M`. 3 | 4 | The selected numbers shall be returned in a list. 5 | 6 | ```ocaml 7 | # lotto_select 6 49;; 8 | - : int list = [20; 28; 45; 16; 24; 38] 9 | ``` 10 | -------------------------------------------------------------------------------- /practice/024/work/impl.ml: -------------------------------------------------------------------------------- 1 | let lotto_select _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/024/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/024/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/025/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/025/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/025/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/025/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/025/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Generate a random permutation of the elements of a list. 3 | 4 | ```ocaml 5 | # permutation ["a"; "b"; "c"; "d"; "e"; "f"];; 6 | - : string list = ["c"; "d"; "f"; "e"; "b"; "a"] 7 | ``` 8 | -------------------------------------------------------------------------------- /practice/025/work/impl.ml: -------------------------------------------------------------------------------- 1 | let permutation _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/025/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/025/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/026/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec extract k list = 2 | if k <= 0 then [[]] 3 | else match list with 4 | | [] -> [] 5 | | h :: tl -> 6 | let with_h = List.map (fun l -> h :: l) (extract (k - 1) tl) in 7 | let without_h = extract k tl in 8 | with_h @ without_h 9 | -------------------------------------------------------------------------------- /practice/026/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/026/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/026/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/026/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/026/work/impl.ml: -------------------------------------------------------------------------------- 1 | let extract _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/026/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/026/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/027/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/027/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/027/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/027/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/027/work/impl.ml: -------------------------------------------------------------------------------- 1 | let group _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/027/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/027/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/028/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/028/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/028/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/028/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/028/work/impl.ml: -------------------------------------------------------------------------------- 1 | let length_sort _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/028/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/028/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/031/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let is_prime n = 2 | let n = abs n in 3 | let rec is_not_divisor d = 4 | d * d > n || (n mod d <> 0 && is_not_divisor (d + 1)) in 5 | n > 1 && is_not_divisor 2 6 | -------------------------------------------------------------------------------- /practice/031/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/031/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/031/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/031/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/031/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Determine whether a given integer number is prime. 3 | 4 | ```ocaml 5 | # not (is_prime 1);; 6 | - : bool = true 7 | # is_prime 7;; 8 | - : bool = true 9 | # not (is_prime 12);; 10 | - : bool = true 11 | ``` 12 | -------------------------------------------------------------------------------- /practice/031/work/impl.ml: -------------------------------------------------------------------------------- 1 | let is_prime _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/031/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/031/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/032/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = 2 | if b = 0 then a else gcd b (a mod b) 3 | -------------------------------------------------------------------------------- /practice/032/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/032/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/032/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/032/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/032/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Determine the greatest common divisor of two positive integer numbers. 3 | 4 | Use Euclid's algorithm. 5 | 6 | ```ocaml 7 | # gcd 13 27;; 8 | - : int = 1 9 | # gcd 20536 7826;; 10 | - : int = 2 11 | ``` 12 | -------------------------------------------------------------------------------- /practice/032/work/impl.ml: -------------------------------------------------------------------------------- 1 | let gcd _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/032/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/032/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/033/answer/impl.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = 2 | if b = 0 then a else gcd b (a mod b) 3 | 4 | let coprime a b = gcd a b = 1 5 | -------------------------------------------------------------------------------- /practice/033/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/033/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/033/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/033/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/033/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Determine whether two positive integer numbers are coprime. 3 | 4 | Two numbers are coprime if their greatest common divisor equals 1. 5 | 6 | ```ocaml 7 | # coprime 13 27;; 8 | - : bool = true 9 | # not (coprime 20536 7826);; 10 | - : bool = true 11 | ``` 12 | -------------------------------------------------------------------------------- /practice/033/work/impl.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = 2 | if b = 0 then a else gcd b (a mod b) 3 | 4 | let coprime _ _ = failwith "Not yet implemented" 5 | -------------------------------------------------------------------------------- /practice/033/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/033/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/034/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/034/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/034/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/034/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/034/work/impl.ml: -------------------------------------------------------------------------------- 1 | let rec gcd a b = if b = 0 then a else gcd b (a mod b) 2 | let coprime a b = gcd a b = 1 3 | 4 | let phi _ = failwith "Not yet implemented" 5 | -------------------------------------------------------------------------------- /practice/034/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/034/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/035/answer/impl.ml: -------------------------------------------------------------------------------- 1 | (* Recall that d divides n iff [n mod d = 0] *) 2 | let factors n = 3 | let rec aux d n = 4 | if n = 1 then [] else 5 | if n mod d = 0 then d :: aux d (n / d) else aux (d + 1) n 6 | in 7 | aux 2 n 8 | -------------------------------------------------------------------------------- /practice/035/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/035/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/035/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/035/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/035/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Construct a flat list containing the prime factors in ascending order. 3 | 4 | 5 | ```ocaml 6 | # factors 315;; 7 | - : int list = [3; 3; 5; 7] 8 | ``` 9 | -------------------------------------------------------------------------------- /practice/035/work/impl.ml: -------------------------------------------------------------------------------- 1 | let factors _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/035/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/035/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/036/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/036/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/036/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/036/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/036/work/impl.ml: -------------------------------------------------------------------------------- 1 | let factors _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/036/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/036/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/037/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/037/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/037/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/037/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/037/work/impl.ml: -------------------------------------------------------------------------------- 1 | let phi _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/037/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/037/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/039/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/039/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/039/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/039/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/039/statement.md: -------------------------------------------------------------------------------- 1 | 2 | Given a range of integers by its lower and upper limit, construct a list 3 | of all prime numbers in that range. 4 | 5 | ```ocaml 6 | # List.length (all_primes 2 7920);; 7 | - : int = 1000 8 | ``` 9 | -------------------------------------------------------------------------------- /practice/039/work/impl.ml: -------------------------------------------------------------------------------- 1 | let all_primes _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/039/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/039/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/040/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/040/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/040/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/040/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/040/work/impl.ml: -------------------------------------------------------------------------------- 1 | let goldbach _ = failwith "goldbach not implemented" 2 | -------------------------------------------------------------------------------- /practice/040/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/040/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/041/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/041/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/041/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/041/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/041/work/impl.ml: -------------------------------------------------------------------------------- 1 | let goldbach_list _ = failwith "goldbach_list not implemented" 2 | -------------------------------------------------------------------------------- /practice/041/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/041/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/046/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/046/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/046/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/046/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/046/work/impl.ml: -------------------------------------------------------------------------------- 1 | type bool_expr = 2 | | Var of string 3 | | Not of bool_expr 4 | | And of bool_expr * bool_expr 5 | | Or of bool_expr * bool_expr 6 | 7 | let table2 _ = failwith "Not yet implemented" 8 | -------------------------------------------------------------------------------- /practice/046/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/046/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/048/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/048/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/048/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/048/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/048/work/impl.ml: -------------------------------------------------------------------------------- 1 | type bool_expr = 2 | | Var of string 3 | | Not of bool_expr 4 | | And of bool_expr * bool_expr 5 | | Or of bool_expr * bool_expr 6 | let table _ = failwith "Not yet implemented" 7 | -------------------------------------------------------------------------------- /practice/048/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/048/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/049/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/049/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/049/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/049/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/049/work/impl.ml: -------------------------------------------------------------------------------- 1 | let gray _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/049/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/049/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/050/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/050/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/050/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/050/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/050/work/impl.ml: -------------------------------------------------------------------------------- 1 | let huffman _ = failwith "Not yet implemented" 2 | -------------------------------------------------------------------------------- /practice/050/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/050/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/055/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/055/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/055/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/055/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/055/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | let cbal_tree _ = failwith "Not yet implemented" 5 | -------------------------------------------------------------------------------- /practice/055/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/055/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/056/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/056/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/056/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/056/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/056/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | let is_symmetric _ = failwith "Not yet implemented" 5 | -------------------------------------------------------------------------------- /practice/056/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/056/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/057/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/057/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/057/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/057/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/057/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let construct _ = failwith "Not yet implemented" 6 | 7 | let is_symmetric _ = failwith "Not yet implemented" 8 | -------------------------------------------------------------------------------- /practice/057/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/057/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/058/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/058/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/058/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/058/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/058/work/impl.ml: -------------------------------------------------------------------------------- 1 | 2 | type 'a binary_tree = 3 | | Empty 4 | | Node of 'a * 'a binary_tree * 'a binary_tree 5 | let sym_cbal_trees _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/058/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/058/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/059/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/059/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/059/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/059/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/059/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let hbal_tree _ = failwith "Not yet implemented" 6 | 7 | let tree_height _ = failwith "Not yet implemented" 8 | 9 | let add_trees_with _ = failwith "Not yet implemented" 10 | 11 | -------------------------------------------------------------------------------- /practice/059/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/059/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/060/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/060/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/060/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/060/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/060/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let max_nodes h = 1 lsl h - 1 6 | 7 | let hbal_tree_nodes _ = failwith "Not yet implemented" 8 | 9 | let min_nodes _ = failwith "Not yet implemented" 10 | 11 | -------------------------------------------------------------------------------- /practice/060/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/060/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/061A/answer/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let rec count_leaves = function 6 | | Empty -> 0 7 | | Node (_, Empty, Empty) -> 1 8 | | Node (_, l, r) -> count_leaves l + count_leaves r 9 | -------------------------------------------------------------------------------- /practice/061A/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/061A/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/061A/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/061A/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/061A/statement.md: -------------------------------------------------------------------------------- 1 | 2 | A leaf is a node with no successors. Write a function `count_leaves` to 3 | count them. 4 | 5 | ```ocaml 6 | # count_leaves Empty;; 7 | - : int = 0 8 | ``` 9 | -------------------------------------------------------------------------------- /practice/061A/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let count_leaves _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/061A/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/061A/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/061B/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/061B/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/061B/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/061B/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/061B/statement.md: -------------------------------------------------------------------------------- 1 | 2 | A leaf is a node with no successors. Write a function `leaves` to 3 | collect them in a list. 4 | 5 | ```ocaml 6 | # leaves Empty;; 7 | - : 'a list = [] 8 | ``` 9 | -------------------------------------------------------------------------------- /practice/061B/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let leaves _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/061B/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/061B/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/062A/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/062A/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/062A/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/062A/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/062A/statement.md: -------------------------------------------------------------------------------- 1 | 2 | An internal node of a binary tree has either one or two non-empty 3 | successors. Write a function `internals` to collect them in a list. 4 | 5 | ```ocaml 6 | # internals (Node ('a', Empty, Empty));; 7 | - : char list = [] 8 | ``` 9 | -------------------------------------------------------------------------------- /practice/062A/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let internals _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/062A/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/062A/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/062B/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/062B/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/062B/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/062B/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/062B/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let at_level _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/062B/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/062B/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/063/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/063/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/063/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/063/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/063/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let complete_binary_tree _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/063/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/063/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/064/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/064/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/064/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/064/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/064/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let layout_binary_tree_1 _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/064/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/064/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/065/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/065/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/065/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/065/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/065/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let layout_binary_tree_2 _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/065/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/065/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/066/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/066/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/066/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/066/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/066/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let layout_binary_tree_3 _ = failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/066/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/066/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/067/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/067/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/067/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/067/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/067/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let string_of_tree _ = failwith "Not yet implemented" 6 | let tree_of_string _ = failwith "Not yet implemented" 7 | -------------------------------------------------------------------------------- /practice/067/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/067/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/068/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/068/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/068/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/068/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/068/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a binary_tree = 2 | | Empty 3 | | Node of 'a * 'a binary_tree * 'a binary_tree 4 | 5 | let preorder _ = failwith "Not yet implemented" 6 | let inorder _ = failwith "Not yet implemented" 7 | let pre_in_tree _ = failwith "Not yet implemented" 8 | -------------------------------------------------------------------------------- /practice/068/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/068/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/070A/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/070A/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/070A/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/070A/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/070A/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a mult_tree = T of 'a * 'a mult_tree list 2 | 3 | let string_of_tree _ = failwith "Not implemented" 4 | let tree_of_string _ = failwith "Not implemented" 5 | -------------------------------------------------------------------------------- /practice/070A/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/070A/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/070B/answer/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a mult_tree = T of 'a * 'a mult_tree list 2 | 3 | let rec count_nodes (T (_, sub)) = 4 | List.fold_left (fun n t -> n + count_nodes t) 1 sub 5 | -------------------------------------------------------------------------------- /practice/070B/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/070B/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/070B/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/070B/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/070B/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a mult_tree = T of 'a * 'a mult_tree list 2 | 3 | let count_nodes (T (_, _)) = 4 | (* Implementation goes here *) 5 | failwith "Not yet implemented" 6 | -------------------------------------------------------------------------------- /practice/070B/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/070B/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/071/answer/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a mult_tree = T of 'a * 'a mult_tree list 2 | 3 | let rec ipl_sub len (T(_, sub)) = 4 | List.fold_left (fun sum t -> sum + ipl_sub (len + 1) t) len sub 5 | 6 | let ipl t = ipl_sub 0 t 7 | -------------------------------------------------------------------------------- /practice/071/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/071/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/071/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/071/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/071/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/071/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/072/answer/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a mult_tree = T of 'a * 'a mult_tree list 2 | 3 | let rec prepend_bottom_up (T (c, sub)) l = 4 | List.fold_right (fun t l -> prepend_bottom_up t l) sub (c :: l) 5 | 6 | let bottom_up t = prepend_bottom_up t [] 7 | -------------------------------------------------------------------------------- /practice/072/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/072/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/072/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/072/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/072/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a mult_tree = T of 'a * 'a mult_tree list 2 | 3 | let prepend_bottom_up (T (_c, _sub)) l = 4 | (* Placeholder function that currently just returns the list unchanged *) 5 | l 6 | 7 | let bottom_up t = prepend_bottom_up t [] 8 | -------------------------------------------------------------------------------- /practice/072/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/072/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/073/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/073/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/073/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/073/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/073/work/impl.ml: -------------------------------------------------------------------------------- 1 | type 'a mult_tree = T of 'a * 'a mult_tree list 2 | 3 | let lispy (T (_c, _sub)) = 4 | (* Placeholder function that currently just returns an empty string *) 5 | "" 6 | -------------------------------------------------------------------------------- /practice/073/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/073/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/081/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/081/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/081/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/081/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/081/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/081/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/082/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/082/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/082/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/082/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/082/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/082/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/091/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/091/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/091/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/091/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/091/work/impl.ml: -------------------------------------------------------------------------------- 1 | let possible _ = 2 | failwith "Not implemented" 3 | 4 | let queens_positions _ = 5 | failwith "Not implemented" 6 | -------------------------------------------------------------------------------- /practice/091/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/091/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/095/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/095/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/095/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/095/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/095/work/impl.ml: -------------------------------------------------------------------------------- 1 | let full_words _ = 2 | failwith "Not implemented" 3 | -------------------------------------------------------------------------------- /practice/095/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/095/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/096/answer/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/096/answer/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Answer) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/096/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs qualified) 2 | (library (name ex) (libraries alcotest)) 3 | -------------------------------------------------------------------------------- /practice/096/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /practice/096/work/impl.ml: -------------------------------------------------------------------------------- 1 | let identifier _ = 2 | failwith "Not implemented" 3 | -------------------------------------------------------------------------------- /practice/096/work/test/dune: -------------------------------------------------------------------------------- 1 | (include_subdirs no) 2 | (test (name run) (libraries alcotest ex)) 3 | -------------------------------------------------------------------------------- /practice/096/work/test/run.ml: -------------------------------------------------------------------------------- 1 | module Test = Ex.Make(Ex.Work) 2 | 3 | let () = Test.run () 4 | -------------------------------------------------------------------------------- /practice/Makefile: -------------------------------------------------------------------------------- 1 | # FIXME: why are the $(for ...) expanding into empty strings 2 | 3 | answer: 4 | dune build $(for i in 0*/answer/test ; do echo @$i/runtest ; done) 5 | 6 | work: 7 | dune build $(for i in 0*/work/test ; do echo @$i/runtest ; done) 8 | -------------------------------------------------------------------------------- /practice/dune: -------------------------------------------------------------------------------- 1 | (rule 2 | (alias answer) 3 | (deps (alias 001/answer/test/runtest) (alias 002/answer/test/runtest) (alias 003/answer/test/runtest)) 4 | (action (run echo "-n"))) 5 | -------------------------------------------------------------------------------- /practice/dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.7) 2 | -------------------------------------------------------------------------------- /scripts/setup_codespaces.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | opam init -y --disable-sandboxing 4 | eval $(opam env) 5 | opam switch create 4.14.0 6 | eval $(opam env) 7 | 8 | opam install -y dune ounit 9 | 10 | chmod +x setup_exercise.sh 11 | --------------------------------------------------------------------------------