Duplicate Character Counter in Ruby

Published on 31 October 2024 (Updated: 07 May 2026)

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

Current Solution

input = ARGV.first.to_s

abort("Usage: please provide a string") if input.empty?

duplicates = input.each_char.tally.select { _2 > 1 }

if duplicates.empty?
  puts "No duplicate characters"
  return
end

duplicates.each { |char, count| puts "#{char}: #{count}" }

Duplicate Character Counter in Ruby 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.