-
-
Save petros/f3ea94dce96faf70c87c38e6528d14f4 to your computer and use it in GitHub Desktop.
Captain's Log - Elixir - Exercism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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