How to resolve the algorithm Determine if a string has all unique characters step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Determine if a string has all unique characters step by step in the Nim programming language
Table of Contents
Problem Statement
Given a character string (which may be empty, or have a length of zero characters):
Use (at least) these five test values (strings):
Show all output here on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Determine if a string has all unique characters step by step in the Nim programming language
Source code in the nim programming language
import unicode, strformat
proc checkUniqueChars(s: string) =
echo fmt"Checking string ""{s}"":"
let runes = s.toRunes
for i in 0..<runes.high:
let rune = runes[i]
for j in (i+1)..runes.high:
if runes[j] == rune:
echo "The string contains duplicate characters."
echo fmt"Character {rune} ({int(rune):x}) is present at positions {i+1} and {j+1}."
echo ""
return
echo "All characters in the string are unique."
echo ""
const Strings = ["",
".",
"abcABC",
"XYZ ZYX",
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ",
"hétérogénéité",
"🎆🎃🎇🎈",
"😍😀🙌💃😍🙌",
"🐠🐟🐡🦈🐬🐳🐋🐡"]
for s in Strings:
s.checkUniqueChars()
You may also check:How to resolve the algorithm Sorting algorithms/Patience sort step by step in the Phix programming language
You may also check:How to resolve the algorithm Sisyphus sequence step by step in the Java programming language
You may also check:How to resolve the algorithm Knapsack problem/Unbounded step by step in the Ruby programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Ascending primes step by step in the V (Vlang) programming language