Elm

Other Elm solutions.
module Grains exposing (square)


square : Int -> Maybe Int
square n =
    if n <= 0 then
        Nothing

    else
        Just (2 ^ (n - 1))

Roc

Other Roc solutions.
module [grainsOnSquare, totalGrains]

grainsOnSquare : U8 -> Result U64 _
grainsOnSquare = \square ->
    if square > 0 && square <= 64 then
        Ok (Num.powInt 2 ((Num.toU64 square) - 1))
    else
        Err NotAChessSquare

totalGrains : U64
totalGrains = Num.maxU64