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.159 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.158 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.157 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.156 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.155 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.154 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.153 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.152 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.151 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.150 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.149 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.148 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.147 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.146 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.145 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.144 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.143 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.142 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.141 tracks/elixir/exercises/grains/example.exs
trackler-2.2.1.140 tracks/elixir/exercises/grains/example.exs