Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,6 +1,6 @@
|
|||
A [[set]] is a collection (container) of certain values, without any particular order, and no repeated values. It corresponds with a finite set in mathematics. A set can be implemented as an associative array (partial mapping) in which the value of each key-value pair is ignored.
|
||||
|
||||
Given a set S, the [[wp:Power_set|power set]] (or powerset) of S, written P(S), or 2<sup>S</sup>, is the set of all subsets of S.<br>
|
||||
'''Task : ''' By using a library or build-in set type, or defining a set type with necessary operations, write a function with a set S as input that yields a power set 2<sup>S</sup> of S.
|
||||
'''Task : ''' By using a library or built-in set type, or by defining a set type with necessary operations, write a function with a set S as input that yields the power set 2<sup>S</sup> of S.
|
||||
|
||||
For example, the power set of {1,2,3,4} is {{}, {1}, {2}, {1,2}, {3}, {1,3}, {2,3}, {1,2,3}, {4}, {1,4}, {2,4}, {1,2,4}, {3,4}, {1,3,4}, {2,3,4}, {1,2,3,4}}.
|
||||
|
|
|
|||
10
Task/Power-set/Bracmat/power-set.bracmat
Normal file
10
Task/Power-set/Bracmat/power-set.bracmat
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
( ( powerset
|
||||
= done todo first
|
||||
. !arg:(?done.?todo)
|
||||
& ( !todo:%?first ?todo
|
||||
& (powerset$(!done !first.!todo),powerset$(!done.!todo))
|
||||
| !done
|
||||
)
|
||||
)
|
||||
& out$(powerset$(.1 2 3 4))
|
||||
);
|
||||
5
Task/Power-set/Common-Lisp/power-set-4.lisp
Normal file
5
Task/Power-set/Common-Lisp/power-set-4.lisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun power-set (list)
|
||||
(let ((pow-set (list nil)))
|
||||
(dolist (element (reverse list) pow-set)
|
||||
(dolist (set pow-set)
|
||||
(push (cons element set) pow-set)))))
|
||||
10
Task/Power-set/Deja-Vu/power-set.djv
Normal file
10
Task/Power-set/Deja-Vu/power-set.djv
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
powerset s:
|
||||
local :out [ set{ } ]
|
||||
for value in keys s:
|
||||
for subset in copy out:
|
||||
local :subset+1 copy subset
|
||||
set-to subset+1 value true
|
||||
push-to out subset+1
|
||||
out
|
||||
|
||||
!. powerset set{ 1 2 3 4 }
|
||||
|
|
@ -10,7 +10,7 @@ import (
|
|||
// element is an interface, allowing different kinds of elements to be
|
||||
// implemented and stored in sets.
|
||||
type element interface {
|
||||
// an element must be disinguishable from other elements to satisfy
|
||||
// an element must be distinguishable from other elements to satisfy
|
||||
// the mathematical definition of a set. a.eq(b) must give the same
|
||||
// result as b.eq(a).
|
||||
eq(element) bool
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ public static ArrayList<String> getpowerset(int a[],int n,ArrayList<String> ps)
|
|||
if(n==0)
|
||||
{
|
||||
if(ps==null)
|
||||
ps=new ArrayList();
|
||||
ps=new ArrayList<String>();
|
||||
ps.add(" ");
|
||||
return ps;
|
||||
}
|
||||
|
|
|
|||
7
Task/Power-set/Julia/power-set.julia
Normal file
7
Task/Power-set/Julia/power-set.julia
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function powerset (x)
|
||||
result = {{}}
|
||||
for i in x, j = 1:length(result)
|
||||
push!(result, [result[j],i])
|
||||
end
|
||||
result
|
||||
end
|
||||
8
Task/Power-set/OPL/power-set-1.opl
Normal file
8
Task/Power-set/OPL/power-set-1.opl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{string} s={"A","B","C","D"};
|
||||
range r=1.. ftoi(pow(2,card(s)));
|
||||
{string} s2 [k in r] = {i | i in s: ((k div (ftoi(pow(2,(ord(s,i))))) mod 2) == 1)};
|
||||
|
||||
execute
|
||||
{
|
||||
writeln(s2);
|
||||
}
|
||||
3
Task/Power-set/OPL/power-set-2.opl
Normal file
3
Task/Power-set/OPL/power-set-2.opl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[{} {"A"} {"B"} {"A" "B"} {"C"} {"A" "C"} {"B" "C"} {"A" "B" "C"} {"D"} {"A"
|
||||
"D"} {"B" "D"} {"A" "B" "D"} {"C" "D"} {"A" "C" "D"} {"B" "C" "D"}
|
||||
{"A" "B" "C" "D"}]
|
||||
66
Task/Power-set/PL-I/power-set.pli
Normal file
66
Task/Power-set/PL-I/power-set.pli
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
*process source attributes xref or(!);
|
||||
/*--------------------------------------------------------------------
|
||||
* 06.01.2014 Walter Pachl translated from REXX
|
||||
*-------------------------------------------------------------------*/
|
||||
powerset: Proc Options(main);
|
||||
Dcl (hbound,index,left,substr) Builtin;
|
||||
Dcl sysprint Print;
|
||||
Dcl s(4) Char(5) Var Init('one','two','three','four');
|
||||
Dcl ps Char(1000) Var;
|
||||
Dcl (n,chunk,p) Bin Fixed(31);
|
||||
n=hbound(s); /* number of items in the list. */
|
||||
ps='{} '; /* start with a null power set. */
|
||||
Do chunk=1 To n; /* loop through the ... . */
|
||||
ps=ps!!combn(chunk); /* a CHUNK at a time. */
|
||||
End;
|
||||
Do While(ps>'');
|
||||
p=index(ps,' ');
|
||||
Put Edit(left(ps,p-1))(Skip,a);
|
||||
ps=substr(ps,p+1);
|
||||
End;
|
||||
|
||||
combn: Proc(y) Returns(Char(1000) Var);
|
||||
/*--------------------------------------------------------------------
|
||||
* returns the list of subsets with y elements of set s
|
||||
*-------------------------------------------------------------------*/
|
||||
Dcl (y,base,bbase,ym,p,j,d,u) Bin Fixed(31);
|
||||
Dcl (z,l) Char(1000) Var Init('');
|
||||
Dcl a(20) Bin Fixed(31) Init((20)0);
|
||||
Dcl i Bin Fixed(31);
|
||||
base=hbound(s)+1;
|
||||
bbase=base-y;
|
||||
ym=y-1;
|
||||
Do p=1 To y;
|
||||
a(p)=p;
|
||||
End;
|
||||
Do j=1 By 1;
|
||||
l='';
|
||||
Do d=1 To y;
|
||||
u=a(d);
|
||||
l=l!!','!!s(u);
|
||||
End;
|
||||
z=z!!'{'!!substr(l,2)!!'} ';
|
||||
a(y)=a(y)+1;
|
||||
If a(y)=base Then
|
||||
If combu(ym) Then
|
||||
Leave;
|
||||
End;
|
||||
/* Put Edit('combn',y,z)(Skip,a,f(2),x(1),a); */
|
||||
Return(z);
|
||||
|
||||
combu: Proc(d) Recursive Returns(Bin Fixed(31));
|
||||
Dcl (d,u) Bin Fixed(31);
|
||||
If d=0 Then
|
||||
Return(1);
|
||||
p=a(d);
|
||||
Do u=d To y;
|
||||
a(u)=p+1;
|
||||
If a(u)=bbase+u Then
|
||||
Return(combu(u-1));
|
||||
p=a(u);
|
||||
End;
|
||||
Return(0);
|
||||
End;
|
||||
End;
|
||||
|
||||
End;
|
||||
Loading…
Add table
Add a link
Reference in a new issue