问:
Primes in Different Bases
Challenge:

You are given a base 10 number.  For each base from 10 counting down to base 2:

Take the original input number as a base 10 string, and remove any
digits of the number which are invalid for the base.

Interpret the resulting number string in the that base. If this gives 1 or 0, terminate the whole process.

Output or print its largest prime factor, as decimal number.

The output can be an array of the largest prime factors.

Sample cases:

Input:

```<code>987654321
</code>```

Output:

```<code>379721
10593529
1091
179
1493
293
19
7
</code>```

Alternately:

```<code>[379721,10593529,1091,179,1493,293,19,7]
</code>```

This prints the largest prime factors of \$987654321\$, \$87654321_9 = 42374116_{10}\$, \$7654321_{8} = 2054353_{10}\$, and so on until it reaches \$1_2\$, where it stops.

答:
Pyth, 25 bytes

```<code>sfTm>1PiFdC,.u-N`tYKrT1zK
</code>```

```<code>                       z   get input as a string
            .u      rT1    cumulative reduce over [10,9,...,2]
              -N`tY        remove one minus the number (10,9,...) from the input
          C,       K    K  pair each step along the chain with corresponding base
   m                       map over [["987654321", 10],...]:
       iFd                   apply the base-conversion (splat over i)
      P                      prime factorization, smallest to largest
    >1                       take [the last element], or [] if empty (1 or 0)
 fT                        remove the []s from 0s or 1s
s                          join the one-element arrays together
</code>```

Try it here.

Title: Primes in Different Bases

Body:
Pyth, 25 bytes

sfTm>1PiFdC,.u-N`tYKrT1zK

                       z   get input as a string
            .u      rT1    cumulative reduce over [10,9,...,2]
              -N`tY        remove one minus the number (10,9,...) from the input
          C,       K    K  pair each step along the chain with corresponding base
   m                       map over [["987654321", 10],...]:
       iFd                   apply the base-conversion (splat over i)
      P                      prime factorization, smallest to largest
    >1                       take [the last element], or [] if empty (1 or 0)
 fT                        remove the []s from 0s or 1s
s                          join the one-element arrays together

Try it here.


答:
MATL, <s>17</s> 15 bytes

```<code>9:PQ"G@ZAYfXzX>
</code>```

This takes the number as a string with quotes, which is allowed by default.

Try it online!

Explanation

```<code>9:PQ     % Push array [10, 9, ..., 2]
"        % For each number in that array. These are the bases to be considered
  G      %   Push input. Forces for input to be taken implicitly first time
  @      %   Push current base
  ZA     %   Convert from that base to base 10, discarding non-valid digits
  Yf     %   Prime factors. Gives empty for input 1, and 0 for input 0
  Xz     %   Non-zero values. Gives empty if previous result was 0, or else
         %   leaves it as it was
  X>     %   Maximum of array. For empty input gives empty
         % Implicitly end for each
         % Implicitly display. Empty arrays are not displayed
</code>```

ContentLicense: CC BY-SA 4.0

Title: Primes in Different Bases

Body:
Challenge:

You are given a base 10 number.  For each base from 10 counting down to base 2:

Take the original input number as a base 10 string, and remove any
digits of the number which are invalid for the base.

Interpret the resulting number string in the that base. If this gives 1 or 0, terminate the whole process.

Output or print its largest prime factor, as decimal number.

The output can be an array of the largest prime factors.

Sample cases:

Input:

```<code>987654321
</code>```

Output:

```<code>379721
10593529
1091
179
1493
293
19
7
</code>```

Alternately:

```<code>[379721,10593529,1091,179,1493,293,19,7]
</code>```

This prints the largest prime factors of \$987654321\$, \$87654321_9 = 42374116_{10}\$, \$7654321_{8} = 2054353_{10}\$, and so on until it reaches \$1_2\$, where it stops.

Body:
MATL, <s>17</s> 15 bytes

9:PQ"G@ZAYfXzX>

This takes the number as a string with quotes, which is allowed by default.

Try it online!

Explanation

9:PQ     % Push array [10, 9, ..., 2]
"        % For each number in that array. These are the bases to be considered
  G      %   Push input. Forces for input to be taken implicitly first time
  @      %   Push current base
  ZA     %   Convert from that base to base 10, discarding non-valid digits
  Yf     %   Prime factors. Gives empty for input 1, and 0 for input 0
  Xz     %   Non-zero values. Gives empty if previous result was 0, or else
         %   leaves it as it was
  X>     %   Maximum of array. For empty input gives empty
         % Implicitly end for each
         % Implicitly display. Empty arrays are not displayed

ContentLicense: CC BY-SA 3.0


问:
Draw an indexed fractal

Introduction

In this challenge, a 2×2 matrix is indexed like this:

```<code>0 1
2 3
</code>```

We define a family of fractal-like patterns F(L), where L is a length-n list of these indices and F(L) has size 2n-1 × 2n-1.

If L == [], then F(L) is the 1×1 pattern #.

If L != [], then F(L) is constructed as follows. Let P be the pattern obtained from L with first element removed. Take four grids of size 2n-1-1 × 2n-1-1 filled with periods ., and replace the grid indexed by L[0] with the pattern P. Then, glue the grids together using one layer of hashes # between them. Here are diagrams for the four cases:

```<code>L[0]==0  L[0]==1  L[0]==2  L[0]==3
   #...  ...#     ...#...  ...#...
[P]#...  ...#[P]  ...#...  ...#...
   #...  ...#     ...#...  ...#...
#######  #######  #######  #######
...#...  ...#...     #...  ...#
...#...  ...#...  [P]#...  ...#[P]
...#...  ...#...     #...  ...#
</code>```

Example

Consider the input L = [2,0].
We begin with the 1×1 grid #, and traverse L from the right.
The rightmost element is 0, so we take four copies of the 1×1 grid ., replace the first one by #, and glue them together with hashes.
This results in the 3×3 grid

```<code>##.
###
.#.
</code>```

The next element is 2, so we take four copies of the 3×3 grid of .s, and replace the third one with the above grid.
The four grids are

```<code>...  ...  ##.  ...
...  ...  ###  ...
...  ...  .#.  ...
</code>```

and gluing them together with #s results in the 7×7 grid

```<code>...#...
...#...
...#...
#######
##.#...
####...
.#.#...
</code>```

This is our final output.

Input

Your input is a list L of the indices 0, 1, 2, 3.
You can take it as a list of integers, or a string of digits.
Note that it may be empty, and it may contain duplicates.
The length of L is at most 5.

Output

Your output is the pattern F(L) as a newline-delimited string.

Rules and scoring

You can write a full program or a function.
the lowest byte count wins, and standard loopholes are disallowed.

Test cases

```<code>[]
#

[0]
##.
###
.#.

[3]
.#.
###
.##

[2,0]
...#...
...#...
...#...
#######
##.#...
####...
.#.#...

[1,1]
...#.##
...####
...#.#.
#######
...#...
...#...
...#...

[1,2,0]
.......#...#...
.......#...#...
.......#...#...
.......########
.......###.#...
.......#####...
.......#.#.#...
###############
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......

[3,3,1]
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
###############
.......#...#...
.......#...#...
.......#...#...
.......########
.......#...#.##
.......#...####
.......#...#.#.

[0,1,2,3]
.......#...#...#...............
.......#...#...#...............
.......#...#...#...............
.......#########...............
.......#.#.#...#...............
.......#####...#...............
.......#.###...#...............
################...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
###############################
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............

[0,0,1,2,3]
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#########...............#...............................
.......#.#.#...#...............#...............................
.......#####...#...............#...............................
.......#.###...#...............#...............................
################...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
################################...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
###############################################################
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
</code>```

答:
Haskell, <s>123</s> 122 bytes

```<code>unlines.foldr(#)["#"]
n#p=zipWith(++)(r++h:t)$('#':)<$>u++h:s where b='.'<$p<$p;h='#'<$p;(r:s:t:u:_)=drop n$cycle[p,b,b,b]
</code>```

Usage example:

```<code>*Main> putStr $ (unlines.foldr(#)["#"]) [2,3,1]
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
###############
...#...#.......
...#...#.......
...#...#.......
########.......
...#.###.......
...#####.......
...#.#.#.......
</code>```

How it works:

```<code>                ["#"]      -- starting with "#"
        foldr(#)           -- fold the function # from the right into the input
unlines                    -- and join the result with newlines

n#p=                       -- helper function #
                           -- n: next index, p: fractal so far
    zipWith(++)            -- join the left and right part elementwise
       (r++h:t)            -- left part
       ('#':) <$> u++h:s   -- right part (prepend '#' to each line for vertical
                           -- separator

                           -- helper
b='.'<$p<$p                -- b is a blank square of the same size as p
h='#'<$p                   -- h is a line of '#' of the same length as p
(r:s:t:u:_)=               -- drop the first n elements of the infinite
    drop n$cycle[p,b,b,b]  --   list [p,b,b,b,p,b,b,b,p,b,b,b,...] and
                           --   assign the next 4 element to r,s,t,u.
                           --   As r,s,t,u are always inserted at the
                           --   same position in the fractal, we get the
                           --   variants by assigning different values.
</code>```

Title: Draw an indexed fractal

Body:
Haskell, <s>123</s> 122 bytes

unlines.foldr(#)["#"]
n#p=zipWith(++)(r++h:t)$('#':)<$>u++h:s where b='.'<$p<$p;h='#'<$p;(r:s:t:u:_)=drop n$cycle[p,b,b,b]

Usage example:

*Main> putStr $ (unlines.foldr(#)["#"]) [2,3,1]
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
###############
...#...#.......
...#...#.......
...#...#.......
########.......
...#.###.......
...#####.......
...#.#.#.......

How it works:

                ["#"]      -- starting with "#"
        foldr(#)           -- fold the function # from the right into the input
unlines                    -- and join the result with newlines

n#p=                       -- helper function #
                           -- n: next index, p: fractal so far
    zipWith(++)            -- join the left and right part elementwise
       (r++h:t)            -- left part
       ('#':) <$> u++h:s   -- right part (prepend '#' to each line for vertical
                           -- separator

                           -- helper
b='.'<$p<$p                -- b is a blank square of the same size as p
h='#'<$p                   -- h is a line of '#' of the same length as p
(r:s:t:u:_)=               -- drop the first n elements of the infinite
    drop n$cycle[p,b,b,b]  --   list [p,b,b,b,p,b,b,b,p,b,b,b,...] and
                           --   assign the next 4 element to r,s,t,u.
                           --   As r,s,t,u are always inserted at the
                           --   same position in the fractal, we get the
                           --   variants by assigning different values.


答:
Ruby, 150 bytes

Anonymous function. Uses a recursive call to build a list of strings, one string per line, then joins them all together at the end.

```<code>->i{f=->l{s=2**l.size-1;g=[[?.*s]*s]*4;m=->x,y{x.zip(y).map{|a,b|a+?#+b}}
s<1?[?#]:(g[l.shift]=f[l];m[*g[0,2]]+[?#*(2*s+1)]+m[*g[2,2]])}
f[i].join"
"}
</code>```

Title: Draw an indexed fractal

Body:
Introduction

In this challenge, a 2×2 matrix is indexed like this:

```<code>0 1
2 3
</code>```

We define a family of fractal-like patterns F(L), where L is a length-n list of these indices and F(L) has size 2n-1 × 2n-1.

If L == [], then F(L) is the 1×1 pattern #.

If L != [], then F(L) is constructed as follows. Let P be the pattern obtained from L with first element removed. Take four grids of size 2n-1-1 × 2n-1-1 filled with periods ., and replace the grid indexed by L[0] with the pattern P. Then, glue the grids together using one layer of hashes # between them. Here are diagrams for the four cases:

```<code>L[0]==0  L[0]==1  L[0]==2  L[0]==3
   #...  ...#     ...#...  ...#...
[P]#...  ...#[P]  ...#...  ...#...
   #...  ...#     ...#...  ...#...
#######  #######  #######  #######
...#...  ...#...     #...  ...#
...#...  ...#...  [P]#...  ...#[P]
...#...  ...#...     #...  ...#
</code>```

Example

Consider the input L = [2,0].
We begin with the 1×1 grid #, and traverse L from the right.
The rightmost element is 0, so we take four copies of the 1×1 grid ., replace the first one by #, and glue them together with hashes.
This results in the 3×3 grid

```<code>##.
###
.#.
</code>```

The next element is 2, so we take four copies of the 3×3 grid of .s, and replace the third one with the above grid.
The four grids are

```<code>...  ...  ##.  ...
...  ...  ###  ...
...  ...  .#.  ...
</code>```

and gluing them together with #s results in the 7×7 grid

```<code>...#...
...#...
...#...
#######
##.#...
####...
.#.#...
</code>```

This is our final output.

Input

Your input is a list L of the indices 0, 1, 2, 3.
You can take it as a list of integers, or a string of digits.
Note that it may be empty, and it may contain duplicates.
The length of L is at most 5.

Output

Your output is the pattern F(L) as a newline-delimited string.

Rules and scoring

You can write a full program or a function.
the lowest byte count wins, and standard loopholes are disallowed.

Test cases

```<code>[]
#

[0]
##.
###
.#.

[3]
.#.
###
.##

[2,0]
...#...
...#...
...#...
#######
##.#...
####...
.#.#...

[1,1]
...#.##
...####
...#.#.
#######
...#...
...#...
...#...

[1,2,0]
.......#...#...
.......#...#...
.......#...#...
.......########
.......###.#...
.......#####...
.......#.#.#...
###############
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......

[3,3,1]
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
###############
.......#...#...
.......#...#...
.......#...#...
.......########
.......#...#.##
.......#...####
.......#...#.#.

[0,1,2,3]
.......#...#...#...............
.......#...#...#...............
.......#...#...#...............
.......#########...............
.......#.#.#...#...............
.......#####...#...............
.......#.###...#...............
################...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
###############################
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............

[0,0,1,2,3]
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#########...............#...............................
.......#.#.#...#...............#...............................
.......#####...#...............#...............................
.......#.###...#...............#...............................
################...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
################################...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
###############################################################
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
</code>```

Body:
Ruby, 150 bytes

Anonymous function. Uses a recursive call to build a list of strings, one string per line, then joins them all together at the end.

->i{f=->l{s=2**l.size-1;g=[[?.*s]*s]*4;m=->x,y{x.zip(y).map{|a,b|a+?#+b}}
s<1?[?#]:(g[l.shift]=f[l];m[*g[0,2]]+[?#*(2*s+1)]+m[*g[2,2]])}
f[i].join"
"}


答:
Pyth - 16 bytes

```<code>V_S9#ePi~-z`NhNB
</code>```

Try it online here.

<s>There are sometimes a few blank lines on inputs without all the digits, lemme know if that's a problem.</s>

Title: Primes in Different Bases

Body:
Pyth - 16 bytes

V_S9#ePi~-z`NhNB

Try it online here.

<s>There are sometimes a few blank lines on inputs without all the digits, lemme know if that's a problem.</s>


问:
Find the program that prints this integer sequence (Robbers' thread)
This is the robbers' thread. The cops' thread goes here.

In the cops thread, the task was to write a program/function that takes a positive (or non-negative) integer and outputs/returns another number (not necessarily integer). The robbers task is to unscramble the code the cops used to produce this output.

The cracked code doesn't have to be identical, as long as it has the same length and any revealed characters are in the correct positions. The language must also be the same (version numbers can be different). The output must of course be identical.

No-ops can be used in robber's solution.

The winner of the robbers thread will be the user who has cracked the
most submissions by May 7th 2016. If there's a tie, the user who has cracked submissions with the longest combined code will win.

The submission should be formatted like this:

Language, nn characters (including link to answer), Cop's username

Code:

```<code>function a(n)
    if n<2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Output

```<code>a(0) returns 0
a(3) returns 2
</code>```

Optional explanation and comments.

答:
C (71 bytes) by mIllIbyte

The sequence is floor(n/4).

x;f(_){x/=4;
    }
main(){
 scanf("%d",&x);
 f( 6);
 printf("%d", x);
}
```


答:
Julia, 101 bytes

f(s,x=[],b=10)=(t=filter(c->c<=47+b,s))>"1"&&b>1?f(s,[x;maximum(keys(factor(parse(Int,t,b))))],b-1):x
```

<p>This is a recursive function that accepts the input as a string and returns an array.</p>

<p>Ungolfed:</p>

<pre class="lang-default prettyprint-override"><code>function f(s, x=[], b=10)
    # Filter the string down to only the digits valid for base b
    t = filter(c -> c <= 47 + b, s)

    # If the filtered string isn't "1" or "0" and b is a valid base
    if t > "1" && b > 1
        # Call the function again, appending the maximum prime factor
        # of t in base b to the argument x and decrementing the base
        f(s, [x; maximum(keys(factor(parse(Int, t, b))))], b-1)
    else
        # Otherwise return the array
        x
    end
end
</code>```

Title: Primes in Different Bases

Body:
Julia, 101 bytes

f(s,x=[],b=10)=(t=filter(c->c<=47+b,s))>"1"&&b>1?f(s,[x;maximum(keys(factor(parse(Int,t,b))))],b-1):x

This is a recursive function that accepts the input as a string and returns an array.

Ungolfed:

function f(s, x=[], b=10)
    # Filter the string down to only the digits valid for base b
    t = filter(c -> c <= 47 + b, s)

    # If the filtered string isn't "1" or "0" and b is a valid base
    if t > "1" && b > 1
        # Call the function again, appending the maximum prime factor
        # of t in base b to the argument x and decrementing the base
        f(s, [x; maximum(keys(factor(parse(Int, t, b))))], b-1)
    else
        # Otherwise return the array
        x
    end
end


Title: Find the program that prints this integer sequence (Robbers' thread)

Body:
This is the robbers' thread. The cops' thread goes here.

In the cops thread, the task was to write a program/function that takes a positive (or non-negative) integer and outputs/returns another number (not necessarily integer). The robbers task is to unscramble the code the cops used to produce this output.

The cracked code doesn't have to be identical, as long as it has the same length and any revealed characters are in the correct positions. The language must also be the same (version numbers can be different). The output must of course be identical.

No-ops can be used in robber's solution.

The winner of the robbers thread will be the user who has cracked the
most submissions by May 7th 2016. If there's a tie, the user who has cracked submissions with the longest combined code will win.

The submission should be formatted like this:

Language, nn characters (including link to answer), Cop's username

Code:

```<code>function a(n)
    if n<2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Output

```<code>a(0) returns 0
a(3) returns 2
</code>```

Optional explanation and comments.

Body:
PHP, 137 bytes, insertusernamehere, A000959

Code:

for($s=range(1,303);$i<($t=count($s));$s=array_merge($s))for($j=($k=++$i==1?2:$s[$i-1])-1;$j<$t;$j+=$k )unset($s[$j]);echo$s[$argv[1]-1];

Output:

a(3)  =   7
a(7)  =  21
a(23) =  99


问:
What's being surrounded
I've always wanted to surround some text with #s, but I have trouble figuring out what I surrounded so in this challenge you'll be writing a program to do just that

Examples

Input / Outputs are separated by a newline.

```<code>###
#a#
###

a
</code>```

```<code> #
#a#
 #

a
</code>```

```<code>  ###
 # a #
# b c #
#######

  a
 b c
</code>```

```<code>ABCDHIJ
E####GK
F# M #L
#   N#O
P####

  M
   N
</code>```

```<code>###A###
#C#B#o#
#d###e#
 # go#
  ###

C   o
d   e
  go
</code>```

Spec

#s are what "surround" a block of text

# will always be adjacent to one another (including diagonally)

# will always form a closed shape

There will only be one # shape

In the event of a concave shape, holes should be filled with spaces.

Whitespace must be preserved in the output

答:
Javascript, 485 464 427 417 396 390 bytes

s='indexOf';k='lastIndexOf';h="#";t=b=>b[0].map((x,i)=>b.map(x=>x[i]));i=>{m=i.split`
`;for(h of m){m[m[s](h)]=h.split``;}for(y=0;y<m.length;y++){for(z=x=0;x<m[y].length;x++){if(m[y][x]==h)break;if(m[y][s](h)<x&&m[y][k](h)>x)z++;q=t(m);if(q[y][s]h)<x&&m[y][k](h)>x)z++;if(z>2)m[y][x]=h}}for(p of m){v=p.join``.match(/\S/);e=v?p.join``:'';m[m[s](p)]=e;}m=m.join`
`;return m.replace(#/g," ")}```

Yes. I tried. And, although I am at 485 bytes, I am winning because no-one else felt like answering this question. So, hah!

And also, I am well aware that I could golf this loads, I just am tired at the moment...  well now I'm at 396 Thanks to Conor for most of the golfing... :D

Title: What's being surrounded

Body:
Javascript, 485 464 427 417 396 390 bytes

s='indexOf';k='lastIndexOf';h="#";t=b=>b[0].map((x,i)=>b.map(x=>x[i]));i=>{m=i.split`
`;for(h of m){m[m[s](h)]=h.split``;}for(y=0;y<m.length;y++){for(z=x=0;x<m[y].length;x++){if(m[y][x]==h)break;if(m[y][s](h)<x&&m[y][k](h)>x)z++;q=t(m);if(q[y][s]h)<x&&m[y][k](h)>x)z++;if(z>2)m[y][x]=h}}for(p of m){v=p.join``.match(/\S/);e=v?p.join``:'';m[m[s](p)]=e;}m=m.join`
`;return m.replace(#/g," ")}

Yes. I tried. And, although I am at 485 bytes, I am winning because no-one else felt like answering this question. So, hah!

And also, I am well aware that I could golf this loads, I just am tired at the moment...  well now I'm at 396 Thanks to Conor for most of the golfing... :D


问:
How many IP addresses are in a given range?
Inspired by...

Networking - How can I work out how many IP addresses there are in a given range?

Write a program or function that takes two strings as input, each being an IPv4 address expressed in standard dotted notation and outputs or returns the number of IP addresses covered by this range, including the two IP addresses input.

You must not use any external code, libraries or services designed to parse an IP address. (Other string processing standard library functions are acceptable.)

All 2^32 IP addresses are equal. No distinction is made to broadcast, class E, etc.

Normal code-golf rules apply.

For example:

```<code>"0.0.0.0","255.255.255.255" returns 4294967296.
"255.255.255.255","0.0.0.0" also returns 4294967296.
"1.2.3.4","1.2.3.4" returns 1.
"56.57.58.59","60.61.62.63" returns 67372037.
"1","2" is invalid input. Your code may do anything you like.
</code>```

答:
Factor, 73 bytes

Translation of the CoffeeScript answer.

```<code>[ "." split [ 10 base> ] [ [ 256 * ] dip + ] map-reduce ] bi@ - abs 1 + ]
</code>```

Body:
Factor, 73 bytes

Translation of the CoffeeScript answer.

[ "." split [ 10 base> ] [ [ 256 * ] dip + ] map-reduce ] bi@ - abs 1 + ]


问:
Find the program that prints this integer sequence (Cops' thread)
This is the cops' thread. The robbers' thread goes here.

The last cops-and-robbers thread was already 4 months ago.

The cop's task

The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.

The cop must state it if the program is intolerant towards zero.

The cop will provide at least 2 sample inputs/outputs.

For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:

```
a(0) returns 0
a(3) returns 2
```

The number of examples is up to the cop's discretion.

However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(

The cop can hide as many characters as is so wished.

For example, if my program is:

```<code>function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Then I would hide these characters as I want:

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

The robber's task

is obviously to find the original source code.

However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

<s>The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.</s>

Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):

Lua, 98 bytes

Output:

```<code>a(0) returns 0
a(3) returns 2
</code>```

Code (# marks unrevealed characters):

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

If the code is cracked, insert [Cracked](link to cracker) in the header.
If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

答:
Python 3, 50 bytes (Cracked)

Another one, because I like this sequence

>>> a(1)
0
>>> a(10)
2303
```

<p>The first number from the sequence is <code>a(0)</code>. <code>#</code> used to obfuscate characters.</p>

```from #### import ####
a=lambda n:####(###########)
```

Body:
Python 3, 50 bytes (Cracked)

Another one, because I like this sequence

>>> a(1)
0
>>> a(10)
2303

The first number from the sequence is a(0). # used to obfuscate characters.

from #### import ####
a=lambda n:####(###########)


答:
Python 3, 50 bytes, CAD97, A004242

from math import    *
a=lambda n:ceil(1000*log(n))
```
<p>Try it online</p>
<p>Output:</p>
```a(1) => 0
a(10) => 2303
```

Body:
Python 3, 50 bytes, CAD97, A004242

from math import    *
a=lambda n:ceil(1000*log(n))

Try it online

Output:

a(1) => 0
a(10) => 2303


答:
Mathematica, 83 bytes

```<code>FactorInteger[Select[IntegerDigits@#,#<a&]~FromDigits~a][[-1,1]]~Table~{a,10,2,-1}&
</code>```

Anonymous function, returns a list. Not that complicated, to be honest.

Title: Primes in Different Bases

Body:
Mathematica, 83 bytes

FactorInteger[Select[IntegerDigits@#,#<a&]~FromDigits~a][[-1,1]]~Table~{a,10,2,-1}&

Anonymous function, returns a list. Not that complicated, to be honest.


答:
Ruby, 120 bytes

Recursive function, takes the input as a string.

```<code>f=->n,b=2{require'prime';i=n.tr([*b.to_s..?9].join,"").to_i(b)
b>10?[]:f[n,b+1]+[*i>1?Prime.prime_division(i).max[0]:p]}
</code>```

Title: Primes in Different Bases

Body:
Ruby, 120 bytes

Recursive function, takes the input as a string.

f=->n,b=2{require'prime';i=n.tr([*b.to_s..?9].join,"").to_i(b)
b>10?[]:f[n,b+1]+[*i>1?Prime.prime_division(i).max[0]:p]}


问:
Is it really a comcoin?

Very interesting background

Comcoins are a currency like any other. The residents of Multibaseania (an economically robust system of city-states with very few residents in a galaxy far, far away) use Comcoins to conduct transactions between themselves. Comcoins are represented by unique codes on special not-paper slips, and when you pay you give the vendor your slip.

However, just like any currency, there are those villainous types that try to take advantage of the system and inflate the currency because they are bored.

To combat this unquestionably illegal behavior, the Multibaseanian governments came together and devised a way to prove that the money is legitimate. The top idea from the think tank was: whenever a Comcoin is given to a vendor, the vendor runs a program that checks if it is legitimate. How does one know if a Comcoin is legitimate?

A legitimate Comcoin is one where:

When the Comcoin's unique code is converted into the bases 2-10, inclusive, that number is composite (i.e. not prime). Also, all of the unique code's digits in base 10 are either 1 or 0, and its length in base 10 is between 1 and 5 inclusive.

Very important example: in base 5, 111 is 421. Even though 111 is not prime, 421 is, so the Comcoin is invalid.

The challenge

Write a function or program that takes a Comcoin's code (a number), which is in base 10 and is an integer. Then, print or return a truthy or falsy value depending on whether that Comcoin is legitimate (criteria above), respectively.

I/O examples

```<code>Input     Output

101         False // because it is prime in base 2
1010        True
10101       True
1010111     False // because it is longer than 5 digits
123         False // because it does not contain *only* 0's and 1's
10111       False // because it is prime in base 6
</code>```

This is code golf, so shortest code in bytes wins!

Edit

A Comcoin is not a number that is not prime, but is a number that is composite.

Inspiration from qualification round of Google CodeJam 2016.

答:
Julia, <s>83</s> 81 bytes

f(x,s="$x")=endof(s)<6&&all(c->c∈"01",s)&&!any(b->isprime(parse(Int,s,b)),2:10)
```

This is a function that accepts an integer and returns a boolean. It's a straightforward check on the conditions of being a Comcoin:

Length as a string between 1 and 5 inclusive: endof(s)<6

All zeros and ones: all(c->c∈"01",s)

No primes in any base from 2 to 10: !any(b->isprime(parse(Int,s,b)),2:10)

Saved 2 bytes thanks to Luis Mendo!

Title: Is it really a comcoin?

Body:
Julia, <s>83</s> 81 bytes

f(x,s="$x")=endof(s)<6&&all(c->c∈"01",s)&&!any(b->isprime(parse(Int,s,b)),2:10)

This is a function that accepts an integer and returns a boolean. It's a straightforward check on the conditions of being a Comcoin:

Length as a string between 1 and 5 inclusive: endof(s)<6

All zeros and ones: all(c->c∈"01",s)

No primes in any base from 2 to 10: !any(b->isprime(parse(Int,s,b)),2:10)

Saved 2 bytes thanks to Luis Mendo!


答:
Ruby, <s>81</s> <s>80</s> 74 bytes

Anonymous function, takes input as a string and returns true or a falsy value (false if it fails a prime check, nil if it contains characters that aren't 0 or 1)

Uses some regex magic suggested by @QPaysTaxes, which thankfully works (within reasonable time) because of the promise that the coin signature has max 5 characters. Also, I forgot to actually check for the length, so only 1 byte was saved overall.

Since 0 and 1 aren't composite numbers in any base, I could save more bytes by modifying my regex.

```<code>->n{n=~/^[01]{2,5}$/&&(2..10).map{|b|?1*n.to_i(b)=~/^(..+?)\1+$/}&[p]==[]}
</code>```

Old version using Ruby's built-in prime checker. 85 bytes after properly checking for length.

```<code>->n{require'prime';n=~/^[01]{1,5}$/&&(2..10).map{|b|Prime.prime? n.to_i(b)}&[!p]==[]}
</code>```

Title: Is it really a comcoin?

Body:
Very interesting background

Comcoins are a currency like any other. The residents of Multibaseania (an economically robust system of city-states with very few residents in a galaxy far, far away) use Comcoins to conduct transactions between themselves. Comcoins are represented by unique codes on special not-paper slips, and when you pay you give the vendor your slip.

However, just like any currency, there are those villainous types that try to take advantage of the system and inflate the currency because they are bored.

To combat this unquestionably illegal behavior, the Multibaseanian governments came together and devised a way to prove that the money is legitimate. The top idea from the think tank was: whenever a Comcoin is given to a vendor, the vendor runs a program that checks if it is legitimate. How does one know if a Comcoin is legitimate?

A legitimate Comcoin is one where:

When the Comcoin's unique code is converted into the bases 2-10, inclusive, that number is composite (i.e. not prime). Also, all of the unique code's digits in base 10 are either 1 or 0, and its length in base 10 is between 1 and 5 inclusive.

Very important example: in base 5, 111 is 421. Even though 111 is not prime, 421 is, so the Comcoin is invalid.

The challenge

Write a function or program that takes a Comcoin's code (a number), which is in base 10 and is an integer. Then, print or return a truthy or falsy value depending on whether that Comcoin is legitimate (criteria above), respectively.

I/O examples

```<code>Input     Output

101         False // because it is prime in base 2
1010        True
10101       True
1010111     False // because it is longer than 5 digits
123         False // because it does not contain *only* 0's and 1's
10111       False // because it is prime in base 6
</code>```

This is code golf, so shortest code in bytes wins!

Edit

A Comcoin is not a number that is not prime, but is a number that is composite.

Inspiration from qualification round of Google CodeJam 2016.

Body:
Ruby, <s>81</s> <s>80</s> 74 bytes

Anonymous function, takes input as a string and returns true or a falsy value (false if it fails a prime check, nil if it contains characters that aren't 0 or 1)

Uses some regex magic suggested by @QPaysTaxes, which thankfully works (within reasonable time) because of the promise that the coin signature has max 5 characters. Also, I forgot to actually check for the length, so only 1 byte was saved overall.

Since 0 and 1 aren't composite numbers in any base, I could save more bytes by modifying my regex.

->n{n=~/^[01]{2,5}$/&&(2..10).map{|b|?1*n.to_i(b)=~/^(..+?)\1+$/}&[p]==[]}

Old version using Ruby's built-in prime checker. 85 bytes after properly checking for length.

->n{require'prime';n=~/^[01]{1,5}$/&&(2..10).map{|b|Prime.prime? n.to_i(b)}&[!p]==[]}


答:
Factor, 128 bytes

```<code>[ dup [| a | 2 10 [a,b] [ a swap base> prime? not ] all? ] swap [ [ [ 49 = ] [ 48 = ] bi or ] all? ] [ length 6 < ] bi and and ]
</code>```

I'll try to golf this more in a sec.

Well, here's the less golfed version I thought might be shorter, but it's 133 bytes...

```<code>[ [ [let :> a 2 10 [a,b] [ a swap base> prime? not ] all? ] ] [ [ [ [ 49 = ] [ 48 = ] bi or ] all? ] [ length 6 < ] bi ] bi and and ]
</code>```

Actually ungolfed:

```<code>: comcoin? ( a -- t/f )
  [
    [let :> a
      2 10 [a,b] [ a swap base> prime? not ] all?
    ]
  ] [
    [ [ [ 49 = ] [ 48 = ] bi or ] all? ]
    [ length 6 < ] bi
  ] bi
  and and ;
</code>```

Title: Is it really a comcoin?

Body:
Factor, 128 bytes

[ dup [| a | 2 10 [a,b] [ a swap base> prime? not ] all? ] swap [ [ [ 49 = ] [ 48 = ] bi or ] all? ] [ length 6 < ] bi and and ]

I'll try to golf this more in a sec.

Well, here's the less golfed version I thought might be shorter, but it's 133 bytes...

[ [ [let :> a 2 10 [a,b] [ a swap base> prime? not ] all? ] ] [ [ [ [ 49 = ] [ 48 = ] bi or ] all? ] [ length 6 < ] bi ] bi and and ]

Actually ungolfed:

: comcoin? ( a -- t/f )
  [
    [let :> a
      2 10 [a,b] [ a swap base> prime? not ] all?
    ]
  ] [
    [ [ [ 49 = ] [ 48 = ] bi or ] all? ]
    [ length 6 < ] bi
  ] bi
  and and ;


答:
MATL, 10 bytes, safe!

```<code>2*##n##qn-
</code>```

Starts at 1, # are hidden characters. Sample input/output:

```<code>a(3)=1
a(8)=2
</code>```

Revealed

The sequence is the number of primes between n and 2*n. The code used was 2*ZqnGZqn-. This takes implicit input, doubles it, and finds the number of primes less than that number, pushes the input again and finds the number of primes less than that, and then subtracts the two lengths from each other.

Title: Find the program that prints this integer sequence (Cops' thread)

Body:
This is the cops' thread. The robbers' thread goes here.

The last cops-and-robbers thread was already 4 months ago.

The cop's task

The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.

The cop must state it if the program is intolerant towards zero.

The cop will provide at least 2 sample inputs/outputs.

For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:

```
a(0) returns 0
a(3) returns 2
```

The number of examples is up to the cop's discretion.

However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(

The cop can hide as many characters as is so wished.

For example, if my program is:

```<code>function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Then I would hide these characters as I want:

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

The robber's task

is obviously to find the original source code.

However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

<s>The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.</s>

Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):

Lua, 98 bytes

Output:

```<code>a(0) returns 0
a(3) returns 2
</code>```

Code (# marks unrevealed characters):

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

If the code is cracked, insert [Cracked](link to cracker) in the header.
If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

Body:
MATL, 10 bytes, safe!

2*##n##qn-

Starts at 1, # are hidden characters. Sample input/output:

a(3)=1
a(8)=2

Revealed

The sequence is the number of primes between n and 2*n. The code used was 2*ZqnGZqn-. This takes implicit input, doubles it, and finds the number of primes less than that number, pushes the input again and finds the number of primes less than that, and then subtracts the two lengths from each other.


答:
Python 3, 58 bytes (Cracked)

One last series

>>> a(0)
0
>>> a(4)
8
>>> a(5)
17
```

<p>Sequence starts with <code>a(0)</code>.</p>

```a=lambda n:###(###(###)## if ###### else #####(#######)##)
```

<p>Original was different than the cracked, because I can't golf Python :P</p>

<pre class="lang-python prettyprint-override"><code>a=lambda n:int(3**(n/2)-1 if n%2==0 else 2*3**(n/2-1/2)-1)
</code>```

Body:
Python 3, 58 bytes (Cracked)

One last series

>>> a(0)
0
>>> a(4)
8
>>> a(5)
17

Sequence starts with a(0).

a=lambda n:###(###(###)## if ###### else #####(#######)##)

Original was different than the cracked, because I can't golf Python :P

a=lambda n:int(3**(n/2)-1 if n%2==0 else 2*3**(n/2-1/2)-1)


答:
Python, <s>161</s> 152 bytes

Sigh. Assign the lambda to use it.

```<code>def p(n):
 i=a=n
 while i>2:i-=1;a*=n%i
 return a>1
lambda s:all([all(map(lambda i:not p(int(s,i)),range(2,11))),filter(lambda i:i in"01",s)),len(s)<6])
</code>```

Title: Is it really a comcoin?

Body:
Python, <s>161</s> 152 bytes

Sigh. Assign the lambda to use it.

def p(n):
 i=a=n
 while i>2:i-=1;a*=n%i
 return a>1
lambda s:all([all(map(lambda i:not p(int(s,i)),range(2,11))),filter(lambda i:i in"01",s)),len(s)<6])


答:
Python 3 (58 bytes) by CAD97

The sequence is A062318. There were a lot of unnecessary characters in this one, so I commented some out.

```<code>a=lambda n: ~-( -~(n%2)
# if ###### else
*3**(n//2))#)##)
</code>```

Body:
Python 3 (58 bytes) by CAD97

The sequence is A062318. There were a lot of unnecessary characters in this one, so I commented some out.

a=lambda n: ~-( -~(n%2)
# if ###### else
*3**(n//2))#)##)


答:
Seriously, 14 bytes (Safe)

```<code>,???D*≈@??D*≈-
</code>```

The ?s denote the hidden code. This sequence starts at a(0).

Output:

```<code>a(0) = 1
a(1) = 0
a(3) = 1
</code>```

Solution:

The sequence is:

 A005614 (the infinite Fibonacci word)

My solution:

 ,;uφD*≈@⌐φD*≈-

The solution is a straightforward implementation of the formula found on the OEIS page (with an error corrected so that the sequence starts at n=0 like the page shows, rather than n=1).

Body:
Seriously, 14 bytes (Safe)

,???D*≈@??D*≈-

The ?s denote the hidden code. This sequence starts at a(0).

Output:

a(0) = 1
a(1) = 0
a(3) = 1

Solution:

The sequence is:

 A005614 (the infinite Fibonacci word)

My solution:

 ,;uφD*≈@⌐φD*≈-

The solution is a straightforward implementation of the formula found on the OEIS page (with an error corrected so that the sequence starts at n=0 like the page shows, rather than n=1).


问:
1/N probability
Because there are not enough simple code-golf challenges:

Create an optionally unnamed program or function that, given (by any means) an integer 1 ≤ N ≤ 10000, outputs your language's True value with a pseudo-random probability of 1/N, False otherwise.

Please note that the requirement for naming has been removed. Feel free to edit answers and scores accordingly.

Some languages use 1 (or -1) and 0 for True and False, that is fine too.

Example:

Example input tests:

```<code>4 -> True
4 -> False
4 -> False
4 -> False
4 -> False
4 -> True
4 -> False
4 -> False
</code>```

I.e. given 4; it returns True with a 25% chance and False with a 75% chance.

答:
Racket, 21 bytes

```<code>(λ(x)(=(random x)0))
</code>```

Title: 1/N probability

Body:
Racket, 21 bytes

(λ(x)(=(random x)0))


问:
The plus-minus sequence

The plus-minus sequence

The plus-minus sequence is one that starts with two seeds, a(0) and b(0). Each iteration of this sequence is the addition and subtraction of the previous two members of the sequence. That is, a(N) = a(N-1) + b(N-1) and b(N) = a(N-1) - b(N-1).

Objective Produce the plus-minus sequence, in infinitude or the first K steps given K. You may do this using an infinite output program, a generator, or a function/program that gives the first K steps. The output order does not matter, so long as it is consistent. (I.e., b(K) a(K) or a(K) b(K), with some non-numeric, non-newline separator in between.) The output must start with the input.

Test cases

For inputs 10 2 (of a(0) b(0), this is a possible output for the first K approach (or a subsection of the infinite approach):

```<code>10     2
12     8
20     4
24     16
40     8
48     32
80     16
96     64
160    32
192    128
320    64
384    256
640    128
768    512
1280   256
1536   1024
2560   512
3072   2048
5120   1024
6144   4096
10240  2048
12288  8192
20480  4096
24576  16384
40960  8192
49152  32768
81920  16384
98304  65536
</code>```

For inputs 2 20 10 (a(0) b(0) k):

```<code>2     20
22   -18
4     40
44   -36
8     80
88   -72
16    160
176  -144
32    320
352  -288
</code>```

This is a code-golf, so the shortest program in bytes wins.

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Seriously, 12 bytes

```<code>,,1WX■@│+)-1
</code>```

Outputs an infinite stream, format is b(n) a(n), one pair of outputs per line.

No online link because TryItOnline doesn't do so well with infinite loops.

Explanation:

```<code>,,1WX■@│+)-1
,,1           push a(0), push b(0), push 1
   W          while loop:
    X           discard the 1 (only used to make sure the while loop always runs)
     ■          print all stack elements, separated by spaces, without popping
      @│        swap, duplicate entire stack
        +)      push a(n) + b(n) (a(n+1)) and move it to the bottom of the stack
          -     push a(n) - b(n) (b(n+1))
           1    push 1 to make sure the loop continues

</code>```

Title: The plus-minus sequence

Body:
Seriously, 12 bytes

,,1WX■@│+)-1

Outputs an infinite stream, format is b(n) a(n), one pair of outputs per line.

No online link because TryItOnline doesn't do so well with infinite loops.

Explanation:

,,1WX■@│+)-1
,,1           push a(0), push b(0), push 1
   W          while loop:
    X           discard the 1 (only used to make sure the while loop always runs)
     ■          print all stack elements, separated by spaces, without popping
      @│        swap, duplicate entire stack
        +)      push a(n) + b(n) (a(n+1)) and move it to the bottom of the stack
          -     push a(n) - b(n) (b(n+1))
           1    push 1 to make sure the loop continues


答:
Python 2, 72 bytes, cracked

print####((#y##########.####c###6#####16#.######)#131963###input()#3###)
```

<p>Outputs:</p>

```a(1) = 1
a(2) = 2
a(3) = 3
a(4) = 6
a(5) = 9
a(6) = 18
```

a(1) is the first element of the sequence. Tested on my personal computer, on repl.it and on ideone (which have versions 2.7.11, 2.7.2 and 2.7.10 respectively).

The sequence is finite, and all terms are listed - it's just the divisors of 18. However, I overlooked the idea that #s could be substituted for newlines...

The original one-liner was:

 print len((BytesWarning.__doc__*6)[8::16].split()[1319648>>input()*3&7])

Body:
Python 2, 72 bytes, cracked

print####((#y##########.####c###6#####16#.######)#131963###input()#3###)

Outputs:

a(1) = 1
a(2) = 2
a(3) = 3
a(4) = 6
a(5) = 9
a(6) = 18

a(1) is the first element of the sequence. Tested on my personal computer, on repl.it and on ideone (which have versions 2.7.11, 2.7.2 and 2.7.10 respectively).

The sequence is finite, and all terms are listed - it's just the divisors of 18. However, I overlooked the idea that #s could be substituted for newlines...

The original one-liner was:

 print len((BytesWarning.__doc__*6)[8::16].split()[1319648>>input()*3&7])


答:
Python 2, 62 56 49 bytes

```<code>lambda n:max(`n`)<"2"and 0x5d75d750>>int(`n`,2)&1
</code>```

Credit to @Sp3000 for the max trick to ensure binary digits.

Title: Is it really a comcoin?

Body:
Python 2, 62 56 49 bytes

lambda n:max(`n`)<"2"and 0x5d75d750>>int(`n`,2)&1

Credit to @Sp3000 for the max trick to ensure binary digits.


问:
A curious prime fraction formula
Given a positive integer \$n\$ output the integers \$a\$ and \$b\$ (forming reduced fraction \$a/b\$) such that:

$$\frac a b = \prod ^n _{k=1} \frac {p^2_k - 1} {p^2_k + 1}$$

Where \$p_k\$ is the \$k\$ th prime number (with \$p_1 = 2\$).

Examples:

```<code>1   -> 3, 5
2   -> 12, 25
3   -> 144, 325
4   -> 3456, 8125
5   -> 41472, 99125
15  -> 4506715396450638759507001344, 11179755611058498955501765625
420 -> very long</code>```

Probabilistic prime checks are allowed, and it's ok if your answer fails due to limitations in your language's integer type.

Shortest code in bytes wins.

答:
Seriously, 25 bytes

```<code>,r`PªD;⌐k`M┬`π`Mi│g;)@\)\
</code>```

Outputs a\nb (\n is a newline). Large inputs will take a long time (and might fail due to running out of memory) because prime generation is pretty slow.

Try it online!

Explanation:

```<code>,r`PªD;⌐k`M┬`π`Mi│g;)@\)\
,r                         push range(input)
  `PªD;⌐k`M                map:
   P                         k'th prime
    ª                        square
     D                       decrement
      ;                      dupe
       ⌐                     add 2 (results in P_k + 1)
        k                    push to list
           ┬               transpose
            `π`M           map product
                i│         flatten, duplicate stack
                  g;)      push two copies of gcd, move one to bottom of stack
                     @\    reduce denominator
                       )\  reduce numerator
</code>```

Title: A curious prime fraction formula

Body:
Given a positive integer \$n\$ output the integers \$a\$ and \$b\$ (forming reduced fraction \$a/b\$) such that:

$$\frac a b = \prod ^n _{k=1} \frac {p^2_k - 1} {p^2_k + 1}$$

Where \$p_k\$ is the \$k\$ th prime number (with \$p_1 = 2\$).

Examples:

```<code>1   -> 3, 5
2   -> 12, 25
3   -> 144, 325
4   -> 3456, 8125
5   -> 41472, 99125
15  -> 4506715396450638759507001344, 11179755611058498955501765625
420 -> <a href="https://gist.githubusercontent.com/orlp/fbe70433285ca8d4aad5/raw/1f787288da7f30cd786b123db59dc0e23d7b7ebd/gistfile1.txt" rel="nofollow noreferrer">very long</a></code>```

Probabilistic prime checks are allowed, and it's ok if your answer fails due to limitations in your language's integer type.

Shortest code in bytes wins.

Body:
Seriously, 25 bytes

,r`PªD;⌐k`M┬`π`Mi│g;)@\)\

Outputs a\nb (\n is a newline). Large inputs will take a long time (and might fail due to running out of memory) because prime generation is pretty slow.

Try it online!

Explanation:

,r`PªD;⌐k`M┬`π`Mi│g;)@\)\
,r                         push range(input)
  `PªD;⌐k`M                map:
   P                         k'th prime
    ª                        square
     D                       decrement
      ;                      dupe
       ⌐                     add 2 (results in P_k + 1)
        k                    push to list
           ┬               transpose
            `π`M           map product
                i│         flatten, duplicate stack
                  g;)      push two copies of gcd, move one to bottom of stack
                     @\    reduce denominator
                       )\  reduce numerator


答:
Lua, 45 Bytes, Cracked

A small hint:

```<code>a(0) will make the program crash :)
</code>```

Output

```<code>a(1)=>0
a(2)=>1
</code>```

Code

Uses # to hide the code :).

```<code>a=function(n)#####n###### and #or ########end
</code>```

I was using the OEIS A007814, with the following code:

```<code>a=function(n)return n%2>0 and 0or 1+a(n/2)end
</code>```

Body:
Lua, 45 Bytes, Cracked

A small hint:

a(0) will make the program crash :)

Output

a(1)=>0
a(2)=>1

Code

Uses # to hide the code :).

a=function(n)#####n###### and #or ########end

I was using the OEIS A007814, with the following code:

a=function(n)return n%2>0 and 0or 1+a(n/2)end


答:
JavaScript (ES6), <s>38</s> 27 bytes

```<code>n=>2641714512>>'0b'+n&n<1e5
</code>```

Port of @orlp's Python answer, except that JavaScript's precedence and weak typing allows me to shift the integer even if it's not valid in base 2, and then bitwise and it with the boolean. Returns 0 or 1 as appropriate. Note that I'm not using @orlp's constant any more, instead I'm assuming the following list of comcoins is valid:

 100

 110

 1000

 1010

 1011

 1100

 1110

 10000

 10010

 10100

 10101

 10110

 11000

 11010

 11011

 11100

 11111

Edit: Fixed to check the length of the comcoin, since JavaScript's shift operator works modulo 32.

Title: Is it really a comcoin?

Body:
JavaScript (ES6), <s>38</s> 27 bytes

n=>2641714512>>'0b'+n&n<1e5

Port of @orlp's Python answer, except that JavaScript's precedence and weak typing allows me to shift the integer even if it's not valid in base 2, and then bitwise and it with the boolean. Returns 0 or 1 as appropriate. Note that I'm not using @orlp's constant any more, instead I'm assuming the following list of comcoins is valid:

 100

 110

 1000

 1010

 1011

 1100

 1110

 10000

 10010

 10100

 10101

 10110

 11000

 11010

 11011

 11100

 11111

Edit: Fixed to check the length of the comcoin, since JavaScript's shift operator works modulo 32.


问:
Draw a spiral in a box

This geometric spiral looks complicated, but it's fairly simple to draw; take the following box:

Draw a straight line between the corner of the box and some set distance above the next corner counter-clockwise.

Continue this pattern inward, always staying that set distance away from the corner of the next line. Here's a few more lines in.

As you can see, as the pattern continues, the spiral approaches the center and the boxes you draw begin to rotate. Note that the distance remains constant, regardless of angle.

The Challenge

The Inspiration (and also thanks to the wonderful person who introduced me to this concept <3)

Given a numerical (possibly fractional) input from 1 to 25, write an image to disk that uses this pattern or display the output on the screen, where the distance from each corner is the distance of one initial side of the box divided by the input. Continue the pattern inward until the distance from the corner specified is longer than the length of the next side.

Rules

You may not use built-ins for this spiral creation, but you may use image processing builtins.

If you write to disk, you must output an image in any of .jpg, .gif, .tiff, .pbm, .ppm, and .png.

The initial side length must be at least 500 pixels.

The initial corner may be whichever you choose.

As always, the Standard Loopholes are disallowed.

Title: Draw a spiral in a box

Body:
Groovy, <s>412</s> <s>411</s> <s>403</s> 398 bytes

import java.awt.*
new Frame(){
def s=499,o=s/(args[0]as float),e=0,i,a,b,d,t
{add new Component(){void paint(Graphics g){g.drawRect 0,0,s,s
p=[s,s,s,0,0,0,0,s]
for(d=s;d>o;d=Math.sqrt(a*a+b*b)){t=o/d
i=e*2
a=(int)((1-t)*p[i]+t*p[(2+i)%8]+0.5)
b=(int)((1-t)*p[1+i]+t*p[(3+i)%8]+0.5)
g.drawLine p[(6+i)%8],p[(7+i)%8],a,b
p[i]=a
p[1+i]=b
e=++e%4
i=e*2
a=p[(2+i)%8]-p[i]
b=p[(3+i)%8]-p[1+i]}}}
show()}}


问:
Remove leading and trailing zeroes
Given a non-empty list/array containing only non-negative integers like this:

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

Output the list with trailing and leading zeroes removed.

The output for this would be:

```<code>[8, 1, 4, 3, 5, 6, 4, 1, 2]
</code>```

Some other test cases:

```<code>[0, 4, 1, 2, 0, 1, 2, 4, 0] > [4, 1, 2, 0, 1, 2, 4]
[0, 0, 0, 0, 0, 0] > nothing
[3, 4, 5, 0, 0] > [3, 4, 5]
[6] > [6]
</code>```

Shortest code wins

答:
05AB1E, 4 bytes

```<code>0Û0Ü
</code>```

Basically trimming leading then trailing zeroes of the input, given as an array.

Try it online !

Title: Remove leading and trailing zeroes

Body:
05AB1E, 4 bytes

0Û0Ü

Basically trimming leading then trailing zeroes of the input, given as an array.

Try it online !


答:
MATL, 20 bytes

```<code>n6<G50<9:Q"G@ZAZp~vA
</code>```

Input is a string.

Try it online!

Explanation

```<code>n6<    % take input implicitly. Is length less than 6?
G50<   % push input again. Array that contains true for digits less than 2
9:Q    % push array of bases: [2,3,...,10]
"      % for each
  G    %   push input again
  @    %   push current base
  ZA   %   interpret input as if it were in that base, and convert to decimal
  Zp~  %   true for composite numbers
  v    %   concatenate vertically all results up to now
  A    %   true if all results were
       % end for each implicitly
       % display implicitly
</code>```

Title: Is it really a comcoin?

Body:
Very interesting background

Comcoins are a currency like any other. The residents of Multibaseania (an economically robust system of city-states with very few residents in a galaxy far, far away) use Comcoins to conduct transactions between themselves. Comcoins are represented by unique codes on special not-paper slips, and when you pay you give the vendor your slip.

However, just like any currency, there are those villainous types that try to take advantage of the system and inflate the currency because they are bored.

To combat this unquestionably illegal behavior, the Multibaseanian governments came together and devised a way to prove that the money is legitimate. The top idea from the think tank was: whenever a Comcoin is given to a vendor, the vendor runs a program that checks if it is legitimate. How does one know if a Comcoin is legitimate?

A legitimate Comcoin is one where:

When the Comcoin's unique code is converted into the bases 2-10, inclusive, that number is composite (i.e. not prime). Also, all of the unique code's digits in base 10 are either 1 or 0, and its length in base 10 is between 1 and 5 inclusive.

Very important example: in base 5, 111 is 421. Even though 111 is not prime, 421 is, so the Comcoin is invalid.

The challenge

Write a function or program that takes a Comcoin's code (a number), which is in base 10 and is an integer. Then, print or return a truthy or falsy value depending on whether that Comcoin is legitimate (criteria above), respectively.

I/O examples

```<code>Input     Output

101         False // because it is prime in base 2
1010        True
10101       True
1010111     False // because it is longer than 5 digits
123         False // because it does not contain *only* 0's and 1's
10111       False // because it is prime in base 6
</code>```

This is code golf, so shortest code in bytes wins!

Edit

A Comcoin is not a number that is not prime, but is a number that is composite.

Inspiration from qualification round of Google CodeJam 2016.

Body:
MATL, 20 bytes

n6<G50<9:Q"G@ZAZp~vA

Input is a string.

Try it online!

Explanation

n6<    % take input implicitly. Is length less than 6?
G50<   % push input again. Array that contains true for digits less than 2
9:Q    % push array of bases: [2,3,...,10]
"      % for each
  G    %   push input again
  @    %   push current base
  ZA   %   interpret input as if it were in that base, and convert to decimal
  Zp~  %   true for composite numbers
  v    %   concatenate vertically all results up to now
  A    %   true if all results were
       % end for each implicitly
       % display implicitly


答:
Pyth, 51 bytes, Safe

# denote hidden characters:

<s>K"#"D#d=#:d"#|#"1Rs#?qd"#"####"##"b#W<#K+#1=KhK;@KQ</s>

```<code>K"0"Dhd=b:d"0|1"1Rsm?qd"0""01""10"b;W<lK+Q1=KhK;@KQ
</code>```

Outputs

```<code>a(0) -> 0
a(1) -> 1
a(2) -> 1
a(4) -> 0
</code>```

This is a fair one.

Thue-morse sequence, A010060.

Body:
This is the cops' thread. The robbers' thread goes here.

The last cops-and-robbers thread was already 4 months ago.

The cop's task

The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.

The cop must state it if the program is intolerant towards zero.

The cop will provide at least 2 sample inputs/outputs.

For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:

```
a(0) returns 0
a(3) returns 2
```

The number of examples is up to the cop's discretion.

However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(

The cop can hide as many characters as is so wished.

For example, if my program is:

```<code>function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Then I would hide these characters as I want:

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

The robber's task

is obviously to find the original source code.

However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

<s>The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.</s>

Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):

Lua, 98 bytes

Output:

```<code>a(0) returns 0
a(3) returns 2
</code>```

Code (# marks unrevealed characters):

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

If the code is cracked, insert [Cracked](link to cracker) in the header.
If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

Body:
Pyth, 51 bytes, Safe

# denote hidden characters:

<s>K"#"D#d=#:d"#|#"1Rs#?qd"#"####"##"b#W<#K+#1=KhK;@KQ</s>

K"0"Dhd=b:d"0|1"1Rsm?qd"0""01""10"b;W<lK+Q1=KhK;@KQ

Outputs

a(0) -> 0
a(1) -> 1
a(2) -> 1
a(4) -> 0

This is a fair one.

Thue-morse sequence, A010060.


答:
Pyth, 4 bytes, Cracked

# denote hidden characters:

```<code>###Q
</code>```

Output

```<code>a(1) -> 1
a(2) -> 2
a(3) -> 3
a(10) -> 42
</code>```

Body:
Pyth, 4 bytes, Cracked

# denote hidden characters:

###Q

Output

a(1) -> 1
a(2) -> 2
a(3) -> 3
a(10) -> 42


答:
Mathematica, 97 bytes

```<code>#<1*^5&&Tr@DigitCount[#][[2;;-2]]<1&&FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ&
</code>```

Hey, at least I tried...

```<code>#<1*^5&&Tr@DigitCount[#][[2;;-2]]<1&&FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ&
#<1*^5&&                                                                                less than 100000?
        Tr@DigitCount[#][[2;;-2]]<1&&                                                             no digits 2-9?
                                     FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ& composite in all bases?
</code>```

Title: Is it really a comcoin?

Body:
Mathematica, 97 bytes

#<1*^5&&Tr@DigitCount[#][[2;;-2]]<1&&FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ&

Hey, at least I tried...

#<1*^5&&Tr@DigitCount[#][[2;;-2]]<1&&FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ&
#<1*^5&&                                                                                less than 100000?
        Tr@DigitCount[#][[2;;-2]]<1&&                                                             no digits 2-9?
                                     FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ& composite in all bases?


答:
Ruby, <s>143</s> 134 bytes

An anonymous function.

1 byte saved by a rearrangement of the first line. 6 bytes saved by changing the way z is incremented from a formula to a table. 2 bytes saved by eliminating varable w.

```<code>->a{r=-1+u=2<<a.size
s=(?.*r+$/)*r
a<<0
z=r*u/2-1
a.each{|i|r/=2
(-r..r).each{|j|s[z+j]=s[z+j*u]=?#}
z+=-r/2*[u+1,u-1,1-u,-u-1][i]}
s}
</code>```

Ungolfed in test program

```<code>f=->a{
  r=w=(u=2<<a.size)-1        #w=length of line excluding newline, u=length of line including newline.
  s=(?.*w+$/)*w              #initialize string s with w rows of w dots terminated by newlines.
  z=w*u/2-1                  #z is the centre of the fractal
  a<<0                       #add a dummy value to the end of a
  a.each{|i|                 #for each element in a
    r/=2                     #r is the radius of the current iteration: ....15,7,3,1
    (-r..r).each{|j|         #for j=-r to r
      s[z+j]=s[z+j*u]=?#     #overwrite . with #, forming horizontal and vertical lines
    }
    z+=-r/2*(u+1)+           #move z to centre of upper left quarter (where it should be if i=0)
      i%2*(q=r+1)+           #move across if i=1,3
      i/2%2*q*u              #and down if i=2,3
  }
s}                           #return string

puts $/,f[[]]

puts $/,f[[0]]

puts $/,f[[3]]

puts $/,f[[2,0]]

puts $/,f[[1,1]]

puts $/,f[[1,2,0]]

puts $/,f[[3,3,1]]

puts $/,f[[0,1,2,3]]

puts $/,f[[0,0,1,2,3]]
</code>```

Title: Draw an indexed fractal

Body:
Introduction

In this challenge, a 2×2 matrix is indexed like this:

```<code>0 1
2 3
</code>```

We define a family of fractal-like patterns F(L), where L is a length-n list of these indices and F(L) has size 2n-1 × 2n-1.

If L == [], then F(L) is the 1×1 pattern #.

If L != [], then F(L) is constructed as follows. Let P be the pattern obtained from L with first element removed. Take four grids of size 2n-1-1 × 2n-1-1 filled with periods ., and replace the grid indexed by L[0] with the pattern P. Then, glue the grids together using one layer of hashes # between them. Here are diagrams for the four cases:

```<code>L[0]==0  L[0]==1  L[0]==2  L[0]==3
   #...  ...#     ...#...  ...#...
[P]#...  ...#[P]  ...#...  ...#...
   #...  ...#     ...#...  ...#...
#######  #######  #######  #######
...#...  ...#...     #...  ...#
...#...  ...#...  [P]#...  ...#[P]
...#...  ...#...     #...  ...#
</code>```

Example

Consider the input L = [2,0].
We begin with the 1×1 grid #, and traverse L from the right.
The rightmost element is 0, so we take four copies of the 1×1 grid ., replace the first one by #, and glue them together with hashes.
This results in the 3×3 grid

```<code>##.
###
.#.
</code>```

The next element is 2, so we take four copies of the 3×3 grid of .s, and replace the third one with the above grid.
The four grids are

```<code>...  ...  ##.  ...
...  ...  ###  ...
...  ...  .#.  ...
</code>```

and gluing them together with #s results in the 7×7 grid

```<code>...#...
...#...
...#...
#######
##.#...
####...
.#.#...
</code>```

This is our final output.

Input

Your input is a list L of the indices 0, 1, 2, 3.
You can take it as a list of integers, or a string of digits.
Note that it may be empty, and it may contain duplicates.
The length of L is at most 5.

Output

Your output is the pattern F(L) as a newline-delimited string.

Rules and scoring

You can write a full program or a function.
the lowest byte count wins, and standard loopholes are disallowed.

Test cases

```<code>[]
#

[0]
##.
###
.#.

[3]
.#.
###
.##

[2,0]
...#...
...#...
...#...
#######
##.#...
####...
.#.#...

[1,1]
...#.##
...####
...#.#.
#######
...#...
...#...
...#...

[1,2,0]
.......#...#...
.......#...#...
.......#...#...
.......########
.......###.#...
.......#####...
.......#.#.#...
###############
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......

[3,3,1]
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
.......#.......
###############
.......#...#...
.......#...#...
.......#...#...
.......########
.......#...#.##
.......#...####
.......#...#.#.

[0,1,2,3]
.......#...#...#...............
.......#...#...#...............
.......#...#...#...............
.......#########...............
.......#.#.#...#...............
.......#####...#...............
.......#.###...#...............
################...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
.......#.......#...............
###############################
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............
...............#...............

[0,0,1,2,3]
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#...#...#...............#...............................
.......#########...............#...............................
.......#.#.#...#...............#...............................
.......#####...#...............#...............................
.......#.###...#...............#...............................
################...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
.......#.......#...............#...............................
################################...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
...............#...............#...............................
###############################################################
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
...............................#...............................
</code>```

Body:
Ruby, <s>143</s> 134 bytes

An anonymous function.

1 byte saved by a rearrangement of the first line. 6 bytes saved by changing the way z is incremented from a formula to a table. 2 bytes saved by eliminating varable w.

->a{r=-1+u=2<<a.size
s=(?.*r+$/)*r
a<<0
z=r*u/2-1
a.each{|i|r/=2
(-r..r).each{|j|s[z+j]=s[z+j*u]=?#}
z+=-r/2*[u+1,u-1,1-u,-u-1][i]}
s}

Ungolfed in test program

f=->a{
  r=w=(u=2<<a.size)-1        #w=length of line excluding newline, u=length of line including newline.
  s=(?.*w+$/)*w              #initialize string s with w rows of w dots terminated by newlines.
  z=w*u/2-1                  #z is the centre of the fractal
  a<<0                       #add a dummy value to the end of a
  a.each{|i|                 #for each element in a
    r/=2                     #r is the radius of the current iteration: ....15,7,3,1
    (-r..r).each{|j|         #for j=-r to r
      s[z+j]=s[z+j*u]=?#     #overwrite . with #, forming horizontal and vertical lines
    }
    z+=-r/2*(u+1)+           #move z to centre of upper left quarter (where it should be if i=0)
      i%2*(q=r+1)+           #move across if i=1,3
      i/2%2*q*u              #and down if i=2,3
  }
s}                           #return string

puts $/,f[[]]

puts $/,f[[0]]

puts $/,f[[3]]

puts $/,f[[2,0]]

puts $/,f[[1,1]]

puts $/,f[[1,2,0]]

puts $/,f[[3,3,1]]

puts $/,f[[0,1,2,3]]

puts $/,f[[0,0,1,2,3]]


答:
C, 82 bytes, safe

```<code>####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}
</code>```

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is <s>A004526, floor(n/2)</s>.

```<code>a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4
</code>```

Solution:

```<code>a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}
</code>```

This works only on little endian machines, and only if the size of char is 1 byte.

And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see https://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
 So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.

Body:
C, 82 bytes, safe

####=############
main(i){scanf("%d",##);
for(i=1;i++/4<#;)##=2;
printf("%d",##);}

Works with gcc, and it is a full program, which reads its input from stdin and prints its output to stdout. Here the sequence is <s>A004526, floor(n/2)</s>.

a(0) = 0    a(1) = 0    a(2) = 1
a(3) = 1    a(4) = 2    a(5) = 2
a(6) = 3    a(7) = 3    a(8) = 4

Solution:

a;*b=(char*)&a+1;
main(i){scanf("%d",&a);
for(i=1;i++/4<2;)a*=2;
printf("%d",*b);}

This works only on little endian machines, and only if the size of char is 1 byte.

And only if the byte higher than the highest order byte of a has value 0. I think this is true for gcc since by default uninitialized global variables go into the bss segment, and initialized global variables go into the data segment (see https://stackoverflow.com/questions/8721475/if-a-global-variable-is-initialized-to-0-will-it-go-to-bss).
 So only a goes into bss (the only other global variable b is initialized and thus goes into the data segment). If a is not at the end of bss, then the byte higher than the highest order byte of a is also in bss and thus has value 0.


问:
Open the browser to http://codegolf.stackexchange.com
Your job is to open a browser window of the default browser to http://codegolf.stackexchange.com.

Your code must open the browser itself, and cannot rely on an open one.

This is code-golf, so the shortest answer in bytes wins.

Moderator note: A large number of answers to this challenge use the URLs http://ppcg.lol or http://ppcg.ga. These URLs did direct to https://codegolf.stackexchange.com at the time, but have since expired. By this meta discussion, they have been allowed to stay, with the note that they are currently invalid.

答:
Lua, 30 Bytes

```<code>os.execute'start http:ppcg.ga'
</code>```

Body:
Lua, 30 Bytes

os.execute'start http:ppcg.ga'


问:
Simple cat program
One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after the Unix shell utility cat it is of course much less powerful than the real thing, which is normally used to print (and concatenate) several files read from disc.

Task

You should write a full program which reads the contents of the standard input stream and writes them verbatim to the standard output stream. If and only if your language does not support standard input and/or output streams (as understood in most languages), you may instead take these terms to mean their closest equivalent in your language (e.g. JavaScript's prompt and alert). These are the only admissible forms of I/O, as any other interface would largely change the nature of the task and make answers much less comparable.

The output should contain exactly the input and nothing else. The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation. This also applies to trailing newlines. If the input does not contain a trailing newline, the output shouldn't include one either! (The only exception being if your language absolutely always prints a trailing newline after execution.)

Output to the standard error stream is ignored, so long as the standard output stream contains the expected output. In particular, this means your program can terminate with an error upon hitting the end of the stream (EOF), provided that doesn't pollute the standard output stream. If you do this, I encourage you to add an error-free version to your answer as well (for reference).

As this is intended as a challenge within each language and not between languages, there are a few language specific rules:

If it is at all possible in your language to distinguish null bytes in the standard input stream from the EOF, your program must support null bytes like any other bytes (that is, they have to be written to the standard output stream as well).

If it is at all possible in your language to support an arbitrary infinite input stream (i.e. if you can start printing bytes to the output before you hit EOF in the input), your program has to work correctly in this case. As an example yes | tr -d \\n | ./my_cat should print an infinite stream of ys. It is up to you how often you print and flush the standard output stream, but it must be guaranteed to happen after a finite amount of time, regardless of the stream (this means, in particular, that you cannot wait for a specific character like a linefeed before printing).

Please add a note to your answer about the exact behaviour regarding null-bytes, infinite streams, and extraneous output.

Additional rules

This is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

Submissions in most languages will be scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8.

Some languages, like Folders, are a bit tricky to score. If in doubt, please ask on Meta.

Feel free to use a language (or language version) even if it's newer than this challenge. Languages specifically written to submit a 0-byte answer to this challenge are fair game but not particularly interesting.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

Also note that languages do have to fulfil our usual criteria for programming languages.

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Headsecks or Unary), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

Unless they have been overruled earlier, all standard code-golf rules apply, including the http://meta.codegolf.stackexchange.com/q/1061.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the author actually had to put effort into golfing the code.

Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Lua, 30 Bytes

Heavily base upon Lynn's answer, but as it is not updated anymore, I'll feel free ot post this 30 bytes answer.

```<code>::a::io.write(io.read())goto a
</code>```

Title: Simple cat program

Body:
Lua, 30 Bytes

Heavily base upon Lynn's answer, but as it is not updated anymore, I'll feel free ot post this 30 bytes answer.

::a::io.write(io.read())goto a


问:
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
R, <s>16</s> <s>28</s> 25 bytes

```<code>x=scan();while(x)cat(1);0
</code>```

Edited to read x

Title: Implement a Truth-Machine

Body:
R, <s>16</s> <s>28</s> 25 bytes

x=scan();while(x)cat(1);0

Edited to read x


Body:
Pyth, 29 bytes

W##YQ#t^#Z=#h#I#_#=#+Y##;@#tQ

Probably not an easy one. Begins at 1.

a(1) -> 2
a(2) -> 3
a(3) -> 5
a(4) -> 7
a(5) -> 13


Body:
Ruby, 38 bytes, cracked

Obfuscated code (# can be any character):

->#{(s=#########).sum==#3333&&eval(s)}

Output:

Multiplies the input by 10 (A008592). Works for any integer, including 0. e.g.

->#{(s=#########).sum==#3333&&eval(s)}[3]  => 30
->#{(s=#########).sum==#3333&&eval(s)}[10] => 100