Unique characters in each string: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "{{Draft task}} ;Task: Given a list of strings,   find characters appearing in each string and once only. The result should be given in alphabetical order. Use the fol...")
 
(Use more illustrative input for this task)
Line 8: Line 8:


Use the following list for this task:
Use the following list for this task:
["1a3c52debeffd", "2b6178c97a938st","3ycxdb1fgxa2yz"]
["1a3c52debeffd", "2b6178c97a938stf","3ycxdb1fgxa2yz"]





Revision as of 07:34, 9 May 2021

Unique characters in each string is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

Given a list of strings,   find characters appearing in each string and once only.

The result should be given in alphabetical order.


Use the following list for this task:

        ["1a3c52debeffd", "2b6178c97a938stf","3ycxdb1fgxa2yz"]


Other tasks related to string operations:
Metrics
Counting
Remove/replace
Anagrams/Derangements/shuffling
Find/Search/Determine
Formatting
Song lyrics/poems/Mad Libs/phrases
Tokenize
Sequences



Ring

<lang ring> see "working..." + nl see "Unique characters in each string are:" + nl row = 0 str = "" cList = [] uniqueChars = ["1a3c52debeffd", "2b6178c97a938st","3ycxdb1fgxa2yz"] lenChars = len(uniqueChars)

for n = 1 to lenChars

   str = str + uniqueChars[n]

next

for n = 1 to len(str)

   flag = 1
   for m = 1 to lenChars
       cnt = count(uniqueChars[m],str[n])
       if cnt != 1
          flag = 0
          exit
       ok
   next
   if flag = 1
      add(cList,str[n])
   ok

next add(cList,"~") cList = sort(cList) for n = 1 to len(cList)-1

   if cList[n] != cList[n+1]
      row = row + 1
      see "" + cList[n] + " "
   ok

next see nl

see "Found " + row + " unique characters in each string" + nl see "done..." + nl

func count(cString,dString)

    sum = 0
    while substr(cString,dString) > 0
          sum++
          cString = substr(cString,substr(cString,dString)+len(string(sum)))
    end
    return sum

</lang>

Output:
working...
Unique characters in each string are:
1 2 3 a b c 
Found 6 unique characters in each string
done...