June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -3,18 +3,14 @@ display(list l)
|
|||
{
|
||||
integer i;
|
||||
record r;
|
||||
text s;
|
||||
|
||||
for (i, r in l) {
|
||||
text u, v;
|
||||
|
||||
o_text(s);
|
||||
s = ", ";
|
||||
o_text("{");
|
||||
o_text(i ? ", {" : "{");
|
||||
for (u in r) {
|
||||
o_text(v);
|
||||
o_(v, u);
|
||||
v = ", ";
|
||||
o_text(u);
|
||||
}
|
||||
o_text("}");
|
||||
}
|
||||
|
|
@ -25,24 +21,13 @@ display(list l)
|
|||
integer
|
||||
intersect(record r, record u)
|
||||
{
|
||||
integer a;
|
||||
text s;
|
||||
|
||||
a = 0;
|
||||
for (s in r) {
|
||||
if (r_key(u, s)) {
|
||||
a = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return a;
|
||||
trap_q(r_vcall, r, r_put, 1, record().copy(u), 0);
|
||||
}
|
||||
|
||||
void
|
||||
merge(record u, record r)
|
||||
{
|
||||
r_wcall(r, r_add, 1, 2, u);
|
||||
r.wcall(r_add, 1, 2, u);
|
||||
}
|
||||
|
||||
list
|
||||
|
|
@ -54,28 +39,21 @@ consolidate(list l)
|
|||
for (i, r in l) {
|
||||
integer j;
|
||||
|
||||
j = i - ~l + 1;
|
||||
while (j) {
|
||||
j = i - ~l;
|
||||
while (j += 1) {
|
||||
record u;
|
||||
|
||||
u = l[j];
|
||||
j += 1;
|
||||
if (intersect(r, u)) {
|
||||
merge(u, r);
|
||||
l_delete(l, i);
|
||||
l.delete(i);
|
||||
i -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
list
|
||||
L(...)
|
||||
{
|
||||
return xcall(l_assemble);
|
||||
l;
|
||||
}
|
||||
|
||||
record
|
||||
|
|
@ -83,7 +61,7 @@ R(...)
|
|||
{
|
||||
record r;
|
||||
|
||||
ucall(r_p_integer, 1, r, 0);
|
||||
ucall(r_put, 1, r, 0);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
|
@ -91,11 +69,11 @@ R(...)
|
|||
integer
|
||||
main(void)
|
||||
{
|
||||
display(consolidate(L(R("A", "B"), R("C", "D"))));
|
||||
display(consolidate(L(R("A", "B"), R("B", "D"))));
|
||||
display(consolidate(L(R("A", "B"), R("C", "D"), R("D", "B"))));
|
||||
display(consolidate(L(R("H", "I", "K"), R("A", "B"), R("C", "D"),
|
||||
R("D", "B"), R("F", "G", "K"))));
|
||||
display(consolidate(list(R("A", "B"), R("C", "D"))));
|
||||
display(consolidate(list(R("A", "B"), R("B", "D"))));
|
||||
display(consolidate(list(R("A", "B"), R("C", "D"), R("D", "B"))));
|
||||
display(consolidate(list(R("H", "I", "K"), R("A", "B"), R("C", "D"),
|
||||
R("D", "B"), R("F", "G", "K"))));
|
||||
|
||||
return 0;
|
||||
0;
|
||||
}
|
||||
|
|
|
|||
41
Task/Set-consolidation/Ring/set-consolidation.ring
Normal file
41
Task/Set-consolidation/Ring/set-consolidation.ring
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# Project : Set consolidation
|
||||
# Date : 2018/03/29
|
||||
# Author : Gal Zsolt [~ CalmoSoft ~]
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
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