text:
Create a Simon Clone!
Scenario: while programming you have a sudden nostalgic urge for the '80s and cheesy games.
Requirements: Make a GUI program (text probably won't work) for Simon, the game. Input can be clicking, or pressing a key. You should divide the screen into 4 regions: yellow, blue, red, green. When the game starts, a random color lights up and you activate it. Then, two lights come on, one after the other, and you need to activate those in order, etc. The game ends when you press the wrong color.
Bonuses:
-100 if you include sound (a different note played when pressing each region and when the game shows you the colors)
-25 if you include a score counter.

GUI and code-golf don't generally work together.

This should be doable in Minecraft. Wouldn't surprise me if someone already has. Don't know how one'd submit that here though...

@Kninnug the amount of blocks * bytes per block;)

@Liam McInroy AFAIK a block is 2 bytes for the block ID and 4 bytes to store it's position in the world.

Bash 318 297 281 273 268 244 240-125=115
This is primarily a response to "Text probably won't work"; the following text-based bash script runs fine in Konsole, gnome-terminal etc. on my Ubuntu 14.04 machine. To create the regions of colour it sets the text background color. In fact, adding text makes the game more accessible to color-blind players. To make the game yet more accessible it reads the characters that the player needs to press (it assumes that espeak is installed). It also assumes that the only file matching /d*/ur*/ is /dev/urandom. For the regions of color to be of non-trivial size you probably want to set the text size to be quite large. Also if you want the regions of color to be quadrants, you have to run it in a terminal that is two characters wide.
To play press y, r, g or b as appropriate.
cat <<"EOF"|sed s/E/`echo -e '\E'`/>simon_golf.sh;bash simon_golf.sh;wc simon_golf.sh
d(){ echo Ecx1r09mRx2g10mGx3y11mYx4b14mBx0m$s|sed s/.$1"//
s/[rgyb]..//g
s/x/E[48;5;/g";};x(){ d $c;espeak $c;d j;};l(){
for c in $o;{ eval $1;x;};};f(){ o=$o\ `tr -dc yrgb</d*/ur*|head -c1`
l;l 'read -n1 i;[ $c = $i ]||exit;let s++';f;};f
EOF

This solution contains two non-printable ESC characters. Although these ESC character appear in the preview, they seem to get deleted after submission, so the code above is a wrapper that generates and runs the golfed simon_golf.sh.
See also the original ungolfed version, and the slightly more playable 256 byte version.
The screenshots below are when the yellow light is on and the player's score is 7. The screenshot on the right has been desaturated to simulate colour-blindness.

Way too big for a code golf...

True. I am here more for the "Programming Puzzles" more than the "Code Golf".

I have slightly golfed it now.

Scratch, 1604 – 125 = 1479
I'm here for the fun, not the golf.
Edit: updated scoring method based on community consensus.
Main program:

Individual sprites:

This is the sprite with number 0. The other sprites have the same script, except the number.
Play with it online.
Code used for byte counting: (Using snippet to hide code)

when green flag clicked
set [s v] to [0]
delete (all v) of [a v]
forever
  set [x v] to (pick random (0) to (3))
  add (x) to [a v]
  set [i v] to [1]
  repeat (length of [a v] :: list)
    broadcast (item (i) of [a v] :: list)
    wait (0.3) secs
    change [i v] by (1)
  end
  set [i v] to [1]
  wait until <(x) = [4]>
end

when I receive [0 v]
play sound [0 v]
next costume
wait (0.3) secs
next costume

when this sprite clicked
broadcast [0 v]
wait (0.3) secs
if <[0] = (item (i) of [a v] :: list)> then
  change [i v] by (1)
else
  stop [all v]
end
if <(i) > (length of [a v] :: list)> then
  set [x v] to [4]
  change [s v] by (1)
end

when this sprite clicked
broadcast [3 v]
wait (0.3) secs
if <[3] = (item (i) of [a v] :: list)> then
  change [i v] by (1)
else
  stop [all v]
end
if <(i) > (length of [a v] :: list)> then
  set [x v] to [4]
  change [s v] by (1)
end

when I receive [3 v]
play sound [3 v]
next costume
wait (0.3) secs
next costume

when I receive [1 v]
play sound [1 v]
next costume
wait (0.3) secs
next costume

when this sprite clicked
broadcast [1 v]
wait (0.3) secs
if <[1] = (item (i) of [a v] :: list)> then
  change [i v] by (1)
else
  stop [all v]
end
if <(i) > (length of [a v] :: list)> then
  set [x v] to [4]
  change [s v] by (1)
end

when this sprite clicked
broadcast [2 v]
wait (0.3) secs
if <[2] = (item (i) of [a v] :: list)> then
  change [i v] by (1)
else
  stop [all v]
end
if <(i) > (length of [a v] :: list)> then
  set [x v] to [4]
  change [s v] by (1)
end

when I receive [2 v]
play sound [2 v]
next costume
wait (0.3) secs
next costume

Note: Code automatically generated using scratchblocks generator, modified as somehow the generator doesn't correctly handle decimal numbers (treating 0.3 as 0).
Screenshot:

Note: Please do not press two buttons within 0.3 seconds.

Ha, that's cool. A pause after a correct answer would be good, though, or some congratulatory sound. It sounds like my last move is part of the pattern. Also, I would play the sounds more slowly than the input cap, since rhythm and tone matching is how people (myself, at least) play... still, I like it. +1

Scratch? Srs? Also, the byte count imo should be the total size of the SB2.

@Trimsty Then it would be 126833 bytes (including the wav sound files etc), which is why I said "I'm here for the fun, not the golf."

According to the scoring I suggested here, the score is 60 (27 blocks, 20 chars/digits in constants, 8 operators, 5 variable uses). With bonuses, you get -65.

@ugoren This is actually only a partial answer. There are 4 sprites, and only the script for one is shown, since the other sprites have almost identical scripts except the number. I will update the answer based on your scoring. Thanks.

@ugoren Hmm... perhaps not. I don't quite get how you counted 8 operators.

@ace, I actually counted funcrions, like item..of as operators.

@ugoren Okay, gotcha. Break-down of the count of 150: Main program: 13 blocks, 10 chars in constants, 4 operators and 3 variables, totalling 30. Each sprite: 14 blocks, 10 char in constants, 4 operators and 2 variables, totalling 30. Total count = 30 * 4 + 30 = 150.

Due to updated community consensus, the above comment concerning the scoring method is invalidated.

Mathematica, 409 - 125 = 284
k = 2;
p = Tuples[{0, 1}, 2];
f[c_, p_] :=
 EventHandler[{c, Rectangle[p]},
  "MouseClicked" :> (AppendTo[x, p]; Beep[]; g)]
h[R_] := (i = 1;
  RunScheduledTask[
   H = If[OddQ@i,
     Beep[]; {EdgeForm[{Thickness[0.02], Black}], FaceForm[],
      Rectangle@R[[Ceiling[i/2]]]}, {}]; i++, {.3, 2 Length@R}])
s := (m = 0; x = {}; h[R = RandomChoice[p, k]];)
g := (m++; If[Take[R, m] != x, k = 2; s, If[m == k, k++; s]])
Dynamic@Graphics[{MapThread[f, {{Yellow, Red, Blue, Green}, p}], H},
  PlotLabel -> k]
s

Windows PowerShell (CLI), 272 - 100 - 25 = 147
$d={param($c)cls;sleep -m 99;'R','Y','Blu','Gre'|
%{Write-Host '#' -N -F "$(if($i%4-ne $c){'Dark'})$_";
$i++}};$b={param($c)&$d $c;[console]::Beep(($c+1)*99,700);&$d};
$m=@();$s=0;for(){$m+=0..3|Get-Random;$m|%{&$b $_};$m|%{
if((read-host)-ne $_){$s;exit}&$b $_};$s++;sleep 1}

I've added newlines here to avoid side-scrolling, but it works as one line so the character count is without newlines.
Screenshot:
To play:

Open PowerShell ISE (v3), paste script into text editor, press F5 to run.
Game will light up a color, play a sound, then wait for input
Press a number (0=red, 1=yellow, 2=blue, 3=green) then Enter.
If you are wrong it prints the score and quits. (NB. it might exit your console).
If you are right it goes for two notes.
You have to press Enter between each note when playing the sequence back.

Comments:

"divide the screen into 4 regions" - you didn't say they had to be quarters, so they aren't.
It's hard to see blue light up on the blue background, but it does.
Please run in PowerShell ISE - in the normal prompt "DarkYellow" shows as white.
You could arguably golf another 28 characters off by removing some of the timing (still making the game playable), and by interpreting the rule "sound (a note played when pressing and when the game shows you the colors)" to mean "they can all be the same sound - default error DING", but I think that's too far against the spirit of it.

ZXBasic: 422 - 100 - 25 = 297
This definitely counts as a nostalgic urge for the '80s...
ZXBasic uses a combination of FreeBASIC type commands and ZX Spectrum BASIC to allow loops and repeats which then turn into TZX format to load into a Spectrum emulator.
This version changes the border (although a legend on screen says which key to press).
It plays the same notes as original Simon game (http://en.wikipedia.org/wiki/Simon_%28game%29).
d=0.5:s=0:l=1:t=1:n$="4261":dim m(4)=>{-8,9,1,4}
border 7
while l>0
 cls:a$="":print at 1,1;"Level: ";t;at 2,1;"Score:";s::for i=1 to 4:print at 0,i;paper val(n$(i));ink 0;i:next
 for i=1 to t
  c=1+int(rnd*4)
  border val(n$(c)):beep d,m(c):border 7
  a$=a$+str(c)
 next
 print at 10,1;"your turn"
 p$="":i=1
 do
  pause 100:k$=inkey:print at 6,i;k$
  if k$=a$(i) then s=s+1:print at 2,7;s:beep d,m(val(k$)):i=i+1
  else l=l-1:i=t+1:print "bad luck!"
  end if
 loop until i>t
 t=t+1:pause 25
end while

HTML5 and Javascript, 1118-100-25=993 bytes

Way too bloated HTML+Js version.
Plays sounds through the Web Audio API.
Frequencies of the notes should be the original Simon's ones, colours and colour placement too.
There is an online demo here: http://www.dantonag.it/miniSimon.html. Works in Web Audio compliant browsers (at least Chrome and Firefox, IE doesn't support it, AFAIK).

0

My record is 15 (I'm pretty bad at this game). What's yours?


text:
Tell me the moves
Jack and Jane decided to play a game of chess to while away time.  Unfortunately, Jack is rather bad at visualizing.  He finds it tough to figure the moves possible for a given piece other than a pawn, of course!
Your challenge is to help find Jack the possible options for a given piece (other than a pawn).
In case one has forgotten, the various pieces are denoted by:

K: King
Q: Queen
N: Knight
B: Bishop
R: Rook

As an example, in the following image the Knight is located at d4 and can move to c2, b3, b5, c6, e6, f5, f3, e2.  For a given input:
Nd4

you would produce:
Nc2 Nb3 Nb5 Nc6 Ne6 Nf5 Nf3 Ne2

Rules:

The order of the output doesn't matter as long as all the possible moves are listed
The possible moves can be separated by whitespaces, newlines or any other delimiter
The input can be passed to the program as a parameter or via STDIN
Whitespace in the program shall be counted, so make optimum use of it

This is code golf.  (Please avoid making use of any tools/utilities specifically designed for the purpose.)  The shortest answer wins!

I believe this would work just fine as a code golf

@JanDvorak I was bit confused about that.  Agree with you.

Code golf is the better choice. The obvious is always forgotten: I understand that we can submit either a function or a program, and that input/output can be either stdin/stout or parameters/return value. I'm thinking recursion might be useful here for the queen: f(x)... case "Q": {f("B");f("R")} If the function requires any #includes these should be part of the byte count.

The font in that graphic. xD

Do the possible moves have to be separated by spaces or are newlines OK as well?

the legal moves for a pawn are more convoluted than any other piece (en passant, diagonal capturing, and the 2-square initial move). so i assume jack also has the castling rules memorized?

@ardnew The complexity involved with pawn movements was the precise reason for excluding that.  Moreover, keeping that would have implied keeping track of color and direction too.  (What's Jack?  You mean rook, don't you?)

jack is the chap with poor visualization skills! and you're right- it wouldn't be possible to identify all valid moves without a full board and some limited move history either. so we should ignore all special moves, correct?

@ardnew You are right.  Making the problem overly complicated doesn't seem like a good code-golf problem.  Feeding a chess board as input wouldn't have made much sense.

GolfScript, 94 93 characters
My first ever GolfScript program! This took me many an hour of fumbling around not really knowing what I was doing, but I persisted and I think I managed to learn the language basics and golf it fairly well.
Fully golfed:
{}/8,{97+.3$-.*:>8,{49+.4$-.*:^2$+.[3<>^*4=>^=>^*!.2$|]"KNBRQ"8$?=*{[5$3$@]""+p}{;}if}/;;}/];

Commented and nicer source:
{}/              # tIn fIn rIn
8,{97+           #             fTst
  .3$-.*:>       #                  fDif^2 : >
  8,{49+         #                         rTst
    .4$-.*:^     #                              rDif^2 : ^
    2$+.         #                                     ^>+
    [3<          # These    #                              [validK
     >^*4=       # checks   #                                      validN
     >^=         # do not   #                                             validB
     >^*!        # account  #                                                    validR
     .2$|]       # for null #                                                           validQ]
    "KNBRQ"8$?=  # move;    #                          valid
    *            # * does.  #                          validNotNull
    {[5$3$@]""+p}{;}if  # print? #  fDif^2
  }/;;           #        rIn
}/];

It may look like Claudiu's answer, which is because I referenced his answer, as well as my (unsubmitted) C solution, while making mine. He provided a good specimen of a (relatively) complex, working GolfScript program, and it helped me learn a lot about the language. So thanks, Claudiu!
Being new to GolfScript still, if you guys have any feedback, I'd appreciate hearing it!

Awesome! Nice work =). I'll have to look at it more closely later to see how you got 40 chars shorter than mine. Isn't Golfscript fun?

Python, 217 212 220 217 213 characters
Tied the 213-byte Mathematica solution
R=range(8)
def f((p,x,y)):
 for a in R:
    for b in R:
     A,B=abs(a-ord(x)+97),abs(b-ord(y)+49);C=max(A,B);r=(A+B==3and C<3,C<2,A*B<1,A==B,0)
     if(r['NKRBQ'.index(p)],any(r[1:]))[p=='Q']*C:print p+chr(a+97)+chr(b+49)

I started off by generating all valid moves but that grew too large so the approach is quite similar to the Mathematica one.
>>> f("Nd4")
Nb3
Nb5
Nc2
Nc6
Ne2
Ne6
Nf3
Nf5
>>> f("Qa1")
Qa2
Qa3
Qa4
Qa5
Qa6
Qa7
Qa8
Qb1
Qb2
Qc1
Qc3
Qd1
Qd4
Qe1
Qe5
Qf1
Qf6
Qg1
Qg7
Qh1
Qh8

Nice extracting of string chars with this argument tuple. Too bad it doesn't work anymore in Python 3.

Mathematica, 278 272 264 260 215 213 characters
f=(FromCharacterCode@Flatten[Table[c=Abs[#2-x];d=Abs[#3-y];b=c==d;r=#2==x||#3==y;If[Switch[#-75,0,c~Max~d<2,-9,b,7,r,6,b||r,3,!r&&c+d==3],{p,x,y},##&[]],{x,97,104},{y,49,56}]&@@ToCharacterCode@#,1]~DeleteCases~#)&

Ungolfed version:
f[pos_] := (
  {piece, u, v} = ToCharacterCode@pos;
  board = Flatten[Table[{piece, i + 96, j + 48}, {i, 8}, {j, 8}], 1];
  DeleteCases[
    FromCharacterCode[
      Cases[board, {_, x_, y_} /; Switch[p,
        75, (* K *)
        ChessboardDistance[{x, y}, {u, v}] < 2,
        66, (* B *)
        Abs[u - x] == Abs[v - y],
        82, (* R *)
        u == x || v == y,
        81, (* Q *)
        Abs[u - x] == Abs[v - y] || u == x || v == y,
        78, (* N *)
        u != x && v != y && ManhattanDistance[{x, y}, {u, v}] == 3
        ]
      ]
    ],
    pos (* remove the input position *)
  ]
)&

Example usage:
f["Nd4"]
> {"Nb3", "Nb5", "Nc2", "Nc6", "Ne2", "Ne6", "Nf3", "Nf5"}

The ungolfed version creates a full board, and then selects correct positions with Cases, whereas the golfed version drops invalid moves immediately in the Table command by issuing ##&[], which simply vanishes.

Just curious about the input, is it N4d?  Shouldn't it be Nd4 instead?

@devnull sure, that's a typo. should be Nd4.

Learned a knew function today ChessboardDistance

Per the Mathematica/Wolfram Language documentation, "ChessboardDistance[u,v] is equivalent to Max[Abs[u-v]]." Perhaps you can save characters by using the latter form, especially if you replace Abs[u-v] with |u-v|.

@MichaelStern that's exactly what I'm doing in the golfed version ;). And unfortunately vertical bars don't work for Abs in Mathematica, because they denote alternatives in a pattern.

Haskell 225 220 208 205 200 182
f=fromEnum
m[p,a,b]=[[p,c,r]|c<-"abcdefgh",r<-"12345678",let{s=abs$f a-f c;t=abs$f b-f r;g"K"=s<2&&t<2;g"Q"=g"B"||g"R";g"N"=s+t==3&&(s-t)^2<2;g"B"=s==t;g"R"=s<1||t<1}in s+t>0&&g[p]]

It's going to be difficult to touch Mathematica when that has chess moves built in :rollseyes: (well played m.buettner) I take it all back. Beating Mathematica by 31!
Latest edit: replaced case with a function, inlined filter into comprehension, to beat the entry in R ;)
usage:
ghci> m "Nd4"
["Nb3","Nb5","Nc2","Nc6","Ne2","Ne6","Nf3","Nf5"]

Ungolfed (corresponds to 208 char version before 'u' was inlined):
f=fromEnum -- fromEnum is 'ord' but for all enum types,
           -- and it's in the prelude, so you don't need an extra import.
u piece dx dy= -- piece is the character eg 'K', dx/dy are absolute so >=0.
  dx+dy > 0 && -- the piece must move.
  case piece of
    'K'->dx<2&&dy<2         -- '<2' works because we already checked dx+dy>0
    'Q'->dx<1||dy<1||dx==dy -- rook or bishop move. see below.
    'N'->dx+dy == 3 &&      -- either 2+1 or 3+0. Exclude the other...
         (dx-dy)^2 < 2      -- 1^2 or 3^2, so valid move is '<2', ie '==1'
    'B'->dx==dy             -- if dx==dy, dx/=0 - we checked that.
                            -- other moves with dx==dy are along diagonal
    _->dx<1||dy<1           -- use _ not 'R' to save space, default case is
                            -- the rook. '<1' saves chars over '==0'.
                            -- Again, dx==dy==0 edge case is excluded.
m[piece,file,rank]=       -- the move for a piece. 'parse' by pattern match.
 filter(                    -- filter...
  \[_,newfile,newrank]->    -- ...each possible move...
    u piece                 -- ...by, as everyone noticed, converting char..
      (abs$f file-f newfile) -- differences to absolute dx, dy differences,..
      (abs$f rank-f newrank)) -- and then using special routines per piece.
    [[piece,newfile, newrank] -- the output format requires these 3 things.
      |newfile<-"abcdefgh",newrank<-"12345678"] -- and this just generates moves.

Can you post an ungolfed version too? (if you have one of course)

@swish I don't but I don't mind writing that up.

@swish done. Hope that makes more sense. Ask away if you need something clarified.

Great job! Why do you need add piece to the list [piece,newfile, newrank] if you don't use it in pattern matching, can save you some characters?

It's there for output. You'll see I don't pattern match on it in '...each possible move...'. Originally I didn't have this - chess moves don't require it - but then I noticed the question wanted it, and everyone else did it, so it's only fair.

Another suggestion: why m(p:[a,b]) and not just m[p,a,b]?

@swish oh, good point. I'd previously had m(p:x) there and only started matching a,b in that function when I got down to 212. I'll fix it now, thanks!

I actually didn't even use ChessboardDistance in the golfed version... the name is just too bulky. ^^

Bash, 238
B={19..133..19}\ {21..147..21};K=1\ {19..21};N='18 22 39 41';R={1..7}\ {2..14..2}0;Q=$B\ $R
a=${1%??};b=$[20#${1:1}-200];c=`eval{,} echo '$'$a`;d=({a..h})
for i in $c -${c// / -};do echo $a${d[$[(i+=b)/20]]}$[i%20];done|grep '[a-h][1-8]$'

How it works

The idea is to represent every field on the board by a numeric value, taking its coordinates as a base-20 number and subtracting 200. This way, a1 becomes 20 * 10 + 1 - 200 = 1, h8 becomes 20 * 17 + 8 - 200 = 148, etc.
Now, the possible moves of the Bishop can be represented by (positive or negative) multiples of 19 – same amount of steps up (+20) and to the left (-1) – or 21 – same amount of steps up (+20) and to the right (+1).
The figure's placement after the move is simply the sum of its original position and the movement. After adding those numbers, we have to check if their sum corresponds to a valid field on the board.
Since the base (20) is more than twice as big as the highest possible number (8), the sum cannot wrap around the board, e.g., moving Bh1 seven steps to the right and up will result in an invalid board position.
The line
B={19..133..19}\ {21..147..21};K=1\ {19..21};N='18 22 39 41';R={1..7}\ {2..14..2}0;Q=$B\ $R

enumerates all possible moves of the pieces that are represented by positive numbers.
The commands
a=${1%??};b=$[20#${1:1}-200];c=`eval{,} echo '$'$a`;d=({a..h})

stores the piece's identifier in variable a, the original position's numeric representation in b and the letters a to h in the array d.
After brace expansion, eval{,} echo '$'$a becomes eval eval echo '$'$a (doubly evil), which evaluates to, e.g., eval echo $K, which evaluates to echo 1 19 20 21.
for i in $c -${c// / -};do …; done loops over all possible movements and their negative counterparts.
echo $a${d[$[(i+=b)/20]]}$[i%20] gives the final position after the movement.
grep '[a-h][1-8]$' makes sure that we have a valid board position.

C 634 632 629 625 600 chars
#define F for(;i<4;i++){
#define B ;}break;
#define O x=X,y=Y,
P,X,Y,c,r,x,y,i=0, N[8][2]={{-2,1},{-1,2},{1,2},{2,1},{-2,-1},{-1,-2},{1,-2},{2,-1}},S[4][2]={{1,0},{0,1},{-1,0},{0,-1}},D[4][2]={{-1,1},{-1,-1},{1,1},{1,-1}};
C(){return((0<=c)&(c<8)&(0<r)&(r<9))?printf("%c%c%d ",P,c+'a',r):0;}
M(int*m){c=m[0]+x,r=m[1]+y;C()?x=c,y=r,M(m):0;}
main(int a,char**v){char*p=v[1];P=*p,X=p[1]-97,Y=p[2]-48; switch(P){case 75:F c=S[i][1]+X,r=S[i][0]+Y,C(),c=D[i][1]+X,r=D[i][0]+Y,C()B case 81:F O M(D[i]),O M(S[i])B case 78:for(;i<8;i++){c=N[i][1]+X,r=N[i][0]+Y,C()B case 66:F O M(D[i])B case 82:F O M(S[i])B}}

Any suggestions on how to improve this? This is my first time submitting an answer.

Welcome to Code Golf!  To begin with, you could strip the whitespace in your code.  Remember this is code golf, which implies that the shortest code wins.  So attempt to reduce the size of your program.

Remember to update the character count too!

@devnull are necessary spaces counted?

Yes, the necessary spaces are counted.

In C if no type is specified, int is implied, so you may want to get rid of the ints in your int C(P,c,r) and M(int P,int x,int y,int m[2]) and use a global variable, e.g. z, to replace the c in your M function so you don't need int there as well.

Also, instead of main(int argc,char*argv[]), you can do main(int a,char**v)

@ace how do I get rid of the ints in M()? mingw is complaining about m[2] needing the int in front of it.

@calccrypto Oops, sorry, I thought you can. My fault. By the way, can you use int*m instead of int m[2]?

One more thing: C can be simplified greatly using the ternary operator ?: and by using the return value of printf. (printf returns the number of characters written, so in this case it is always non-zero.) C(P,c,r){return(0<=c)&(c<8)&(0<r)&(r<9)?printf("%c%c%d ",P,c+'a',r):0;}. A minor edit: there is an extra space in M after the if that you can remove.

i forgot about that. thanks!

Right now, you seem not to be counting any newlines. While some of them can be removed, others cannot. Required newlines should definitely contribute to the byte count.

For this specific puzzle, the table of moves you have isn't the shortest solution. Take a look at the other solutions - they mostly use absolute dx and dy differences, and 'min(dx,dy)' and 'max(dx,dy)' can be useful too. We also went for generating all positions on the board once and then per-piece testing if the move was valid, not per-piece generate&test functions.

i know, i know. im just doing using naive method

There's still a whole bunch of whitespace that can be removed: there are unnecessary spaces after open braces and semicolons.

You may benefit from defining something shorter for case.

Golfscript, 144 135 characters
Instead of continuing to try golfing my Python solution, I translated it into Golfscript:
{}/49-:y;97-:x;:N;8,{.x-abs:A
8,{.y-abs:B@[\]$1=:C[B
A+3=\3<&2C>B
A*1<B
A=]81N={(;{|}*}{"NKRB"N?=}if
C*{[N
2$97+@49+]''+p}{;}if
A}/;;}/

Straightforward translation without much golfing so it can most likely be whittled away further. Takes input from stdin without a newline, try it here (1st two lines are to mimic stdin).

Seems to work well!  I hope that someone comes up with a brainf*ck solution too.

Haskell, 300 269 chars
Thanks to bazzargh for help with losing 31 characters...
import Data.Char
f x=filter(x#)[x!!0:y|y<-[v:[w]|v<-"abcdefgh",w<-"12345678"],y/=tail x]
a%b=abs(ord a-ord b)
x#y=let{h=(x!!1)%(y!!1);v=(x!!2)%(y!!2);m=max h v;n=min h v}in case(x!!0)of{'N'->m==2&&n==1;'K'->m==1;'B'->h==v;'R'->n==0;'Q'->('R':tail x)#y||('B':tail x)#y}

Same algorithm as the Mathematica version.  Sample output from ghci:
*Main> f "Nd4"
["Nb3","Nb5","Nc2","Nc6","Ne2","Ne6","Nf3","Nf5"]
*Main> f "Ni9"
["Ng8","Nh7"]

(You didn't ask for sanity checking!)

You can get rid of syntactic whitespace. See my answer here: http://codegolf.stackexchange.com/questions/19255/tips-for-golfing-in-haskell (to be more specific, you want let{h=d(x!!1)(y!!1);...})

Haskell , 446 chars
import Data.Char
a=[-2,-1,1,2]
b=[-1,1]
d=[1..8]
e=[-8..8]
g=[-1..1]
h 'N' c r=[(c+x,r+y)|x<-a,y<-a,3==(sum$map abs[x, y])]
h 'B' c r=[(c+x*z,r+y*z)|x<-b,y<-b,z<-d]
h 'R' c r=[(c+x,r)|x<-e]++[(c,r+y)|y<-e]
h 'Q' c r=h 'B' c r++h 'R' c r
h 'K' c r=[(c+x,r+y)|x<-g,y<-g]
l s=ord s-96
m n=chr$n+96
k ch (c,r)=ch:m c:[intToDigit r]
f (x,y)=all(`elem`[1..8])[x, y]
i n c r=map(k n).filter(/=(c,r)).filter f$h n c r
j s=i(s!!0)(l$s!!1)(digitToInt$s!!2)

Called using the j function
j "Nd4"

I haven't worked with Haskell in a few months, so it didn't end up being as short as most of the other solutions, but I'm sure there are some optimizations to made, mainly with h. I might shorten it in a bit.

q & k [311 262 chars]
There is a potential of reducing some more characters. I will be reducing it in next iteration.
k)o:{n:#m:&(#x)##y;((),x)[m],'n#y}

k)a:`$"c"$(o/)c:+(97;49)+/:!8

k)r:{{|x@<x}'?,/{o[x]y}'[x](|"c"$c)}
k)k:{"c"$(6h$x)+/:(o/)2 3#-1 0 1}
k)n:{"c"$(6h$x)+/:(|:'t),t:o[-1 1;2 2]}
k)b:{"c"$(6h$x)+/:(n,'n),n,'|n:-8+!17}
k)q:{,/(r;b)@\:x}

d:{(`$("rknbq"!(r;k;n;b;q))[x]y)except`$y}
g:{a inter d[x 0]@1_x}

Usage
Rook
g"ra1"
`a2`a3`a4`a5`a6`a7`a8`b1`c1`d1`e1`f1`g1`h1

King
g"ka1"
`a2`b1`b2

Knight
g"na1"
`b3`c2

Bishop
g"ba1"
`b2`c3`d4`e5`f6`g7`h8

Queen
g"qa1"
`a2`a3`a4`a5`a6`a7`a8`b1`b2`c1`c3`d1`d4`e1`e5`f1`f6`g1`g7`h1`h8

Haskell (hypothetical), 248 chars
import Data.Char
f x=filter(o x)[x!!0:y|y<-[v:[w]|v<-"abcdefgh",w<-"12345678"],y/=tail x]
d a b=abs(ord a-ord b)
h x y=(c*(d(x!!1)(y!!1))-(d(x!!2)(y!!2)))+200*c
 where c=d (x!!0)'A'
o x y=elem(chr(h x y))"ਲ਼ੁߏߚߙÈേെ൅ൄൃ൙൪ൻඌඝථ඿౿౾౽౼౻౺౹ಐಏಠಞರಭೀ಼೐ೋೠ೚೰೩"

Unfortunately, every Haskell compiler I can get my hands on right now has problems with Unicode string literals.  Here's the (longer) version that actually works:
import Data.Char
f x=filter(o x)[x!!0:y|y<-[v:[w]|v<-"abcdefgh",w<-"12345678"],y/=tail x]
d a b=abs(ord a-ord b)
h x y=(c*(d(x!!1)(y!!1))-(d(x!!2)(y!!2)))+200*c
 where c=d (x!!0)'A'
o x y=elem(chr(h x y))"\2611\2625\1999\2010\2009\200\3399\3398\3397\3396\3395\3394\3393\3417\3434\3451\3468\3485\3502\3519\3199\3198\3197\3196\3195\3194\3193\3216\3215\3232\3230\3248\3245\3264\3260\3280\3275\3296\3290\3312\3305"

The definition h x y=... is a hash function; valid moves will hash to character numbers that are in the 41-character string.  This gets rid of the need for a "case" statement or equivalent.
I'm not planning to work further on this right now.  It would be fun to see if someone can use a hash function in a more concise language to make a shorter solution.

R, 203 chars
f=function(p,x,y){x=which((l=letters)==x);X=rep(1:8,8);Y=rep(1:8,rep(8,8));A=abs(X-x);L=abs(Y-y);B=A==L;R=!A|!L;i=switch(p,N=A+L==3&A&L,R=R,B=B,Q=R|B,K=(R|B)&A<2&L<2)&A+L>0;paste(p,l[X[i]],Y[i],sep="")}

Ungolfed version:
f = function(p,x,y) {
  x = which(letters == x)  # Gives index between 1 and 8.
  X = rep(1:8, 8)          # 1,2,...,7,8,1,2,.... (8x8).
  Y = rep(1:8, rep(8,8))   # 1,1,...2,2,.....,8,8 (8x8).
  dx = abs(X-x)
  dy = abs(Y-y)
  B = (dx == dy)           # Bishop solutions
  R = (!dx | !dy)          # Rock solutions
  i = switch(p,
             N=dx+dy==3 & dx & dx,  # Sum of dist. is 3, dx and dy must be <> 0.
             R=R,
             B=B,
             Q=R|B,                 # Queen is merge of rock and bishop.
             K=(R|B) & dx<2 & dy<2  # King's distance is < 2.
             ) & (dx+dy > 0)        # Exclude start field.

  paste(p, letters[X[i]], Y[i], sep="")
}

Usage:
> f('N', 'a', 3)
[1] "Nb1" "Nc2" "Nc4" "Nb5"

The solution is even good readable. However I added some parentheses and comments for readers unfamiliar with R code (on the ungolfed version).

source: Stack Exchange

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

sort: votes


text:
I like Pythagorean trees
...so this is a challenge to make me a tree.
Produce a program or function called tree which takes a single integer argument, N and draws a Pythagorean Tree N levels deep, where level 0 is just the trunk.
Each junction of the tree should place the vertex of the triangle at a random point on the perimeter (this point should be uniformly distributed over at least 5 equally spaced points, or uniformly over the whole semicircle).
Optionally your tree may be 3d, be colourful, or be lit according to the time of day. However, this is code-golf, so the smallest file wins.
EDIT: I'll shut the contest and accept the smallest answer when it's a week old

Appears to be a duplicate: http://codegolf.stackexchange.com/questions/18785/create-a-fractal-tree

False. I'm after a different algorithm :)

Ok. Fair enough.  You may want to consider retitling your submission to "Pythagorean Tree".

I like trains? :)

Mathematica, 246 234 221 characters
g[n_,s_:1]:={p=RandomReal[q=Pi/2],r=##~Rotate~(o={0,0})&,t=Translate}~With~If[n<0,{},Join[#~t~{0,s}&/@(#~r~p&)/@g[n-1,s*Cos@p],t[#,s{Cos@p^2,1+Sin[2p]/2}]&/@(r[#,p-q]&)/@g[n-1,s*Sin@p],{Rectangle[o,o+s]}]]
f=Graphics@g@#&

This is certainly not the most elegant/shortest way to do this.
Usage: f[8]

And here are example outputs for f[6] and f[10] respectively.

Somewhat ungolfed:
g[n_, s_:1] := With[{p},
  r = Rotate;
  t = Translate;
  p = RandomReal[q = Pi/2];
  If[n < 0, {},
   Join[
    (t[#, {0, s}] &) /@ (r[#, p, {0, 0}] &) /@ g[n - 1, s*Cos[p]],
    (t[#, s {Cos[p]^2, 1 + Sin[2 p]/2}] &) /@ (r[#, p - q, {0, 0}] &) /@
       g[n - 1, s*Sin[p]],
    {Rectangle[{0, 0}, {s, s}]}
    ]
   ]
  ]
f = Graphics@g[#] &

That is quite impressive. Shame I don't have mathematica to test it - could you add another couple of example outputs?

@ali0sha see edit

You don't need Show in there, and Module is also unnecessary.

@swish Thanks for the Show hint, but how can I get rid of Module? If I don't declare p local, it will be overwritten in the recursive calls, so I couldn't do both calls with the same p, right?

@m.buettner Maybe you can use Block, which is shorter than Module.

@alephalpha Ah, I didn't know Block. That did work!

How about {r = Rotate, t = Translate, p = RandomReal[q = π/2]}~With~If[...?

@swish ah yes, With works too. That's another two characters saved, thanks! :)

CFDG, 134 characters
This one isn't exactly valid, because you cannot limit the recursion depth. But the problem just calls for a solution in this one. :)
startshape t
c(q)=cos(q/2)^2
d(q)=1+sin(q)/2
p=acos(-1)
shape t{w=rand(p)
SQUARE[x .5 .5]t[trans 0 1 c(w) d(w)]t[trans c(w) d(w) 1 1]}

The results look something like this

For another 46 characters (180 characters in total), you can even colour it in:
startshape t
c(q)=cos(q/2)^2
d(q)=1+sin(q)/2
p=acos(-1)
shape t{w=rand(p)
SQUARE[x .5 .5 h 25 sat 1 b .2]t[trans 0 1 c(w) d(w) b .08 .8 h 2.2]t[trans c(w) d(w) 1 1 b .08 .8 h 2.2]}

I know this isn't fully ontopic, but how would a version look if instead of "white noise", you used "brown noise" as angles?

@Synthetica you mean with more angles around 90° and less at 0 and 180?

@Synthetica Similar to this. I couldn't implement actual random-walk noise, because that requires taking an input parameter (the last random value), adjusting it and passing it on. This would make the grammar context-sensitive and is hence not supported by CFDG. I slightly faked it, by simply pushing the random values a bit more towards π/2 using a simple cubic function on the random sample.

I think that your imgur link is broken, and also much though I enjoy the colour and shape, I think I have to disqualify this one for the reason you mentioned

@ali0sha you're right, here is the fixed link. Disqualifying this one is absolutely fair, I just wanted to share Context Free Art with some people and it seemed like a neat approach for the problem. ;) ... Well I've still got the Mathematica answer ^^

Mathematica, 122 characters
Graphics[Polygon/@ReIm@NestList[Join@@({##3}+Cos[t=Random[]Pi/2]E^(I t){I Tan@t(#2-{##}),{##}-#}&)@@@#&,{{0,1,1+I,I}},#]]&

Ungolfed version:
Clear["`*"];
next=Compile[{{z,_Complex,1},t},{z[[4]]-E^(I t) (z[[1]]-z) Cos[t],z[[3]]+I E^(I t) (z[[2]]-z) Sin[t]},RuntimeAttributes->{Listable}];
n=15;
list=ReIm@NestList[next[#,Random[]Pi/2]&,N@{{0,1,1+I,I}},n];
poly=MapIndexed[With[{i=Tr@#2},{ColorData["Rainbow",i/(n+1)],Polygon@Flatten[#,i-1]}]&,list];
Graphics[{Antialiasing->True,poly},PlotRange->{{-7,7},{-1,10}},ImageSize->Large,Background->Black]

3D version, refer to https://mathematica.stackexchange.com/questions/213727/how-to-draw-a-pythagoras-tree-like-this/213827#213827, render by POV-Ray

Coffeescript 377B 352B
I feel dirty writing coffeescript but I can't find a decent drawing package for python3 :-/
Q=(n)->X=(D=document).body.appendChild(C=D.createElement('Canvas')).getContext('2d');C.width=C.height=400;M=Math;T=[[175,400,50,i=0]];S=M.sin;C=M.cos;while [x,y,l,a]=T[i++]
 X.save();X.translate x,y;X.rotate -a;X.fillRect 0,-l,l,l;X.restore();T.push [e=x-l*S(a),f=y-l*C(a),g=l*C(b=M.random()*M.PI/2),d=a+b],[e+g*C(d),f-g*S(d),l*S(b),d-M.PI/2] if i<2**n

Javascript 393B 385B
Slightly prettier in javascript and I'm much happier with the for-loop but without the [x,y,z]=A syntax I just can't make it short enough to beat coffeescript
function Q(n){X=(D=document).body.appendChild(C=D.createElement('Canvas')).getContext('2d');C.width=C.height=600;M=Math;T=[[275,400,50,i=0]];while(A=T[i++]){X.save();X.translate(x=A[0],y=A[1]);X.rotate(-(a=A[3]));X.fillRect(0,-(l=A[2]),l,l);X.restore();S=M.sin;C=M.cos;i<M.pow(2,n)&&T.push([e=x-l*S(a),f=y-l*C(a),g=l*C(b=M.random()*M.PI/2),d=a+b],[e+g*C(d),f-g*S(d),l*S(b),d-M.PI/2])}}

Got to say I'm a bit galled this is almost twice as long as the mathematica solution :-/ see it in action: http://jsfiddle.net/FK2NX/3/

A few suggestions: You can save at least 16 characters by using semicolons instead of line breaks in CoffeeScript. In both cases, if any of the methods on X return X, you can chain them. And you can save another good bunch of characters by saving M.sin and M.cos in single-character variables.

Unfortunately context operations don't return the context, which I was pretty upset by. Also, you can rename M.sin to M.s, but the line M.s=M.sin takes up more characters than it saves... I'll look at stripping out the spaces.

No, you can just do s=M.sin.

How come I can do S=M.sin, but not R=X.rotate ?

I suppose rotate uses this, and sin doesn't. You'd need to do something like R=X.rotate.bind(X), but that's probably not worth it any more.

You could reduce the JavaScript to 378 with: X=(D=document).body.appendChild(C=D.createElement("Canvas")).getContext("2d"),n=prompt();C.width=C.height=800;M=Math;for(T=[[275,400,50,i=0]];A=T[i++];)X.save(),X.translate(x=A[0],y=A[1]),X.rotate(-(a=A[3])),X.fillRect(0,-(l=A[2]),l,l),X.restore(),S=M.sin,C=M.cos,i<M.pow(2,n)&&T.push([e=x-l*S(a),f=y-l*C(a),g=l*C(b=M.random()*M.PI/2),d=a+b],[e+g*C(d),f-g*S(d),l*S(b),d-M.PI/2])

Postscript, 322 270
Edit: It appears that realtime can't be used as proper random generator seed. Therefore, we'll use environment variable for this purpose and run the program like that:
gs -c 20 $RANDOM -f tree.ps

or
gswin32c -c 20 %RANDOM% -f tree.ps

Now our trees are less predictable. 14 bytes are added to total count. Other changes: 1) Program argument is now passed on command line. 2) No explicit iteration counter - stack size serves for this purpose (left branch rotation angle is stored on stack, to draw right branch, later). 3) There's no named variable for required depth - stack size is its offset, on stack. It's left there on exit, i.e. it is not consumed.
srand
250 99 translate
50 50 scale
/f{
    count
    dup index div dup 1 le{
        0 exch 0 setrgbcolor
        0 0 1 1 rectfill
        0 1 translate
        rand 5 mod 1 add 15 mul
        gsave
        dup rotate
        dup cos dup scale
        f
        grestore
        dup cos dup dup mul
        exch 2 index sin mul translate
        dup 90 sub rotate
        sin dup scale 1
        f
        pop
    }{pop}ifelse
}def
f

I think it's pretty obvious - graphics state is prepared and f procedure is called recursively for each consecutive level of depth, twice - for 'left' and 'right' branches. Working with rectangle of 1x1 size (see original scale) saves the trouble of multiplying by side length. Angle of rotation of left branch is randomized - one of 5 random equally spaced divisions is used - I think it prevents possible ugly cases for uniform randomness.
It might be slow for required depth of more than 20 or so.
Next is golfed version, using ASCII-encoded binary tokens (see luser droog's answer from linked topic). Note, cos, sin, rand can not use this notation.
/${{<920>dup 1 4 3 roll put cvx exec}forall}def srand 250 99<AD>$ 50 50<8B>$/f{count(8X68)$ 1 le{0(>)$ 0<9D>$ 0 0 1 1<80>$ 0 1<AD>$ rand 5 mod 1 add 15<~CecsG2u~>$ cos<388B>$ f(M8)$ cos(88l>)$ 2(X)$ sin<6CAD38>$ 90<A988>$ sin<388B>$ 1 f pop}{pop}(U)$}def f

.
/${{<920>dup 1 4 3 roll put cvx exec}forall}def
srand
250 99<AD>$
50 50<8B>$
/f{
count(8X68)$
1 le{
0(>)$ 0<9D>$
0 0 1 1<80>$
0 1<AD>$
rand 5 mod 1 add 15
<~CecsG2u~>$
cos<388B>$
f
(M8)$
cos(88l>)$
2(X)$ sin<6CAD38>$
90<A988>$ sin<388B>$
1
f
pop
}{pop}(U)$
}def
f

I think the style here is that command line arguments need to be added so this scores 344... I have to say that even by codegolf standards this is pretty impressively foreign-looking. How far could you get it with binary tokens? You're not far off Mathematica surely

@ali0sha, -dGraphicsAlphaBits is a flag to anti-alias output to prevent jagged edges of larger squares, it can be omitted (or 'hidden' in e.g. environment variable). Some people may like it more without this flag (tree leaves get more 'volume'). Well, those 20 bytes not that much important. I'd say 20-25% off using ascii-encoded binary tokens (judging by linked topic answer). Maybe 50% off without ascii-encoding, 2 binary bytes per system name token. Will look like some usually winning languages ;)

I think you should do it - make it a bit more competitive in here :)

all_licenses: 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/


text:
Shortest code for a codegolf-style character counter without using bash
You have to write a program that will count all the characters in specified source file so that people entering a code golf competition can see their score. You do not need to ignore comments (it is code golf) in your program but newlines should be counted as a character. The number of characters must be printed to stdout. Shortest code wins!
Example in python:
import sys

try:
    content = open(sys.argv[1], "r").read()
except IndexError, e:
    print("No file specified")
    sys.exit(1)
except IOError, e:
    print("File not found")
    sys.exit(1)

count = 0
for i in list(content):
    if(i!=''):
        count+=1

print(str(count)+" characters long")

Note: you cannot use the bash command wc -c.

5 chars in bash. wc -c. This is trivial.

"Note: you cannot use the bash command wc -c." You can't fix a broken problem by banning one example of why it's so broken.

Question seems trivial. Also banning 'bash' while not banning the other '*sh' languages is essentially pointless.

In the future, you might want to run your questions by the sandbox to get help ironing out any problems.

Dash, 18
tr \\0-ÿ \\n|wc -l

Reads from STDIN. Doesn't use wc -c or Bash.

bash+coreutils, 7 chars
stat $1


text:
Calculate your stack exchange reputation
Background:
I often find that, when browsing a Stackexchange site, I begin to wonder how people get the amount of reputation that they have. I know I can always count on codegolf SE to solve my problems, so here it is:
Create a program that will accept a positive integer which represents a person's reputation. We will ignore bounties, and say that these are the only ways to gain/lose rep on SE (full table here):

Every account starts out with 1 rep and cannot go below that
Your question is upvoted = +5
Your answer is upvoted = +10
Your question is downvoted = -2
Your answer is downvoted = -2
You downvote an answer = -1
Your answer is accepted = +15
You accept an answer = +2

Your program must figure out how many of those actions occurred on that user's account to get to the rep they have. It must figure out the shortest number of actions to get to this level of rep. Examples:

Input: 11
Output: 1 answer upvote
Input: 93
Output: 6 answer accepts, 1 answer accepted

In these examples when I say 'question upvote', it means that person's queston got upvoted. When I say 'answer downvoted', it means they downvoted someone else's answer.
Rules:
code-golf, so the shortest code that can do this wins.

There are an infinite number of ways to obtain any given reputation. Only implementing "answer upvote" and "answer downvoted" is enough to always find a way, so there is no impetus to use any wider subset of the score changes. Is this what you intended?

@algorithmshark edited. You must find the smallest number of actions that will get you there

"""I often find that, when browsing a Stackexchange site, I begin to wonder how people get the amount of reputation that they have.""" vs """You must find the smallest number of actions that will get you there""". The 2nd quote is not neccessarily the correct answer to the first quote.

@algorithmshark In general I agree with your comments. However 6 answer accepts + 1 answer accepted is 615+2=92, not 93! I can't see a way to do it in 7 actions, but I can do it in 8: 6 answer accepts, one question upvote, one question downvote: 615+5-2=93. Doctor, if there is more than one possibility for "smallest number of actions" do we have to find all of them or just one?

Do we need to take into account that we can downvote only after reaching certain level of rep?

@steveverrill you start with 1 rep

@ace - nope. only the rules listed above

As @Dennis shows in the explanation of his answer, this is fairly trivial now that the question has evolved from having infinite answers. Strictly, you don't say the "when I say" phrases.

I suggest to remove one of the -2events.

There is missing one: you get -5 reputation when a user is removed. I don't know what that means, but it's a valid one. You can check my reputation history and see for yourself. I will provide a printscreen if needed.

@IsmaelMiguel it's someone who upvoted an answer of yours, so you lost that upvote. I suppose for the purpose of this question that may just count as not ever having received that upvote in the first place.

I've sort-of corrected the output to the test case, in the sense that it now has an interpretation which gives the correct answer. But it's horribly ambiguous which of "answer accepts" and "answer accepted" means that I performed the action, and which means that someone else performed the action on my answer.

@m.buettner but you only lose 5, not the 10

@Ismael, sorry I meant a question, not an answer.

@m.buettner You still lose only 5, it's a totally different event.

@IsmaelMiguel http://meta.stackexchange.com/questions/126470/what-does-user-was-removed-mean-and-why-did-my-reputation-change-because-of-it

@TheDoctor That gives a whole new twist to this loss of reputation for an user deleting it's account... You even have to calculate the current reputation that the user had. But still, it's a totally different event from the ones listed.

I didn't include that in the possible rep actions for a reason

bash, 23: echo random glitch, +$1

At least we're not all traveling salesmen.

But... association bonus?

Oh wait. You can only downvote when you have a certain rep. (And its answer only too)

Golfscript, 162 144 bytes
{{}if}:?;~.)15/:^15*-:~3>1~8>' answer ':A' question 'if'upvote'++?^^A'accept'+:C+^1>{'s'+}??~5%:,4<,1>&1C'ed'++?,2%!1A'downvote'++,4<{'d'+}??]n*

How it works
The general idea is exactly the same as in my Bash answer.
{{}if}:?;         # Create an `if' statement with an empty `else' block.
                  #
~.)15/:^          # Interpret the input string, subtract 1 from its only element (the
                  # reputation score), divide by 15 and save the result in `^'. This gives
                  # the number of accepted answers.
                  #
15*-:~            # Multiply the number of accepted answer by 15 and subtract the product
                  # from the reputation score. Save the result in `~'.
                  #
3>                # If the result is greater than 3:
                  #
  1               # Push 1 on the stack.
                  #
  ~8>             # If the result is greater than 8:
                  #
    ' answer ':A  # Push `answer' on the stack. Either way, save the string in `A'.
                  #
    ' question '  # Otherwise, push `question' on the stack.
                  #
  if              #
                  #
  'upvote'++      # Push `upvote' on the stack and concatenate the three strings.
                  #
?                 #
                  #
^                 # If the number of accepted answers is positive:
                  #
  ^A'accept'+:C+  # Push the number, concatenated with the string ` answer accept', on the
                  # stack. Either way, the string in `C'.
                  #
  ^1>             # If the number of accepted answers is greater than 1:
                  #
    {'s'+}        # Cocatenate the previous string with `s', for proper pluralization.
                  #
  ?               #
                  #
?                 #
                  #
~5%:,             # Calculate the reputation score modulus 5. Save the result in `,'.
                  #
4<,1>&            # If the result is less than 4 and greater than 1:
                  #
  1C'ed'++        # Push the string `1 answer accepted' on the stack.
                  #
?                 #
                  #
,2%!              # If the result is odd:
                  #
  1A'downvote'++  # Push the string `1 answer downvote' on the stack.
                  #
  ,4<             # If the result is less than 4:
                  #
    {'d'+}        # Concatente the previous string with `d'.
                  #
  ?               #
                  #
?                 #
                  #
]n*               # Join the array formed by all strings on the stack, separating the
                  # strings by newlines. This is the output.

Bash, 247 202 192 bytes
n=$1 bash <(sed 's/E/)echo /;s/C/ Aaccept/;s/A/answer /
s/.*)/((&)\&\&/'<<<'a=(n+1)/15,a-1)s=s;q=question
aE$aC$s
r=n%5,r-4)d=d&&
r>1E1Ced
1-r%2E1 Adownvote$d
n-=15*a,n>8)q=A
n>3E1 $q upvote')

How it works
After the sed command does it job, the following bash script gets executed:
((a=(n+1)/15,a-1))&&s=s;q=question
((a))&&echo $a answer accept$s
((r=n%5,r-4))&&d=d&&
((r>1))&&echo 1 answer accepted
((1-r%2))&&echo 1 answer downvote$d
((n-=15*a,n>8))&&q=answer
((n>3))&&echo 1 $q upvote

To obtain the optimal solution (minimal number of events to get n reputation), it suffices to compute the number of accepted answers (a) necessary to get to a reputation below 16 (1 answer accept) and handle the residue as follows:
1  (no rep change)
2  answer accepted, answer downvoted
3  answer accepted
4  question upvote, answer downvote
5  question upvote, answer downvoted
6  question upvote
7  question upvote, answer accepted, answer downvoted
8  question upvote, answer accepted
9  answer upvote, answer downvote
10 answer upvote, answer downvoted
11 answer upvote
12 answer upvote, answer accepted, answer downvoted
13 answer upvote, answer accepted
14 answer accept, answer downvote
15 answer accept, answer downvoted

Thanks for the explanation, it's not simple to deal with -2 and -1 downvotes.

Perl, 500 263 256 208 bytes
Script rep.pl:
$_=1+pop;sub P($){print$=,@_,$/}$;=" answer ";$:="$;downvote";($==$_/15)&&P"$;accept"."s"x($=>1);$_%=15;$==1;P"$;upvote",$_-=10if$_>9;P" question upvote",$_-=5if$_>4;P"$;accepted"if$_>2;P$:."d"if$_%2;P$:if!$_

Usage
The input is expected as positive integer, given as argument to the script. The different actions are output as lines.
Tests
perl rep.pl 11
1 answer upvote

perl rep.pl 93
6 answer accepts
1 answer accepted

perl rep.pl 1

perl rep.pl 4
1 question upvote
1 answer downvote

perl rep.pl 12
1 answer upvote
1 answer accepted
1 answer downvoted

perl rep.pl 19
1 answer accept
1 question upvote
1 answer downvote

perl rep.pl 34
2 answer accepts
1 question upvote
1 answer downvote

perl rep.pl 127
8 answer accepts
1 question upvote
1 answer accepted
1 answer downvoted

perl rep.pl 661266
44084 answer accepts
1 question upvote

Ungolfed
$_ = pop() + 1; # read the reputation as argument,
                # remove the actionless start reputation
                # and add a bias of two to calculate
                # the answer accepts in one division.

# Actions
# -------
# answer accepts:      Your answer is accepted    = +15
# answer upvotes:       Your answer is upvoted     = +10
# question upvotes:     Your question is upvoted   = +5
# answers accepted:     You accept an answer       = +2
# answers downvoted:    You downvote an answer     = -1
# answer downvotes:     Your answer is downvoted   = -2
# (questions downvoted: Your question is downvoted = -2) not used

# Function P prints the number of actions in $= and
# the action type, given in the argument.
# The function is prototyped "($)" to omit the
# parentheses in the usage.
sub P ($) {
    print $=, @_, $/ # $/ is the line end "\n"
}
# abbreviations,
# special variable names to save a space if a letter follows
$; = " answer ";
$: = "$;downvote";

# Calculation and printing the result
# -----------------------------------
($= = $_ / 15) && # integer division because of the special variable $=
P "$;accept" .
  "s" x ($= > 1); # short for: ($= == 1 ? "" : "s")
$_ %= 15;
$= = 1;           # now the action count is always 1 if the action is used
P "$;upvote",         $_ -= 10 if $_ > 9;
P " question upvote", $_ -=  5 if $_ > 4;
P "$;accepted"                 if $_ > 2;
P $: . "d"                     if $_ % 2;
P $:                           if ! $_

Older version
$_ = pop() + 1; # read the reputation as argument
                # subtract start reputation (1)
                # add bias (2)

# Actions
# -------
# $= answer accepts:      Your answer is accepted    = +15
# $b answer upvotes:      Your answer is upvoted     = +10
# $c question upvotes:    Your question is upvoted   = +5
# $d answers accepted:    You accept an answer       = +2
# $e answers downvoted:   You downvote an answer     = -1
# $f answer downvotes:    Your answer is downvoted   = -2
# -- questions downvoted: Your question is downvoted = -2

# Calculaton of answer accepts by a simple division that is
# possible because of the bias.
$= = $_ / 15; # integer division because of the special variable $=
$_ %= 15;

# The older version of the calculation can be simplified further, see below.
# Also the older version did not use the bias.
#
# function E optimizes the construct "$_ == <num>" to "E <num>"
# sub E {
#     $_ == pop
# }
#
# $d = $e = 1 if E 1;       #  1 =     +2 -1
# $d++ if E 2;              #  2 =     +2
#
# $c = $f = 1 if E 3;       #  3 =  +5 -2
# $c = $e = 1 if E 4;       #  4 =  +5 -1
# $c++ if E 5;              #  5 =  +5
# $c = $d = $e = 1 if E 6;  #  6 =  +5 +2 -1
# $c = $d = 1 if E 7;       #  7 =  +5 +2
#
# $b = $f = 1 if E 8;       #  8 = +10 -2
# $b = $e = 1 if E 9;       #  9 = +10 -1
# $b++ if E 10;             # 10 = +10
# $b = $d = $e = 1 if E 11; # 11 = +10 +2 -1
# $b = $d = 1 if E 12;      # 12 = +10 +2
#
# $=++, $f++ if E 13;       # 13 = +15 -2
# $=++, $e++ if E 14;       # 14 = +15 -1

$b++, $_ -= 10 if $_ > 9;
$c++, $_ -=  5 if $_ > 4;

# Now $_ is either 0 (-2), 1 (-1), 2 (0), 3 (1), or 4 (2).
# The number in parentheses is the remaining reputation change.

# The following four lines can be further optimized.
# $f++        if ! $_;    # "! $_" is short for "$_ == 0"
# $e++        if $_ == 1;
# $d = $e = 1 if $_ == 3;
# $d++        if $_ == 4;

# Optimized version of the previous four lines:

$f++ if ! $_;
$e++ if $_ % 2;
$d++ if $_ > 2;

# function P optimizes the printing and takes the arguments for "print";
# the first argument is the action count and the printing is suppressed,
# if this action type is not needed.
sub P {
    print @_, $/ if $_[0]
    # $/ is "\n"
}

# some abbreviations to save some bytes
$; = " answer ";
$D = "$;downvote";

# output the actions

P $=, "$;accept", ($= == 1 ? "" : "s");
P $b, "$;upvote";
P $c, " question upvote";
P $d, "$;accepted";
P $e, $D, "d";
P $f, $D

Edits

Case 4 is fixed.
This also simplifies the calculation that is now done without a loop.
Unreachable plural "s" removed, function S no longer needed.
Calculation optimized, function E no longer needed.
Bias of 2 added for optimized calculation.
Larger rewrite to remove most variables some other tricks to save some bytes.

according to this, Jon Skeet has 44084 answer accepts & 1 answer upvote

@TheDoctor: According to the question, these are the minimal number of actions to get a reputation of 661266.

R, 454 421
r=as.integer(commandArgs(T)[1])-1;p=function(...){paste(...,sep='')};a='answer ';b='accept';e='ed';f='d';v='vote';d=p('down',v);u=p('up',v);q='question ';z=c();t=r%/%15;if(t>0){z=c(p(t,' ',a,b));r=r%%15;};if(r%in%(8:12))z=c(z,p(a,u));if(r%in%(3:7))z=c(z,p(q,u));if(r%in%c(1,2,6,7,11,12))z=c(z,p(a,b,e));if(r%in%(13:14))z=c(z,p(a,b));if(r%in%c(3,8,13))z=c(z,p(a,d));if(r%in%c(1,4,6,9,11,14))z=c(z,p(a,d,f));cat(z,sep=', ')

Thanks to Dennis for his answer which helped me a lot.
Ungolfed version
# read input
r = as.integer(commandArgs(T)[1]) - 1

# shortcut to join strings (... will pass the parameter to paste() *as is*)
p = function(...) {paste(..., sep = '')}

# strings
a = 'answer '; b = 'accept'; e = 'ed'; f = 'd'
v = 'vote'; d = p('down',v); u = p('up',v)
q = 'question '

z = c()

# +15
t = r %/% 15;
if (t > 0) {
    z = c(p(t,' ',a,b))
    r = r %% 15
}

if (r %in% (8:12))              z = c(z,p(a,u));    # answer upvote
if (r %in% (3:7))               z = c(z,p(q,u));    # question upvote
if (r %in% c(1,2,6,7,11,12))    z = c(z,p(a,b,e));  # answer accepted
if (r %in% (13:14))             z = c(z,p(a,b));    # answer accept
if (r %in% c(3,8,13))           z = c(z,p(a,d));    # answer downvote
if (r %in% c(1,4,6,9,11,14))    z = c(z,p(a,d,f));  # answer downvoted

# print operations
cat(z,sep = ', ')

JavaScript - 270 237 227 206 192 characters
p=prompt,r=p()-1,a="1answer ",v="vote,";s=(r/15|0)+"answer accept,",r%=15;if(r>9)s+=a+"+"+v,r-=10;if(r>2)s+="1question +"+v,r-=5;r>0?s+=a+"accepted,":0;r<-1?s+=a+"-"+v:0;p(r&1?s+=a+"-voted":s)

Exactly as many chars as Bash (yeah!), and beats Python and Perl :) It cuts down the reputation until 14 after which it takes after which it takes the other necessary actions, completely loop-style.
EDIT 1: Converted \ns to ,s and converted one if block to ternary, and better flooring with short names.
EDIT 2: Big thanks to Alconja who helped me cut down 11 chars. After which I made some more corrections to cut down 2 more chars.

Older Version:
r=prompt()-1,a="1answer ",q="1question ",v="vote,";s=(c=r/15|0)+"answer accept,",r-=c*15;if(r>9)s+=a+"+"+v,r-=10;if(r>2)s+=q+"+"+v,r-=5;r>0?s+=a+"accepted,":0;if(r<-1)s+=a+"-"+v;r&1?s+=a+"-voted":0;alert(s)

Test:
INPUT: 42
OUTPUT:
2answer accept,1answer +vote,1answer accepted,1answer -voted

/*I sincerely hope the output is clear and easy to make out*/

INPUT: 1337
OUTPUT:
89answer accept,1answer accepted,1answer -voted

Ungolfed Code:
// different version from the golfed code
rep = prompt() - 1
string = ""

function $(z, c, k){
  while(rep > 0 && rep >= z - 2) c += 1 , rep -= z;

  if(c) string += c + k + "\n"
}

a=" answer ", q=" question "

$(15, 0, a + "accept")
$(10, 0, a + "upvote")
$(5, 0, q + "upvote")
$(2, 0, a + "accepted")

function _(z, c, str){
  while(rep <= z) c += 1, rep -= z

  if(c) string += c + str + "\n";
}

_(-2, 0, a + "downvote");
_(-1, 0, a + "downvoted");

alert(string);

Why is the first one Firefox only?

@TheDoctor It utilizes the feature of JS currently available only in Firefox - function name(args){} becomes name=(args)=>{} and thus saves a lot of bytes.

@TheDoctor I have updated my program to be cross-browser, and it is now much shorter than before !

Your current version only uses q once, so you can inline it. Also, you can drop the c variable and do a r%=15 instead of r-=c*15. Should bring you down to 195 chars (r=prompt()-1,a="1answer ",v="vote,";s=(r/15|0)+"answer accept,",r%=15;if(r>9)s+=a+"+"+v,r-=10;if(r>2)s+="1question +"+v,r-=5;r>0?s+=a+"accepted,":0;if(r<-1)s+=a+"-"+v;r&1?s+=a+"-voted":0;alert(s)).

@Alconja Wow! Thanks a lot! I finally am very very close to Bash ! Thanks a lot again!

@Alconja And with some more corrections, I am exactly at par with Bash :D

JavaScript - 273 256 235
p=prompt(s=j="\n")-1;z=" answer",w=" accept",x=" upvoted"+j,y=w+"ed",v=" question",u=" downvoted";if(m=p/15|0)s+=m+z+y+j;r=p-m*15;if(m=r/10|0)s+=m+z+x;r-=m*10;if(m=r/5|0)s+=m+v+x;r-=m*5;n=r/2|0;if(m=r-=n*2)n++,s+=m+u+z+j;alert(s+n+y+z)

Combined calculation and output, and golfed further to a total of 287.
Edit: took out some variables for a few shorter.
Removed Math.Floor for |0 approach.
Moved some initialisation to the prompt() param, removed some brackets, alert with final string append.

Welcome to codegolf.SE ! The instructions say: "Create a program that will accept a positive integer" -> so you will need to use prompt, and can't hard code the value.

No worries, added prompt(), which bumps it up to 161.

Following @GaurangTandon's smarter prompt()-1 and alert output approach to get this down further. Reduced some of the hardcoded string storage too.

C# - 391
A bit long, and I haven't tested this thoroughly (much). :)
class R{void Main(string[] a){var r=int.Parse(a[0])-1;var a=new[]{15,10,5,2};var o=new List<string>();Func<int,string>y=z=>{var w="";if(z==15)w=" answer accepted";if(z==10)w=" answer upvotes";if(z==5)w=" question upvotes";if(z==2)w=" answer accepts";return w;};foreach(var x in a)if(r/x>0){o.Add(r/x+y(x));r-=(r/x)*x;}if(r==1)o.Add("1 question downvotes");Console.Write(string.Join(", ",o));

Un-golfed - NEW
class R
{
    void Main(string[] a)
    {
        var r = int.Parse("122")-1; // subtracts 1 from total rep
        var a = new[] {15,10,5,2};
        var o = new List<string>();

        Func<int,string> y =
            z =>
                {
                    var w="";
                    if(z==15) w=" answer accepted";
                    if(z==10) w=" answer upvotes";
                    if(z==5) w=" question upvotes";
                    if(z==2) w=" answer accepts";
                    return w;
                };

        foreach(var x in a) {
            if (r/x>0) {
                o.Add(r/x+y(x));
                r-=(r/x)*x;
            }
        }

        if(r==1)
            o.Add("1 question downvotes");

        Console.Write(string.Join(", ",o));
    }
}

Un-golfed - OLD (409)
class R
{
    void Main(string[] a)
    {
        var r = int.Parse(a[0])-1; // subtracts 1 from total rep
        var v = new[] {" question"," answer"," downvotes"," upvotes"," accepts"," accepted"};
        var o = new List<string>();

        // Starts from 15, then checks all the lower values.
        if (r/15>0) {
            o.Add(r/15+v[1]+v[5]);
            r-=(r/15)*15; // automatic rounding down due to int
        }
        if(r/10>0) {
            o.Add(r/10+v[1]+v[3]);
            r-=(r/10)*10;
        }
        if(r/5>0) {
            o.Add(r/5+v[0]+v[3]);
            r-=(r/5)*5;
        }
        if(r/2>0) {
            o.Add(r/2+v[1]+v[4]);
            r-=(r/2)*2;
        }
        if(r==1) {
            o.Add("1"+v[0]+v[2]);
        }
        Console.Write(string.Join(", ",o));
    }
}

Test:
> prog.exe 120

7 answer accepted, 1 answer upvotes, 2 answer accepts

Python - 213 207
p,k=__import__('itertools').combinations_with_replacement,int(input())
t,m,u=[5,10,-2,-1,15,2],[],iter(range(0,k))
while not m:m=list(filter(lambda v:k-1==sum(v),p(t,next(u))))
print(''.join(map(chr,m[0])))

Curse you long function names!
Example: (ignore the trailing newline)
$ echo "93" | python per.py | hexdump -C
00000000  0f 0f 0f 0f 0f 0f 02 0a                           |........|

$ echo "11" | python per.py | hexdump -C
00000000  0a 0a                                             |..|

How do you display number of questions and answers votes, etc.? Your code doesn't contain these strings (see the other answers), so I'm afraid the output is not compliant with the rules.

The output is golfed too since there was no requirement about that. It doesn't treat downvoted question/answers separately as both give -2 points, the resulting list that is printed is the shortest sequence to achieve the score.

Yes, the rules don't go into details about this point. But you can notice that in the other answers the output is standard and display X answer accepts, Y answer upvotes, etc. But that's not a problem since you don't have the shortest code.

@LemonBoy I have tried this on three interpreters and it doesn't work. All say EOF. Can you please point me to a compiler which works (and which I should keep for future reference) ?

@GaurangTandon I've tested it with both python2.7.6/3.4.0 and works just fine.

@LemonBoy That's great! But I am asking you to point me to the online interpreter where you have tested, so I keep it for future reference when I learn Python.

@GaurangTandon huh? I've tested it with my local install of python. Anyway the first site that popped up when I searched for an online python repl, repl.it, runs the code just fine.

@LemonBoy Looks like it's something wrong with me, here's the code I pasted http://repl.it/Qth looks good, I don't know why it gives an error ...

@GaurangTandon sigh, you're trying to run Python code using the coffeescript interpreter

Game Maker Language, 276
p=real(keyboard_string())-1j="#"s=""z=" answer"w=" accept"x=" upvoted"+j;y=w+"ed"v=" question"u=" downvoted"if m=floor(p/15)s+=(m+z+y)+j;r=p-m*15if m=floor(r/10)s+=(m+z+x)r-=m*10if m=floor(r/5)s+=(m+v+x)r-=m*5n=floor(r/2)r-=n*2if m=r{n++;s+=(m+u+z)+j}s+=(n+y+z)show_message(s)

Python3, 188B
n=input()+1
a=n//15
n%=15
A='answer '
print("%d %saccepted\n%d %supvoted\n%d question upvoted\n%d accept %s\n%d downvote %s\n%d %sdownvoted"%(a,A,n//10,A,n%10//5,n%5>2,A,n%5%2,A,n%5==0,A))

Usage: python3 score.py <ret> 11 <ret> where this script is saved as score.py.
Sample output:
$ python score.py
5543
369 answer accepted
0 answer upvoted
1 question upvoted
1 accept answer
0 downvote answer
0 answer downvoted

accepted = accept + d, downvoted = downvote + d, upvoted is repeated.

Yes but those substitutions don't save any characters overall - try it and see

C++, 276 (316 w/ includes)
#include <stdio.h>
#include <stdlib.h>
p(int&q,int*d){int r;char*s[]={"downvoted","accepted","question","answer","upvoted"};
if(r=(q&&q>=*d)){q-=(*d?*d:2);printf("%s %s\n",s[*(++d)],s[*(++d)]);}return r;}main(
int n,char**v){int q=atoi(v[1]);int d[]={-1,3,0,0,3,1,5,4,2,10,4,3,15,1,3};n=15;while
(p(q,d+n-3)||(n-=3));}

Compiles with GCC, with warnings. Example:
$ ./a.out 0
$ ./a.out 1
accepted answer
downvoted answer
$ ./a.out 2
accepted answer
$ ./a.out 5
question upvoted
$ ./a.out 10
answer upvoted
$ ./a.out 15
answer accepted
$ ./a.out 16
answer accepted
accepted answer
downvoted answer
$ ./a.out 17
answer accepted
accepted answer

Feel free to port this to a language that doesn't require type declarations and post it as your own.

authors: Михаил Кузнецов


text:
Compare two poker hands
Challenge:
Given two five-card hands, determine which one wins by the standard ranking of poker hands.
Input:
Ten cards separated by spaces from stdin or as command line arguments, whichever you prefer. The first five cards are Player 1's hand while the last five are Player 2's hand. Each card will be a two letter string of the form RS where R is rank and S is suit. The ranks range from 2-9, T for ten, and J, Q, K, and A for Jack, Queen, King, and Ace respectively. The suits are H, D, C, S for Hearts, Diamonds, Clubs, and Spades respectively. You must output the number of the player that wins: '1' or '2'.
Examples of Cards:
AS - the Ace of Spades
QD - the Queen of Diamonds
2C - the Two of Clubs
TH - the Ten of Hearts

Input to Output Examples:
5H 5C 6S 7S KD 2C 3S 8S 8D TD -> 2

Explanation: Player 1 has a Pair of Fives while Player 2 has a Pair of Eights.
5D 8C 9S JS AC 2C 5C 7D 8S QH -> 1

Explanation: Neither Player has anything special, but Player 1's high card is an Ace while Player 2's high card is a Queen.
2D 9C AS AH AC 3D 6D 7D TD QD -> 2

Explanation: Player 1 has Three Aces, Player 2 has a Flush of Diamonds.
4D 6S 9H QH QC 3D 6D 7H QD QS -> 1

Explanation: Both players have a Pair of Queens, but Player 1's second highest card is a Nine whereas Player 2's is a Seven.
Rules and Clarifications:

Refer to the standard ranking of poker hands for the details of comparing hands.
You may assume that there are no repeated cards in each pair of hands.
You may assume that there is a definite winner in each case.
Suit does not factor into the ranking of a hand. For example, two royal flushes of different suits are equal (therefore any input where both players have a royal flush is invalid by the preceding rule).
As this is code golf, the shortest answer wins.

Notes:

Related to this question and this one.
Based on Project Euler Problem 54

Apologies if there's anything I've missed! This is my first code golf question.

This is similar to this recent question http://codegolf.stackexchange.com/q/23743/15599 and the 5-card version referenced within it. However those questions only required to name the type of hand. A big difference here is that if both players have the same type of hand, we have to determine which is better by card rank (e.g. for two pairs, who has the best first pair, second pair, and if necessary single card.) Therefore it is not a duplicate. Always search for similar questions, link them, (i see you did) and be prepared to defend why it is not a duplicate before posting.

What if the flop and the hand are the same?

@IsmaelMiguel There is no flop in this version. There are simply two separate hands that must be evaluated against each other.

Previously solved for 10 cards here

Haskell - 352 339 characters
import Data.List
v h=10*(sum$map(\l->l*l)g)+b g:k where
  (g,k)=unzip$reverse$sort$map(\r->(length r,head r))$group$sort$map(maybe 0 id.(`elemIndex`"23456789TJQKA").head)h
  b(1:_)=f(map(!!1)h)+t k;b _=0
f(y:z)|all(==y)z=75;f _=0
t[y,_,_,_,z]|y-z==4=70;t[12,3,2,1,0]=65;t _=0
w(a,b)|v a>v b="1\n";w _="2\n"
main=interact$w.splitAt 5.words

Runs:
& echo "5H 5C 6S 7S KD 2C 3S 8S 8D TD" | runhaskell 25056-Poker.hs
2

& echo "5D 8C 9S JS AC 2C 5C 7D 8S QH" | runhaskell 25056-Poker.hs
1

& echo "2D 9C AS AH AC 3D 6D 7D TD QD" | runhaskell 25056-Poker.hs
2

& echo "4D 6S 9H QH QC 3D 6D 7H QD QS" | runhaskell 25056-Poker.hs
1

Ungolf'd and commented, so you can see the techinque:
import Data.List

value :: [String] -> [Int]
value hand = 10 * (sum $ map (\l->l*l) groups) + bonus groups : kicker
    -- ^ Value of a hand is 10 times the sum of the squares of the group lengths
    -- plus the straight & flush bonus, followed by the kicker (to break ties)
    -- This 10 * sum-of-squares + bonus works out to put the hands in category
    -- order, and then they only need to be ordered by card ranks.
  where
    -- | The cards are sorted into groups by matching rank, then the groups
    -- sorted by length and rank: For example: "7C 7D 7H QS 2S" will becomes
    -- [(3,7),(1,Q),(1,2)]. This is like a run-length encoding. Finally, the
    -- groups lengths, and the kicker ranks are taken apart into two lists.
    -- N.B: kicker here includes the ranks of the groups, unlike the poker term.

    (groups,kicker) = unzip             -- split apart
        $ reverse $ sort                -- reverse sort by (length,rank)
        $ map (\r->(length r,head r))   -- turn groups into (length,rank) pairs
        $ group $ sort                  -- group sorted ranks
        $ map (maybe 0 id . (`elemIndex`"23456789TJQKA") . head) hand
            -- take first letter of each card in the hand, and map to [0..12]

    -- | Give a bonus for flush and straight to hands with five cards,
    -- or equivalently hands where the largest group length is just 1
    bonus (1:_ ) = flush (map (!!1) hand)   -- flush takes the suits of the hand
                   + straight kicker        -- straight takes the ranks
    bonus _      = 0

    -- | A flush is if all suits match the first suit
    flush (y:z) | all (==y) z = 75
                | otherwise   =  0

    -- | There are two kinds of straight.
    -- N.B: If there are five groups, then there are no duplicate ranks
    straight [y,_,_,_,z] | y-z == 4 = 70    -- normal, high to low
    straight [12,3,2,1,0]           = 65    -- ace is low, but it sorts high
    straight _                      =  0

wins :: ([String], [String]) -> String
wins (a,b) | value a > value b = "1\n"
           | otherwise         = "2\n"

main = interact $ wins . splitAt 5 . words

Python - 774 722 707 698 685 chars
import sys
t,q,e,u='--23456789TJQKA','SDCH',enumerate,len
_=lambda c,i=0:chr(97+c[i])
def j(s):
 v,g,l=[0]*15,[0]*4,''
 for c in s:
  r,s=c[0],c[1];v[t.find(r)]+=1;g[q.find(s)]+=1
 c,h,k,m,f=0,0,[0,0,[],[],[]],0,0
 for x,i in e(v):
  for b in[2,3,4]:
   if i==b:k[b]+=[x]
 v[1]=v[14]
 for x,i in e(v):
  if i:
   c+=1
   if c==5:m,h=1,x
   if i==1:l+=_([x])
  else:c=0
 f,l,d=max(g)//5*2,l[::-1],'';z=f+m
 if z==3:d='z'+l
 if k[4]:d='y'+_(k[4])+l
 if k[2] and k[3]:d='x'+_(k[3])+_(k[2])
 if z==2:d='w'+l
 if z==1:d='v'+_([h])
 if k[3]:d='u'+_(k[3])+l
 if u(k[2])>1:d='t'+_(k[2],1)+_(k[2])+l
 if u(k[2])==1>u(k[3]):d='s'+_(k[2])+l
 return d or l
p=sys.argv
print(1+(j(p[1:6])<j(p[6:])))

I chose to generate a string for each hand that represents it, starting with a character for the type of hand, followed by characters describing the particular variation of the type (for example, which card did you just have 4 of?), followed by the values of the remaining cards in case of a tie (if both players have the same double pair, the 5th card will have to decide who wins). I've tested it quite extensively, but I don't actually play poker, so I hope I got it right. Also, I know it's not fully golfed yet, I can probably shave off a few dozen chars later on.

Kill 5 chars with _=lambda c:chr(97+c). Also, you have some unnecessary whitespace after :s and =s. Finally, use ; instead of new lines to separate statements to reduce whitespace used for indentation.

Nice one with the lambda, thanks!

JavaScript - 526 508
function a(b){b=b.split(" ");var c=b.splice(5,5),d=[],e=[],r=[8,9,5,6,1,2,3,10,4,7],A=14,K=13,Q=12,J=11,S={"S":1,"C":2,"H":4,"D":8};for(i=0;i<5;i++){d.push(b[i].split('')[1]);b[i]=b[i].split('')[0];e.push(c[i].split('')[1]);c[i]=c[i].split('')[0]}function p(w,m){var v,i,o,s=1<<w[0]|1<<w[1]|1<<w[2]|1<<w[3]|1<<w[4];for(i=-1,v=o=0;i<5;i++,o=Math.pow(2,w[i]*4)){v+=o*((v/o&15)+1)}v=v%15-((s/(s&-s)==31)||(s==0x403c)?3:1);v-=(m[0]==(m[1]|m[2]|m[3]|m[4]))*((s==0x7c00)?-5:1);return r[v]}alert(p(b,d)>p(c,e)?1:2)}

usage:
a("5H 5C 6S 7S KD 2C 3S 8S 8D TD");

ungolfed:
function a(b) {
b = b.split(" ");
var c=b.splice(5,5),
        d=[],
        e=[],
        r=[8,9,5,6,1,2,3,10,4,7],
        A=14,
        K=13,
        Q=12,
        J=11,
        S={"S":1,"C":2,"H":4,"D":8};

    for (i=0;i<5;i++) {
        d.push(b[i].split('')[1]);
        b[i] = b[i].split('')[0];
        e.push(c[i].split('')[1]);
        c[i] = c[i].split('')[0];
    }

function p(w,m){
  var v, i, o, s = 1<<w[0]|1<<w[1]|1<<w[2]|1<<w[3]|1<<w[4];
  for (i=-1, v=o=0; i<5; i++, o=Math.pow(2,w[i]*4)) {v += o*((v/o&15)+1);}
  v = v % 15 - ((s/(s&-s) == 31) || (s == 0x403c) ? 3 : 1);
  v -= (m[0] == (m[1]|m[2]|m[3]|m[4])) * ((s == 0x7c00) ? -5 : 1);
  return r[v];
}

alert(p(b,d)>p(c, e)?1:2);
}

source

Python 3, 454 characters
def z(v,u):
 v.sort();o,d,w=0,{2:0,3:0},[0]+v[:-1]
 if v[4]==13 and T(w):v=w
 t,f=T(v),len(set(u))==1
 for p,c in set((p,v.count(p)) for p in v):
  if c==4:o+=2**77
  d[c]=d.get(c,0)+1;o+=2**(c*14+p)
 if f+t:o+=2**(71+f*4+t*3)
 elif d[3]:o+=2**(73+3*d[2])
 o+=2**(70+d[2]);return o
i,c,T=input().split(),'-23456789TJQKA',lambda v:all(v[i]==v[0]+i for i in range(5))
v,u=[c.find(x[0]) for x in i],[x[1] for x in i]
print(1+(z(v[:5],u[:5])<z(v[5:],u[5:])))

Function z evaluates a hand to a single integer, which is effectively serving as an ordinal using Python's arbitrary precision integers. Its parameters, v and u, are lists of the values (2-14) and suits (single-char strings). The first two lines of z sort the cards, initialize relevant structures, and check if we have a low-ace straight. We then check for a straight or flush on the next line. The internal loop iterates the counts of different cards, solves the 4-of-a-kind case, tallies, and adds the appropriate ordinal. The last 3 lines of z solve the ordinals of all the other hand ranks -- flushes, straights, and straight-flushes, followed by 3-of-a-kind and full houses, followed by two pair, pair, and high card.
In the main area, we parse the input, declare lambda v (which checks for straights), and the last line evaluate the hands and prints the result.

perl, 801 733 chars
I believe this is a pretty straight-forward implementation. Basically, for each hand, we sort the suits and the faces separately. Then we make another copy of the faces with aces counting low so we can check for straights with low aces. Then we determine if we have a flush or straight, and what the high card is. Then we just check for matches in order of score (first we check for straight flushes, then four of a kinds, etc.). The actual score is just the concatenation of the type of hand followed by the face values of the cards in the order they matter (that's _s() in the ungolfed version, u() in the golfed version). Here it is:
@l{2..9,qw(T J Q K A)}=2..14;sub u{join"",map{$_>9?$_:"0$_"}shift,ref$_[0]?$$_[0]:map{$h[$_]}@_}sub e{$p[$_[0]-1]-1==$p[$_[0]]}sub f{@p=@_;e(1)&&e(2)&&e(3)&&e 4}sub h{$h[$_[0]]==$h[$_[1]]}sub i{h(@_[0,1])&&h @_[2,3]}sub t{@s=sort map{substr($_,1)}@_;$f=$s[0]eq$s[4];@l=@h=sort{$b<=>$a}map{$l{substr($_,0,1)}}@_;@l=(@l[1..4],1)while$l[0]==14;$s=0;if(f@l){$s=1;$h=$l[0]}else{$h=$h[0];$s=1 if f@h}$f&&$s?u 9,\$h:h(4,1)?u 7,4,0:h(3,0)?u 7,3,4:i(4,3,2,0)?u 6,0,4:i(4,2,1,0)?u 6,4,0:$f?u 5,0:$s?u 4,\$h:h(4,2)?u 3,4,0,1:h(3,1)?u 3,3,0,4:h(2,0)?u 3,2..4:i(4,3,2,1)?u 2,2,4,0:i(4,3,1,0)?u 2,1,4,2:i(3,2,1,0)?u 2,1,3,4:h(4,3)?u 1,4,0,1,2:h(3,2)?u 1,3,0,1,4:h(2,1)?u 1,2,0,3,4:h(1,0)?u 1,1..4:u 0,0..4}print t(@ARGV[0..4])gt t(@ARGV[5..9])?1:2

And here's the less-golfed equivalent:
use strict;
use warnings;

# ace high or low in straights, otherwise high
# T = ten, J = jack, Q = queen, K = king, A = ace

# 0 high card
# 1 one pair
# 2 two pair
# 3 3 of a kind
# 4 straight
# 5 flush
# 6 full house
# 7 four of a kind
# 9 straight flush (royal flush a subclass of straight flush)

my %l;@l{2..9,qw(T J Q K A)}=2..14;
sub score {
  my @suits = sort map { substr($_,1) } @_;
  my @faces_h = sort { $b <=> $a } map { $l{substr($_,0,1)} } @_;
  my @faces_l = @faces_h;
  @faces_l = (@faces_l[1..4], 1) while $faces_l[0] eq 14;
  my $is_flush = $suits[0] eq $suits[4];
  my ($is_straight, $high_card);
  if($faces_l[0]-1==$faces_l[1] &&
     $faces_l[1]-1==$faces_l[2] &&
     $faces_l[2]-1==$faces_l[3] &&
     $faces_l[3]-1==$faces_l[4]) {
    $is_straight=1;
    $high_card = $faces_l[0];
  } else {
    $high_card = $faces_h[0];
    if($faces_h[0]-1==$faces_h[1] &&
       $faces_h[1]-1==$faces_h[2] &&
       $faces_h[2]-1==$faces_h[3] &&
       $faces_h[3]-1==$faces_h[4]) {
      $is_straight=1;
    }
  }
  return _s(9, \$high_card) if $is_flush && $is_straight;
  return _s(7, 4,0) if $faces_h[4] == $faces_h[1];
  return _s(7, 3,4) if $faces_h[3] == $faces_h[0];
  return _s(6, 0,4) if $faces_h[4] == $faces_h[3] && $faces_h[2] == $faces_h[0];
  return _s(6, 4,0) if $faces_h[4] == $faces_h[2] && $faces_h[1] == $faces_h[0];
  return _s(5, 0) if $is_flush;
  return _s(4, \$high_card) if $is_straight;
  return _s(3, 4,0,1) if $faces_h[4] == $faces_h[2];
  return _s(3, 3,0,4) if $faces_h[3] == $faces_h[1];
  return _s(3, 2,3,4) if $faces_h[2] == $faces_h[0];
  return _s(2, 2,4,0) if $faces_h[4] == $faces_h[3] && $faces_h[2] == $faces_h[1];
  return _s(2, 1,4,2) if $faces_h[4] == $faces_h[3] && $faces_h[1] == $faces_h[0];
  return _s(2, 1,3,4) if $faces_h[3] == $faces_h[2] && $faces_h[1] == $faces_h[0];
  return _s(1, 4,0,1,2) if $faces_h[4] == $faces_h[3];
  return _s(1, 3,0,1,4) if $faces_h[3] == $faces_h[2];
  return _s(1, 2,0,3,4) if $faces_h[2] == $faces_h[1];
  return _s(1, 1,2,3,4) if $faces_h[1] == $faces_h[0];
  return _s(0, 0..4);
}

sub _s {
  join "", map { $_ > 9 ? $_ : "0$_" } shift,
    ref $_[0] ? $$_[0] : map { $faces_h[$_] } @_
  # my @a=@_;
  #  if(ref $a[1]) {
  #    $a[1]=${$a[1]};
  #  } else {
  #    $a[$_]=$faces_h[$a[$_]] for 1..$#a;
  #  }
  #  join "", map { $_ < 10 ? "0$_" : $_ } @a;
}

my @p1 = @ARGV[0..4];
my @p2 = @ARGV[5..9];

my $s1 = score(@p1);
my $s2 = score(@p2);
print $s1 gt $s2 ? 1 : 2;

AH 2C 3S 4S 5D 6C 7S 7C 7D TD produces a result of 2, but I think a straight beats three of a kind


text:
Protect my walls from these pesky doors
Doorknobs are great and all, but when you open a door, it always dents the walls around it. I need you to take input of ASCII art of a room, like this:
+---------+--X  --X    --+-----+
|       \     \   |\     |   \ |
|        \     \  | \    |    \|
|         X       |  \   |     X
|      /  |       |   \  X
|     /   |     \       /
|    /    |      \     /       |
+---X   --+-------X------+-----+

And output the room with doorstops, like this:
+---------+--X  --X    --+-----+
|       \  .  \   |\     |   \.|
|        \     \  | \   .|    \|
|         X       |  \   |     X
|      /  |       |.  \  X
|     /  .|     \       /
|.   /    |     .\     /       |
+---X   --+-------X------+-----+

Specification:

The ASCII room (input) will consist of +, -, and |. These characters are purely cosmetic; they could all be +s but that would look horrible. It will also contain hinges (X) and doors (/ or \).
Doors are made up of / or \. Starting from the "hinge" character, which is X, they will go directly diagonally (change of 1 in x and 1 in y) for 2 or more units (characters).
To find where to put the doorstop for a door (there is always only one doorstop per door), find the doorway for the door. The doorway will always start at one hinge, and go the same amount of spaces as the door's length up, down, left, or right from there. The next space after that will always be a wall. For example, in this door, the doorway is marked by Ds:
   \
    \
---DDX-----

One the doorway is found, find out whether you need to go clockwise or counterclockwise to reach the door. For example, in that example door above, you have to go clockwise, and in this one, you must go counterclockwise:
   \ <-
    \  )
-----X  ---

Once you know which way to go, keep going that way (ignoring the door) until you reach a wall.
Here's a visualization of that for the example door above:

The blue is the doorway, the orange is finding that you must go clockwise, and the red is continuing to go clockwise until a wall is reached.
Once you reach a wall, go (the door's length) spaces from the hinge (X) on that wall, move one space away from the wall towards the door (so you don't place the doorstop right on the wall), and insert a . there. Here's the same example door showing how the doorstop is placed:
   \
    \  .
---DDX12---

Repeat for every door, and output the result! Use the example input at the top of this post as a test case to check if your program is valid.
Note that you do not have to handle doors that don't fit on their walls, such as:
|     /
|    /
|   /
|  /
+-X    --

Or:
     /
    /
   /
+-X   --
|
|

This is code-golf, so the shortest code in bytes will win.

What are the rules for doorways? They must be orthogonal, the same length as their doors, and surrounded by a wall on one side, and a hinge (for the right door) on the other side?

@JanDvorak Ok, edited for clarification

Can we assume that the wall starting at the hinge is at least of the same length as the door and that no other walls (not starting at the hinge) interfere with that specific door?

@Howard I'm not sure what you're talking about. Are you asking if you can assume that the opposite wall from the doorway is the same length as the doorway? If so, then no, since the door could only swing 90 degrees like the second one in the test case (counting by hinge placement starting from the top left).

Also, I'm not sure what you mean by "no other walls interfere." If that is asking whether all doors will swing 180 degrees, then no to that as well.

I had a similar thought to Howard: consider test case +X  -+ newline | \  | newline |  \ |. This case doesn't seem to be prohibited by the rules or exemplified by the test case, and if it is permitted then it's not clear how to interpret "go (the door's length) spaces from the hinge on that wall"

@Doorknob, I think Howard is asking if (for example) a 3 length door could be on a 2 length wall, necessitating additional calculations, or if we can assume that an x length door will come to rest against a minimum x length wall

@Peter But that door does not go diagonally. Down the middle column it's " \\" which is an invalid door.

@Sean Yes, you may assume that. I will edit to clarify

@Doorknob Regarding Howard's problem. Look at the lower left door in your example. If doorway and door were one unit longer, the door couldn't swing around completely. Does this case have to be considered? Similary, if the corner in such a case is not convex but concave (so that corner doesn't obstruct the door, but the door would extend beyond the corner), does this have to be considered?

Huh? The door is diagonal. All of those strings are 6 chars wide, so there isn't a middle column.

@Peter Hrmph, the SE Android app is messing up the rendering. In any case, the ambiguity has been resolved by the edit.

@m.buettner Nope; adding another edit to fix that as well

Scala, 860 bytes
Golfed:
    object D extends App{val s=args(0)split("\n")
    val r=Seq(P(1,0),P(1,-1),P(0,-1),P(-1,-1),P(-1,0),P(-1,1),P(0,1),P(1,1))
    var m=r(0)
    val e=s.map(_.toCharArray)
    case class P(x:Int,y:Int){def u=x==0||h
    def h=y==0
    def p(o:P)=P(x+o.x,y+o.y)
    def o="\\/".contains(c)
    def w="-|+".contains(c)
    def c=try s(y)(x) catch {case _=>'E'}
    def n=r.filter(!_.u).map(d => d.j(p(d))).sum
    def j(t:P):Int=if(t.o)1+j(p(t))else 0
    def q=if(c=='X'){m=this
    r.filter(_.u).map{d=>if(p(d).c==' '&&p(P(d.x*(n+1),d.y*(n+1))).w)d.i}}
    def i:Unit=Seq(r++r,(r++r).reverse).map(l=>l.drop(l.indexOf(this)+1)).map(_.take(4)).filter(_.exists(a=>a.p(m)o))(0).grouped(2).foreach{p=>if(p(1)p(m)w){p(0)add;return}}
    def add=if(r.filter(_.h).map(p(_)p(m)).exists(_.w))e(y*m.n+m.y)(x+m.x)='.'else e(y+m.y)(x*m.n+m.x)='.'}
    val f=args(0).size
    Array.tabulate(f,f){(i,j)=>P(i,j)q}
    e.map(_.mkString).map(println)}

Un-golfed:
    object DoorknobCleanVersion extends App {
            val s = args(0) split ("\n")

            val r = Seq(P(1, 0), P(1, -1), P(0, -1), P(-1, -1), P(-1, 0), P(-1, 1), P(0, 1), P(1, 1))
            val HorizontalDirections = r.filter(_.isHorizontal)

            var hinge = r(0)
            val result = s.map(_.toCharArray)

            type I = Int
            case class P(x: Int, y: Int) {
                    def isCardinal = x == 0 || isHorizontal
                    def isHorizontal = y == 0

                    override def toString = x + "," + y

                    def p(o: P) = P(x + o.x, y + o.y)

                    def isDoor = Seq('\\', '/').contains(charAt)
                    def isWall = Seq('-', '|', '+').contains(charAt)

                    def charAt = try s(y)(x) catch { case _ => 'E' }

                    def doorLength = r.filter(!_.isCardinal).map(d => d.recursion2(p(d))).sum

                    def recursion2(currentPosition: P): Int =
                            if (currentPosition.isDoor)
                                    1 + recursion2(p(currentPosition))
                            else
                                    0

                    def findDoorway =
                            if (charAt == 'X') {
                                    hinge = this
                                    r.filter(_.isCardinal).map { d =>
                                            if (p(d).charAt == ' ' && p(P(d.x * (doorLength + 1), d.y * (doorLength + 1))).isWall)
                                                    d.getCorrectRotation2
                                    }
                            }

                    def getCorrectRotation2: Unit = Seq(r ++ r, (r ++ r).reverse).map(l => l.drop(l.indexOf(this) + 1))
                            .map(_.take(4))
                            .filter(_.exists(a => a.p(hinge)isDoor))(0)
                            .grouped(2)
                            .foreach {
                                    p =>
                                            if (p(1) p (hinge)isWall) {
                                                    p(0)add;
                                                    return
                                            }
                            }

                    def add =
                            if (HorizontalDirections.map(p(_) p (hinge)).exists(_.isWall))
                                    result(y * hinge.doorLength + hinge.y)(x + hinge.x) = '.'
                            else
                                    result(y + hinge.y)(x * hinge.doorLength + hinge.x) = '.'

            }

            val size = args(0).size
            Array.tabulate(size, size) { (i, j) => P(i, j).findDoorway }

            result.map(_.mkString).map(println)
    }

Using OOP was definitely the wrong approach here, in hindsight. If I could do it again I would definitely go with a bunch of hardcoded truth tables.


text:
Android Lock Screen
Intro
You are sitting in a board room at the end of a long table. You look around and see Tim Cook, the Apple Board of Directors, the ghost of Steve Jobs, and Jack Donaghy. Apple has called this meeting because they have realized how much cooler the Android lock screen is, and they want to 1-UP them. Everyone in the room stares at you as Ghost Steve cries, "Help me, CodeGolf Man! You're my only hope!"
The Problem
The Android lock screen is a 3 x 3 grid of dots that can be connected by swiping a finger from one dot to the next, creating a path. A password is considered any possible path that includes any number of dots, and excludes any number of dots. (On an actual phone, the path must be at least 4 dots long. For this challenge, ignore that restriction.) Apple plans to replace the 3 x 3 grid with an M x N grid, which is (M*N)/9 times better!
Rules:

A zero dot path is not a password, but a 1 dot path is
A path can cross itself
A path cannot cross directly over a dot without including that dot
A dot can only be used once
Paths that are identical by rotation are not the same password
Paths that are identical but ordered in reverse are not the same password

For example, on a 3x3 grid with dots numbered from 1 to 9:
1 2 3
4 5 6
7 8 9

Some valid paths are:
1
3
7,2,3
1,5,9,2
1,8,6,5,4
4,2,3,5,6,7,8,9
5,9,6,4

And some invalid paths are:
1,3
1,9,5
7,5,4,7
4,6

Your input will be three numbers:
(M,N,d)

Where the grid is M x N, and d is the length of the path
1 <= M <= 16
1 <= N <= 16
1 <= d <= M * N

Your program or function will be given the input as a comma separated string, and it must return the number of possible passwords of that length. For example:
Input:  2,2,1
Output: 4
Input:  2,2,2
Output: 12
Input:  7,4,1
Output: 28

Standard code golf rules apply, shortest code wins!
//If I've made a mistake or the rules are unclear, please correct me!

You said "your program must return...", but in your example you have provided something that resembles a function. It may be better to reword your question so that it is either a program, or a function, or a program or a function.

It that more clear? This is my first question, so I'm not 100% clear on the specifics.

Is the input a comma-separated string or three separate parameters?

@user80551 Based on the context, I think it will be a string if it is input to a program, or separate parameters if it is used to call the function.

@Platatat can you please answer user80551's question, as this is really important to design the code

Let's say the input is a comma separated string

You should decide if there's going to be a time limit for both the compile and execution time of a given solution. Without such a limit, it's easy to write a program that, in theory, verifies which of all 256! permutations of the dots on the 16 x 16 grid represent a valid unlock pattern. In practice, such a program would never terminate.

What about the same paths in reverse order ? d must be greater or equal. I think you should remove movements like 7,2 (not neighbours) and 5,6,4 (overlapping), they add difficulty to an already hard challenge.

can you explain why 5,9,6,4 is considered a valid path? it appears you are crossing over (but not including) 5 to get from 6 to 4

Yes, you are crossing over 5, but since 5 has already been used it isn't considered illegal. "A path cannot cross directly over a dot without including that dot" was as best as I could word this, and basically since this path DOES use 5 before it jumps over it, the path is legal. This is how actual android phones work, too.

Just because it's how it works in Android doesn't mean it's interesting in the context of code golf. There was a typo in my previous comment, d must be superior or equal to 2.

But I said the problem was based on the android lock system... So why shouldn't I use the same rules as the android lock system?

Python - 170 bytes
from fractions import*
p=lambda m,n,d,l=0,s=set():d<1or sum([p(m,n,d-1,i,s|{i})for i in range(m*n)if not(s and(s&{i}or set(range(l,i,abs(i-l)/gcd(i%n-l%n,i/n-l/n)))-s))])

I realize that the brackets inside sum([...]) are not strictly necessary, but there's a large performance penalty for not including them.
Output for all 3x3s:
for i in range(4, 10):
  print p(3, 3, i)

Produces:
1624
7152
26016
72912
140704
140704

For testing/confirmation purposes, the first 6 values for a 4x5 board:
20
262
3280
39644
459764
5101232

4x5 is an interesting case to verify, because it has 2x2, 3x3, and 2x4 peg jumps.

Brief Explanation
In general, this is an exhaustive search, with cumulative pruning. For example, because p(3, 3, 4) is 1624, p(3, 3, 5) will only check 8120 posibilities, rather than naïvely checking all 15120. Most of the logic is contained in the condition:
if not(s and(s&{i}or set(range(l,i,abs(i-l)/gcd(i%n-l%n,i/n-l/n)))-s))

In plain english, this can be understood as:
If no pegs have been used yet
     OR
   the target peg has not yet been used
     AND
   each of the pegs directly between the target peg and the
   current peg (a.k.a. "jumped over") have already been used

Could you explain what in the world is going on here?

You can save a few bytes by having s be a set instead of a list. I'm not seeing the large performance penalty of dropping the brackets; why would there be such a penalty?

@user2357112 one is summing over a Generator, the other over a List. With CPython, you're right, there isn't much difference (only about 20% slower). With PyPy, it's over 5 times as slow.

@user2357112 I finally see what you meant by defining s as a set. My python lesson for today: {i} evaluates as set([i]). I would have expected a syntax error. Appending an item to a set then becomes s|{i}, and it also allows i in s to be replaced by s&{i}.