Duplicate Character Counter in V

Published on 30 October 2025 (Updated: 30 October 2025)

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

Current Solution

import os

fn show_error() {
	println('Usage: please provide a string')
}

fn main() {
	args := os.args[1..] // skip program name
	if args.len == 0 {
		show_error()
		return
	}
	input_str := args[0]
	if input_str.len == 0 {
		show_error()
		return
	}

	mut counts := map[rune]int{}
	for c in input_str.runes() {
		counts[c]++
	}

	mut found := false
	for c in input_str.runes() {
		if counts[c] > 1 {
			println('${c.str()}: ${counts[c]}')
			counts[c] = 0 // prevent duplicate printing
			found = true
		}
	}

	if !found {
		println('No duplicate characters')
	}
}

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