Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
32
Task/Comma-quibbling/Dc/comma-quibbling.dc
Normal file
32
Task/Comma-quibbling/Dc/comma-quibbling.dc
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[(q)uibble: main entry point. print brackets, calling n in between if stack not
|
||||
empty.]sx
|
||||
[ [{]n z 0 !=n [}]pR ]sq
|
||||
|
||||
[(n)onempty: if more than 1 item, call m. then print top of stack.]sx
|
||||
[ z 1 !=m n ]sn
|
||||
|
||||
[(m)ore: call f to flip stack into r register, call p to print most of it,
|
||||
then pop the last item back onto the main stack so it's there to be printed
|
||||
after we return]sx
|
||||
[ lfx lpx Lr ]sm
|
||||
|
||||
[(f)lip: utility routine to reverse the stack into the r register]sx
|
||||
[ Sr z 0 !=f ]sf
|
||||
|
||||
[(p)rint: get next item from stack in r register and print it. If there are
|
||||
more than 2 items left on the register stack (which never drops below one
|
||||
item), print a comma (c) and recurse. If there are exactly two items left,
|
||||
print " and " (a) and return.]sx
|
||||
[ Lr n 2 yr >c 2 yr =a 2 yr >p]sp
|
||||
|
||||
[(c)omma: utility routine to print a comma followed by a space]sx
|
||||
[ [, ]n ]sc
|
||||
|
||||
[(a)and: utility routine to print " and "]sx
|
||||
[ [ and ]n ]sa
|
||||
|
||||
[run tests]sx
|
||||
lqx
|
||||
[ABC] lqx
|
||||
[ABC] [DEF] lqx
|
||||
[ABC] [DEF] [G] [H] lqx
|
||||
Loading…
Add table
Add a link
Reference in a new issue