问:
Smallest chess board compression
Write an algorithm or program that can encode and decode a chess board. The goal is to make the smallest representation of a chessboard that could be used (once decoded) to determine all movement possibilities for a player on that turn.

The encoding must be able to show:

Whose turn it is.

Whether the player can castle on each side.

Whether the player can perform an en-passant, and if so, which of their pawns?

Positions of all pieces.

Important note on castling: If white moves their king one turn, and then moves it back the next, it must be clear that they cannot castle on either side after that. Same would go if they moved their left or right rook. Although the board is visually in the same state as it was two turns ago, the game state has changed. More info here: http://en.wikipedia.org/wiki/Chess#Castling

Important note on en-passant: This is also a turn-sensitive move. Read the rules for more info. http://en.wikipedia.org/wiki/Chess#En_passant

Determine input and output as needed. Major props to whoever can compress it the most!

Your score is determined worst-case scenario - maximum possible size in bits. Make sure you show how you calculated it that number and what you accounted for. Shoot for the smallest worst-case!

答:
171 bits worst case:

I've combined a couple of ideas, as well as some of my own thoughts.

We are going to start with a 64 bit board. Each bit represents an occupied space on the board. They fill along rows.
So the start looks like: 1111 1111 1111 1111 0000 0000 0000 0000 0000 0000 0000 0000 1111 1111 1111 1111

Now, each piece will be represented by 4 bits.
1st bit: color (0=white, 1=black)
2nd-4th bits: One of 8 types.

```<code>0=king, 1=queen, 2=bishop0, 3=knight, 4=rook, 5=pawn0, 6=pawn1, 7=bishop1
</code>```

At the end we will include a bit designating the turn. 0=white, 1=black.

4bits*32 pieces=128 bits and I've already got 64+1 from turn and board. That gives a total of 128+64+1=193 I haven't even started with en passant or castling. Well over my limit with nothing -- not even turns. This is where the tricks start.

Okay -- you see those types above? Bishop0 and Bishop1? Pawn0 and pawn1? Those types are so designated, because they tell us a bit to insert after this piece. So Bishop0 means that after it, there will be a 0 -- i.e that the next piece is white. Bishop1 tells us the next piece is black, and the pawn0 and pawn1 work the same. (If this piece is the last piece being enumerated, then it tells us about the next turn instead).

My worst case involves all the pieces on the board, so with 16 pawns and 4 bishops, this saves me 20 bits. I'm down to 173.

Okay. For another bit in my worst case -- once there are 16 of a color encoded, we stop encoding color -- as we know it going forwards. My worst case now involves a white piece making it to the far corner with no captures. There, I save only one bit. 172.

I'm going to now change the order in which I name the pieces. We will name them along columns starting at the outside moving in. The board named at the beginning will stay the same, but when I place pieces on it, i start from whites bottom right, and go up that column. Then I jump to black's bottom right, and go up that column. I jump to white's bottom right unknown cell, and so forth -- this means my worst case is again the start. My reason has to do with my en passant trick, the next two bits I lose, and castling.

Now, for a pawn to be promoted (as has been discussed at length) a piece must be captured. Thus, when we know there are 32 pieces, we only need to denote 31 of them. The last piece is uniquely identified. As it turns out, for me, this only saves 2 bits -- because my last piece might be a pawn/bishop (which normally costs me 3 bits because I save one on the next piece) who's color is determined already and so was only 2 bits. I'm down to 170 bits.

When pawns get promoted, they simply change their type. For each piece that goes off the board I rid myself of (minimum) 3 bits, and two pawn promotions cost me 2 bits, so I'm declining (slowly) in promotions.

Castling. For castling to happen, neither king nor relevant rook may have moved. Thus, when a rook is capable of castling both it and the king will be in their original places. So, rooks capable of castling will be listed in the same place as kings of that color. As this is illegal (two kings or three kings of the same color on the board) and only can happen in three possible setups for each color (left, right, both rooks are listed as kings) -- decoding is utterly possible. So, for no bits we have encoded castling.

En Passant Here we will also use illegal positions. Only one pawn can be in danger of en passant at a time. It must be in its fourth row. The pawn that is vulnerable will be 'flipped' back to its home row -- switched with whatever is there. As that pawn is in its own first row -- an illegal position, the situation will be obvious to the decoder -- it will reverse the positions, and mark the pawn as vulnerable to en passant.

We needed to muck about with the order because the last piece has to be 'uniquely identified'. In a standard order, we wouldn't be able to tell if the rook in the back corner could castle -- that's not known. When we work from the outside in, we guarantee that wherever that rook is 'listed' be it in its own corner, or in the middle of the board because it was switched with an en passant vulnerable pawn, there will be a piece listed after it -- so we are told the rook's type. We know there will be a piece after it because, for a pawn to be vulnerable there must be a pawn to its inside (which will crucially be encoded later as per the instructions above).

Oh, and to help make sure that the worst case involves all pieces on the board, once we have less than 32 pieces, we can use the 64 bit board to identify turn as well as occupied positions by using 0's to represent pieces when its white's turn and 1's when it is blacks turn.

So we got en passant and castling for free. We picked up the last piece for free, though it took some finagling with order to make that play nice with the en passant and castling rules. We ditched 20 bits on the standard pieces. I believe the worst case here involves a midde white pawn moved forward and a black piece in between it and its queen while all pieces are on the board.
Quick double check: first piece is captured -- call it a pawn, 3 bits off the board in the pawn, 3 bits on the board in the form of a last piece, one bit off in the turn marker disappearing. Promote two pawns 2 bits back on the board. Ah damn, I'm at 171.

EDIT I've added code for a (working?) decoder -- in R -- below. It takes vectors of booleans as input -- (sorry -- I'm not capable of coding well in anything that would let me actually use the bits) I've also included the start position.

```<code>separate = function(vec){
    #Using a boolean vector (sorry R doesn't handle bits well and this will build quickest)
    board = matrix(vec[1:64],8,8,byrow=T)
    npieces = min(sum(board),64-sum(board))
    n = length(vec)
    a = vec[65:n]
    counter = 0
    pieces = list()
    white = 0
    Letters=c(letters,LETTERS)
    for (i in 1:npieces){
        col = ifelse(a[1],"black",{white=white+1;"white"})
        typ = a[2:4]
        a=a[-(1:4)]
        num = 4*typ[1] + 2*typ[2] + typ[3]
        type = switch(letters[num+1],a="king",b="queen",c="knight",d="rook",e="bishop0",f="bishop1",g="pawn0",h="pawn1")
        if (num > 3) {
            if(num%%2){
                a = c(T,a)
            } else {
                a = c(F,a)
            }
            type = substr(type,1,nchar(type)-1)
        }
        pieces[[Letters[i]]] = list(color=col,type=type)
        if (length(pieces)==31&&npieces==32) {
            col = ifelse(16-white,{white=white+1;"white"},"black")
            type = "TBD"
            pieces[[Letters[i+1]]] = list(color=col,type=type)
            break
        }
    }

    if (npieces==32) {
        f=function(y){sum(sapply(pieces,function(x)x$type==y))}
        if (f("pawn")<16) {pieces[[32]]$type="pawn"}
        if (f("bishop")<4) {pieces[[32]]$type="bishop"}
        if (f("knight")<4) {pieces[[32]]$type="knight"}
        if (f("queen")<2)  {pieces[[32]]$type="queen"}
        if (f("king")<2)   {pieces[[32]]$type="king"}
        if (f("rook")<(6-f("king"))) {pieces[[32]]$type="rook"}
    }
    return(list(board,pieces,turn=ifelse(a[length(a)],"black","white")))
}

fillboard = function(out) {
    board = out[[1]]
    pieces = out[[2]]
    turn = out[[3]]
    lpieces = lapply(pieces,function(x) paste(substr(x$color,1,1),x$type))
    game = matrix("     ",8,8)
    #Start with corners.
    a = c(1,57,8,64)
    #Then kings
    b = c(25,32)
    #Then rooks in en passant
    c = c(4,60,5,61)
    #Then kings in en passant
    d = 28:29
    exceptions = list(a,b,c,d)
    for (places in exceptions) {
        c= which(board[places])
        if (length(c)) {
            repl = lpieces[1:length(c)]
            game[places[c]] = unlist(repl)
            board[places] = F
            lpieces = lpieces[-(1:length(c))]
        }
    }
    #Loop through rows.
    for (i in c(1:4,8:5)) {
        j = which(board[i,])
        if (length(j)) {
            repl = lpieces[1:length(j)]
            game[i,j] = unlist(repl)
            board[i,j] = F
            lpieces = lpieces[-(1:length(j))]
        }
    }
    return(matrix(unlist(game),8,8,F))
}

swapillegal = function(matr) {
    mat = matr
    if (any(mat[8,]=="b pawn")) {
        j = which(mat[8,]=="b pawn")
        mat[8,j] = mat[5,j]
        mat[5,j] = "b pawn-e"
    }
    if (any(mat[1,]=="w pawn")) {
        j = which(mat[1,]=="w pawn")
        mat[1,j] = mat[4,j]
        mat[4,j] = "w pawn-e"
    }

    if (sum(mat[8,]=="b king") > 1) {
        j = which(mat[8,-4]=="b king")
        j[j==7] = 8
        mat[8,j] = "b rook-c"
    }
    if (sum(mat[1,]=="w king") >1) {
        j = which(mat[1,-4]=="w king")
        j[j==7] = 8
        mat[1,j] = "w rook-c"
    }
    return(mat)
}

decode = function(vec) {
    a = separate(vec)
    b = fillboard(a)
    c = swapillegal(b)
    list(board=c,turn=a[[3]])
}

startboard = c(rep(T,16),rep(F,32),rep(T,16))
#Re-ordering -- first spots will be the corners. Then kings. then en passant positions of those spots
pieces = c(F,F,T,T,F,F,T,T,T,F,T,T,T,F,T,T,F,F,F,F,T,F,F,F,F,F,T,F,F,T,F,F,F,F,T,F,T,F,F,F,T,F,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,T,F,T,F,T,T,F,T,F,F,T,T,T,F,T,F,T,F,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,F)
########## w rook -w rook -B rook -B rook -W king -B king -w kni  -w bi 0 -w Q  -w Bi 0 -w kni-w p0   - 2   -   3 -  4  - 5   -  6  -  7  -w p1 -b kni-b bi1  -b q  -b bi1  -b kni-b p1   -2    - 3   - 4   - 5   - 6   - b p0- implicit b p0.
#After the kings come all the prior en passant positions. which are empty at start. Then we start at whites bottom right, and move across rows to middle. Then we go to blacks bottom left, and fill across to the middle.
#Changing start to properly encode rooks for castling
newpieces= c(F,F,F,F,F,F,F,F,T,F,F,F,T,F,F,F ,pieces[-(1:16)])
test2 = decode(c(startboard,newpieces))
</code>```

This code builds 4 functions. One that does some basic separation of the pieces and the board structure, as well as figuring out piece type and any 'implicit' pieces. The next function fills in the board structure with those pieces in a slightly bizzarre (and different from my initial algorithm's) order [explained in code comments]. The next function takes the filled in board and detects any illegal positions -- it then fixes them and renames pawns that are vulnerable to en passant "x pawn-e" and any rooks that can castle "x rook-c". The final function is a wrapper that runs those functions in order and gives an output which is the current board as well as the turn.

I've also included the encoding of the start position (though to see it you will have to call c(startboard,newpieces) and the code calls the wrapper function on that position.

Title: Smallest chess board compression

Body:
171 bits worst case:

I've combined a couple of ideas, as well as some of my own thoughts.

We are going to start with a 64 bit board. Each bit represents an occupied space on the board. They fill along rows.
So the start looks like: 1111 1111 1111 1111 0000 0000 0000 0000 0000 0000 0000 0000 1111 1111 1111 1111

Now, each piece will be represented by 4 bits.
1st bit: color (0=white, 1=black)
2nd-4th bits: One of 8 types.

0=king, 1=queen, 2=bishop0, 3=knight, 4=rook, 5=pawn0, 6=pawn1, 7=bishop1

At the end we will include a bit designating the turn. 0=white, 1=black.

4bits*32 pieces=128 bits and I've already got 64+1 from turn and board. That gives a total of 128+64+1=193 I haven't even started with en passant or castling. Well over my limit with nothing -- not even turns. This is where the tricks start.

Okay -- you see those types above? Bishop0 and Bishop1? Pawn0 and pawn1? Those types are so designated, because they tell us a bit to insert after this piece. So Bishop0 means that after it, there will be a 0 -- i.e that the next piece is white. Bishop1 tells us the next piece is black, and the pawn0 and pawn1 work the same. (If this piece is the last piece being enumerated, then it tells us about the next turn instead).

My worst case involves all the pieces on the board, so with 16 pawns and 4 bishops, this saves me 20 bits. I'm down to 173.

Okay. For another bit in my worst case -- once there are 16 of a color encoded, we stop encoding color -- as we know it going forwards. My worst case now involves a white piece making it to the far corner with no captures. There, I save only one bit. 172.

I'm going to now change the order in which I name the pieces. We will name them along columns starting at the outside moving in. The board named at the beginning will stay the same, but when I place pieces on it, i start from whites bottom right, and go up that column. Then I jump to black's bottom right, and go up that column. I jump to white's bottom right unknown cell, and so forth -- this means my worst case is again the start. My reason has to do with my en passant trick, the next two bits I lose, and castling.

Now, for a pawn to be promoted (as has been discussed at length) a piece must be captured. Thus, when we know there are 32 pieces, we only need to denote 31 of them. The last piece is uniquely identified. As it turns out, for me, this only saves 2 bits -- because my last piece might be a pawn/bishop (which normally costs me 3 bits because I save one on the next piece) who's color is determined already and so was only 2 bits. I'm down to 170 bits.

When pawns get promoted, they simply change their type. For each piece that goes off the board I rid myself of (minimum) 3 bits, and two pawn promotions cost me 2 bits, so I'm declining (slowly) in promotions.

Castling. For castling to happen, neither king nor relevant rook may have moved. Thus, when a rook is capable of castling both it and the king will be in their original places. So, rooks capable of castling will be listed in the same place as kings of that color. As this is illegal (two kings or three kings of the same color on the board) and only can happen in three possible setups for each color (left, right, both rooks are listed as kings) -- decoding is utterly possible. So, for no bits we have encoded castling.

En Passant Here we will also use illegal positions. Only one pawn can be in danger of en passant at a time. It must be in its fourth row. The pawn that is vulnerable will be 'flipped' back to its home row -- switched with whatever is there. As that pawn is in its own first row -- an illegal position, the situation will be obvious to the decoder -- it will reverse the positions, and mark the pawn as vulnerable to en passant.

We needed to muck about with the order because the last piece has to be 'uniquely identified'. In a standard order, we wouldn't be able to tell if the rook in the back corner could castle -- that's not known. When we work from the outside in, we guarantee that wherever that rook is 'listed' be it in its own corner, or in the middle of the board because it was switched with an en passant vulnerable pawn, there will be a piece listed after it -- so we are told the rook's type. We know there will be a piece after it because, for a pawn to be vulnerable there must be a pawn to its inside (which will crucially be encoded later as per the instructions above).

Oh, and to help make sure that the worst case involves all pieces on the board, once we have less than 32 pieces, we can use the 64 bit board to identify turn as well as occupied positions by using 0's to represent pieces when its white's turn and 1's when it is blacks turn.

So we got en passant and castling for free. We picked up the last piece for free, though it took some finagling with order to make that play nice with the en passant and castling rules. We ditched 20 bits on the standard pieces. I believe the worst case here involves a midde white pawn moved forward and a black piece in between it and its queen while all pieces are on the board.
Quick double check: first piece is captured -- call it a pawn, 3 bits off the board in the pawn, 3 bits on the board in the form of a last piece, one bit off in the turn marker disappearing. Promote two pawns 2 bits back on the board. Ah damn, I'm at 171.

EDIT I've added code for a (working?) decoder -- in R -- below. It takes vectors of booleans as input -- (sorry -- I'm not capable of coding well in anything that would let me actually use the bits) I've also included the start position.

separate = function(vec){
    #Using a boolean vector (sorry R doesn't handle bits well and this will build quickest)
    board = matrix(vec[1:64],8,8,byrow=T)
    npieces = min(sum(board),64-sum(board))
    n = length(vec)
    a = vec[65:n]
    counter = 0
    pieces = list()
    white = 0
    Letters=c(letters,LETTERS)
    for (i in 1:npieces){
        col = ifelse(a[1],"black",{white=white+1;"white"})
        typ = a[2:4]
        a=a[-(1:4)]
        num = 4*typ[1] + 2*typ[2] + typ[3]
        type = switch(letters[num+1],a="king",b="queen",c="knight",d="rook",e="bishop0",f="bishop1",g="pawn0",h="pawn1")
        if (num > 3) {
            if(num%%2){
                a = c(T,a)
            } else {
                a = c(F,a)
            }
            type = substr(type,1,nchar(type)-1)
        }
        pieces[[Letters[i]]] = list(color=col,type=type)
        if (length(pieces)==31&&npieces==32) {
            col = ifelse(16-white,{white=white+1;"white"},"black")
            type = "TBD"
            pieces[[Letters[i+1]]] = list(color=col,type=type)
            break
        }
    }

    if (npieces==32) {
        f=function(y){sum(sapply(pieces,function(x)x$type==y))}
        if (f("pawn")<16) {pieces[[32]]$type="pawn"}
        if (f("bishop")<4) {pieces[[32]]$type="bishop"}
        if (f("knight")<4) {pieces[[32]]$type="knight"}
        if (f("queen")<2)  {pieces[[32]]$type="queen"}
        if (f("king")<2)   {pieces[[32]]$type="king"}
        if (f("rook")<(6-f("king"))) {pieces[[32]]$type="rook"}
    }
    return(list(board,pieces,turn=ifelse(a[length(a)],"black","white")))
}

fillboard = function(out) {
    board = out[[1]]
    pieces = out[[2]]
    turn = out[[3]]
    lpieces = lapply(pieces,function(x) paste(substr(x$color,1,1),x$type))
    game = matrix("     ",8,8)
    #Start with corners.
    a = c(1,57,8,64)
    #Then kings
    b = c(25,32)
    #Then rooks in en passant
    c = c(4,60,5,61)
    #Then kings in en passant
    d = 28:29
    exceptions = list(a,b,c,d)
    for (places in exceptions) {
        c= which(board[places])
        if (length(c)) {
            repl = lpieces[1:length(c)]
            game[places[c]] = unlist(repl)
            board[places] = F
            lpieces = lpieces[-(1:length(c))]
        }
    }
    #Loop through rows.
    for (i in c(1:4,8:5)) {
        j = which(board[i,])
        if (length(j)) {
            repl = lpieces[1:length(j)]
            game[i,j] = unlist(repl)
            board[i,j] = F
            lpieces = lpieces[-(1:length(j))]
        }
    }
    return(matrix(unlist(game),8,8,F))
}

swapillegal = function(matr) {
    mat = matr
    if (any(mat[8,]=="b pawn")) {
        j = which(mat[8,]=="b pawn")
        mat[8,j] = mat[5,j]
        mat[5,j] = "b pawn-e"
    }
    if (any(mat[1,]=="w pawn")) {
        j = which(mat[1,]=="w pawn")
        mat[1,j] = mat[4,j]
        mat[4,j] = "w pawn-e"
    }

    if (sum(mat[8,]=="b king") > 1) {
        j = which(mat[8,-4]=="b king")
        j[j==7] = 8
        mat[8,j] = "b rook-c"
    }
    if (sum(mat[1,]=="w king") >1) {
        j = which(mat[1,-4]=="w king")
        j[j==7] = 8
        mat[1,j] = "w rook-c"
    }
    return(mat)
}

decode = function(vec) {
    a = separate(vec)
    b = fillboard(a)
    c = swapillegal(b)
    list(board=c,turn=a[[3]])
}

startboard = c(rep(T,16),rep(F,32),rep(T,16))
#Re-ordering -- first spots will be the corners. Then kings. then en passant positions of those spots
pieces = c(F,F,T,T,F,F,T,T,T,F,T,T,T,F,T,T,F,F,F,F,T,F,F,F,F,F,T,F,F,T,F,F,F,F,T,F,T,F,F,F,T,F,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,F,T,T,T,F,T,F,T,T,F,T,F,F,T,T,T,F,T,F,T,F,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,T,F)
########## w rook -w rook -B rook -B rook -W king -B king -w kni  -w bi 0 -w Q  -w Bi 0 -w kni-w p0   - 2   -   3 -  4  - 5   -  6  -  7  -w p1 -b kni-b bi1  -b q  -b bi1  -b kni-b p1   -2    - 3   - 4   - 5   - 6   - b p0- implicit b p0.
#After the kings come all the prior en passant positions. which are empty at start. Then we start at whites bottom right, and move across rows to middle. Then we go to blacks bottom left, and fill across to the middle.
#Changing start to properly encode rooks for castling
newpieces= c(F,F,F,F,F,F,F,F,T,F,F,F,T,F,F,F ,pieces[-(1:16)])
test2 = decode(c(startboard,newpieces))

This code builds 4 functions. One that does some basic separation of the pieces and the board structure, as well as figuring out piece type and any 'implicit' pieces. The next function fills in the board structure with those pieces in a slightly bizzarre (and different from my initial algorithm's) order [explained in code comments]. The next function takes the filled in board and detects any illegal positions -- it then fixes them and renames pawns that are vulnerable to en passant "x pawn-e" and any rooks that can castle "x rook-c". The final function is a wrapper that runs those functions in order and gives an output which is the current board as well as the turn.

I've also included the encoding of the start position (though to see it you will have to call c(startboard,newpieces) and the code calls the wrapper function on that position.


问:
Convert xxd output to shellcode
Taking some output from xxd and turning it into usable shellcode by hand is no fun, so your job is to automate the process.

Rules

Your submission can be a function, lambda, script, or any reasonable equivalent of those. You may print the result, or if your submission is a function/lambda then you may also return it.

You program must take three arguments, the first being a string containing the output of xxd, ran with no arguments other than a filename, like this: xxd some_file. Here's an example of what the the first argument will look like:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Your need to take that middle section containing the bytes (the first 8 columns after the :) and turn it into shellcode by removing any whitespace, then putting a \x before each byte.

Here's what the output should be for the input above (ignoring any other arguments):

\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e\x58\x58\x58\x58\x59\x59\x59\x59

You can assume the first argument will always be a valid xxd output, ran with no arguments other than the filename.

Your output should also be a string where the backslashes are literal backslashes, not used as escape characters. So when I say "\x65", I'm not talking about the byte 0x65, or even the letter "A". In code, it would be the string "\x65".

The second argument specifies where in the xxd output the shellcode should start, and the third specifies where it should end. If the third argument is -1, it will end at the end of xxd output. The second and third argument will also always be non negative, except for when the third is -1

Here are some test cases:

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: 7, Argument 3: e (these are both strings representing hexadecimal numbers)

Output: \xc9\xcd\x80\xeb\x16\x5b\x31\xc0

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: 0, Argument 3: 2e

Output: \x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: a, Argument 3: -1

Output: \xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e\x58\x58\x58\x58\x59\x59\x59\x59

The code with the least bytes wins. The winner will be announced in seven days, on August 15, 2016 (but submissions after then are still appreciated).

Update

Congrats to @Adnan to winning the challenge!

答:
05AB1E, <s>39</s> 38 bytes

Input in the form:

```<code>arg2
arg3
arg1
</code>```

Code:

```<code>²\|vy9F¦}40£ðK}J2ô„\xì²H>²®Qi²}£¹HF¦}J
</code>```

Explanation:

```<code>²\                                       # Get the first two inputs and discard them.
  |                                      # Take the rest of the input as an array.
   vy         }                          # For each line...
     9F¦}                                #   Ten times, remove the first character.
         40£                             #   Only remain the substring [0:40].
            ðK                           #   Remove spaces.
               J                         # Join the string.
                2ô                       # Split into pieces of 2.
                  „\xì                   # Prepend a "\x" at each string.
                      ²H                 # Convert the second line from hex to int.
                        >                # Increment by one.
                         ²               # Push the second input again.
                          ®Qi }          # If equal to -1...
                             ²           #   Push the second input again.
                               £         # Take the substring [0:(² + 1)].
                                ¹H       # Convert the first input from hex to int.
                                  F¦}    # Remove that many characters at the beginning.
                                     J   # Join the array and implicitly output.
</code>```

Uses the CP-1252 encoding. Try it online!.

ContentLicense: CC BY-SA 3.0

Title: Convert xxd output to shellcode

Body:
05AB1E, <s>39</s> 38 bytes

Input in the form:

arg2
arg3
arg1

Code:

²\|vy9F¦}40£ðK}J2ô„\xì²H>²®Qi²}£¹HF¦}J

Explanation:

²\                                       # Get the first two inputs and discard them.
  |                                      # Take the rest of the input as an array.
   vy         }                          # For each line...
     9F¦}                                #   Ten times, remove the first character.
         40£                             #   Only remain the substring [0:40].
            ðK                           #   Remove spaces.
               J                         # Join the string.
                2ô                       # Split into pieces of 2.
                  „\xì                   # Prepend a "\x" at each string.
                      ²H                 # Convert the second line from hex to int.
                        >                # Increment by one.
                         ²               # Push the second input again.
                          ®Qi }          # If equal to -1...
                             ²           #   Push the second input again.
                               £         # Take the substring [0:(² + 1)].
                                ¹H       # Convert the first input from hex to int.
                                  F¦}    # Remove that many characters at the beginning.
                                     J   # Join the array and implicitly output.

Uses the CP-1252 encoding. <a href="http://05ab1e.tryitonline.net/#code=wrJcfHZ5OUbCpn00MMKjw7BLfUoyw7TigJ5ceMOswrJIPsKywq5RacKyfcKjwrlIRsKmfUo&input=YQotMQowMDAwMDAwMDogMzFjMCBiMDQ2IDMxZGIgMzFjOSBjZDgwIGViMTYgNWIzMSBjMDg4ICAxLi5GMS4xLi4uLi5bMS4uCjAwMDAwMDEwOiA0MzA3IDg5NWIgMDg4OSA0MzBjIGIwMGIgOGQ0YiAwODhkIDUzMGMgIEMuLlsuLkMuLi4uSy4uUy4KMDAwMDAwMjA6IGNkODAgZThlNSBmZmZmIGZmMmYgNjI2OSA2ZTJmIDczNjggNGU1OCAgLi4uLi4uLi9iaW4vc2hOWAowMDAwMDAzMDogNTg1OCA1ODU5IDU5NTkgNTkgICAgICAgICAgICAgICAgICAgICAgICBYWFhZWVlZ" rel="nofollow noreferrer">Try it online!.


问:
Keep nonzeros and their neighbours
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.

The challenge

Given an array of integer values, remove all zeros that are not flanked by some nonzero value.

Equivalently, an entry should be kept either if it's a nonzero or if it's a zero that is immediately close to a nonzero value.

The entries that are kept should maintain in the output the order they had in the input.

Example

Given

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0]
</code>```

the values that should be removed are marked with an x:

```<code>[2 0 4 -3 0 x 0 3 0 0 2 0 x]
</code>```

and so the output should be

```<code>[2 0 4 -3 0 0 3 0 0 2 0]
</code>```

Rules

The input array may be empty (and then the output should be empty too).

Input and output formats are flexible as usual: array, list, string, or anything that is reasonable.

Code golf, fewest best.

Test cases

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0] -> [2 0 4 -3 0 0 3 0 0 2 0]
[] -> []
[1] -> [1]
[4 3 8 5 -6] -> [4 3 8 5 -6]
[4 3 8 0 5 -6] -> [4 3 8 0 5 -6]
[0] -> []
[0 0] -> []
[0 0 0 0] -> []
[0 0 0 8 0 1 0 0] -> [0 8 0 1 0]
[-5 0 5] -> [-5 0 5]
[50 0] -> [50 0]
</code>```

答:
Haskell, 48 bytes

p%(h:t)=[h|any(/=0)$p:h:take 1t]++h%t
p%e=e
(0%)
```

Looks at the previous element p, the first element h, and the element after (if any), and if any are nonzero, prepends the first element h.

The condition any(/=0)$p:h:take 1t is lengthy, in particular the take 1t. I'll look for a way to shorten it, perhaps by pattern matching.

Title: Keep nonzeros and their neighbours

Body:
Haskell, 48 bytes

p%(h:t)=[h|any(/=0)$p:h:take 1t]++h%t
p%e=e
(0%)

Looks at the previous element p, the first element h, and the element after (if any), and if any are nonzero, prepends the first element h.

The condition any(/=0)$p:h:take 1t is lengthy, in particular the take 1t. I'll look for a way to shorten it, perhaps by pattern matching.


问:
Snakes all around

Challenge

The challenge is simple: print a snake.

You will get the length of the snake as input.

A snake of length 2 looks like this:

```<code>==(:)-
</code>```

A snake of length 7 looks like this:

```<code>=======(:)-
</code>```

In other words, the length of a snake is how many equal signs are before the head.

Usage

Let's say I made a C++ implementation and compiled it to ./getsnake.

I could run it like so:

```<code>$ ./getsnake 10
==========(:)-
</code>```

Clarifications

Standard loopholes are disallowed.

You can get input and output in any acceptable way.

You can assume all inputs given are positive integers.

You may write a function instead of a regular program.

答:
Factor 34

```<code>[ [ "="write ] times "(:>~"print ]
</code>```

Quotation (anonymous function) that takes a number and prints a snake.

Alternative (also 34):

```<code>[ 61 <string> ":>~""("glue print ]
</code>```

Sorry, but i made some aesthetic changes...

```<code>10 [ [ "="write ] times "(:>~"print ] call
==========(:>~
</code>```

Title: Snakes all around

Body:
Factor 34

[ [ "="write ] times "(:>~"print ]

Quotation (anonymous function) that takes a number and prints a snake.

Alternative (also 34):

[ 61 <string> ":>~""("glue print ]

Sorry, but i made some aesthetic changes...

10 [ [ "="write ] times "(:>~"print ] call
==========(:>~


答:
Mathematica, 43 bytes

```<code>ArrayFilter[If[#.#>0,#[[2]],Nothing]&,#,1]&
</code>```

Title: Keep nonzeros and their neighbours

Body:
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.

The challenge

Given an array of integer values, remove all zeros that are not flanked by some nonzero value.

Equivalently, an entry should be kept either if it's a nonzero or if it's a zero that is immediately close to a nonzero value.

The entries that are kept should maintain in the output the order they had in the input.

Example

Given

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0]
</code>```

the values that should be removed are marked with an x:

```<code>[2 0 4 -3 0 x 0 3 0 0 2 0 x]
</code>```

and so the output should be

```<code>[2 0 4 -3 0 0 3 0 0 2 0]
</code>```

Rules

The input array may be empty (and then the output should be empty too).

Input and output formats are flexible as usual: array, list, string, or anything that is reasonable.

Code golf, fewest best.

Test cases

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0] -> [2 0 4 -3 0 0 3 0 0 2 0]
[] -> []
[1] -> [1]
[4 3 8 5 -6] -> [4 3 8 5 -6]
[4 3 8 0 5 -6] -> [4 3 8 0 5 -6]
[0] -> []
[0 0] -> []
[0 0 0 0] -> []
[0 0 0 8 0 1 0 0] -> [0 8 0 1 0]
[-5 0 5] -> [-5 0 5]
[50 0] -> [50 0]
</code>```

Body:
Mathematica, 43 bytes

ArrayFilter[If[#.#>0,#[[2]],Nothing]&,#,1]&


答:
C, 96 bytes

Call f() with a pointer to the list of integers, and a pointer to the size of the list. The list and size are modified in-place.

```<code>i,t,e,m;f(int*p,int*n){int*s=p;for(i=m=e=0;i++<*n;s+=t=m+*s||i<*n&&p[1],e+=t,m=*p++)*s=*p;*n=e;}
</code>```

Try it on ideone.

Title: Keep nonzeros and their neighbours

Body:
C, 96 bytes

Call f() with a pointer to the list of integers, and a pointer to the size of the list. The list and size are modified in-place.

i,t,e,m;f(int*p,int*n){int*s=p;for(i=m=e=0;i++<*n;s+=t=m+*s||i<*n&&p[1],e+=t,m=*p++)*s=*p;*n=e;}

Try it on ideone.


问:
Tips for golfing in Haskell
What general tips do you have for golfing in Haskell? I am looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Haskell. Please post only one tip per answer.

If you are new to golfing in Haskell, please have a look at the Guide to Golfing Rules in Haskell. There is also a dedicated Haskell chat room: Of Monads and Men.

答:
Get suffixes

Use scanr(:)[] to get the suffixes of a list:

```<code>λ scanr(:)[] "abc"
["abc","bc","c",""]
</code>```

This is much shorter than tails after import Data.List. You can do prefixes with scanr(\_->init)=<<id (found by Ørjan Johansen).

```<code>λ  scanr(\_->init)=<<id $ "abc"
["","a","ab","abc"]
</code>```

This saves a byte over

```<code>scanl(\s c->s++[c])[]
</code>```

Title: Tips for golfing in Haskell

Body:
Get suffixes

Use scanr(:)[] to get the suffixes of a list:

λ scanr(:)[] "abc"
["abc","bc","c",""]

This is much shorter than tails after import Data.List. You can do prefixes with scanr(\_->init)=<<id (found by Ørjan Johansen).

λ  scanr(\_->init)=<<id $ "abc"
["","a","ab","abc"]

This saves a byte over

scanl(\s c->s++[c])[]

ContentLicense: CC BY-SA 4.0


答:
Python, 140 bytes

```<code>lambda O,a,b:''.join(sum([['\\x'+x[:2],('','\\x')[len(x)>2]+x[2:]]for x in O.split()if len(x)<5],[])[int(a,16):(int(b,16)+1,None)[b=='-1']])
</code>```

https://repl.it/ClB3

Splits the original string and dumps the elements if they're less than five characters, prepends \x, and slices by the second and third arguments.

162 byte version if we need to handle other types of output not specified by the question:

```<code>import re
J=''.join
def f(x,a,b):r=J(J(re.findall(':(.*?)  ',x)).split());print J(['\\x'+i+j for i,j in zip(r,r[1:])][::2][int(a,16):(int(b,16)+1,None)[b=='-1']])
</code>```

Title: Convert xxd output to shellcode

Body:
Taking some output from xxd and turning it into usable shellcode by hand is no fun, so your job is to automate the process.

Rules

Your submission can be a function, lambda, script, or any reasonable equivalent of those. You may print the result, or if your submission is a function/lambda then you may also return it.

You program must take three arguments, the first being a string containing the output of xxd, ran with no arguments other than a filename, like this: xxd some_file. Here's an example of what the the first argument will look like:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Your need to take that middle section containing the bytes (the first 8 columns after the :) and turn it into shellcode by removing any whitespace, then putting a \x before each byte.

Here's what the output should be for the input above (ignoring any other arguments):

\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e\x58\x58\x58\x58\x59\x59\x59\x59

You can assume the first argument will always be a valid xxd output, ran with no arguments other than the filename.

Your output should also be a string where the backslashes are literal backslashes, not used as escape characters. So when I say "\x65", I'm not talking about the byte 0x65, or even the letter "A". In code, it would be the string "\x65".

The second argument specifies where in the xxd output the shellcode should start, and the third specifies where it should end. If the third argument is -1, it will end at the end of xxd output. The second and third argument will also always be non negative, except for when the third is -1

Here are some test cases:

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: 7, Argument 3: e (these are both strings representing hexadecimal numbers)

Output: \xc9\xcd\x80\xeb\x16\x5b\x31\xc0

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: 0, Argument 3: 2e

Output: \x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: a, Argument 3: -1

Output: \xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e\x58\x58\x58\x58\x59\x59\x59\x59

The code with the least bytes wins. The winner will be announced in seven days, on August 15, 2016 (but submissions after then are still appreciated).

Update

Congrats to @Adnan to winning the challenge!

Body:
Python, 140 bytes

lambda O,a,b:''.join(sum([['\\x'+x[:2],('','\\x')[len(x)>2]+x[2:]]for x in O.split()if len(x)<5],[])[int(a,16):(int(b,16)+1,None)[b=='-1']])

https://repl.it/ClB3

Splits the original string and dumps the elements if they're less than five characters, prepends \x, and slices by the second and third arguments.

162 byte version if we need to handle other types of output not specified by the question:

import re
J=''.join
def f(x,a,b):r=J(J(re.findall(':(.*?)  ',x)).split());print J(['\\x'+i+j for i,j in zip(r,r[1:])][::2][int(a,16):(int(b,16)+1,None)[b=='-1']])


问:
Can you outgolf me? (Robbers section)

Robbers section

The cops section can be found here.

Challenge

Your task is to outgolf the submissions of the cops in the same language and the same version (for example, Python 3.5 ≠ Python 3.4, so that is not allowed). A submission is outgolfed when the length in bytes is shorter than the original submission. You only need to golf off at least 1 byte in order to crack a submission. E.g. if the task was to perform 2 × n, and the submission was the following:

```<code>print(2*input())
</code>```

You could outgolf the cop by doing the following:

```<code>print 2*input()
</code>```

Or even this (since lambda's are allowed):

```<code>lambda x:2*x
</code>```

Post this with the following header:

```<code>##{language name}, <s>{prev byte count}</s> {byte count}, {cop's submission + link}
</code>```

For example:

Python 2, <s>16</s> 12 bytes, Adnan (+ link to submission)

```<code>lambda x:2*x
</code>```

Computes A005843, (offset = 0).

In that case, you have cracked the submission.

Scoring

The person with who cracked the most submissions is the winner.

Rules

The crack submission must be in the same language as the cop submission.

The same input should result into the same output (so a(2) = 4 should remain 4).

For languages such as Python, you can import libraries that are standard included within the language. (So, no numpy/sympy etc.)

Input and output are both in decimal (base 10).

Note

This challenge is finished. The winner of the Robbers section is feersum. The final scores for the CnR are shown below:

feersum: 16 cracks

Dennis: 12 cracks

Leaky Nun: 6 cracks

Lynn: 4 cracks

miles: 3 cracks

Martin Ender: 2 cracks

Emigna: 2 cracks

jimmy23013: 1 crack

Sp3000: 1 crack

randomra: 1 crack

alephalpha: 1 crack

nimi: 1 crack

Destructible Watermelon: 1 crack

Dom Hastings: 1 crack

Title: Can you outgolf me? (Robbers section)

Body:
MarioLANG, <s>87</s> 86 bytes, Business Cat

Don't know how I did it, but here it is I think

;
)-)+(< >>(
-)===" ""====
>>+([!)( >-(
"====#[(("==+[
!-) - <!!![)<<)
#======###====:


答:
Bash + GNU utils, 25

```<code>grep -vC1 ^0|grep -v \\-$
</code>```

Accepts input as a newline-separated list.

Ideone - with test driver code added to run all testcases together by converting to/from space-separated and newline-separated.

Title: Keep nonzeros and their neighbours

Body:
Bash + GNU utils, 25

grep -vC1 ^0|grep -v \\-$

Accepts input as a newline-separated list.

Ideone - with test driver code added to run all testcases together by converting to/from space-separated and newline-separated.


问:
Print the Capitals without the Capitals
Whoa, whoa, whoa ... stop typing your program. No, I don't mean "print ABC...." I'm talking the capitals of the United States.

Specifically, print all the city/state combinations given in the following list

in any order

with your choice of delimiters (e.g., Baton Rouge`LA_Indianapolis`IN_... is acceptable), so long as it's unambiguous which words are cities, which are states, and which are different entries

without using any of ABCDEFGHIJKLMNOPQRSTUVWXYZ in your source code

Output should be to STDOUT or equivalent.

EDIT - Whoops!

<edit>

While typing up the list from memory (thanks to the Animaniacs, as described below), I apparently neglected Washington, DC, which isn't a state capital, but is in the song, and is sometimes included in "lists of capitals" (like the Mathematica answer below). I had intended to include that city in this list, but missed it, somehow. As a result, answers that don't have that city won't be penalized, and answers that do have that city won't be penalized, either. Essentially, it's up to you whether Washington, DC is included in your ouput or not. Sorry about that, folks!

</edit>

```<code>Baton Rouge, LA
Indianapolis, IN
Columbus, OH
Montgomery, AL
Helena, MT
Denver, CO
Boise, ID
Austin, TX
Boston, MA
Albany, NY
Tallahassee, FL
Santa Fe, NM
Nashville, TN
Trenton, NJ
Jefferson, MO
Richmond, VA
Pierre, SD
Harrisburg, PA
Augusta, ME
Providence, RI
Dover, DE
Concord, NH
Montpelier, VT
Hartford, CT
Topeka, KS
Saint Paul, MN
Juneau, AK
Lincoln, NE
Raleigh, NC
Madison, WI
Olympia, WA
Phoenix, AZ
Lansing, MI
Honolulu, HI
Jackson, MS
Springfield, IL
Columbia, SC
Annapolis, MD
Cheyenne, WY
Salt Lake City, UT
Atlanta, GA
Bismarck, ND
Frankfort, KY
Salem, OR
Little Rock, AR
Des Moines, IA
Sacramento, CA
Oklahoma City, OK
Charleston, WV
Carson City, NV
</code>```

(h/t to Animaniacs for the list of capitals)

Take a bonus of -20% if your submission doesn't explicitly have the numbers 65 through 90 or the number 1 in the code. Generating these numbers (e.g., a=5*13 or a="123"[0] or a=64;a++ or the like) is allowed under this bonus, explicitly having them (e.g., a=65 or a="1 23 456"[0]) is not.

Leaderboard

var QUESTION_ID=60650,OVERRIDE_USER=42963;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+(?:[.]\d+)?)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

答:
Ruby, (925 * 80%) = 740 bytes

```<code>require "zlib";eval "puts \x5alib::inflate('789c35925db2da300c85dfb50a16a04d98044a203f0ca450faa64b44e2892333b6c394dd57e1b66fdfb1251fe98c8dfb2279637d0323424fef6cc42a07931c4922fc61c0ccfd1c15ab8d624c56b0fd056b4a5e56273ff78ca581b58d1385fb88750e6b6f2363b140d422ac0c6414a2966736a9d305b28182e3cfe57551fc6611c6eb0d32efe6e9cb129eb37f3c476c76ca72f7a1c37a0739cb8b03668d525c55de0a472c0ce47e39ce37b00d24e3c38784871bec28041bbfe6d0e3d12c2a3d9677b21676ec58742b252f6ae566dc15504867e97f0e450d7bba8f7159e20c7b7e3c387c4403fb59986634072849a2951eab024aab533ac17aa39892630d48333127a8a8b34be7b580ca4beafdc4e18da6fca8273baba35f5aa8290e2feb1c635b43333a1afc44dfb1350768dc7b7a6a365703c7c1b3d83f687ec3517b03e3398763f02fdbb1dc194f059cc8b1ed07ac3338d9fb3079e9f062e04cf740134bf2982dca4a5a1d697658d5aa1c4fd89c1648ab9246fef6fed9ea89fe86d596b1aee0fc0cbaf0c3b2ebb028a125a783528cccb855e99f3c121eced086c546e3d8c35f3dcecbfd'.scan(/.{2}/).map {|i|i.hex.chr}.join)"
</code>```

Oof, this one was hard. This is a Zlib compressed string in hex encoded bytes, which is then decompressed, turned into an array of strings by the scan regex, then each string is converted to a decimal integer, then to a character, and finally this array is joined into a string. I might post a better version later that uses a modified base64 encoding.

Though the encoded string may have some instances of 65-90 or 1's, I don't count those because the string is one huge number in hexadecimal. Thus this qualifies for the 20% bonus.

Title: Print the Capitals without the Capitals

Body:
Ruby, (925 * 80%) = 740 bytes

require "zlib";eval "puts \x5alib::inflate('789c35925db2da300c85dfb50a16a04d98044a203f0ca450faa64b44e2892333b6c394dd57e1b66fdfb1251fe98c8dfb2279637d0323424fef6cc42a07931c4922fc61c0ccfd1c15ab8d624c56b0fd056b4a5e56273ff78ca581b58d1385fb88750e6b6f2363b140d422ac0c6414a2966736a9d305b28182e3cfe57551fc6611c6eb0d32efe6e9cb129eb37f3c476c76ca72f7a1c37a0739cb8b03668d525c55de0a472c0ce47e39ce37b00d24e3c38784871bec28041bbfe6d0e3d12c2a3d9677b21676ec58742b252f6ae566dc15504867e97f0e450d7bba8f7159e20c7b7e3c387c4403fb59986634072849a2951eab024aab533ac17aa39892630d48333127a8a8b34be7b580ca4beafdc4e18da6fca8273baba35f5aa8290e2feb1c635b43333a1afc44dfb1350768dc7b7a6a365703c7c1b3d83f687ec3517b03e3398763f02fdbb1dc194f059cc8b1ed07ac3338d9fb3079e9f062e04cf740134bf2982dca4a5a1d697658d5aa1c4fd89c1648ab9246fef6fed9ea89fe86d596b1aee0fc0cbaf0c3b2ebb028a125a783528cccb855e99f3c121eced086c546e3d8c35f3dcecbfd'.scan(/.{2}/).map {|i|i.hex.chr}.join)"

Oof, this one was hard. This is a Zlib compressed string in hex encoded bytes, which is then decompressed, turned into an array of strings by the scan regex, then each string is converted to a decimal integer, then to a character, and finally this array is joined into a string. I might post a better version later that uses a modified base64 encoding.

Though the encoded string may have some instances of 65-90 or 1's, I don't count those because the string is one huge number in hexadecimal. Thus this qualifies for the 20% bonus.


问:
Fraction to exact decimal
Write a program or function that given two integers a, b outputs a string containing a decimal number representing the fraction a/b exactly.

If a/b is integer, simply output the value, without a decimal dot or leading zeroes:

```<code>123562375921304812375087183597 / 2777 -> 44494913907563850333124661
81 / 3 -> 27
-6 / 2 -> -3
</code>```

If a/b is not integer but has a finite representation in base 10, output the value without leading or trailing zeroes (except a single zero before the dot):

```<code>1 / 2 -> 0.5
3289323463 / -250000000 -> -13.157293852
</code>```

Finally, if and only if (so no 0.999...) a/b is not integer and does not have a finite representation, output the finite part followed by the repeating part in parenthesis. The repeating part must be as small as possible, and start as early as possible.

```<code>-1 / 3 -> -0.(3)
235 / 14 -> 16.7(857142)
123 / 321 -> 0.(38317757009345794392523364485981308411214953271028037)
355 / 113 -> 3.(1415929203539823008849557522123893805309734513274336283185840707964601769911504424778761061946902654867256637168)
</code>```

Your program must work for all above examples in under 10 seconds on a modern desktop PC. Smallest program in bytes wins.

答:
Python 2, 174 bytes

x,y=input()
a=abs(x)
b=abs(y)
r=a%b*10
L=[]
M=''
while~-(r in L):L+=r,;M+=str(r/b);r=r%b*10
i=L.index(r)
t=M[:i]+"(%s)"%M[i:]*(M[i:]>'0')
print"-%d."[x*y>=0:(t>'')+3]%(a/b)+t
```

I'm not quite convinced about the validity of this answer, but it's worked for the test cases above and other test cases I've thrown at it. It looks like a right mess though, so I'm sure there's plenty of room for golfing.

The initial setup takes absolute values of both arguments to ensure that we're dealing with nonnegative numbers (saving the sign calculation for later), and delegates the quotient part of the result to Python's arbitrary precision arithmetic. The fractional part is done with the grade-school division algorithm until we get a repeat in the remainder. We then look up when we last saw this repeat in order to get the period, and construct the string accordingly.

Note that the algorithm's actually quite slow due to the O(n) in operation, but it's fast enough for the examples.

Title: Fraction to exact decimal

Body:
Python 2, 174 bytes

x,y=input()
a=abs(x)
b=abs(y)
r=a%b*10
L=[]
M=''
while~-(r in L):L+=r,;M+=str(r/b);r=r%b*10
i=L.index(r)
t=M[:i]+"(%s)"%M[i:]*(M[i:]>'0')
print"-%d."[x*y>=0:(t>'')+3]%(a/b)+t

I'm not quite convinced about the validity of this answer, but it's worked for the test cases above and other test cases I've thrown at it. It looks like a right mess though, so I'm sure there's plenty of room for golfing.

The initial setup takes absolute values of both arguments to ensure that we're dealing with nonnegative numbers (saving the sign calculation for later), and delegates the quotient part of the result to Python's arbitrary precision arithmetic. The fractional part is done with the grade-school division algorithm until we get a repeat in the remainder. We then look up when we last saw this repeat in order to get the period, and construct the string accordingly.

Note that the algorithm's actually quite slow due to the O(n) in operation, but it's fast enough for the examples.


答:
Jelly, <s>9</s> 8 bytes, Dennis

```<code>œċr0$L€Ḅ
</code>```

Sorry! I wasn't able to find your intended solution.

This relies on the fact that C(n+k-1, k) is the number of ways to choose k values from n with replacement.

Note: This is inefficient since it generates the possible sets in order to count them, so try to avoid using large values of n online.

Try it online or Verify up to n.

I later found another 8 byte version that is efficient enough to compute n = 1000. This computes the values using the binomial coefficient and avoids generating the lists.

```<code>Ḷ+c’Ṛ;1Ḅ
</code>```

Try it online or Verify up to n.

Explanation

```<code>œċr0$L€Ḅ  Input: n
  r0$     Create a range [n, n-1, ..., 0]
œċ        Create all combinations with replacement for
          (n, n), (n, n-1), ..., (n, 0)
     L€   Find the length of each
       Ḅ  Convert it from binary to decimal and return

Ḷ+c’Ṛ;1Ḅ  Input: n
Ḷ         Creates the range [0, 1, ..., n-1]
 +        Add n to each in that range
   ’      Get n-1
  c       Compute the binomial coefficients between each
    Ṛ     Reverse the values
     ;1   Append 1 to it
       Ḅ  Convert it from binary to decimal and return
</code>```

Title: Can you outgolf me? (Robbers section)

Body:
Robbers section

The cops section can be found here.

Challenge

Your task is to outgolf the submissions of the cops in the same language and the same version (for example, Python 3.5 ≠ Python 3.4, so that is not allowed). A submission is outgolfed when the length in bytes is shorter than the original submission. You only need to golf off at least 1 byte in order to crack a submission. E.g. if the task was to perform 2 × n, and the submission was the following:

```<code>print(2*input())
</code>```

You could outgolf the cop by doing the following:

```<code>print 2*input()
</code>```

Or even this (since lambda's are allowed):

```<code>lambda x:2*x
</code>```

Post this with the following header:

```<code>##{language name}, <s>{prev byte count}</s> {byte count}, {cop's submission + link}
</code>```

For example:

Python 2, <s>16</s> 12 bytes, Adnan (+ link to submission)

```<code>lambda x:2*x
</code>```

Computes A005843, (offset = 0).

In that case, you have cracked the submission.

Scoring

The person with who cracked the most submissions is the winner.

Rules

The crack submission must be in the same language as the cop submission.

The same input should result into the same output (so a(2) = 4 should remain 4).

For languages such as Python, you can import libraries that are standard included within the language. (So, no numpy/sympy etc.)

Input and output are both in decimal (base 10).

Note

This challenge is finished. The winner of the Robbers section is feersum. The final scores for the CnR are shown below:

feersum: 16 cracks

Dennis: 12 cracks

Leaky Nun: 6 cracks

Lynn: 4 cracks

miles: 3 cracks

Martin Ender: 2 cracks

Emigna: 2 cracks

jimmy23013: 1 crack

Sp3000: 1 crack

randomra: 1 crack

alephalpha: 1 crack

nimi: 1 crack

Destructible Watermelon: 1 crack

Dom Hastings: 1 crack

Body:
Jelly, <s>9</s> 8 bytes, Dennis

œċr0$L€Ḅ

Sorry! I wasn't able to find your intended solution.

This relies on the fact that C(n+k-1, k) is the number of ways to choose k values from n with replacement.

Note: This is inefficient since it generates the possible sets in order to count them, so try to avoid using large values of n online.

Try it online or Verify up to n.

I later found another 8 byte version that is efficient enough to compute n = 1000. This computes the values using the binomial coefficient and avoids generating the lists.

Ḷ+c’Ṛ;1Ḅ

Try it online or Verify up to n.

Explanation

œċr0$L€Ḅ  Input: n
  r0$     Create a range [n, n-1, ..., 0]
œċ        Create all combinations with replacement for
          (n, n), (n, n-1), ..., (n, 0)
     L€   Find the length of each
       Ḅ  Convert it from binary to decimal and return

Ḷ+c’Ṛ;1Ḅ  Input: n
Ḷ         Creates the range [0, 1, ..., n-1]
 +        Add n to each in that range
   ’      Get n-1
  c       Compute the binomial coefficients between each
    Ṛ     Reverse the values
     ;1   Append 1 to it
       Ḅ  Convert it from binary to decimal and return


问:
Can you outgolf me? (Cops section)

Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

Python 2, 16 bytes, score = 15 / 16 = 0.9375

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

More information can be found here.

Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

Rules

The task you need to do is an OEIS sequence of your choice.

Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).

Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).

In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.

Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)

Input and output are both in decimal (base 10)

Leaderboard

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea">

Uncracked submissions

 Language	 Score	 User

Sort by: score creation

Safe submissions

 Language	 Score	 User

```

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

答:
Brachylog, 11 bytes, score = 10 / 11 = 0.909, cracked!

```<code>ybLrb:Lrcc.
</code>```

Computes A173426.

Try it online!

Explanation

```<code>ybL      L = [1, 2, …, Input]
rb       Get [Input - 1, …, 2, 1]
:Lrc     Concatenate [1, 2, …, Input] and [Input - 1, …, 2, 1]
c.       Concatenate [1, 2, …, Input, Input - 1, …, 2, 1] into a single integer
</code>```

Title: Can you outgolf me? (Cops section)

Body:
Brachylog, 11 bytes, score = 10 / 11 = 0.909, cracked!

ybLrb:Lrcc.

Computes A173426.

Try it online!

Explanation

ybL      L = [1, 2, …, Input]
rb       Get [Input - 1, …, 2, 1]
:Lrc     Concatenate [1, 2, …, Input] and [Input - 1, …, 2, 1]
c.       Concatenate [1, 2, …, Input, Input - 1, …, 2, 1] into a single integer


问:
Write a program that uses all printable non-alphanumeric ASCII symbols
In particular, use each of these symbols at least once in your source code:

```<code>! " # $ % & ' () * + , - .  / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
</code>```

Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count (but their delimiters such as /**/ or "" do count).

The program should not perform any action. It just has to compile and do nothing when run.

If for some reason some of the symbols cannot be used in the language of your choice, explain that rigorously (what and why must be excluded).

Update: A few answers used symbols withing regular expressions. I'd consider this a bit problematic, it's the same thing as putting them into string literals or comments (that's why I put etc. in that requirement). Please try without this. I also updated the requirement above.

Update: Shortest code wins (tagged as code-golf). As suggested, we'll most likely need some tie-breaker criteria. I suggest that if there is a tie, the winning one is the one in which the ASCII symbols appear as much ordered as possible. Formally: Filter out the first occurrence of each of the listed symbols from a program. This will result in a permutation on the listed symbols. The program with less inversion number of its permutation wins.

Update: I'd be happy to see some/more solutions in regular/mainstream languages, such as C(++), Java, Scala, Haskell, etc.

答:
Perl, 32 chars

no hiding symbols in comments, string literals, or regular expressions. uses all symbols precisely once.

```<code>$`<@"^[(\{_},)]/+-~%'?&|:!*.=>;#
</code>```

Description

i have tried to indicate operator precedence with indentation: the right-most expressions are evaluated before those to their left

```<code>        $`            # scalar variable $ named `
      <               # numeric less-than inequality <
        @"            # array variable @ named "
                      #   (array evaluated in scalar context)
    ^                 # bitwise XOR ^
        [(\{_},)]     # array reference []
                      #   containing array ()
                      #     containing reference \
                      #       to anonymous hash reference {}
                      #         with one key "_"
                      #           and no value (nothing following comma ,)
                      #             (reference evaluated in scalar context)
      /               # numeric division /
        +-~%'         # unary addition +
                      #   and unary negation -
                      #     and bitwise complement ~
                      #       on hash variable % named '
                      #         (hash evaluated in scalar context)
  ?                   # ternary conditional operator ?:
    &|                # code reference variable & named |
  :                   # ternary conditional operator ?:
    ! *.              # logical negation !
                      #   on typeglob variable * named .
                      #     (typeglob evaluated in scalar context)
  =>                  # fat comma => for compound expression
                      #   (evaluates LHS as string, RHS is empty)
;                     # end of expression ;
#                     # start of comment #
</code>```

Body:
Perl, 32 chars

no hiding symbols in comments, string literals, or regular expressions. uses all symbols precisely once.

$`<@"^[(\{_},)]/+-~%'?&|:!*.=>;#

Description

i have tried to indicate operator precedence with indentation: the right-most expressions are evaluated before those to their left

        $`            # scalar variable $ named `
      <               # numeric less-than inequality <
        @"            # array variable @ named "
                      #   (array evaluated in scalar context)
    ^                 # bitwise XOR ^
        [(\{_},)]     # array reference []
                      #   containing array ()
                      #     containing reference \
                      #       to anonymous hash reference {}
                      #         with one key "_"
                      #           and no value (nothing following comma ,)
                      #             (reference evaluated in scalar context)
      /               # numeric division /
        +-~%'         # unary addition +
                      #   and unary negation -
                      #     and bitwise complement ~
                      #       on hash variable % named '
                      #         (hash evaluated in scalar context)
  ?                   # ternary conditional operator ?:
    &|                # code reference variable & named |
  :                   # ternary conditional operator ?:
    ! *.              # logical negation !
                      #   on typeglob variable * named .
                      #     (typeglob evaluated in scalar context)
  =>                  # fat comma => for compound expression
                      #   (evaluates LHS as string, RHS is empty)
;                     # end of expression ;
#                     # start of comment #


问:
Place a stone on an empty Go board
See also: Make a move on a Go board.

Task

Go is a board game where two players (Black and White) place stones on the intersections of grid lines on a 19×19 board. Black moves first — for example, on D4:

In this challenge, you must take a Go board coordinate like D4 as input, and output an ASCII representation of a board with the first move played at the given point.

Note that there is no column I. This is, historically, to reduce confusion with J and L.

This output consists of 19 lines, each containing 19 characters. The point with the stone on it is marked O. Empty points on the board are shown as ., except for the nine star points (at D4, D10, D16, K4, K10, K16, Q4, Q10, and Q16), which are marked *.

For example, given F5 as an input, your answer’s output must be:

```<code>...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
.....O.............
...*.....*.....*...
...................
...................
...................
</code>```

And given Q16 as input, your output must be:

```<code>...................
...................
...................
...*.....*.....O...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
</code>```

Rules

You may write a function that takes the coordinate as an argument, or a program that reads the coordinate from the command line or from STDIN.

You may choose to accept input either in lower-case or upper-case, but your answer doesn’t need to handle both.

The input is always a single string like a1 or T19, never a string + number or two strings.

If you write a full program, your answer must be printed to STDOUT as a string, optionally followed by a trailing newline. If your answer is a function, you may print to STDOUT, or return a string, or return an array/list of strings (rows), or return a two-dimensional array or nested list of characters.

This is code-golf. The shortest answer in bytes wins.

答:
><>, <s>98</s> 96 bytes

```<code>'_U'i-:b)-0\
+*a$%cv?(0:i<
{*+{4*\+
+4gf-o>1-:?!;:{:}=3*&::aa+%::0=2*&+&6%1-}-aa+,6%{*9=&
=9^^
</code>```

Note that there is an 0x14 in the first row after the first ', and an 0x19 between the 9 and the first ^ of the last line. Try it online!

The input is mapped so that A-T become 1-19 (with 0 denoting an imaginary "newline" column) and the integer row number is decremented by 1. The program does a loop from 379 down to 0, choosing a char from the bottom row as it goes (offset by 15, to account for the fact that you can't enter a literal newline in the codebox). Newlines are checked via i % 20 == 0, and star points are checked by ((i%20-1)%6)*((i/20)%6) == 9.

Title: Place a stone on an empty Go board

Body:
><>, <s>98</s> 96 bytes

'_U'i-:b)-0\
+*a$%cv?(0:i<
{*+{4*\+
+4gf-o>1-:?!;:{:}=3*&::aa+%::0=2*&+&6%1-}-aa+,6%{*9=&
=9^^

Note that there is an 0x14 in the first row after the first ', and an 0x19 between the 9 and the first ^ of the last line. Try it online!

The input is mapped so that A-T become 1-19 (with 0 denoting an imaginary "newline" column) and the integer row number is decremented by 1. The program does a loop from 379 down to 0, choosing a char from the bottom row as it goes (offset by 15, to account for the fact that you can't enter a literal newline in the codebox). Newlines are checked via i % 20 == 0, and star points are checked by ((i%20-1)%6)*((i/20)%6) == 9.


答:
Go, 319 286 bytes

```<code>import(."strconv"
."strings")
func g(c string)(s string){p:=SplitN(c,"",2)
n,_:=Atoi(p[1])
for i:=19;i>0;i--{
for j:= 'a';j<'t';j++{
if j=='i'{
}else if n==i&&ContainsRune(p[0],j){s+="o"
}else if((i==4||i==10||i==16)&&(j=='d'||j=='k'||j=='q')){s+="*"
}else{s+="."}}
s+="\n"}
return}
</code>```

Probably golfable quit a bit, i'm a begginner

Title: Place a stone on an empty Go board

Body:
See also: Make a move on a Go board.

Task

Go is a board game where two players (Black and White) place stones on the intersections of grid lines on a 19×19 board. Black moves first — for example, on D4:

In this challenge, you must take a Go board coordinate like D4 as input, and output an ASCII representation of a board with the first move played at the given point.

Note that there is no column I. This is, historically, to reduce confusion with J and L.

This output consists of 19 lines, each containing 19 characters. The point with the stone on it is marked O. Empty points on the board are shown as ., except for the nine star points (at D4, D10, D16, K4, K10, K16, Q4, Q10, and Q16), which are marked *.

For example, given F5 as an input, your answer’s output must be:

```<code>...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
.....O.............
...*.....*.....*...
...................
...................
...................
</code>```

And given Q16 as input, your output must be:

```<code>...................
...................
...................
...*.....*.....O...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
</code>```

Rules

You may write a function that takes the coordinate as an argument, or a program that reads the coordinate from the command line or from STDIN.

You may choose to accept input either in lower-case or upper-case, but your answer doesn’t need to handle both.

The input is always a single string like a1 or T19, never a string + number or two strings.

If you write a full program, your answer must be printed to STDOUT as a string, optionally followed by a trailing newline. If your answer is a function, you may print to STDOUT, or return a string, or return an array/list of strings (rows), or return a two-dimensional array or nested list of characters.

This is code-golf. The shortest answer in bytes wins.

Body:
Go, 319 286 bytes

import(."strconv"
."strings")
func g(c string)(s string){p:=SplitN(c,"",2)
n,_:=Atoi(p[1])
for i:=19;i>0;i--{
for j:= 'a';j<'t';j++{
if j=='i'{
}else if n==i&&ContainsRune(p[0],j){s+="o"
}else if((i==4||i==10||i==16)&&(j=='d'||j=='k'||j=='q')){s+="*"
}else{s+="."}}
s+="\n"}
return}

Probably golfable quit a bit, i'm a begginner


Title: Place a stone on an empty Go board

Body:
R, <s>169</s> 161 bytes

f=function(p){S=substr;N=rep(".",114);N[61+6*0:2]="*";M=matrix(N,19,19);M[(S(p,2,3):1)[1],which(LETTERS[-9]==S(p,1,1))]="O";for(i in 19:1)cat(M[i,],"\n",sep="")}

With indents and newlines:

f=function(p){
    S=substr
    N=rep(".",114) # 6 lines of dots
    N[61+6*0:2]="*" # Place the hoshis
    M=matrix(N,19,19) # Make the 19x19 board using vector recycling
    M[(S(p,2,3):1)[1],  #grab and force coerce the row number to integer
      which(LETTERS[-9]==S(p,1,1))]="O" #Place the first stone
    for(i in 19:1) cat(M[i,],"\n",sep="")
}

Usage:

> f("A19")
O..................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
> f("D4")
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...O.....*.....*...
...................
...................
...................
> f("K10")
...................
...................
...................
...*.....*.....*...
...................
...................
...................
...................
...................
...*.....O.....*...
...................
...................
...................
...................
...................
...*.....*.....*...
...................
...................
...................


答:
Retina, <s>42</s> <s>35</s> 33 bytes

7 bytes thanks to Martin Ender.

```
(?<=^|\b0 )0(?=$| 0)

 +

^ | $

```

The last line is necessary.

Verify all testcases at once. (Slightly modified to run all testcases at once.)

Looks like the perfect language to do this in... still got defeated by most of the answers.

Title: Keep nonzeros and their neighbours

Body:
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.

The challenge

Given an array of integer values, remove all zeros that are not flanked by some nonzero value.

Equivalently, an entry should be kept either if it's a nonzero or if it's a zero that is immediately close to a nonzero value.

The entries that are kept should maintain in the output the order they had in the input.

Example

Given

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0]
</code>```

the values that should be removed are marked with an x:

```<code>[2 0 4 -3 0 x 0 3 0 0 2 0 x]
</code>```

and so the output should be

```<code>[2 0 4 -3 0 0 3 0 0 2 0]
</code>```

Rules

The input array may be empty (and then the output should be empty too).

Input and output formats are flexible as usual: array, list, string, or anything that is reasonable.

Code golf, fewest best.

Test cases

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0] -> [2 0 4 -3 0 0 3 0 0 2 0]
[] -> []
[1] -> [1]
[4 3 8 5 -6] -> [4 3 8 5 -6]
[4 3 8 0 5 -6] -> [4 3 8 0 5 -6]
[0] -> []
[0 0] -> []
[0 0 0 0] -> []
[0 0 0 8 0 1 0 0] -> [0 8 0 1 0]
[-5 0 5] -> [-5 0 5]
[50 0] -> [50 0]
</code>```

Body:
Retina, <s>42</s> <s>35</s> 33 bytes

7 bytes thanks to Martin Ender.

(?<=^|\b0 )0(?=$| 0)

 +

^ | $

The last line is necessary.

Verify all testcases at once. (Slightly modified to run all testcases at once.)

Looks like the perfect language to do this in... still got defeated by most of the answers.


答:
Batch, <s>349</s> 344 bytes

```<code>@echo off
set/ad=%2,i=%1/d,r=%1%%d
if not %r%==0 set i=%i%.&if %r% leq 0 set/ar=-r&if %i%==0 set i=-0.
set d=%d:-=%
set/ae=d
:g
if %r%==0 echo %i%&exit/b
set/ag=-~!(e%%2)*(!(e%%5)*4+1)
if not %g%==1 set/ae/=g&call:d&goto g
set/as=r
set i=%i%(
:r
call:d
if %r%==%s% echo %i%)&exit/b
goto r
:d
set/ar*=10,n=r/d,r%%=d
set i=%i%%n%
</code>```

Edit: Saved 5 bytes by removing unnecessary characters. "Ungolfed":

```<code>@echo off
set /a d = %2
set /a i = %1 / d
set /a r = %1 % d
if not %r%==0 (
    set i=%i%.                  Decimal point is required
    if %r% leq 0 (
        set /a r = -r           Get absolute value of remainder
        if %i%==0 set i=-0.     Fix edge case (-1/3 = 0 remainder -1)
    )
)
set d = %d:-=%                  Get absolute value of divisor
set /a e = d
:g
if %r%==0 echo %i% & exit /b    Finished if there's no remainder
set /a g = gcd(e, 10)           Loop through nonrecurring decimals
if not %g%==1 (
    set /a e /= g
    call :d
    goto g
)
set /a s = r                    Save remainder to know when loop ends
set i=%i%(
:r
call :d
if %r%==%s% echo %i%)&exit/b
goto r
:d                              Add the next decimal place
set /a r *= 10
set /a n = r / d
set /a r %= d
set i=%i%%n%
</code>```

Title: Fraction to exact decimal

Body:
Write a program or function that given two integers a, b outputs a string containing a decimal number representing the fraction a/b exactly.

If a/b is integer, simply output the value, without a decimal dot or leading zeroes:

```<code>123562375921304812375087183597 / 2777 -> 44494913907563850333124661
81 / 3 -> 27
-6 / 2 -> -3
</code>```

If a/b is not integer but has a finite representation in base 10, output the value without leading or trailing zeroes (except a single zero before the dot):

```<code>1 / 2 -> 0.5
3289323463 / -250000000 -> -13.157293852
</code>```

Finally, if and only if (so no 0.999...) a/b is not integer and does not have a finite representation, output the finite part followed by the repeating part in parenthesis. The repeating part must be as small as possible, and start as early as possible.

```<code>-1 / 3 -> -0.(3)
235 / 14 -> 16.7(857142)
123 / 321 -> 0.(38317757009345794392523364485981308411214953271028037)
355 / 113 -> 3.(1415929203539823008849557522123893805309734513274336283185840707964601769911504424778761061946902654867256637168)
</code>```

Your program must work for all above examples in under 10 seconds on a modern desktop PC. Smallest program in bytes wins.

Body:
Batch, <s>349</s> 344 bytes

@echo off
set/ad=%2,i=%1/d,r=%1%%d
if not %r%==0 set i=%i%.&if %r% leq 0 set/ar=-r&if %i%==0 set i=-0.
set d=%d:-=%
set/ae=d
:g
if %r%==0 echo %i%&exit/b
set/ag=-~!(e%%2)*(!(e%%5)*4+1)
if not %g%==1 set/ae/=g&call:d&goto g
set/as=r
set i=%i%(
:r
call:d
if %r%==%s% echo %i%)&exit/b
goto r
:d
set/ar*=10,n=r/d,r%%=d
set i=%i%%n%

Edit: Saved 5 bytes by removing unnecessary characters. "Ungolfed":

@echo off
set /a d = %2
set /a i = %1 / d
set /a r = %1 % d
if not %r%==0 (
    set i=%i%.                  Decimal point is required
    if %r% leq 0 (
        set /a r = -r           Get absolute value of remainder
        if %i%==0 set i=-0.     Fix edge case (-1/3 = 0 remainder -1)
    )
)
set d = %d:-=%                  Get absolute value of divisor
set /a e = d
:g
if %r%==0 echo %i% & exit /b    Finished if there's no remainder
set /a g = gcd(e, 10)           Loop through nonrecurring decimals
if not %g%==1 (
    set /a e /= g
    call :d
    goto g
)
set /a s = r                    Save remainder to know when loop ends
set i=%i%(
:r
call :d
if %r%==%s% echo %i%)&exit/b
goto r
:d                              Add the next decimal place
set /a r *= 10
set /a n = r / d
set /a r %= d
set i=%i%%n%


答:
Coffeescript, 83 bytes, score = 79/83 = 0.952 [cracked!]

r=(n)->return if r<0 then 0 else Array(parseInt(n/9)+2).join ((n-1)%9+1).toString()
```
<p>Computes A010785.</p>
<p>(Not so) Surprisingly, @DomHastings managed to shave 33 bytes off of my solution.</p>
<p>Wow, I suck at code-golf, don't I? Well, here's my other code:</p>
<pre class="lang-coffee prettyprint-override"><code>r=(n)->return if r<0 then 0 else ((n-1)%9+1).toString().repeat(parseInt(n/9)+2)
</code>```

Here's a less messy version of the code:

r=(n)->
  if r<0
   return 0
  else
   ((n-1)%9+1).toString().repeat(parseInt(n/9)+2)
   # ((n-1)%9+1).toString() is the repeating digit (as a string).
   # parseInt(n/9)+2 is the times the digit is repeated.
```

Title: Can you outgolf me? (Cops section)

Body:
Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

Python 2, 16 bytes, score = 15 / 16 = 0.9375

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

More information can be found here.

Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

Rules

The task you need to do is an OEIS sequence of your choice.

Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).

Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).

In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.

Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)

Input and output are both in decimal (base 10)

Leaderboard

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea">

Uncracked submissions

 Language	 Score	 User

Sort by: score creation

Safe submissions

 Language	 Score	 User

```

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

Body:
Coffeescript, 83 bytes, score = 79/83 = 0.952 [cracked!]

r=(n)->return if r<0 then 0 else Array(parseInt(n/9)+2).join ((n-1)%9+1).toString()

Computes A010785.

(Not so) Surprisingly, @DomHastings managed to shave 33 bytes off of my solution.

Wow, I suck at code-golf, don't I? Well, here's my other code:

r=(n)->return if r<0 then 0 else ((n-1)%9+1).toString().repeat(parseInt(n/9)+2)

Here's a less messy version of the code:

r=(n)->
  if r<0
   return 0
  else
   ((n-1)%9+1).toString().repeat(parseInt(n/9)+2)
   # ((n-1)%9+1).toString() is the repeating digit (as a string).
   # parseInt(n/9)+2 is the times the digit is repeated.


答:
CoffeeScript, <s>83</s> 50 bytes, DerpfacePython

s=(n)->0|r<0||Array(0|(n/9)+2).join ((n-1)%9+1)+''
```

Tested via http://coffeescript.org/.

Title: Can you outgolf me? (Robbers section)

Body:
CoffeeScript, <s>83</s> 50 bytes, DerpfacePython

s=(n)->0|r<0||Array(0|(n/9)+2).join ((n-1)%9+1)+''

Tested via http://coffeescript.org/.


问:
Determine if a number is divisible by 13 (without using 13 itself)
Your challenge, should you choose to accept it, is to create a function or a program that outputs "yes" if a given number is divisible by 13 and outputs "no" if it isn't.

Rules:

 - You're not allowed to use the number 13 anywhere.

 - No cop-out synonyms for 13 either (like using 15 - 2).

 - Bonus points will be awarded for not using modulus, additional bonus for not using division.

Scoring:

 - Your score will be the number of bytes in your code (whitespace not included) multiplied by your bonus.

 - If you didn't use modulus, that bonus is 0.90; if you didn't use division, that bonus is 0.90.

 - If you didn't use either, that bonus is 0.80.

 - The lower your score, the better.

The input will always be an integer greater than 0 and less than 2^32.

Your output should be a simple "yes" or "no".

Clarifications:

 - Using some roundabout method of generating the number 13 for use is acceptable.  Simple arithmetic synonyms like (10 + 3) are not allowed.

 - The function or program must literally output "yes" or "no" for if the given number is divisible by 13.

 - As always, clever solutions are recommended, but not required.

答:
Cheddar, 20 bytes (noncompeting)

Score is 20 * 0.9 = 18

```<code>n->n*2%26?'no':'yes'
</code>```

A straightforward answer.

Body:
Cheddar, 20 bytes (noncompeting)

Score is 20 * 0.9 = 18

n->n*2%26?'no':'yes'

A straightforward answer.


问:
Output a playable crossword grid
Write a program to produce a file containing a crossword grid
that the user can print out and work the puzzle on.

Input

A filename representing a crossword grid file and
optionally a second filename representing a crossword numbering
file. The input should be accepted by a conventional means for
your programming environment: command line arguments, the standard
input, web forms, etc..

You may assume that the crossword has been validated, and if
using a numbering file that is corresponds to the grid provided.

Grid file format: The first line consists of two white-space
separated integer constants M and N. Following that line are M
lines each consisting of N characters (plus a new line) selected
from [#A-Z ]. These characters are interpreted such that '#'
indicates a blocked square, ' ' a open square in the puzzle
with no known contents and any letter an open square whose
containing that letter.

Numbering file format Lines starting with '#' are ignored and
may be used for comments. All other lines contain a tab separated
triplet i, m, n where i represents a number to be printed
on the grid, and m and n represent the row and column of the
square where it should be printed. The number of both rows and
columns starts at 1.

Output

The output will be a file that the user can print out and work a
crossword on. ASCII, postscript, pdf, png, and any other
reasonable format will be accepted, but all must abide by these
rules:

There must be a rule around the entire puzzle and between
every pair of squares.

Blocked squares must be filled in darkly.

In play square that represent the start of a numbered (across
or down) clue must be provided with a number in the upper,
left corner of the square, while leaving most of the square
blank for the play to write in. Note that typical grid published
in the papers will have many tens of clues and may have more than
100.

The output will be of the grid alone, without the list of clues.

Output should be sent to a conventional destination (a file whose name
is derived from the input filename, produced as a web page, etc..)

Test case

Given a input of

```<code>5   5
#  ##
#
  #
    #
##  #
</code>```

the starting corner of an acceptable ASCII output might look like this

```<code>+-----+-----+-----+---
|#####|1    |2    |###
|#####|     |     |###
|#####|     |     |###
+-----+-----+-----+---
|#####|3    |     |4
|#####|     |     |
|#####|     |     |
+-----+-----+-----+---
|6    |     |#####|
|     |     |#####|
</code>```

Those using graphical formats should take their inspiration from
the usual printed sources.

Numbering scheme

A correctly numbered grid has the following properties:

Numbering begins at 1.

No column or span of open squares is unnumbered.

Numbers will be encountered in counting order by scanning from
top row to the bottom taking each row from left to right.

Aside

This is the third of several crossword related challenges. I
plan to use a consistent set of file-formats throughout and to
build up a respectable suite of crossword related utilities in
the process.

Previous challenges in this series:

Crossword numbering

Crossword grid validation

答:
PostScript (435) (434)

```<code>[/r{currentfile 999 string readline pop}/p{pop}/x{exch}/T{translate}/S{scale}/G{gsave}/R{grestore}/_( )>>begin/Courier 1 selectfont
20 20 S
.05 setlinewidth{r token
p x p
dup 3 x 3 add
T
G G{R
0 -1 T
G
_ 0
r{0 0 1 1
4 index 35 eq{rectfill p}{rectstroke
put
.3 .1 moveto
_ show}ifelse
1 0 T _ 0}forall}repeat
R R
1 -1 S -.9 -.7 T{{r
dup 0 get 35 ne{( )search
p 3 2 roll
cvx exec
G
x
T
.4 -.4 S
0 0 moveto show
p
R}if}loop}stopped}exec
</code>```

Un-golfed with data:

```<code>%!
<<
  /r{currentfile 999 string readline pop}
  /p{pop}
  /x{exch}
  /T{translate}
  /S{scale}
  /G{gsave}
  /R{grestore}
  /_( )
>>begin
/Courier 1 selectfont
% In theory, 20 20 scale isn't needed,
% but it would make the whole thing very tiny when printed
% (on screen it doesn't matter too much, it can be zoomed)
20 20 S
.05 setlinewidth
{ % exec
% Read number of lines
r token                          % restString numberOfLines true
% Discard rest of line (Contains number of columns.
% It becomes clear implicitly from number of letters in a line of grid definition)
p x p                            % numberOfLines
% Move to where the top line starts
dup 3 x 3 add                    % numberOfLines x y
T                                % numberOfLines
G G
{ %repeat
  R
  % Move to next line
  0 -1 T
  G
  _ 0
  r                              % ( ) 0 line
  { %forall                      % ( ) 0 char
    0 0 1 1                      % ( ) 0 char 0 0 x y
    % Check whether char is a hash
    4 index 35 eq{ %ifelse
      4 copy rectfill
    }if
    rectstroke                   % ( ) 0 char
    put                          % -/-
    .3 .1 moveto
    _ show
    1 0 T
    _ 0                          % ( ) 0
  }forall                        %
}repeat
R R
% Now, render the numbers according to the numbering definitions
1 -1 S -.9 -.7 T
{{
  r
  %Check whether this is a comment
  dup 0 get 35 ne{               % line
    % Split at the first tab
    %TODO: Ust tab instead of space
    ( )search                    % (y x) tab number true
    p 3 2 roll                   % tab number (y x)
    cvx exec                     % tab number y x
    G
    x                            % tab number x y
    T                            % tab number
    .4 -.4 S
    0 0 moveto show              % tab
    % This pop can be eliminated in theory to save two characters,
    % but the operand stack will continue to grow
    p
    R
  }if
}loop}stopped
}exec
15 15
     #   #

       #     ##
##   #   #
    #     #
   #    #
       #
      #    #
    #     #
    K#   #   ##
##  I  #
    L
    N
    S#   #
#i m n   figure(number), row, col
1 1 1
2 1 2
3 1 3
4 1 4
5 1 5
6 1 7
7 1 8
8 1 9
9 1 11
10 1 12
11 1 13
12 1 14
13 1 15
14 2 1
15 2 6
16 2 10
17 3 1
18 4 1
19 4 9
20 5 3
21 5 7
22 5 8
23 5 11
24 5 14
25 5 15
26 6 1
27 6 2
28 6 6
29 6 10
30 6 12
31 7 1
32 7 5
33 7 10
34 7 11
35 8 1
36 8 4
37 8 9
38 9 1
39 9 8
40 9 13
41 10 1
42 10 6
43 10 7
44 10 12
45 11 1
46 11 5
47 11 7
48 11 11
49 12 3
50 12 6
51 12 9
52 12 10
53 12 14
54 12 15
55 13 1
56 13 2
57 13 8
58 14 1
59 15 1
60 15 7
60 15 11
</code>```

ContentLicense: CC BY-SA 2.5

Title: Output a playable crossword grid

Body:
PostScript (435) (434)

[/r{currentfile 999 string readline pop}/p{pop}/x{exch}/T{translate}/S{scale}/G{gsave}/R{grestore}/_( )>>begin/Courier 1 selectfont
20 20 S
.05 setlinewidth{r token
p x p
dup 3 x 3 add
T
G G{R
0 -1 T
G
_ 0
r{0 0 1 1
4 index 35 eq{rectfill p}{rectstroke
put
.3 .1 moveto
_ show}ifelse
1 0 T _ 0}forall}repeat
R R
1 -1 S -.9 -.7 T{{r
dup 0 get 35 ne{( )search
p 3 2 roll
cvx exec
G
x
T
.4 -.4 S
0 0 moveto show
p
R}if}loop}stopped}exec

Un-golfed with data:

%!
<<
  /r{currentfile 999 string readline pop}
  /p{pop}
  /x{exch}
  /T{translate}
  /S{scale}
  /G{gsave}
  /R{grestore}
  /_( )
>>begin
/Courier 1 selectfont
% In theory, 20 20 scale isn't needed,
% but it would make the whole thing very tiny when printed
% (on screen it doesn't matter too much, it can be zoomed)
20 20 S
.05 setlinewidth
{ % exec
% Read number of lines
r token                          % restString numberOfLines true
% Discard rest of line (Contains number of columns.
% It becomes clear implicitly from number of letters in a line of grid definition)
p x p                            % numberOfLines
% Move to where the top line starts
dup 3 x 3 add                    % numberOfLines x y
T                                % numberOfLines
G G
{ %repeat
  R
  % Move to next line
  0 -1 T
  G
  _ 0
  r                              % ( ) 0 line
  { %forall                      % ( ) 0 char
    0 0 1 1                      % ( ) 0 char 0 0 x y
    % Check whether char is a hash
    4 index 35 eq{ %ifelse
      4 copy rectfill
    }if
    rectstroke                   % ( ) 0 char
    put                          % -/-
    .3 .1 moveto
    _ show
    1 0 T
    _ 0                          % ( ) 0
  }forall                        %
}repeat
R R
% Now, render the numbers according to the numbering definitions
1 -1 S -.9 -.7 T
{{
  r
  %Check whether this is a comment
  dup 0 get 35 ne{               % line
    % Split at the first tab
    %TODO: Ust tab instead of space
    ( )search                    % (y x) tab number true
    p 3 2 roll                   % tab number (y x)
    cvx exec                     % tab number y x
    G
    x                            % tab number x y
    T                            % tab number
    .4 -.4 S
    0 0 moveto show              % tab
    % This pop can be eliminated in theory to save two characters,
    % but the operand stack will continue to grow
    p
    R
  }if
}loop}stopped
}exec
15 15
     #   #

       #     ##
##   #   #
    #     #
   #    #
       #
      #    #
    #     #
    K#   #   ##
##  I  #
    L
    N
    S#   #
#i m n   figure(number), row, col
1 1 1
2 1 2
3 1 3
4 1 4
5 1 5
6 1 7
7 1 8
8 1 9
9 1 11
10 1 12
11 1 13
12 1 14
13 1 15
14 2 1
15 2 6
16 2 10
17 3 1
18 4 1
19 4 9
20 5 3
21 5 7
22 5 8
23 5 11
24 5 14
25 5 15
26 6 1
27 6 2
28 6 6
29 6 10
30 6 12
31 7 1
32 7 5
33 7 10
34 7 11
35 8 1
36 8 4
37 8 9
38 9 1
39 9 8
40 9 13
41 10 1
42 10 6
43 10 7
44 10 12
45 11 1
46 11 5
47 11 7
48 11 11
49 12 3
50 12 6
51 12 9
52 12 10
53 12 14
54 12 15
55 13 1
56 13 2
57 13 8
58 14 1
59 15 1
60 15 7
60 15 11