OCaml Exercises
This is a collection of OCaml programming exercises for the course CAS CS 320: Concepts of Programming Languages at Boston University. They've been written by me over the last iterations of the course, with help from Ankush Das and others. This page is essentially a course-specific version of
all of which are also valuable resources.
1. Arithmetic
- Fahrenheit to Celsius
- Factorial, Twice
- Number of Digits
- Palindromic Integers
- Modular Arithmetic
- The Fibonacci Sequence
- The Collatz Conjecture
- Integer Square Root
- Integer Exponentiation
- Perfect Powers
- Greatest Common Divisor
- Primality
- Number of Factors
- Nth Prime Number
- Perfect Numbers
- Hypotenuse
- Sums of Squares
- Taxicab Numbers
- Total Stopping Time Records
- Path Records
2. Lists and Strings
- Reverse Append
- Reverse Concatenation
- Drop Leading
- Drop Trailing
- Towers of Hanoi
- String Triangle
- Hourglass
- Lookup (Right)
- Split by Less-Than
- Split At
- Splitting Lists
- Sum at K
- Product Above K
- Every K Elements
- Every Other
- Suffixes
- Prefixes
- Nub
- Splits
- Sublists
- Permutations
- Pairs
- Bitonic Sequences
- Packing
- Grouping
- Factoring
- The Generalized Fibonacci Sequence
- Graph Connectivity
- Valid 1D Paths
- Split by Whitespace
- Split by Whitespace, Correctly
- Reversing Strings
- Split on Character
3. Sums and Products
- Walking Distance
- Repeats
- All Some
- Grouping Integers and Strings
- Icy Hot
- Height of a Binary Tree
- Binary Tree Insertion
- Flattening Binary Trees
- Sorting by Flattening
- Alternating Paths
- Counting 2-3 Trees
- Summing 3-2 Trees
- Recipes by Ingredients
- Updating Recent Posts
- Sorting Concatenation Lists
- Tailing Ordered Fork Lists
- Reversing Double Lists
- Splitting Rose Trees
- Summing Rose Trees
- Reversing Rose Trees
- Binary Tree to Rose Tree
- File Trees
- Deepest Parentheses
- Allocating Memory
- Freeing Memory
- Pretty Arithmetic Expressions
- Mapping Keys
- S-Expressions to Rose Trees
- Rose Trees to S-Expressions
4. Higher-Order Programming
- Curry
- Uncurry
- Curry 3
- Uncurry 3
- Map 2
- Filter Map
- Prefix Map
- All Map
- Take While
- Drop While
- Split By
- Filter Any
- Filter All
- Fold Right 2
- Fold Left 2
- Mapping Rose Trees
- Filtering Rose Trees
- Replicate
- Cyclic Function Application
- Fixpoints
- Increasing Sequence
- Consecutives
- List Convolution and Multiplying Polynomials
- Function Maximum
- Graph Walks
- Random Walks
- Last Function Standing
- Folding and OUnit