# Day 18

## Exercises

* [x] [Captain's Log](#captains-log)

### Captain's Log

[Exercise on Exercism](https://exercism.org/tracks/elixir/exercises/captains-log) **|** [View my solution](https://exercism.org/tracks/elixir/exercises/captains-log/solutions/petros)

#### Solution

<details>

<summary>Expand to see code (spoiler alert)</summary>

{% code lineNumbers="true" %}

```elixir
defmodule CaptainsLog do
  @planetary_classes ["D", "H", "J", "K", "L", "M", "N", "R", "T", "Y"]

  @spec random_planet_class() :: String.t()
  def random_planet_class(), do: Enum.random(@planetary_classes)

  @spec random_ship_registry_number() :: String.t()
  def random_ship_registry_number(), do: "NCC-#{Enum.random(1000..9999)}"

  @spec random_stardate() :: float
  def random_stardate(), do: 41000.0 + (42000.0 - 41000.0) * :rand.uniform()

  @spec format_stardate(Float.t()) :: String.t()
  def format_stardate(stardate), do: :io_lib.format("~.1f", [stardate]) |> List.to_string()
end

```

{% endcode %}

[View gist on GitHub](https://gist.github.com/petros/f3ea94dce96faf70c87c38e6528d14f4)

</details>

#### Notes

Part of this exercise is showing you how to use Erlang libraries and functions for functionality that doesn't exist in Elixir. However, the Erlang documentation for those functions is not as digestible as Elixir's documentation.

## Overall progress

<figure><img src="https://722931016-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FDUq5E45vIeUDn4lY3Psn%2Fuploads%2Fb3MK2WhZS7LElWiKerVD%2F20220825-exhort-day18-progress.png?alt=media&#x26;token=72864f31-e69b-4f4f-85f1-c6e6b4fc6cdb" alt="An image showing my progress on Exercism. It&#x27;s 20.5% as of Thursday, 25 August 2022."><figcaption><p>Progress</p></figcaption></figure>
