Sha256: 5fd897631204a44eafef2cfbc17282a1ec3e20375aa565da6c9194dbb634775f

Contents?: true

Size: 362 Bytes

Versions: 69

Compression:

Stored size: 362 Bytes

Contents

defmodule Grains do
  use Bitwise, only_operators: true
  def square(number) when number in 1..64, do: {:ok, 1 <<< (number - 1)}
  def square(_), do: {:error, "The requested square must be between 1 and 64 (inclusive)"}

  def total,
    do:
      {:ok,
       Enum.reduce(1..64, 0, fn n, acc ->
         {:ok, sq} = square(n)
         acc + sq
       end)}
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.179 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.178 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.177 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.176 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.175 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.174 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.173 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.172 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.171 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.170 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.169 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.167 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.166 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.165 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.164 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.163 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.162 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.161 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.160 tracks/elixir/exercises/grains/example.exs