Giter Club home page Giter Club logo

ocaml-6-subtasks's Introduction

Task 1

Find functions f1, f2, and f3, such that

fold_left f1 [] [(a1, b1) ; ... ; (an, bn)] for arbitrary ai, bi computes the list [(b1, a1); ... ; (bn, an) ]

fold_left f2 [] [a_0 ; ... ; a_{n−3} ; a_{n−2}; a_{n−1}; a_n] for arbitrary elements a_i computes the list [a_n; a_{n−2} ; ... ; a_0 ; ... ; a_{n−3} ; a_{n−1}]

fold_left f3 (fun _ -> 0) [(k1 , v1) ; ... ; (kn, vn) ] computes a function g such that g(ki) = vi for all 1 ≤ i ≤ n. The k's are assumed to be pairwise distinct.

Task 2

Rewrite the following functions in a tail-recursive form:

let rec map f = function | [] -> [] | x :: xs -> f x :: map f xs

let rec replicate n x = if n < 1 then [] else x :: replicate (n-1) x

Task 3

Implement a mapping function that maps a function over a lazy list. Implement it both for custom and OCaml lazy list variants. Call them respectively map_over_custom_llist and map_over_ocaml_llist.

Task 4

Implement a merging function that combines two sorted lazy lists.

The idea of merging two lists: merge [1;4;6;7;8; ... ] [1;2;3;4;10; ... ] = [1;1;2;3;4;4;6;7;8;10; ... ]

Implement the function both for custom and OCaml lazy list variants. Call them respectively merge_custom_llists and merge_ocaml_llists.

Task 5

Implement a function that drops duplicates from a sorted lazy list.

Implement it both for custom and OCaml lazy list variants. Call them respectively drop_dupl_custom_llist and drop_dupl_ocaml_llist.

Task 6

Implement a function hamming that lazily computes the infinite sequence of Hamming numbers (i.e., all natural numbers whose only prime factors are 2, 3, and 5), e.g., hamming = [1;2;3;4;5;6;8;9;10;12;15;16;18;20; ... ]

Implement it both for custom and OCaml lazy list variants. Call them respectively hamming_custom_llist and hamming_ocaml_llist.

ocaml-6-subtasks's People

Contributors

nickgabriadze avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.