How to resolve the algorithm Determine if a string has all unique characters step by step in the Wren 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 Wren 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 Wren programming language
Source code in the wren programming language
import "./fmt" for Conv, Fmt
var analyze = Fn.new { |s|
var chars = s.codePoints.toList
var le = chars.count
System.print("Analyzing %(Fmt.q(s)) which has a length of %(le):")
if (le > 1) {
for (i in 0...le-1) {
for (j in i+1...le) {
if (chars[j] == chars[i]) {
System.print(" Not all characters in the string are unique.")
var c = String.fromCodePoint(chars[i])
var hex = "0x" + Conv.hex(chars[i])
System.print(" '%(c)' (%(hex)) is duplicated at positions %(i+1) and %(j+1).\n")
return
}
}
}
}
System.print(" All characters in the string are unique.\n")
}
var strings = [
"",
".",
"abcABC",
"XYZ ZYX",
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ",
"01234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ0X",
"hétérogénéité",
"🎆🎃🎇🎈",
"😍😀🙌💃😍🙌",
"🐠🐟🐡🦈🐬🐳🐋🐡"
]
for (s in strings) analyze.call(s)
You may also check:How to resolve the algorithm Quickselect algorithm step by step in the C# programming language
You may also check:How to resolve the algorithm Department numbers step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Bitwise IO step by step in the Raku programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Crack programming language
You may also check:How to resolve the algorithm Sort three variables step by step in the C++ programming language