5
\$\begingroup\$

Inspired by this question, I wrote a program in Whitespace to output the following text:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~~+~
+~++~++~++~++~++~++~++~++~++~++~++~++~++~++~++~+     
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I left comments in the source code to state what the program does, if I understand the instructions correctly, but I will state the essential parts here as well:

IMP           Meaning
[Space]       Stack Manipulation
[Tab][Space]  Arithmetic
[Tab][Tab]    Heap access
[LF]          Flow Control
[Tab][LF]     I/O

The program stars with a space, signified with S, to start a stack manipulation statement. After the space, I enter the value of a Tilde (126) in binary, with spaces representing 0 and tabs representing 1. Then, I enter a linefeed (L) to signal the end of the binary character.

Next comes a TL to being an I/O command, followed by SS to output the value at the top of the stack.

This continues on, with the three characters '~', '+', and L (newline). Is there any way to simplify this either externally or internally? You can run this program on Ideone.

S S S T T   T   T   T   T   S L---BEGINS-WITH-SPACE-TO-SIGNIFY-STACK-MANIPULATION-OTHER-VALUES-ARE-BINARY-CODE-FOR-126
T   L---BEGIN-OUTPUT-COMMAND
S S S S S T T   T   T   T   T   S L---BELOW-HERE-LINES-NEED-SS-AT-BEGINNING-TO-OUTPUT-VALUE-AT-TOP-OF-STACK
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L---END-OF-FIRST-LINE
S S S S S T S T S L---NEW-LINE(BINARY-CODE-10)
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L---BINARY-CODE-43-FOR-PLUS
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L---END-OF-SECOND-LINE
S S S S S T S T S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S S T   S T S T T   L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S S T   S T S T T   L
T   L---END-OF-THIRD-LINE
S S S S S T S T S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L
S S S S S T T   T   T   T   T   S L
T   L---END-OF-FOURTH-LINE
S S S S S T S T S L
T   L---EXTRA-NEW-LINE-TO-PUSH-END-OF-PROGRAM-OUTPUT-DOWN
S S L---TRIPLE-LINEFEED-TO-END-PROGRAM
L
L
\$\endgroup\$
7
\$\begingroup\$

I know nothing of whitespace, but your code strikes me as something like this:

...
Console.Write("+");
Console.Write("~");
Console.Write("+");
Console.Write("+");
Console.Write("~");
Console.Write("+");
Console.Write("+");
Console.Write("~");
Console.Write("+");
Console.Write("+");
...

You have a heap, and you're not using it.

Heap access commands look at the stack to find the address of items to be stored or retrieved. To store an item, push the address then the value and run the store command. To retrieve an item, push the address and run the retrieve command, which will place the value stored in the location at the top of the stack.

http://compsoc.dur.ac.uk/whitespace/tutorial.html

I'm not going to test this, but the idea would be something like this:

  • Push 126 ("~") to heap at address A // tilde
  • Push 43 ("+") to heap at address B // plus

Now, SpaceSpace marks a label, TabTab would be a modulo operation, and TabSpace jumps to a label if the value at the top of the stack is zero: you can implement a form of conditional goto loop. And you can call a subroutine with SpaceTab, and return to caller with TabLF.

Make a subroutine that pushes the value at address A ("~") to the stack, and outputs it before discarding (LFLF) the value at the top of the stack, and then make another subroutine that does the same thing for address B ("-"). Or better, make one that pops an address from the stack, reads the heap value at that address and pushes it to the stack, outputs it and removes it from the stack, then returns to caller. For the purpose of this post let's call this subroutine PrintChar.

Now, break down the patterns:

  • ~~~~ // pattern A
  • ~+~~ // pattern B
  • +~++ // pattern C

Make a subroutine that pushes address A ("~") onto the stack from the heap and calls PrintChar, 4 times. Or better, store 4 on the heap at address C and implement a goto loop that exits after 4 iterations, and inside that loop you push address A onto the stack from the heap and call PrintChar, once; let's call that subroutine PatternA. Then, implement similar subroutines for PatternB and PatternC.

The rest is simple: make a subroutine that pops the address of a pattern subroutine from the stack, makes 12 iterations of calling that pattern subroutine and then outputs a newline - let's call that PrintLine.

The "main" procedure simply pushes a pattern to the stack and calls PrintLine:

  • Push the address of PatternA to the stack
  • Call PrintLine
  • Push the address of PatternB to the stack
  • Call PrintLine
  • Push the address of PatternC to the stack
  • Call PrintLine
  • Push the address of PatternA to the stack
  • Call PrintLine

And don't forget to comment along the way - I find your commenting not very useful here.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.