问:
Cities: Sightlines
I'm at position (0, 0) of an infinite two-dimensional city, which is perfectly divided into blocks centered at each lattice point, some of which contain buildings. A building at a certain point (x, y) takes up the entire square with opposite corners at (x-.5, y-.5) and  (x+.5, y+.5), including its border. A building is visible iff there is some line segment from (0, 0) to a point in the building which does not intersect any other building.

For example, I (the @) can see 6 buildings (*) in the following city:

```<code>  *
 *
*
*@
x**
 *  y
</code>```

I can't see the building marked with an x, at (-1, -1) because it's obstructed by the two adjacent to it; or the one marked with a y at (3, -2) because it's obstructed by the edge of the (1, -1) building.

Input

A multiline string, or list of lines, optionally padded with spaces into a rectangle. It will contain only:

a single @ (my position)

Spaces

*, which represent buildings.

There will always be at least one building, and therefore at least one visible building.

Output

The number of visible buildings.

Test cases

```<code>*@
1

* *******
 @     *
7

*****
**@**
*****
4

   *
  **
@ **
2

*      *
 *    *
@
4

@
 *
  ***
1
</code>```

Thanks to @Geobits for the title.

答:
Java 8 lambda, <s>1506</s> <s>1002</s> <s>972</s> 942 characters

I wanted to beat this challenge, as it is very interesting. The result <s>(not very golfy)</s> can be seen here:

```<code>import java.util.*;f->{Set<double[]>B=new HashSet(),r,n;double a,M,m,P=Math.PI*2,z=.5;int x=0,y,v=0,i,j,c[],p,q,l=g.length;for(;x<l;x++)for(y=0;y<g[x].length;y++)if(g[x][y]>63)for(;;){c=new int[]{-1};M=2e31-1;for(i=0;i<l;i++)for(j=0;j<g[i].length;j++)if(g[i][j]==42)if((m=(p=x-i)*p+(q=y-j)*q)<M){M=m;c=new int[]{i,j};}if(c[0]<0)break;g[c[0]][c[1]]=0;double[]A={(a=Math.atan2((c[1]-=y)-z,(c[0]-=x)-z))<0?a+P:a,(a=Math.atan2(c[1]+z,c[0]-z))<0?a+P:a,(a=Math.atan2(c[1]+z,c[0]+z))<0?a+P:a,(a=Math.atan2(c[1]-z,c[0]+z))<0?a+P:a};r=new HashSet();M=-P;m=P;for(double d:A){M=d>M?d:M;m=d<m?d:m;}r.add(new double[]{m,M});for(double[]t:B){n=new HashSet();for(double[]h:r)for(double[]u:t[0]<h[0]?t[1]<h[0]?new double[][]{h}:t[1]<h[1]?new double[][]{{t[1],h[1]}}:new double[0][]:t[0]>h[1]?new double[][]{h}:t[1]>h[1]?new double[][]{{h[0],t[0]}}:new double[][]{{h[0],t[0]},{t[1],h[1]}})if(u[0]<u[1])n.add(u);r=n;}B.addAll(r);if(!r.isEmpty())v++;}return v;}
</code>```

Of course this also exists in the ungolfed version:

```<code>import java.util.*;

public class AngleCheck {

    static int getViewableBuildingsC(char[][] grid) {

        Set<double[]> blocked = new HashSet(), ranges, newRanges;

        double angle, max, min, PI2 = Math.PI * 2, half = 0.5;

        int x = 0, y, viewable = 0, i, j, building[], dX, dY, length = grid.length;

        for (; x < length; x++) {
            for (y = 0; y < grid[x].length; y++) {
                if (grid[x][y] > 63) {
                    for (;;) {
                        building = new int[]{-1};
                        max = 2e31-1;
                        for (i = 0; i < length; i++) {
                            for (j = 0; j < grid[i].length; j++) {
                                if (grid[i][j] == 42) {
                                    if ((min = (dX = x - i) * dX + (dY = y - j) * dY) < max) {
                                        max = min;
                                        building = new int[]{i, j};
                                    }
                                }
                            }
                        }

                        if (building[0] < 0)
                            break;

                        grid[building[0]][building[1]] = 0;
                        double[] angles = {
                                        (angle = Math.atan2((building[1] -= y) - half, (building[0] -= x) - half)) < 0 ? angle + PI2 : angle,
                                        (angle = Math.atan2(building[1] + half, building[0] - half)) < 0 ? angle + PI2 : angle,
                                        (angle = Math.atan2(building[1] + half, building[0] + half)) < 0 ? angle + PI2 : angle,
                                        (angle = Math.atan2(building[1] - half, building[0] + half)) < 0 ? angle + PI2 : angle};

                        ranges = new HashSet();

                        max = -PI2;
                        min = PI2;
                        for (double d : angles) {
                            max = d > max ? d : max;
                            min = d < min ? d : min;
                        }

                        ranges.add(new double[]{min, max});

                        for (double[] reference : blocked) {
                            newRanges = new HashSet();
                            for (double[] currentRange : ranges) {
                                for (double[] subRange : reference[0] < currentRange[0] ?
                                            reference[1] < currentRange[0] ?
                                                // whole range after referencerange
                                                new double[][]{currentRange}
                                            :
                                                reference[1] < currentRange[1] ?
                                                    // lower bound inside referencerange, but upper bound outside
                                                    new double[][]{{reference[1], currentRange[1]}}
                                                :
                                                    // whole range inside referencerange -> nothing free
                                                    new double[0][]
                                        :
                                            // greater or equal lower bound
                                            reference[0] > currentRange[1] ?
                                                // whole range before referencerange
                                                new double[][]{currentRange}
                                            :
                                                // ranges overlap
                                                reference[1] > currentRange[1] ?
                                                    // range starts before and ends in reference range
                                                    new double[][]{{currentRange[0], reference[0]}}
                                                :
                                                    // referencerange is in the range -> two free parts, one before, one after this
                                                    new double[][]{{currentRange[0], reference[0]}, {reference[1], currentRange[1]}}) {
                                    if (subRange[0] < subRange[1])
                                        newRanges.add(subRange);
                                }
                            }
                            ranges = newRanges;
                        }

                        blocked.addAll(ranges);
                        if (!ranges.isEmpty()) {
                            viewable++;
                        }
                    }
                }
            }
        }
        return viewable;
    }
}
</code>```

So it looks very difficult but it's way easier than one might think. My first idea was to use some intersection algorithm to check whether a line from my position to the building can be made without any intersections. To do this I decided to use the Cohen-Sutherland algorithm and draw lines to all four corners of the building. This worked pretty well for the first tests, but the last one failed. I soon found out, that it's a case where you can't see the corners but a part of an edge. So I thought about some sort of ray casting like @Blue did it. I put that challenge away, as I didn't got some progress. Then I saw Blue's answer and the following simple idea came to my mind: Each building blocks some angle in which nothing else can be seen. I just need to keep track of what can be seen and what is already hidden by other buildings. That's it!

The algorithm works as follows: It determines the building with the smallest distance to the person. Then we imagine four lines drawn from the person to the corners of the building. Two of these have an extreme value: The minimum and maximum angle in which the building can be seen. We take them as a range and compare them with other buildings of which we know that they can be seen (none at the beginning). The ranges may overlap, include each other or don't touch at all. I compare the ranges and get some new ranges of the building which aren't hidden by the viewable buildings. If there is something remaining after comparing it with the buildings in-sight the building is also viewable. We add the remaining angle range to the list of ranges to compare to and start off with the next building with the next longer distance.

Sometimes the ranges may overlap in a way that I end up with a range of 0 degrees. These ranges will be filtered to don't mistakenly add a building that isn't even viewable.

I hope someone understood this explanation :)

<s>I know this code isn't golfed very much, I'll do this asap.</s>

That was a really challenging task. You thought you found a solution that works but instead you are far away still. I think this solution works pretty good. It isn't very fast but at least it works ;) Thanks for that puzzle!

Update

I found the time to golf the whole thing down into a single function, which thus can be turned into a lambda. All functions were only called once and thus can be put into one method. I switched from lists to sets as this saves some additional characters. The declarations have been put together. The comparisons have been put together and characters were replaced by there ascii value. The range comparing can be expressed as many ternaries. Some tricks here and there to prevent long expressions like Double.NEGATIVE_INFINITY got done. Where possible inline assigments are done. To save a bit more I switched from comparing the angles in degrees to comparing the radians. The whole change saved over 500 characters, I hope to get it all under 1000 though ;)

I removed the generics where possible and shortened the return comparison by creating an one element array and check it's value instead. I also replaced the Double.NEGATIVE_INFINITY with PI2 and -PI2 as these are the upper and lower bounds of the angles. Now it's finally under 1000 chars long!

I merged the loops for finding the persons location and the building iterator to save some characters. Unfortunately this requires us to move the return out of the loop and still use a break but this time without a label. I merged max and distanceSquared and min and newDistanceSquared as they aren't required at the same time. I changed Integer.MAX_VALUE to 2e31-1. Also I created a constant half = 0.5 which is used to calculate the corners of the building. This is shorter in the golfed version. Overall we saved another 30 characters!

Title: Cities: Sightlines

Body:
Java 8 lambda, <s>1506</s> <s>1002</s> <s>972</s> 942 characters

I wanted to beat this challenge, as it is very interesting. The result <s>(not very golfy)</s> can be seen here:

import java.util.*;f->{Set<double[]>B=new HashSet(),r,n;double a,M,m,P=Math.PI*2,z=.5;int x=0,y,v=0,i,j,c[],p,q,l=g.length;for(;x<l;x++)for(y=0;y<g[x].length;y++)if(g[x][y]>63)for(;;){c=new int[]{-1};M=2e31-1;for(i=0;i<l;i++)for(j=0;j<g[i].length;j++)if(g[i][j]==42)if((m=(p=x-i)*p+(q=y-j)*q)<M){M=m;c=new int[]{i,j};}if(c[0]<0)break;g[c[0]][c[1]]=0;double[]A={(a=Math.atan2((c[1]-=y)-z,(c[0]-=x)-z))<0?a+P:a,(a=Math.atan2(c[1]+z,c[0]-z))<0?a+P:a,(a=Math.atan2(c[1]+z,c[0]+z))<0?a+P:a,(a=Math.atan2(c[1]-z,c[0]+z))<0?a+P:a};r=new HashSet();M=-P;m=P;for(double d:A){M=d>M?d:M;m=d<m?d:m;}r.add(new double[]{m,M});for(double[]t:B){n=new HashSet();for(double[]h:r)for(double[]u:t[0]<h[0]?t[1]<h[0]?new double[][]{h}:t[1]<h[1]?new double[][]{{t[1],h[1]}}:new double[0][]:t[0]>h[1]?new double[][]{h}:t[1]>h[1]?new double[][]{{h[0],t[0]}}:new double[][]{{h[0],t[0]},{t[1],h[1]}})if(u[0]<u[1])n.add(u);r=n;}B.addAll(r);if(!r.isEmpty())v++;}return v;}

Of course this also exists in the ungolfed version:

import java.util.*;

public class AngleCheck {

    static int getViewableBuildingsC(char[][] grid) {

        Set<double[]> blocked = new HashSet(), ranges, newRanges;

        double angle, max, min, PI2 = Math.PI * 2, half = 0.5;

        int x = 0, y, viewable = 0, i, j, building[], dX, dY, length = grid.length;

        for (; x < length; x++) {
            for (y = 0; y < grid[x].length; y++) {
                if (grid[x][y] > 63) {
                    for (;;) {
                        building = new int[]{-1};
                        max = 2e31-1;
                        for (i = 0; i < length; i++) {
                            for (j = 0; j < grid[i].length; j++) {
                                if (grid[i][j] == 42) {
                                    if ((min = (dX = x - i) * dX + (dY = y - j) * dY) < max) {
                                        max = min;
                                        building = new int[]{i, j};
                                    }
                                }
                            }
                        }

                        if (building[0] < 0)
                            break;

                        grid[building[0]][building[1]] = 0;
                        double[] angles = {
                                        (angle = Math.atan2((building[1] -= y) - half, (building[0] -= x) - half)) < 0 ? angle + PI2 : angle,
                                        (angle = Math.atan2(building[1] + half, building[0] - half)) < 0 ? angle + PI2 : angle,
                                        (angle = Math.atan2(building[1] + half, building[0] + half)) < 0 ? angle + PI2 : angle,
                                        (angle = Math.atan2(building[1] - half, building[0] + half)) < 0 ? angle + PI2 : angle};

                        ranges = new HashSet();

                        max = -PI2;
                        min = PI2;
                        for (double d : angles) {
                            max = d > max ? d : max;
                            min = d < min ? d : min;
                        }

                        ranges.add(new double[]{min, max});

                        for (double[] reference : blocked) {
                            newRanges = new HashSet();
                            for (double[] currentRange : ranges) {
                                for (double[] subRange : reference[0] < currentRange[0] ?
                                            reference[1] < currentRange[0] ?
                                                // whole range after referencerange
                                                new double[][]{currentRange}
                                            :
                                                reference[1] < currentRange[1] ?
                                                    // lower bound inside referencerange, but upper bound outside
                                                    new double[][]{{reference[1], currentRange[1]}}
                                                :
                                                    // whole range inside referencerange -> nothing free
                                                    new double[0][]
                                        :
                                            // greater or equal lower bound
                                            reference[0] > currentRange[1] ?
                                                // whole range before referencerange
                                                new double[][]{currentRange}
                                            :
                                                // ranges overlap
                                                reference[1] > currentRange[1] ?
                                                    // range starts before and ends in reference range
                                                    new double[][]{{currentRange[0], reference[0]}}
                                                :
                                                    // referencerange is in the range -> two free parts, one before, one after this
                                                    new double[][]{{currentRange[0], reference[0]}, {reference[1], currentRange[1]}}) {
                                    if (subRange[0] < subRange[1])
                                        newRanges.add(subRange);
                                }
                            }
                            ranges = newRanges;
                        }

                        blocked.addAll(ranges);
                        if (!ranges.isEmpty()) {
                            viewable++;
                        }
                    }
                }
            }
        }
        return viewable;
    }
}

So it looks very difficult but it's way easier than one might think. My first idea was to use some intersection algorithm to check whether a line from my position to the building can be made without any intersections. To do this I decided to use the Cohen-Sutherland algorithm and draw lines to all four corners of the building. This worked pretty well for the first tests, but the last one failed. I soon found out, that it's a case where you can't see the corners but a part of an edge. So I thought about some sort of ray casting like @Blue did it. I put that challenge away, as I didn't got some progress. Then I saw Blue's answer and the following simple idea came to my mind: Each building blocks some angle in which nothing else can be seen. I just need to keep track of what can be seen and what is already hidden by other buildings. That's it!

The algorithm works as follows: It determines the building with the smallest distance to the person. Then we imagine four lines drawn from the person to the corners of the building. Two of these have an extreme value: The minimum and maximum angle in which the building can be seen. We take them as a range and compare them with other buildings of which we know that they can be seen (none at the beginning). The ranges may overlap, include each other or don't touch at all. I compare the ranges and get some new ranges of the building which aren't hidden by the viewable buildings. If there is something remaining after comparing it with the buildings in-sight the building is also viewable. We add the remaining angle range to the list of ranges to compare to and start off with the next building with the next longer distance.

Sometimes the ranges may overlap in a way that I end up with a range of 0 degrees. These ranges will be filtered to don't mistakenly add a building that isn't even viewable.

I hope someone understood this explanation :)

<s>I know this code isn't golfed very much, I'll do this asap.</s>

That was a really challenging task. You thought you found a solution that works but instead you are far away still. I think this solution works pretty good. It isn't very fast but at least it works ;) Thanks for that puzzle!

Update

I found the time to golf the whole thing down into a single function, which thus can be turned into a lambda. All functions were only called once and thus can be put into one method. I switched from lists to sets as this saves some additional characters. The declarations have been put together. The comparisons have been put together and characters were replaced by there ascii value. The range comparing can be expressed as many ternaries. Some tricks here and there to prevent long expressions like Double.NEGATIVE_INFINITY got done. Where possible inline assigments are done. To save a bit more I switched from comparing the angles in degrees to comparing the radians. The whole change saved over 500 characters, I hope to get it all under 1000 though ;)

I removed the generics where possible and shortened the return comparison by creating an one element array and check it's value instead. I also replaced the Double.NEGATIVE_INFINITY with PI2 and -PI2 as these are the upper and lower bounds of the angles. Now it's finally under 1000 chars long!

I merged the loops for finding the persons location and the building iterator to save some characters. Unfortunately this requires us to move the return out of the loop and still use a break but this time without a label. I merged max and distanceSquared and min and newDistanceSquared as they aren't required at the same time. I changed Integer.MAX_VALUE to 2e31-1. Also I created a constant half = 0.5 which is used to calculate the corners of the building. This is shorter in the golfed version. Overall we saved another 30 characters!


问:
A Hundred Squares!

Back to basics...

As a teacher at the local primary (grade?) school, you need a way to teach your class their times tables. At your disposal, you have hundred squares and a load of red pens. You need to also be able to show your class the correct answers quickly.

Now, you're clever enough to write a program that can do times tables, but can you draw them on a hundred square?

The challenge

Output a hundred square to stdout or equivalent using ansi-escape codes to shade in numbers which are multiples of the input.

Output a 10x10 grid containing the numbers 1-100.

It doesn't matter the alignment of 2 digit numbers in each box as long as it's consistant

For 1 digit numbers, you may pad to 2 digits and use the same formatting as 2 digit numbers or centered in the middle of the box.

If the number in the box is a multiple of the input, colour the entire box red.

This means the whole box, not just the number part

For example, given the input 3, print the given hundred square

This is code golf so the shortest answer in bytes wins!

ContentLicense: CC BY-SA 3.0

Title: A Hundred Squares!

Body:
HTML + Javascript, 379

HTML:

<input id=a value=3><pre id=z>

Javascript:

for(i=0,s=`\n|`,o='+';i++<109;x=i<10?` ${i} `:i-100?' '+i:i,s+=x+'|',o+=x='---+',i%10||(o+=s+'\n+',s=`\n|`));z.innerHTML=[...o+x].map((x,i)=>`<span id=i${i}>${x}</span>`).join``;f=m=>window['i'+m].style.background='red';for(j=k=+a.value;j<=100;j+=k){p=(j/10|0)*84+((m=j%10)?(m-1)*4:-48);'000102030442434445468485868788'.match(/../g).map(x=>f(+x+p))}

jsfiddle.


问:
OMG! We're Twinning!

Introduction

We define twin primes as two natural numbers p,p+2 which both are prime.

Example: 5 and 7 are twin primes.

Let's define the twin number of some set of numbers as the number of twin prime numbers in that set

Example: {6,7,11,13,18,29,31} has a twin number 4, since there are four twin primes; 11,13 and 29,31.

Program

Input: A number n

Output: The twin number of the set of all natural numbers below n

Scoring

This is code-golf, so lowest bytes wins.

答:
MATL, 7 bytes

```<code>qZqd2=s
</code>```

This solution exploits the fact that the prime gap (the difference between successsive prime numbers) is always >= 2 (with the exception being the gap between 2 and 3). Because of this fact, all twin primes will be successive prime numbers. In this solution we just compute the differences between all primes less than the input n and count how many of these differences are equal to 2.

Try it Online

Explanation

```<code>    % Implicitly grab input, N
q   % Subtract one from the input (N-1)
Zq  % Get an array of all primes <= (N-1)
d   % Compute successive differences (prime gaps)
2=  % Create a boolean array indicating which prime gaps are equal to 2
s   % Count the TRUE values in this array to determine the twin number
    % Implicitly display the result

</code>```

If you instead want the not the number of pairs but the number of primes that are part of a pair, the following would work

```<code>qZqt!-|H=az
</code>```

Try it Online

Title: OMG! We're Twinning!

Body:
MATL, 7 bytes

qZqd2=s

This solution exploits the fact that the prime gap (the difference between successsive prime numbers) is always >= 2 (with the exception being the gap between 2 and 3). Because of this fact, all twin primes will be successive prime numbers. In this solution we just compute the differences between all primes less than the input n and count how many of these differences are equal to 2.

Try it Online

Explanation

    % Implicitly grab input, N
q   % Subtract one from the input (N-1)
Zq  % Get an array of all primes <= (N-1)
d   % Compute successive differences (prime gaps)
2=  % Create a boolean array indicating which prime gaps are equal to 2
s   % Count the TRUE values in this array to determine the twin number
    % Implicitly display the result

If you instead want the not the number of pairs but the number of primes that are part of a pair, the following would work

qZqt!-|H=az

Try it Online


问:
Weapons of Math Instruction
Last time when I tried to come up with something easy that wasn't a duplicate, it ended up being way too hard.. So hopefully this time it's indeed something newcomers can try as well.

Input:

An array/list with integers/decimals. (Or a string representing an array with integers/decimals.)

Output:

Loop through the numbers and apply the following five mathematical operands in this order:

Addition (+);

Subtraction (−);

Multiplication (* or × or ·);

Real / Calculator Division (/ or ÷);

Exponentiation (^ or **).

(NOTE: The symbols between parenthesis are just added as clarification. If your programming language uses a completely different symbol for the mathematical operation than the examples, then that is of course completely acceptable.)

Keep continuing until you've reached the end of the list, and then give the result of the sum.

Challenge rules:

Exponentiation by 0 (n ^ 0) should result in 1 (this also applies to 0 ^ 0 = 1).

There are no test cases for division by 0 (n / 0), so you don't have to worry about that edge-case.

If the array contains just a single number, we return that as the result.

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Test cases:

```<code>[1,2,3,4,5] -> 0
-> 1 + 2 = 3
  -> 3 - 3 = 0
    -> 0 * 4 = 0
      -> 0 / 5 = 0

[5,12,23,2,4,4,2,6,7] -> 539
-> 5 + 12 = 17
  -> 17 - 23 = -6
    -> -6 * 2 = -12
      -> -12 / 4 = -3
        -> -3 ^ 4 = 81
          -> 81 + 2 = 83
            -> 83 - 6 = 77
              -> 77 * 7 -> 539

[-8,50,3,3,-123,4,17,99,13] -> -1055.356...
-> -8 + 50 = 42
  -> 42 - 3 = 39
    -> 39 * 3 = 117
      -> 117 / -123 = -0.9512...
        -> -0.9512... ^ 4 = 0.818...
          -> 0.818... + 17 = 17.818...
            -> 17.818... - 99 -> -81.181...
              -> -81.181... * 13 = -1055.356...

[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2] -> 256
-> 2 + 2 = 4
  -> 4 - 2 = 2
    -> 2 * 2 = 4
      -> 4 / 2 = 2
        -> 2 ^ 2 = 4
          -> 4 + 2 = 6
            -> 6 - 2 = 4
              -> 4 * 2 = 8
                -> 8 / 2 = 4
                  -> 4 ^ 2 = 16
                    -> 16 + 2 = 18
                      -> 18 - 2 = 16
                        -> 16 * 2 = 32
                          -> 32 / 2 = 16
                            -> 16 ^ 2 = 256

[1,0,1,0,1,0] -> 1
-> 1 + 0 = 1
  -> 1 - 1 = 0
    -> 0 * 0 = 0
      -> 0 / 1 = 0
        -> 0 ^ 0 = 1

[-9,-8,-1] -> -16
  -> -9 + -8 = -17
    -> -17 - -1 = -16

[0,-3] -> -3
  -> 0 + -3 = -3

[-99] -> -99
</code>```

答:
CJam, 18 bytes

```<code>q~{"+-*/#"W):W=~}*
</code>```

Input is an array of floats. Try it online!

How it works

```<code>q~                  Read and evaluate all input.
  {             }*  Reduce:
   "+-*/#"            Push the string of operators.
          W           Push W (initially -1).
           ):W        Increment and save in W.
              =       Retrieve the character at that index.
               ~      Evaluate.
</code>```

Title: Weapons of Math Instruction

Body:
CJam, 18 bytes

q~{"+-*/#"W):W=~}*

Input is an array of floats. Try it online!

How it works

q~                  Read and evaluate all input.
  {             }*  Reduce:
   "+-*/#"            Push the string of operators.
          W           Push W (initially -1).
           ):W        Increment and save in W.
              =       Retrieve the character at that index.
               ~      Evaluate.


答:
Jolf, 10 bytes

```<code>ZlZd~Bx©{2
</code>```

Try it here!

Explanation

```<code>ZlZd~Bx©{2
    ~B     all numbers satisfying
       ©{  the prime condition ("the prime directive"?)
      x    below x
  Zd       (the differences between indices)
Zl       2 count the number of 2's
</code>```

Title: OMG! We're Twinning!

Body:
Introduction

We define twin primes as two natural numbers p,p+2 which both are prime.

Example: 5 and 7 are twin primes.

Let's define the twin number of some set of numbers as the number of twin prime numbers in that set

Example: {6,7,11,13,18,29,31} has a twin number 4, since there are four twin primes; 11,13 and 29,31.

Program

Input: A number n

Output: The twin number of the set of all natural numbers below n

Scoring

This is code-golf, so lowest bytes wins.

Body:
Jolf, 10 bytes

ZlZd~Bx©{2

Try it here!

Explanation

ZlZd~Bx©{2
    ~B     all numbers satisfying
       ©{  the prime condition ("the prime directive"?)
      x    below x
  Zd       (the differences between indices)
Zl       2 count the number of 2's


答:
Perl 6, <s> 54 </s> 53 bytes

<s>{2*(3..$_).rotor(3=>-1).grep: {all .[0,2]».is-prime}}</s>
{2*(3,5...$_).rotor(2=>-1).grep: {all $_».is-prime}}```

<h3>Explanation:</h3>

<pre class="lang-perl6 prettyprint-override"><code>{
  2
  *
  (3,5...$_)        # odd numbers
  .rotor( 2 => -1 ) # grab 2 then backup one, repeat
  .grep:            # find all that match the following
    {
      # create a Junction object of the following
      all

        # call .is-prime on both elements of the
        # list given to this inner block
        $_».is-prime
    }
}
</code>```

Title: OMG! We're Twinning!

Body:
Perl 6, <s> 54 </s> 53 bytes

<s>{2*(3..$_).rotor(3=>-1).grep: {all .[0,2]».is-prime}}</s>
{2*(3,5...$_).rotor(2=>-1).grep: {all $_».is-prime}}

Explanation:

{
  2
  *
  (3,5...$_)        # odd numbers
  .rotor( 2 => -1 ) # grab 2 then backup one, repeat
  .grep:            # find all that match the following
    {
      # create a Junction object of the following
      all

        # call .is-prime on both elements of the
        # list given to this inner block
        $_».is-prime
    }
}


问:
Is my emoji dry?
This is my pet emoji, Billy:

```<code>-_-
</code>```

Emojis don't like to be in the rain, so Billy is sad... Let's draw him an umbrella to make him feel better!

```<code>  /\
 /  \
/    \

  -_-
</code>```

This is good, he is entirely covered by his umbrella! Here is an example where only part of him is covered:

```<code>  /\
 /  \
/    \

     -_-
</code>```

In this case, sections 2 and 3 of his body are exposed to the rain.

Umbrellas come in many shapes and sizes, but they're always made up from a series of ascending slashes / followed by a series of descending backslashes \. For example, these are all valid umbrellas:

```<code>  /\
 /  \
/    \

/\

    /\
   /  \
  /    \
 /      \
/        \
</code>```

And these are not:

```<code>/   \

\/

  \
 / \
/   \

 0\
/  \

//\\
/  \
</code>```

You need to determine which parts of my emoji are exposed to the rain.

Clarifications

Your program (or function) will take a 2d string as input. This can be in whatever format is most convenient or natural to your language. An array of strings, an array of arrays of characters, a string with newlines in it etc.

You must output which sections of the emoji are exposed to the rain. This can be zero-indexed or one-indexed, as long as you make this clear. Output can be in any reasonable format. If the entire emoji is protected from the rain, output nothing (or an empty array).

You can assume that all inputs will have a valid umbrella, and the same emoji: -_-. The emoji will always be on the last line of the input, however their might be several empty lines between the umbrella and the emoji.

Everything that isn't part of the umbrella or the emoji will be a space   character or newline.

The input will be padded with spaces so that the length of each line is the same.

Standard loopholes apply, and the shortest answer in bytes wins!

Test IO:

All of the sample cases will use one-indexing.

```<code>  /\
 /  \
/    \

  -_-

Outputs: []

----------------

   /\
  /  \

     -_-

Outputs: [2, 3]

----------------

    /\
   -_-

Outputs: [1]

----------------

     /\
    /  \
   /    \
  /      \
 /        \
/          \

               -_-

Outputs: [1, 2, 3]
</code>```

Title: Is my emoji dry?

Body:
Python 2, <s>114</s> 111 bytes

def f(a):c=a.find("\n")+1;r=a.rfind;g=lambda i:([i],[])[r("\\")%c>=r("-")%c-2+i>=r("/")%c];print g(0)+g(1)+g(2)

Uses 0 based indexing.

Try it here.


问:
The Ever Amplifying Zigzag
Write a program or function that takes in a positive integer N and outputs the first N numbers of this amplifying zigzag pattern, using only the lines needed:

```<code>                                         26
                                       25  27                                      .
         10                          24      28                                  .
        9  11                      23          29                              .
 2     8     12                  22              30                          44
1 3   7        13              21                  31                      43
   4 6           14          20                      32                  42
    5              15      19                          33              41
                     16  18                              34          40
                       17                                  35      39
                                                             36  38
                                                               37
</code>```

So, if N is 1 the output is

```<code>1
</code>```

If N is 2, the output is

```<code> 2
1
</code>```

If N is 3 the output is

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

If N is 4 the output is

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

If N is 10 the output is

```<code>         10
        9
 2     8
1 3   7
   4 6
    5
</code>```

If N is 19 the output is

```<code>         10
        9  11
 2     8     12
1 3   7        13
   4 6           14
    5              15      19
                     16  18
                       17
</code>```

and so on.

Notes

Each peak or trough of the zigzag reaches its point one more line away from the line with the 1 on it than the previous peak or trough.

N is not limited to 44. The zigzag grows in the same pattern and larger N should be supported.

Numbers with multiple digits should only "touch" at their corners, as depicted. Make sure this works when N is 100 and above.

There should be no empty (or space only) lines in the output except one optional trailing newline.

Any line may have any amount of trailing spaces.

Scoring

The shortest code in bytes wins. Tiebreaker is earlier answer.

答:
PHP, <s>211</s> <s>177</s> <s>164</s> 163 bytes

Predict the peaks with $n and increase the array dynamically in either direction, using ($x, $y) output cursor.

Numbers are aligned with str_pad() and the final output is the implode() of that array of strings ($g).

```<code>for($x=0,$d=-1,$h=$n=2,$y=$a=1;$a<=$argv[1];$y+=$d){$g[$y]=str_pad($g[$y],$x).$a;$x+=strlen($a);if($a++==$n){$h+=2;$n+=$h-1;$d*=-1;}}ksort($g);echo implode(~õ,$g);
</code>```

Test it online!

Update: removed 34 bytes by getting rid of the unneeded array_pad().
Update2: followed @insertusernamehere's advice to shorten it a bit more.
Update3: followed @Lynn's advice to save one more byte with ~õ which imposes the use of LATIN-1 charset. (not available in online PHP emulator so not included there)

Title: The Ever Amplifying Zigzag

Body:
PHP, <s>211</s> <s>177</s> <s>164</s> 163 bytes

Predict the peaks with $n and increase the array dynamically in either direction, using ($x, $y) output cursor.

Numbers are aligned with str_pad() and the final output is the implode() of that array of strings ($g).

for($x=0,$d=-1,$h=$n=2,$y=$a=1;$a<=$argv[1];$y+=$d){$g[$y]=str_pad($g[$y],$x).$a;$x+=strlen($a);if($a++==$n){$h+=2;$n+=$h-1;$d*=-1;}}ksort($g);echo implode(~õ,$g);

Test it online!

Update: removed 34 bytes by getting rid of the unneeded array_pad().
Update2: followed @insertusernamehere's advice to shorten it a bit more.
Update3: followed @Lynn's advice to save one more byte with ~õ which imposes the use of LATIN-1 charset. (not available in online PHP emulator so not included there)


问:
Denominator of harmonic series
Earlier, we did the pseudofactorial of a number, which is the LCM of the numbers from 1 to n.

It would be useful in adding fractions together.

However, we find that the denominator of 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 is 20 instead of the pseudofactorial of 6, which is 60.

Your task is to find the denominator of 1/1 + 1/2 + ... + 1/n given positive integer n.

Testcases

```<code> n result
 1 1
 2 2
 3 6
 4 12
 5 60
 6 20
 7 140
 8 280
 9 2520
10 2520
11 27720
12 27720
13 360360
14 360360
15 360360
16 720720
17 12252240
18 4084080
19 77597520
20 15519504
21 5173168
22 5173168
23 118982864
24 356948592
25 8923714800
26 8923714800
27 80313433200
28 80313433200
29 2329089562800
30 2329089562800
</code>```

List for n from 1 to 200.

List for n from 1 to 1000.

List for n from 1 to 10000.

References

Obligatory OEIS A002805 (thanks to @FryAmTheEggman)

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Python 2, <s>69</s> 67 bytes

a=b=k=r=1
exec'a=a*k+b;b*=k;k+=1;'*input()
while r*a%b:r+=1
print r
```

<p>Test it on Ideone.</p>

<h3>How it works</h3>

<p>Let <strong>H(n)</strong> be the sum of the multiplicative inverses of the first <strong>n</strong> positive integers. At all times, we have that <strong>a / b = 1 + H(k - 1)</strong>. In fact, <strong>a</strong>, <strong>b</strong>, and <strong>k</strong> are all initialized to <strong>1</strong>, and <strong>1 / 1 = 1 = 1 + H(0)</strong>.</p>

<p>We repeat the code snippet</p>

<pre class="lang-python prettyprint-override"><code>a=a*k+b;b*=k;k+=1;
</code>```

(as a string) n (input) times and execute the result. In each step, we update a, b, and k using the identity a / b + 1 / k = ak / bk + b / bk = (ak + b) / bk.

After all copies have been executed, a / b = 1 + H(n), which has the same denominator as H(n).

The fully reduced form of a / b is (a ÷ gcd(a,b)) / (b ÷ gcd(a,b)). Instead of calculating the greatest common divisor, we initialize r as 1 and keep incrementing r until ra is a multiple of b.

Clearly, this makes ra the least common multiple of a and b. Since gcd(a,b) · lcm(a,b) = ab, we have that b ÷ gcd(a,b) = lcm(a,b) ÷ a = ra ÷ a = r, making r the desired output.

Title: Denominator of harmonic series

Body:
Python 2, <s>69</s> 67 bytes

a=b=k=r=1
exec'a=a*k+b;b*=k;k+=1;'*input()
while r*a%b:r+=1
print r

Test it on Ideone.

How it works

Let H(n) be the sum of the multiplicative inverses of the first n positive integers. At all times, we have that a / b = 1 + H(k - 1). In fact, a, b, and k are all initialized to 1, and 1 / 1 = 1 = 1 + H(0).

We repeat the code snippet

a=a*k+b;b*=k;k+=1;

(as a string) n (input) times and execute the result. In each step, we update a, b, and k using the identity a / b + 1 / k = ak / bk + b / bk = (ak + b) / bk.

After all copies have been executed, a / b = 1 + H(n), which has the same denominator as H(n).

The fully reduced form of a / b is (a ÷ gcd(a,b)) / (b ÷ gcd(a,b)). Instead of calculating the greatest common divisor, we initialize r as 1 and keep incrementing r until ra is a multiple of b.

Clearly, this makes ra the least common multiple of a and b. Since gcd(a,b) · lcm(a,b) = ab, we have that b ÷ gcd(a,b) = lcm(a,b) ÷ a = ra ÷ a = r, making r the desired output.


答:
Ruby, 43 + 8 (-rprime flag) = 51 bytes

```<code>->n{Prime.each(n-1).count{|i|(i-2).prime?}}
</code>```

Title: OMG! We're Twinning!

Body:
Ruby, 43 + 8 (-rprime flag) = 51 bytes

->n{Prime.each(n-1).count{|i|(i-2).prime?}}


问:
Excludivisible numbers
Given an integer N, output the Nth positive number K with the following property in decimal base:

For each digit I at position P of K, the number formed from K by removing the Pth digit (i.e. I) is divisible by I.

Example and remarks

324 is such a number:

3 divides 24

2 divides 34

4 divides 32

Note 1: we assume that the empty number is divisible by anything, like 0. Therefore 1, 2, 3, 4, 5, 6, 7, 8 and 9 are valid.

Note 2: K cannot contain the digit 0, since you cannot divide by 0.

Inputs and outputs

You may take the input as a function argument, through STDIN, etc.

You may return the output from a function, through STDOUT, etc.

You may index those numbers starting from 0 (in which case N >= 0) or from 1 (in which case N > 0), whichever suits you more.

Test cases

Those examples are indexed from 0, so if you indexed from 1, then add 1 to the numbers in the N column.

```<code>N    Output
0    1
4    5
8    9
15   77
16   88
23   155
42   742
47   1113
121  4244
144  6888
164  9999
</code>```

Scoring

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

答:
Pyth, 26 bytes

```<code>e.f&!/J`Z\0!s%VsM.DLJUJjZT
</code>```

Test suite.

```<code>e.f&!/J`Z\0!s%VsM.DLJUJjZT
e.f                          The n-th number (Z) where:
    !/J`Z\0                      Z does not contain "0"
   &                             and
           !s                    the following does not contain zero:
               sM.DLJUJ              generate the set of the digits removed
                       jZT           all the digits
             %V                      modulus in parallel
                                     if Z is 324,
                                     the first set would be [24,34,32]
                                     the second set would be [3,2,4]
                                     the third set would be [24%3, 34%2, 32%4]
</code>```

Title: Excludivisible numbers

Body:
Pyth, 26 bytes

e.f&!/J`Z\0!s%VsM.DLJUJjZT

Test suite.

e.f&!/J`Z\0!s%VsM.DLJUJjZT
e.f                          The n-th number (Z) where:
    !/J`Z\0                      Z does not contain "0"
   &                             and
           !s                    the following does not contain zero:
               sM.DLJUJ              generate the set of the digits removed
                       jZT           all the digits
             %V                      modulus in parallel
                                     if Z is 324,
                                     the first set would be [24,34,32]
                                     the second set would be [3,2,4]
                                     the third set would be [24%3, 34%2, 32%4]


答:
Jelly, <s>41</s> <s>37</s> 29 bytes

```<code>RDµḌ’½Ċ-*_\x©L€Ṣ.ị®ạ€⁶ẋj"FZj⁷
</code>```

Try it online!

How it works

```<code>RDµḌ’½Ċ-*_\x©L€Ṣ.ị®ạ€⁶ẋj"FZj⁷  Main link. Argument: n (integer)

R                              Range; yield [1, ..., n].
 D                             Decimal; yield A =: [[1], ..., [1, 0], ...].
  µ                            Begin a new, monadic chain. Argument: A
   Ḍ                           Undecimal; convert back to falt range.
    ’                          Decrement to yield [0, ..., n-1].
     ½Ċ                        Take the square root and round up (ceil).
       -*                      Elevate -1 to each rounded square root.
         _\                    Cumulatively reduce by subtraction.
                               This yields [1, 2, 1, 0, -1, 0, ...], i.e., the
                               vertical positions of the digits in A.
             L€                Compute the length of each list in A.
           x                   Repeat the nth position l times, where l is the
                               nth length.
            ©                  Copy the result to the register.
               Ṣ               Sort.
                .ị             At-index 0.5; yield the last and first element,
                               which correspond to the highest and lowest position.
                  ạ€®          Take the absolute difference of each position in the
                               register and the extrema.
                               This yields the number of spaces above and below
                               the integers in r as a list of pairs.
                     ⁶ẋ        Replace each difference with that many spaces.
                         F     Flatten the list A.
                       j"      Join the nth pair of strings of spacing, separating
                               by the nth digit in flat A.
                          Z    Zip/transpose the result.
                           j⁷  Join, separating by linefeeds.
</code>```

Title: The Ever Amplifying Zigzag

Body:
Write a program or function that takes in a positive integer N and outputs the first N numbers of this amplifying zigzag pattern, using only the lines needed:

```<code>                                         26
                                       25  27                                      .
         10                          24      28                                  .
        9  11                      23          29                              .
 2     8     12                  22              30                          44
1 3   7        13              21                  31                      43
   4 6           14          20                      32                  42
    5              15      19                          33              41
                     16  18                              34          40
                       17                                  35      39
                                                             36  38
                                                               37
</code>```

So, if N is 1 the output is

```<code>1
</code>```

If N is 2, the output is

```<code> 2
1
</code>```

If N is 3 the output is

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

If N is 4 the output is

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

If N is 10 the output is

```<code>         10
        9
 2     8
1 3   7
   4 6
    5
</code>```

If N is 19 the output is

```<code>         10
        9  11
 2     8     12
1 3   7        13
   4 6           14
    5              15      19
                     16  18
                       17
</code>```

and so on.

Notes

Each peak or trough of the zigzag reaches its point one more line away from the line with the 1 on it than the previous peak or trough.

N is not limited to 44. The zigzag grows in the same pattern and larger N should be supported.

Numbers with multiple digits should only "touch" at their corners, as depicted. Make sure this works when N is 100 and above.

There should be no empty (or space only) lines in the output except one optional trailing newline.

Any line may have any amount of trailing spaces.

Scoring

The shortest code in bytes wins. Tiebreaker is earlier answer.

Body:
Jelly, <s>41</s> <s>37</s> 29 bytes

RDµḌ’½Ċ-*_\x©L€Ṣ.ị®ạ€⁶ẋj"FZj⁷

Try it online!

How it works

RDµḌ’½Ċ-*_\x©L€Ṣ.ị®ạ€⁶ẋj"FZj⁷  Main link. Argument: n (integer)

R                              Range; yield [1, ..., n].
 D                             Decimal; yield A =: [[1], ..., [1, 0], ...].
  µ                            Begin a new, monadic chain. Argument: A
   Ḍ                           Undecimal; convert back to falt range.
    ’                          Decrement to yield [0, ..., n-1].
     ½Ċ                        Take the square root and round up (ceil).
       -*                      Elevate -1 to each rounded square root.
         _\                    Cumulatively reduce by subtraction.
                               This yields [1, 2, 1, 0, -1, 0, ...], i.e., the
                               vertical positions of the digits in A.
             L€                Compute the length of each list in A.
           x                   Repeat the nth position l times, where l is the
                               nth length.
            ©                  Copy the result to the register.
               Ṣ               Sort.
                .ị             At-index 0.5; yield the last and first element,
                               which correspond to the highest and lowest position.
                  ạ€®          Take the absolute difference of each position in the
                               register and the extrema.
                               This yields the number of spaces above and below
                               the integers in r as a list of pairs.
                     ⁶ẋ        Replace each difference with that many spaces.
                         F     Flatten the list A.
                       j"      Join the nth pair of strings of spacing, separating
                               by the nth digit in flat A.
                          Z    Zip/transpose the result.
                           j⁷  Join, separating by linefeeds.


Title: Excludivisible numbers

Body:
Given an integer N, output the Nth positive number K with the following property in decimal base:

For each digit I at position P of K, the number formed from K by removing the Pth digit (i.e. I) is divisible by I.

Example and remarks

324 is such a number:

3 divides 24

2 divides 34

4 divides 32

Note 1: we assume that the empty number is divisible by anything, like 0. Therefore 1, 2, 3, 4, 5, 6, 7, 8 and 9 are valid.

Note 2: K cannot contain the digit 0, since you cannot divide by 0.

Inputs and outputs

You may take the input as a function argument, through STDIN, etc.

You may return the output from a function, through STDOUT, etc.

You may index those numbers starting from 0 (in which case N >= 0) or from 1 (in which case N > 0), whichever suits you more.

Test cases

Those examples are indexed from 0, so if you indexed from 1, then add 1 to the numbers in the N column.

```<code>N    Output
0    1
4    5
8    9
15   77
16   88
23   155
42   742
47   1113
121  4244
144  6888
164  9999
</code>```

Scoring

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

Body:
Ruby, 109 bytes

->n{i=s=1;n.times{s=?0;s="#{i+=1}"while s[?0]||(0...x=s.size).any?{|i|(s[0,i]+s[i+1,x]).to_i%s[i].to_i>0}};s}


答:
Jelly, <s>21</s> 19 bytes

```<code>DLR©œ^€®ịDḌḍ@DPȧµ#Ṫ
</code>```

Input is 1-indexed. Try it online!

How it works

```<code>DLR©œ^€®ịDḌḍ@DPȧµ#Ṫ  Main link. No arguments.

                µ    Convert the chain to the left into a link.
                 #   Read n from STDIN and execute the link to the left for
                     k = 0, 1, 2, ... until n value return a truthy value.
D                      Convert D to base 10 (digit array).
 LR                    Construct the range from 1 to the length of the digit array.
   ©                   Copy the range to the register.
       ®               Yield the value of the register.
    œ^€                Take the multiset difference of each element of the range
                       and the range itself.
        ịD             Index into the digit array.
          Ḍ            Convert each list of digits to integer.
                       This yields all numbers with one suppressed digit.
           ḍ@D         Test each of these numbers for divisibility by the
                       suppressed digit from the digit array.
              P        Take the product of the resulting Booleans.
               ȧ       Logical AND with k (k would return 1).
                  Ṫ  Tail; extract the last (nth) element.
</code>```

Title: Excludivisible numbers

Body:
Jelly, <s>21</s> 19 bytes

DLR©œ^€®ịDḌḍ@DPȧµ#Ṫ

Input is 1-indexed. Try it online!

How it works

DLR©œ^€®ịDḌḍ@DPȧµ#Ṫ  Main link. No arguments.

                µ    Convert the chain to the left into a link.
                 #   Read n from STDIN and execute the link to the left for
                     k = 0, 1, 2, ... until n value return a truthy value.
D                      Convert D to base 10 (digit array).
 LR                    Construct the range from 1 to the length of the digit array.
   ©                   Copy the range to the register.
       ®               Yield the value of the register.
    œ^€                Take the multiset difference of each element of the range
                       and the range itself.
        ịD             Index into the digit array.
          Ḍ            Convert each list of digits to integer.
                       This yields all numbers with one suppressed digit.
           ḍ@D         Test each of these numbers for divisibility by the
                       suppressed digit from the digit array.
              P        Take the product of the resulting Booleans.
               ȧ       Logical AND with k (k would return 1).
                  Ṫ  Tail; extract the last (nth) element.


答:
Julia, <s>219</s> <s>182</s> <s>169</s> 167 bytes

!n=(~j=j%n<1;k(v=j->"---",c=+,s="$c\e[m";l=~)=println([(l(j)?"\e[;;41m$c":s)v(j)for j=10i+(1:10)]...,s);i=0;k();for i=0:9 k(j->lpad(j,3),|);k(l=j->~j|~(j+10(i<9)))end)
```

<p>Used like this: <code>!7</code></p>

<p>Ungolfed:</p>

<pre class="lang-julia prettyprint-override"><code>function !(n::Integer)
     for j=(1:10)     #This loop generates the top of the box
       if (j%n==0)
         print("\e[;;41m+---") #"\e[;;41m" is the ANSI escape code
                               #for red background colour in Julia
       else
         print("+\e[m---")     #"\e[m" resets to original colours
       end
     end
     println("+\e[m")
     for i=0:9
       for j=10i+(1:10)  #This loop generates the rows with the numbers
         if (j%n==0)
           print("\e[;;41m|",lpad(j,3))
         else
           print("|\e[m",lpad(j,3))
         end
       end
       println("|\e[m")
       for j=10i+(1:10)  #This loop generates the other rows
         if (j%n==0)||((j+10)%n==0&&i<9)
           print("\e[;;41m+---")
         else
           print("+\e[m---")
         end
       end
       println("+\e[m")
     end
   end
</code>```

Note that this is very ungolfed, for maximal readability.

Title: A Hundred Squares!

Body:
Back to basics...

As a teacher at the local primary (grade?) school, you need a way to teach your class their times tables. At your disposal, you have hundred squares and a load of red pens. You need to also be able to show your class the correct answers quickly.

Now, you're clever enough to write a program that can do times tables, but can you draw them on a hundred square?

The challenge

Output a hundred square to stdout or equivalent using ansi-escape codes to shade in numbers which are multiples of the input.

Output a 10x10 grid containing the numbers 1-100.

It doesn't matter the alignment of 2 digit numbers in each box as long as it's consistant

For 1 digit numbers, you may pad to 2 digits and use the same formatting as 2 digit numbers or centered in the middle of the box.

If the number in the box is a multiple of the input, colour the entire box red.

This means the whole box, not just the number part

For example, given the input 3, print the given hundred square

This is code golf so the shortest answer in bytes wins!

Body:
Julia, <s>219</s> <s>182</s> <s>169</s> 167 bytes

!n=(~j=j%n<1;k(v=j->"---",c=+,s="$c\e[m";l=~)=println([(l(j)?"\e[;;41m$c":s)v(j)for j=10i+(1:10)]...,s);i=0;k();for i=0:9 k(j->lpad(j,3),|);k(l=j->~j|~(j+10(i<9)))end)

Used like this: !7

Ungolfed:

function !(n::Integer)
     for j=(1:10)     #This loop generates the top of the box
       if (j%n==0)
         print("\e[;;41m+---") #"\e[;;41m" is the ANSI escape code
                               #for red background colour in Julia
       else
         print("+\e[m---")     #"\e[m" resets to original colours
       end
     end
     println("+\e[m")
     for i=0:9
       for j=10i+(1:10)  #This loop generates the rows with the numbers
         if (j%n==0)
           print("\e[;;41m|",lpad(j,3))
         else
           print("|\e[m",lpad(j,3))
         end
       end
       println("|\e[m")
       for j=10i+(1:10)  #This loop generates the other rows
         if (j%n==0)||((j+10)%n==0&&i<9)
           print("\e[;;41m+---")
         else
           print("+\e[m---")
         end
       end
       println("+\e[m")
     end
   end

Note that this is very ungolfed, for maximal readability.


答:
APL (Dyalog Unicode), <s>29</s> 27 bytesSBCS

Anomymous tacit prefix function. Note that * is exponentiation in APL.

≢{⍎3↓⍕⌽⍵,¨⍨⍺⍴'+-×÷*',¨'⍨'}⊢
```

Try it online!

Because APL executes right to left, we can just reverse the order of arguments of the inserted operations and reverse the entire expression. Postfix ⍨ reverses arguments. After doing a perfect shuffle of numbers and operations, we only just need to reverse, flatten, and evaluate:

≢{…}⊢ call the following function with count of and actual numbers as ⍺ and ⍵:

 '⍨' this character

 '+-×÷*',¨ prepend each of these characters to that; ["+⍨","-⍨","×⍨","÷⍨","*⍨"]

 ⍺⍴ use the left argument (count of numbers) to cyclically reshape that

 ⌽ reverse

 ⍕ format as flat string

 3↓ drop leading 3 characters (a space and a symbol and ⍨)

 ⍎ execute as APL code

Title: Weapons of Math Instruction

Body:
Last time when I tried to come up with something easy that wasn't a duplicate, it ended up being way too hard.. So hopefully this time it's indeed something newcomers can try as well.

Input:

An array/list with integers/decimals. (Or a string representing an array with integers/decimals.)

Output:

Loop through the numbers and apply the following five mathematical operands in this order:

Addition (+);

Subtraction (−);

Multiplication (* or × or ·);

Real / Calculator Division (/ or ÷);

Exponentiation (^ or **).

(NOTE: The symbols between parenthesis are just added as clarification. If your programming language uses a completely different symbol for the mathematical operation than the examples, then that is of course completely acceptable.)

Keep continuing until you've reached the end of the list, and then give the result of the sum.

Challenge rules:

Exponentiation by 0 (n ^ 0) should result in 1 (this also applies to 0 ^ 0 = 1).

There are no test cases for division by 0 (n / 0), so you don't have to worry about that edge-case.

If the array contains just a single number, we return that as the result.

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Test cases:

```<code>[1,2,3,4,5] -> 0
-> 1 + 2 = 3
  -> 3 - 3 = 0
    -> 0 * 4 = 0
      -> 0 / 5 = 0

[5,12,23,2,4,4,2,6,7] -> 539
-> 5 + 12 = 17
  -> 17 - 23 = -6
    -> -6 * 2 = -12
      -> -12 / 4 = -3
        -> -3 ^ 4 = 81
          -> 81 + 2 = 83
            -> 83 - 6 = 77
              -> 77 * 7 -> 539

[-8,50,3,3,-123,4,17,99,13] -> -1055.356...
-> -8 + 50 = 42
  -> 42 - 3 = 39
    -> 39 * 3 = 117
      -> 117 / -123 = -0.9512...
        -> -0.9512... ^ 4 = 0.818...
          -> 0.818... + 17 = 17.818...
            -> 17.818... - 99 -> -81.181...
              -> -81.181... * 13 = -1055.356...

[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2] -> 256
-> 2 + 2 = 4
  -> 4 - 2 = 2
    -> 2 * 2 = 4
      -> 4 / 2 = 2
        -> 2 ^ 2 = 4
          -> 4 + 2 = 6
            -> 6 - 2 = 4
              -> 4 * 2 = 8
                -> 8 / 2 = 4
                  -> 4 ^ 2 = 16
                    -> 16 + 2 = 18
                      -> 18 - 2 = 16
                        -> 16 * 2 = 32
                          -> 32 / 2 = 16
                            -> 16 ^ 2 = 256

[1,0,1,0,1,0] -> 1
-> 1 + 0 = 1
  -> 1 - 1 = 0
    -> 0 * 0 = 0
      -> 0 / 1 = 0
        -> 0 ^ 0 = 1

[-9,-8,-1] -> -16
  -> -9 + -8 = -17
    -> -17 - -1 = -16

[0,-3] -> -3
  -> 0 + -3 = -3

[-99] -> -99
</code>```

Body:
APL (Dyalog Unicode), <s>29</s> 27 bytesSBCS

Anomymous tacit prefix function. Note that * is exponentiation in APL.

≢{⍎3↓⍕⌽⍵,¨⍨⍺⍴'+-×÷*',¨'⍨'}⊢

Try it online!

Because APL executes right to left, we can just reverse the order of arguments of the inserted operations and reverse the entire expression. Postfix ⍨ reverses arguments. After doing a perfect shuffle of numbers and operations, we only just need to reverse, flatten, and evaluate:

≢{…}⊢ call the following function with count of and actual numbers as ⍺ and ⍵:

 '⍨' this character

 '+-×÷*',¨ prepend each of these characters to that; ["+⍨","-⍨","×⍨","÷⍨","*⍨"]

 ⍺⍴ use the left argument (count of numbers) to cyclically reshape that

 ⌽ reverse

 ⍕ format as flat string

 3↓ drop leading 3 characters (a space and a symbol and ⍨)

 ⍎ execute as APL code

ContentLicense: CC BY-SA 4.0


问:
Define a field with 256 elements
A field in mathematics is a set of numbers, with addition and multiplication operations defined on it, such that they satisfy certain axioms (described in Wikipedia; see also below).

A finite field can have pn elements, where p is a prime number, and n is a natural number. In this challenge, let's take p = 2 and n = 8, so let's make a field with 256 elements.

The elements of the field should be consecutive integers in a range that contains 0 and 1:

-128 ... 127

0 ... 255

or any other such range

Define two functions (or programs, if that is easier), a(x,y) for abstract "addition", and m(x,y) for abstract "multiplication", such that they satisfy the field axioms:

Consistency: a(x,y) and m(x,y) produce the same result when called with same arguments

Closedness: The result of a and m is an integer in the relevant range

Associativity: for any x, y and z in the range, a(a(x,y),z) is equal to a(x,a(y,z)); the same for m

Commutativity: for any x and y in the range, a(x,y) is equal to a(y,x); the same for m

Distributivity: for any x, y and z in the range, m(x,a(y,z)) is equal to a(m(x,y),m(x,z))

Neutral elements: for any x in the range, a(0,x) is equal to x, and m(1,x) is equal to x

Negation: for any x in the range, there exists such y that a(x,y) is 0

Inverse: for any x≠0 in the range, there exists such y that m(x,y) is 1

The names a and m are just examples; you can use other names, or unnamed functions. The score of your answer is the sum of byte-lengths for a and m.

If you use a built-in function, please also describe in words which result it produces (e.g. provide a multiplication table).

答:
Python 2, 11 + 45 = 56 bytes

Addition (11 bytes):

int.__xor__
```

<p><strong>Multiplication</strong> (45 bytes):</p>

<pre class="lang-py prettyprint-override"><code>m=lambda x,y:y and m(x*2^x/128*283,y/2)^y%2*x
</code>```

Takes input numbers in the range [0 ... 255]. Addition is just bitwise XOR, multiplication is multiplication of polynomials with coefficients in GF2 with Russian peasant.

And for checking:

a=int.__xor__
m=lambda x,y:y and m(x*2^x/128*283,y/2)^y%2*x

for x in range(256):
    assert a(0,x) == a(x,0) == x
    assert m(1,x) == m(x,1) == x

    assert any(a(x,y) == 0 for y in range(256))

    if x != 0:
        assert any(m(x,y) == 1 for y in range(256))

    for y in range(256):
        assert 0 <= a(x,y) < 256
        assert 0 <= m(x,y) < 256
        assert a(x,y) == a(y,x)
        assert m(x,y) == m(y,x)

        for z in range(256):
            assert a(a(x,y),z) == a(x,a(y,z))
            assert m(m(x,y),z) == m(x,m(y,z))
            assert m(x,a(y,z)) == a(m(x,y), m(x,z))
```

Title: Define a field with 256 elements

Body:
Python 2, 11 + 45 = 56 bytes

Addition (11 bytes):

int.__xor__

Multiplication (45 bytes):

m=lambda x,y:y and m(x*2^x/128*283,y/2)^y%2*x

Takes input numbers in the range [0 ... 255]. Addition is just bitwise XOR, multiplication is multiplication of polynomials with coefficients in GF2 with Russian peasant.

And for checking:

a=int.__xor__
m=lambda x,y:y and m(x*2^x/128*283,y/2)^y%2*x

for x in range(256):
    assert a(0,x) == a(x,0) == x
    assert m(1,x) == m(x,1) == x

    assert any(a(x,y) == 0 for y in range(256))

    if x != 0:
        assert any(m(x,y) == 1 for y in range(256))

    for y in range(256):
        assert 0 <= a(x,y) < 256
        assert 0 <= m(x,y) < 256
        assert a(x,y) == a(y,x)
        assert m(x,y) == m(y,x)

        for z in range(256):
            assert a(a(x,y),z) == a(x,a(y,z))
            assert m(m(x,y),z) == m(x,m(y,z))
            assert m(x,a(y,z)) == a(m(x,y), m(x,z))


Title: Define a field with 256 elements

Body:
A field in mathematics is a set of numbers, with addition and multiplication operations defined on it, such that they satisfy certain axioms (described in Wikipedia; see also below).

A finite field can have pn elements, where p is a prime number, and n is a natural number. In this challenge, let's take p = 2 and n = 8, so let's make a field with 256 elements.

The elements of the field should be consecutive integers in a range that contains 0 and 1:

-128 ... 127

0 ... 255

or any other such range

Define two functions (or programs, if that is easier), a(x,y) for abstract "addition", and m(x,y) for abstract "multiplication", such that they satisfy the field axioms:

Consistency: a(x,y) and m(x,y) produce the same result when called with same arguments

Closedness: The result of a and m is an integer in the relevant range

Associativity: for any x, y and z in the range, a(a(x,y),z) is equal to a(x,a(y,z)); the same for m

Commutativity: for any x and y in the range, a(x,y) is equal to a(y,x); the same for m

Distributivity: for any x, y and z in the range, m(x,a(y,z)) is equal to a(m(x,y),m(x,z))

Neutral elements: for any x in the range, a(0,x) is equal to x, and m(1,x) is equal to x

Negation: for any x in the range, there exists such y that a(x,y) is 0

Inverse: for any x≠0 in the range, there exists such y that m(x,y) is 1

The names a and m are just examples; you can use other names, or unnamed functions. The score of your answer is the sum of byte-lengths for a and m.

If you use a built-in function, please also describe in words which result it produces (e.g. provide a multiplication table).

Body:
JavaScript (ES6), 10 + 49 = 59 bytes

a=(x,y)=>x^y
m=(x,y,p=0)=>x?m(x>>1,2*y^283*(y>>7),p^y*(x&1)):p

Domain is 0 ... 255. Source.


问:
Calculate the relativistic velocity
In special relativity, the velocity of a moving object relative to another object that is moving in the opposite direction is given by the formula:

\begin{align}s = \frac{v+u}{1+vu/c^2}.\end{align}

```<code>s = ( v + u ) / ( 1 + v * u / c ^ 2)
</code>```

In this formula, \$v\$ and \$u\$ are the magnitudes of the velocities of the objects, and \$c\$ is the speed of light (which is approximately \$3.0 \times 10^8 \,\mathrm m/\mathrm s\$, a close enough approximation for this challenge).

For example, if one object was moving at v = 50,000 m/s, and another object was moving at u = 60,000 m/s, the velocity of each object relative to the other would be approximately s = 110,000 m/s. This is what you would expect under Galilean relativity (where velocities simply add). However, if v = 50,000,000 m/s and u = 60,000,000 m/s, the relative velocity would be approximately 106,451,613 m/s, which is significantly different than the 110,000,000 m/s predicted by Galilean relativity.

The Challenge

Given two integers v and u such that 0 <= v,u < c, calculate the relativistic additive velocity, using the above formula, with c = 300000000. Output must be either a decimal value or a reduced fraction. The output must be within 0.001 of the actual value for a decimal value, or exact for a fraction.

Test Cases

Format: v, u -> exact fraction (float approximation)

```<code>50000, 60000 -> 3300000000000/30000001 (109999.99633333346)
50000000, 60000000 -> 3300000000/31 (106451612.90322581)
20, 30 -> 7500000000000000/150000000000001 (49.999999999999666)
0, 20051 -> 20051 (20051.0)
299999999, 299999999 -> 53999999820000000000000000/179999999400000001 (300000000.0)
20000, 2000000 -> 4545000000000/2250001 (2019999.1022226212)
2000000, 2000000 -> 90000000000/22501 (3999822.2301231055)
1, 500000 -> 90000180000000000/180000000001 (500000.9999972222)
1, 50000000 -> 90000001800000000/1800000001 (50000000.972222224)
200000000, 100000000 -> 2700000000/11 (245454545.45454547)
</code>```

答:
Pyth, 14 bytes

```<code>csQhc*FQ*9^T16
</code>```

Test suite.

Formula: sum(input) / (1 + (product(input) / 9e16))

Bonus: click here!

Title: Calculate the relativistic velocity

Body:
Pyth, 14 bytes

csQhc*FQ*9^T16

Test suite.

Formula: sum(input) / (1 + (product(input) / 9e16))

Bonus: click here!


答:
Javascript 24 bytes

Shaved off 4 bytes thanks to @LeakyNun

```<code>v=>u=>(v+u)/(1+v*u/9e16)
</code>```

Pretty straightforward

Title: Calculate the relativistic velocity

Body:
In special relativity, the velocity of a moving object relative to another object that is moving in the opposite direction is given by the formula:

\begin{align}s = \frac{v+u}{1+vu/c^2}.\end{align}

```<code>s = ( v + u ) / ( 1 + v * u / c ^ 2)
</code>```

In this formula, \$v\$ and \$u\$ are the magnitudes of the velocities of the objects, and \$c\$ is the speed of light (which is approximately \$3.0 \times 10^8 \,\mathrm m/\mathrm s\$, a close enough approximation for this challenge).

For example, if one object was moving at v = 50,000 m/s, and another object was moving at u = 60,000 m/s, the velocity of each object relative to the other would be approximately s = 110,000 m/s. This is what you would expect under Galilean relativity (where velocities simply add). However, if v = 50,000,000 m/s and u = 60,000,000 m/s, the relative velocity would be approximately 106,451,613 m/s, which is significantly different than the 110,000,000 m/s predicted by Galilean relativity.

The Challenge

Given two integers v and u such that 0 <= v,u < c, calculate the relativistic additive velocity, using the above formula, with c = 300000000. Output must be either a decimal value or a reduced fraction. The output must be within 0.001 of the actual value for a decimal value, or exact for a fraction.

Test Cases

Format: v, u -> exact fraction (float approximation)

```<code>50000, 60000 -> 3300000000000/30000001 (109999.99633333346)
50000000, 60000000 -> 3300000000/31 (106451612.90322581)
20, 30 -> 7500000000000000/150000000000001 (49.999999999999666)
0, 20051 -> 20051 (20051.0)
299999999, 299999999 -> 53999999820000000000000000/179999999400000001 (300000000.0)
20000, 2000000 -> 4545000000000/2250001 (2019999.1022226212)
2000000, 2000000 -> 90000000000/22501 (3999822.2301231055)
1, 500000 -> 90000180000000000/180000000001 (500000.9999972222)
1, 50000000 -> 90000001800000000/1800000001 (50000000.972222224)
200000000, 100000000 -> 2700000000/11 (245454545.45454547)
</code>```

Body:
Javascript 24 bytes

Shaved off 4 bytes thanks to @LeakyNun

v=>u=>(v+u)/(1+v*u/9e16)

Pretty straightforward


答:
Pyke, 12 bytes

```<code>sQB9T16^*/h/
</code>```

Try it here!

Title: Calculate the relativistic velocity

Body:
Pyke, 12 bytes

sQB9T16^*/h/

Try it here!


答:
Matlab - 95 91 85 bytes / Octave - 81 bytes

Input is in such form: a = ['1' '2' '3' '4' '5'];, I hope this is covered by "string representing an array with integers/decimals", else there are 2 num2str needed additionally.

Every intermediate result gets printed to console because that saves me some semicolons. a(1) is executed so its value is then saved to ans. Also of course using ans in code is bad practice.

```<code>b='+-*/^'
a(1)
for i=2:length(a)
  ['(',ans,')',b(mod(i-2,5)+1),a(i)]
end
eval(ans)
</code>```

In Octave, '+-*/^'(mod(i+2,5)+1) also works, which saves another 4 bytes, thanks Adám and Luis Mendo:

```<code>a(1)
for i=2:length(a)
  strcat('(',ans,')','+-*/^'(mod(i-2,5)+1),a(i))
end
eval(ans)
</code>```

Changelog:

Removed spaces where possible

added Octave solution

replaced strcat() with []

Title: Weapons of Math Instruction

Body:
Matlab - 95 91 85 bytes / Octave - 81 bytes

Input is in such form: a = ['1' '2' '3' '4' '5'];, I hope this is covered by "string representing an array with integers/decimals", else there are 2 num2str needed additionally.

Every intermediate result gets printed to console because that saves me some semicolons. a(1) is executed so its value is then saved to ans. Also of course using ans in code is bad practice.

b='+-*/^'
a(1)
for i=2:length(a)
  ['(',ans,')',b(mod(i-2,5)+1),a(i)]
end
eval(ans)

In Octave, '+-*/^'(mod(i+2,5)+1) also works, which saves another 4 bytes, thanks Adám and Luis Mendo:

a(1)
for i=2:length(a)
  strcat('(',ans,')','+-*/^'(mod(i-2,5)+1),a(i))
end
eval(ans)

Changelog:

Removed spaces where possible

added Octave solution

replaced strcat() with []


答:
MATL, 9 bytes

```<code>sG3e8/pQ/
</code>```

Try it online!

```<code>s      % Take array [u, v] implicitly. Compute its sum: u+v
G      % Push [u, v] again
3e8    % Push 3e8
/      % Divide. Gives [u/c, v/c]
p      % Product of array. Gives u*v/c^2
Q      % Add 1
/      % Divide. Display implicitly
</code>```

Title: Calculate the relativistic velocity

Body:
MATL, 9 bytes

sG3e8/pQ/

Try it online!

s      % Take array [u, v] implicitly. Compute its sum: u+v
G      % Push [u, v] again
3e8    % Push 3e8
/      % Divide. Gives [u/c, v/c]
p      % Product of array. Gives u*v/c^2
Q      % Add 1
/      % Divide. Display implicitly


答:
JavaScript (ES6), <s>82</s> <s>78</s> 76 bytes

```<code>f=(n,k=0)=>n?f(n-!eval(/0/.test(++k)+`${k}`.replace(/./g,"|'$`$''%$&")),k):k
</code>```

Input is 1-indexed. Works by building up a string of the form false|'24'%3|'34'%2|'32'%4 and evaluating it. Strings are used because they are still syntactically valid in the single-digit case.

The recursion limits this to about n=119. Iterative version for <s>88</s> <s>84</s> 82 bytes:

```<code>n=>{for(k=0;n;n-=!eval(/0/.test(++k)+`${k}`.replace(/./g,"|'$`$''%$&")));return l}
</code>```

Edit: Saved 2 bytes thanks to @Dennis♦.

Title: Excludivisible numbers

Body:
JavaScript (ES6), <s>82</s> <s>78</s> 76 bytes

f=(n,k=0)=>n?f(n-!eval(/0/.test(++k)+`${k}`.replace(/./g,"|'$`$''%$&")),k):k

Input is 1-indexed. Works by building up a string of the form false|'24'%3|'34'%2|'32'%4 and evaluating it. Strings are used because they are still syntactically valid in the single-digit case.

The recursion limits this to about n=119. Iterative version for <s>88</s> <s>84</s> 82 bytes:

n=>{for(k=0;n;n-=!eval(/0/.test(++k)+`${k}`.replace(/./g,"|'$`$''%$&")));return l}

Edit: Saved 2 bytes thanks to @Dennis♦.


答:
Mathematica, 17 bytes

```<code>+##/(1+##/9*^16)&
</code>```

An unnamed function taking two integers and returning an exact fraction.

Explanation

This uses two nice tricks with the argument sequence ##, which allows me to avoid referencing the individual arguments u and v separately. ## expands to a sequence of all arguments, which is sort of an "unwrapped list". Here is a simple example:

```<code>{x, ##, y}&[u, v]
</code>```

gives

```<code>{x, u, v, y}
</code>```

The same works inside arbitrary functions (since {...} is just shorthand for List[...]):

```<code>f[x, ##, y]&[u, v]
</code>```

gives

```<code>f[x, u, v, y]
</code>```

Now we can also hand ## to operators which will first treat them as a single operand as far as the operator is concerned. Then the operator will be expanded to its full form f[...], and only then is the sequence expanded. In this case +## is Plus[##] which is Plus[u, v], i.e. the numerator we want.

In the denominator on the other hand, ## appears as the left-hand operator of /. The reason this multiplies u and v is rather subtle. / is implemented in terms of Times:

```<code>FullForm[a/b]
(* Times[a, Power[b, -1]] *)
</code>```

So when a is ##, it gets expanded afterwards and we end up with

```<code>Times[u, v, Power[9*^16, -1]]
</code>```

Here, *^ is just Mathematica's operator for scientific notation.

Title: Calculate the relativistic velocity

Body:
Mathematica, 17 bytes

+##/(1+##/9*^16)&

An unnamed function taking two integers and returning an exact fraction.

Explanation

This uses two nice tricks with the argument sequence ##, which allows me to avoid referencing the individual arguments u and v separately. ## expands to a sequence of all arguments, which is sort of an "unwrapped list". Here is a simple example:

{x, ##, y}&[u, v]

gives

{x, u, v, y}

The same works inside arbitrary functions (since {...} is just shorthand for List[...]):

f[x, ##, y]&[u, v]

gives

f[x, u, v, y]

Now we can also hand ## to operators which will first treat them as a single operand as far as the operator is concerned. Then the operator will be expanded to its full form f[...], and only then is the sequence expanded. In this case +## is Plus[##] which is Plus[u, v], i.e. the numerator we want.

In the denominator on the other hand, ## appears as the left-hand operator of /. The reason this multiplies u and v is rather subtle. / is implemented in terms of Times:

FullForm[a/b]
(* Times[a, Power[b, -1]] *)

So when a is ##, it gets expanded afterwards and we end up with

Times[u, v, Power[9*^16, -1]]

Here, *^ is just Mathematica's operator for scientific notation.


答:
Python3, 55 31 29 bytes

Python is awful for getting inputs as each input needs int(input())
but here is my solution anyway:

v,u=int(input()),int(input());print((v+u)/(1+v*u/9e16))

Thanks to @Jakube I don't actually need the whole prgrame, just the function. Hence:

```<code>lambda u,v:(v+u)/(1+v*u/9e16)
</code>```

Rather self explanatory, get inputs, computes. I've used c^2 and simplified that as 9e16 is shorter than (3e8**2).

Python2, 42 bytes

```<code>v,u=input(),input();print(v+u)/(1+v*u/9e16)
</code>```

Thanks to @muddyfish

Title: Calculate the relativistic velocity

Body:
Python3, 55 31 29 bytes

Python is awful for getting inputs as each input needs int(input())
but here is my solution anyway:

v,u=int(input()),int(input());print((v+u)/(1+v*u/9e16))

Thanks to @Jakube I don't actually need the whole prgrame, just the function. Hence:

lambda u,v:(v+u)/(1+v*u/9e16)

Rather self explanatory, get inputs, computes. I've used c^2 and simplified that as 9e16 is shorter than (3e8**2).

Python2, 42 bytes

v,u=input(),input();print(v+u)/(1+v*u/9e16)

Thanks to @muddyfish


问:
Find operations required to get result
So task is simple, given array of numbers and result, you need to find what operations you need to use on numbers from array , to obtain requested result.

Let's make it simple for start, and allow only basic operations such as: addition, subtraction, multiplication and division.

Example:

```<code>Input  : [5,5,5,5,5] 100
Output : 5*5*5-5*5
</code>```

To give some advantage to languages like Java, request is to implement function, not entire program, and result can be return via parameter or print to console.

Code is scored based on amount bytes, and as it's golf code challenge, lowest score wins.

Another requirment is <s>You can get additional -10 points</s> if for array contains only digids, support solutions where you could construct numbers from following digits.
Ie

```<code>Input  : [1,2,3,4,5] 0
Output : 12-3-4-5
</code>```

Note that, provided outputs are proposed outputs, some cases might have more than one solution. It's up to you will you provide one or more solutions for given task.

EDIT:
Result has to be valid from mathematical point of view, hence division is rational division, not integer, and operation precedence is same as in classical math (first multiplication and division then addition and subtraction).

答:
Pyth, 23 bytes

Due to security reasons, * and / won't evaluate online, but they theoretically work.

```<code>fqeQvTms.ihQd^"+-*/"lth
</code>```

Test suite with only + and -.

Title: Find operations required to get result

Body:
Pyth, 23 bytes

Due to security reasons, * and / won't evaluate online, but they theoretically work.

fqeQvTms.ihQd^"+-*/"lth

Test suite with only + and -.


问:
Obfuscated Hello World
Create the shortest possible obfuscated program that displays the text "Hello World".

In order to be considered an obfuscated program, it must meet at least two of the following requirements:

Does not contain the characters: h, l, w and d in any case

Does not contain the characters: e, o, r, 0, and 1 in any case

Does not contain the characters: 2 or 7

Input:

none

Output:

Hello World

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 307; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];

  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '
' + c.body.replace(OVERRIDE_REG, '') + '
';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });

  });

  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Title: Obfuscated Hello World

Body:
Java, 88

I'm surprised, nobody used java.

System.out.print\u006Cn("\u0048e\u006C\u006Co "+((c\u0068ar)(11*8-1))+"or\u006C\u0064");


问:
Golf the xᵗʰ root of x
While bored in high-school (when I was half my current age...), I found that \$f(x) = x^{x^{-1}}\$ had some interesting properties, including e.g. that the maximum \$f\$ for \$0 ≤ x\$ is \$f(e)\$, and that the binding energy per nucleon of an isotope can be approximated as \$6 × f(x ÷ 21)\$...

Anyway, write the shortest function or program that calculates the xth root of x for any number in your language's domain.

Examples cases

For all languages

```<code>     -1   >       -1
   ¯0.2   >    -3125
   ¯0.5   >        4
    0.5   >     0.25
      1   >        1
      2   >    1.414
      e   >    1.444
      3   >    1.442
    100   >    1.047
  10000   >    1.001
</code>```

For languages that handle complex numbers

```<code>   -2   >        -0.7071i
    i   >            4.81
   2i   >    2.063-0.745i
 1+2i   >   1.820-0.1834i
 2+2i   >   1.575-0.1003i
</code>```

For languages that handle infinities

```<code>-1/∞   >   0    (or ∞ or ̃∞)
   0   >   0    (or 1 or ∞)
 1/∞   >   0
   ∞   >   1
  -∞   >   1
</code>```

For languages that handle both infinities and complex numbers

```<code> -∞-2i   >   1      (or ̃∞)
</code>```

 ̃∞ denotes directed infinity.

答:
05AB1E, 3 bytes

```<code>Dzm
</code>```

Explanation:

```<code>D    # Duplicate the input
 z   # Inverse, 1 ÷ input
  m  # Power, calculating input ** (1 ÷ input)
</code>```

Try it online!.

Title: Golf the xᵗʰ root of x

Body:
05AB1E, 3 bytes

Dzm

Explanation:

D    # Duplicate the input
 z   # Inverse, 1 ÷ input
  m  # Power, calculating input ** (1 ÷ input)

Try it online!.


Title: Calculate the relativistic velocity

Body:
J, <s>13</s> 11 bytes

+%1+9e16%~*

Usage

>> f =: +%1+9e16%~*
>> 5e7 f 6e7
<< 1.06452e8

Where >> is STDIN and << is STDOUT.


答:
PHP, 44 45 bytes

Anonymous function, pretty straightforward.

```<code>function($v,$u){echo ($v+$u)/(1+$v*$u/9e16);}
</code>```

Title: Calculate the relativistic velocity

Body:
PHP, 44 45 bytes

Anonymous function, pretty straightforward.

function($v,$u){echo ($v+$u)/(1+$v*$u/9e16);}


答:
PowerShell, 34 bytes

```<code>param($u,$v)($u+$v)/(1+$v*$u/9e16)
</code>```

Extremely straightforward implementation. No hope of catching up with anyone, though, thanks to the 6 $ required.

Title: Calculate the relativistic velocity

Body:
PowerShell, 34 bytes

param($u,$v)($u+$v)/(1+$v*$u/9e16)

Extremely straightforward implementation. No hope of catching up with anyone, though, thanks to the 6 $ required.


答:
Pyth, 20

```<code>e.f!s.e.x%s.D`Zksb1`
</code>```

Try it here or run the Test Suite

N is 1-indexed for this answer.

Uses largely the same logic as my python script. Notable differences are using .D to delete the digit from the string during the test and using exception handling to deal with zero digits.

Title: Excludivisible numbers

Body:
Given an integer N, output the Nth positive number K with the following property in decimal base:

For each digit I at position P of K, the number formed from K by removing the Pth digit (i.e. I) is divisible by I.

Example and remarks

324 is such a number:

3 divides 24

2 divides 34

4 divides 32

Note 1: we assume that the empty number is divisible by anything, like 0. Therefore 1, 2, 3, 4, 5, 6, 7, 8 and 9 are valid.

Note 2: K cannot contain the digit 0, since you cannot divide by 0.

Inputs and outputs

You may take the input as a function argument, through STDIN, etc.

You may return the output from a function, through STDOUT, etc.

You may index those numbers starting from 0 (in which case N >= 0) or from 1 (in which case N > 0), whichever suits you more.

Test cases

Those examples are indexed from 0, so if you indexed from 1, then add 1 to the numbers in the N column.

```<code>N    Output
0    1
4    5
8    9
15   77
16   88
23   155
42   742
47   1113
121  4244
144  6888
164  9999
</code>```

Scoring

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

Body:
Pyth, 20

e.f!s.e.x%s.D`Zksb1`

Try it here or run the Test Suite

N is 1-indexed for this answer.

Uses largely the same logic as my python script. Notable differences are using .D to delete the digit from the string during the test and using exception handling to deal with zero digits.


问:
Sum It Up with a Digital Triangle
Well, sum it down really.

Write a program or function that takes in a nonempty list of decimal integers (0-9) and outputs a downward pointing "triangle" of digits with the input list at the top where every digit after the first line is the sum of the two digits above it modulo 10.

For example, the input [7, 5, 0, 9] has output

```<code>7 5 0 9
 2 5 9
  7 4
   1
</code>```

because 2 is (7 + 5) mod 10, 5 is (5 + 0) mod 10, 9 is (0 + 9) mod 10, etc. all the way to 1 being (7 + 4) mod 10.

If the list has only one item, then the output matches the input; e.g. an input of [4] will yield

```<code>4
</code>```

Here are some additional examples:

```<code>[0]

0

[1, 2]

1 2
 3

[8, 7]

8 7
 5

[0, 0]

0 0
 0

[1, 4, 2]

1 4 2
 5 6
  1

[0, 1, 0]

0 1 0
 1 1
  2

[1, 0, 0, 0]

1 0 0 0
 1 0 0
  1 0
   1

[1, 2, 3, 4]

1 2 3 4
 3 5 7
  8 2
   0

[1, 2, 3, 5, 8]

1 2 3 5 8
 3 5 8 3
  8 3 1
   1 4
    5

[9, 2, 4, 5, 3, 2, 2]

9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0
</code>```

Note that in the output:

The first line does not have leading spaces.

Each subsequent line has one more leading space than the line previous.

Digits are separated by a single space.

Each line is allowed to have up to one trailing space.

There may be a single optional trailing newline.

You must use the characters for normal decimal digits (0 through 9).

The shortest code in bytes wins. Tiebreaker is earlier answer.

答:
C# 6, <s>125+31</s> 125+18 = 143 bytes

```<code>string f(int[] n,string s="")=>s+string.Join(" ",n)+"\n"+(n.Length>1?f(n.Zip(n.Skip(1),(a,b)=>(a+b)%10).ToArray(),s+" "):"");
</code>```

The +18 is for using System.Linq;

Thanks to @TheLethalCoder for saving 13 bytes, by pointing out a unnecessary using statement

Title: Sum It Up with a Digital Triangle

Body:
C# 6, <s>125+31</s> 125+18 = 143 bytes

string f(int[] n,string s="")=>s+string.Join(" ",n)+"\n"+(n.Length>1?f(n.Zip(n.Skip(1),(a,b)=>(a+b)%10).ToArray(),s+" "):"");

The +18 is for using System.Linq;

Thanks to @TheLethalCoder for saving 13 bytes, by pointing out a unnecessary using statement