# Compiling English for your Boss

Your boss has recently learned of this interesting programming language called English. He has had this "revolutionary" idea, he wants to code with you to double code production rates! Since he is not a tech savvy, he wants you to write a compiler for it so that he can code too!

Now, you are an evil lazy programmer and obviously will not write a program to compile this ridiculously complex language. Instead, you are going to make sure there is always an error in your boss's code, so that he never gets to the actual compilation and is stuck fixing grammar errors instead of coding.

The challenge is to write a program that can be run from the terminal, and accepts a file path as an argument. The program has to:

1. modify the file input by introducing a typo.
2. Pretend to fail compilation due to encountering the typo you introduced.
3. Running the program on copies of the same file should not introduce the same typo twice in a row.

To illustrate the challenge, running your program on this file:

Take an array as input.
Sort the array.
Output the array.


should output something along the lines of

Error on line 1:
'Take an arqay as input.'
^
arqay is not a valid identifier.


and the file that you told the program to compile should now look like:

Take an arqay as input.
Sort the array.
Output the array.


Here are some more details on the specs of the program:

Your program is allowed to assume that swapping any character in the program your boss inputs for a different random character will cause a grammar error. Your program should not use non alphabetical characters to create errors in your bosses code. Your boss would never use a number or symbol, and he would find out that something is afoot. Your program should only introduce errors to the words in your boss's program. Do not change the spaces in the sentences, or the punctuation. Your program should not alter the case of the program your boss tries to compile, meaning errors like arQay are invalid. This prevents errors like take instead of Take happening, or Array instead of array. Your program should output the error by first stating what line the error is at:

Error on line <insert line number here>:


It should then print out the line with the error inside ' symbols. On the next line it should place a ^ symbol under the word with the error, and finally it should have some text describing the error (this part is up to you, you can say whatever you want there as long as it describes an error).

You can assume that the input file exists and it is not empty. You can also assume the input file has no grammatical errors before you add one.

Bonuses:

-60 bytes if the errors your code introduces are not completely random, but typo-based as in this question.

-60 bytes for at least 5 different error messages, randomly alternating.

-60 bytes if your program has a 1 in 100 chance or less to output some demotivational message to your boss.

EDIT: The byte count of the messages do not count towards your score. (Thanks to Martin Büttner for this good idea)

This is code-golf, shortest byte count wins. Please do not golf the error message content, your boss wont be happy if he can't understand the error messages, and will ask you to fix them for him.

• Do I have to deal with lines that don't contain letters? – Οurous Nov 1 '14 at 6:45
• You can only create a typo in alphabet characters, and you can assume the input file is a valid non-empty file that exists. – rodolphito Nov 1 '14 at 7:08
• I'm not a fan of leaving the error messages up to us. Even if we "don't golf the error message" they could still make a difference of a handful of bytes, of probably even two dozen if we're going for the second bonus. That can be quite a lot. I think for a fair golfing contest you should specify 5 error messages and a demotivational message, or let us subtract their string length's from the byte count. – Martin Ender Nov 1 '14 at 11:10
• Thanks for the tip, i had thought about having predefined messages, but i wanted to give a little more freedom with that. Substracting the message byte counts from the score is a great idea. – rodolphito Nov 1 '14 at 19:13

# TI-BASIC, 77 - 34 (error text) = 43

In case he wants to do in on his TI-83/84 calculator ;)

As standard for functions, file string should be in Ans so it can return and display the output.

Ans->Str1:If 1=inString(Ans,"A
Then:"B
Else:"A
End:Disp "ERROR ON LINE 1","'"+Ans+sub(Str1,2,-1+length(Str1))+"'"," ^ INVALID


Note that many tokens are one byte.

• Where could I run this code? – rodolphito Nov 1 '14 at 22:54
• TI-83/84 calculator or an emulator for one. – Timtech Nov 2 '14 at 12:27
• inString, Ans, sub, Else, Then, End, Disp , Str1... Aren't those all 1 byte for the calculator? – Ismael Miguel Nov 2 '14 at 15:30
• WHAT????????????????? That's like saying that 8 bits isn't 1 byte!!!!!!!!! If I present a code in assembly, using binary form, will they also count the bytes as 1 macro of 5+ bytes? That is plainly stupid! (sorry the strong words, but it IS REALLY STUPID!) This doesn't represent your code. I mean Ans isn't the same as the byte represented by Ans. One is A*n*s which produces any result the calculator wants, the other returns the value of the last arithmetic expression. Taking this into account, I think that not accepting the REAL count makes this a wrong representation of the code. – Ismael Miguel Nov 2 '14 at 21:11
• It doesn't seem to randomly modify the file, it looks as if it always displays a change in line 1, and changes the first letter to B if its A, or to A if not. – rodolphito Nov 3 '14 at 4:51