Data update

This commit is contained in:
Ingy döt Net 2025-06-11 20:16:52 -04:00
parent 72eb4943cb
commit 4d5544505c
2347 changed files with 62432 additions and 16731 deletions

View file

@ -0,0 +1,14 @@
struct Set
def powerset
result = Set(typeof(self)).new
arr = to_a
(0..size).each do |n|
arr.each_combination(n, true) do |comb|
result << comb.to_set
end
end
result
end
end
p [1, 2, 3, 4].to_set.powerset

View file

@ -0,0 +1,72 @@
Function ToStringSet {
if match("A") then
read SetA
else.if not empty then
SetA=Cons(array([]))
else
SetA=(,)
End if
k=each(SetA)
variant z
while k
z=Array(k)
if type$(z)="tuple" then
if len(Array(k))=0 then
data "∅"
else.if type$(z, 0)="tuple" then
data "{∅}"
else
data "{"+(Array(k)#str$(", "))+"}"
end if
else
data z
end if
end while
if len(SetA)=0 then
="∅"
else
="{"+Array([])#Str$(", ")+"}"
end if
}
Function PowerSet {
if match("A") then
read SetA
else.if not empty then
SetA=Cons(array([]))
else
SetA=(,)
End if
a$=string$("0",Len(SetA))
p=lambda a$ -> {
boolean ok
if len(a$)=0 then ="": exit
for i=1 to len(A$)
if mid$(a$,i,1)="0" then insert i,1 a$="1": ok=true : exit else insert i,1 a$="0"
next
if ok then =a$ else =""
}
if Len(setA)>1 then
setAll=("{}",)
else
setAll=((,),)
end if
do
z=p()
if len(z)=0 then exit
SetB=(,)
for i=1 to len(z)
if mid$(z, i,1)="1" then
SetB=SetB#end(SetA#Slice(i-1, i-1))
end if
next
Append setAll, (SetB,)
always
=setAll
}
open dir$+"powerset.txt" for wide output as #f
Print #f, "P(";ToStringSet();")=";ToStringSet(PowerSet())
Print #f, "P(";ToStringSet(PowerSet());")=";ToStringSet(PowerSet(PowerSet()))
Print #f, "P(";ToStringSet(1,2,3,4);")=";ToStringSet(PowerSet(1,2,3,4))
Print #f, "P(";ToStringSet("A", "B");")=";ToStringSet(PowerSet("A", "B"))
close #f
win notepad.exe, dir$+"powerset.txt"

View file

@ -0,0 +1,15 @@
$ENTRY Go {
= <Prout '[A B C D]:' <Powerset A B C D>>
<Prout '[]:' <Powerset>>
<Prout '[()]:' <Powerset ()>>;
};
Powerset {
= ();
e.X t.I, <Powerset e.X>: e.F = e.F <Append t.I e.F>;
};
Append {
t.I = ;
t.I (e.X) e.Y = (e.X t.I) <Append t.I e.Y>;
};