πŸ—“οΈDay 18

Thursday, 25 August 2022 - Day 18 of Exhort August 2022 - Exercism (My Elixir Journey)

Exercises

Captain's Log

Exercise on Exercismarrow-up-right | View my solutionarrow-up-right

Solution

chevron-rightExpand to see code (spoiler alert)hashtag
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

View gist on GitHubarrow-up-right

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

An image showing my progress on Exercism. It's 20.5% as of Thursday, 25 August 2022.
Progress

Last updated