Now is the time to show off your abilities to write bad code. I am trying out a new sort of programming puzzle, most similar, I think, to the underhanded C contest. The main difference is that this is not nearly as nefarious: it's just some good clean fun. The goal of the puzzle is to pack as many bugs as you can into a program. The winner of this contest is the one who writes the program with the most bugs per character.
To avoid a huge thread of comments asking for clarification, I should define right now what I consider to be qualifying bugs.
First, a bug is not an error. If it is a problem that can be detected by the interpreter as an error (e.g. mismatched delimeters, badly-formed syntax, acessing a property of a null object, etc.) or if it prevents the program from executing or continuing, it is not a bug. Otherwise, you could type in four characters and the interpreter could list eight syntax errors and you could claim a bug-character ratio of 2.
Second, the bug must not be obviously wrong and a bug is not an easter egg. This is certainly a subjective criterion, but I think essential to this sort of contest. This means that you cannot have conditional code that specifically mangles the code in obvious ways. (Read: use a turing pit language, because nobody will know the difference).
Third, the bug must be plausible. This is subjective, like the one above, but the bug must look like it could have been written by a less-than-meticulous or perhaps ignorant person, or someone who just made a mistake. This includes, for example, off-by-one errors or syntax that is valid and looks correct but causes undesired behavior (say, using square brackets instead of parentheses).
The bug can cause any sort of undesired behavior to the program, including, but certainly not limited to, undesired output for some exceptional cases, have different behavior based on something that is seemingly unrelated (e.g. output displays differently depending on whether the current time ends with an odd or even number of seconds), memory leaks, loss of data, and so on.
Make a program that displays all of the ASCII characters in ascending order of their numerical value.
Brainf***, 5 chars, 1 bug, 0.2 bug-char ratio
Bug: does not display the ASCII character for 1. Could be fixed by changing to
Ok, I think you should mostly have gotten it by now, here is your puzzle:
Decode a Caesar Cipher and Sort the Words Alphabetically
A caesar cipher is created by taking a series of letters and shifting them n letters over in the alphabet. If it goes all the way to the beginning or end of the alphabet, A comes after Z, and Z comes before A. For example:
Mannequin Nboofrvjo //Shifted over 1 or -25 Wkxxoaesx //Shifted over 10 -16 Ftggxjnbg //Shifted over -7 or 19
You will be given two inputs (you can get input however is most convenient for you, within reason). The first input is the words, and the second input is the value it is shifted over. Your task is to output the decoded words, and then output the decoded words after they have been sorted alphabetically.
Example (no offense to bad boys, it's just an example):
First input: gtdx wjbfwiji. ljy Gfi hfssty
Second input: 5
First output: boys rewarded. get Bad cannot
Second output: Bad boys cannot get rewarded.