Skip to content

Instantly share code, notes, and snippets.

@petros
Last active August 28, 2022 17:32
Show Gist options
  • Save petros/f3ea94dce96faf70c87c38e6528d14f4 to your computer and use it in GitHub Desktop.
Save petros/f3ea94dce96faf70c87c38e6528d14f4 to your computer and use it in GitHub Desktop.
Captain's Log - Elixir - Exercism
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment