csci-350-lab1 /

Filename Size Date modified Message
2.5 KB
627 B
529 B
38 B
1.3 KB

CSCI 350 - Programming Languages - Fall 2012

Lab 1

For this lab exercise, you will write three small programs as described below. Submit the three source files via Blackboard. This is an individual assignment. You may not work in groups for this lab.

Due Date: 11.59.59pm, Wednesday, Sep. 19th, 2011. Late assignments will be penalized at 10% per day, up to two days. Submitted work after three days will receive no credit.

  1. Install the OCaml compiler and runtime on your system. You can find binary distributions at Inria. You can also install this via Cygwin, if you are on Windows.

  2. Implement a program which reads in an integer value,n, and computes the nth Fibonacci number. Once computed, your program should print the value to the screen. Name your program

    Recall that the Fibonacci sequence is defined as:

    f(0) = 0
    f(1) = 1
    f(n) = f(n-1) + f(n-2)
  3. Implement a program which reads in two integer values, m and n, then computes the value of the Ackermann function. Once computed, your program should print the value to the screen. Name your program

    Recall that the Ackermann function is defined as:

    A(m,n) = n + 1 if m = 0
    A(m,n) = A(m-1, 1) if m > 0 and n = 0
    A(m,n) = A(m-1, A(m, n-1)) if m > 0 and n > 0
  4. Implement the following algorithm in OCaml. Your program should open a file: input.dat, which has a sequence of integers in it. The integers will be one per-line. Read in the integers, sort them and print them out in sorted order (on a single line). Name your program

    The basic steps in the algorithm are:
    - Read input into a list.
    - Print the input list.
    - Call a function, splitter, which takes the input list and splits it into two lists. One list will contain all of the even numbers from the input file and the other contains all of the odd numbers.
    - Print out both the even and odd lists.

    This program can be implemented without using any assignment statements. Programs without any assignment statements or side-effects are said to bepure functionalprograms. Your solution should be implemented in a functional style, without using unnecessary assignment statements.

    Your program should produce the following output:

    $ ./splitter
    input: 7 6 5 4 3 2 1
    evens: 2 4 6
    odds: 1 3 5 7