Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,29 @@
(define (set-cons a A)
(make-set (cons a A)))
(define (power-set e)
(cond ((null? e)
(make-set (list ∅)))
(else (let [(ps (power-set (cdr e)))]
(make-set
(append ps (map set-cons (circular-list (car e)) ps)))))))
(define B (make-set ' ( 🍎 🍇 🎂 🎄 )))
(power-set B)
→ { ∅ { 🍇 } { 🍇 🍎 } { 🍇 🍎 🎂 } { 🍇 🍎 🎂 🎄 } { 🍇 🍎 🎄 } { 🍇 🎂 } { 🍇 🎂 🎄 }
{ 🍇 🎄 } { 🍎 } { 🍎 🎂 } { 🍎 🎂 🎄 } { 🍎 🎄 } { 🎂 } { 🎂 🎄 } { 🎄 } }
;; The Von Neumann universe
(define V0 (power-set null)) ;; null and ∅ are the same
→ { ∅ }
(define V1 (power-set V0))
→ { ∅ { ∅ } }
(define V2 (power-set V1))
→ { ∅ { ∅ } { ∅ { ∅ } } { { ∅ } } }
(define V3 (power-set V2))
→ { ∅ { ∅ } { ∅ { ∅ } } …🔃 )
(length V3) → 16
(define V4 (power-set V3))
(length V4) → 65536
;; length V5 = 2^65536 : out of bounds

View file

@ -0,0 +1 @@
def powerset( s ) = s.subsets().toSet()

View file

@ -0,0 +1,5 @@
def
powerset( {} ) = {{}}
powerset( s ) =
acc = powerset( s.tail() )
acc + map( x -> {s.head()} + x, acc )

View file

@ -0,0 +1,5 @@
import lists.foldr
def powerset( s ) = foldr( \x, acc -> acc + map( a -> {x} + a, acc), {{}}, s )
println( powerset({1, 2, 3, 4}) )

View file

@ -0,0 +1,19 @@
import sets, hashes
proc hash(x): THash =
var h = 0
for i in x: h = h !& hash(i)
result = !$h
proc powerset[T](inset: HashSet[T]): auto =
result = toSet([initSet[T]()])
for i in inset:
var tmp = result
for j in result:
var k = j
k.incl(i)
tmp.incl(k)
result = tmp
echo powerset(toSet([1,2,3,4]))

View file

@ -0,0 +1,4 @@
var arr = %w(a b c)
for i in (0 .. arr.len) {
say arr.combinations(i)
}

View file

@ -0,0 +1,3 @@
def powerset:
reduce .[] as $i ([[]];
reduce .[] as $r (.; . + [$r + [$i]]));

View file

@ -0,0 +1,7 @@
# The power set of the empty set:
[] | powerset
# => [[]]
# The power set of the set which contains only the empty set:
[ [] ] | powerset
# => [[],[[]]]

View file

@ -0,0 +1,6 @@
def powerset:
if length == 0 then [[]]
else .[0] as $first
| (.[1:] | powerset)
| map([$first] + . ) + .
end;