Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Set-consolidation/Ring/set-consolidation.ring
Normal file
38
Task/Set-consolidation/Ring/set-consolidation.ring
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Project : Set consolidation
|
||||
|
||||
load "stdlib.ring"
|
||||
test = ["AB","AB,CD","AB,CD,DB","HIK,AB,CD,DB,FGH"]
|
||||
for t in test
|
||||
see consolidate(t) + nl
|
||||
next
|
||||
func consolidate(s)
|
||||
sets = split(s,",")
|
||||
n = len(sets)
|
||||
for i = 1 to n
|
||||
p = i
|
||||
ts = ""
|
||||
for j = i to 1 step -1
|
||||
if ts = ""
|
||||
p = j
|
||||
ok
|
||||
ts = ""
|
||||
for k = 1 to len(sets[p])
|
||||
if j > 1
|
||||
if substring(sets[j-1],substr(sets[p],k,1),1) = 0
|
||||
ts = ts + substr(sets[p],k,1)
|
||||
ok
|
||||
ok
|
||||
next
|
||||
if len(ts) < len(sets[p])
|
||||
if j > 1
|
||||
sets[j-1] = sets[j-1] + ts
|
||||
sets[p] = "-"
|
||||
ts = ""
|
||||
ok
|
||||
else
|
||||
p = i
|
||||
ok
|
||||
next
|
||||
next
|
||||
consolidate = s + " = " + substr(list2str(sets),nl,",")
|
||||
return consolidate
|
||||
Loading…
Add table
Add a link
Reference in a new issue