As much as I'd like encourage everyone to Try it Online, text output is just painful.
According to the docs it uses the "Turing Text Model". While an... interesting concept, using it is about as much fun as shooting yourself in the foot. And what do we do with a task like this? Automate it.
The Turing Text Model
The characters INTERCAL knows are printed on a circular tape that can only be moved in the positive direction. Printing is done by passing tape head movement commands in an array to the
READ OUT statement.
Every ASCII character is written on the inside of that tape (The outside has the characters for the input on it, duh). This results in the characters' bytes being on the tape in reverse. Also the tape head moves backwards along the character list, because its positioning is based on the outside of the tape.
The head starts at position 0.
Now the magic starts. I'll be using Truttle1's explanation on how to achieve output.
- Set up an array with the output length.
- Fill the entries in the array with tape head movement values.
- Find the current character's ASCII value in binary
- Reverse it and convert back a number
nfrom the current head postion and modulo by 256 if needed, resulting in a value
ris the value you need to store in the array
- The head is now at position
DO READ OUTthe array.
- Array is pre-initialized with
0, first index is
- INTERCAL uses extended 8-bit ASCII characters, hence the tape length of 256.
- Between 1/3rd and 1/5th of all lines have to start with
PLEASE. Note that in that case you drop the
READ OUT, but not for anything else, as seen in the examples.
Given an input string, output a valid INTERCAL program that prints that string and terminates.
DO ,1 <- #4 DO ,1 SUB #1 <- #190 DO ,1 SUB #2 <- #152 PLEASE DO ,1 SUB #3 <- #336 DO READ OUT ,1 PLEASE GIVE UP
Whitespace is optional. The following prints "FIZZ"
(Examples shamelessly stolen from Truttle1's FizzBuzz program from the video.)
You can find an ungolfed reference implementation in python 3 here
- No standard loopholes
- This is code-golf, shortest code wins.
- You can expect input >= 1, ASCII characters only.
- The program may not throw any errors apart from
ICL774I RANDOM COMPILER BUGand
ICL666I COMPILER HAS INDIGESTION. First one happens at random, second one is C-Intercal running out of memory and circumventing that isn't part of the challenge