User Tools

Site Tools


This is an old revision of the document!

CSci 326: Daily 3

Define each of these functions in a module Daily3. Place the module in a file daily3.exs along with code to exercise the functions (and print the results) using the tests given below. This script should run properly using the elixir program which is how I'll test them.

You saw the tuple data type in Daily 1. There are two built-in functions for accessing tuple elements and creating new tuples from existing ones:

  • elem(tp, index) returns the nth value in the tuple tp, starting at 0
  • put_elem(tp, n, value) returns a new tuple replacing the nth element of tp with value

We can represent a quadratic equation as a tuple where each element is a coefficient; for example we can use {1, 3, 2} to represent x2 + 3x + 2.

  1. Write a function quad_eval that takes a tuple and a value for x and returns the result of evaluating the equation at that value. You can assume the tuple is the correct length and contains numbers
cs326/daily3.1517200793.txt.gz · Last modified: 2018/01/28 22:39 by scarl