A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Reverse String in Unicat page! Here, you'll find the source code for this program as well as a description of how the program works.
# Find end of input by finding null-termination
0o00 πΊπΌπΉπΊππ Memory 10 (0o12) through N+11 = input (N characters), newline, null
0o01 π»πΉπΈπππΉπΊππ Memory 0 = 0o12 (10 = '\n')
0o02 π»πΉπΉπππΉπΊππ Memory 1 = 0o12 (10, input pointer)
0o03 π»πΉπΊπππΉππ Memory 2 = 1
0o04 π»πΉπ»πππΈππ Memory 3 = 0
0o05 πΏππΈπ»πππΉππ Memory 3 += Memory 1 (input pointer)
0o06 πΌπΎπ»ππ Memory 3 = pointer(Memory 3) (contents of input pointer)
0o07 π½πΏπ»πππΉπΈππ If Memory 3 > 0, jump to 0o11 (0o10 + 1)
0o10 π»πΉπΉππΏπΉπΊππ Jump to 0o13 (0o12 + 1)
0o11 πΏππΈπΉπππΊππ Memory 1 += Memory 2 (1) (increment input pointer)
0o12 π»πΉπΉππΏπ»ππ Jump to 0o04 (0o03 + 1)
# Null-terminate before input
0o13 π»πΉπΉπΉπππΈπΈππ Memory 9 (0o11) = 0
# Strip trailing newline (if present)
0o14 π»πΉπ»πππΉππΏ Memory 3 = -1
0o15 πΏππΈπ»πππΉππ Memory 3 += Memory 1 (input pointer - 1, previous character)
0o16 πΌπΎπ»ππ Memory 3 = pointer(Memory 3) (previous character)
0o17 πΏππΊπ»πππΈππ Memory 3 -= Memory 0 (contents of input pointer - '\n')
0o20 π½πΏπ»πππΊπΌππ If Memory 3 > 0, jump to 0o25 (0o24 + 1) (if contents of input pointer > '\n')
0o21 π»πΉπΌπππΉππΏ Memory 4 = -1
0o22 πΏπππ»πππΌππ Memory 3 *= Memory 4
0o23 π½πΏπ»πππΊπΌππ If Memory 3 > 0, jump to 0o25 (0o24 + 1) (if '\n' > contents of input pointer)
0o24 πΏππΊπΉπππΊππ Memory 1 -= Memory 2 (1) (decrement input pointer)
# Output reversed string starting before newline (if present) until beginning
# null-termination is found, then output a newline
0o25 πΏππΊπΉπππΊππ Memory 1 -= Memory 2 (1) (decrement input pointer)
0o26 π»πΉπ»πππΈππ Memory 3 = 0
0o27 πΏππΈπ»πππΉππ Memory 3 += Memory 1 (input pointer)
0o30 πΌπΎπ»ππ Memory 3 = pointer(Memory 3) (contents of input pointer)
0o31 π½πΏπ»πππ»π»ππ If Memory 3 > 0, jump to 0o34 (0o33 + 1)
0o32 π½πΌπΈππ Output Memory 0 ('\n')
0o33 ππ Exit
0o34 π½πΌπ»ππ Output Memory 3 (contents of input pointer)
0o35 π»πΉπΉππΏπΊπΌππ Jump to 0o25 (0o24 + 1)
Reverse String in Unicat was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.