Ascending Pea Pattern generator For those who are not familiarized with the Pea Pattern, it is a simple mathematical pattern.

There are multiple variations of this pattern, but we will focus in one:

  Ascending  Pea Pattern

It looks like this:

1
11
21
1112
3112
211213
...

It seems really hard to get the following line, but it is really easy. The way to get the next line is by counting the number of times a digit have repeated on the previous line (start counting with the lowest, to largest):

one
one one
two ones
one one, one two
three ones, one two
two ones, one two, one three
...

Requirements/Rules:

We will start at 1
It will be a snippet
There must be a way to specify the number of lines generates (e.g 5
will give the first 5 lines)
The code should be as short as possible
It must start counting from lowest to largest (the Ascending
variation)

APL, 32 characters
⍪⌽({⍵,⍨,/{⌽⍵,+/⍵⍷d}¨⍳⌈/d←⊃⍵}⍣⎕)1

This generates lines starting from 0 (i.e. 0 generates 1, 1 generates 1 followed by 1 1, etc.), as specified by user input. I used Dyalog APL for this, and ⎕IO should be set to its default of 1.
Example:
      ⍪⌽({⍵,⍨,/{⌽⍵,+/⍵⍷d}¨⍳⌈/d←⊃⍵}⍣⎕)1
⎕:
      0
1

      ⍪⌽({⍵,⍨,/{⌽⍵,+/⍵⍷d}¨⍳⌈/d←⊃⍵}⍣⎕)1
⎕:
      13
               1
             1 1
             2 1
         1 1 1 2
         3 1 1 2
     2 1 1 2 1 3
     3 1 2 2 1 3
     2 1 2 2 2 3
     1 1 4 2 1 3
 3 1 1 2 1 3 1 4
 4 1 1 2 2 3 1 4
 3 1 2 2 1 3 2 4
 2 1 3 2 2 3 1 4
 2 1 3 2 2 3 1 4

Once I get some more time, I'll write up an explanation. ⍨


Little Chandler is sad. Draw him a cloud to cheer him up Little Chandler is sad. Draw him a cloud to cheer him up.
Note: Drawing a cloud won't actually cheer him up.

A circle can be defined as a 3-tuple (x,y,r) where x is the x position of the circle on a Cartesian plane, y is the y position of the circle on a Cartesian plane, and r is the radius of the circle. x and y may be negative. r is always positive. The input is a list of circles in the form of space separated 3-tuples. For instance:

3,1,1 3,2,1.5 1,2,0.7 0.9,1.2,1.2 1,0,0.8

The 3,1,1 means "A circle with centre point at 3,1 with 1 radius. 3,2,1.5 means "A circle with centre point at 3,2 with 1.5 radius.

If we draw all of these circles of the input on a graph, it looks like this (I've included grid lines and labels for clarity only; they are not required):

Notice how all the circles are cohesive. That is, they're all overlapped together such that it forms one large group without any small groups of circles separated from the rest. The input is guaranteed to be cohesive.

Suppose now we draw a line that travels around the "border" formed by these circles, without any of the other lines. It would be like drawing the border of the silhouette formed by all the circles. The resulting cloud would look something like this:

So this cloud has been formed by drawing only the arcs of the circles in the input that form a border, resulting in a single shape. In other words, the cloud is formed by only drawing the arcs that are not within another circle. Your program will take in input in the form explained above, and output an image that displays the resulting cloud. The overall shape of the cloud must be correct, but the scale, colour, line thickness, and how it looks at vertexes is up to you. Note that the cloud must be visible, so you can't pull something like "This program draws a white cloud on a white background", "This program draws a cloud at a infinitesimally small scale", "This program draws a cloud with 0 line thickness", etc. Also note that the colour of the border must be different from the colour of the fill or background.

Another example. Input:

1,4,2 5,2,1 3,1,1 3.5,2,1.2 3,3,0.7 1,2,0.7

Output:

If there is a "hole" in the cloud, you should draw the hole as well. Input:

0,5,4 3,4,4 4,3,4 5,0,4 4,-3,4 3,-4,4 0,-5,4 -3,-4,4 -4,-3,4 -5,0,4 -4,3,4 -3,4,4

Output:

Here is an important rule: your program must draw only the lines that form the border. This means that you CANNOT simply draw the circles fully, and then draw the circles slightly smaller with a white fill -- because that method still draws lines that don't form a border, it just covers them up afterwards. The purpose of the rule was to prevent the "draw the circles, then draw the circles again with a white fill" implementations, or anything similar to that. The answer is expected to actually calculate where to draw things before drawing it.

This is code golf, so the shortest character count wins.

T-SQL 235 234 229 212 171 73 bytes
This makes use of spatial functionality in SQL Server 2012+.  When it is run in SSMS (SQL Server Management Studio) is produces a spatial results pane.
The input is from variable @i.  I could reduce it further if the input could be taken from a table.
Since table input is now allowed.
SELECT Geometry::UnionAggregate(Geometry::Point(X,Y,0).STBuffer(R))FROM A

I've left the previous solution below.
DECLARE @ VARCHAR(999)='WITH a AS(SELECT *FROM(VALUES('+REPLACE(@i,' ','),(')+'))A(X,Y,R))SELECT Geometry::UnionAggregate(Geometry::Point(X,Y,0).STBuffer(R))FROM a'EXEC(@)

Edit: Remove stray space, surplus into and subquery
171: Replaced table creation with CTE and @s with @.

Break down of the Dynamic SQL
DECLARE @i VARCHAR(100) = '1,4,2 5,2,1 3,1,1 3.5,2,1.2 3,3,0.7 1,2,0.7' -- Input
DECLARE @ VARCHAR(999) = '
WITH a AS(                                       --CTE to produce rows of x,y,r
    SELECT *FROM(VALUES('+
        REPLACE(@i,' ','),(')                    --Format @i to a value set
        +'))A(X,Y,R)
)
SELECT Geometry::UnionAggregate(                 --Aggregate Buffered Points
    Geometry::Point(X,Y,0).STBuffer(R)           --Create point and buffer
    )
FROM a                                           --from the table variable
'
EXEC(@)                                          --Execute Dynamic sql


Find the largest gap between good primes Following the fine tradition of questions such as Find the largest prime whose length, sum and product is prime , this is a variant on a largest prime challenge.
Input
Your code should not take any input.
Definition
We say a prime p is good if p-1 has exactly 2 distinct prime factors.
Output
Your code should output the absolute difference between consecutive good primes q and p so that |q-p| is as large as possible and q is the smallest good prime larger than p.  You may output any number of good pairs and your last output will be taken as the score.
Example
The sequence of the first 55 good primes  is https://oeis.org/A067466 .
Score
Your score is simply |q-p| for the pair of good primes you output.
Languages and libraries
You can use any language or library you like (that wasn't designed for this challenge) except for any library functions for primality testing or factoring integers. However, for the purposes of scoring I will run your code on my machine so please provide clear instructions for how to run it on Ubuntu.
My Machine The timings will be run on my machine. This is a standard Ubuntu install on an 8GB AMD FX-8350 Eight-Core Processor.  This also means I need to be able to run your code.
Details

I will kill your code after 2 minutes unless it starts to run out of memory before that. It should therefore make sure to output something before the cut off.
You may not use any external source of primes.
You may use probabilistic prime testing methods although I am told by Mego that with good tables, Miller-Rabin can test up to 341,550,071,728,321 (or even higher) deterministically. See also http://miller-rabin.appspot.com/ .

Best entries that check all integers from 1

756 by cat in Go
756 by El'endia Starman in Python
1932 by Adnan in C# (using mono 3.2.8)
2640 by yeti in Python (using pypy 4.01)
2754 by Reto Koradi in C++
3486 by Peter Taylor in Java
3900 by primo in RPython (using pypy 4.01)
4176 by The Coder in Java

Best entries that may skip a large number of integers to find a large gap

14226 by Reto Koradi in C++
22596 by primo in RPython (using pypy 4.01). Record reached after 5 seconds!

Probably 4032, mixed Atkin-Bernstein sieve and "deterministic" Miller-Rabin

Wheel factorisation and good primes

It's highly obvious that with the exceptions of 2, 3, and 5, every prime is coprime to 2*3*5 = 60. There are 16 equivalence classes modulo 60 which are coprime to 60, so any primality test only needs to check those 16 cases.

However, when we're looking for "good" primes we can thin the herd even more. If gcd(x, 60) = 1, we find that in most cases gcd(x-1, 60) is either 6 or 10. There are 6 values of x for which it is 2:

17, 23, 29, 47, 53, 59

Therefore we can precompute the "good" primes of the form 2^a 3^b + 1 and 2^a 5^b + 1 and merge them into the result of a prime generator which only considers 10% of numbers as even potential primes.

Implementation notes

Since I already had a Java implementation of the Atkin-Bernstein sieve lying around, and that already uses a wheel as a key component, it seemed natural to strip out the unnecessary spokes and adapt the code. I originally tried using a producer-consumer architecture to exploit the 8 cores, but memory management was too messy.

To test whether a prime is a "good" prime, I'm using a "deterministic" Miller-Rabin test (which really means a Miller-Rabin test which someone else has pre-checked against a list generated deterministically). This can certainly be rewritten to also use Atkin-Bernstein, with some caching to cover the ranges corresponding to sqrt, cbrt, etc., but I'm not sure whether it would be an improvement (because it would be testing lots of numbers which I don't need to test), so that's an experiment for another day.

On my fairly old computer this runs to

987417437 - 987413849 = 3588
1123404923 - 1123401023 = 3900
1196634239 - 1196630297 = 3942
1247118179 - 1247114147 = 4032

in pretty much exactly 2 minutes, and then

1964330609 - 1964326433 = 4176
2055062753 - 2055058529 = 4224
2160258917 - 2160254627 = 4290

at 3:10, 3:20, and 3:30 respectively.

import java.util.*;

public class PPCG65876 {
    public static void main(String[] args) {
        long[] specials = genSpecials();
        int nextSpecialIdx = 0;
        long nextSpecial = specials[nextSpecialIdx];
        long p = 59;
        long bestGap = 2;

        for (long L = 1; true; L += B) {

            long[][] buf = new long[6][B >> 6];
            int[] Lmodqq = new int[qqtab.length];
            for (int i = 0; i < Lmodqq.length; i++) Lmodqq[i] = (int)(L % qqtab[i]);

            for (long[] arr : buf) Arrays.fill(arr, -1); // TODO Can probably get a minor optimisation by inverting this
            for (int[] parms : elliptic) traceElliptic(buf[parms[0]], parms[1], parms[2], parms[3] - L, parms[4], parms[5], Lmodqq, totients[parms[0]]);
            for (int[] parms : hyperbolic) traceHyperbolic(buf[parms[0]], parms[1], parms[2], parms[3] - L, Lmodqq, totients[parms[0]]);

            // We need to filter down to squarefree numbers.
            long pg_base = L * M;
            squarefreeMid(buf, invTotients, pg_base, 247, 1, 38);
            squarefreeMid(buf, invTotients, pg_base, 253, 1, 38);
            squarefreeMid(buf, invTotients, pg_base, 257, 1, 38);
            squarefreeMid(buf, invTotients, pg_base, 263, 1, 38);
            squarefreeMid(buf, invTotients, pg_base, 241, 0, 2);
            squarefreeMid(buf, invTotients, pg_base, 251, 0, 2);
            squarefreeMid(buf, invTotients, pg_base, 259, 0, 2);
            squarefreeMid(buf, invTotients, pg_base, 269, 0, 2);

            // Turn bitmasks into primes
            long[] page = new long[150000]; // TODO This can almost certainly be smaller
            long[] transpose = new long[6];
            for (int j = 0, off = 0; j < (B >> 6); j++) {
                // Reduce cache locality problems by transposing.
                for (int k = 0; k < 6; k++) transpose[k] = buf[k][j];
                for (long mask = 1L; mask != 0; mask <<= 1) {
                    for (int k = 0; k < 6; k++) {
                        if ((transpose[k] & mask) == 0) page[off++] = pg_base + totients[k];
                    }

                    pg_base += M;
                }
            }

            // Insert specials and look for gaps.
            for (long q : page) {
                if (q == 0) break;

                // Do we need to insert one or more specials?
                while (nextSpecial < q) {
                    if (nextSpecial - p > bestGap) {
                        bestGap = nextSpecial - p;
                        System.out.format("%d - %d = %d\n", nextSpecial, p, bestGap);
                    }

                    p = nextSpecial;
                    nextSpecial = specials[++nextSpecialIdx];
                }

                if (isGood(q)) {
                    if (q - p > bestGap) {
                        bestGap = q - p;
                        System.out.format("%d - %d = %d\n", q, p, bestGap);
                    }

                    p = q;
                }
            }

        }
    }

    static long[] genSpecials() {
        // 2^a 3^b + 1 or 2^a 5^b + 1
        List<Long> tmp = new LinkedList<Long>();
        for (long threes = 3; threes <= 4052555153018976267L; threes *= 3) {
            for (long t = threes; t > 0; t <<= 1) tmp.add(t + 1);
        }
        for (long fives = 5; fives <= 7450580596923828125L; fives *= 5) {
            for (long f = fives; f > 0; f <<= 1) tmp.add(f + 1);
        }

        // Filter down to primes
        Iterator<Long> it = tmp.iterator();
        while (it.hasNext()) {
            long next = it.next();
            if (next < 60 || next > 341550071728321L || !isPrime(next)) it.remove();
        }

        Collections.sort(tmp);
        long[] specials = new long[tmp.size()];
        for (int i = 0; i < tmp.size(); i++) specials[i] = tmp.get(i);

        return specials;
    }

    private static boolean isGood(long p) {
        long d = p - 1;
        while ((d & 1) == 0) d >>= 1;

        if (d == 1) return false;

        // Is d a prime power?
        if (d % 3 == 0 || d % 5 == 0) {
            // Because of the way the filters before this one work, nothing should reach here.
            throw new RuntimeException("Should be unreachable");
        }

        // TODO Is it preferable to reuse the Atkin-Bernstein code, caching pages which correspond
        // to the possible power candidates?
        if (isPrime(d)) return true;
        for (int a = (d % 60 == 1 || d % 60 == 49) ? 2 : 3; (1L << a) < d; a++) {
            long r = (long)(0.5 + Math.pow(d, 1. / a));
            if (d == (long)(0.5 + Math.pow(r, a)) && isPrime(r)) return true;
        }

        return false;
    }

    /*---------------------------------------------------
               Deterministic Miller-Rabin
    ---------------------------------------------------*/
    public static boolean isPrime(int x) {
        // See isPrime(long). We pick bases which are known to work for the entire range of int.
        // Special case for the bases.
        if (x == 2 || x == 7 || x == 61) return true;

        int d = x - 1;
        int s = 0;
        while ((d & 1) == 0) { s++; d >>= 1; } // TODO Can be optimised

        if (!isSPRP(2, d, s, x)) return false;
        if (!isSPRP(7, d, s, x)) return false;
        if (!isSPRP(61, d, s, x)) return false;
        return true;
    }

    private static boolean isSPRP(int b, int d, int s, int x /* == d << s */) {
        int l = modPow(b, d, x);
        if (l == 1 || l == x - 1) return true;
        for (int r = 1; r < s; r++) {
            l = modPow(l, 2, x);
            if (l == x - 1) return true;
            if (l == 1) return false;
        }

        return false;
    }

    public static int modPow(int a, int b, int c) {
        int accum = 1;
        while (b > 0) {
            if ((b & 1) == 1) accum = (int)(accum * (long)a % c);
            a = (int)(a * (long)a % c);
            b >>= 1;
        }
        return accum;
    }

    public static boolean isPrime(long x) {
        if (x < Integer.MAX_VALUE) return isPrime((int)x);

        long d = x - 1;
        int s = 0;
        while ((d & 1) == 0) { s++; d >>= 1; } // TODO Can be optimised

        // If b^d == 1 (mod x) or (b^d)^(2^r) == -1 (mod x) for some r < s then we pass for base b.
        // We select bases according to Jaeschke, Gerhard (1993), "On strong pseudoprimes to several bases", Mathematics of Computation 61 (204): 915–926, doi:10.2307/2153262
        // TODO Would it be better to use a set of 5 bases from http://miller-rabin.appspot.com/ ?
        if (!isSPRP(2, d, s, x)) return false;
        if (!isSPRP(3, d, s, x)) return false;
        if (!isSPRP(5, d, s, x)) return false;
        if (!isSPRP(7, d, s, x)) return false;
        if (x < 3215031751L) return true;
        if (!isSPRP(11, d, s, x)) return false;
        if (x < 2152302898747L) return true;
        if (!isSPRP(13, d, s, x)) return false;
        if (x < 3474749660383L) return true;
        if (!isSPRP(17, d, s, x)) return false;
        if (x < 341550071728321L) return true;

        throw new IllegalArgumentException("Overflow");
    }

    private static boolean isSPRP(long b, long d, int s, long x /* == d << s */) {
        if (b * (double)x > Long.MAX_VALUE) throw new IllegalArgumentException("Overflow"); // TODO Work out more precise page bounds

        long l = modPow(b, d, x);
        if (l == 1 || l == x - 1) return true;
        for (int r = 1; r < s; r++) {
            l = modPow(l, 2, x);
            if (l == x - 1) return true;
            if (l == 1) return false;
        }

        return false;
    }

    /**
     * Computes a^b (mod c). We assume c &lt; 2^62.
     */
    public static long modPow(long a, long b, long c) {
        long accum = 1;
        while (b > 0) {
            if ((b & 1) == 1) accum = prodMod(accum, a, c);
            a = prodMod(a, a, c);
            b >>= 1;
        }
        return accum;
    }

    /**
     * Computes a*b (mod c). We assume c &lt; 2^62.
     */
    private static long prodMod(long a, long b, long c) {
        // The naive product would require 128-bit integers.

        // Consider a = (A << 32) + B, b = (C << 31) + D. Different shifts chosen deliberately.
        // Then ab = (AC << 63) + (AD << 32) + (BC << 31) + BD with intermediate values remaining in 63 bits.
        long AC = (a >> 32) * (b >> 31) % c;
        long AD = (a >> 32) * (b & ((1L << 31) - 1)) % c;
        long BC = (a & ((1L << 32) - 1)) * (b >> 31) % c;
        long BD = (a & ((1L << 32) - 1)) * (b & ((1L << 31) - 1)) % c;

        long t = AC;
        for (int i = 0; i < 31; i++) {
            t = (t + t) % c;
        }
        // t = (AC << 31)
        t = (t + AD) % c;
        t = (t + t) % c;
        t = (t + BC) % c;
        // t = (AC << 32) + (AD << 1) + BC
        for (int i = 0; i < 31; i++) {
            t = (t + t) % c;
        }
        // t = (AC << 63) + (AD << 32) + (BC << 31)
        return (t + BD) % c;
    }

    /*---------------------------------------------------
                      Atkin-Bernstein
    ---------------------------------------------------*/
    // Page size.
    private static final int B = 1001 << 6;
    // Wheel modulus for sharding between binary quadratic forms.
    private static final int M = 60;

    // Squares of primes 5 < q < 240
    private static final int[] qqtab = new int[] {
        49, 121, 169, 289, 361, 529, 841, 961, 1369, 1681, 1849, 2209, 2809,
        3481, 3721, 4489, 5041, 5329, 6241, 6889, 7921, 9409, 10201, 10609, 11449, 11881,
        12769, 16129, 17161, 18769, 19321, 22201, 22801, 24649, 26569, 27889, 29929, 32041, 32761,
        36481, 37249, 38809, 39601, 44521, 49729, 51529, 52441, 54289, 57121
    };
    // If a_i == q^{-2} (mod 60) is the reciprocal of qq[i], qq60tab[i] = qq[i] + (1 - a_i * qq[i]) / 60
    private static int[] qq60tab = new int[] {
        9, 119, 31, 53, 355, 97, 827, 945, 251, 1653, 339, 405, 515,
        3423, 3659, 823, 4957, 977, 6137, 1263, 7789, 1725, 10031, 1945, 2099, 11683,
        2341, 2957, 16875, 3441, 18999, 21831, 22421, 4519, 4871, 5113, 5487, 31507, 32215,
        35873, 6829, 7115, 38941, 43779, 9117, 9447, 51567, 9953, 56169
    };

    /**
     * Produces a set of parameters for traceElliptic to find solutions to ax^2 + cy^2 == d (mod M).
     * @param d The target residue.
     * @param a Binary quadratic form parameter.
     * @param c Binary quadratic form parameter.
     */
    private static List<int[]> initElliptic(final int[] invTotients, final int d, final int a, final int c) {
        List<int[]> rv = new ArrayList<int[]>();

        // The basic idea is that we maintain an invariant of the form
        //     M k = a x^2 + c y^2 - d
        // Therefore we increment x in steps F such that
        //     a((x + F)^2 - x^2) == 0 (mod M)
        // and similarly for y in steps G.
        int F = computeIncrement(a, M), G = computeIncrement(c, M);
        for (int f = 1; f <= F; f++) {
            for (int g = 1; g <= G; g++) {
                if ((a*f*f + c*g*g - d) % M == 0) {
                    rv.add(new int[] { invTotients[d], (2*f + F)*a*F/M, (2*g + G)*c*G/M, (a*f*f + c*g*g - d)/M, 2*a*F*F/M, 2*c*G*G/M });
                }
            }
        }

        return rv;
    }

    private static int computeIncrement(int a, int M) {
        // Find smallest F such that M | 2aF and M | aF^2
        int l = M / gcd(M, 2 * a);
        for (int F = l; true; F += l) {
            if (a*F*F % M == 0) return F;
        }
    }

    public static int gcd(int a, int b) {
        while (b != 0) {
            int t = b;
            b = a % b;
            a = t;
        }

        return a;
    }

    // NB This is generalised somewhat from primegen's implementation.
    private static void traceElliptic(final long[] buf, int x, int y, long start, final int cF2, final int cG2, final int[] Lmodqq, final int d) {
        // Bring the annular segment into the range of ints.
        start += 1000000000;
        while (start < 0) {
            start += x;
            x += cF2;
        }
        start -= 1000000000;
        int i = (int)start;

        while (i < B) {
            i += x;
            x += cF2;
        }

        while (true) {
            x -= cF2;
            if (x <= cF2 >> 1) {
                // It makes no sense that doing this in here should perform well, but empirically it does much better than
                // only eliminating the squares once.
                squarefreeTiny(buf, Lmodqq, d);
                return;
            }
            i -= x;

            while (i < 0) {
                i += y;
                y += cG2;
            }

            int i0 = i, y0 = y;
            while (i < B) {
                buf[i >> 6] ^= 1L << i;
                i += y;
                y += cG2;
            }
            i = i0;
            y = y0;
        }
    }

    // This only handles 3x^2 - y^2, and is closer to a direct port of primegen.
    private static void traceHyperbolic(final long[] a, int x, int y, long start, final int[] Lmodqq, final int d) {
        x += 5;
        y += 15;

        // Bring the segment into the range of ints.
        start += 1000000000;
        while (start < 0) {
            start += x;
            x += 10;
        }
        start -= 1000000000;
        int i = (int)start;

        while (i < 0) {
            i += x;
            x += 10;
        }

        while (true) {
            x += 10;
            while (i >= B) {
                if (x <= y) {
                    squarefreeTiny(a, Lmodqq, d);
                    return;
                }
                i -= y;
                y += 30;
            }

            int i0 = i, y0 = y;
            while (i >= 0 && y < x) {
                a[i >> 6] ^= 1L << i;
                i -= y;
                y += 30;
            }
            i = i0 + x - 10;
            y = y0;
        }
    }

    private static void squarefreeTiny(final long[] a, final int[] Lmodqq, final int d) {
        for (int j = 0; j < qqtab.length; ++j) {
            int qq = qqtab[j];
            int k = qq - 1 - ((Lmodqq[j] + qq60tab[j] * d - 1) % qq);
            while (k < B) {
                a[k >> 6] |= 1L << k;
                k += qq;
            }
        }
    }

    private static void squarefreeMid(long[][] buf, int[] invTotients, final long base, int q, int dqq, int di) {
        int qq = q * q;
        q = M * q + (M * M / 4);

        while (qq < M * B) {
            int i = qq - (int)(base % qq);
            if ((i & 1) == 0) i += qq;

            if (i < M * B) {
                int qqhigh = ((qq / M) << 1) + dqq;
                int ilow = i % M;
                int ihigh = i / M;
                while (ihigh < B) {
                    int n = invTotients[ilow];
                    if (n >= 0) buf[n][ihigh >> 6] |= 1L << ihigh;

                    ilow += di;
                    ihigh += qqhigh;
                    if (ilow >= M) {
                        ilow -= M;
                        ihigh += 1;
                    }
                }
            }

            qq += q;
            q += M * M / 2;
        }

        squarefreebig(buf, invTotients, base, q, qq);
    }

    private static void squarefreebig(long[][] buf, int[] invTotients, final long base, int q, long qq) {
        long bound = base + M * B;
        while (qq < bound) {
            long i = qq - (base % qq);
            if ((i & 1) == 0) i += qq;

            if (i < M * B) {
                int pos = (int)i;
                int n = invTotients[pos % M];
                if (n >= 0) {
                    int ihigh = pos / M;
                    buf[n][ihigh >> 6] |= 1L << ihigh;
                }
            }

            qq += q;
            q += M * M / 2;
        }
    }

    // The relevant totients of M - those which only have one forced prime factor.
    static final int[] totients = new int[] { 17, 23, 29, 47, 53, 59 };
    private static final int[] invTotients;
    // Parameters for tracing the hyperbolic BQF used for 59+60Z.
    private static final int[][] hyperbolic = new int[][] {
        {5, 1, 2, -1}, {5, 1, 8, -2}, {5, 1, 22, -9}, {5, 1, 28, -14}, {5, 4, 7, -1}, {5, 4, 13, -3}, {5, 4, 17, -5}, {5, 4, 23, -9},
        {5, 5, 4, 0}, {5, 5, 14, -3}, {5, 5, 16, -4}, {5, 5, 26, -11}, {5, 6, 7, 0}, {5, 6, 13, -2}, {5, 6, 17, -4}, {5, 6, 23, -8},
        {5, 9, 2, 3}, {5, 9, 8, 2}, {5, 9, 22, -5}, {5, 9, 28, -10}, {5, 10, 1, 4}, {5, 10, 11, 2}, {5, 10, 19, -2}, {5, 10, 29, -10}
    };

    // Parameters for tracing the elliptic BQFs used for all totients except 11 and 59.
    private static final int[][] elliptic;
    static {
        invTotients = new int[M];
        Arrays.fill(invTotients, -1);
        for (int i = 0; i < totients.length; i++) invTotients[totients[i]] = i;

        // Calculate the parameters for tracing the elliptic BQFs from a table of the BQF used for each totient.
        // E.g. for 17+60Z we use 5x^2 + 3y^2.
        int[][] bqfs = new int[][] {
            {17, 5, 3}, {23, 5, 3}, {29, 4, 1}, {47, 5, 3}, {53, 5, 3}
        };
        List<int[]> parmSets = new ArrayList<int[]>();
        for (int[] bqf : bqfs) parmSets.addAll(initElliptic(invTotients, bqf[0], bqf[1], bqf[2]));
        elliptic = parmSets.toArray(new int[0][]);
    }
}

Save as PPCG65876.java, compile as javac PPCG65876.java, and run as java -Xmx1G PPCG65876.


What's the file extension? Your challenge is to find the file extension of a provided filename:

hi.txt -> txt or .txt
carrot.meme -> meme or .meme
lol (undefined behavior)
what..is..this..file -> file or .file
.bashrc -> bashrc or .bashrc
T00M@n3KaPZ.h0wC[]h -> h0wC[]h or .h0wC[]h
agent.000 -> 000 or .000

You must get the text from the last .  or after the last . to the end of the string. The first capturing group match of the regular expression /\.([^.]+)$/ works, and so does splitting the input on .s and returning the last one.

The file name will always contain at least one ., but it may contain multiple .. (see examples)

The input will always match ^[.a-zA-Z0-9^!\[\]{}@$%+=]+$.

Retina, 5 bytes

.*\.

Replaces everything and a dot with nothing at all.

Try it online!


How many friday the 13th in a year? Your challenge is to write a program which, given a year, outputs the number of "Friday 13ths" in it.

Rules & Details:

You can take input via STDIN, or as an argument passed to your program.
You should output the result to STDOUT.
You may assume that input will be a valid year, and does not pre-date the Gregorian calendar (undefined behaviour is permitted in these cases).
Calendar/Date libraries are allowed.

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

(Related challenge link)

Mathematica 49 46 45 44 42
As a pure function: 42 chars
DayName@{#,m,6}~Table~{m,12}~Count~Friday&

Example
DayName@{#,m,6}~Table~{m,12}~Count~Friday&[2013]

2

As a named function: 44 chars
f=DayName@{#,m,6}~Table~{m,12}~Count~Friday&

Examples
f[1776]
f[2012]
f[2013]
f[2014]

2
3
2
1


Cantor Function, Cruel A ripoff of this challenge. Go upvote it!
Objective
Given a rational number amongst \$[0,1]\$, apply the Cantor function to it and output the rational number that's produced.
The Cantor function
The Cantor function is continuous everywhere and constant almost everywhere, but has an average slope of 1:

The Cantor function \$f(x)\$ can be expressed as a limit \$f(x)=\lim\limits_{n\to\infty} f_n(x)\$ of a sequence of functions \$f_0, f_1, f_2, \dots\$, which are defined recursively as:
\$f_0(x)=x\$
\$f_{n+1}(x)=\left\{\begin{matrix}\frac{1}{2}f_n(3x)&x\in[0,\frac{1}{3})\\ \frac{1}{2}&x\in[\frac{1}{3},\frac{2}{3})\\ \frac{1}{2}+\frac{1}{2}f_n(3x-2)&x\in[\frac{2}{3},1] \end{matrix}\right.\$

Your task is to compute \$f(x)\$ for the rational \$x \in [0,1] \cap \mathbb{Q}\$ given as input.
How?
Though this task might seem impossible, this is actually possible, for the Cantor function is computable.
A step-by-step solution for \$x \in \mathbb{R}\$:

Ternary-expand \$x\$ to \$0.t_1t_2t_3\cdots\$.

Write "0.".

Set \$n=1\$.

If \$t_n = 1\$, write "1" and halt.

Otherwise, if \$t_n = 0\$, write "0", increment \$n\$, then continue doing step #4.

Otherwise (\$t_n = 2\$), write "1", increment \$n\$, then continue doing step #4.

Parse the resulting string as a binary expansion of a real number.

As \$x\$ actually is in \$\mathbb{Q}\$ in this challenge, you should exploit the fact that the ternary expansion of \$x\$ repeats. It follows that the output is also in \$\mathbb{Q}\$.
Examples
$$
\begin{array}{r|c|c|c|c|c|c|c|c|c|c}
x & 0 & ½ & ⅓ & ¼ & ⅕ & ⅚ & 1 \\ \hline
\text{Ternary expansion of }x & 0.\overline{0} & 0.\overline{1} & 0.1\overline{0} & 0.\overline{02} & 0.\overline{0121} & 0.2\overline{1} & 0.\overline{2}  \\ \hline
\text{Binary expansion of } f(x) & 0.\overline{0} & 0.1 & 0.1 & 0.\overline{01} & 0.01 & 0.11 & 0.\overline{1} \\ \hline
f(x) & 0 & ½ & ½ & ⅓ & ¼ & ¾ & 1
\end{array}
$$
Rules

Invalid inputs fall in don't care situation. In particular, you don't need to deal with numbers outside of \$[0,1]\$.

Input and output must be exact rational numbers. If your language doesn't natively support rational number arithmetic, use a pair of integers.

JavaScript (ES7),  141 ... 128  125 bytes
Saved 2 bytes thanks to @Ada
Expects the fraction \$p/q\$ as (p)(q). Returns \$P/Q\$ as [P,Q].

p=>q=>(k='0b'+(n=0,g=p=>(r=n-g[p])?'':p/q&1||[p/q>>1]+g(p%q*3,g[p]=n++))(p),r?[((k>>r)*(m=2**r-1)+(k&m))*2,m<<n-r]:[+k,1<<n])

Try it online!
How?
Ternary and binary expansions
k =                    // build a binary string
  '0b' + (             // append the binary prefix
    n = 0,             // n is a bit counter
    g = p =>           // g is a recursive function taking the numerator p
      (r = n - g[p]) ? //   if p was already encountered, we have a repeating
                       //   pattern, whose length is stored in r; in that case:
        ''             //     stop the recursion
      :                //   else:
        p / q & 1 ||   //     if p/q = 1, append a '1' and stop the recursion
        [p / q >> 1] + //     otherwise, append '1' if p/q = 2 or '0' if p/q = 0
        g(             //     append the result of a recursive call to g:
          3 * (p % q), //       update p to 3 * (p modulo q)
          g[p] = n++   //       store the position of p in g and increment n
        )              //     end of recursive call
  )(p)                 // initial call with the numerator provided in the input

Turning the binary expansion into a decimal fraction
If \$r\$ is NaN after the first step, it means that the binary expansion has no repeating pattern. In that case, the numerator is \$k\$ and the denominator is \$2^n\$.
If \$r\$ is defined, we compute the following bitmask:
m = 2 ** r - 1

The numerator is:
((k >> r) * m + (k & m)) * 2

and the denominator is:
m << n - r


Calculate the Delacorte Number of a square Challenge: implement calculation of a Delacorte Number in any language. Shortest code wins.

For a given square matrix of distinct integers 1..n² (possible side length n at least between 3 and 27), its Delacorte Number is the sum of the products gcd(a, b) × distance²(a, b) for each distinct pair of integers {a, b}.

The following example shows a 3×3 square with a Delacorte Number of 160.

3 2 9
4 1 8
5 6 7

In this square we have 36 distinct pairs to calculate, for example the pair 4 and 6: gcd(4, 6) × distance²(4, 6) = 4

Another example square for testing - this has a Delacorte Number of 5957:

10  8 11 14 12
21  4 19  7  9
 5 13 23  1 16
18  3 17  2 15
24 22 25  6 20

Delacorte Numbers are taken from this programming contest - see there for further details... The contest ended in January 2015. It was great fun!

Rules:

Necessary line breaks count as 1 char. You may post your golfed solution with line breaks, but they are only counted if necessary in that language.

You can choose how to handle input and output and you don't have to count the necessary framework of your language, like standard-includes or main function headers. Only the actual code counts (including shortcut/alias definitions), like in this C# example:

namespace System
{
    using Collections.Generic;
    using I=Int32; //this complete line counts
    class Delacorte
    {
        static I l(I[]a){return a.Length;} //of course this complete line counts

        static void CalculateSquare(int[] a, out int r)
        {
            r=0;for(I i=l(a);i-->0;)r+=a[i]; //here only this line counts
        }

        static void Main()
        {
            int result;
            CalculateSquare(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, out result);
            Console.Write(result); //should output 140 for the example
            Console.ReadKey();
        }
    }
}

You may also input the square as 2-dimensional array or from a prompt or as string or some standard collection type. A 2-dimensional array is the only way not having to calculate the side length of the square yourself.
A sub-function for the actual work is not required, you could also put the code directly within Main().

Even more preparation is allowed for free, like here:

using System;
unsafe class Delacorte
{
    static void CalculateSquare(int* a, out int r)
    {
        r=0;while(*a>0)r+=*a++; //only this line counts
    }

    static void Main()
    {
        var input = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; //adding a terminator
        int result;
        fixed (int* a = &input[0]) //necessary in C#
            CalculateSquare(a, out result);
        Console.Write(result);
        Console.ReadKey();
    }
}

If you are unsure whether your lengthy preparation is in the spirit of these rules or could be called cheating, just ask :)

APL (38)

{.5×+/∊∘.{(∨/Z[⍺⍵])×+/⊃×⍨⍺-⍵}⍨⊂¨⍳⍴Z←⍵}

This is a function that takes a matrix as its right argument, like so:

      sq5←↑(10 8 11 14 12)(21 4 19 7 9)(5 13 23 1 16)(18 3 17 2 15)(24 22 25 6 20)
      sq5
10  8 11 14 12
21  4 19  7  9
 5 13 23  1 16
18  3 17  2 15
24 22 25  6 20
      {.5×+/∊∘.{(∨/Z[⍺⍵])×+/⊃×⍨⍺-⍵}⍨⊂¨⍳⍴Z←⍵}sq5
5957

Explanation:

⊂¨⍳⍴Z←⍵: store the matrix in Z. Make a list of each possible pair of coordinates in Z.
∘.{...}⍨: for each pair of coordinates, combined with each pair of coordinates:

+/⊃×⍨⍺-⍵: calculate distance^2: subtract the first pair of coordinates from the second, multiply both by themselves and sum the result
∨/Z[⍺⍵]: get the number in Z for both pairs of coordinates, and find the GCD
×: multiply them by each other

+/∊: sum the elements of the result of that
.5×: multiply by 0.5 (because we counted each nonzero pair twice earlier)


I am greater than you! Write a function or program that given a list of non negative integers, arranges them such that they form the largest possible number.

INPUT

[50, 2, 1, 9]

OUTPUT

95021

INPUT

0

OUTPUT

0

INPUT
(Interesting one)

[7, 76]

OUTPUT

776

RULES

standard loopholes apply.
Depending on your language you can use int(32) / int(64) or any other numeric datatype. (Please append the chosen type to your answer)
take a list as Input
you choose the behavior on empty input

GL

Python 2, 85 80 77 72 70 bytes

lambda l:''.join(sorted(map(str,l),key=lambda i:i+i[-1]*max(l))[::-1])

Try it online!

Sorts the numbers lexicographically, but each number is padded with its last  digit.

This means that 'shorter' numbers (string-wise) can be larger than 'longer' numbers:

Example:

Input: [76, 7]

Each number gets padded with its last digit: ['76666..','7777..']

Sorted (descending): ['7777..',76666..'], which gives [7, 76]

Joining the result gives: 776


Print all the numbers! (At least, as many as possible.) Your task is to print a number. Simple, right? It is simple, but not as simple as this. The first answer is to print the number 1, the second answer is to print the number 2, etc.

Rules

The first answer must print 1, and the nth answer must print n.
The first answer may be of any length.
Whitespace, comments, etc. are permitted.
The next answer's submission's length must within 1 unit of the previous answer's length. That is, if a submissions length is L, the next submission must be of length L + 1 or L - 1. The length is measured in characters, not bytes.
No language may be used more than once.
No person may answer earlier than eight hours after their most recent answer.
No person may answer twice in a row.
You may not use a REPL environment.

To win, you must have the most valid answers to this question. You may use a language updated after/ made later than this challenge so long as the language was not intended to answer this challenge.

Answer template

All answers must conform to this template.

# Answer N, Lang name, M characters

    program

 optional description

Leader board

A leader board will be maintained here in this section. (If anyone wants to create a leader board counting the number of submissions a person has, I will give them a 50 rep bounty on any answer to this question.)

Answer 8, Carrot, 3 bytes
8^

Note the trailing space.


Compute the Lambert W function Your challenge is to compute the Lambert W function. \$W(x)\$ is defined to be the real value(s) \$y\$ such that
$$y = W(x) \text{ if } x = ye^y$$
where \$e = 2.718281828...\$ is Euler's number.
Sometimes, \$y\$ may not be real.
Examples
W(-1) = non-real
W(-0.1) = -0.11183, -3.57715
W(1) = 0.56714
W(2) = 0.85261

Here's a quick graph of what this function looks like.

Rules
Your goal is to take an input and output either nothing, 1 solution, or 2 solutions, out to 5 significant figs. You should expect float inputs within the reasonable range of -100..100.
This is code-golf, so shortest code wins.

Octave, 36 34 bytes

@(x)(y=lambertw(-1:0,x))(~imag(y))

Try it online!

I solved this in 10 different ways without the builtin, but I couldn't get the solution for both the -1 branch and the 0-branch. I wasn't able to solve this without resorting to the builtin lambertw function. Even though it uses a builtin, it's far from straightforward.

lambertw will only give out one value by default, namely the W0(x), unless otherwise specified. The problem arises when we specifies that we want two values, both W0(x) and W-1(x). If this is the case, and x>=0, it will return one real and one complex result.

We therefore have to specify that we only want the results where the imaginary part of the result is zero.

Breakdown:

@(x)                              % Anonymous function that takes x as input
    (y=lambertw(-1:0,x))          % The lambertw function, with both the -1 and 0 branches
                        (~imag(y))  % Index, where the elements with imag(y)=0 is true


Let's converge to 9! Given an integer n > 2, print or return the smallest non-negative integer k such that a(n, k) = 9, where a(n, k) is defined by:

a(n, 0) = n
a(n, k+1) =

a(n, k) / 2 + 1 if a(n, k) is even
the sum of the digits of a(n, k)² (in base 10) if a(n, k) is odd

Examples

For n = 5, the expected output is k = 4:

a(5, 0) = 5
a(5, 1) = 7  (5² = 25 and 2 + 5 = 7)
a(5, 2) = 13 (7² = 49 and 4 + 9 = 13)
a(5, 3) = 16 (13² = 169 and 1 + 6 + 9 = 16)
a(5, 4) = 9  (16 / 2 + 1)

For n = 40, the expected output is k = 2:

a(40, 0) = 40
a(40, 1) = 21 (40 / 2 + 1)
a(40, 2) = 9  (21² = 441 and 4 + 4 + 1 = 9)

Clarifications and rules

The input is guaranteed to be greater than 2.
Your program should theoretically work for any value of n. (In practice, it may be limited by the maximum integer size supported by your language.)
k may be either 0-indexed or 1-indexed. Please state it in your answer.
This is code-golf, so the shortest answer in bytes wins!

First values

Below are the first values from n = 3 to n = 422, with k 0-indexed. (For 1-indexing, just add 1 to these values.)

 1  2  4  3  3  5  0  4  3  4  2  6  1  1  6  5  5  4  1  5  2  3  3  7  6  2  3  2  2  7
 6  6  5  6  6  5  1  2  2  6  6  3  1  4  3  4  4  8  1  7  6  3  5  4  6  3  2  3  3  8
 7  7  3  7  4  6  6  7  5  7  6  6  6  2  4  3  3  3  6  7  3  7  2  4  7  2  6  5  6  4
 7  5  2  5  6  9  6  2  3  8  2  7  1  4  6  6  6  5  1  7  4  4  3  3  7  4  3  4  2  9
 6  8  6  8  6  4  6  8  2  5  3  7  6  7  3  8  2  6  7  8  6  7  5  7  6  7  4  3  3  5
 6  4  3  4  4  4  6  7  6  8  3  4  6  8  7  3  6  5  6  8  3  3  2  7  6  6  5  7  6  5
 7  8  2  6  3  3  6  6  6  7  4 10  6  7  3  3  6  4  1  9  2  3  3  8  7  2  6  5  2  7
 7  7  6  7  3  6  7  2  4  8  3  5  6  5  6  4  2  4  6  8  3  5  6  4  7  5  2  3  6 10
 7  7  3  9  2  7  1  9  5  7  6  5  6  7  4  9  6  3  6  6  3  4  2  8  7  7  6  8  6  4
 7  9  4  3  3  7  7  8  3  9  4  7  6  8  3  6  6  8  7  7  7  8  6  5  7  4  6  4  2  6
 7  7  6  5  3  4  7  5  4  5  3  5  7  7  6  8  2  7  1  9  6  4  6  5  7  7  2  9  6  8
 7  4  3  7  4  6  6  7  6  9  3  4  6  4  2  3  3  8  1  7  6  7  2  6  7  8  3  7  5  6
 7  8  2  9  3  3  6  7  6  4  4  4  6  7  6  7  6  7  6  8  7  5  6 11  7  7  3  8  4  4
 7  4  6  7  3  5  6  2  2 10  6  3  6  4  3  4  4  9  7  8  3  3  6  7  7  6  4  3  6  8

Perl 6, 41 bytes (40 chars)

{+($_,{$_%2??[+] $_².comb!!$_/2+1}...9)}

Try it online!

This uses 1-indexing of k's, so it gives 1 higher answers than the examples in OP. If this is not what the 1-indexing means, I'll have to add 1 byte more.

Explanation: It's an anonymous function. We just use the Perl 6's facility for generating lists using recursion :—). It looks like this: (first element),(block that takes the previous element and gives the next)...(end condition). In this case, the first element is $_ (argument of the main function) and the end condition is 9 (fulfilled when we generate a 9). In the middle block, we use $_ to refer to its argument ( = the previous element of the sequence). The ?? !! is the old ternary operator (better known as ? :). Finally, we take the length of this list by forcing numerical context by +(...).

The last weird thing here is the sum of digits. Numbers are Cool (behave both like strings and numbers), so we use a string method .comb on $_² (give list of characters = digits), then adding the characters up (that converts them back to numbers).


How fast is my Hot Wheels car? Several years back, Hot Wheels made a simple flash game called "Formula Fuelers Racers"*.  To play the game, you select three ingredients from a fridge to put into your car, which is then raced against the computer's randomly-generated car.  It turns out the mechanics of this game are pretty simple.  First off, the actual race "time" of your car is randomly generated and has no bearing on whether or not you win the race.  Secondly, the winner of the race is determined by a score which is calculated from the selected ingredients (duplicate ingredients are allowed, and the order matters).  Each ingredient has an associated "value" and an associated "operation" as shown in the following table:

#   ingredient     val  op
1   Hot Salsa       2   +
2   Root Beer       1   +
3   Milk            1   +
4   Pickle Juice    2   +
5   Mystery Lunch   -3  *
6   BBQ Sauce       2   +
7   Egg             1   +
8   Ketchup         2   +
9   Mustard         -1  *
10  Melon           1   +
11  Chocolate Milk  1   +
12  Mayonnaise      -2  *
13  Baby Food       0   +
14  Pepper          1   +
15  Salt            2   +
16  Syrup           -1  *
17  Salad Dressing  2   +
18  Orange Juice    1   +
19  Soy Sauce       2   +

For convenience, this challenge will be referring to ingredients by their number and not their name.  Here are the steps to compute a score:

First, initialize the score with the value of the first ingredient.
Then, use the second ingredient's operation to combine the current score and the second ingredient's value to get an updated score.
Finally, use the third ingredient's operation to combine the current score and the third ingredient's value to get the final score.

Higher scores are better and always beat lower scores.

For example, the ingredients 1 2 3 have a score of (2+1)+1 = 4.  The ingredients 7 5 6 have a score of (1*-3)+2 = -1.  Therefore, 1 2 3 beats 7 5 6.

Challenge

In this challenge, you shall write a program which takes an ordered list of 3 integers and outputs the corresponding score.

Input

Your program may accept a list of three integers in the most convenient format.  You are allowed to use either 1-indexing for the ingredient names (as above) or 0-indexing (subtract 1 from every index above).

Ouput

Your program must output a single integer indicating the score.

Test Cases

4 5 5  =>  18 // max score
5 5 5  =>  -27 // min score
13 13 13  =>  0
1 2 3  =>  4
7 5 6  =>  -1
16 2 19  =>  2
19 7 12  =>  -6

*This page is pretty outdated and doesn't work in some browsers, but you don't need to play the game for this challenge.

Jelly, 24 bytes
“zẈ€$ụ¤’b6’ị@µỊị⁾+×żCFḊV

Takes a list of 0-indexed ingredients.
Try it online! or see a test suite
How?
Uses a slightly convoluted form of compressing the values as a base-6 number and the fact that the multiplicative entries are the negative ones. Instead of simply shifting up by 3 to get the base-6 digits, the complemented values incremented are used - this saves bytes by allowing the Ị atom to pick out the negative entries prior to the complement step while also saving a byte in the base-250 compression.
“zẈ€$ụ¤’b6’ị@µỊị⁾+×żCFḊV - Main link: 0-based ingredient list  e.g. [6,4,5]
“zẈ€$ụ¤’                 - base 250 compressed number: 120851767994004
        b6               - convert to base 6: [1,1,0,5,0,1,0,3,1,1,4,2,1,0,3,0,1,0,0]
          ’              - decrement: [0,0,-1,4,-1,0,-1,2,0,0,3,1,0,-1,2,-1,0,-1,-1]
           ị@            - index into [reversed @rguments]          [0,4,-1]
             µ           - monadic chain separation (call that x)
              Ị          - insignificant(x)? (abs(x)<=1)            [1,0,1]
                ⁾+×      - ['+','×']
               ị         - index into                               ['+','×','+']
                    C    - complement(x) (1-x)                      [1,-3,2]
                   ż     - zip                                      [['+',1],['×',-3],['+',2]]
                     F   - flatten                                  ['+',1,'×',-3,'+',2]
                      Ḋ  - dequeue                                  [1,'×',-3,'+',2]
                       V - evaluate as Jelly code                   -1


Recover polynomial \$f(x)\$ from \$f^2(x)\$ Related: Calculate \$f^n(x)\$, Polynomialception
Challenge
Given a polynomial \$f(x) = a_0 + a_1 x + a_2 x^2 + \cdots + a_k x^k\$ of order \$k\$, we can compute its composition with itself \$f\left(f(x)\right) = f \circ f(x) =: f^2(x)\$, which evaluates to another polynomial of order \$k^2\$.
The challenge is to reverse the process. Assuming \$f(x)\$ is an integer polynomial (\$a_0, a_1, \cdots, a_k \in \mathbb{Z}\$), take the polynomial \$f^2(x)\$ and recover the polynomial \$f(x)\$. This is equivalent to finding a functional square root of the given polynomial.
The polynomials may be input and output as a list of coefficients (highest-order term going first or last) or a built-in polynomial object. You may assume \$k \ge 1\$, i.e. \$f(x)\$ is not a constant. It is guaranteed that a solution exists. If multiple distinct \$f(x)\$s have the same \$f^2(x)\$, your program may output any nonempty subset of all solutions.
Standard code-golf rules apply. The shortest code wins.
Test cases
Coefficient list is given in highest-order-term-first order.
Input: x / coefficients: [1, 0]
Output: x, -x, or -x + c for any integer c / coefficients: [1, 0] or [-1, c]

Input: x + 20 / coefficients: [1, 20]
Output: x + 10 / coefficients: [1, 10]

Input: 25x - 18 / coefficients: [25, -18]
Output: 5x - 3 / coefficients: [5, -3]

Input: x^4 - 4x^3 + 8x^2 - 8x + 6 / [1, -4, 8, -8, 6]
Output: x^2 - 2x + 3 / [1, -2, 3]

Input: -x^4 - 2x^2 - 2 / [-1, 0, -2, 0, -2]
Output: -x^2 - 1 / [-1, 0, -1]

Input: x^9 + 6x^8 + 21x^7 + 58x^6 + 119x^5 + 194x^4 + 262x^3 + 260x^2 + 201x + 112 / [1, 6, 21, 58, 119, 194, 262, 260, 201, 112]
Output: x^3 + 2x^2 + 3x + 4 / [1, 2, 3, 4]

Input: x^9 + 6x^8 + 21x^7 + 54x^6 + 103x^5 + 154x^4 + 182x^3 + 160x^2 + 105x + 40 / [1, 6, 21, 54, 103, 154, 182, 160, 105, 40]
Output: -x^3 - 2x^2 - 3x - 4 / [-1, -2, -3, -4]

Input: x^9 / [1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Output: x^3 or -x^3 / [1, 0, 0, 0] or [-1, 0, 0, 0]

Python 2, 638 634 608 603 572 560 508 470 bytes (without brute force as well)
Tthanks to @randomdude999 for the golfing down the code by like 100 bytes as well as everyone who has helped point out smaller golfing tricks!

from gmpy2 import*
R=range
r=reduce
p=lambda n,i=1:n/i and[l+[i]for l in p(n-i,i)]+p(n,i+1)or[[]][n:]
e=lambda f,x:r(lambda y,z:y*x+z,f)
def s(g):
 n=isqrt(len(g));N=n+1;t,_=iroot(abs(g[0]),N)
 for F in(t,-t):
	f=[F]
	for i in R(1,N):f+=[0];f[i]=(g[i]-sum(fac(n)/fac(n-len(j))/r(mul,[fac(j.count(k))for k in R(i+1)])*r(mul,[f[k]for k in j])*F**(N-len(j))for j in p(i))-(i==n)*f[1]*F**~-n)/n/F**n
	if n<2:f[1]=g[1]/-~F
	if all(e(f,e(f,i))==e(g,i)for i in R(N*N)):return f

Try it online!
Explanation
In the code, the functions

m computes the multinomial coefficient \$\binom{n}{k_0,k_1,\dots,n-\sum k}\$
p list out all partitions of n (code from https://codegolf.stackexchange.com/a/84192/61039 (without this code was 601 bytes))
e evaluates our polynoimal
s does the actual functional square root

The way it works is by computing the coefficients of \$f\$ (of degree \$n\$) using the \$n+1\$th highest coefficients of \$f\circ f\$, then checks if the computation is correct as multiple polynomials can lead to the same highest coefficients. The way the computation works is by considering the following series of manipulations:
\begin{align*}
f(x)&=\sum_{i=0}^na_ix^i\\
f(f(x))&=\sum_{i=0}^na_i\left(\sum_{j=0}^na_jx^j\right)^i\\
&=\sum_{i=0}^na_i\sum_{k_0+k_1+\dots+k_n=i}\binom{i}{k_0,k_1,\dots,k_n}\prod_{j=0}^n a_j^{k_j}x^{jk_j}\\
&=\sum_{i=0}^na_i\sum_{k_0+k_1+\dots+k_n=i}\binom{i}{k_0,k_1,\dots,k_n}\left(\prod_{j=0}^na_j^{k_j}\right)x^{\sum_{j=0}^njk_j}\\
&=\sum_{k_0+k_1+\dots+k_n\leq n}a_{k_0+k_1+\dots+k_n}\binom{k_0+k_1+\dots+k_n}{k_0,k_1,\dots,k_n}\left(\prod_{j=0}^na_j^{k_j}\right)x^{\sum_{j=0}^njk_j}\\
&=\sum_{i=0}^{n^2}\left(\sum_{\sum_{j=0}^njk_j=i,k_i\geq0}a_{k_0+k_1+\dots+k_n}\binom{k_0+k_1+\dots+k_n}{k_0,k_1,\dots,k_n}\left(\prod_{j=0}^na_j^{k_j}\right)\right)x^i\\
\end{align*}
From here, if \$i>n^2-n\$, then \$k_1+\dots+k_n=n\$, forcing \$k_0=0\$ since \$a_{>n}=0\$. Furthermore,
$$\sum_{j=0}^njk_j=n\sum_{j=0}^nk_j-\sum_{j=0}^njk_{n-j}=n^2-\sum_{j=0}^njk_{n-j}$$
so the coefficient of \$x^{n^2-i}\$ for \$i<n\$ simplifies to
\begin{align*}
&\hphantom{=}a_n\sum_{\substack{\sum_{j=1}^njk_j=n^2-i\\k_0=0\\k_i\geq0}}\binom{n}{k_0,k_1,\dots,k_n}\left(\prod_{j=0}^na_j^{k_j}\right)\\
&=a_n\sum_{\substack{\sum_{j=0}^njk_{n-j}=i\\\sum_{j=0}^nk_j=n\\k_i\geq0}}\binom{n}{k_0,k_1,\dots,k_n}\left(\prod_{j=0}^na_j^{k_j}\right)\\
&=a_n\sum_{\substack{\sum_{j=0}^njk_j=i\\k_0=n-\sum_{j=1}^nk_j\\k_i\geq0}}\binom{n}{k_0,k_1,\dots,k_n}\left(\prod_{j=0}^na_{n-j}^{k_j}\right)
\end{align*}
and the \$\sum_{j=1}^njk_j=i\$ is really asking for partitions of \$i\$.
To extend this analysis to \$i=n\$ to get \$a_0\$, we simply notice that we need to include the case that \$1(n-1)+(n-1)n=n^2\$, i.e. we simply add \$a_0^{n-1}a_1\$.
The reason why this helps is this expansion gives us

\$x^{n^2}\$ coefficient of \$f\circ f\$ is \$a_n^{n+1}\$
\$x^{n^2-i}\$ coefficient is linear in \$a_i\$ for \$0<i<n\$ as the only term containing \$a_i\$ is \$na_0^na_i\$

As all terms in the coefficient of \$x^{n^2-i}\$ in \$f\circ f\$ only depends on \$a_{<i}\$ other than \$na_0^na_i\$, we can easily compute \$a_i\$. The only issue is when \$n\$ is odd, which gives us \$2\$ solutions for \$a_n\$.


Everyone Ought to Have a Friend An isolated character is a character (other than a newline) that doesn't have an adjacent character of the same type.  Adjacent characters can be to the left, the right above or below, but not diagonals.  For example in the following text H is isolated:

Ybb
YH%
%%%%

All the other characters are not isolated because each of them has at least one other character of the same type adjacent.

Your task is to write a program that takes a string as input and determines the number of isolated characters.

Scoring

You answer will be scored by two metrics.  The first is the number of isolated characters in your program.  You should aim to minimize this.  The second will be the number of bytes in your program.  You should minimize this as well.  Program size will act as a tie breaker for the first criterion.

Additional Rules

You should support input on the printable ascii range plus any characters you use in your program.
You may consider a line break to either be a newline character or a newline followed by a line feed.
You may take input in any reasonable format.  This includes a list of lines.

Test Cases

Ybb
YH%
%%%%

\$1\$

Aaaab
uuu
yyybbb

\$2\$

A

\$1\$

qqWWaaww

\$0\$

Python 2, 0 (350 344 314 309 301 298 291 bytes)

def f(tt):11
def f(tt):
 tt=tt.split('\n')
 r =0#.split('\n')
#r  0#
#for
 for  ii,ll in enumerate(tt):
  for jj,cc in enumerate(ll):
##for+=1-(
    r+=1-(cc in ll[(jj or 2)-1:jj+2:2]    +''.join(ll[jj:
 jj+1]for ll in tt[(ii or 2)-1:ii+2:2]))##+''.join(ll[jj:
#  +1]for
#print r
 print r

Try it online!

-7 bytes, thanks to Jo King


Natural Pi #0 - Rock Goal

Create a program/function that takes an input N, check if N random pairs of integers are relatively prime, and returns sqrt(6 * N / #coprime).

TL;DR

These challenges are simulations of algorithms that only require nature and your brain (and maybe some re-usable resources) to approximate Pi. If you really need Pi during the zombie apocalypse, these methods don't waste ammo! There are eight more challenges to come. Checkout the sandbox post to make recommendations.

Simulation

What are we simulating? Well, the probability that two random integers are relatively prime (ie coprime or gcd==1) is 6/Pi/Pi, so a natural way to calculate Pi would be to scoop up two buckets (or handfuls) of rocks; count them; see if their gcd is 1; repeat. After doing this a couple lot of times, sqrt(6.0 * total / num_coprimes) will tend towards Pi. If calculating the square-root in post-apocalyptic world makes you nervous, don't worry! There is Newton's Method for that.

How are we simulating this?

Take input N
Do the following N times:

Uniformly generate random positive integers, i and j
With 1 <= i , j <= 10^6
If gcd(i , j) == 1: result = 1
Else: result = 0

Take the sum of the N results, S
Return sqrt(6 * N / S)

Specification

Input

Flexible, take input in any of the standard ways (eg function parameter,STDIN) and in any standard format (eg String, Binary)

Output

Flexible, give output in any of the standard ways (eg return, print)
White space, trailing and leading white space is acceptable
Accuracy, please provide at least 4 decimal places of accuracy (ie 3.1416)

Scoring

Shortest code wins!

Test Cases

Your output may not line up with these, because of random chance. But on average, you should get about this much accuracy for the given value of N.

Input     ->  Output
-----         ------
100       ->  3.????
10000     ->  3.1???
1000000   ->  3.14??

APL, 23 bytes

{.5*⍨6×⍵÷1+.=∨/?⍵2⍴1e6}

Explanation:

?⍵2⍴1e6: generate a 2-by-⍵ matrix of random numbers in the range [1..106]
1+.=∨/: get the GCD of each pair and see how many are equal to 1. This calculates S.
.5*⍨6×⍵÷: (6 × ⍵ ÷ S)0.5


Place a Carcassonne tile The board game

In the board game "Carcassonne" players place tiles by matching their edges and earn the highest scores through creating large contiguous areas of terrain. The following are (roughly) the types and quantities of tiles included in the game:

#01 x4
 #02 x5
 #03 x8
 #04 x2

#05 x9
 #06 x4
 #07 x1
 #08 x3

#09 x3
 #10 x3
 #11 x4
 #12 x5

#13 x3
 #14 x3
 #15 x2
 #16 x5

#17 x5
 #18 x2
 #19 x3
 #20 x1

#21 x5
 #22 x2
 #23 x1
 #24 x1

#25 x1

The Task

You must place a tile by matching edges, while trying to maintain the largest possible contiguous areas of terrain.

Placement

Tiles can only be placed in one of the (up to 4) blank spaces adjacent to any existing tile (or tiles) in the play area.
Tiles can be rotated 90, 180 or 270 degrees.

Edge-matching

Edges of a placed tile must match the touching edges of the (up to 4) neighbouring tiles, i.e. touching pixels are the same colour.

Contiguous terrain

"Closing an area of terrain" refers to placing a tile such that any contiguous area of colour could not then be continued with further tile placements.
If an alternative placement is possible, it must be chosen over any tile placement that would close an area of terrain.
If you have to choose between a number of closing placements, choose any. If you have to choose between a number of non-closing placements, choose any.
Disregard #ff00ff (the corner pixels) when calculating contiguous areas. Also disregard buildings, i.e. areas of colour already fully enclosed within a tile.

Input

Input is two images:

The play area.

The initial play area consists of tile #11 (a single tile).
The augmented play area created as output must also be supported as input.

The tile to be placed.

All of the example tiles must be supported as input.

Determine matching edges/contiguous terrain using this image data alone. No hardcoding.

Output

Output is an image showing the resultant play area after placing the tile.
The image must be compatible with your own program,  i.e. it can be used as play area input.
If it's impossible to place a tile, return an error.

You can assume that

Tiles are always 55 px by 55 px
Tiles will only ever feature the colours currently used in the example tiles.

Notes

Your answer must feature example output after at least 2 passes (more is encouraged).
This is a partial and inaccurate rendering of the original board game, you don't need to apply any of the rules or tactics not mentioned here.

Score

Your score is your submission's byte count.
Image data isn't included in your score.
Lowest score wins.

Playing a full game

You may wish to write a script that uses your submissison to play a full game, which might consist of:

Placing a tile chosen pseudorandomly from the full set of 85.
Returning the tile to the set if it can't be placed.
Repeating until every tile has been placed - or until two tiles in a row can't be placed.

It won't be included in your byte count, or improve your score, but I'll likely offer a bounty to this kind of answer.

Common Lisp, 2650 2221 1992 1186 1111 bytes

Update: "Easy" golfing now done, further gains will require bigger changes.

Update 2: With the competition getting fiercer, the new version no longer favors positions inside the current playing field rectangle (that would be 57 bytes extra). This option, as well as a simple speed optimization, is by enabled by default in the downloadable version with the simulator, but not in the official answer below.

Update 3: Minor interface changes for major byte count gains.

I created a simple Web UI as well. The full package (a single LISP file and the tile images) can be downloaded here. To try it, install hunchentoot, zpng and png-read with quiclisp, load in carcassonne.lisp, and connect to localhost:8080. The code has been tested on CCL/Windows and SBCL/Linux. The above mentioned libraries are only needed for the UI/simulator part; the solution itself is plain ANSI Common Lisp.

(defun c(f p &aux b a s z(c 55))
  (macrolet((d(v l &body b)`(dotimes(,v,l),@b))
            (b(b c)`(d i c(d j c(setf,b,c))))
            (r(&rest p)`(aref,@p))
            (n(u v i j)`(and(setf l(*(f,u,v)l))
                            (find(r f(+,u,i)(+,v,j))`(0,(r f,u,v))))))
    (labels((p(p w)(d y(ceiling w 2)(d x(- w y y)(rotatef(r p y #6=(+ x y))(r p #6##7=(- w y))(r p #7##8=(- w x y))(r p #8#y)))))
            (a(y x)(or(if(= 0(r f y x))1 #4=(and(= 1(incf(r s y x)))(=(r f y x)z)(push`(,y,x)a)0))0))
            (f(y x)(setf z(r f y x))(if #4#(loop for((y x))= a while(pop a)maximize(+(a(1- y)x)(a y(1- x))(a(1+ y)x)(a y(1+ x))))1)))
      (d i 8(when(d x #1=(array-dimension f 0)(or(= 0(r f(- #1#52 i)x))(return t)))(setf f(adjust-array f`(#2=,(+ #1#c)#2#))))(p f(1- #1#)))
      (d i 4(d u #9=(/ #1#c)(d v #9#
        (let((y(* u c))(x(* v c))(l 9e9))
          (when(= 0(r f y x))
            (b #10=(r f(+ y i)(+ x j))(r p i j))
            (setf s(make-array`(,#1#,#1#))a())
            (ignore-errors(if(> #11=(*(loop for d from 1 to 53
                                            sum(+(n y #3=(+ x d)-1 0)(n #5=(+ y d)(+ 54 x)0 1)(n(+ 54 y)#3#1 0)(n #5#x 0 -1)))
                                      (1+ l))
                                (or(car b)0))
                             (setf b`(,#11#,i,y,x))))
            (b #10#0)))))
         (p p 54))
      (when b(d j(cadr b)(p p 54))(b(r f(+(third b)i)(+(nth 3 b)j))(r p i j)))
      `(,f,b))))

All line feeds and line-starting spacing are for cosmetics only, to ensure legibility, and not counted into the total sum.

You should call the function c with two arguments: The current play field, and the tile to place. Both should be 2D arrays; the tile 55x55 and the field a multiple of that. Additionally, the field array must be adjustable. The function returns a two-element list with the new field as its first argument. The second element is NIL if the tile cannot be placed, or otherwise a list containing the top-left coordinates and rotation of the latest tile on that array and the score for that tile. This information can be used for visualization purposes.

Note that in further calls, you must use the new field returned by c even if the second list element is NIL (the original array may have been adjust-arrayed and thus invalidated).

The code is now a bit on the slow side, byte count optimization resulting in redundant calculations. The example below completed in about three minutes on my system.

Example run for all 85 tiles:

Web UI screenshot:


Who's next to me in the queue? Problem 4 in the 2019 BMO, Round 1 describes the following setup:

  There are \$2019\$ penguins waddling towards their favourite restaurant. As
  the penguins arrive, they are handed tickets numbered in ascending order
  from \$1\$ to \$2019\$, and told to join the queue. The first penguin starts the queue.
  For each \$n > 1\$ the penguin holding ticket number \$n\$ finds the greatest \$m < n\$
  which divides \$n\$ and enters the queue directly behind the penguin holding
  ticket number \$m\$. This continues until all \$2019\$ penguins are in the queue.

The second part of the question asked candidates to determine the penguins standing directly in front of, and directly behind, penguin \$33\$. This could be done by examining the patterns in the queue, considering prime factors: see the online video solutions for more information.

The Challenge

Your task is to design a program or function which, given a positive integer \$k\$ representing the penguin with ticket number \$k\$, outputs the ticket numbers of the penguins directly before and after this penguin.

For example, penguin \$33\$, stands directly behind \$1760\$ and directly in front of \$99\$, so the program should output, in some reasonable format, \$[1760, 99]\$.

Rules

The input will be an integer in the range \$1 < k \le 2019\$.
Your program should output two integers, in any reasonable format, representing the ticket numbers of the penguins before and after.
These can be output in any order, (front first or behind first) but this order must be consistent.
The penguin will not be at the front or back of the queue: so you don't have to handle the edge cases of \$k = 1\$ or \$k = 1024\$.
As penguins find it difficult to read human glyphs, your program should be as short as possible. This is a code-golf - so the shortest program (in bytes) wins!

Test Cases

These outputs are given in the format [front, behind].

33   -> [1760, 99]
512  -> [256, 1024]
7    -> [1408, 49]
56   -> [28, 112]
1387 -> [1679, 1241]
2019 -> [673, 1346]
2017 -> [1, 2011]
2    -> [1536, 4]

Perl 6, 79 76 71 bytes

{($!=sort {[R,] -$_,{first $_%%*,$_^..1}...1},^2020)[+(@$!...$_)X-2,0]}

Try it online!

Sorts numbers 1 to 2019 lexicographically by the reversed, negated sequence of largest divisors, then finds the neighbors. Example mappings:

1760 => (-1 -11 -55 -110 -220 -440 -880 -1760)
  33 => (-1 -11 -33)
  99 => (-1 -11 -33 -99)

In other words, the negated cumulative product of prime factors in descending order.


Golfing Chain (Cops' Thread) This is a Cops and Robbers challenge. For the Robbers' thread, go here.

The Cops have three tasks.
1) Pick a sequence from the OEIS.

2) Pick a language (this is suggested to be a golflang, but doesn't have to be) that, when given input n, outputs A(n) (where A(n) is the sequence chosen) using all usual code-golf rules.
Call this language LA and code CA.
For example, Jelly and Jelly_code.

3) Then, pick a different language (this is suggested to be a non-golflang, but doesn't have to be) and write code that takes no input and outputs code CA, again following all usual code-golf rules. (Note: this can be obfuscated code and doesn't necessarily need to be golfed, but the longer this code is the easier it will be for the robbers to crack your submission.)
Call this language LB and code CB.
For example, Python and Python_code.

The Cop's submission to this challenge is the sequence (specified whether 0- or 1-indexed), the name of the two languages LA and LB (and which one solves which part), and the byte-count of CB only. Keep the actual code of both parts, and the length of CA, secret.

For the Cop, links to documentation for LA and LB, or an interpreter (or a TIO link, since that includes both), are appreciated but not required.

The Robber's challenge is to select a Cops' entry and write code CC in the same LB language that outputs some code in the same LA language that solves the original OEIS task. The length of CC can be no longer than the length of CB as revealed by the cop (though may be shorter). Note: The code produced by CC does not have to match CA.

For our example, this means that the Robber has to write Python code that outputs Jelly code that solves the original OEIS sequence, and that Python code has to be no longer than the length revealed by the Cop.

Winning conditions

Answers that have not been cracked in a week can have their solutions revealed, at which point they are considered Safe. Note that if you don't reveal your solution after a week, it can still be cracked. The Cop with the shortest Safe answer wins.

OEIS A000041, cracked by ETHproductions
Let's try it the other way around: golflang generates non-golflang.

a(n) = number of partitions of n (the partition numbers).

a(n) (0-indexed) is returned by a JavaScript function (ES6)
The program that outputs the JS function is written in Jelly
The length of the Jelly program is 35 bytes

Intended solution

    Jelly: “¦ṚoIwƭ- ḊFæSḂ¥¶Ẉ|ḊJƓƝʋnrB⁾’b28+40Ọ

    which outputs

    JS: C=(A,B=A)=>A<0?0:A?B?C(A,B-1)+C(A-B,B):0:1


End the tabs versus space war End the tabs versus space war

So, there has been a great deal of debate of whether to use tabs or spaces to indent/format code. Can you help the university settle the dispute, by going to an incredibly crazy unique method of formatting.

Your job is to write a full program or function which expands all tabs into four spaces. And then replaces a run of n leading spaces with "/(n - two stars here)/". You will receive input over multiple lines in any reasonable format (single string array of strings for each new line. Columnar array etc.)

Sample input shamelessly stolen. Note that since tabs get automagically expanded to four spaces on SE I represent it as the "^" character, but you must handle tabs (codepoint 0x09) as well. All "^" characters represent a tabulation.

Calculate the value 256 and test if it's zero
If the interpreter errors on overflow this is where it'll happen
++++++++[>++++++++<-]>[<++++>-]
+<[>-<
    Not zero so multiply by 256 again to get 65536
    [>++++<-]>[<++++++++>-]<[>++++++++<-]
    +>[>
        # Print "32"
        ++++++++++[>+++++<-]>+.-.[-]<
    <[-]<->] <[>>
        # Print "16"
        +++++++[>+++++++<-]>.+++++.[-]<
<<-]] >[>
    # Print "8"
    ++++++++[>+++++++<-]>.[-]<
<-]<
# Print " bit cells\n"
+++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<.
>>.++.+++++++..<-.>>-
Clean up used cells.
[[-]<]l
^this is preceded by a tab
^^two tabs
^^^three tabs etcetera!

Sample output

Calculate the value 256 and test if it's zero
If the interpreter errors on overflow this is where it'll happen
++++++++[>++++++++<-]>[<++++>-]
+<[>-<
/**/Not zero so multiply by 256 again to get 65536
/**/[>++++<-]>[<++++++++>-]<[>++++++++<-]
/**/+>[>
/******/# Print "32"
/******/++++++++++[>+++++<-]>+.-.[-]<
/**/<[-]<->] <[>>
/******/# Print "16"
/******/+++++++[>+++++++<-]>.+++++.[-]<
<<-]] >[>
/**/# Print "8"
/**/++++++++[>+++++++<-]>.[-]<
<-]<
# Print " bit cells\n"
+++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<.
>>.++.+++++++..<-.>>-
Clean up used cells.
[[-]<]l
/**/this is preceded by a tab
/******/two tabs
/**********/three tabs etcetera!

Because the university needs space to download both Vim and Emacs, you are allowed very little storage for your code. Therefore this is code-golf and the shortest code wins. You may assume that input is well formed and lines with less than four spaces (after replacement of tabs) may result in undefined behavior.

Disclaimer

This "excellent" formatting strategy came courtesy of Geobits, and is reproduced with his permission. No programmers were harmed during the production of this challenge.

Vim, 37, 34, 33, 32 bytes

:%s/\t/    /g|%norm ^hr/hv0r*r/

Try it online!

Note that this requires a trailing carriage return (enter) in vim, although not in the online interpreter.

This uses the V interpreter because it's backwards compatible. A very straightforward solution.

Here's a gif that lets you see the solution happen in real time. This uses a slightly older version, and I added some extra keystrokes to make it run slower so you can see what happens:

And here is the explanation of how it works:

:%s/\t/    /g           "Replace every tab with 4 spaces
|                       "AND
%norm                   "On every line:
      ^                 "  Move to the first non-whitespace char
       h                "  Move one character to the left. If there is none, the command will end here.
         r/             "  Replace it with a slash
           h            "  Move to the left
            v0          "  Visually select everything until the first column
              r*        "  Replace this selection with asterisks
                r/      "  Replace the first character with a slash


Fill in the Number Blanks You are given a list of 2-tuples of positive integers, of the form:

a1 b1, a2 b2, ..., an bn

In other words, the 2-tuples are comma-separated, and the integers within each tuple are space-separated. All of the a numbers are in strictly increasing order, as well as the bs. Your goal is to "fill in the gaps." What is meant by that is the following:

If ai+1 == ai+1, don't do anything.
Else if ai+1 < ai+1, you will insert tuples into the sequence as follows: ai bi, ai+1 bi+1, ai+2 bi+1, ..., ai+1-1 bi+1, ai+1 bi+1.

In other words, if there is a "gap" in the ai, then you will insert more into the list with the inserted bs to be bi+1 (the end of the gap).

Example:

Input: 6 125, 7 170, 10 185

Output: 6 125, 7 170, 8 185, 9 185, 10 185

Scoring: the score of the submission is the number of bytes needed to construct a program to, when given a string as described above, output in the same format the "filled" list of tuples.

Lowest score wins!

CJam, 42 41 39 38 bytes

q~,]:T(\-2=),>{IST2/z~\{I<!}#=,',S}fI&

Try it online in the CJam interpreter.


Code close to the challenge: Inception This is a sequel to this challenge: Code close to the challenge: Sum of integers

The challenge in this one is a bit harder, and also makes for a cool title (Which is why I picked it):

  Calculate the Levenshtein distance between two strings

Just like last challenge, your score in this challenge is the Levenshtein distance between your code and the quote above.

So now for the details!

Your program will take 2 inputs, both strings with no trailing spaces or newlines, and will output the Levenshtein distance between them. Levenshtien distance is defined as the number of of additions, deletions, and substitutions necessary to transform one string to another. For more information on how to calculate it, see the Wikipedia page linked above. To test if your program works, use this calculator.
Your program must output nothing but the Levenshtein distance between the two strings. It will be disqualified if anything else is outputted.
Example I/O:

Inputs:
test
test2
Output:
1

Inputs:
222
515
Output:
3

Inputs:
Test
test
Output:
1

Your code may not have no-ops or comments.

Frink, distance 24

Calculate[the,Levenshtein]:=editDistance[the,Levenshtein]

To use this, you would call Calculate with the two strings, and since this is returning, you also need to surround the call with print[]. If this isn't allowed, my score is 30.

Example:

Calculate["kitten","spork"]        -> returns 6
print[Calculate["kitten","spork"]] -> prints 6.

You need to download Frink, as the web interpreter doesn't allow defining functions. It should run on all systems, considering it's a Java applet. Download instructions here..

Psst. Hey! Here's a Levenshtein implementation in Symbolic, something I'm working on: k=λ:Δ(ί,ί).


Help Trump build the wall! Trump needs the wall constructed and you are going to do it! To most efficiently build his wall I have created a simple, repeatable pattern for you to use:

    __   __
   |  |_|  |
___|       |___
-   -   -   -
 - - - - - - -
- - - - - - - -
———————————————

Trump will tell you how many wall segments he needs and you will build them to look just like this.

Here is the pattern:

    __   __     <-- 4-2-3-2-4          ' _ _ '
   |  |_|  |    <-- 3-1-2-1-1-1-2-1-3  ' | |_| | '
___|       |___ <-- 3-1-7-1-3          '_| |_'
-   -   -   -   <-- 1-3-1-3-1-3-1-1    '- - - - '
 - - - - - - -  <-- 1-1-...-1-1        ' - -...- - '
- - - - - - - - <-- 1-1-...-1-1        '- - ... - -'
——————————————— <-- 15                 Unicode U+2014

Input will always be an integer >0.

Test cases:

1
    __   __
   |  |_|  |
___|       |___
-   -   -   -
 - - - - - - -
- - - - - - - -
———————————————

2
    __   __        __   __
   |  |_|  |      |  |_|  |
___|       |______|       |___
-   -   -   -  -   -   -   -
 - - - - - - -  - - - - - - -
- - - - - - - -- - - - - - - -
——————————————————————————————

5
    __   __        __   __        __   __        __   __        __   __
   |  |_|  |      |  |_|  |      |  |_|  |      |  |_|  |      |  |_|  |
___|       |______|       |______|       |______|       |______|       |___
-   -   -   -  -   -   -   -  -   -   -   -  -   -   -   -  -   -   -   -
 - - - - - - -  - - - - - - -  - - - - - - -  - - - - - - -  - - - - - - -
- - - - - - - -- - - - - - - -- - - - - - - -- - - - - - - -- - - - - - - -
———————————————————————————————————————————————————————————————————————————

Since you need to do this fast, write the shortest program possible!

If it helps, I wrote the challenge first, title last ;)

CJam, 52 bytes

F,ri*"s@;b6(MBZF,fu"128b6b"_
|-—"f=N/ff=zN*

Includes a bunch of unprintable ASCII characters. The hexdump of the first string literal pushed is:

01 73 06 40 3B 62 36 28 1E 4D 07 42 5A 14 1B 46 2C 66 75

Try it here!

Explanation

The above hexdump is interpreted as a base-128 number, then converted to base 6, to get this list:

[1 1 1 1 0 0 1 1 1 0 0 2
 1 1 1 3 1 1 3 0 3 1 1 3 2
 0 0 0 3 1 1 1 1 1 1 1 3 2
 4 1 1 1 2
 1 4 2
 4 1 2
 5]

To this, we apply the mapping 0 → _, 1 → space, 2 → \n, 3 → |, 4 → -, 5 → —. This gets us the string:

    __   __
   |  |_|  |
___|       |
-
 -
-
—

It consists of the "period" of each line; i.e. we can cycle the fifth line " -" to get " - - - - - - - ".

Then, we execute this subprogram:

N/               Split into lines.
  Ff*            Repeat each line 15 times (to cycle it).
     Ff<         Take the first 15 chars of each line.
        rif*     Repeat these chars input() times.
            N*   Join lines.

(The new version does this in a slightly different way that I actually can't wrap my head around myself very well, because it uses ff=.)


Generate lowest degree polynomial from sequence Introduction
A sequence of numbers is passed in as the input. The program has to generate the lowest degree polynomial possible. This was my first programming project in college and it would be interesting to see how much smaller the solution could have been.
Challenge
The input is a list of integers separated by a comma. The output is simply the equation that generates that sequence. The exact output of the equation is up to you i.e. no spaces are required between terms of the polynomial but it has to be human readable. The equation has to be expressed with the variable x. The first integer in the supplied sequence will correspond with x = 1, the second integer supplied would be x = 2 etc.
i.e.

x^2

would result in the sequence

1,4,9,16 NOT 0,1,4,9

Example Input and Output
Input:

5,14,27,44

Output:

2x^2 + 3x

Edit
I marked the questions as duplicate, thanks for the head up.

Pari/GP, 28 bytes

l->polinterpolate([1..#l],l)

Try it online!


The Arithmetic Derivative The derivative of a function is a cornerstone of mathematics, engineering, physics, biology, chemistry, and a large number of other sciences as well. Today we're going to be calculating something only tangentially related: the arithmetic derivative.

Definition

The arithmetic derivative a(n) or n' is defined here (A003415) by a number of properties that are similar to the derivative of a function.

a(0) = a(1) = 0,
a(p) = 1, where p is any prime, and
a(mn) = m*a(n) + n*a(m).

The third rule is based on the product rule for differentiation of functions: for functions f(x) and g(x), (fg)' = f'g + fg'. So with numbers, (ab)' = a'b + ab'.

Also of note, since the arithmetic derivative can be extended to the negative numbers via this simple relation, a(-n) = -a(n), the input may be negative.

Rules

Write a program or function that, given any integer n, returns the arithmetic derivative of n.
Inputs will be -230 < n < 230, to avoid problems with integer sizes and numbers too large to factor in a reasonable amount of time. Your algorithm should still be able to theoretically calculate the arithmetic derivative of numbers outside this range.
Built-ins for symbolic math, prime factorization and differentiation are allowed.

Examples

> a(1)
0
> a(7)
1
> a(14)   # a(7)*2 + a(2)*7 = 1*2 + 1*7 = 9
9
> a(-5)   # a(-5) = -a(5) = -1
-1
> a(8)    # a(8) = a(2**3) = 3*2**2 = 12
12
> a(225)  # a(225) = a(9)*25 + a(25)*9 = 6*25 + 10*9 = 150 + 90 = 240
240
> a(299792458)  # a(299792458) = a(2)*149896229 + a(7)*42827494 + a(73)*4106746 + a(293339)*1022 = 1*149896229 + 1*42827494 + 1*4106746 + 1*1022 = 149896229 + 42827494 + 4106746 + 1022 = 196831491
196831491

As always, if the problem is unclear, please let me know. Good luck and good golfing!

MATL, 12 bytes

|1>?GtYf/s}0

Try it online!

Explanation

Consider an integer a with |a|>1, and let the (possibly repeated) prime factors of |a| be f1, ..., fn. Then the desired result is a·(1/f1 + ... + 1/fn).

|1>     % take input's absolute value. Is it greater than 1?
?       % if so:
  Gt    %   push input twice
  Yf    %   prime factors. For negative input uses its absolute value
  /     %   divide element-wise
  s     %   sum of the array
}       % else:
  0     %   push 0


TiB, not TB, Seriously? If you're like me (and/or use Windows), You should have found this issue quite disturbing.
You plug in a hard drive (2TB for my occasion), and realize it doesn't show as 2TB, but a bit smaller size which is clearly not 2TB.
Over some research, I found it was because of Microsoft's mistake. Mistyping Binary prefix as Decimal prefixes. (i.e. They typed 1TiB as 1TB)
So, I would like to see a Binary prefix to Decimal prefix program. Since this is a big problem (and some computers are literally toasters), You have to make your program as short as possible.
conversion chart I found

I/O
You will be given the size (positive real number, will not exceed 2ˆ16 when converted), and the unit (4 of them, KiB, MiB, GiB and TiB, each corresponds to 1024ˆ1, 1024ˆ2, 1024ˆ3 and 1024ˆ4 bytes)
You have to output the (decimal representation of) the size (rounded half-up to integer value), and the corresponding unit.

Examples
678 MiB => 711 MB
1.8 TiB => 2 TB

Tip: Google has a unit converter


Find the largest recurring prime Inspired by Find the largest fragile prime

A recurring prime (or whatever you choose to call it) is a prime that, when removing leading digits, always remain prime regardless of how many digits are removed.

for example
6317 is a recurring prime because...
317 is a recurring prime because...
17 is a recurring prime because...
7 is a prime

727 is a prime but not a recurring prime because 27 is not a prime.

Goal
Like the original question, your score is the largest recurring prime found by your program/ algorithm.

Rules
I copied these from the original question

You may use any language and any third-party libraries.
You may use probabilistic primality tests.
Everything is in base 10.

Edit: Welp... turns out I have not factored in adding zeros in this question. Although I have not thought about adding 0 at first but it indeed satisfy my requirements, since removing a digit in front of (any number of) zeros skips many digits of prime tests and returns trivially true if the last few digits is a recurring prime. To make this question less of a "zero spam" but also reward strategic use of zeros, at most 2 consecutive zeros can be present in your answer. (Sorry to Level River St who asked me this)

Python 3, 79 digits (probably optimal)

A simple depth first search that allows up to two consecutive zeros.

from sympy.ntheory.primetest import isprime

def dfs(n=0, k=1):
    yield n
    if 100*n > k:
        yield from dfs(n, k*10)
    for i in range(1,10):
        if isprime(k*i + n):
            yield from dfs(k*i + n, k*10)

l = 1
for prime in dfs():
    if prime > l:
        d = len(str(prime))
        print(f'{d} digits: {prime}')
        l = 10**d

Try it online! Validate the result!

Finds 200400201909005006060042636079002004200130030090050030780060900408062003 (72 digits) in 8 seconds on TIO. I let the program run on my computer a little longer and the highest recurrent prime it found is 7030560306007020600400306654060053003909007054300609009069003056030702030330347 (validation). The program actually completed after finding this number, so this is probably the longest prime meeting the challenges requirement.

Note that sympys isprime could theoretically return true for pseudoprimes >2^64, though no examples are known as of now.

Python 3, 24 digits

only considers numbers without zeros

from sympy.ntheory.primetest import isprime

def dfs(n=0, k=1):
    yield n
    for i in range(1,10):
        if isprime(k*i + n):
            yield from dfs(k*i + n, k*10)

l = 1
for prime in dfs():
    if prime > l:
        print(f'{len(str(prime))} digits: {prime}')
        l *= 10

Try it online! Validate the result!

Finds 357686312646216567629137 in less then a second on TIO.


IPV4 subnet list cleaner (in CIDR notation) We have a lot of IPV4 address, to group into subnets, so we need a tool for doing this:

Our list is very ugly, not ordered and sometime in subnet notation, sometime in simple address.

Sample:

192.168.5.16/30
192.168.5.18
192.168.2.231/27
192.173.17.0/24
192.168.1.5/32
192.168.5.18/32
192.168.3.0/24
192.168.2.231/27
192.168.2.245/29
192.168.4.0/29
192.173.16.0/24
192.173.18.0/24
192.173.19.0/24
10.100.12.24

some explanation about the input (our old list):

each line hold only 1 IPV4 subnet
if a line don't contain any subnet info like on line 2, it's a single ip, so the 32 bit mask is to be considered.
subnet info is in the CIDR form: IPV4/integer where integer is mask length
IPV4 is not necessarely the base (first in range) of subnet
list is not sorted
list is not short... could make more the 60k entries...
there is repetition, overlap of subnets... lot of useless lines

( The last is the main reason we need to build this tool! ;-)

From this sample list we want to obtain shortened, sorted and cleaned list like:

10.100.12.24/32
192.168.1.5/32
192.168.2.224/27
192.168.3.0/24
192.168.4.0/29
192.168.5.16/30
192.173.16.0/22

Where all lines is subnet and all IPV4 part is base IP (begin of range), sorted, and without overlap or repetitions.

And where all IP present somewhere in input is present and no one more!

CIDR

For informations about:

Subnetting http://en.wikipedia.org/wiki/IPv4_subnetting_reference
CIDR notation http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation

Code golf

Input values could be given as you will, (arguments, read from file or STDIN)
Output to STDOUT, one subnet per line.
Output has to be sorted by the unsigned integer value of IPV4 (big-endian)
Output has to contain as few lines as possible
Of course, sum of output subnet must match sum of input subnet! no more, nor less!  So 0.0.0.0/0 which override everything is not accepted! (unless it's the only valid answer, see last test)
Use of libraries forbiden! Standard loophole applies
Shortest code wins!

Test cases

For testing this, (under bash) I use something like:

for i in {167772416..167774464};do
     echo $[i>>24].$[i>>16&255].$[i>>8&255].$[i&255]
  done

as input, this must render:

10.0.1.0/24
10.0.2.0/23
10.0.4.0/22
10.0.8.0/24
10.0.9.0/32

or

for i in {167772416..167774464};do
     [ $i -gt 167773316 ] && [ $i -lt 167773556 ] ||
         echo $[i>>24].$[i>>16&255].$[i>>8&255].$[i&255]/30
  done

Note, I've added /30 after each ip. this will do a lot of overlap!

10.0.1.0/24
10.0.2.0/23
10.0.4.0/25
10.0.4.128/29
10.0.5.116/30
10.0.5.120/29
10.0.5.128/25
10.0.6.0/23
10.0.8.0/24
10.0.9.0/30

Extreme test rule

63.168.3.85/2
64.168.3.85/2
192.168.3.85/2
191.168.3.85/2

This special case must render:

0.0.0.0/0

Accepted answers

As this question seem not so easy, I will add time from question to the list

  CJam, 101 - user23013 - 38 hours
  Perl, 223 - nutki - 1 week
  Pure bash, 1040 - F.Hauri - 4 days

CJam, 101 95 94
qN/{'//('./1\+256b2b\{i)<}/}%_|{{):T;_aM+:M(a&}gT+}%${_2$#!{;}*}*]{_(!a32*+32<8/2fb'.*'/@,(N}%

The {~}2j construct didn't make it shorter...
Try it here. (And link for Firefox.)
Explanation
qN/               " Read each line. ";
{                 " For each line: ";
    '//           " Split by / ";
    ('./          " Split first item by . ";
    1\+256b2b     " The address + 2^32 in base 2, which always has length 33 ";
    \{i)<}/       " For each other items N (if any), get the first N+1 bits. ";
}%
_|                " Remove duplicates. ";
{                 " For each item (each array of bits): ";
    {             " Do: ";
        ):T;      " Remove last bit and save it in T. ";
        _aM+:M    " Add the array to M. ";
        (a#)      " Find the array in the original M. ";
    }g            " while it is found. ";
    T+            " Append the last T back. ";
}%
$                 " Sort. ";
{                 " Reduce and wrap in array: ";
    _2$#!         " Test if the previous string is a prefix of the current. ";
     {;}*         " If so, discard it. ";
}*]
{                 " For each item (each array of bits): ";
    _(!a32*+32<   " Remove first bit and pad to 32 bits to the right. ";
    8/2fb'.*      " Convert to IP address. ";
    '/@,(         " Append / and original length - 1. ";
    N             " Append a newline. ";
}%


Shortest 8-bit xor cipher 8-bit XOR encryption takes a single byte and XORs every byte in the file by that byte. Here is a reference program in C++:

/*xorcipher.cpp
 *Encrypts a file using 8-bit xor encrytpion
 */

#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

int main(int argc, char** argv){
   ifstream* in = NULL;
   ofstream* out = NULL;

   if(argc < 3){
      cerr << "Usage: xor <key> <filename...>" << endl;
      exit(1);
   }

   int key = atoi(argv[1]);

   for(int x = 2; x < argc; x++){
      in = new ifstream(argv[x], ios::binary);
      if(!in->good()){
         cerr << "Error reading from " << argv[x] << endl;
         exit(1);
      }

      //Get file size
      in->seekg(0, ios::end);
      int size = in->tellg();
      in->seekg(0, ios::beg);

      //Allocate memory
      int* data = new int[size];

      int c = 0;
      for(int y = 0; (c = in->get()) != EOF; y++)
         data[y] = c ^ key;

      in->close();
      delete in;
      in = NULL;

      out = new ofstream(argv[x], ios::binary);
      if(!out->good()){
         cerr << "Error writing to " << argv[x] << endl;
         exit(1);
      }

      for(int y = 0; y < size; y++)
         out->put(data[y]);

      out->flush();
      out->close();
      delete out;
      out = NULL;

      delete[] data;
      data = NULL;
   }
   cout << "Operation complete" << endl;

   return 0;
}

The shortest answer (whitespace doesn't count) that produces the same end result will be selected. It does not have to store everything in memory at once or open and close every file multiple times. It can do anything as long as a file encrypted with the reference program can be decrypted with the answer, and vice versa.

Edit: The above program is not a specification. The only requirement is that answers should be able to decrypt a file encrypted with the above program, and the above program should be able to decrypt a file encrypted with the answer. I'm sorry if that was unclear.

The above program can be compiled with:

g++ xorcipher.cpp -o ~/bin/xor

It can be run like this:

xor <key> <filename...>

For example, if the key is 42 and the file is alpha.txt, you would use:

xor 42 alpha.txt


Implement Ash's float division Ash has a bit of an interesting float division algorithm. It's designed to never return NaN, and things like signed zero and infinity need to be handled.
How it works:
Assume the inputs are positive for the rules below. One input being negative will always result in the output being negative, and both being negative will result in a positive output.

Zero divided by anything is 0
Anything other than 0 divided by 0 is Infinity
Anything other than Infinity divided by Infinity is 0
Infinity divided by anything other than Infinity is Infinity
Infinity divided by Infinity is 1
All other division works as normal

I/O:
For languages with floats that support signed zero and positive/negative infinity, floats are an accepted I/O format. For others, using a string is allowed. You can use any reasonable format in this string, and you can represent the infinities with anything that can't be confused with another number (such as I, ∞, inf, or :().
Input will always be two floats in your chosen representation, and output will be a single one. Floating point errors and large numbers being represented as Infinity are allowed.
Test cases:
0 / 0                   0
0 / 1                   0
0 / 8                   0
0 / Infinity            0
0 / -0                 -0
0 / -1                 -0
0 / -8                 -0
0 / -Infinity          -0
-0 / 0                 -0
-0 / 1                 -0
-0 / 8                 -0
-0 / Infinity          -0
-0 / -0                 0
-0 / -1                 0
-0 / -8                 0
-0 / -Infinity          0
1 / 0                   Infinity
8 / 0                   Infinity
Infinity / 0            Infinity
1 / -0                 -Infinity
8 / -0                 -Infinity
Infinity / -8          -Infinity
-1 / 0                 -Infinity
-8 / 0                 -Infinity
-Infinity / 0          -Infinity
-1 / -0                 Infinity
-8 / -0                 Infinity
-Infinity / -0          Infinity
Infinity / 1            Infinity
Infinity / 8            Infinity
Infinity / -1          -Infinity
Infinity / -8          -Infinity
-Infinity / 1          -Infinity
-Infinity / 8          -Infinity
-Infinity / -1          Infinity
-Infinity / -8          Infinity
Infinity / Infinity     1
Infinity / -Infinity   -1
-Infinity / Infinity   -1
-Infinity / -Infinity   1
1 / 1                   1
1 / 8                   0.125
1 / Infinity            0
1 / -1                 -1
1 / -8                 -0.125
1 / -Infinity          -0
-1 / 1                 -1
-1 / 8                 -0.125
-1 / Infinity          -0
-1 / -1                 1
-1 / -8                 0.125
-1 / -Infinity          0
8 / 1                   8
8 / 8                   1
8 / Infinity            0
8 / -1                 -8
8 / -8                 -1
8 / -Infinity          -0
-8 / 1                 -8
-8 / 8                 -1
-8 / Infinity          -0
-8 / -1                 8
-8 / -8                 1
-8 / -Infinity          0
1 / 0.125               8
0.1 / 0.2               0.5
10 / -3                 -3.333333
1 / 0.0000000000000001  10000000000000000

Other:
This is code-golf, so shortest answer in bytes (per language) wins!

Haskell, 35 bytes

x?y|isNaN$x/y=tanh x*tanh y|0<1=x/y

Try it online!
The relevant function is (?), which takes two Doubles as input and returns a Double as output.
How?
The hyperbolic tangent is an amazing function (two bytes shorter than signum!).

x
tanh x

0.0
0.0

-0.0
-0.0

Infinity
1.0

-Infinity
-1.0

Haskell, 30 29 bytes
x?y|x/y<=1/0=x/y|0<1=tanh$x*y

Try it online!
Using MarcMush's amazing trick, which relies on the well-known formula1
$$
\tanh(x\cdot y)=\tanh(x)\cdot\tanh(y).
$$

1 I know, I know, maths.


Permutation Coefficient What is Permutation Coefficient
Permutation refers to the process of arranging all the members of a given set to form a sequence. The number of permutations on a set of n elements is given by n! , where “!” represents factorial.
The Permutation Coefficient represented by P(n, k) is used to represent the number of ways to obtain an ordered subset having k elements from a set of n elements.
Mathematically,

Examples:
P(10, 2) = 90
P(10, 3) = 720
P(10, 0) = 1
P(10, 1) = 10

To Calculate the Permutation Coefficient, you can use the following recursive approach:
P(n, k) = P(n-1, k) + k * P(n-1, k-1)
Though, this approach can be slow at times. So Dynamic approach is preferred mostly.
Example of Dynamic Approach (Python)
Input Format
{n} {k}
Output Format
{PermutationCoefficient}
Test Cases
INPUT - 100 2
OUTPUT - 9900

INPUT - 69 5
OUTPUT - 1348621560

INPUT - 20 19
OUTPUT - 2432902008176640000

INPUT - 15 11
OUTPUT - 54486432000

Constraints in input
N will always be greater than or equal to K.
(Not to be confused with Binomial Coefficient)

APL (Dyalog Extended), 5 bytes

⊣÷⍥!-

⊣      left argument
 ÷⍥!   divide over factorial, apply factorial to both arguments and then divide
    -  subtract

Try it online!