Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

20
Task/Stack/Jq/stack-1.jq Normal file
View file

@ -0,0 +1,20 @@
# create a Stack
def Stack: {stack: []};
# check an object is a Stack
def isStack:
type == "object" and has("stack") and (.stack|type) == "array";
def pop:
if .stack|length == 0 then "pop: stack is empty" | error
else {stack: .stack[1:], item: .stack[0]]
end;
def push($x):
.stack = [$x] + .stack | .item = null;
def size:
.stack | length;
def isEmpty:
size == 0;

1
Task/Stack/Jq/stack-2.jq Normal file
View file

@ -0,0 +1 @@
Stack | push(3) | pop | .item

4
Task/Stack/Jq/stack-3.jq Normal file
View file

@ -0,0 +1,4 @@
Stack
| size, (push(3)
| size, (pop
| size, .item ))

5
Task/Stack/Jq/stack-4.jq Normal file
View file

@ -0,0 +1,5 @@
null
| observe(Stack; size)
| observe(push(3); size)
| observe(pop; size)
| .emit, item

12
Task/Stack/Jq/stack-5.jq Normal file
View file

@ -0,0 +1,12 @@
# Input: an object
# Output: the updated object with .emit filled in from `update|emit`.
# `emit` may produce a stream of values, which need not be strings.
def observe(update; emit):
def s(stream): reduce stream as $_ (null;
if $_ == null then .
elif . == null then "\($_)"
else . + "\n\($_)"
end);
.emit as $x
| update
| .emit = s($x // null, emit);