Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Subleq/Jq/subleq-1.jq
Normal file
32
Task/Subleq/Jq/subleq-1.jq
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# If your jq has while/2 then the following definition can be omitted:
|
||||
def while(cond; update):
|
||||
def _while: if cond then ., (update | _while) else empty end;
|
||||
_while;
|
||||
|
||||
# subleq(a) runs the program, a, an array of integers.
|
||||
# Input: the data
|
||||
# When the subleq OSIC is about to emit a NUL character, it stops instead.
|
||||
def subleq(a):
|
||||
. as $input
|
||||
# state: [i, indexIntoInput, a, output]
|
||||
| [0, 0, a]
|
||||
| while( .[0] >= 0 and .[3] != 0 ;
|
||||
.[0] as $i
|
||||
| .[1] as $ix
|
||||
| .[2] as $a
|
||||
| if $a[$i] == -1 then
|
||||
if $input and $ix < ($input|length)
|
||||
then [$i+3, $ix + 1, ($a[$a[$i + 1]] = $input[$ix]), null]
|
||||
else [-1]
|
||||
end
|
||||
elif $a[$i + 1] == -1 then [$i+3, $ix, $a, $a[$a[$i]]]
|
||||
else
|
||||
[$i, $ix, ($a | .[.[$i + 1]] -= .[.[$i]]), null]
|
||||
| .[2] as $a
|
||||
| if $a[$a[$i+1]] <= 0 then .[0] = $a[$i + 2] else . end
|
||||
| .[0] += 3
|
||||
end )
|
||||
| .[3] | select(.) | [.] | implode;
|
||||
|
||||
subleq([15, 17, -1, 17, -1, -1, 16, 1, -1, 16, 3, -1, 15, 15, 0, 0, -1,
|
||||
72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0])
|
||||
2
Task/Subleq/Jq/subleq-2.jq
Normal file
2
Task/Subleq/Jq/subleq-2.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -r -j -n -f subleq.jq
|
||||
Hello, world!
|
||||
Loading…
Add table
Add a link
Reference in a new issue