How to resolve the algorithm Determine if a string has all unique characters step by step in the Nanoquery 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 Nanoquery 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 Nanoquery programming language
Source code in the nanoquery programming language
def analyze(s)
s = str(s)
println "Examining [" + s + "] which has a length of " + str(len(s)) + ":"
if len(s) < 2
println "\tAll characters in the string are unique."
return
end
seen = list()
for i in range(0, len(s) - 2)
if s[i] in seen
println "\tNot all characters in the string are unique."
println "\t'" + s[i] + "' " + format("(0x%x)", ord(s[i])) +\
" is duplicated at positions " + str(i + 1) + " and " +\
str(s.indexOf(s[i]) + 1)
return
end
seen.append(s[i])
end
println "\tAll characters in the string are unique."
end
tests = {"", ".", "abcABC", "XYZ ZYX", "1234567890ABCDEFGHIJKLMN0PQRSTUVWXYZ"}
for s in tests
analyze(s)
end
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm Machine code step by step in the Wren programming language
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the Quackery programming language
You may also check:How to resolve the algorithm Singly-linked list/Element definition step by step in the Perl programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Quite BASIC programming language