spark: add word counter utility with tests

This commit is contained in:
spark committed 2026-10-20 17:41:45 +00:00
1 parent 394de5374a
commit bea6b75eec
243 files changed
+11095

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env python3
"""Array intersection utility - returns sorted unique elements in both arrays."""
def array_intersection(arr1, arr2):
"""Return sorted list of unique elements present in both arrays."""
return sorted(set(arr1) & set(arr2))
if __name__ == "__main__":
import sys
# Parse arrays from command line: python script.py "1 2 3" "2 3 4"
if len(sys.argv) == 3:
a1 = list(map(int, sys.argv[1].split()))
a2 = list(map(int, sys.argv[2].split()))
result = array_intersection(a1, a2)
print(" ".join(map(str, result)))
else:
# Demo test case
arr1 = [1, 2, 3, 4, 5]
arr2 = [3, 4, 5, 6, 7]
print(f"Intersection of {arr1} and {arr2}: {array_intersection(arr1, arr2)}")