Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

29
Task/Set/Ada/set.adb Normal file
View file

@ -0,0 +1,29 @@
with ada.containers.ordered_sets, ada.text_io;
use ada.text_io;
procedure set_demo is
package cs is new ada.containers.ordered_sets (character); use cs;
function "+" (s : string) return set is
(if s = "" then empty_set else Union(+ s(s'first..s'last - 1), To_Set (s(s'last))));
function "-" (s : Set) return string is
(if s = empty_set then "" else - (s - To_Set (s.last_element)) & s.last_element);
s1, s2 : set;
begin
loop
put ("s1= ");
s1 := + get_line;
exit when s1 = +"Quit!";
put ("s2= ");
s2 := + get_line;
Put_Line("Sets [" & (-s1) & "], [" & (-s2) & "] of size"
& S1.Length'img & " and" & s2.Length'img & ".");
Put_Line("Intersection: [" & (-(Intersection(S1, S2))) & "],");
Put_Line("Union: [" & (-(Union(s1, s2))) & "],");
Put_Line("Difference: [" & (-(Difference(s1, s2))) & "],");
Put_Line("Symmetric Diff: [" & (-(s1 xor s2)) & "],");
Put_Line("Subset: " & Boolean'Image(s1.Is_Subset(s2))
& ", Equal: " & Boolean'Image(s1 = s2) & ".");
end loop;
end set_demo;

32
Task/Set/Crystal/set.cr Normal file
View file

@ -0,0 +1,32 @@
# Several ways to create a set:
s1 = [1, 2, 3, 4].to_set
s2 = Set{3, 4, 5, 6}
s3 = Set.new [1, 2, 3, 4]
# To create an empty set, the type of its elements needs to be specified:
s4 = Set(Int32).new
p! s1, s2, s3
puts "\nTest inclusion:"
p! 2.in?(s1),
s1.includes?(5)
puts "\nUnion:"
p! s1 + s2
puts "\nIntersection:"
p! s1 & s2
puts "\nDifference (symmetric):"
p! s1 - s2, s1 ^ s2
puts "\nSubset (proper):"
p! s1.subset_of?(s3),
s1.proper_subset_of?(s3)
puts "\nEquality:"
p! s1 == s2, s1 == s3
puts "\nAdd element:"
p! s1, s1.add(5), s1

20
Task/Set/Gleam/set.gleam Normal file
View file

@ -0,0 +1,20 @@
import gleam/set
pub fn main() {
let s = set.new()
let sa = set.insert(s, "a")
let sab = set.from_list(["a", "b"])
echo set.contains(sa, "a")
let union = set.union(sa, sab)
let union_list = set.to_list(union)
echo union_list
let intersection = set.intersection(sa, sab)
let intersection_list = set.to_list(intersection)
echo intersection_list
let subtract = set.difference(sab, sa)
let subtract_list = set.to_list(subtract)
echo subtract_list
let is_subset = set.is_subset(sa, sab)
echo is_subset
echo sa == sab
}

View file

@ -0,0 +1,17 @@
[System.Collections.Generic.HashSet[object]]$set1 = 1..4
[System.Collections.Generic.HashSet[object]]$set2 = 3..6
# Operation + Definition + Result
#--------------------------------+---------------------+-------------------------
$set1.UnionWith($set2) # Union $set1 = 1, 2, 3, 4, 5, 6
$set1.IntersectWith($set2) # Intersection $set1 = 3, 4
$set1.ExceptWith($set2) # Difference $set1 = 1, 2
$set1.SymmetricExceptWith($set2) # Symmetric difference $set1 = 1, 2, 6, 5
$set1.IsSupersetOf($set2) # Test superset False
$set1.IsSubsetOf($set2) # Test subset False
$set1.Equals($set2) # Test equality False
$set1.IsProperSupersetOf($set2) # Test proper superset False
$set1.IsProperSubsetOf($set2) # Test proper subset False
5 -in $set1 # Test membership False
7 -notin $set1 # Test non-membership True