Resolution of Linear SystemsThis exercise revisits the resolution of linear systems
presented as an exercise in the chapter on imperative programming
By using the Printf module, write a function
that aligns the columns of the system.
this function on the examples given on page ??.
Search for Prime Numbers
The Sieve of Eratosthenes is an easily programmed algorithm
that searches for prime numbers in a range of integers, given
that the lower limit is a prime number. The method is:
Here are the steps to create a program that implements this algorithm:
Enumerate, in a list, all the values on the range.
- Remove from the list all the values that are multiples of the first
- Remove this first element from the list, and keep it as a prime.
- Restart at step 2 as long as the list is not empty.
Write a function range
that builds a range of integers represented in the form of a list.
- Write a function eras
that calculates the prime numbers on a range of integers starting with 2,
according to the algorithm of the Sieve of Eratosthenes.
Write a function era_go
that takes an integer and returns a list of all the prime numbers
smaller than this integer.
- We want to write an executable primes
that one will launch by typing the command primes n, where n
is an integer. This executable will print the prime numbers smaller
than n. For this we must use the Sys module
and check whether a parameter was passed.
Bitmaps saved as color array array are
bulky. Since 24 bits of color are rarely used, it is possible to
encode a bitmap in less space. For this we will analyze
the number of colors in a bitmap. If the number is small
(for example less than 256) we can encode each pixel in 1 byte,
representing the number of the color in the table of colors of this
Write a function analyze_colors
exploring a value of type color array array and that
returns a list of all the colors found in this image.
- From this list, construct
a palette. We will take a vector of colors.
The index in the table will correspond to the order of the color,
and the contents are the color itself. Write the function
that returns the index of a value stored in the array.
- From this table, write a conversion function,
that goes from a
color array array to a string. Each pixel is
thus represented by a character.
- Define a type image_tdc
comprising a table that matches colors to a vector of strings, allowing
the encoding of a bitmap (or color array) using a smaller method.
- Write the function to_image_tdc
to convert a color array array to this type.
- Write the function save_image_tdc
to save the values to a file.
the size of the file obtained with the saved version of an
- Write the function from_image_tdc
to do the reverse conversion.
- Use it to display
an image saved in a file. The file will be in the form of a value of type