3.2 KiB
3.2 KiB
Hints
General
- Read about bitstrings in the Getting Started guide.
- Review the documentation for the bitstring special form.
- Review how to convert decimal numbers to binary numbers.
- Elixir supports different ways of writing integers, including binary notation.
1. Calculate palette bit size
- This task doesn't use the bitstring data type.
- Find the smallest positive number
n
such that 2 raised to the power ofn
is greater than or equal than the number of colors we need to represent. - Create a recursive function for this.
- Choose a starting bit size of 1. If 2 raised to the power of the bit size is greater than or equal to the color count, we've found our bit size. If not, add 1 to the bit size and check again (recursion).
- Use
Integer.pow/2
to raise 2 to a given power.
2. Create an empty picture
- Use the bitstring special form to create a new bitstring.
3. Create a test picture
- Use the bitstring special form to create a new bitstring.
- Use the type operator to specify the bit size of each fragment.
4. Prepend a pixel to a picture
- The bitstring special form can be used to append a new fragment to an existing bitstring.
- Use the type operator to specify the bit size of the new fragment as well as the existing bitstring.
- Use the previously implemented
PaintByNumber.palette_bit_size/1
function to get the bit size of the new fragment. - Use the special
::bitstring
type to specify that the old fragment is of unknown size.
5. Get the first pixel from a picture
- The bitstring special form can be used to pattern match bitstrings.
- Use the previously implemented
PaintByNumber.palette_bit_size/1
function to get the bit size of one pixel. - Use the special
::bitstring
type to specify that the rest of the bitstring is of unknown size.
6. Drop the first pixel from a picture
- The bitstring special form can be used to pattern match bitstrings.
- Use the previously implemented
PaintByNumber.palette_bit_size/1
function to get the bit size of one pixel. - Use the special
::bitstring
type to specify that the rest of the bitstring is of unknown size.
7. Concatenate two pictures
- The bitstring special form can be used to concatenate two bitstrings.
- Use the special
::bitstring
type to specify that each of the bitstring fragments is of unknown size.