text:
Create a World Cup guessing program
As you know, the World Cup group stage is over, and from tomorrow the best 16 teams will commence the knockout stage:

Brazil (BRA)
Mexico (MEX)
Netherlands (NED)
Chile (CHI)
Colombia (COL)
Greece (GRE)
Costa Rica (CRC)
Uruguay (URU)
France (FRA)
Switzerland (SUI)
Argentina (ARG)
Nigeria (NGA)
Germany (GER)
United States (USA)
Belgium (BEL)
Algeria (ALG)

In the knockout stage, after each match the winner gets through to the next round, and the loser goes home (there are no draws). Click here to see more about the knockout stage.
You have been hired by golfbet.com, a new betting website because you are known to be good at both programming and sports betting. Your task is to write a program or function which can guess the winner of a match. Of course, everybody makes different guesses, it doesn't matter as long as your guesses are consistent.
If you don't want to guess, you can use the following guesses:
BRA
        BRA
CHI
                BRA
COL
        COL
URU
                        GER
FRA
        FRA
NGA
                GER
GER
        GER
ALG
                                        GER
NED
        NED
MEX
                NED
CRC
        CRC
GRE
                        ARG
ARG
        ARG
SUI
                ARG
BEL
        BEL
USA

The program has to output the same winner regardless the order of the to teams (the winner of the BRA-CHI match has to be the same as of the CHI-BRA match)
If a team loses, it cannot play any more matches. This means for matches that don't take place, you have to indicate so. For example if your program guesses Brazil to win the BRA-CHI match, then CHI-GER has to return "no result", because Chile won't play against Germany. See the link above for schedule.

For the sake of simplicity you don't have to deal with the bronze match (but you can of course).
Your program or function takes two strings as input: the 3-letter country code of the two teams and returns the country code of the winning team (you can use standard input/output, or two function parameters/return value). If the given two teams will not play according to your guesses, you must return something else (this can be anything but the country codes, eg empty string, null, error message). You can assume the input is correct (two different country codes which are in the list).
This is primarily a code-golf, so shortest program in bytes wins. However, nice and tricky solutions are also valuable.
Example (of course, you can make your own guesses):
input:
BRA
CHI
output:
BRA
input:
CHI
BRA
output:
BRA
input:
CHI
GER
output: no result

Should've been an [underhanded] that outputs random guesses, but always let's your favorite team win ;) (As in: outputs a random guess-tree)

@ɐɔıʇǝɥʇuʎs http://codegolf.stackexchange.com/questions/32092/its-not-who-votes-that-counts-its-who-counts-the-votes This one is very similar to that

@ɐɔıʇǝɥʇuʎs, this is far more interesting as is. We're given a space of possible programs, roughly corresponding to hash functions onto a three-element set, and we have to find the smallest program which is equivalent to any program in that space.

Can be assume the input will be valid or would BRA BRA and HAZ CHEEZBURGER have to be handled properly?

@Dennis see my edit — the input is always valid

I agree with your prediction table. Those Germans - football play they better than you.

Python 2.x  - 368 283
Interesting challenge. Of course we need to get present rankings from the FIFA.
Brazil have the so-called "12th man" as they have home advantage therefore the weighting 12/11.
a='BRA CHI COL URU FRA NGA ALG GER MEX NED CRC GRE ARG SUI BEL USA'.split()
d=[1242*12/11,1026,1137,1147,913,640,858,1300,882,981,762,1064,1175,1149,1074,1035]
m={}
for n in[16,8,4,2]:
 j=0
 for k in range(0,n,2):
  s=a[k] if d[k]>d[k+1] else a[k+1]
  m[a[k]+' '+a[k+1]]=s
  a[j]=s
  j+=1
def f(s):
 try: print m[s]
 except: print 'no result'

Tips to shorten the above are welcome :-).
Improvements thanks to @TheRare and @MrLemon
a='BRA CHI COL URU FRA NGA ALG GER MEX NED CRC GRE ARG SUI BEL USA'.split()
d=15,6,10,11,4,0,2,14,3,5,1,8,13,12,9,7
m={}
for n in 16,8,4,2:
 j=0
 for k in range(0,n,2):s=a[k]if d[k]>d[k+1]else a[k+1];m[a[k]+' '+a[k+1]]=s;a[j]=s;j+=1
def f(s):print s in m and m[s]or'no result'

This leads to the following results:
BRA CHI: BRA
COL URU: URU
FRA NGA: FRA
ALG GER: GER
MEX NED: NED
CRC GRE: GRE
ARG SUI: ARG
BEL USA: BEL
------------
BRA URU: BRA
FRA GER: GER
NED GRE: GRE
ARG BEL: ARG
------------
BRA GER: BRA
GRE ARG: ARG
------------
BRA ARG: BRA

Example calls:
f('BRA MEX')
no result
f('BRA CHI')
BRA

You don't use j (it's always zero). 2. for k can be written in one line by using ; delimiter. 3. You don't need space after keywords like try or except 4. You can remove spaces between brackets and keywords (a[k]if d[k]>d[k+1]else a[k+1] is valid) 5. for n in 16,8,4,2 6. def f(s):print s in m and m[s]or'no result'

@TheRare He does use j, but there's a slight formatting error with the j+=1. And you can save lots of characters by reencoding the FIFA data to [15,6,10,11,4,0,2,14,3,5,1,8,13,12,9,7], of course.

@MrLemon Ah, I didn't try the code myself, just looked at it.

C, 182 178 133 (or 126)
Not the shortest program here, but it is the shortest in which the prediction can be changed easily. Now that all the semifinalists are known, I'm updating.
There's some changes to the code, too. Apart from Dennis's suggestions in the comments, the program has been converted to a function (as on re-reading this is allowed by the rules) and the hashing has been shortened.
Code,133
f(char*a,char*b){
  char*p,*t=" HIAEAIH N?=R=?N ;@4S4@; 5BDGDB5 B@?I?@B",h[3]={*a-a[1]%16,*b-b[1]%16};
  (p=strstr(t,h))&&puts(p-t&2?a:b);
}

How it works
the inputs a and b are hashed by the expression *a-a[1]%16 to a single character (*a is a shorter equivalent to a[0]). The hash results for teams a and b are stored in h. For example BRA CHI becomes @;. Hashed values are as follows (the confirmed semifinalists and my predicted champion are marked with *.)
GRE E   CRC A   *NED I   MEX H
USA R   BEL =   *ARG ?   SUI N
URU S   COL 4  **BRA @   CHI ;
NGA G   FRA D   *GER B   ALG 5

t[] stores my predictions. The results of the round of 16 and quarter finals are now known. Each group of 4 teams is ordered such that the 1st and 4th were eliminated, and the 3rd is the semifinalist. Similarly of the semifinalists, I'm predicting that the 1st and 4th will be eliminated and the 3rd semifinalist will be the overall winner. If you disagree with my predictions, simply reorder the table.
The predictions are stored in palindromic blocks to accommodate the possibility of the user entering the teams in either possible order. The ordering puts the winning teams of each set of 4 together to play a third match. Thus in the first group GREE lost to CRC and MEXH lost to NED. This sets up CRCA to play NEDI in the quarter final without having to repeat the typing. The string is padded with a space between each group of 4 teams / 7 characters to help ensure there is no output for teams that will not play each other.
The winner of each possible match in each group of 8 characters is as follows: invalid,b,a,a,b,b,a,invalid. Thus the correct choice of winner can be made by taking the position of h in t AND 2. Unfortunately the strstr function is not the most straighforward as it returns a pointer p, so we must subtract p from t to get the actual position in t. If the match is invalid (cannot be found in t), p is zero and the phrase no result is printed.
Some dubious improvements, 126
2 characters saved by an improved hash expression. Unfortunately, this requires the case of the teams to be as shown in the test program below the function (eg Bra instead of BRA as used in the program above.) I've satisfied myself that there is no way of doing this with a single operator, so 2 operators and a single-character constant is as good as it gets. Note also that Uru maps to space so an alternate character | is needed to separate the groups of teamcodes.
5 characters saved by eliminating t and treating the prediction string as a literal. This means it is impossible to know the address where the string is stored. However, provided it is not stored at zero, we are only interested in p&2 so the code will work if the address is divisible by 4. (Note that it is not allowed to treat pointer p directly as an integer, it must be subtracted from another pointer. I use the pointer a so a must also be divisible by 4.) One can be fairly confident on a 32 or 64 bit compiler/architecture strings will be stored in this way. This has been working fine for me on GCC/cygwin, though it refuses to compile on visual studio / windows.
g(char*a,char*b){
  char*p,h[3]={*a^a[1]+3,*b^b[1]+3};
  (p=strstr("|%&626&%|+4*#*4+|(71 17(|./3$3/.|/74&47/",h))&&puts(p-a&2?a:b);
}

main(){
  char team[16][4]={"Gre","Crc","Ned","Mex", "Usa","Bel","Arg","Sui", "Uru","Col","Bra","Chi", "Nga","Fra","Ger","Alg"};
  int i;
  for(i=1;i<16;i++){printf("%s %s \n",team[i-1],team[i]);g(team[i],team[i-1]);g(team[i-1],team[i]);}
}

Interesting approach! You can save a few bytes by removing the space between char and *p and replacing a[0], b[0] and h[0] with *a, *band*h. Also, the question says that *if the given two teams will not play according to your guesses, you must return something else (this can be anything but the country codes, eg empty string, null, error message)*, so printing **no result** is not required and you could replace puts(...)with(p=strstr(t,h))&&puts(p-t&2?a:b)`.

Thanks for the tips, especially a[0]->*a! Will update soon. Just wondering, is there any way to access a multidimensional array with a single number? I wrote this command line version of identical length (can save 1 byte with a #define.) It would be nice to avoid the double subscripts in this and similar cases: char *p,h[2],*t="-LgRrRgL bA9j9Ab hp535ph OKYtYKO KpAgApK";main(int c,char**v){h[0]=v[1][1]*3-v[1][0]*2;h[1]=v[2][1]*3-v[2][0]*2;puts((p=strstr(t,h))?v[1+!(p-t&2)]:"no result");}

I found a small bug. h should be null-terminated, so it has to be h[3]. 2. If you set p=v[1], you can access v[i][j] as p[4*(i-1)+j]. It works on my machine, but I don't know if it's portable... 3. You should be able to initialize h if you declare it inside main: main(int c,char**v){char*t="-LgRrRgL bA9j9Ab hp535ph OKYtYKO KpAgApK",*p=v[1],h[3]={p[1]*3-*p*2,p[5]*3-p[4]*2};(p=strstr(t,h))&&puts(v[1+!(p-t&2)]);}

@Dennis your code works fine on both GCC/cygwin and VS/Windows on my machine. Also for(int i=0;i<1000;i++)printf("%d %c    ",i,i[*argv]) echoes back evey printable character of the command line on VS, but on GCC the program name is at 0, the first argument is at 40 and the second argument is nowhere to be seen (i went up to 1000.) Curious. Anyway, I changed to a function which is within the rules, in addition to updating my predictions (I was just waiting for tonight's result to confirm them before posting.)  Thanks again and good luck against Brazil on Tuesday.

JavaScript 215 206 120  116
A lot of room for improvement:
ES5 - 215
a=prompt().split(' ');("BRACHI0COLURU0FRANGA0GERALG0NEDMEX0CRCGRE0ARGSUI0BELUSA0BRACOL0FRAGER0NEDCRC0ARGBEL0BRAGER0NEDARG0BRANED".split(0).filter(function(x){return x.match(a[0])&&x.match(a[1])})[0]||"").substr(0,3)

ES6 - 206
a=prompt().split(' ');("BRACHI0COLURU0FRANGA0GERALG0NEDMEX0CRCGRE0ARGSUI0BELUSA0BRACOL0FRAGER0NEDCRC0ARGBEL0BRAGER0NEDARG0BRANED".split(0).filter((x)=>{return x.match(a[0])&&x.match(a[1])})[0]||"").substr(0,3)

Regex Approach - 116
Thanks to ɐɔıʇǝɥʇuʎs for posting this link, it helped me making the regex
a=prompt().split(' ').sort();a.join('').match(/LG(.R(A|G)|GE)|RG(S|BE|CR)|ELUS|AC(H|O)|OLUR|CGR|CM|FRANG|XNE/)&&a[0]

You can shorten your solutions by converting split(' ') to split\`andjoin('')tojoin```.

Python (179 148 139 c.q. way too long)
f=lambda *l:sorted(l)[0]if"".join(sorted(l))in"BRACHI COLURU FRANGA ALGGER MEXNED CRCGRE ARGSUI BELUSA BRACOL ALGFRA CRCMEX ARGBEL BRAFRA CRCMEX ARGBEL BRAFRA ARGCRC ARGBRA"else 0

Everybody knows the country with the name that comes first in the alphabet is going to win. (This answer just exists to get things started)
Thanks to the charity of the guy(s) over here, I could shorten my answer by a bit:
import re;f=lambda *l:sorted(l)[0]if re.match('RGB|CM|RGS|CGR|L.F|XNE|EL.S|O.UR|RGCR|B.AF|L.GE|^BRACHI$|^FRANGA$|^BRACOL$',"".join(sorted(l)))else 0

This does assume valid teams, but doesn't need a valid line-up (f('BRA','NED') would return 0 (invalid match), but f('XNE') would return 'XNE'. I don't get from your question that this is a problem though. Feel free to re-abuse this regex as you see fit.
Thanks @Ventero, I know nothing about regexes.
import re;f=lambda*l:sorted(l)[0]if re.match('RGB|CM|RGS|CGR|L.F|XNE|EL.S|O.UR|RGCR|B.AF|L.GE|BRACHI|FRANGA|BRACOL',"".join(sorted(l)))else 0

You probably want re.search in the golfed version, not re.match. Also, you should be able to drop the ^ and $ anchors.

Scala (150)
type s=String;var m=Map[s,s]();def f(x:(s,s))={var a=x._1;var b=x._2;if(b<a){b=a;a=x._1};if(m.getOrElse(a,a)=="")m.getOrElse(b,b)else{m=m+(b->"");a}}

Here are matches between "foo" and "bar" possible, also teams wich won't play in real against each other in the first rounds will have a result.(for example starting with BRA,ARG)
It's just recording loosing teams.
type s=String //just aliasing for saving characters
var m=Map[s,s]() //map for storing loosing teams, a set would do too
def f(x:(s,s))={
  var a=x._1 var b=x._2
  if(b<a){b=a;a=x._1};//swap if b<a lexographically
  if(m.getOrElse(a,a)=="")//if a has loosed previously
     m.getOrElse(b,b)// return b if b was not in the map else return ""
  else{
    m=m+(b->"") //add b to the map, because a will definitly win this amazing match
    a //and return a
  }
}

Called with:
f(("GER","BRA"))

PowerShell (261 221)
$a=Read-Host;$b=Read-Host;$x="CHIBRA","URUCOL","FRANGA","ALGGER","MEXNED","CRCGRE","SUIARG","BELUSA";0..($x.Length-2)|%{$x+=$x[2*$_].Substring(3)+$x[2*$_+1].Substring(3)};$x|?{"$a$b","$b$a"-eq$_}|%{$_.Substring(3);exit};0

As a relatively new PowerShell user, I find the pipeline absolutely amazing. I think next up might be to try and fiddle with the array to hopefully eliminate all these substring calls. (I had to add a call at the end or else it outputted both teams)

New member, first attempt at code golf!
Could have hard-coded the quarterfinal, semis, and finals to save a few characters, but >that wouldn't be quite as fun.
Should be simple enough to decipher, but it fulfills both conditions: gives same winner >regardless of order entered, and only returns a winner for matches that actually take >place!
Any advice for improvement would be greatly appreciated, thanks!

Original
$a=Read-Host;$b=Read-Host;$x=("CHIBRA","URUCOL","FRANGA","ALGGER","MEXNED","CRCGRE","SUIARG","BELUSA");for($c=0;$c-lt$x.length-1;$c+=2){$x+=$x[$c].Substring(3)+$x[$c+1].Substring(3)}foreach($i in $x){if($i-match$a-and$i-match$b){return $i.Substring(3)}}return 0

A few things (fixing this completely would take a lot more time): Don't write PowerShell as if it were C or C#. This means, return is unnecessary in most cases. foreach and most explicit loops are overrated and useless. Methods like .Substring should be only used in extreme circumstances (and while the utility of football might be debated, it's not an extreme sport). Generally you want to use the pipeline as much as possible.

Instead of writing a long-winded for loop like for($c=0;$c-lt$x.length-1;$c+=2){$x+=$x[$c].Substring(3)+$x[$c+1].Substring(3)} you can just use a pipeline with a range and ForEach-Object (aliased %): 0..($x.Length/2)|%{$x+=$x[2*$_].Substring(3)+$x[2*$_+1].Substring(3)}. By carefully considering how your data is represented you can very likely get rid of the Substring calls. The parentheses around the initial array are unneeded. For larger arrays it also can make sense to use a separator character and use -split (unary -split in case of the separator being space or tab).

The final foreach loop for example can be written as a pipeline as well (? is Where-Object): $x|?{$_-match$a-and$_-match$b}|%{$_;exit};0 which essentially says »Filter every element in $x for whether it matches both $a and $b and output the first one, exiting afterwards. If none could be found, output 0.«. Since you know the format of your strings you can also just use -match"$a$b|$b$a", I guess. Because they just have to appear in either order in the string. Which also means that we can use a little trick here: "$a$b","$b$a"-eq$_ to golf yet another byte.

CJam, 64 58 bytes
lS/$_0=\:+4b256b1>:ca"oM-YtM-mM-^@}gM-^VM-^U8tM-=nM-^MfM-]oM-xgM-)tM-|m@gim{g_"2/&,*

The above uses caret and M- notation, since the code contains unprintable characters.
At the cost of six additional bytes, those characters can be avoided:
lS/$_0=\:+4b95b1>32f+:c"I8Vyv)2~N{VIEh1$IW32W)B82QBs2G"2/N*\#W>*

Try it online.
Test run
$ base64 -d > worldcup.cjam <<< \
> bFMvJF8wPVw6KzRiMjU2YjE+OmNhIm/ZdO2AfWeWlTh0vW6NZt1v+GepdPxtQGdpbXtnXyIyLyYsKg==
$ wc -c worldcup.cjam
58 worldcup.cjam
$ for A in ALG ARG BEL BRA CHI COL CRC FRA GER GRE MEX NED NGA SUI URU USA; do
> for B in ALG ARG BEL BRA CHI COL CRC FRA GER GRE MEX NED NGA SUI URU USA; do
> [[ $A < $B ]] && echo $A - $B : $(LANG=en_US cjam worldcup.cjam <<< "$A $B")
> done; done | grep ': .'
ALG - ARG : ALG
ALG - BRA : ALG
ALG - FRA : ALG
ALG - GER : ALG
ARG - BEL : ARG
ARG - CRC : ARG
ARG - SUI : ARG
BEL - USA : BEL
BRA - CHI : BRA
BRA - COL : BRA
COL - URU : COL
CRC - GRE : CRC
CRC - MEX : CRC
FRA - NGA : FRA
MEX - NED : MEX

How it works
lS/$    " Read one line from STDIN, split at spaces and sort the resulting array.         ";
_0=\    " Extract the first element of a copy of the array and swap it with the array.    ";
:+      " Concatenate the strings.                                                        ";
4b      " Convert the resulting string into an integer by considering it a base 4 number. ";
256b    " Convert the integer into an array by considering it a base 256 number.          ";
1>:ca   " Drop the first element, convert into a string and create a singleton array.     ";
"…"     " Push a string of all matches encoded as explained above.                        ";
2/      " Split the string into an array of two-character strings.                        ";
&       " Intersect the two arrays. If the array is non-empty, the teams play.            ";
,*      " Multiply the string on the stack by the length of the array.                    ";

You should add the size of your bash script to the size of the CJam program to be fair.

@DavidFrank: I've included the Bash script to show proof that my program provides output only for the 15 matches that take place. It works on its own and requires no external programs.

CJam, 49 48 bytes
lS/$_0="^\16@&^^/+(^]^W^Y,>O?"{_2%+}3*@{2b91%c}%#1&!*

The above uses caret notation, since the code contains unprintable characters.
At the cost of two additional bytes, those characters can be avoided:
lS/$_0="(=BL2*;74)#%8J[K"{_2%+}3*@{2b91%C+c}%#1&!*

Try it online.
Test run
$ base64 -d > wc.cjam <<< bFMvJF8wPSIcMTZAJh4vKygdFxksPk8/IntfMiUrfTMqQHsyYjkxJWN9JSMxJiEq
$ wc -c wc.cjam
48 wc.cjam
$ for A in ALG ARG BEL BRA CHI COL CRC FRA GER GRE MEX NED NGA SUI URU USA; do
> for B in ALG ARG BEL BRA CHI COL CRC FRA GER GRE MEX NED NGA SUI URU USA; do
> [[ $A < $B ]] && echo $A - $B : $(cjam wc.cjam <<< "$A $B"); done; done | grep ': .'
ALG - ARG : ALG
ALG - BRA : ALG
ALG - FRA : ALG
ALG - GER : ALG
ARG - BEL : ARG
ARG - CRC : ARG
ARG - SUI : ARG
BEL - USA : BEL
BRA - CHI : BRA
BRA - COL : BRA
COL - URU : COL
CRC - GRE : CRC
CRC - MEX : CRC
FRA - NGA : FRA
MEX - NED : MEX

Background
We start by assigning and ASCII character to each team by considering its name a base 2 number, taking the resulting integer modulo 91, adding 12 (to avoid unprintable characters) and selecting the character corresponding to the resulting ASCII code. In CJam code, this is achieved by 2b91%c.
For example, the character codes of ALG are 65 76 71. Since (4 × 65 + 2 × 76 + 71) = 483, 483 % 91 + 12 = 40 and 40 if the character code of (.
This gives the following mapping:
ALG (    ARG 4    BEL #    BRA 2    CHI *    COL ;    CRC 8    FRA B
GER =    GRE J    MEX [    NED K    NGA L    SUI )    URU 7    USA %

Now, we can encode the matches of the round of 16 as follows:
(=BL2*;74)#%8J[K

If we assume that the first team in alphabetical order always wins, the matches of the quarter-finals are as follows:
(B2;4#8[

Note that this string can be obtained from the first by selecting every second character, starting with the first. In CJam code, this is achieved by 2%.
Using the same idea, the matches of the semi-finals and the final match are as follows:
(248
(4

The code
"(=BL2*;74)#%8J[K"{_2%+}3*

pushes the string containing the matches of the round of 16, then does the following thrice: duplicate the string, extract every second character of the copy, concatenate. The result is the string
(=BL2*;74)#%8J[K(B2;4#8[(B2;4#8[(248(B2;4#8[(248(248(4

which contains all matches (some of them more than once).
How it works
lS/$        " Read one line from STDIN, split at spaces and sort the resulting array.     ";
_0=         " Extract the first element of a copy of the array.                           ";
"…"         " Push the string containing the matches of the round of 16.                  ";
{_2%+}3*    " Push the remaining matches.                                                 ";
@           " Rotate the input array on top of the stack.                                 ";
{2b91%C+c}% " Perform the mapping for each team in the input array.                       ";
#           " Push the index of the match in the array of all matches (-1 for not found). ";
1&!         " Push 1 if the index is even (valid match) and 0 if it is odd.               ";
,*          " Repeat the string on the stack that many times.                             ";

It's amazing what you do with Cjam. Whenever I think you might borrow one of my ideas, you come up with something better! your prediction code "(=BL2*;74)#%8J[K"{_2%+}3* is the same length as the nonpalindromic form of my prediction string "rRgL j9Ab 35ph tYKO gApK" but a lot easier to handle.

JavaScript 271
t=prompt('Match?').split('-')
x=t[0],y=t[1],T='BRACHICOLURUFRANGAGERALGNEDMEXCRCGREARGSUIBELUSA'
v='\n',R='',W='No Game'
for(z=1;T!='USA';++z,T=n){R+=v+z+v,n='',r=/(...)(...)/g
while(m=r.exec(T))a=m[1],n+=b=m[2],R+=a+'-'+b+v,W=a==x&&b==y||a==y&&b==x?b:W
}
alert(W+'\n'+R)

authors: Андрей Белецкий


text:
Translate ASCII text to braille
Write a program that translates ASCII text to braille output. Requirements:

Input may come from stdin, command line, or some other external input source.
Output should be recognisable as braille, the form of output is up to you. An example would be o for a raised dot and . for a non-raised dot. Textual pattern representation such as 1-3-4 is not acceptable. Long line wrapping is not required.
Only the 26 alphabet characters and space are required for a minimal solution. All input characters not supported by your solution should be ignored.

Scoring is by number of characters in the source code. Penalties and bonuses are:

+50 penalty for using Unicode braille characters as output.
-50 bonus for supporting capitals, numbers, and punctuation.
-200 bonus for supporting ligatures and one-letter contractions from English (Grade-2) Braille. (Will make this a separate challenge since it's quite a different problem.)

Sample invocation and output (minimal solution):
$ braille Hello world
o .  o .  o .  o .  o .  . .  . o  o .  o .  o .  o o
o o  . o  o .  o .  . o  . .  o o  . o  o o  o .  . o
. .  . .  o .  o .  o .  . .  . o  o .  o .  o .  . .

define "valiant attempt". Also, is  line-wrapping required?

@JanDvorak: Thanks, updated question.

I'm sorry, but a single example doesn't cut it in a code golf specification. Please give us the objective minimal requirements to qualify for the bonus.

@JanDvorak: Fair point, I've removed the "valiant attempt" weasel words. There is considerable variation in real world use of these contractions, and fully spelling out contractable words using only letters is valid but considered clumsy by braille readers.

What punctuation do we need to support? Some symbols don't have a standard braille equivalent.

@qwr the basic punctuation listed in the braille Wikipedia article.

@GregHewgill Can you make the bonus for including capitals, numbers, and punctuation larger? Currently that's 26+10+12 = 48 extra characters, not much of a bonus (unless you compress the braille data)

@qwr: I'm not going to change the bonus at this point. Note that capitals aren't separate letter codes, but a prefix code that means "the next letter is capital".

You could count bytes instead of characters and remove the penalty, the cost is about the same (@DigitalTrauma's first solution is 85 bytes). Edit: I just realized that would penalize languages like APL. It's up to you.

can the output be vertical?

Man... the penalty for unicode chars isn't big enough to make this interesting. I wanted to see how people were going to encode the braille set.

Which English grade-2 Braille? American, British or Unified?

@aditsu: I'm probably going to make the Grade-2 challenge a separate problem, and specify the requirements carefully.

@GregHewgill from what I've seen around here (to my dismay), that would likely get a bunch of downvotes and be closed as a duplicate

Python, 162
l=map((" a c,bif/e d:hjg'k m;lsp o n!rtq%12s. w -u x v   z y"%'').find,raw_input().lower())
for i in 1,4,16:print'  '.join('.o.o    ..oo'[(n&i*3)/i::4]for n in l)

Currently supports lowercase letters and some punctuation, but it's still a work in progress.
Example:
$ python braille.py
Hello, world!
o .  o .  o .  o .  o .  . .  . .  . o  o .  o .  o .  o o  . .
o o  . o  o .  o .  . o  o .  . .  o o  . o  o o  o .  . o  o o
. .  . .  o .  o .  o .  . .  . .  . o  o .  o .  o .  . .  o .

Python - 90 75 + 50 = 125
Use lower case letters.
for l in input():
 a=ord(l)-96
 if a<0:a=0
 print("⠀⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵"[a],end="")

One-liner (thanks to ɐɔıʇǝɥʇuʎs)
for l in input():print("⠀⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵"[max(0,ord(l)-96)],end="")

Why not make it a one-liner? for l in input():print("⠀⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵"[max(0,ord(l)-96)],end="") 75 characters.

@ɐɔıʇǝɥʇuʎs wow, I forgot about the max trick. Thank you

You can save a char by just putting blanks for all non-letter characters: for l in input():print((" "*97+"⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵")[ord(l)],end="")

BBC Basic 103 ASCII characters or 92 tokens
A$="HXIKJY[ZQShxikjy{zqsl|Wmon"FORK=1TO26A=ASC(MID$(A$,K))VDU23,K+96,A AND9;0,A/2AND9;0,A/4AND9;:NEXT

Possibly not quite what the OP intended, this redefines the font for the lowercase characters. VDU 23,n,a,b,c,d,e,f,g,h assigns an 8x8 bitmap to character n, consisting of eight bytes. Following a parameter with a semicolon instead of a comma causes it to be treated as a two-byte little-endian number.
The braille patterns for letters a through z are stored in A$, according to the following bit pattern. This is extracted by masks with 9=binary1001 and rightshifts (division by 2 and 4 is used as standard BBC basic has no shift operator.)
 8 1
16 2
32 4

Ungolfed code
A$="HXIKJY[ZQShxikjy{zqsl|Wmon"
FORK=1TO26
  A=ASC(MID$(A$,K))
  VDU23,K+96,A AND9;0,A/2AND9;0,A/4AND9;
NEXT

Usage example
This is done in screen mode 6 for clarity (type MODE6 as soon as you open the command line emulator.)
Actually, after running the code, any lowercase letters (including keyboard input) appear in Braille.

Emulator at  http://bbcbasic.co.uk/bbcwin/bbcwin.html.
See also this similar answer of mine: https://codegolf.stackexchange.com/a/28869/15599

C, 269
#define C char
#define O*p++=(*t&1)*65+46;*t>>=1;
main(int c,C**v){C b[99]={1,5,3,11,9,7,15,13,6,14},o[99],*q=o,*p=v[1],*t;while(c=*p++)*q++=c=='w'?46:c>='a'&&c<='z'?c-='a'+(c>'w'),b[c%10]|(c>9)*16|(c>19)*32:0;for(c=3;c;c--){p=b;for(t=o;t<q;t++){O;O*p++=32;}puts(b);}}

This implementation requires that its argument, if it contains spaces, must be quoted:
# braille "hello world"

Bash + coreutils
Minimal solution - lowercase only, 83 (33 unicode chars + 50 penalty):
tr a-z ⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠭⠽⠵⠺

Capitals, numbers and punctuation, 120 (120 unicode chars + 50 penalty - 50 bonus):
a=⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠭⠽⠵⠺
sed 's/\([0-9]\)/⠼&/g;s/\([A-Z]\)/⠠&/g'|tr ",;':\-⎖.!“?”()/a-zA-Z1-90" ⠂⠆⠄⠒⠤⠨⠲⠖⠦⠦⠴⠶⠶⠌$a$a$a

Example output:
$ echo {A..Z} {a..z} {0..9} ".,;:" | ./braille.sh
⠠⠁ ⠠⠃ ⠠⠉ ⠠⠙ ⠠⠑ ⠠⠋ ⠠⠛ ⠠⠓ ⠠⠊ ⠠⠚ ⠠⠅ ⠠⠇ ⠠⠍ ⠠⠝ ⠠⠕ ⠠⠏ ⠠⠟ ⠠⠗ ⠠⠎ ⠠⠞ ⠠⠥ ⠠⠧ ⠠⠭ ⠠⠽ ⠠⠵ ⠠⠺ ⠁ ⠃ ⠉ ⠙ ⠑ ⠋ ⠛ ⠓ ⠊ ⠚ ⠅ ⠇ ⠍ ⠝ ⠕ ⠏ ⠟ ⠗ ⠎ ⠞ ⠥ ⠧ ⠭ ⠽ ⠵ ⠺ ⠼⠚ ⠼⠁ ⠼⠃ ⠼⠉ ⠼⠙ ⠼⠑ ⠼⠋ ⠼⠛ ⠼⠓ ⠼⠊ ⠲⠂⠆⠒
$

CJam - 51
q{i32%"@`hptdx|lX\bjrvfz~nZ^ck]swg"=i2b1>2/}%zSf*N*

Try it at http://cjam.aditsu.net/
Example input:
braille is strange

Example output:
10 10 10 01 10 10 10 00 01 01 00 01 01 10 10 11 11 10
10 11 00 10 10 10 01 00 10 10 00 10 11 11 00 01 11 01
00 10 00 00 10 10 00 00 00 10 00 10 10 10 00 10 00 00

It only supports lowercase letters and space. Other characters are mapped to supported characters (in particular uppercase letters to lowercase).
Explanation:
Braille characters are encoded using 1 for a raised dot and 0 for a non-raised dot, left to right and top to bottom. This gives 6 base-2 digits; a 1 is prepended to avoid stripping leading zeros, then the number is converted to base 10 then to the corresponding ASCII character.
Example: t -> ⠞ -> 01/11/10 -> 1011110 -> 94 -> ^
The program converts back each character to the triplet of pairs of bits (such as [[0 1][1 1][1 0]]) obtaining a matrix of bit pairs. The matrix is then transposed and separators are added (spaces within rows, newlines between rows).
q reads the input into a string = array of characters
{…}% applies the block to each character
i32% gets the ASCII code mod 32 (space->0, a->1, b->2, z->26)
"@`hptdx|lX\bjrvfz~nZ^ck]swg" is a string containing the braille characters encoded as explained before
= gets the corresponding encoded braille character from the string
i2b gets the ASCII code then converts to base 2 (obtaining an array of 7 digits)
1> removes the leading 1 digit
2/ splits the array into (3) pairs
z transposes the matrix
Sf* joins each row with spaces
N* joins the rows with newlines

APL (Dyalog Extended), 81 + 50 - 50 = 81 bytes
(i,'⠚⠁⠃⠉⠙⠑⠋⠛⠓⠊⠲⠂⠒⠆⠦⠖ ',⍨i←'⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵')[(⎕A,⎕C⎕A,⎕D,'.,:;?! ')⍳⍞]

Try it online uses Dyalog 17, so ⎕C is not supported in it. The alternative, 819⌶ (suggested by dzaima), has been used for demonstration purposes.
Braille symbols taken from dcode.
Explanation
                                                  ⍳⍞ Find index of each character of the input in the string..
                            (⎕A,⎕C⎕A,⎕D,'.,:;?! ')   A-Z, a-z, 0-9, and punctuation.
                           [                      ]  Pick characters from those indices..
(i,'⠚⠁⠃⠉⠙⠑⠋⠛⠓⠊....⠧⠺⠭⠽⠵')                          In the braille representation of the Alphanumeric and punctuation characters.
(last line is shortened to take up less space.)

Try it online!

JavaScript - 286
w=prompt().split('');for(i=0;i<w.length;i++){z=w[i];o="o",p=".";b=[1,5,3,11,9,7,15,13,6,14];e=[c="",1,3];g=z.charCodeAt(0)-97;if(g>22)g--;f=e[g/10|0];d=b[g%10];if(g==22){d=14;f=2;}c+=d&1?o:p;c+=d&2?o:p;c+="\n";c+=d&4?o:p;c+=d&8?o:p;c+="\n";c+=f&1?o:p;c+=f&2?"o\n":".\n";console.log(c);}

First attempt. No bonuses.

You can reduce it to 279 with w=prompt().split("");for(i=0;i<w.length;i++)z=w[i],o="o",p=".",b=[1,5,3,11,9,7,15,13,6,14],e=[c="",1,3],g=z.charCodeAt(0)-97,22<g&&g--,f=e[g/10|0],d=b[g%10],22==g&&(d=14,f=2),c+=d&1?o:p,c+=d&2?o:p,c+="\n",c+=d&4?o:p,c+=d&8?o:p,c+="\n",c+=f&1?o:p,c+=f&2?"o\n":".\n",console.log(c)

Will have to remember that approach, nice long single statement for loop :)

PHP, 331
<?php $d=split("/",gzinflate(base64_decode("NYzBDQBACIM26o3G/r+LRf2QYAOZe4SCLKgU7A9lEWVOzrQVrAiwghWhLKLMyZlawTTGMIYxPg==")));$d[-65]="......";$i=str_split(preg_replace("/[^a-z ]/","",trim(fgets(STDIN))));$o=["","",""];$S="substr";foreach($i as $c){$v=ord($c)-97;for($x=0;$x<3;$x++)$o[$x].=$S($d[$v],$x*2,2)." ";}echo join($o,"\n");

No bonuses for now.

I think it's okay to use a short opening tag in [tag:code-golf], so you can use <? instead of <?php[SPACE] to save 4 characters.

C, 249 244
#define B?111:46
#define P(a,b)printf("%c%c ",a B,b B):
a,i;main(int c,char**v){for(char*p;p=v[1],a<3;puts(""),++a)while(i=*p++)i==32?P(0,0)i/97&122/i?c=(i+=(i==119)*17-97-(i>119))%10,a?a^1?P(i/10%3,i/20)P(c>4|c==1,c/3&&c%3-2)P(c<8,5*c/8%2)0;}

Input is a command-line argument, which must be escaped or quoted if the string contains spaces.  Supported characters are lowercase letters and space.  Unsupported characters are silently dropped.
Edit: Shaved 5 bytes by simplifying a condition

perl, 195+2-50=147
This handles capital, number and punctuation, without relying on unicode (195 bytes + 2 bytes (for -pl) - 50 bonus)
~s/([A-Z])/|$1/g,~s/(\d)/#$1/g,tr/1-90/a-ij/;for$i(1,2,4){map{for$j(1,8){$s.=index(" a,b'k;l^cif/msp_e:h*o!r_djg_ntq|_?_-u(v_____x____._)z\"___w_#y",l$
"}$_=$s

With indentation:
~s/([A-Z])/|$1/g,
~s/(\d)/#$1/g,
tr/1-90/a-ij/;
for$i(1,2,4){
  map{
    for$j(1,8){
     $s.=index(" a,b'k;l^cif/msp_e:h*o!r_djg_ntq|_?_-u(v_____x____._)z\"___w_#y",lc($_))&$j*$i?o:_
    }
   $s.=_
  }split//;
  $s.="
"}
$_=$s

Sample output
perl -pl brail.pl
Hello, 99!
___o__o__o__o__o_________o__o__o__o____
___oo__o_o__o___o_o______o_o___o_o__oo_
_o_______o__o__o________oo____oo____o__

Javascript ES6 - 282 309 297 283 270 - 50 = 232 259 233 220 bytes
This would be shorter, but checking for capital letters hurt.
f=_=>{z='toLowerCase';k=(a,b)=>a%b>~-b/2?1:0;t=(a,b)=>k(a,b)+`${k(a,b/2)} `;b=c=d='';for(v of _){v==v[z]()?0:(b+=0,c+=0,v=v[z](d+=1));$=` ,'-";9015283467@./+^_>#i[s!jwt)a*kue:ozb<lvh\\r(c%mxd?nyf$p&g]q=`.search(v);b+=t($,64);c+=t($,16);d+=t($,4)}alert(`${b}
${c}
${d}`)}

EDIT: Thanks to mbomb007 for saving me two bytes - unfortunately, I found that a little bit of previous golfing had ruined everything, so I had to add 27 characters back in.
EDIT: Aaand 12 bytes saved by moving the spaces.
EDIT: Realized it was silly to output as characters, and saved quite a few bytes. I also saved a few characters by swapping k=(a,b)=>a%(2*b)>b-1?1:0 for k=(a,b)=>a%b>~-b/2?1:0.

Maybe it'd be shorter to assign string.toLowerCase to a variable?

Numbers should be two letters (eg. 3=⠼⠉): the number prefix (⠼) and ciphers are converted to the equivalent letter (3=c=⠉). 1-9-->a-i and 0-->j

I've seen different charts - that wasn't the case on the one I checked.

And I just realized I used the ASCII Braille encoding rather than an actual Ascii chart. So this is disqualified anyway.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Randomly pick one number that is different than two other random numbers
Two random numbers A and B have been generated to be either 1, 2, or 3
your job is to randomly pick a third number C that can also be 1, 2 or 3. But, C cannot equal A or B.

A can equal B.
If A = B, then C has only two numbers left it can be.
If A ≠ B, C has only one number it can be.
Assume A and B have already been chosen for you

This is how A and B would be created in Python
A = random.randrange(1,4)
B = random.randrange(1,4)

Assume this is already in your code.
This is the shortest I've come up with in Python
while True:
    C = random.randrange(1,4)
    if C != A and C != B:
        break

Here are some acceptable values for A, B and C.

1,2,3
1,1,2
2,3,1
3,3,2

Here are some unacceptable values for A, B and C.

1,2,1
2,3,3
1,1,1
3,2,3

So if A and B are given, they aren't actually random as far as my program/function is concerned, right? Also what do you mean by "general code"? Are you actually looking for a solution you can use in a project of yours? In that case, I wouldn't look to code-golf for help - the code is going to be absolutely unusable in production. The entire point of code-golf is to abuse language-specific features to get the code size as far down as possible.

I was using this for a project and have already got a long answer, but I am asking this because I thought it was interesting problem that the community would enjoy. And I put general code because I find it more interesting when someone used more logical thinking to get an answer rather than vast knowledge of some language-specific features, but if code-golf is to abuse these, then I will remove that last line.

Well assume A and B can equal either 1, 2 or 3, so right your code to anticipate all of the possibilities.

I don't understand. Is there something I'm missing or does C = (A!=B ? 6-A-B : (!(A-1) ? 2 : 1)) work? Also your solution is highly inefficient as it wastes time looping and possibly could take an infinite amount of time to run. Also, import random counts in byte size...

I edited my question to add clarity

You can do random.randint(1,3) to make it shorter.

If A,B=random.randrange(1,4),random.randrange(1,4) is already in the code, can I assume that import random is also there or will it count towards my byte-count?

You can assume that's already in there. Assume A and B are variables already created.

Whoops I made a mistake in my above comment. That code should be C=A!=B?6-A-B:!(A-1)?2:!(A-2)?3:2 (32 bytes by the way)

So you want us to write a Monty Hall simulator? ;-)

@IlmariKaronen I totally missed the similarity to Monty Hall! it is indeed equivalent to the choice the host makes once he has the player's first guess (since he already knows where the prize is.) However it doesn't simulate a) the placement of the prize or b) the choices made by the player. I don't think this is a duplicate of the other Monty Hall questions.

Does it have to be a complete program or is a snippet enough? (e.g. leaving out main() in C)

Ruby, 22 characters
([1,2,3]-[A,B]).sample

Still not sure if I understood the question correctly ...

C,26
a-b?6-a-b:(rand()%2+a)%3+1

If I've understood the question correctly:
If a and b are different, there is no random. the answer must be the only one of 1,2,3 that is unused: 6-a-b.
IF a and b are the same there are 2 choices:
a=b=           1 2 3
            return value
rand()%2=0     2 3 1
rand()%2=1     3 1 2

Befunge (156 89 85 74)
Okay, this is terrible, I know. But it's my first Befunge attempt ever, so I'm still pretty happy that it even works. I'm sure there's a much, much better solution.
<v1p90&p80&
<<@.g70_v#-g70_v#-g70g90g80p70
  v     <      <
^1?v
^3<2
^  <

On my phone right now.. Not sure if some rows shifted a bit accidentally. I'll check it when I'm home.

Looks good to me. Much better than my 99 bytes attempt. I hope you're having fun with befunge.

Yeah, the mobile version doesn't seem to be monospaced. Befunge is quite fun, but I wish there'd be a decent Befunge-98 interpreter (I couldn't find any… /edit: rcfunge seems to work)

Python - 35
C=random.sample({1,2,3}-{A,B},1)[0]

Assumes random is imported, which seems to be specified in the question.
PYG - 25
C=RSm({1,2,3}-{A,B},1)[0]

GolfScript, 13 chars
~0]4,^.,rand=

This is a complete GolfScript program that reads two whitespace-separated numbers (each assumed to be either 1, 2, or 3) from standard input, and outputs a random number from the set {1, 2, 3} that does not equal any of the input numbers.
Try it online. (Note: the link is to the previous version; I'm on a mobile device and can't fix it.)
Here's a commented version of the program:
~         # eval the input, pushing the input numbers onto the stack
0         # push the number 0 onto the stack
]         # collect all the numbers on the stack into an array
4,        # create another array containing the numbers 0, 1, 2 and 3
^         # xor the arrays (i.e. take their symmetric set difference)
.,rand=   # choose a random element from the array

If you'd prefer a named function that takes the two numbers as arguments on the stack, that takes a few more chars:
{[\0]4,^.,rand=}:f;

The actual body of the function is only one char longer than the stand-alone code (because we need the [ to make sure we consume only two arguments), but the overhead of wrapping the code in a block and assigning it to a symbol takes five more chars, for a total of 19.
Alternatively, if you literally have the two numbers assigned into the variables A and B, and want the third number assigned to C, that can also be done in 19 chars:
4,[0A B]^.,rand=:C;

(If leaving the third number on the stack instead is acceptable, you can leave the :C; off the end.)
Ps. Thanks for the suggestion to use ^, Howard.

Instead of \- you can use ^.

Python, 14 characters
I tried it for every 9 possible cases and it seems to work fine!
C=A^B or A^1|2

(edit): As edc65 pointed out, this isn't valid since it's not random... I missed that part of the question and I feel stupid right now.

Not random at all

Still, +1 for the admission

Befunge - 99 bytes
&:01p&:11p-!!#v_v
   @,g2+g11g10< "
   321 vv*2g<"v ^
 2v v v 5v*2^10<"
 v?v?v?vp5     ^<
 2 3 1 2<
 > > > >.@

Not very impressive.

PowerShell, 21
1..3-ne$A-ne$B|random

Very straightforward. Abusing the fact that comparison operators act differently with an array as their left operand.

Nice tip about the comparison operators. Makes me want to look at some of my old scripts and see if there are places it can be used. Particularly, this reminds me of part of the Monty Hall simulator.

Mathematica, 37 bytes
RandomChoice@DeleteCases[{1,2,3},a|b]

Basically the same as the Ruby answer, but considerably longer thanks to Mathematica's function names. I'm using lower-case variables, because upper-case names might clash with built-ins (they don't, in this case, but you simply don't do it in Mathematica).

R, 42 chars
x=c(1,1,1);x[c(A,B)]=0;C=sample(1:3,1,p=x)

Vector x is the vector of probability weights for obtaining the elements of the vector being sampled. It is set to 1 for each at first, then elements corresponding to A and B are set to 0, hence they have no chance of being picked.

Rebol - 40 chars
random/only difference[1 2 3]reduce[A B]

CJam - 12
4,[AB0]-mr0=

This assumes the variables A and B have already been set, according to the question.
You can try it at http://cjam.aditsu.net/
To test it with random numbers, use:
"A="3mr):A", B="3mr):B", C="
4,[AB0]-mr0=

To test it with specific values, use (for example):
"A="1:A", B="1:B", C="
4,[AB0]-mr0=

Explanation:
4, creates the array [0 1 2 3]
[AB0]- removes the numbers A, B and 0 from the array
mr shuffles the remaining array
0= takes the first element
In a future CJam version this program will be 2 bytes shorter :)

C 67
int C(int a,int b){int c=0;while(c!=a&&c!=b)c=rand()%3+1;return c;}

JS, 35
inspired by Brandon Anzaldi's answer
A=1; // init
B=3; // init
do{C=1+new Date%3}while(C==A||C==B) // 35b

Pyth, 5 bytes
O.-S3

Try it online!
O.-S3
O.-S3Q - Implicitly read input
   S3  - Create range [1, 2, 3]
 .-    - Subtract input elements from the range
O      - Select a random element.

Arn, 9 bytes
╚<<ÙŒÔ“Âj

Try it!
Explained
Unpacked: ?.$v{!&v}~3
?.          Random entry in
  $           Filtered list
    v{          With block; entry named v
      !           Boolean NOT
          _           Variable ≡ STDIN; implied
        &           Contains (implicit casting to array)
          v           Variable `v`
    }            End block
    ~           On one-range to
      3           Literal three

Julia, 32 or 56 depending on the rules
julia> r()=rand(1:3);f(x...)=(i=r();i in x?f(x...):i)
julia> f(r(),r())

32 if I don't need to generate a and b.

The question says "assume A and B have already been chosen for you".

JS, 43
for(C=0;~[0,A,B].indexOf(C);)C=1+new Date%3

Won't run. You might want to define A and B first.

well, the question says: "Assume A and B have already been chosen for you". So you should run "A=1+new Date%3;B=1+new Date%3" first.

J (21 19: too long for my liking)
({~?@#)(>:i.3)-.A,B

Are there any J wizards around to help remove that variable assignment? It's only 2 chars shorter...
Or, if it doesn't have to be random, you could do with this:
{:(i.4)-.A,B

12 chars.

Java - 126 123 83 85 (using the clever c=6-a-b)
int c;if(a==b){int r=(int)(Math.random()*2);c=a==1?r+2:a==2?2*r+1:r+1;}else{c=6-a-b;}

Full version:
public void test(int a, int b) {
    int c;
    if (a == b) {
        // Random 0 or 1.
        int r = (int)Math.random()*2;
        c = // 1 -> 2 or 3
                a == 1 ? r + 2
                // 2 -> 1 or 3
                : a == 2 ? 2 * r + 1
                // 3 -> 1 or 2
                : r + 1;
    } else {
        // Whichever is not taken.
        //int[][] r = {{0, 3, 2}, {3, 0, 1}, {2, 1, 0}};
        //c = r[a - 1][b - 1];
        // Using @steveverrill's clever
        c = 6 - a - b;
    }
    System.out.println("a=" + a + " b=" + b + " c=" + c);
}

But 6-a-b is not random, is it? :)

@xem - No - but it only uses 6-a-b when there is no other choice, both the other two are taken. It is a clever way of picking the unselected number from 1, 2, 3. 6-1-2 = 3, 6-1-3=2, 6-2-3=1 so for each non-equal a,b 6-a-b picks the third one. Clever eh? The only time you can use random is when a==b.

oh, great. good job then.

R, 24 characters
Initialize with
a = sample(1:3,1)
b = sample(1:3,1)

Then
n=1:3;n[!n%in%c(a,b)][1]

Or just n=1:3;n[!n%in%c(a,b)] but then you return both numbers.

R, 31 characters
sample(rep((1:3)[-c(A,B)],2),1)

If you do sample(x) in R, then it is interpreted as a random sample from 1:x. Repeating the vector (1:3)[-c(A,B)] twice is one way of stopping this from happening.

Javascript - 76
r=(y,z)=>Math.floor(Math.random()*(z-y+1)+y);a=b=r(1,3);while(c==a)c=r(1,3);

Math.floor can be replaced by ~~. You could also say r=(y,z)=>y+New Date(z-y). Also, A and B are not meant to be equal, and you don't have to count their initialization in your score.

@xem A and B are meant to be random. The rules say that they can be equal. Also, not sure about ES6 but y+New Date(z-y) is a SyntaxError

@xem y+new Date(z-y) on the other hand reports new Date() string with y appended.

sorry for the typo, I meant y+new Date%(z-y) ... or (z-y+1) depending on the params.

and my remark about A and B equal was about "a=b=r(1,3);". If you do that a is always equal to b, but that's not what the rules ask. They ask for A and B random. They can be equal but not necessarily

@xem A and B are random, just not separately set and the rules don't state that that isn't allowed.

Try to read the rules again. It's not that dificult. "Assume A and B are already choosed. If A= B... If A does not equal B..."

JavaScript - 41 (up to 46) 37 35 34 30
Updated:
Managed to get it down to 30 chars by modifying it, inspired by stevevarrill's answer in C.
C=A-B?6-A-B:1+(A+new Date%2)%3

Thank you nyuszika7h for getting me down to 34~:
C=A;while(C==A|C==B)C=1+new Date%3
Borrowing from xem's answer to at least fall on par with him:
C=A;while(C==A||C==B)C=1+new Date%3
Thanks for reminding me that 1+new Date%3 === (new Date%3)+1!
Previous Solution:
C=A;while(C==A||C==B)C=(new Date%3)+1
Ensure conditions of while() are satisfied, and loop through until they're not.

Other solution:
C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1;
This assumes that C has already been declared OR that the JavaScript interpreter can handle undeclared variables.
However, if the JS interpreter can handle EOL without a semicolon, it could be bumped down to 41.
C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1
If C hasn't been declared, and there is no error correction for it, that will bring the tally up to 46 characters.
var C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1;
Test Program:
var iterations = 100;

for(var i = 0;i<iterations;i++) {
    var A = Math.floor(Math.random() * 3) + 1;
    var B = Math.floor(Math.random() * 3) + 1;
    C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1
    if (C === A || C === B || C > 3 || C < 1) {
        console.log('FAILURE!');
        console.log(A + ',' + B + ',' + C)
        return;
    }
    console.log(A+','+B+','+C);
}

great! I made a 35b answer based on this, but using a do-while loop ;)

You should be able to use | instead of ||.

Save 1 byte with a for loop: for(C=A;C==A|C==B;)C=1+new Date%3

I'd just like to thank everyone for their help :)

C - 38
main(c){for(;c==a|c==b;c=rand()%2+1);}

Java, 264 bytes
Random r = new Random();ArrayList<Integer> s = new ArrayList<>();ArrayList<Integer> q = new ArrayList<>();for(int i=0; i<n; i++) s.add(r.nextInt(k));q.add(s.get(r.nextInt(n)));q.add(s.get(r.nextInt(n)));int x;do{x = s.get(r.nextInt()); }while(!q.contains(x));

This code generates n different random numbers from 0 to k.

Golfscript, 13 Characters
~]4,^.,rand)=

Befunge-98 (57 bytes)
This code assumes the numbers will be input on stdin. It will pick a random number if both of the first numbers are the same until it is different, otherwise it will choose the last available number.
6&::11p&:12pw>   ?1  >#<:11g-!_.@
     @.-g21-<>3;#[2#;^

Jelly, 5 bytes
3Rḟ⁸X

Try it online!
This takes [A, B] as input, as Jelly doesn't have the concept of variables
How it works
3Rḟ⁸X - Main link. Takes [A, B] on the left
3R    - Yield [1, 2, 3]
   ⁸  - Yield [A, B]
  ḟ   - Remove [A, B] from [1, 2, 3]
    X - Randomly select an element from the remaining list

Japt, 7 bytes
3õ kU ö

Try it here

Python, 54 41 105 characters
Quite long answer in Python but I like list comprehension, so I decided to post this here
// [0] means it is the first element of
from random import random
C=[i for i in sorted([1,2,3], key=lambda x: random()) if not(i in(A,B))][0]

Fixed but it is really long now.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Golfing ASCII-art
Let's try to golf this piece of ascii-art representing a golfing man:

      '\                   .  .                        |>18>>
        \              .         ' .                   |
       O>>         .                 'o                |
        \       .                                      |
        /\    .                                        |
       / /  .'                                         |
 jgs^^^^^^^`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Source: JGS - http://www.retrojunkie.com/asciiart/sports/golf.htm
Rules:

No input allowed
No external resources allowed
The output must be exactly this text, displayed in a monospace font (OS console, JS console, HTML <pre> tag, ...), including the leading and trailing line-break.
Surrounding quotes or double-quotes are allowed (the JS console adds double quotes when you output a string, this is okay)

The best answer will be the one using the less characters in any language.
Have fun!

"exactly this text": including the empty line at the beginning? including the empty line at the end? with a trailing new-line or without? (That is, 0, 1 or 2 new-.lines at the end?)

@m.buettner the output should have exactly one leading line break and one trailing line break/new line. (and quotes if you can't avoid them) :)

That ASCII looks more like a Cricket shot to me

@Mr.Alien I saw it in Martin Kleppe's recent talk: https://speakerdeck.com/aemkei/jscamp-dot-ro-minified-javascript-craziness (video: https://www.youtube.com/watch?v=zy-2ruMHdbU)

CJam, 62 characters
"Ⴀ지尦렒>Ä΀ྀ㸀⡅쇋蒧ʸ鿀ʃ케袧Ƽ蟀ʄ導뤷쀂萯Ű⋥ἀ਎밊耧台 ⢙⿶ꝍ㕟劢햟騤꩏脽啎"2G#b128b:c~

Try it online.
Test run
$ base64 -d > golf.cjam <<< IgHhgqDsp4DlsKbroJLujJ8+w4TOgOC+gOO4gOKhheyHi+iSp8q46b+AyoPsvIDvoIPuhKvooqfGvOifgMqE5bCO66S37ICC6JCvxbDii6XhvIDgqI7rsIrvgYvogKflj7DCoOKimeK/tuqdjeOVn+WKou2Wn+mopO+em+qpj+iEve6arOWVjiIyRyNiMTI4Yjpjfg==
$ wc -m golf.cjam
62 golf.cjam
$ cjam golf.cjam

      '\                   .  .                        |>18>>
        \              .         ' .                   |
       O>>         .                 'o                |
        \       .                                      |
        /\    .                                        |
       / /  .'                                         |
 jgs^^^^^^^`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
$

How it works
2G#b converts the preceding string into an integer by considering it a base-65536 number.
128b:c converts that integer back to a string (110 bytes) by considering it a base-128 number, which ~ then executes:
"
^F'^@\^S.^B.^X|^@>^@1^@8^@>^@>^@
^H\^N.^I'^A.^S|^@
^GO^@>^@>^I.^Q'^@o^P|^@
^H\^G.&|^@
^H/^@\^D.(|^@
^G/^A/^B.^@')|^@
^A"2/{)iS*}%"jgs"'^7*'`'^51*N

(caret notation)
2/{)iS*}%

splits the string into pairs of two characters and does the following for each pair: Pop the second character of the string, convert it into an integer and repeat the string " " that many times.
For example, ".(" becomes ".                                        ", because the ASCII character code of ( is 40.
Finally,
"jgs"'^7*'`'^51*N

pushes the string "jgs", the character ^ repeated 7 times, the character `, the character ^ repeated 51 times and a linefeed.

Really awesome, but when I take the 62char version from the pastebin and "try it online", a line break is missing before the last line "jgs..."

@xem: Did you copy from the RAW Paste Data section? If I copy the formatted code, I get the same result.

Ruby, 107
I thought I'd actually try to "generate" the image in code (instead of using some existing compression function):
S=?\s*351+?^*60
"⠀鰇렜렟쐺⠾롖鱠롢⡷뢋鲝⢰룁⣩볲룸⤢봪봬뤯鴰⥛".chars{|q|S[511&r=q.ord]=(r>>10).chr}
puts S

There are some non-printable characters in that array literal.
Here is the hex view of the file, to show the non-printable characters, too:
0000000: 533d 3f5c 732a 3335 312b 3f5e 2a36 300a  S=?\s*351+?^*60.
0000010: 22e2 a080 e9b0 87f0 9780 88eb a09c eba0  "...............
0000020: 9ff0 9f80 b8ef a0b9 ec90 baee 80bb efa0  ................
0000030: bcef a0bd e2a0 bef0 9781 87eb a196 e9b1  ................
0000040: a0eb a1a2 f09f 81b6 e2a1 b7f0 93b1 bfef  ................
0000050: a280 efa2 81eb a28b e9b2 9df0 9bb2 9ef0  ................
0000060: 9f82 afe2 a2b0 f097 82b9 eba3 81f0 9f83  ................
0000070: a8e2 a3a9 ebb3 b2f0 9783 b3eb a3b8 f09f  ................
0000080: 84a1 e2a4 a2eb b4aa ebb4 aceb a4af e9b4  ................
0000090: b0f0 9f85 9ae2 a59b f09a a59d f099 b59e  ................
00000a0: f09c b59f f098 85a7 222e 6368 6172 737b  ........".chars{
00000b0: 7c71 7c53 5b35 3131 2672 3d71 2e6f 7264  |q|S[511&r=q.ord
00000c0: 5d3d 2872 3e3e 3130 292e 6368 727d 0a70  ]=(r>>10).chr}.p
00000d0: 7574 7320 53                             uts S

Thanks to Ventero for some major improvements! (He basically reduced the code by 50%.)

Nice effort! I was hoping for answers like that, that don't just gzip the ASCII ;)

The second line could be 6.times{|i|S[i+1]=' '*55+?|} to save 2 characters.

@voidpigeon Ah thanks. I actually started with that, but initially thought I'd need i more than once. Good catch!

Hope you don't mind if I mention a few more ways to shorten this! Using S.fill{' '*55+?|} instead saves a few more characters (you'll have to define S as ['']*7, change the puts to puts p,S,p and subtract 1 from all your y coordinates though). Then, by using varargs in f (def f(*p,c)), you can save the [] in the function calls. Oh, and you can drop the () around y,x.

@Ventero whoa, 20 characters. Thanks a lot!

If you make S  one-dimensional, you can save another 55 characters ;) Here's the code if you don't want to do it yourself.

@Ventero oh, very good idea. I'll go ahead and steal that. ;)

@Ventero two more and it's half as long as the ASCII art itself ;)

Done: http://fpaste.org/115666/45130641/

Let us continue this discussion in chat.

bash + iconv + DosBox/x86 machine code (104 97 96 95 characters)
echo ↾각슈삨੽₲ɻ庲錿ʴ⇍罋곹삄ૃ蘊尧⺓⺂粘ㄾ㸸ਾ岈⺎➉⸠粓蜊㹏褾鄮漧粐蠊蝜꘮੼⾈葜꠮੼⾇⼠⺂ꤧ੼樠獧惇૳|iconv -futf8 -tucs2>o.com;dosbox o*

I suggest to put this in a script in an empty directory, it's almost guaranteed that copy-pasting it in a terminal will break everything; even better, you can grab the script here ready-made.
Expected output:
How it works
The bash part is just a launcher that uses iconv to "decompress" a .com file from the UTF-8 characters of the script and launches it with DosBox.
Notice that this poses some limitation on the content, as not all the input sequences can be interpreted as UCS-2 with iconv not complaining; for example, for some reason many operations involving the bx register broke havoc depending on the place where I used them, so I had to work around this problem several times.
Now, the Unicode thing is just to take advantage of the "character count" rules; the actual size (in bytes) of the script is way larger than the original .COM file.
The extracted .com file is
00000000  be 21 01 ac 88 c2 a8 c0  7d 0a b2 20 7b 02 b2 5e  |.!......}.. {..^|
00000010  83 e0 3f 93 b4 02 cd 21  4b 7f f9 ac 84 c0 75 e4  |..?....!K.....u.|
00000020  c3 0a 0a 86 27 5c 93 2e  82 2e 98 7c 3e 31 38 3e  |....'\.....|>18>|
00000030  3e 0a 88 5c 8e 2e 89 27  20 2e 93 7c 0a 87 4f 3e  |>..\...' ..|..O>|
00000040  3e 89 2e 91 27 6f 90 7c  0a 88 5c 87 2e a6 7c 0a  |>...'o.|..\...|.|
00000050  88 2f 5c 84 2e a8 7c 0a  87 2f 20 2f 82 2e 27 a9  |./\...|../ /..'.|
00000060  7c 0a 20 6a 67 73 c7 60  f3 0a 0a 00              ||. jgs.`....|
0000006c

and is 108 bytes long. The NASM source for it is:
    org 100h

start:
    ; si: pointer to current position in data
    mov si,data
    ; load the character in al
    lodsb
mainloop:
    ; bx: repetition count
    ; - zero at startup
    ; - -1 after each RLE run
    ; - one less than each iteration after each "literal" run
    ; the constant decrement is not really a problem, as print
    ; always does at least one print, and there aren't enough
    ; consecutive literal values to have wraparound

    ; if the high bit is not set, we have a "literal" byte;
    ; we prepare it in dl just in case
    mov dl,al
    ; then check if it's not set and branch straight to print
    ; notice that bx=0 is fine, as print prints always at least one character
    ; test the top two bits (we need the 6th bit below)
    test al,0xc0
    ; to see if the top bit was set, we interpret it as the sign bit,
    ; and branch if the number is positive or zero (top bit not set)
    jge print
rle:
    ; it wasn't a literal, but a caret/space with a repetition count
    ; space if 6th bit not set, caret otherwise
    mov dl,' '
    ; exploit the parity bit to see if the 6th bit was set
    jnp nocaret
    mov dl,'^'
nocaret:
    ; lower 6 bits: repetition count
    ; and away the top bits and move in bx
    ; we and ax and not al because we have to get rid of the 02h in ah
    and ax,3fh
    xchg ax,bx
print:
    ; print bx times
    mov ah,2
    int 21h
    dec bx
    jg print
    ; read next character
    lodsb
    test al,al
    ; rinse & repeat unless we got a zero
    jnz mainloop
end:
    ret
data:
    ; here be data
    incbin "compressed.dat"
    ; NUL terminator
    db 0

All this is just a decompresser for compressed.dat whose format is as follows:

if the high bit is not set, print the character as-is;
otherwise, the low 6 bits are the repetition count, and the second-highest bit specifies if it has to print a space (bit not set) or a caret (bit set).

compressed.dat in turn is generated using a Python script from the original text.
The whole thing can be found here.

Python, 156
print'''
%6s'\%19s.  .%24s|>18>>
%8s\%14s.%9s' .%19s|
%7sO>>%9s.%17s'o%16s|
%8s\%7s.%38s|
%8s/\%4s.%40s|
%7s/ /  .'%41s|
 jgs'''%(('',)*19)+'^'*7+'`'+'^'*51

This uses string formatting with space padding for some basic compression.

PHP, 147
This runs on the command line and outputs directly to the console:
php -r 'echo gzinflate(base64_decode("41IAA/UYBUygB0bYQY2doYWdHReMG4OhEwrUsRpRA9Pob2eHRRNccz5OjXAbcboQl0b9GBK0IWnUB0IFPXUFEjRmpRfHQUBCHOmAiwsA"));'

Perl - 127 129 130 132 135 137 145
print q(
6'\19.2.24|>18>>
8\14.9'1.19|
7O>>9.17'o16|
8\7.38|
8/\4.40|
7/1/2.'41|
1jgs^^^^^^^`0
)=~s/\d++(?!>)/$"x$&||'^'x51/reg

Thanks to Ventero and m.buettner for their help in my RegEx optimization.

You can save one character with s/\d+(?!8?>)/%$&s/rg

@Ventero thank you for the suggestion.

You can save another one by using a possessive quantifier: /\d++(?!>)/

@m.buettner I didn't know that. Learning new things every day :)

GCC C - 203 bytes
I figured I'd have some fun with this one. This compiles on my version of MinGW and outputs the expected text.
Whitespace added for clarity.
char*v="\n ú'\\ í.  . è|>18>>\n ø\\ ò. ÷' . í|\n ùO>> ÷. ï'o ð|\n ø\\ ù. Ú|\n ø/\\ ü. Ø|\n ù/ /  .' ×|\n jgs^ù`^Í\n";
main(g,o,l){
    for(;*v;
        g=!g&*v<0&l?-*v++:g){
        v+=!(l=*v-35);
        putchar((g-=g>0)?o:(o=*v++));
    }
}

None of the online code pasting sites allow the use of single byte characters outside the ASCII range, so I had to escape them for an uploaded example. It's otherwise identical though. http://codepad.org/nQrxTBlX
You can always verify it with your own compiler, too.

LOLCODE, 590 characters
Cuz LOLCODE iz perfik language 4 golfin: iz easy 2 compres an obfuscate an it isnt verbose at all.
HAI
HOW DUZ I D C T
I HAZ A O
I HAZ A N ITZ 0
IM IN YR LOOP UPPIN YR N TIL BOTH SAEM N AN T
O R SMOOSH O AN C MKAY
IM OUTTA YR LOOP
FOUND YR O
IF U SAY SO
VISIBLE ""
VISIBLE SMOOSH "  '\" AN D " " 19 AN ".  ." AN D " " 24 AN "|>18>>" MKAY
VISIBLE "    \              .         ' .                   |"
VISIBLE "   O>>         .                 'o                |"
VISIBLE SMOOSH "    \       ." AN D " " 38 AN "|" MKAY
VISIBLE SMOOSH "    /\    ." AN  D " " 40 AN "|" MKAY
VISIBLE SMOOSH "   / /  .'" AN D " " 41 AN "|" MKAY
VISIBLE SMOOSH "jgs^^^^^^^`" AN D "^" 51 MKAY
VISIBLE ""
KTHXBYE

Im pritee sure dis werkz, but I doan has an LOLCODE interpretr an http://repl.it's seems 2 not liek funcshuns.
(Tranzlashun generously providd by http://speaklolcat.com's robots cuz I doan speek lolcat)

Indented, spaced, and commented version of the code (LOLCODE comments start with BTW):
HAI BTW All LOLCODE programs start with HAI
    HOW DUZ I D C T BTW Function declarations follow the form "HOW DUZ I <func-name>[ <func-arg1>[ <func arg2>[ ...]]]". In this case, D is a function that repeats a YARN C (YARN is the equivalent of string in LOLCODE) NUMBR T (NUMBR = int) times.
        I HAZ A O BTW Variable declarations follow the form "I HAZ A <var-name>"

        I HAZ A N ITZ 0 BTW Variables can be intialised when declared by appending " ITZ <init-value>" to the declaration
        IM IN YR LOOP UPPIN YR N TIL BOTH SAEM N AN T BTW Loops follow the form "IM IN YR LOOP <action> TIL <condition>" where action and condition are "UPPIN YR N" and "BOTH SAEM N AN T", respectively, in this case
            O R SMOOSH O AN C MKAY BTW "R" assigns a new value to a variable. YARN (string) concatenation follows the form "SMOOSH <str-1> AN <str-2>[ AN <str-3>[...]] MKAY"
        IM OUTTA YR LOOP BTW "IM OUTTA YR LOOP" ends LOLCODE loops

        FOUND YR O BTW "FOUND YR <value>" returns a value
    IF U SAY SO BTW "IF U SAY SO" ends functions

    VISIBLE "" BTW "VISIBLE" prints its argument to stdout
    VISIBLE SMOOSH "  '\" AN D " " 19 AN ".  ." AN D " " 24 AN "|>18>>" MKAY BTW The function I wrote above only "pays off" in terms of characters added/saved when repeating 19 or more characters (the function call itself takes 8 characters, assuming a one-character first argument and a 2-digit second one; you need to factor in the added quotes (2 characters), spaces (4) and ANs (4) for 18 total extra characters; and possible SMOOSH/MKAY)
    VISIBLE "    \              .         ' .                   |"
    VISIBLE "   O>>         .                 'o                |"
    VISIBLE SMOOSH "    \       ." AN D " " 38 AN "|" MKAY
    VISIBLE SMOOSH "    /\    ." AN  D " " 40 AN "|" MKAY
    VISIBLE SMOOSH "   / /  .'" AN D " " 41 AN "|" MKAY
    VISIBLE SMOOSH "jgs^^^^^^^`" AN D "^" 51 MKAY
    VISIBLE ""
KTHXBYE BTW "KTHXSBYE" ends LOLCODE programs

haha, nice compression, like it :D

Python - 205 203 197
i="""
G^y`G^MsGgGj!G
G|!o'G.!H/!G/!M
G|!n.!J\G/!N
G|!l.!M\!N
G|!VoG'!W.!O>HO!M
G|!Y.!G'!O.!T\!N
G>H8G1G>G|!^.!H.!Y\G'!L
G""".replace('!','G ')
o=''
j=140
while j:j-=2;o+=ord(i[j+1])%70*i[j]
print o

The string i interleaves the characters in the ascii art with their multiplicites, represented as characters, all in in reverse order. In addition, I save a bit of space by using '!' instead of 'G ' in i and then just replacing it.

Python (145)
'eJzjUgAB9RgFTKAHRthBjZ2hhZ0dF5SHphuhSx2rCTVQff52dlj0wPXm49IHtw+n83Do048hQRdCnz4QKuipE6sNqC8rvTgOAhLiSAdcAG/9Ri8='.decode('base64').decode('zip')

Not very original, I know.

Javascript (ES6) 193 175 bytes
Edit: Modified RegPack v3 to maintain newlines, use a for in loop to save 3 bytes, and removed eval for implicit console output.
_="\nx'\\w{. z~|>18>>\n~\\~x.~ 'z{yx O>>~z 'owy~\\xzwxy~/\\{zw~yx / /  .'ww~ y jgs}`}}}}}}}^^\n~x  }^^^^^^^{   z .wy|\nx{{w~~";for(i of "wxyz{}~")with(_.split(i))_=join(pop())

Using xem's unicode compression: 133 characters
eval(unescape(escape('').replace(/uD./g,'')))

great! <3 the RegPack's post-processing! psst, you can make it in 143b: http://xem.github.io/obfuscatweet/

@xem 143 characters, but a lot more bytes

yes sorry, 143 chars. the question says that you can count chars. anyway, the regpack's approach is more interesting than the unicode-obfuscation ;)

FWIW, http://mothereff.in/byte-counter is a tool that counts both characters and bytes (as per UTF-8).

ES6, 155 chars
Just trying anorher approach:
Run this in Firefox's JS console.
Each unicode character has the following form: \uD8[ascii charcode]\uDC[number of repeats].
"".replace(/../g,a=>String.fromCharCode(a[c='charCodeAt']()&255).repeat(a[c](1)&255))

(Unicode string made with: http://jsfiddle.net/LeaS9/)

-3: .replace(/../g,a=>String.fromCharCode(a[c='charCodeAt']()&255).repeat(a[c](1)&255))

oh, great, thanks!

PHP
Method 1, simpler (139 bytes):
Using a pre-deflated string.
<?=gzinflate(base64_decode('41IAA/UYBUygB0bYQY2doYWdHReMG4OhEwrUsRpRA9Pob2eHRRNccz5OjXAbcboQl0b9GBK0IWnUB0IFPXUFEjRmpRfHQUBCHOmACwA='));?>

Method 2, encoding runs of spaces into alphabet letters (192 bytes):
<?=preg_replace_callback('#[D-NP-Zu]#',function($e){return str_repeat('a'<$e[0]?'^':' ',ord($e[0])-66);},"
H'\U.D.Z|>18>>
J\P.K' .U|
IO>>K.S'oR|
J\I.WS|
J/\F.ZR|
I/ /D.'ZS|
 jgs^^^^^^^`u
")?>

PowerShell, 192 188 119
 -join('̠§Üঠ®Ġ®ఠü¾±¸ľРÜܠ®Ҡ§ ®ঠüΠÏľҠ®ࢠ§ïࠠüРÜΠ®ጠüР¯ÜȠ®ᐠüΠ¯ ¯Ġ®§ᒠü êçóϞà᧞'[0..70]|%{"$([char]($_%128))"*(+$_-shr7)})

The part above contains a few non-characters. Hex dump:
00: 002D 006A 006F 0069 │ 006E 0028 0027 008A  -join('
10: 0320 00A7 00DC 09A0 │ 00AE 0120 00AE 0C20  ̠§Üঠ®Ġ®ఠ
20: 00FC 00BE 00B1 00B8 │ 013E 008A 0420 00DC  ü¾±¸ľРÜ
30: 0720 00AE 04A0 00A7 │ 00A0 00AE 09A0 00FC  ܠ®Ҡ§ ®ঠü
40: 008A 03A0 00CF 013E │ 04A0 00AE 08A0 00A7  ΠÏľҠ®ࢠ§
50: 00EF 0820 00FC 008A │ 0420 00DC 03A0 00AE  ïࠠüРÜΠ®
60: 1320 00FC 008A 0420 │ 00AF 00DC 0220 00AE  ጠüР¯ÜȠ®
70: 1420 00FC 008A 03A0 │ 00AF 00A0 00AF 0120  ᐠüΠ¯ ¯Ġ
80: 00AE 00A7 14A0 00FC │ 008A 00A0 00EA 00E7  ®§ᒠü êç
90: 00F3 03DE 00E0 19DE │ 0027 005B 0030 002E  óϞà᧞'[0.
A0: 002E 0037 0030 005D │ 007C 0025 007B 0022  .70]|%{"
B0: 0024 0028 005B 0063 │ 0068 0061 0072 005D  $([char]
C0: 0028 0024 005F 0025 │ 0031 0032 0038 0029  ($_%128)
D0: 0029 0022 002A 0028 │ 002B 0024 005F 002D  )"*(+$_-
E0: 0073 0068 0072 0037 │ 0029 007D 0029       shr7)})

Encoding scheme is RLE with the length encoded above the lower 7 bit, which are the character to display.

JS (190b) / ES6 (146b) / ES6 packed (118chars)
Run this in the JS console:
JS:
"\n7'\\20.3.25|>18>>\n9\\15.10'2.20|\n8O>>10.9 9'o17|\n9\\8.39|\n9/\\5.41|\n8/2/3.'42|\n2jgs^^^^^^^`".replace(/\d+/g,function(a){return 18==a?a:Array(+a).join(' ')})+Array(51).join("^")+"\n"

ES6:
"\n6'\\19.2.24|>0>>\n8\\14.9'1.19|\n7O>>9.17'o16|\n8\\7.38|\n8/\\4.40|\n7/1/2.'41|\n1jgs58`101\n".replace(/\d+/g,a=>' ^'[a>51|0].repeat(a%51)||18)

ES6 packed: (http://xem.github.io/obfuscatweet/)
eval(unescape(escape('').replace(/uD./g,'')))

Thanks to @nderscore!

ES6 down to 158: (goes down to 124 chars with unicode compression) "\n6'\\19.2.24|>18>>\n8\\14.9'1.19|\n7O>>9.17'o16|\n8\\7.38|\n8/\\4.40|\n7/1/2.'41|\n1jgs^^^^^^^\".replace(/\d+/g,a=>18-a?' '.repeat(a):a)+"^".repeat(50)+"\n"`

oh, great, I didn't know repeat

@nderscore don't be sorry it's great :) but the last line seems broken in my Firefox console

146: "\n6'\\19.2.24|>0>>\n8\\14.9'1.19|\n7O>>9.17'o16|\n8\\7.38|\n8/\\4.40|\n7/1/2.'41|\n1jgs58\101\n".replace(/\d+/g,a=>' ^'[a>51|0].repeat(a%51)||18)` (stackexchange adds invisible line-breaking characters after 41|\)

Thanks, I updated the answer and it works. :) I also added another 158b anwser, maybe you'll have an idea to improve it!

Python - 236
s=' ';print('\n'+6*s+"'\\"+19*s+'.  .'+24*s+"|>18>>\n"+8*s+'\\'+14*s+'.'+9*s+"' ."+19*s+"|\n       O>>"+9*s+'.'+17*s+"'o"+16*s+'|\n'+8*s+"\\       ."+38*s+'|\n'+8*s+"/\\    ."+40*s+"|\n       / /  ."+42*s+"|\n jgs^^^^^^^`"+51*'^'+'\n')

ES6, 163b / 127 chars
Yet another approach, thanks to @nderscore.
Execute it in Firefox's console
JS (163b):
"\n'\\..|>18>>\n\\. '.|\nO>>    .'o|\n\\.&|\n/\\.(|\n//.')|\njgs<`h\n".replace(/[^'`Og\n>\\,-8j-|]/g,a=>" ^"[a=a.charCodeAt(),a>53|0].repeat(a%53))

Packed (127c):
eval(unescape(escape('').replace(/uD./g,'')))

I'm sure @nderscore will find an enhancement :)

I think SE is breaking some of the characters in this solution. Using a similar approach to what I did with your other answer, this goes down to 163: http://jsfiddle.net/2Fbxq/3/

Well, that's a great enhancement (and a very nice fiddle). I updade the answer.

Python, 70 UTF-16 chars
挣摯湩㩧呕ⵆ㘱䕂
print砧RԘꁌ䘇䇘鶍薡ᶝ谗ꚋꄝᵍᆫ〵ﺍ癶㑘㗁ࣔᆷ஧楱返䄡鈛絆吠叐嘧䠟噣煺М쐤ຑꀀ䜮'.decode(稧楬b')

Of course you're probably going to have to use the hex version:
23 63 6F 64 69 6E 67 3A 55 54 46 2D 31 36 42 45 0A 00 70 00 72 00 69 00 6E 00 74 00 27 78 9C E3 52 00 03 F5 18 05 4C A0 07 46 D8 41 8D 9D A1 85 9D 1D 17 8C 8B A6 1D A1 4D 1D AB 11 35 30 8D FE 76 76 58 34 C1 35 E7 E3 D4 08 B7 11 A7 0B 71 69 D4 8F 21 41 1B 92 46 7D 20 54 D0 53 27 56 1F 48 63 56 7A 71 1C 04 24 C4 91 0E 00 A0 2E 47 05 00 27 00 2E 00 64 00 65 00 63 00 6F 00 64 00 65 00 28 00 27 7A 6C 69 62 00 27 00 29 00

or the base64 version:
I2NvZGluZzpVVEYtMTZCRQoAcAByAGkAbgB0ACd4nONSAAP1GAVMoAdG2EGNnaGFnR0XjIumHaFNHasRNTCN/nZ2WDTBNefj1Ai3EacLcWnUjyFBG5JGfSBU0FMnVh9IY1Z6cRwEJMSRDgCgLkcFACcALgBkAGUAYwBvAGQAZQAoACd6bGliACcAKQA=

The first "line" of the program declares the UTF-16 encoding. The entire file is UTF16, but the Python interpreter always interprets the coding line in ASCII (it is #coding:UTF-16BE). After the newline, the UTF-16 text begins. It simply amounts to print'<data>'.decode('zlib') where the text is a deflated version of the target ASCII image. Some care was taken to ensure that the stream had no surrogates (which would ruin the decoding).

Well, the first line made me think "oh great, someone made unicode python"

awesome! Can you do the same in ~35b with UTF-32? :)

zip instead of zlib may save one char.

@xem: most characters stop being valid UTF-32 (chars must be <= 0x10ffff).

@CeesTimmerman: actually the choice of zlib rather than zip is very purposeful. zlib is an even number of characters.

C# - 354 332

using System;
using System.IO;
using System.IO.Compression;
class X
{
    static void Main(string[] args)
    {
        var x= Convert.FromBase64String("41IAA/UYBUygB0bYQY2doYWdHReMG4OhEwrUsRpRA9Pob2eHRRNccz5OjXAbcboQl0b9GBK0IWnUB0IFPXUFEjRmpRfHQUBCHOmAiwsA");
        Console.WriteLine(new StreamReader(new DeflateStream(new MemoryStream(x), CompressionMode.Decompress)).ReadToEnd());
    }
}

A bit golfed:
using System;using System.IO;using System.IO.Compression;class X{static void Main(){var x=Convert.FromBase64String("41IAA/UYBUygB0bYQY2doYWdHReMG4OhEwrUsRpRA9Pob2eHRRNccz5OjXAbcboQl0b9GBK0IWnUB0IFPXUFEjRmpRfHQUBCHOmAiwsA");Console.WriteLine(new StreamReader(new DeflateStream(new MemoryStream(x),(CompressionMode)0)).ReadToEnd());}}

That's not really golfed if you still have variable names longer than a character in there. Or unnecessary things like string[] args.

Dunno the rules, but there is no other way in C#, and code need to compile so, this is the shortest possible.

Main does not need to have any arguments, it will still compile (in contrast to Java). Removing that and inlining x brings this to 333 already. You can save another byte by removing the space between the arguments in the DeflateStream ctor. You can use a cast for the enum member: (CompressionMode)0, which brings us down to 324. So I'd argue it's not yet the shortest possible ;-)

Right you are..

bzip2, 116
After seeing the CJAM answer, I figured this one should qualify too.
$ wc -c golf.txt.bz2
116 golf.txt.bz2
$ bzip2 -dc golf.txt.bz2

  '\                   .  .                        |>18>>
    \              .         ' .                   |
   O>>         .                 'o                |
    \       .                                      |
    /\    .                                        |
   / /  .'                                         |
jgs^^^^^^^`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

$

I doubt any further explanation is required. :)

Using Bubblegum with DEFLATE gets it down to 77 bytes. Try it online!

C (gcc), 190 bytes
r(n,c){while(n--)putchar(c);}f(c){for(char*s="F'\\S.B.X|>18>>\nH\\N.I' .S|\nGO>>I.Q'oP|\nH\\G.ZL|\nH/\\D.ZN|\nG/ /B.'ZN |\n jgs^^^^^^^`";c=*s++;)c>64&&c<91&&c^79?r(c-64,32):r(1,c);r(51,94);}

Try it online!

Vim, 99 keystrokes
63i^<Esc>0R jgs<C-O>7l`<Esc>O<Esc>55I <Esc>A|<Esc>Y5PA>18>><Esc>7|R'\<Down>\<Down><Left><Left>O>><Down><Left><Left>\<Down>\<Down><Left><Left><Left>/<Up>/<Down>/<Right><Right>.'<Up>.<Right><Up>.<Right><Right><Up>.<Right><Right><Right><Up>.<Right><Right><Right><Up>.<Right><Right>.<Right><Right><Down>'<Right>.<Down><Right>'o

probably golfable
Explanation:
63i^<Esc>0R jgs<C-O>7l`<Esc>
Bottom line, 63 '^'s, replace the beginning with ' jgs', then move 7 caracters to the right and replace one character with '`'

O<Esc>55I <Esc>A|<Esc>
Above current line, add one line and insert 55 spaces, then a trailing '|'

Y5PA>18>><Esc>
Copy that line and paste it above five times. Cursor ends up in topmost line. Append '>18>>'

7|R'\<Down>\<Down><Left><Left>O>><Down><Left><Left>\<Down>\<Down><Left><Left><Left>/<Up>/<Down>/<Right><Right>.'<Up>.<Right><Up>.<Right><Right><Up>.<Right><Right><Right><Up>.<Right><Right><Right><Up>.<Right><Right>.<Right><Right><Down>'<Right>.<Down><Right>'o
Go to 7th column, enter Replace-mode, and replace spaces with golfer and golf ball trail. Arrow keys are used to move around, since it uses fewer keypresses to use the arrow keys instead of <C-o>+movement for up to three keypresses.


text:
Make a finky syntax checker
You are to make a program that can check the syntax of programs of its same language. For example, if you do it in python, it checks python syntax. Your program will receive a program on standard input, and verify whether or not its syntax is correct. If it is correct, output just "true" on standard output. If not, output just "false" on standard output.
Your program must be incorrect in one instance though. If fed its own source code, it will just output "false" on standard output. This is code golf, so shortest program wins!
Note: Although this isn't technically a quine, you must follow the quine rules, meaning you can't access your source code through the file system or whatever.
Note: You can't claim a program that could not be run due to a syntax error solves this challenge, since it needs to be runnable.

Is using standard and/or 3rd-party libraries allowed? (specifically, to use a working lexer/parser for your language)

Is try:exec(raw_input())... allowed?

@user80551 That won't work for syntactically correct input which loops forever. It's also a slight security risk.

Shouldn't it have the quine tag?

@m.buettner What if we indent raw_input() into a new function and exec it so that the function is never actually called. BTW who he heck cares about security risks in code-golf?

@user80551 Well that kind of security risk would prevent the code from working in all cases, because the executed code might crash the computer, kill the process, etc. Wrapping the code into something that's never executed and then calling exec sounds like a decent idea though! :)

@Sylwester Its not quite a quine, since you don't technically have to produce the code. In fact, you could just put in a syntax error (according to, say, your language's standard) as long as it is ignored by the compiler (and therefore run-able.)

@PyRulez I don't think that would work, because then there would be other programs which would exhibit the same behaviour. To actually make the program behave differently only on itself, I'm pretty sure you'll have to use quine techniques in that you need to check the input against some string which happens to be equal to your own source code (like Ventero did).

Ruby 2.0, 65 76 164 characters
eval r="gets p;$<.pos=0;`ruby -c 2>&0`;p$?==0&&$_!='eval r=%p'%r"

This uses Ruby's built-in syntax checker (ruby -c) to check the input's syntax, which means the code won't be evaluated.
Basic usage example:
ruby syntax.rb <<< foo
true
ruby syntax.rb <<< "'"
false
ruby syntax.rb < synxtax.rb # assumes the file was saved without trailing newline
false

Explanation
This solution is (was) based on the standard Ruby quine:
q="q=%p;puts q%%q";puts q%q

%p is the format specifier for arg.inspect, which can be compared to uneval: when evaling the string returned by arg.inspect, you (usually) get the original value again. Thus, when formatting the q string with itself as argument, the %p inside the string will be replaced with the quoted string itself (i.e. we get something like "q=\"q=%p;puts q%%q\";puts q%q").
Generalizing this type of quine leads to something like the following:
prelude;q="prelude;q=%p;postlude";postlude

This approach has one huge drawback though (at least in code-golf): All code needs to be duplicated. Luckily, eval can be used to get around this:
eval r="some code;'eval r=%p'%r"

What happens here is that the code passed to eval is stored inside r before eval is called. As a result, the full source code of the eval statement can be obtained with 'eval r=%p'%r. If we do this inside the evald code and ensure that the top level of our consists only of the one eval statement, that expression actually gives us the full source code of our program, since any additional code passed to eval is already stored inside r.
Side note: This approach actually allows us to write a Ruby quine in 26 characters: eval r="puts'eval r=%p'%r"
Now, in this solution the additional code executed inside eval consists of four statements:
gets p

First, we read all input from STDIN and implicitly save it into $_.
$<.pos=0

Then, we rewind STDIN so the input is available again for the subprocess we start in the next step.
`ruby -c 2>&0`

This starts Ruby in its built-in syntax checking mode, reading the source code from stdin. If the syntax of the supplied script (filename or stdin) is ok, it prints Syntax OK to its stdout (which is captured by the parent process), but in case of a syntax error, a description of the error is printed to stderr - which would be visible, so we redirect that into nirvana (2>&0) instead.
p$?==0&&$_!='eval r=%p'%r

Afterwards, we check the subprocess's exit code $?, which is 0 if the syntax was ok. Lastly, the input we read earlier ($_) is compared against our own source code (which, as I described earlier, can be obtained with 'eval r=%p'%r).
Edit: Saved 14 characters thanks to @histocrat!

I do believe that your answer is the only one that has truly followed the rules so far.

Very nice! I think you can replace .write  with <<, and >>1<1 with ==0.

@histocrat Huh, somehow missed the part about == in the Process::Status docs. Thanks a lot!

Rebol - 69 or 7475 fully compliant with all rules
New working versions thanks to @rgchris! Not sure if the first fails the "don't access the source" requirement as the interpreter holds the loaded and parsed code it has been passed as a cmd line parameter in the system object (system/options/do-arg) which is used to recognise itself.
probe not any[error? i: try[load/all input]i = system/options/do-arg]

This one follows all of the rules:
do b:[i: input prin block? if i <> join "do b:" mold b [try [load/all i]]]

Example usage:
First printing a valid integer, the second printing an invalid integer.
echo "rebol [] print 123" | rebol --do "probe not any[error? i: try[load/all input]i = system/options/do-arg]"
true
echo "rebol [] print 1w3" | rebol --do "probe not any[error? i: try[load/all input]i = system/options/do-arg]"
false
echo "probe not any[error? i: try[load/all input]i = system/options/do-arg]" | rebol --do "probe not any[error? i: try[load/all input]i = system/options/do-arg]"
false

Fully compliant version:
echo 'rebol [] 123' |r3 --do 'do b:[i: input prin block? if i <> join "do b:" mold b [try [load/all i]]
true
echo 'rebol [] 123a' |r3 --do 'do b:[i: input prin block? if i <> join "do b:" mold b [try [load/all i]]]'
false
echo 'do b:[i: input prin block? if i <> join "do b:" mold b [try [load/all i]]]' |r3 --do 'do b:[i: input prin block? if i <> join "do b:" mold b [try [load/all i]]
false

Explanation:
First version
This uses Rebols built-in load function to parse and load the code from stdin but it does not execute it.
The try block catches any syntax errors and the error? function converts the error to a simple boolean.
The i = system/options/do-arg compares the input from stdin (assigned to i) with the code passed on the do-arg argument (sneaky but very golf :).
any is a great function which returns true if any-thing in the block evaluates to true (for example, any [ false false true ] would return true).
not then just inverts the boolean to give us the correct answer and probe displays the contents of the returned value.
Fully compliant version
Let's go through this in order ...
Assign the word b to the block [] that follows.
Use the do function to interpret the do dialect in the b block.
Inside the b block ...
Set the word i to refer to the contents of stdin (input).
Now, if we join the string "do b:" to the mold'ed block b and it is not equal (<>) to the stdin input i then we try to load the input i.
If the result is a block then we have load'ed the passed data correctly otherwise we would receive a none from the failed if.
Use prin to display the result of block? which returns true if the result is a block. Using prin as opposed to print does not display a carriage return after the output (and it saves us another char).

I think you can shave that down to 36 chars with print not error? try[load/all input]

That checks the syntax... but the problem stipulates that it return false on its own code.  Offhand, ungolfed... c:[c: compose/only [c: (c)]print not error? try[if c = load/all input[1 / 0]]]

I missed the bit about not valid code. How about this?
`(prin none? attempt[load/all input] halt) 1a`

The invalid integer would fail syntax evaluation, but the halt would stop an error in normal operation

"Still can't come up with a way of failing to validate my own code short of checksum'ing the code and returning false if I see my own code."  If you can checksum/secure your program, and include the hash inside the source itself for purposes of comparison, then I would like to enlist your services in my cybercrime syndicate.  Barring that, start from my code, which works.  :-)

A 69 that flunks loaded source: probe not any[error? i: try[load/all input]i = system/options/do-arg]

An 83 that flunks exact source: probe not any [input = mold/only system/options/do-arg error? try [load/all input]] — note: can't be trimmed, has to match the loaded source after molding.

This 78 is definitive, adheres to the quine rule and does not refer directly to source: do b:[probe not any [input = join "do b:" mold b error? try [load/all input]]]

Down to 75: do b:[i: input probe block? if i <> join "do b:" mold b [try [load/all i]]] — could shave one more off by using prin instead of probe at the expense of a newline after true/false.

RebMu at 53: do b:[pb bl? iu a cb ["do b:" ml b] [try [ld/all a]]] Usage: rebmu/args line input

D'oh! RebMu at 49: do B[pb bl? iu a jn "do B" ml b [try [ld/all a]]]

I think this follows the rules:
JS (✖╭╮✖)
function f(s){if(s==f.toString())return false;try{eval(s)}catch(e){return false}return true}
The code will be evaluated if it's correct.
Need to take a look at arrow notation to see if it can't be shortened more.
!function f(){try{s=prompt();return"!"+f+"()"!=s?eval(s):1}catch(e){return 0}}()
After a couple failed attempts and reverts - new version!
!function f(){try{s=prompt();"!"+f+"()"!=s?eval(s):o}catch(e){return 1}}()
And I'm back!
!function f(){try{s=prompt();"!"+f+"()"!=s?eval(s):o}catch(e){return !(e instanceof SyntaxError)}}()
And I'm gone! Unfortunately due to nature of eval and thanks to @scragar (damn you @scragar!) this approach will not work (seeing as throw new SyntaxError is valid JS code, which ticks this method of) - as such, I'd say it's impossible to create a syntax checker (at least using eval or any variation thereof)
(*see the comments!)

Suppose the input is an infinite loop? I suggest you use eval("x=function(){"+t+"}");

@ZoveGames That can be broken with input like }// or };{.

I don't know if this is valid or not according to the rules since it has to be a program, not a function (I think)

@ZoveGames Good point! While the browsers script handling should kick in (loop counter / timeout), it's still easy to write script that will cause the "system" to hang. I'll await with the change until OP specifies the rule about this.

@Abraham - fair point. Though what would comprise as JS program then? Let JS folks play as well ;)

@eithedog Compare with my JS answer, which runs automatically without requiring a function to be called. (Not trying to be rude, just want to make a level playing field)

@Abraham great rebuttal :D will have a think when I'm home

@scragar - throw new Exception(''); gives me ReferenceError: Exception is not defined in console (tried it in jsfiddle as well to make sure that console doesn't override exception handling). Can you explain how can I replicate it?

@eithedog Sorry, got confused on languages, Javascripts base throwable is actually called Error, not Exception. throw new Error('') causes the incorrect behaviour.

@scragar - I forgot as well :D Anyhow - good point; I'm putting it at hold for now (and can't really do anything about it - at work atm)

@scragar - hopefully this version should work against that. I'm not sure if ReferenceError should be treated as invalid syntax (it was earlier), soo... (I guess, thinking about it - why should it, it's a valid syntax :D). On the other hand... let me update the answer again!

@eithedog I've managed to resolve that problem, but it's still not quite safe, since it's still possible to generate SyntaxErrors by using internal eval statements. http://jsfiddle.net/kA2Wv/

@scragar - yup - b('throw new _SyntaxError("")') gives false, and I think any redefining of SyntaxError won't really work. One more thing I was thinking of was to user new Function(s) but don't have time atm to look into that (don't think it will work though)

Javascript - 86 82
!function $(){b=(a=prompt())=='!'+$+'()';try{Function(a)}catch(e){b=1}alert(!b)}()

Paste into your browser's Javascript console to test.
Explanation:
// Declare a function and negate it to call it immediately
// <http://2ality.com/2012/09/javascript-quine.html>
!function $ () {
  // Concatenating $ with strings accesses the function source
  invalid = (input = prompt()) == '!' + $ + '()';
  try {
    // Use the Function constructor to only catch syntax errors
    Function(input)
  }
  catch (e) {
    invalid = 1
  }
  alert(!invalid)
// Call function immediately
}()

Note: @m.buettner brought up the point that the program returns true for a naked return statement, such as return 0;. Because Javascript doesn't throw a syntax error for an illegal return statement until it actually runs (meaning code like if (0) { return 0; } doesn't throw a syntax error), I don't think there's any way to fix this short of writing a Javascript parser in Javascript. For example, consider the code:
while (1) {}
return 0;

If the code is executed, it will hang because of the loop. If the code is not executed, no error will be thrown for the illegal return statement. Therefore, this is as good as Javascript can get for this challenge. Feel free to disqualify Javascript if you feel that this doesn't fulfill the challenge sufficiently.

Now it will not report a syntax error when giving it return 0.

Mm, good one @m.buettner

Haskell - 222 bytes
Note that this uses a true parser. It does not depend on eval like functions of dynamic languages.
import Language.Haskell.Parser
main=interact(\s->case parseModule s of ParseOk _->if take 89s=="import Language.Haskell.Parser\nmain=interact(\\s->case parseModule s of ParseOk _->if take"then"False"else"True";_->"False")

This solution is not particularly pretty but does work.

Does it fail for itself?

It does. The if take ... instruction check to see if the input matches a string literal which is the first part of the program.

Python (95)
c=raw_input()
try:compile('"'if sum(map(ord,c))==7860 else c,'n','exec');print 1
except:print 0

Doesn't that only work for one line of input?

Doesn't work: c=u'#\u1e91' because ord('#') + ord(u'\u1e91') == 7860

Try a hash instead.

PHP - 140
<?exec("echo ".escapeshellarg($argv[1])." | php -l",$A,$o);echo$o|(array_sum(array_map(ord,str_split($argv[1])))==77*150)?"false":"true";//Q

Comment necessary to keep the 'hash' (a shameless copy of s,ɐɔıʇǝɥʇuʎs). Using php -l / lint to check for errors.
$ php finky_syntax_check.php '<?php echo "good php code"; ?>'
true
$ php finky_syntax_check.php '<?php echo bad--php.code.; ?>'
false
$ php finky_syntax_check.php '<?exec("echo ".escapeshellarg($argv[1])." | php -l",$A,$o);echo$o|(array_sum(array_map(ord,str_split($argv[1])))==77*150)?"false":"true";//Q'
false
$ php finky_syntax_check.php '<?exec("echo ".escapeshellarg($argv[1])." | php -l",$A,$o);echo$o|(array_sum(array_map(ord,str_split($argv[1])))==77*150)?"false":"true";//D'
true // note that the last character was changed

C 174
Explanation -Wall needed to produce system error while still being compilable. The syntax error is no return 0; To enter via stdin in Windows console type Ctrl-Z after pasting and press enter.
Golfed
char c[256];int i;int main(){FILE *f=fopen("a.c","w");while(fgets(c,256,stdin)!=NULL){fputs(c,f);}fclose(f);i=system("gcc a.c -o -Wall a.exe");printf("%s",i?"false":"true");}

Ungolfed:
#include <stdio.h>
#include <stdlib.h>
char c[256];int i;
int main()
{
FILE *f=fopen("a.c","w");
while(fgets(c,256,stdin)!=NULL)
{
fputs(c,f);
}
fclose(f);
i=system("gcc a.c -o -Wall a.exe");
printf("%s",i?"false":"true");
}

T-SQL - 110
Fairly simple, I've been wanting to try a challenge on here for a while, finally got round to doing it. This is not the fanciest code, but I had fun nontheless.
The 'golfed' version.
BEGIN TRY DECLARE @ VARCHAR(MAX)='SET NOEXEC ON'+'//CODE GOES HERE//'EXEC(@)PRINT'TRUE'END TRY BEGIN CATCH PRINT'FALSE'END CATCH

A better formatted version.
BEGIN TRY
    DECLARE @SQL VARCHAR(MAX)='SET NOEXEC ON'+'//CODE GOES HERE//'
    EXEC(@SQL)
    PRINT'TRUE'
END TRY

BEGIN CATCH
    PRINT'FALSE'
END CATCH

It's fairly self explanatory, it uses SET NOEXEC on which makes it just parse the query instead of returning any results. the rest is mostly the try/catch that I use to determine what I need to print.
EDIT: I should have added that this will technically fail for itself. because it uses dynamic SQL any single quotes in the input have to be doubled ' -> ''


text:
Reduce html to n characters while keeping the formatting
Almost every language has a built-in function that can split a string at a given position. However, as soon as you have html tags in the string, the built-in function will not work properly.
Your task is to write a program or function which splits a string at the nth character but does not count characters of html tags and will output a valid html. The program must keep the formatting. Spaces outside the html tags may be counted or not counted, as you wish, but must be preserved. You can, however, exchange multiple consecutive spaces into a single space.
Input:

the string
the position to split at (0-based)

These can be taken as program or function arguments or can be read from the standard input.
Output:
The split string which can be returned or written to the standard output.
The input will be valid html, it won't contain any entities (such as  ). Tags that are opened after the character limit should be omitted from the output (see the last example).
Example:
Input: test, 3
Output: tes
Input: more complicated, 7
Output: more co
Input: no html, 2
Output: no
Input: no html root, 5
Output: no ht
Input: no imgmore text, 6
Output: no img
You can use any language and the standard library of the given language. This is code golf, shortest program wins. Have fun!

can the input contain "<"s and ">"s that are not part of a HTML tag?

One should use < and > instead of <>, so no (< or > won't be present either).

Could you include an example where there is mark up after the text node where the split occurs? Like abcd 1?

Are there any other options than a ?

@DavidFrank a (Which makes sense if you consider that b could also be div or img.)

@m.buettner You are right, I updated the rules.

The last rule is really challenging - try this : even more difficult

We need to have a regex answer to celebrate TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚N̐Y̡

This answer is no longer valid with the latest rule.
Javascript (ES6) 94 91
f=(s,l)=>s.split(/(<[^>]+>)/).map(x=>x[0]=='<'?x:[l-->0?y:''for(y of x)].join('')).join('')

f('more complicated', 7);
// 'more co'

Ungolfed:
f=(s,l)=>
    s.split(/(<[^>]+>)/). // split string s by <*>, capture group is spliced into the array
    map(x=> // map function to every item in the array
        x[0]=='<'? // if first character is a <
            x // don't modify the string
        : // else
            [ // array comprehension
                for(y of x) // for every character y in x
                    l-->0? // if l > 0 (and decrement l)
                        y // character y
                    : // else
                        '' // empty string
            ].join('') // join characters in array
        ).
    join('') // join all strings in array

Could you please provide the un-golfed code, or maybe just explanation of what and why the code does? Its currently a bit hard to grasp. Thanks!

@GaurangTandon added ungolfed code with comments

Rebol - 252 chars
c: complement charset"<>"f: func[s n][t: e: 0 to-string collect[parse s[any[(m: 0)copy w[["</"some c">"](-- t)|["<"some c"/>"]|["<"some c">"](++ t)| any c(m: 1)](if e = 0[if m = 1[w: copy/part w n n: n - length? w]keep w]if all[n <= 0 t = 0][e: 1])]]]]

Ungolfed with comments:
c: complement charset "<>"

f: func [s n] [
    t: e: 0             ;; tag level (nesting) & end output flag
    to-string collect [
        parse s [
            any [
                (m: 0)                            ;; tag mode
                copy w [
                      ["</" some c ">" ] (-- t)   ;; close tag
                    | ["<"  some c "/>"]          ;; self-closing / void elements
                    | ["<"  some c ">" ] (++ t)   ;; open tag
                    | any c (m: 1)                ;; text mode
                ] (
                    ;; flag not set so can still output
                    if e = 0 [
                        ;; in text mode - so trim text
                        if m = 1 [
                            w: copy/part w n
                            n: n - length? w
                        ]
                        keep w
                    ]

                    ; if all trimmed and returned to flat tag level then end future output
                    if all [n <= 0  t = 0] [e: 1]
                )
            ]
        ]
    ]
]

Examples in Rebol console:
>> f "test" 3
== "tes"

>> f {more complicated} 7
== {more co}

>> f {no html} 2
== "no"

>> f {no html root} 5
== "no ht"

>> f {no imgmore text} 6
== "no img"

>> f {a} 1
== "a"

>> f {even more difficult} 14
== {even more diff}

>> f {even more difficult} 3
== {eve}

Again this breaks the last rule: tags that are opened after the character limit should be omitted from the output (see the last example). In the last example the span and b tags should be omitted. This rule makes the challenge almost impossible.

@edc65 - Unfortunately (@David Frank) hasn't commented or updated his examples so its unclear whether he wants this behaviour or not?   I was hoping my last example would stir something! Going to leave as is until we get clarification.   Anyway it would only take an additional 17 chars to make it work the way you've suggested.  I didn't particular like the hack so instead rewrote it here (ungolfed) - https://gist.github.com/draegtun/93682f5a07c40bd86e31

(IE) JS - 135
function f(t,n){b=document.body;b.innerHTML=t;r=b.createTextRange();r.moveStart("character",n);r.select();r.execCommand('cut');return b.innerHTML}
Now I feel dirty. But need to start removing all those chars...
function f(t,n)
{b=document.body;b.innerHTML=t;r=b.createTextRange();r.collapse();r.moveEnd("character",n);
r.select();return r.htmlText}

Disclaimer:

run in IE console

This break the last (mad) rule: Tags that are opened after the character limit should be omitted from the output (try my example in comments above).

@edc65 hopefully, updated version checks on all rules

Ruby... Very unrubylike with loops
def split(str,n)

  i = current = 0
  return_str = ""

  while i < n
    if str[current] == "<"
      while str[current] != ">"
        return_str.concat str[current]
        current += 1
      end
      return_str.concat str[current]
      current += 1
    else
      return_str.concat str[current]
      i += 1
      current += 1
    end
  end

  while current < str.length
    if str[current] == "<"
      while str[current] != ">"
        return_str.concat str[current]
        current += 1
      end
      return_str.concat str[current]
      current += 1
    end
    current += 1
  end

  return_str + str[current..-1]
end

This question is marked as codegolf, you should golf your reply. You can start by replacing the variable names to one letter names, using shorter function names and removing white-space wherever you can

authors: Света Гомозина