exercism/elixir/dna-encoding/HINTS.md

2.7 KiB

Hints

General

  • Use ? to work with the character code points.
  • \s can be used to represent a space.
  • Use integer binary notation for working with the codes.
  • Try to use the tail call recursion strategy.

1. Encode nucleic acid to binary value

  • This function needs to map one integer to another.
  • This function doesn't need recursion.
  • Making use of multiple clause functions may make this easier by breaking it down.

2. Decode the binary value to the nucleic acid

  • This function is the opposite of part 1's function.
  • This function doesn't need recursion.
  • Making use of multiple clause functions may make this easier by breaking it down.

3. Encode a DNA charlist

  • Create a tail-recursive function which takes a code point from the charlist and recursively builds the bitstring result.
  • Tail-recursive functions need an accumulator.
  • Remember, a charlist is a list of integer code points.
  • You can get the first and remaining items from a list using a built-in Kernel module function.
  • You can also pattern match on a list using the [head | tail] notation.
  • Use multiple clause functions to separate the base case from the recursive cases.
  • Do not forget to specify the types of bitstring segments using the :: operator.

4. Decode a DNA bitstring

  • Create a tail-recursive function which matches the first 4 bits from the bitstring and recursively builds the charlist result.
  • Tail-recursive functions need an accumulator.
  • Remember the bitstring special form can be used for matching on bitstrings.
  • Do not forget to specify the types of bitstring segments using the :: operator.
  • You will need to reverse the accumulator at the end. Write a private tail-recursive reverse function to do that and use it in the base-case of the decode function.