Duplicate Character Counter in Elixir

Published on 04 June 2026 (Updated: 04 June 2026)

Welcome to the Duplicate Character Counter in Elixir page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

case System.argv() do
  [str] when byte_size(str) > 0 ->
    chars = String.graphemes(str)

    frequencies = Enum.reduce(chars, %{}, fn el, acc ->
      Map.update(acc, el, 1, &(&1 + 1))
    end) |> Enum.filter(fn {_, count} -> count > 1 end) |> Map.new()

    if Enum.empty?(frequencies) do
      IO.puts("No duplicate characters")
    else
      chars
      |> Enum.uniq()
      |> Enum.each(fn char ->
        if Map.has_key?(frequencies, char) do
          IO.puts("#{char}: #{frequencies[char]}")
        end
      end)
    end
  _ -> IO.puts("Usage: please provide a string")
end

Duplicate Character Counter in Elixir was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.