How to resolve the algorithm Determine if a string has all unique characters step by step in the Sidef 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 Sidef 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 Sidef programming language
Source code in the sidef programming language
func index_duplicates(str) {
gather {
for k,v in (str.chars.kv) {
var i = str.index(v, k+1)
take([k, i]) if (i != -1)
}
}
}
var strings = [
"", ".", "abcABC", "XYZ ZYX",
"1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ",
"01234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ0X",
"hétérogénéité", "🎆🎃🎇🎈", "😍😀🙌💃😍🙌",
"🐠🐟🐡🦈🐬🐳🐋🐡"
]
strings.each {|str|
print "\n'#{str}' (size: #{str.len}) "
var dups = index_duplicates(str)
say "has duplicated characters:" if dups
for i,j in (dups) {
say "#{str[i]} (#{'%#x' % str[i].ord}) in positions: #{i}, #{j}"
}
say "has no duplicates." if !dups
}
You may also check:How to resolve the algorithm Leonardo numbers step by step in the BASIC programming language
You may also check:How to resolve the algorithm Terminal control/Dimensions step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the J programming language
You may also check:How to resolve the algorithm Simple windowed application step by step in the Phix programming language
You may also check:How to resolve the algorithm Factorial step by step in the SETL programming language