- Iterations
- 1 1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | defmodule Grains do use Bitwise @doc """ Calculate two to the power of the input minus one. """ @spec square(pos_integer) :: pos_integer def square(number) do bsl(1, number-1) end @doc """ Adds square of each number from 1 to 64. """ @spec total :: pos_integer def total do square(65) - 1 end end |

defmodule Grains do
use Bitwise
@doc """
Calculate two to the power of the input minus one.
"""
@spec square(pos_integer) :: pos_integer
def square(number) do
bsl(1, number-1)
end
@doc """
Adds square of each number from 1 to 64.
"""
@spec total :: pos_integer
def total do
square(65) - 1
end
end

@elvanja and @derhackler think this looks great

## Comments

A very very nice idea on how to execute power of 2, without actually doing it :D Thank you for the idea!

You're not logged in right now. Please login via GitHub to comment