This repository has been archived on 2022-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
dandhelper.ex/Attack.ex

16 lines
427 B
Elixir

defmodule Attack do
def parse(str) when is_bitstring(str) do
parse(str, [])
end
def parse(str, bonus) when is_bitstring(str) and is_list(bonus) do
cap = Regex.named_captures(~r/^(?<current>[\+\-]?\d+)(?<next>(\/([\+\-]?\d+))*)/, str)
cond do
is_nil(cap) ->
bonus
true ->
parse(String.trim_leading(cap["next"], "/"), bonus ++ [String.to_integer(cap["current"])])
end
end
end