DEV Community

loading...

Discussion on: Daily Challenge #259 - Duplicate Encoder

Collapse
ilhotiger profile image
Ilho Song

Erlang solution, though not sure this would be the most efficient. I am still learning the language :)

process(Input) ->
    ResultMap = lists:foldl(
        fun(Char, Map) -> 
            case maps:is_key(Char, Map) of
                true -> maps:put(Char, ")", Map);
                false -> maps:put(Char, "(", Map)
            end
        end, 
        maps:new(), 
        string:lowercase(Input)),
    lists:foldl(
        fun(Char, Acc) -> lists:append(Acc, maps:get(Char, ResultMap)) end,
        "",
        string:lowercase(Input)
    ).