Can my 4-note music box play that song? I have a crank-operated music box that can play a series of four notes. When I turn the crank, it plucks one of four strings, depending on the position of the crank and the direction of the turn. When the crank is turned due north, the box (with its strings numbered 1 through 4) looks like this:

1  |  2
   |
   O

4     3

From there, I can turn the crank clockwise to pluck the #2 string and point the crank east:

1     2

   O---

4     3

Alternatively, I could have also turned the crank counterclockwise from north to play the #1 string and end with a crank pointing west:

1     2

---O

4     3

At any given time, then, the box can play one of two notes: the next note available in the clockwise direction or the next note in the counterclockwise direction.

Challenge

Your challenge is to write a program or function that accepts a non-empty string of note values (i.e., numerals 1 through 4) and determine if it is ever possible to play that sequence of notes on the music box. Produce a truthy or falsy result to indicate the playability or non-playability of the input.

Some notes:

The input makes no assumptions about initial start position. The inputs 214 (starting east and moving strictly counterclockwise) and 234 (starting north and moving strictly clockwise) and both valid.
The crank may move freely in either direction after each note. A series of the same note is possible (e.g., 33333) by moving back and forth across one string. The series 1221441 is perfectly playable (starting west, moving clockwise two steps, then counterclockwise three steps, then clockwise two steps).

Samples

Some true cases:

1
1234
1221
3333
143332
22234
2234
22214
1221441
41233

Some false cases:

13     (note 3 is never available after note 1)
1224   (after `122`, the crank must be north, so 4 is not playable)
121    (after `12` the crank is east; 1 is not playable)
12221  (as above, after `1222` the crank is east)
43221

CJam, 34 31 bytes
8,q{~2*f{_@-_zF8b&,@@+8,=*}0-}/

Did this on my phone, so I'll have to put up an explanation later. Output is nonempty iff truthy.
Try it online | Test suite
Explanation
The new code shifts the layout a little:
2    3    4

1    .    5

0/8  7    6

Even numbers correspond to string positions and odd numbers correspond to crank positions.
Here's what happens:
8,           Create the range [0 1 .. 7] of possible starting positions
             We can leave the string positions [0 2 4 6] in since it doesn't matter
q{ ... }/    For each character in the input...
  ~2*          Evaluate as integer and double, mapping "1234" -> [2 4 6 8]
  f{ ... }     Map over our possible current crank positions with the string
               position as an extra parameter
    _@-          Calculate (string - crank), giving some number in [-7 ... 7]
    _z           Duplicate and absolute value
    F8b          Push 15 base 8, or [1 7]
    &,           Setwise intersection and get length. If (string - crank) was in
                 [-7 -1 1 7] then the move was valid and this evaluates to 1, otherwise 0
    @@+          Calculate ((string - crank) + string)
    8,=          Take modulo 8, giving the new crank position. x%y in Java matches the
                 sign of x, so we need to do ,= (range + index) to get a number in [0 .. 7]
    *            Multiply the new crank position by our previous 0 or 1
  0-           Remove all 0s, which correspond to invalid positions

The stack is then automatically printed at the end. Any possible ending positions will be in the output, e.g. for the input 1 the output is 31, which means the crank can end facing either left or up.
If only CJam had filter with extra parameter...

Edit: Temporarily rolling back while I convince myself that this 29-byte works:
8,q{~2*f{_@-_7b1#@@+8,=|}W-}/


Convert JSF**k to normal JS Many of you already know JSF**k. For those who don't, it's a script that basically turns any JavaScript code into something written using only []()!+.

Your task is to build, using any language of your choice, a program which converts JSF**k into unobfuscated JavaScript.

Input: A string with valid JSF**k code.
Output: A string with the regular JavaScript code that has been previously JSF**ked to generate the input.

For this challenge, consider that the input string has only been JSF**ked once.

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

Javascript - 68 55 51

alert(/\n(.+)/.exec(eval(prompt().slice(0,-2)))[1])

Alternatively: (same length)

alert(/.+(?=\n})/.exec(eval(prompt().slice(0,-2))))

Runs in the console of your browser. Only guaranteed to work with code generated by jsfuck.com with the 'Eval Source' option ticked.

Ungolfed:

alert(
    /\n(.+)/.exec(                 // regex to extract code from inside outer function braces {}
        eval(prompt().slice(0,-2)) // remove the final set of parens () and evaluate the code
                                   // this results in a function, which will be converted to a string as 'exec' expects a string
    )[1]                           // get the first capture group
)


Mow a Rectangular Lawn A lawn is defined as a rectangular field with of one character surrounded by two layers of visible whitespace. This means two lines above and twos lines below, and a two space padding on the left (the right has visible whitespace, so you do not need to include it).

  |||||
  |||||
  |||||

A mowed lawn is a similar structure, except that the main character is a shortened version of the first character.

  .....
  .....
  .....

A mower is two different characters, different than the two lawn characters. Here is an example, with = as the back of the mower and o as the front:

=o

A mower will move around the lawn vertically, and can also rotate on its front. The above mower may look like any of the below during some point in the animation:

=o

o=

o
=

=
o

The mower can start on any set of the below positions on the below lawn. Mowers with o would drive around the lawn clockwise. Mowers with 0 would drive around the lawn counterclockwise.

  =   =
  0   o
=o|||||0=
  |||||
=0|||||o=
  o   0
  =   =

The animation starts at second 0. Each second, the mower moves forward one space, and cut the grass on its front. When the mower vacates a spot, it appears cut. When the mower front reaches the last uncut item on a line (and there is still uncut grass), the mower back rotates once so as to continue the current mow (staying in clockwise/counterclockwise based on original position) When the mower is finished, it continues straight (mowing already cut grass) until it is completely off the lawn.

With a mower starting in the left top, this shows the basic progression for a 5x3 lawn:

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

                                                                  =
=o|||||    =o||||     =o|||     .=o||     ..=o|     ...=o     ....o     ....=     .....     .....     .....     .....     .....     .....     .....     .....     .....     .....     .....     .....     .....     .....     .....
  |||||     |||||     |||||     |||||     |||||     |||||     |||||     ||||o     ||||=     ||||.     ||||.     ||||.     ||||.     ||||.     ||||.     o|||.    =o|||.     =o||.     .=o|.     ..=o.     ...=o     ....=o    .....=o
  |||||     |||||     |||||     |||||     |||||     |||||     |||||     |||||     ||||o     ||||o=    |||o=     ||o=.     |o=..     o=...     o....     =....     .....     .....     .....     .....     .....     .....     .....
                                                                                =

Input

Your input will be the dimensions of the lawn (two integers).

Output

Print the lawn and the mower in your chosen position. You may chose the four characters for grass, cut grass, mower front, and mower back. You only to need enough whitespace to show the current second's content to specs, but extra whitespace is completely allowed, as long as it looks the same.

Since this is an animation, you may either clear the output each second, or print enough newlines to appear to animate in the viewing frame (you may assume the viewing frame is the size needed to appear to animate).

A consistent time interval other than one second is allowed (i.e. 999 millis to save a byte, or two seconds for some reason), but it should be such that the lawn mower still appears to be moving naturally.

If possible, provide a visual (TIO, Snippet, GIF, etc.)

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

JavaScript (ES6/Node.js), 664 525 523 chars

f=(w,h)=>{Z=require('sleep');c=a=>console.log(a);X=1;Y=2;D='e';N='|';O={'|':[0,-1],'e':[1,0],'s':[0,1],'w':[-1,0]};S=[N,D,'s','w'];q=d=>F[Y+O[d][1]][X+O[d][0]];b=' '.repeat(w+4),U='  ';F=[b,b].concat([...Array(h)].map(x=>U+N.repeat(w)+U)).concat([b,b]).map(x=>x.split``);for(;;){f=F.map(a=>a.concat());f[Y][X]='@';d=O[D];f[Y-d[1]][X-d[0]]='=';c(f.map(x=>x.join``).join`\n`);if(F[Y][X]==N)F[Y][X]='.';d=O[D],f=q(D),R=S[(S.indexOf(D)+1)%4],r=q(R);(r==N)&&((f==' ')||(f=='.'))?D=R:(X+=d[0],Y+=d[1])
Z.msleep(1E3);c('\033[2J')}}

Unminified with comments:

f=(w,h)=>{
  Z = require('sleep');
  c=a=>console.log(a);
  //mower coordinates
  X = 1;
  Y = 2;
  //mower direction
  D='e'; //n/e/s/w
  N='|';
  //directions with amount of change in [x,y] coordinates
  O = {'|':[0,-1],'e':[1,0],'s':[0,1],'w':[-1,0]};
  //direction short names
  S=[N,D,'s','w'];
  //query for item in specified direction relative to mower
  q=d=>F[Y+O[d][1]][X+O[d][0]];
 //generate field + whitespace
 b=' '.repeat(w+4),U='  ';
 F=[b,b].concat([...Array(h)].map(x=>U+N.repeat(w)+U)).concat([b,b]).map(x=>x.split``);
 for(;;){
    //print the field:
    //make a copy of the field, so we can paste the mower on top of it
    f=F.map(a=>a.concat());
    //print mower head
    f[Y][X]='@';
    //print mower tail
    d = O[D];
    f[Y-d[1]][X-d[0]]='=';
    c(f.map(x=>x.join``).join`\n`);
    //-----
    //move the mower
    if(F[Y][X]==N)F[Y][X]='.';//cut the grass if we stand on some
    d=O[D],//how many fields to move forward
        f=q(D),//item in front of mower
        R=S[(S.indexOf(D)+1)%4],//name of direction if we rotate to the right
        r=q(R);//item to right of mower
    //if there is wall in front of me OR cut grass in front of me and uncut on the right, turn right, else go ahead
    (r==N) && ((f==' ') || (f=='.'))?D=R:(X+=d[0],Y+=d[1])
    Z.msleep(1E3);
    c('\033[2J');
};
}
//test script
f(3,3);

note: I suppose I should get of the 'sleep' package and rewrite with setTimeout to be nodejs independent


Put the line in the code you nut and shake it all up Using one programming language write 5 single-line programs, each of which outputs a different line of the first verse to Harry Nilsson's 1972 song "Coconut" when run individually:

Brother bought a coconut, he bought it for a dime
His sister had another one, she paid it for a lime
She put the lime in the coconut, she drank them both up
She put the lime in the coconut, she drank them both up
She put the lime in the coconut, she drank them both up

(full lyrics)
The last 3 lines have the same lyrics, so your last 3 programs might be as well.
There are 5 factorial or 120 ways these 5 single-line programs can be arranged one per line in a single 5-line program. You must optimize your single-line programs such that for as many of these 120 combinations as possible the 5-line program outputs the entire verse in its proper order, exactly as it appears above.
Example
The simplest answer would have 5 single line print statements, the last 3 identical:
print('Brother bought a coconut, he bought it for a dime')
print('His sister had another one, she paid it for a lime')
print('She put the lime in the coconut, she drank them both up')
print('She put the lime in the coconut, she drank them both up')
print('She put the lime in the coconut, she drank them both up')
The output to the 5-line programs will be the verse in its proper order as long as the first two single-liners are in their correct places. Only 6 of the 120 possible arrangements accomplish this.
Scoring
The submission with the most working cases out of all 120 wins. Tie breaker goes to the set of programs with the lowest cumulative byte count (newlines not counted). The example has 309 bytes.
Details

Your programs may not read their own source code. Nor should they read other external files or require a network connection.

Output to stdout or closest alternative. You may also output to a file with the name of your choice.

"Single-line programs" are strings that contain any characters except line terminators (you'll probably just need to worry about newlines)
.

When composing the single-liners into the 5-liners you should add exactly 4 newlines, one between each adjacent pair of single-liners. You may optionally add a trailing newline.

CJam, 120 valid permutations, 334 299 290 bytes
"She put the lime in the coconut, she drank them both up"N+
"Brother bought a coconut, he bought it for a dime"N+]$~
"She put the lime in the coconut, she drank them both up"N+
"His sister had another one, she paid it for a lime"N+]$~
"She put the lime in the coconut, she drank them both up"N+

Pretty simple logic:

Put each line of the song in each of the 5 programs
Wrap everything on stack in an array
Sort the array
Unwrap the array so that the next program can use the same logic
In each step, we have the partial lyrics in an array. Luckily, sorting the array gives the correct order of the lyrics.

UPDATE: Turns out that you don't need the wrap-sort-unwrap cycle after the 3 similar and appearing at the end lines of the song. I can explain why if its not that apparent :)


Dither a Grayscale Image Dither a grayscale image into pure black and white with your own algorithm.

Guidelines: You must come up with your own new algorithm. You cannot use pre-existing algorithms (ex. Floyd-Steinburg) but you can use the general technique. Your program must be able to read an image and produce an image the same size. This is a popularity contest, so whoever produces the best (closest to original) and most creative (determined by votes) wins. Bonus if the code is short, though this is not necessary.

You can use whatever grayscale image you want as input, it should be larger than 300x300. Any file format is fine.

Example input:

Example output:

This is a pretty good job, but there still are visible lines and patterns.

GraphicsMagick/ImageMagick

Ordered Dither:

magick B2DBy.jpg -gamma .45455 -ordered-dither [all] 4x4 ordered4x4g45.pbm

Before complaining about my using an "established algorithm" please read the ChangeLog for GraphicsMagick and ImageMagick for April 2003 where you'll see that I implemented the algorithm in those applications.  Also, the combination of "-gamma .45455" with "-ordered-dither" is new.

The "-gamma .45455" takes care of the image being too light.  The "all" parameter is only needed with GraphicsMagick.

There's banding because there are only 17 graylevels in a 4x4 ordered-dither image.
The appearance of banding can be reduced by using an 8x8 ordered-dither which has 65 levels.

Here are the original image, the 4x4 and 8x8 ordered dithered output and the random-threshold output:

I prefer the ordered-dither version, but am including the random-threshold version for completeness.

magick B2DBy.jpg -gamma .6 -random-threshold 10x90% random-threshold.pbm

The "10x90%" means to render below 10 percent intensity pixels as pure black and above 90 percent as pure white, to avoid having a few lonely specks in those areas.

It's probably worth noting that both are as memory-efficient as they can possibly be.  Neither does any diffusion, so they work one pixel at a time, even when writing ordered-dither blocks, and don't need to know anything about the neighboring pixels.  ImageMagick and GraphicsMagick process a row at a time, but it's not necessary for these methods.  The ordered-dither conversions take less than .04 second real time on my old x86_64 computer.


Count the number of Hankelable matrices Background

A binary Hankel matrix is a matrix with constant skew-diagonals (positive sloping diagonals) containing only 0s and 1s. E.g. a 5x5 binary Hankel matrix looks like

a b c d e
b c d e f
c d e f g
d e f g h
e f g h i

where a, b, c, d, e, f, g, h, i are either 0 or 1.

Let's define a matrix M as Hankelable if there is a permutation of the order of rows and columns of M so that M is a Hankel matrix. This means one can apply one permutation to the order of the rows and a possibly different one to the columns.

The Challenge

The challenge is to count how many Hankelable n by n matrices there are for all n up to as large a value as possible.

Output

For each integer n from 1 upwards, output the number of Hankelable n by n matrices with entries which are 0 or 1.

For n = 1,2,3,4,5 the answers should be 2,12,230,12076,1446672. (Thanks to orlp for the code to produce these.)

Time limit

I will run your code on my machine and stop it after 1 minute. The code that outputs the correct answers up to the largest value of n wins. The time limit is for everything from n = 1 to the biggest value of n for which you give an answer.

The winner will be the best answer by the end of Saturday 18 April.

Tie Breaker

In the case of a tie for some maximum n I will time how long it takes to give the outputs up to n+1 and the quickest one wins. In the case that they run in the same time to within a second up to n+1, the first submission wins.

Languages and libraries

You can use any language which has a freely available compiler/interpreter/etc. for Linux and any libraries which are also freely available for Linux.

My machine

The timings will be run on my machine. This is a standard ubuntu install on an AMD FX-8350 Eight-Core Processor on an Asus M5A78L-M/USB3 Motherboard (Socket AM3+, 8GB DDR3). This also means I need to be able to run your code. As a consequence, only use easily available free software and please include full instructions how to compile and run your code.

Notes

I recommend against iterating over all n by n matrices and trying to detect if each one has the property I describe. First, there are too many and second, there seems to be no quick way to do this detection.

Leading entries so far

n = 8 by Peter Taylor. Java
n = 5 by orlp. Python

Java (n=8)

import java.util.*;
import java.util.concurrent.*;

public class HankelCombinatorics {
    public static final int NUM_THREADS = 8;

    private static final int[] FACT = new int[13];
    static {
        FACT[0] = 1;
        for (int i = 1; i < FACT.length; i++) FACT[i] = i * FACT[i-1];
    }

    public static void main(String[] args) {
        long prevElapsed = 0, start = System.nanoTime();
        for (int i = 1; i < 12; i++) {
            long count = count(i), elapsed = System.nanoTime() - start;
            System.out.format("%d in %dms, total elapsed %dms\n", count, (elapsed - prevElapsed) / 1000000, elapsed / 1000000);
            prevElapsed = elapsed;
        }
    }

    @SuppressWarnings("unchecked")
    private static long count(int n) {
        int[][] perms = new int[FACT[n]][];
        genPermsInner(0, 0, new int[n], perms, 0);

        // We partition by canonical representation of the row sum multiset, discarding any with a density > 50%.
        Map<CanonicalMatrix, Map<CanonicalMatrix, Integer>> part = new HashMap<CanonicalMatrix, Map<CanonicalMatrix, Integer>>();
        for (int m = 0; m < 1 << (2*n-1); m++) {
            int density = 0;
            int[] key = new int[n];
            for (int i = 0; i < n; i++) {
                key[i] = Integer.bitCount((m >> i) & ((1 << n) - 1));
                density += key[i];
            }
            if (2 * density <= n * n) {
                CanonicalMatrix _key = new CanonicalMatrix(key);
                Map<CanonicalMatrix, Integer> map = part.get(_key);
                if (map == null) part.put(_key, map = new HashMap<CanonicalMatrix, Integer>());
                map.put(new CanonicalMatrix(m, perms[0]), m);
            }
        }

        List<Job> jobs = new ArrayList<Job>();
        ExecutorService pool = Executors.newFixedThreadPool(NUM_THREADS);

        for (Map.Entry<CanonicalMatrix, Map<CanonicalMatrix, Integer>> e : part.entrySet()) {
            Job job = new Job(n, perms, e.getKey().sum() << 1 == n * n ? 0 : 1, e.getValue());
            jobs.add(job);
            pool.execute(job);
        }

        pool.shutdown();
        try {
            pool.awaitTermination(1, TimeUnit.DAYS); // i.e. until it's finished - inaccurate results are useless
        }
        catch (InterruptedException ie) {
            throw new IllegalStateException(ie);
        }

        long total = 0;
        for (Job job : jobs) total += job.subtotal;
        return total;
    }

    private static int genPermsInner(int idx, int usedMask, int[] a, int[][] perms, int off) {
        if (idx == a.length) perms[off++] = a.clone();
        else for (int i = 0; i < a.length; i++) {
            int m = 1 << (a[idx] = i);
            if ((usedMask & m) == 0) off = genPermsInner(idx+1, usedMask | m, a, perms, off);
        }
        return off;
    }

    static class Job implements Runnable {
        private volatile long subtotal = 0;
        private final int n;
        private final int[][] perms;
        private final int shift;
        private final Map<CanonicalMatrix, Integer> unseen;

        public Job(int n, int[][] perms, int shift, Map<CanonicalMatrix, Integer> unseen) {
            this.n = n;
            this.perms = perms;
            this.shift = shift;
            this.unseen = unseen;
        }

        public void run() {
            long result = 0;
            int[][] perms = this.perms;
            Map<CanonicalMatrix, Integer> unseen = this.unseen;
            while (!unseen.isEmpty()) {
                int m = unseen.values().iterator().next();
                Set<CanonicalMatrix> equiv = new HashSet<CanonicalMatrix>();
                for (int[] perm : perms) {
                    CanonicalMatrix canonical = new CanonicalMatrix(m, perm);
                    if (equiv.add(canonical)) {
                        result += canonical.weight() << shift;
                        unseen.remove(canonical);
                    }
                }
            }

            subtotal = result;
        }
    }

    static class CanonicalMatrix {
        private final int[] a;
        private final int hash;

        public CanonicalMatrix(int m, int[] r) {
            this(permuteRows(m, r));
        }

        public CanonicalMatrix(int[] a) {
            this.a = a;
            Arrays.sort(a);

            int h = 0;
            for (int i : a) h = h * 37 + i;
            hash = h;
        }

        private static int[] permuteRows(int m, int[] perm) {
            int[] cols = new int[perm.length];
            for (int i = 0; i < perm.length; i++) {
                for (int j = 0; j < cols.length; j++) cols[j] |= ((m >> (perm[i] + j)) & 1L) << i;
            }
            return cols;
        }

        public int sum() {
            int sum = 0;
            for (int i : a) sum += i;
            return sum;
        }

        public int weight() {
            int prev = -1, count = 0, weight = FACT[a.length];
            for (int col : a) {
                if (col == prev) weight /= ++count;
                else {
                    prev = col;
                    count = 1;
                }
            }
            return weight;
        }

        @Override public boolean equals(Object obj) {
            // Deliberately unsuitable for general-purpose use, but helps catch bugs faster.
            CanonicalMatrix that = (CanonicalMatrix)obj;
            for (int i = 0; i < a.length; i++) {
                if (a[i] != that.a[i]) return false;
            }
            return true;
        }

        @Override public int hashCode() {
            return hash;
        }
    }
}

Save as HankelCombinatorics.java, compile as javac HankelCombinatorics.java, run as java -Xmx2G HankelCombinatorics.

With NUM_THREADS = 4 on my quad-core machine it gets 20420819767436 for n=8 in 50 to 55 seconds elapsed, with a fair amount of variability between runs; I expect that it should easily manage the same on your octa-core machine but will take an hour or more to get n=9.

How it works

Given n, there are 2^(2n-1) binary nxn Hankel matrices. The rows can be permuted in n! ways, and the columns in n! ways. All we need to do is to avoid double-counting...

If you calculate the sum of each row, then neither permuting the rows nor permuting the columns changes the multiset of sums. E.g.

0 1 1 0 1
1 1 0 1 0
1 0 1 0 0
0 1 0 0 1
1 0 0 1 0

has row sum multiset {3, 3, 2, 2, 2}, and so do all Hankelable matrices derived from it. This means that we can group the Hankel matrices by these  row sum multisets and then handle each group independently, exploiting multiple processor cores.

There's also an exploitable symmetry: the matrices with more zeroes than ones are in bijection with the matrices with more ones than zeroes.

Double-counting occurs when Hankel matrix M_1 with row permutation r_1 and column permutation c_1 matches Hankel matrix M_2 with row permutation r_2 and column permutation c_2 (with up to two but not all three of M_1 = M_2, r_1 = r_2, c_1 = c_2). The row and column permutations are independent, so if we apply row permutation r_1 to M_1 and row permutation r_2 to M_2, the columns as multisets must be equal. So for each group, I calculate all of the column multisets obtained by applying a row permutation to a matrix in the group. The easy way to get a canonical representation of the multisets is to sort the columns, and that is also useful in the next step.

Having obtained the distinct column multisets, we need to find how many of the n! permutations of each are unique. At this point, double-counting can only occur if a given column multiset has duplicate columns: what we need to do is to count the number of occurrences of each distinct column in the multiset and then calculate the corresponding multinomial coefficient. Since the columns are sorted, it's easy to do the count.

Finally we add them all up.

The asymptotic complexity isn't trivial to calculate to full precision, because we need to make some assumptions about the sets. We evaluate on the order of 2^(2n-2) n! column multisets, taking n^2 ln n time for each (including the sorting); if grouping doesn't take more than a ln n factor, we have time complexity Theta(4^n n! n^2 ln n). But since the exponential factors completely dominate the polynomial ones, it's Theta(4^n n!) = Theta((4n/e)^n).


9erilous 9ermutations Note: This is an attempt at recycling guest271314's permutation question(s)

There's an interesting pattern that forms when you find the differences between lexographically sorted permutations of base 10 numbers with ascending unique digits. For example, 123 has permutations:

123 132 213 231 312 321

When you find the differences between these, you get the sequence

9 81 18 81 9

Which are all divisible by nine (because of the digit sum of base 10 numbers), as well as being palindromic.

Notably, if we use the next number up, 1234, we get the sequence

9 81 18 81 9 702 9 171 27 72 18 693 18 72 27 171 9 702 9 81 18 81 9

Which extends the previous sequence while remaining palindromic around \$693\$. This pattern always holds, even when you start using more that 10 numbers, though the length of the sequence is \$n!-1\$ for \$n\$ numbers. Note that to use numbers above 0 to 9, we don't change to a different base, we just multiply the number by \$10^x\$, e.g. \$ [1,12,11]_{10} = 1*10^2 + 12*10^1 + 11*10^0 = 231\$.

Your goal is to implement this sequence, by returning each element as a multiple of nine. For example, the first 23 elements of this sequence are:

1 9 2 9 1 78 1 19 3 8 2 77 2 8 3 19 1 78 1 9 2 9 1

Some other test cases (0 indexed):

23     => 657
119    => 5336
719    => 41015
5039   => 286694
40319  => 1632373
362879 => 3978052
100    => 1
1000   => 4
10000  => 3
100000 => 3

Rules:

The submission can be any of:

A program/function that takes a number and returns the number at that index, either 0 or 1 indexed.
A program/function that takes a number \$n\$ and returns up to the \$n\$th index, either 0 or 1 indexed.
A program/function that outputs/returns the sequence infinitely.

The program should be capable of theoretically handling up to the \$11!-1\$th element and beyond, though I understand if time/memory constraints make this fail. In particular, this means you cannot concatenate the digits and evaluate as base 10, since something like \$012345678910\$ would be wrong.
This is code-golf, so the shortest implementation for each language wins!

Notes:

This is OEIS A217626
I am offering a bounty of 500 for a solution that works out the elements directly without calculating the actual permutations.
The sequence works for any contiguous digits. For example, the differences between the permutations of \$ [1,2,3,4]_{10} \$ are the same as for \$[-4,-3,-2,-1]_{10}\$.

Jelly, 9 bytes

,‘œ?ŻḌI÷9

Try it online! (print the n'th element)

Try it online! (20 first elements)

Explanation:

      I÷9      Compute the difference divided by 9 between
 ‘             the (n+1)th
  œ?           permutation
,              and
               the (n)th
  œ?           permutation
    Ż          of [0,1,2,...n]
     Ḍ         converted to decimal.

(Jelly has the builtin œ? which computes the nth permutation of a list in approximately linear time. Quite useful.)


Brainf**k to Unary and Back A language that is very useful in restricted source and other such challenges is Unary, a brainfuck derivative in which programs are written in with only one character. Your job is to write a program to convert programs from brainfuck to unary and a program to do the opposite, both programs in the same language. Your score will be the sum of the lengths of the two programs.
How do you convert from brainfuck to unary?

First convert you brainfuck code to binary according to this table:

Now concatenate the code into one giant binary number in order of the code.
Prepend a 1 to the string to ensure a unique binary number.
Convert from a binary number to a unary number using any character.
Ex: +. would be 000000000000000000000000000000000000000000000000000000000000000000000000000000000000 (84 zeroes).

Brainfuck -> Unary Specs

Since the resulting programs will be impossibly huge, print not the actual program but merely the length of the resulting program.
Take the brainfuck program as a string through stdin, function arg, etc and output the length.
The program will always be valid and have only those 8 chars in it.

Unary -> Brainfuck Specs

You will have to implement the reverse of the above algorithm.
Again because of the huge sizes in question, the input will be a number describing the length of the Unary code.
Same I/O rules as always.
The program will always be valid and have only those 8 chars in it.

Test Cases

Hello World - ++++++[>++++++++++++<-]>.>++++++++++[>++++++++++<-]>+.+++++++..+++.>++++[>+++++++++++<-]>.<+++[>----<-]>.<<<<<+++[>+++++<-]>.>>.+++.------.--------.>>+. = 239234107117088762456728667968602154633390994619022073954825877681363348343524058579165785448174718768772358485472231582844556848101441556
Fibonacci - ++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++>++++++++++++++++>>+<<[>>>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>[<+>-]>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]<[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]<<<++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<<.>.>>[>>+<<-]>[>+<<+>-]>[<+>-]<<<-]<<++... = 13067995222095367150854793937817629722033205198624522624687536186118993888926522550140580142585590431635487113180955099384652678100247403485397450658564826143160529351955621991895221530908461364045400531236124980271740502887704217664044858614821622360156740992393765239123681327824577149595724956207165558106099868913919959549896553103116795519592552089266360725543244154867904980260

This is code-golf so lowest score in bytes wins!
Anyone up for a solution in Unary? ;P


Decryption by pattern analysis You are given an encrypted string, encrypted using a very simple substitution cipher.

Problem

You do not know what the cipher is but you do know the ciphertext is English and that the most frequent letters in English are etaoinshrdlucmfwypvbgkqjxz in that order. The only allowed characters are uppercase letters and spaces. You can do basic analysis - starting from single letters, but you can migrate onto more complex multi-letter analysis - for example, U almost always follows Q, and only certain letters can come twice in a row.

Examples

clear : SUBMARINE TO ATTACK THE DOVER WAREHOUSE AND PORT ON TUESDAY SUNRISE
cipher: ZOQ DUPAEYSRYDSSDXVYSHEYNRBEUYLDUEHROZEYDANYKRUSYRAYSOEZNDMYZOAUPZE

clear : THE QUICK BROWN FOX BEING QUITE FAST JUMPED OVER THE LAZY DOG QUITE NICELY
cipher: TNAEPDHIGEMZQJLEVQBEMAHL EPDHTAEVXWTEODYUASEQKAZETNAERXFCESQ EPDHTAELHIARC

clear : BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO BUFFALO
cipher: HV  WRPDHV  WRPDHV  WRPDHV  WRPDHV  WRPDHV  WRPDHV  WRP

Challenges

See if you can decrypt the text in each of these ciphers:

SVNXIFCXYCFSXKVVZXIHXHERDXEIYRAKXZCOFSWHCZXHERDXBNRHCXZR  RONQHXORWECFHCUH
SOFPTGFIFBOKJPHLBFPKHZUGLSOJPLIPKBPKHZUGLSOJPMOLEOPWFSFGJLBFIPMOLEOPXULBSIPLBP
KBPBPWLIJFBILUBKHPGKISFG
TMBWFYAQFAZYCUOYJOBOHATMCYNIAOQW Q JAXOYCOCYCHAACOCYCAHGOVYLAOEGOTMBWFYAOBFF
ACOBHOKBZYKOYCHAUWBHAXOQW XITHJOV WOXWYLYCU
FTRMKRGVRFMHSZVRWHRSFMFLMBNGKMGTHGBRSMKROKLSHSZMHKMMMMMRVVLVMPRKKOZRMFVDSGOFRW

I have the substitution matrices and cleartext for each, but I will only reveal them if it becomes too difficult or someone doesn't figure it out.

The solution which can decrypt the most messages successfully is the winner. If two solutions are equally good, they will be decided by vote counts.

Python

I've figured out all the secret phrases, but I won't post them here.  Run the code if you care.

The code works by picking a space character, enumerating all possible substitutions for each word, then searching for compatible substitutions.  It also allows for some out-of-lexicon words to deal with misspellings in the cleartext :)

I used a large lexicon (~500K words) from http://wordlist.sourceforge.net/.

import sys,re

# get input
message = sys.argv[1]

# read in lexicon of words
# download scowl version 7.1
# mk-list english 95 > wordlist
lexicon = set()
roman_only = re.compile('^[A-Z]*$')
for word in open('wordlist').read().upper().split():
  word=word.replace("'",'')
  if roman_only.match(word): lexicon.add(word)

histogram={}
for c in message: histogram[c]=0
for c in message: histogram[c]+=1
frequency_order = map(lambda x:x[1], sorted([(f,c) for c,f in histogram.items()])[::-1])

# returns true if the two maps are compatible.
# they are compatible if the mappings agree wherever they are defined,
# and no two different args map to the same value.
def mergeable_maps(map1, map2):
  agreements = 0
  for c in map1:
    if c in map2:
      if map1[c] != map2[c]: return False
      agreements += 1
  return len(set(map1.values() + map2.values())) == len(map1) + len(map2) - agreements

def merge_maps(map1, map2):
  m = {}
  for (c,d) in map1.items(): m[c]=d
  for (c,d) in map2.items(): m[c]=d
  return m

def search(map, word_maps, outside_lexicon_allowance, words_outside_lexicon):
  cleartext = ''.join(map[x] if x in map else '?' for x in message)
  #print 'trying', cleartext

  # pick a word to try next
  best_word = None
  best_score = 1e9
  for (word,subs) in word_maps.items():
    if word in words_outside_lexicon: continue
    compatible_subs=0
    for sub in subs:
      if mergeable_maps(map, sub): compatible_subs += 1
    unassigned_chars = 0
    for c in word:
      if c not in map: unassigned_chars += 1  #TODO: duplicates?
    if compatible_subs == 0: score = 0
    elif unassigned_chars == 0: score = 1e9
    else: score = 1.0 * compatible_subs / unassigned_chars   # TODO: tweak?
    if score < best_score:
      best_score = score
      best_word = word
  if not best_word:  # no words with unset characters, except possibly the outside lexicon ones
    print cleartext,[''.join(map[x] if x in map else '?' for x in word) for word in words_outside_lexicon]
    return True

  # use all compatible maps for the chosen word
  r = False
  for sub in word_maps[best_word]:
    if not mergeable_maps(map, sub): continue
    r |= search(merge_maps(map, sub), word_maps, outside_lexicon_allowance, words_outside_lexicon)

  # maybe this word is outside our lexicon
  if outside_lexicon_allowance > 0:
    r |= search(map, word_maps, outside_lexicon_allowance - 1, words_outside_lexicon + [best_word])
  return r

for outside_lexicon_allowance in xrange(3):
  # assign the space character first
  for space in frequency_order:
    words = [w for w in message.split(space) if w != '']
    if reduce(lambda x,y:x|y, [len(w)>20 for w in words]): continue  # obviously bad spaces

    # find all valid substitution maps for each word
    word_maps={}
    for word in words:
      n = len(word)
      maps = []
      for c in lexicon:
        if len(c) != n: continue
        m = {}
        ok = 1
        for i in xrange(n):
          if word[i] in m:                      # repeat letter
            if m[word[i]] != c[i]: ok=0; break  # repeat letters map to same thing
          elif c[i] in m.values(): ok=0; break  # different letters map to different things
          else: m[word[i]]=c[i]
        if ok: maps.append(m);
      word_maps[word]=maps

    # look for a solution
    if search({space:' '}, word_maps, outside_lexicon_allowance, []): sys.exit(0)

print 'I give up.'


Expand Comparison Chains Unlike most languages, Python evaluates a<b<c as it would be done in mathematics, actually comparing the three numbers, as opposed to comparing the boolean a<b to c. The correct way to write this in C (and many others) would be a<b && b<c.
In this challenge, your task is to expand such comparison chains of arbitrary lengths from the Python/intuitive representation, to how it would be written in other languages.
Specifications

Your program will have to handle the operators: ==, !=, <, >, <=, >=.
The input will have comparison chains using only integers.
Don't worry about the trueness of any of the comparisons along the way, this is purely a parsing/syntactical challenge.
The input won't have any whitespace to prevent answers that trivialize parsing by splitting on spaces.
However, your output may have a single space surrounding either just the &&'s, or both the comparison operators and the &&'s, or neither, but be consistent.

Test Cases
Input                  Output
---------------------------------------------------------------

3<4<5                  3<4 && 4<5
3<4<5<6<7<8<9          3<4 && 4<5 && 5<6 && 6<7 && 7<8 && 8<9
3<5==6<19              3<5 && 5==6 && 6<19
10>=5<7!=20            10>=5 && 5<7 && 7!=20
15==15==15==15==15     15==15 && 15==15 && 15==15 && 15==15

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

Retina, 33 22 17 bytes

-5 bytes thanks to @MartinEnder

-2`\D(\d+)
$&&&$1

Try it online!


Shortest a -> b -> (a -> b) function in Haskell I got the following question at a test:

  Write a function f with the following type a -> b -> (a -> b). a and b should not be bound in any sense, the shorter the code, the better.

I came up with f a b = \x -> snd ([a,x],b). Can you find something tinier?

Currently the winner is: f _=(.f).const

Your example can be shrunk by getting rid of the anonymous function on the right-hand side:

f a b x = snd ([a,x],b)

This works because the type a -> b -> a -> b is equivalent to a -> b -> (a -> b) in Haskell.


Fast line drawing algorithm The task is to find a way to draw a horizontal line in an array of 16-bit integers.

We're assuming a 256x192 pixel array with 16 pixels per word. A line is a contiguous run of set (1) bits. Lines can start in the middle of any word, overlap any other words, and end in any word; they may also start and end in the same word. They may not wrap on to the next line. Hint: the middle words are easy - just write 0xffff, but the edges will be tricky, as will handling the case for the start and end in the same word. A function/procedure/routine must take an x0 and x1 coordinate indicating the horizontal start and stop points, as well as a y coordinate.

I exclude myself from this because I designed a nearly identical algorithm myself for an embedded processor but I'm curious how others would go about it. Bonus points for using relatively fast operations (for example, a 64 bit multiply or floating point operation wouldn't be fast on an embedded machine but a simple bit shift would be.)

This code assumes that both x0 and x1 are inclusive endpoints, and that words are little endian (i.e. the (0,0) pixel can be set with array[0][0]|=1).

int line(word *array, int x0, int x1, int y) {
  word *line = array + (y << 4);
  word *start = line + (x0 >> 4);
  word *end = line + (x1 >> 4);
  word start_mask = (word)-1 << (x0 & 15);
  word end_mask = (unsigned word)-1 >> (15 - (x1 & 15));
  if (start == end) {
    *start |= start_mask & end_mask;
  } else {
    *start |= start_mask;
    *end |= end_mask;
    for (word *p = start + 1; p < end; p++) *p = (word)-1;
  }
}


"Fouriest" Transform of An Integer Challenge
Inspired by this SMBC comic, discussed on reddit, math.stackexchange, and calculus7, the challenge is to return the lowest base such that a number is "fouriest."
Description

[From the comic]
"It's called a Fourier Transform when you take a number and convert it to the base system where it has more fours, thus making it 'fourier.' If you pick the base with the most fours, the number is said to be 'fouriest.'"

The challenge is: given an integer greater than four, return the lowest base in which it is "fouriest."
Rules

The solution may be either a function or a full program, whose input and output are of integral type (Int, Long, etc.)
If your language has a function to convert base systems or solve this challenge for a number other than four, it is disallowed
I will not accept my own solution
Solution with the lowest number of bytes wins!

Test Cases
f(17)      = 13
f(72)      = 17
f(176)     = 43
f(708)     = 176
f(500)     = 124
f(2004)    = 500
f(1004)    = 250
f(4020)    = 1004
f(1004)    = 250
f(4020)    = 1004
f(4076)    = 1018
f(16308)   = 4076
f(8156)    = 2038
f(32628)   = 8156
f(3444443) = 10
f(9440449) = 5

Aside: Except for the final two test cases (which are palindromic primes), each one is a record in this sequence such that its position is an additional record.
You may also note that (the position)/(the record) is around four, and I conjecture that this ratio converges to four.
Test Implementations:
Mathematica:
Maxnum4s[x_] := Block[{thisbest = 0, best = 0, bestpos = 4},
  Do[thisbest = num4s[x, pos];
   If[thisbest > best, best = thisbest; bestpos = pos, 0], {pos, 5, x - 1}]; {bestpos, best}]

Python3:
def foursCount(x0,b):
    count = 0
    x     = x0
    while x > 0:
        if x % b == 4:
            count += 1
        x = x // b
    return count

def fouriest(x):
    bestpos = 4
    best    = 0
    this    = 0
    for pos in range(4,x):
        this = foursCount(x,pos)
        if this > best:
            best    = this
            bestpos = pos
    return bestpos

C:
int foursCount(int x0, int b){
    int count = 0;
    int     x = x0;
    while (x > 0) {
        if (x % b == 4) {
            count++;
        }
        x = x / b;
    }return count;
}
int fouriest(int x){
    int pos     = 5;
    int this    = 0;
    int best    = 0;
    int bestpos = 0;
    while (pos < x) {
        this = foursCount(x, pos);
        if (this > best) {
            bestpos = pos;
            best    = this;
        }
        pos++;
    }
    return bestpos;
}

If you're curious, just for fun:
Mathematica:            77.042 s
Python:                  8.596 s
Haskell (Interpreted): 579.270 s
Haskell (compiled):      4.223 s
C:                       0.129 s

Haskell, 82 bytes
The function 'f' gives the final result:
_#0=0
b#x=sum[1|4==mod x b]+b#div x b
f x=[b|b<-[5..x],and[b#x>=c#x|c<-[b..x]]]!!0

Less golfed:
countFours 0    _ = 0
countFours base x | x == 0          = 0
                  | mod x base == 4 = 1 + countFours (div x base) base

f x = head [base | base <- [5..x], and smallerBasesNotFouriest]
  where
    smallerBasesNotFouriest = [(countFours base x) >= (countFours base' x) | base' <- [5..base]]


Fill empty spaces by filling empty blanks Write a function (such as placeAt) that takes an array of non-negative integers and an index that is a non-negative integer. It should place a 1 at the given index, possibly shifting other entries by one spot to vacate that spot, with 0's standing for empty spots.

If the entry at the desired index is 0, fill it with a 1.
Otherwise, look for the nearest 0 to the left of the index. Shift entries one spot left into that 0 to make room, then fill the index with a 1.
If there's no 0 to the left, do the same going right.
If neither is possible (i.e. if there is no 0), return the array unchanged.

The items are 0-indexed. Function name can be anything you want.

Examples:

(Letters stand for any positive integer values.)

[a, b, 0, c, d, 0] placeAt 2    // output [a, b, 1, c, d, 0]    place 2 is 0, just fill
[a, b, 0, c, d, 0] placeAt 3    // output [a, b, c, 1, d, 0]    place 3 is filled, shift items left
[a, b, 0, c, d, 0] placeAt 0    // output [1, a, b, c, d, 0]    place 0 is filled, can't shift left, shift items right
[a, b, 0, c, d, 0] placeAt 1    // output [a, 1, b, c, d, 0]    place 1 is filled, can't shift left, shift items right
[0, a, b, 0, c, d, 0] placeAt 2 // output [a, b, 1, 0, c, d, 0] place 2 is filled, shift items left
[0, a, b, 0, c, d, 0] placeAt 4 // output [0, a, b, c, 1, d, 0] place 4 is filled, shift items left (notice you keep shifting up until a 0)
[0, 2, 0, 2] placeAt 3          // output [0, 2, 2, 1]          place 3 is filled, shift items left

This is a code golf challenge. The shortest entry at the end of 9 days wins.

JavaScript (ES6), 85

Test running the snippet on any EcmaScript 6 compliant browser (notably not Chrome not MSIE. I tested on Firefox, Safari 9 could go)

(I found this without looking at any of the other answers, now I see it's very similar to rink's. Yet quite shorter. Probably I won't get many upvotes for this one)

F=(a,p,q=~a.lastIndexOf(0,p)||~a.indexOf(0))=>(q&&(a.splice(~q,1),a.splice(p,0,1)),a)

// Ungolfed
U=(a,p)=>{
  q = a.lastIndexOf(0, p)
  if (q < 0) q = a.indexOf(0)
  if (q >= 0) {
    a.splice(q, 1)
    a.splice(p, 0, 1)
  }
  return a
}

// TEST
out=x=>O.innerHTML+=x+'\n';

[ [['a', 'b', 0, 'c', 'd', 0], 2, ['a', 'b', 1, 'c', 'd', 0]] // place 2 is 0, just fill
, [['a', 'b', 0, 'c', 'd', 0], 3, ['a', 'b', 'c', 1, 'd', 0]] // place 3 is filled, shift items left
, [['a', 'b', 0, 'c', 'd', 0], 0, [1, 'a', 'b', 'c', 'd', 0]] // place 0 is filled, can't shift left, shift items right
, [['a', 'b', 0, 'c', 'd', 0], 1, ['a', 1, 'b', 'c', 'd', 0]] // place 1 is filled, can't shift left, shift items right
, [[0, 'a', 'b', 0, 'c', 'd', 0], 2, ['a', 'b', 1, 0, 'c', 'd', 0]] // place 2 is filled, shift items left
, [[0, 'a', 'b', 0, 'c', 'd', 0], 4, [0, 'a', 'b', 'c', 1, 'd', 0]] // place 4 is filled, shift items left (notice you keep shifting up until a 0)
, [['a', 'b', 'c', 'd'], 2, ['a', 'b', 'c', 'd']] // impossible
, [[0, 2, 0, 2], 3, [0, 2, 2, 1]]] // place 3 is filled, shift items left
.forEach(t=>{
  i=t[0]+''
  r=F(t[0],t[1])+''
  k=t[2]+''
  out('Test ' + (r==k?'OK':'Fail') +'\nInput: '+i+' '+t[1]+'\nResult:'+r+'\nCheck: '+k+'\n')
})


90% fail this challenge? I guess I'm not the only one who have seen this kind of image on Facebook (and other sites).

The picture above was posted 16 days ago, and has accumulated 51 k comments. Some answers: 0, 4, 8, 48, 88, 120, 124 and so on.

Challenge:

The mathematics in the question doesn't make sense1, so we can't find the correct answer by looking at the equation (or whatever you'd call that mess of numbers and operators). However, there's a very large number of people who have answered, and 10% of those people are right!

Let's find the right answer!

Take an integer, percent, decimal value in 0-1, or fraction N representing how many percent of the test group who failed the question (or optionally how many answered correctly), and a list of numbers representing the answers people post.

Find the number that 100-N percent of the test group answered and output it. If there are more than one answer that matches this criterion, then you must output all of them.
If there are no answers that are represented 100-N percent of the time then you must output the number that's closest (measured in number of answers from 100-N).

To make the input rules for N clear: If 90 % fails, then you may input 90, 10, 0.9 or 0.1. You must specify which one you choose. You may assume that the percentage numbers are integers.

Test cases:

In the test cases below, N is the percentage that failed the test. You may choose to input using any of the allowed input methods.

N:  90   (meaning 90 % will fail and 10 % answer correctly)
List: 3 1 5 6 2 1 3 3 2 6
Output: 5   (because 90 % of the answers weren't 5)
---
N:  50   (50 % will answer correctly)
List: 3 6 1 6
Output: 6   (because 50 % of the answers weren't 6)
---
N:  69   (31 % will answer correctly)
List: 1 9 4 2 1 9 4 3 5 1 2 5 2 4 4 5 2 1 6 4 4 3
Output: 4    (because 31% of 22 is 6.82. There are 6 fours, which is the
              closest to 6.82)
---
N = 10   (90 % will answer correctly)
List: 1 2 3 4 5 6 7 8 9 10
Output: 1 2 3 4 5 6 7 8 9 10 (because 9/10 will answer correctly. All numbers
                              have been answered the same number of times, thus
                              all are equally likely to be correct.
---
N:  90
List: 1 1 1
Output: 1

code-golf

1 Please don't argue with me here. If you "know" the answer, join the other 10% and post it on Facebook!

MATL, 16 14 bytes

-1 byte thanks to @Giuseppe

-1 byte thanks to @LuisMendo

SY'ts/i-|tX<=)

Explanation:

        % implicit input
S       % sort
Y'      % run-length encoding
ts      % duplicate elements and sum (get number of elements)
/       % array right division (get array of probability for each answer)
i-|     % get absolute difference with second input
tX<     % duplicate and get minimum value
=)      % get each answer that match with the minimum value
        % (implicit) convert to string and display

Try it online! or verify all test cases


Write a program that sees the New Year in itself Write the smallest program that maps strings injectively to outputs and maps itself to 2020.

To be clear, your program \$p\$ must have the following properties:

every possible input string \$s\$ has a well-defined output \$p(s)\$,
for every pair of strings \$s\$ and \$t\$ with \$s\neq t\$, it holds that \$p(s)\neq p(t)\$, and
\$p(p)=2020\$.

Be sure to explain why your submission satisfies properties 1 and 2. For property 3, the output can be a string or any type of number.

Edit 1: Programs need to be proper quine variants. Reading the source code is not allowed.

Edit 2: Note that as a consequence of property 2, it holds that \$p(s)\neq p(p)\$ for every \$s\neq p\$.

awk, 4 bytes
The structure of an awk program is pattern { action }. If pattern evaluates to true, { action } is performed. If { action } is omitted, the default is to output the current input record.
Code:
2020

As 2020 always evaluates to true, the program always prints it's input, therefore satisfying properties 1. and 2. When the input is the program itself it satisfies property 3. \$p(p)=2020\$ — even \$p(p)=p\$.
Some test cases:
$ echo 2020 | awk '2020'
2020
$ echo 0 | awk '2020'
0
$ echo "" | awk '2020'

$ echo foo | awk '2020'
foo

Would've been more glorious back in the good old days:
$ echo 1 | awk '1'
1


Loan "generous" amounts of money Introduction
You have a friend that keeps asking you for loans and you are getting tired of it. Today, he came for a loan again.  Instead of turning down his offer, you get a great idea: troll your friend by giving him as many coins/bills as possible.
Challenge
You will take as input: the amount of money your friend wants a loan for and the amount of coins/bills you have. For this challenge, the possible denominations are $20.00, $10.00, $5.00, $2.00, $1.00, $0.25, $0.10, $0.05, and $0.01. An example of input is 5.67, [5, 3, 4, 5, 5, 9, 8, 1, 2] if you friend wants $5.67 and you have 5 $20 bills, 3 $10 bills, etc. Your output will be the amount of coins/bills that gives your friend as much metal/paper/plastic as possible.
If it is not possible to give your friend the exact amount of money he wants, give him the closest amount of money you can pay that is greater than what he wants. For example, if your friend wants $0.07 but you only have [0, 0, 0, 0, 0, 2, 4, 2, 0], give him 2 $0.05 coins (not 1 $0.10 because that wouldn't be giving him as many coins as possible!).
If your friend wants more money than you have, give him all your money (and pray you won't need to buy anything).
Test cases
Input:  6.54, [9, 8, 7, 6, 5, 4, 3, 2, 4]
Output: [0, 0, 0, 1, 4, 1, 2, 1, 4]

Input:  2, [0, 1, 0, 0, 0, 0, 0, 0, 0]
Output: [0, 1, 0, 0, 0, 0, 0, 0, 0]

Input:  9999, [0, 0, 0, 0, 0, 0, 0, 0, 1]
Output: [0, 0, 0, 0, 0, 0, 0, 0, 1]

Input:  0, [99, 99, 99, 99, 99, 99, 99, 99, 99]
Output: [0, 0, 0, 0, 0, 0, 0, 0, 0]

This is code-golf so shortest code wins.


Biggest Irreducible Hello World Create a program that outputs Hello, World!

The winner is the source code that is the biggest, subject to the constraint that it is irreducible

For this challenge, irreducible means there does not exist a program that outputs Hello, World! that can be constructed by removing characters from the original program.

For example

console.log(`Hello, ` + `World!`);

can have the the bracketed characters removed

console.log(`Hello, [` + `]World!`)[;] -> console.log(`Hello, World!`)

And it will still output Hello, World, so it is not irreducible.

Extra Rules:

Whitespace is ignored with regards to both irreducibility and size.
Unary or anything that operates in a similar fashion (I'll make this more clear if I have to) is banned.

Keg,  \$3.3 \times 10^{8912898}\$ bytes
...÷⅍+ℤ,(|⅍+)ℤ,(|⅍+)ℤ,(|⅍+)ℤ,(|⅍+)ℤ,⅍+ℤ,⅍+ℤ,⅍+ℤ,(|⅍+)ℤ,(|⅍+)ℤ,(|⅍+)ℤ,(|⅍+)ℤ,⅍+ℤ,

Program as seen in the raw editor

So where that ... is, replace it with \$3.3 * 10^{8912898}\$ 0s. Then, add a ! after those 0s. This splits the number into chunks, divides these chunks by  and outputs them.
I owe a special thanks to @JoKing for helping me generate a truly irreducible score... it took me a while to understand it, but it got there in the end.


Two Dimensional Waterflow problem The one dimensional twitter waterflow problem is this:

You are given an array that represents a hill in the sense that the ith entry is the height of the ith location of the hill. When it rains, water logs in the hills, and you need to figure out how much water would log.

For example, after raining, the array 2 5 3 4 3 2 5 5 3 4 2 2 2 looks like this,

and 9 units of water have accumulated.

The challenge is to solve the 2D version of this. To clarify, you will be given a 2D matrix of land heights, and you will have to output the total amount of rainwater it can collect. Water cannot flow out through diagonals, but only the four cardinal directions.

Python 3, O(h × w × d) 296 bytes, O(h × w × d')

def f(a):
 w=0;b=[len(a[0])*[0]];a=b+a+b;a=[[0]+x+[0]for x in a];b=sorted(set(sum(a,[])))
 for[i,j]in zip(b,b[1:]+[1+max(b)]):
  c=[[0,0]]
  while c:
   [x,y]=c.pop()
   if x<len(a)and x>=0and y<len(a[0])and y>=0and a[x][y]<=i:w+=i-a[x][y];a[x][y]=j;c+=[[x+1,y],[x,y+1],[x-1,y],[x,y-1]]
 return w

Try it online! Where d' represents the number of distinct values in the input. Edit: Saved 3 bytes thanks to @Mr.Xcoder.


Smallest code to return sum of all characters in an array of strings Smallest code to return sum of all characters of an array of C-strings, including null-byte-terminattor of each string in the array.

example in C:

    const char *a[] = { "abc", "bdef", "cee", "deee" };
    size_t n = sumOfAllBytes(a);
    printf("n = %d\n", n); // n = 18

e.g.,

   strlen(a[0]) + 1 + ... + strlen(a[n])

where n is array-size-1, ie, the last elemet in the array, in this case, deee word. Note that n = 4 (starting from 0 as C does)

Each character is an ASCII character in C it's 1 byte-size.

Haskell, 21 19 bytes

succ.length.unwords

Edit: Removed two bytes thanks to ais523!


Verify a ballot triangle A ballot number, which we'll label B, is the number of ways of arranging the numbers from 1 through B(B+1)/2 into a triangle, such that each row and column is in any increasing order. The first four ballot numbers are:

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

a(3) is 2, which means that there are 2 ways of arranging the numbers from 1 to 3(3+1)/2 = 6 in such a triangle:

1          1
2 3    or  2 4
4 5 6      3 5 6

See the OEIS sequence entry for more details.

Your challenge, given a ballot triangle, is to verify its correctness. If it satisfies the conditions of a ballot triangle (rows and columns increasing), you should output how many other ways (excluding the one in the input) there are to arrange the triangle correctly. If the input triangle is incorrectly constructed, you should output nothing.

Trailing newlines are allowed.

Input

A triangle of numbers, which may or may not be a valid ballot triangle. For example:

1
2 3
4 5 6

1
10 5
9 8 2
7 6 4 3

1
3 2

9
2 11
14 3 5
12 8 1 7
15 13 10 4 6

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

Output

If the input is a valid ballot triangle, the remaining number of ways to arrange the same numbers in a valid ballot triangle. If the input is not a valid ballot triangle, nothing. For example, the inputs above produce these outputs (<nothing> is a placeholder for an actual empty output):

1                     # the same as a(3)-1

<nothing>

<nothing>

<nothing>

33591                 # the same as a(6)-1

Scoring

This is code-golf: as usual, lowest byte-count wins. Tiebreaker is earliest posted.

Jelly, 20 bytes

;Zµ⁼Ṣ€
ẋÇFŒ!ṁ€⁸ÇÐfL’

For valid ballot triangles, run time and memory usage are at least O(n!), where n is the number of entries of the triangle. Invalid ones are recognized by crashing, thus printing nothing.

Try it online!

Test run

Locally, I was able to verify that a(4) is calculated correctly.

$ time jelly eun ';Zµ⁼Ṣ€¶ẋÇFŒ!ṁ€⁸ÇÐfL’' '[1],[2,3],[4,5,6],[7,8,9,10]'
11

real    6m9.829s
user    6m7.930s
sys     0m2.579s

How it works

;Zµ⁼Ṣ€         Helper link. Argument: T (triangular array)

 Z             Zip/transpose T.
;              Concatenate the original and the transposed copy.
  µ            Begin a new monadic chain, with the previous result (R) as argument.
    Ṣ€         Sort each array in R.
   ⁼           Test for equality with R.
               This returns 1 if T is a ballot triangle, 0 if not.

ẋÇFŒ!ṁ€⁸ÇÐfL’  Main link. Argument: A (triangular array)

 Ç             Call the helper link with argument A.
ẋ              Repeat A that many times.
               This yields an empty array if A is not a ballot triangle.
  F            Flatten the result.
   Œ!          Generate all permutations of the digits of A.
     ṁ€⁸       Mold each permutation like A, i.e., give it triangular form.
               This crashes if permutation array is empty.
        ÇÐf    Filter; keep permutations for which the helper link returns 1.
           L’  Compute the length and decrement it.


Match the Striking Clock Introduction:

At home we have a clock that strikes the stated amount at each hour, but also strikes once at every half-hour. So from 0:01 to and including 12:00 it strikes in this order:

1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12

Challenge:

Given an integer n, output a list of time-frames in which the total strikes are equal to n. In addition, always start at least 1 minute before this time-frame and end at least 1 minute after this time-frame (and at most 29 minutes).
For example, if the input is n=8, the output could be:

[00:59-03:01, 01:29-03:31, 02:59-04:01, 05:29-06:31, 06:29-07:01, 06:59-07:31, 07:59-08:01]

For which these time-frames have the following sums, all equaling 8:

[1+1+2+1+3, 1+2+1+3+1, 3+1+4, 1+6+1, 1+7, 7+1, 8]

Challenge rules:

Output is flexible. You can output as Time (or Date/DateTime) objects, timestamps, strings (with or without leading zeroes), decimals with .29/.31/.59/.01 (i.e. 0.29-3.01 instead of 00:29-03:01), etc. As long as it's clear it's before and after the time-frame.
In addition, you can choose the amount yourself. In all my examples I use 1 minute, but you can also choose 5 minutes, 15 minutes, etc. This also means you can use .4/.6/.9/.1 (i.e. 0.4-3.1 instead of 00:24-03:06) for example.
The list is also flexible. Can be a list/collection, array, delimiter-separated string, printing per line to STDOUT, etc.
Please state which output choice you've made. Note: You are not allowed to output the sums of the time-frames like above, this is only mentioned as clarification. You must output the time-frames, including slightly before and after it.
The strikes do wrap around from 12:00 to 00:30. So if n=14, two of the time-frames are 11:29-00:31 and 11:59-01:01.
Input will be in the range 1 <= n <= 90, where 90 is the total sum of all possible strikes.
The time-frames you return can be in any order.

General rules:

This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.
If possible, please add a link with a test for your code.
Also, please add an explanation if necessary.

Test cases:

(all using 1 minute before / after the time-frames and leading zeroes)

Input: 8
Ouput:
[00:59-03:01, 01:29-03:31, 02:59-04:01, 05:29-06:31, 06:29-07:01, 06:59-07:31, 07:59-08:01]

Input: 14
Output:
[00:29-04:01, 00:59-04:31, 02:59-05:01, 04:29-06:31, 05:59-07:01, 11:29-00:31, 11:59-01:01]

Input: 90
Output:
[00:29-00:01, 00:59-00:31, 01:29-01:01, 01:59-01:31, 02:29-02:01, 02:59-02:31, 03:29-03:01, 03:59-03:31, 04:29-04:01, 04:59-04:31, 05:29-05:01, 05:59-05:31, 06:29-06:01, 06:59-06:31, 07:29-07:01, 07:59-07:31, 08:29-08:01, 08:59-08:31, 09:29-09:01, 09:59-09:31, 10:29-10:01, 10:59-10:31, 11:29-11:01, 11:59-11:31]

Input: 1
Output:
[00:29-00:31, 00:59-01:01, 01:29-01:31, 02:29-02:31, 03:29-03:31, 04:29-04:31, 05:29-05:31, 06:29-06:31, 07:29-07:31, 08:29-08:31, 09:29-09:31, 10:29-10:31, 11:29-11:31]

Input: 2
Output:
[00:29-01:01, 00:59-01:31, 01:59-02:01]

JavaScript (ES6), 104 bytes

Prints time intervals in H.MM,H.MM format.

F=(n,f=0,s=n,t=f++)=>t<f+23?F(n,f,s-=t&1||t/2%12+1,++t,s||alert([f/2%12+.01,-~t/2%12+.01])):f<24&&F(n,f)

Try it online!

Uses essentially the same algorithm as the non-recursive version below.

Non-recursive version, 117 bytes

Outputs a space-delimited string of time intervals in H.MM,H.MM format.

n=>[...Array(24)].map((_,f,a)=>a.map(_=>(s-=t++&1||t/2%12+.5)||(r+=[-~f/2%12+.01,-~t/2%12+.01]+' '),s=n,t=f),r='')&&r

Test cases

let f =

n=>[...Array(24)].map((_,f,a)=>a.map(_=>(s-=t++&1||t/2%12+.5)||(r+=[-~f/2%12+.01,-~t/2%12+.01]+' '),s=n,t=f),r='')&&r

console.log(f(8))
console.log(f(14))
console.log(f(90))
console.log(f(1))
console.log(f(2))

Commented

n =>                           // n = input
  [...Array(24)].map((_, f, a) // FOR f = 0 TO 23:
    => a.map(_ =>              //   FOR t = f TO f + 23:
      (                        //     update s
        s -=                   //       by subtracting:
          t++ & 1 ||           //         - 1 if t is odd (half hour)
          t / 2 % 12 + .5      //         - the current hour if t is even
      ) || (                   //     if s is equal to zero:
        r += [                 //       update the result string by appending:
          -~f / 2 % 12 + .01   //         - the formatted 'from' time
          ,                    //         - a comma
          -~t / 2 % 12 + .01   //         - the formatted 'to' time
        ] + ' '                //       and a padding space
      ),                       //     inner map() initialization:
      s = n,                   //     - s = target number of strikes
      t = f                    //     - 'to' time = 'from' time
    ),                         //   end of inner map()
    r = ''                     //   start with r = empty string
  )                            // end of outer map()
  && r                         // return r


Pass The ⚽ Around The Circle The ball game is a game in which a number of players sit together in a circle. Each player is first assigned a number \$ n \$, either 1, 2, or 3. The game begins with any starting player, and proceeds clockwise around the circle. The current player with the ball throws it to the next player. Who the next player is solely depends on the number \$ n \$ the current player was assigned.

If \$ n = 1 \$, the next player will be the one sat directly adjacent (one space away), traveling in the current direction.

If \$ n = 2 \$, the next player will be the one sat two spaces away, traveling in the current direction.

If \$ n = 3 \$, the direction of play is first switched (clockwise to counter-clockwise, and vice-versa). The next player will then be the one sat directly adjacent, traveling in the new direction.

Task

You are given a list of numbers \$ l \$ all in the range \$ [1 - 3] \$, denoting the numbers each player was assigned. The elements in \$ l \$ are given in clockwise order, and such that the last element of \$ l \$ is adjacent to the first element. Your task is to determine the number of players who have touched the ball, before it reaches a player who previously already touched the ball.

Example

The starting player is at the first index. X represents a visited index, O represents an index visited twice.

[1, 2, 1, 1, 2, 2, 3] ->
[X, 2, 1, 1, 2, 2, 3] ->
[X, X, 1, 1, 2, 2, 3] ->
[X, X, 1, X, 2, 2, 3] ->
[X, X, 1, X, X, 2, 3] ->
[X, X, 1, X, X, 2, X] ->
[X, X, 1, X, X, X, X] ->
[X, X, 1, O, X, X, X]
The answer is 6.

Clarifications

\$ l \$ can be inputted in any reasonable format, but the numbers 1, 2, and 3 must not change
The starting player does not have to be at the first index, but please specify where it would start
This is code-golf, so the shortest code in bytes wins!

Test Cases

Input (start is index 0) -> Output
[1] -> 1
[2] -> 1
[3] -> 1
[3, 2] -> 2
[2, 1] -> 1
[2, 2, 3] -> 3
[1, 1, 1, 1, 1] -> 5
[2, 2, 2, 2, 2] -> 5
[3, 3, 3, 3, 3] -> 2
[1, 3, 2, 1, 2, 3] -> 2
[1, 2, 1, 1, 2, 2, 3] -> 6

Python 3, 67 55 bytes

f=lambda x,*l:x and-~f(*l[x%3-1::1-x//3*2],0,*l[x%2:1])

Try it online!

Use @Leo's idea of keeping the current player at a fixed index and transforming the list instead. Be sure to check out and upvote his answer!

If the current list is [x, a, b, c, d], where x is the move of the current player, then we want to rotate the list appropriately, and replace x with 0:

If x == 1, the new list is [a, b, c, d, 0]
If x == 2, the new list is [b, c, d, 0, a]
If x == 3, the new list is [d, c, b, a, 0]
If x == 0, this player has already been visited, thus we stop the algorithm.

Python 2, 90 85 bytes

f=lambda l,d=1,p=0,*t:(p in t)^1and-~f(l,[d,-d][l[p]>2],(-~l[p]%4*d-d+p)%len(l),p,*t)

Try it online!

Not every elegant, but does the job.

This recursive function keeps track of the current direction d, the position p, and the list of seen position t.


Very Nice Friedman Numbers A Friedman Number is a positive integer that is equal to a non-trivial expression which uses its own digits in combination with the operations +, -, *, /, ^, parentheses and concatenation.

A Nice Friedman Number is a positive integer that is equal to a non-trivial expression which uses its own digits in combination with the same operations, with the digits in their original order.

A Very Nice Friedman Number (VNFN), which I am inventing here, is a Nice Friedman Number which can be written without the less pretty (in my opinion) parts of such an expression. Parentheses, concatenation and unary negation are disallowed.

For this challenge, there are three possible ways of writing an expression without parentheses.

Prefix: This is equivalent to left-associativity. This type of expression is written with all operators to the left of the digits. Each operator applies to the following two expressions. For instance:

*+*1234 = *(+(*(1,2),3),4) = (((1*2)+3)*4) = 20

A VNFN which can be written this way is 343:

^+343 = ^(+(3,4),3) = ((3+4)^3) = 343

Postfix: This is equivalent to right-associativity. It is just like prefix notation, except that the operation go to the right of the digits. Each operator applies to the two previous expressions. For instance:

1234*+* = (1,(2,(3,4)*)+)* = (1*(2+(3*4))) = 14

A VNFN which can be written this way is 15655:

15655^+** = (1,(5,(6,(5,5)^)+)*)* = (1*(5*(6+(5^5)))) = 15655

Infix: Infix notation uses the standard order of operations for the five operations. For the purposes of the challenge, that order of operations will be defined as follows: Parenthesize ^ first, right associatively. Then, parenthesize * and / simultaneously, left associatively. Finally, parenthesize + and - simultaneously, left associatively.

1-2-3 = (1-2)-3 = -4
2/3*2 = (2/3)*2 = 4/3
2^2^3 = 2^(2^3) = 256
1^2*3+4 = (1^2)*3+4 = 7

A VNFN which can be written this way is 11664:

1*1*6^6/4 = (((1*1)*(6^6))/4) = 11664

Challenge: Given a positive integer, if it can be expressed as a non-trivial expression of its own digits in either prefix, infix or postfix notation, output that expression. If not, output nothing.

Clarifications: If multiple representations are possible, you may output any non-empty subset of them. For instance, 736 is a VNFN:

+^736 = 736
7+3^6 = 736

+^736, 7+3^6 or both would all be acceptable outputs.

A "Trivial" expression means one that does not use any operators. This only is relevant for one digit numbers, and means that one digit numbers cannot be VNFNs. This is inherited from the definition of a Friedman Number.

Answers should run in seconds or minutes on inputs under a million.

Related.

IO: Standard IO rules. Full program, function, verb or similar. STDIN, command line, function argument or similar. For outputing "Nothing", the empty string, a blank line, null or similar, and an empty collection are all fine. Output may be a string delimited with a character that cannot be in a representation, or may be a collection of strings.

Examples:

127
None

343
^+343

736
736^+
7+3^6

2502
None

15655
15655^+**

11664
1*1*6^6/4
1^1*6^6/4

5
None

Scoring: This is code golf. Fewest bytes wins.

Also, if you find one, please give a new Very Nice Friedman Number in your answer.

Perl, 345 334 318 293 263 245B

$_='$_=$i=pop;$c=y///c-1;sub f{say if$c&&$i==eval pop=~s/\^/**/gr}A$m)$1$4"})};f"("x$c.$m}globOx$c.$i;A$1$4($m"})};f$m.")"x$c}glob$i.Ox$c;map{f$_}glob joinO,/./g';s!O!"{+,-,*,/,^}"!g;s!A!'map{m{(\d)((?R)|(\d)(?{$m=$3}))(.)(?{$m="'!ge;s!d!D!;eval

Call with perl -M5.10.0 scratch.pl 736

Results

The first few results that I found are:

^+343
736^+
7+3^6
^+/3125
^+^3125
/^+-11664
/^--11664
1-1+6^6/4
/^++14641
^^++14641
1+5^6/1-8
1+5^6^1-8
1+5^6-2-2
1+5^6-2^2
1+5^6+2-4
1+5^6+4^2
-^+^16377
-^-+16377
/^+^16384
/^-+16384

Explanation

Fully ungolfed

I tried to repeat myself as much as possible to make the later golfing easier.

#!perl
use 5.10.0;

$_ = $input = pop;

# y///c counts characters in $_
$count = y///c - 1;

sub f {
    say if $count && $input == eval pop =~ s/\^/**/gr
}

# PREFIX
map {
    m{                            # Parses *^+1234
        (\D)                      # $1 = first symbol
        (
            (?R)                  # RECURSE
        |
            (\d)(?{               # $3 = first digit
                $match=$3
            })
        )
        (.)(?{                    # $4 = last digit
            $match="$match)$1$4"
        })
    }x;
    f "(" x $count . $match
}
    # glob expands '{0,1}{0,1}' into 00,01,10,11
    glob "{+,-,*,/,^}" x $count . $input;

# POSTFIX
map {
    m{(\d)((?R)|(\d)(?{$match=$3}))(.)(?{$match="$1$4($match"})};
    f $match. ")" x $count
}
    glob $input . "{+,-,*,/,^}" x $count;

# INFIX
# /./g splits $_ into characters
map { f $_} glob join "{+,-,*,/,^}", /./g

How it's golfed

Remove whitespace & comments and replace all vars with 1-character version
Wrap program in $_=q! ... !;eval
Extract strings and substitute them in afterwards.

This gives something like this, from which you can remove the line breaks for the result:

$_='
    $_=$i=pop;
    $c=y///c-1;
    sub f{say if$c&&$i==eval pop=~s/\^/**/gr}
    A$m)$1$4"})};f"("x$c.$m}globOx$c.$i;
    A$1$4($m"})};f$m.")"x$c}glob$i.Ox$c;
    map{f$_}glob joinO,/./g
';
s!O!"{+,-,*,/,^}"!g;
s!A!'map{m{(\d)((?R)|(\d)(?{$m=$3}))(.)(?{$m="'!ge;
s!d!D!;
eval


Emulate the Professor's typing Emulate the Professor's typing
Background
Unfortunately, the Professor is not able to use his keyboard properly: whenever he is meant to use the Shift key, he presses Caps Lock once before typing, and doesn't bother to correct himself. If there are two or more keys in a row that require Shift, he presses Caps Lock before the first one and does nothing before the others.
As his secretary, I want to replicate this effect so that people think that he is the one replying to his emails, not me. He knows his typing looks stupid, but he doesn't care.
Task
Write a program that takes STDIN or file input of some text, and then outputs that text as if it had been typed by the Professor.
This is code golf, and standard loopholes are not allowed.
Keyboard layout
Default:
` 1 2 3 4 5 6 7 8 9 0 - =
   q w e r t y u i o p [ ]
    a s d f g h j k l ; ' #
   \ z x c v b n m , . /

With shift:
¬ ! " £ $ % ^ & * ( ) _ +
   Q W E R T Y U I O P { }
    A S D F G H J K L : @ ~
   | Z X C V B N M < > ?

With caps lock:
` 1 2 3 4 5 6 7 8 9 0 - =
   Q W E R T Y U I O P [ ]
    A S D F G H J K L ; ' #
   \ Z X C V B N M , . /

Example input / output
(The CapsLock line is just there for your understanding, and should not be outputted in your program)
Input:    abc ** def ! (ghijkl) mnop
Output:   abc 88 DEF 1 9GHIJKL0 mnop
CapsLock:     *      * *      *       (* means Caps Lock was pressed before this character)

Input:    print("Hello, World!"); sys.exit()
Output:   print92HELLO, world120; SYS.EXIT90
CapsLock:      *        *    *            *

Input:    !ABC!abc!ABC!abc!x!y!z
Output:   1ABC1ABC1abc1abc1X1y1Z
CapsLock: *       *       * * *

Python 2 - 269 275 290 318 337
Input is mostly safe if you use triple-quotes:"""print("Hello, World!"); sys.exit()"""
C=D=0
r=''
l,u,c=" `1234567890-=qwertyuiop[]asdfghjkl;'#\\zxcvbnm,./",' \xac!"\xa3$%^&*()_+QWERTYUIOP{}ASDFGHJKL:@~|ZXCVBNM<>?'," `1234567890-=QWERTYUIOP[]ASDFGHJKL;'#\\ZXCVBNM,./"
for h in input():w=h!=' ';U=h in u;C^=w&U&~D;D=U&w;r+=[l,c][C][[l,u][U].find(h)]
print r

Encoding doesn't seem to help much, except with the awkward ¬ and £ characters (I've tried looking at other problems like this and I think I should try to use split?)(It doesn't seem like the keyboard compresses enough to make it worth .decode, etc...)
Also, spaces suck.
Edit note: Indexing is weird


Crosswalk Efficiency A standard road intersection contains 4 sidewalk corners and four crosswalks connecting them. It could also have 2 diagonal walks.

    sRRRRs
    iOOOOi
    dAAAAd
    eDDDDe
side0----1walk
ROAD|\  /|ROAD
ROAD| \/ |ROAD
ROAD| /\ |ROAD
ROAD|/  \|ROAD
side2----3walk
    wRRRRw
    aOOOOa
    lAAAAl
    kDDDDk

Not all 6 crosswalks are needed to let pedestrians get from any corner to any other (assuming no jaywalking). It's better for traffic and cheaper for the highway department if there are fewer crosswalks. However, it is better for pedestrians if they can get across faster.

Let L be the total length of the crosswalks present in the intersection. Assume the intersection is a unit square, so the length of orthogonal walks is 1 and for diagonal walks it's sqrt(2).

Let W be the average distance a pedestrian needs to walk when crossing the intersection. Each corner fills up with pedestrians evenly and each pedestrian at a corner is randomly headed for one of the 3 other corners with equal chance.

When L and W are low we have an efficient intersection. Let E = 1 / (W * L) be the crosswalk efficiency of a particular set of crosswalks. Higher E means more efficient.

Goal

Write a program that takes in a list of present crosswalks and outputs the efficiency.

Input will come from stdin in the form 01 32 21 (for example), which represents an intersection with crosswalks from corners 0 to 1, 3 to 2, and 2 to 1 (in a Z). Output to stdout.

Running your program might look something like

$ crosswalk.mylanguage 01 23
0.0

Scoring

This is code golf. The submission with the fewest characters wins.

Details

Pedestrians always stay on the crosswalks and always take the shortest route.
Pedestrians can change direction where the diagonals meet (and at corners).
If all corners aren't connected take W to be infinity (and E to be 0).
The input crosswalk edges are always unique and there are only up to 6.
The input or corner order doesn't matter. 01 32 21 is the same as 23 21 10.


I palindrome the source code, you palindrome the input! This is a rip-off of a rip-off of a  rip-off of a rip-off of a rip-off. Go upvote those!
Your task, if you accept it, is to write a program/function that outputs/returns its input/args. The tricky part is that if I make your source code palindrome via duplicating reversed source code after the original code, the output must be returned "palindromize".
The source code will be only duplicated once.
Examples
Let's say your source code is ABC and the input is xyz. If i run ABC the output must be xyz. But if i run ABCCBA instead, the output must be xyzzyx.
Put it in a table:
Input: "xyz"
code ABC => "xyz"
code ABCCBA => "xyzzyx" (aware that it isn't "xyzyx")

Details
Your code before processing should return the input.
Your code after processing should return the input with reversed input following no matter what input is.
The process:
Your code, no matter what, will be followed with a reversed code after it. Even if it's already palindrome by itself.
Multiline code:
Multiline code will be treated as single line code but with \n(newline)
Rules

Input can be taken in any convenient format.
Output can be in any convenient format as well. As long as it follow the input-reversed input order.
Standard Loopholes are forbidden.

Scoring
This is code-golf so the answer with the fewest amount of bytes wins.

Haskell, Full program, 39 bytes
iddi=(++)<*>reverse;main=interact--
 id

Try it online!
Mirrored

iddi=(++)<*>reverse;main=interact--
 iddi
--tcaretni=niam;esrever>*<)++(=iddi

Try it online!
Very simple approach for a full program.  We have two "lines" (separated by ; rather than an actual line break) of boilerplate ending in -- and then the function id.  When the program is reversed id gets changed to iddi, which we have defined to do the intended operation.
Haskell, Function, 20 bytes
f x=x--x esrever++

Try it online!
Mirrored
f x=x--x esrever++

 ++reverse x--x=x f

Try it online!
This one is also a pretty simple approach.  We have a function f x=x and   a payload hidden in a comment.  When the code is revealed the payload extends our function with ++reverse x.
Haskell, Function, No Comments, 95 bytes

i=id
ko 'a' b=i id b
ko u m=i reverse m
u=flip ko
k s="ab">>=s
yf i=k<$>u
erehw l=l
fy=i erehw

Try it online!
Mirrored
i=id
ko 'a' b=i id b
ko u m=i reverse m
u=flip ko
k s="ab">>=s
yf i=k<$>u
erehw l=l
fy=i erehw  where i=yf
l=l where
u>$<k=i fy
s=>>"ba"=s k
ok pilf=u
m esrever i=m u ok
b di i=b 'a' ok
di=i

Try it online!
The relevant function is fy. This one is likely not optimal.  I will explain it when I shorten it down a bit.


Rube Goldberg Hello World For this golf, you will need to use more than one language.
The task
A Rube Goldberg machine is a contraption that takes an enormous number of complicated steps in order to execute a very simple task. The goal of this golf is to output Rube Goldberg... but not directly.
The machine
Your "machine" is the source code that, once executed, will give another source code in another language that will output Rube Goldberg upon execution. Got it?
I rephrase: your initial code must give another code, that other code must output Rube Goldberg. Both codes must be written in different languages.
The bonus which is more like the only fun way to do it
There is a bonus if your code outputs a code that will output a code that will ... that will output Rube Goldberg.
NOTE: any sort of output can be used (stdout, stderr, dialog box, ...)
The points
The number of points is equal to the number of bytes used in your code, divided by the number of distinct, extra languages that you used.
NOTE: different languages use different encodings. The number of bytes is counted in the initial language with its own encoding.
Examples

Pyth -> J -> Javascript -> output in 30 bytes = 30/2 = 15 points (J and Javascript are the extra languages)
Java -> C# -> C++ -> PHP -> output in 36 bytes = 36/3 = 12 points (More bytes and more languages can win over fewer bytes and fewer languages (I know there is no way that these languages do it in 36 bytes))
C -> output in 10 bytes = 10/0 = Infinity points (No extra languages)
Python -> Perl -> Ruby -> Python -> Ruby in 44 bytes = 44/2 = 22 points (Perl and Ruby are the extra languages, the second Python is not counted as it is not an extra language, the second Ruby is not counted as it has already been used)

NOTE: Languages that output their input can't be used. That would be an extra language with absolutely no additional bytes.
The answer
Please provide an answer that clearly states which languages you used and shows us the code at each step (i.e.: in each language).
The winner
Of course, like usual, the lowest score wins.
NOTE: As usual, standard loopholes and "cheats" are not allowed.

Foo → gs2 → M → Jelly → Retina → Aeolbonn → Par → Actually → Sprects → sed → Universal Lambda → Lines → /// → m4: 19/13 ≈ 1.4615 points

"“GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦

All answers are given in the Jelly code page. ¶ represents a newline.

Mechanism

  Language      Code
 ——————————————————————————————————————
  Foo           "“GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦
  gs2           “GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ¦
  M             “GḋÞḊCøẉYỴ⁴ñ<ȯƥ»Ṿ
  Jelly         “¶:`".c Rube Goldberg#\/”
  Retina        ¶:`".c Rube Goldberg#\/
  Aeolbonn      :`".c Rube Goldberg#\/
  Par           `".c Rube Goldberg#\/
  Actually      ".c Rube Goldberg#\/
  Sprects       .c Rube Goldberg#\/
  sed           c Rube Goldberg#\/
  U.Lambda       Rube Goldberg#\/
  Lines         Rube Goldberg#\/
  ///           Rube Goldberg#/
  m4            Rube Goldberg#

EDIT: Oops, there was an error in the Pyth program. I replaced Pyth and GolfScript by Par.

EDIT 2: Added GNU m4.

EDIT 3: Added Foo and M.


Create a Magic 8 Ball As a child, my friend had a magic 8 ball that we would ask questions to and see what the fate of that question was.

Challenge

Your challenge is to write a program (or function) that when run (or called), outputs (or returns) a random answer from the possible answers below. (Random being: each output should have a nonzero chance of occurring but they do not need to meet any other criteria)

The possible answers from the Magic 8-ball are (case-insensitive):

It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yep
Signs point to yes
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

Input

No input.

Output

A random choice from above. Case does not matter.

Rules

Standard loopholes are not allowed.

This is code-golf, so the shortest code in bytes for each language wins!

SOGL V0.12, 166 bytes

,▓a⁰²z○½℮ķčλ─fj[Ycψ-⁸jΔkÆΞu±⁄│(┼∞׀±q- υ~‼U/[DΓ▓νg⁸⅝╝┘¤δα~0-⁄⅝v⁄N⁷⁽╤oο[]āŗ=§№αU5$┌wΨgΘ°σΖ$d¦ƨ4Z∞▒²÷βΗ◄⁴Γ■!≤,A╬╤╬χpLΧ⁸⁽aIΘād⁵█↔‚\¶σΞlh³Ζ╤2rJ╚↓○sēχΘRψΙ±ιΗ@:┌Γ1⁷‘Ƨ! ΘlΨιw

Try it Here!

\o/ every word was in SOGLs dictionary!


Find the indices of values in one list in another You must take two lists of positive integers as input, let's call these n and m.

You may assume that:

All integers in n are part of m
All integers in m are unique
The lists are non-empty

Challenge: Return the indices of where you find the values in n, in m.

That might be confusing, but I think the test cases will make the task pretty clear. The examples are 1-indexed, you may choose 0-indexed if you want to (please specify).

n = 5 3 4 1
m = 6 8 4 1 2 5 3 100
output: 6 7 3 4    // 5 is in the 6th position of m
                   // 3 is in the 7th position of m
                   // 4 is in the 3rd position of m
                   // 1 is in the 4th position of m

n = 5 3 4 9 7 5 7
m = 3 4 5 7 9
output: 3 1 2 5 4 3 4

n = 1 2 3 4 5 6
m = 1 2 3 4 5 6
output: 1 2 3 4 5 6

n = 16 27 18 12 6 26 11 24 26 20 2 8 7 12 5 22 22 2 17 4
m = 15 18 11 16 14 20 37 38 6 36 8 32 21 2 31 22 33 4 1 35 3 25 9 30 26 39 5 23 29 10 13 12 7 19 24 17 34 27 40 28
output: 4 38 2 32 9 25 3 35 25 6 14 11 33 32 27 16 16 14 36 18

n = 54
m = 54
output: 1

The winners will be the shortest solutions in each language.

This is a very nice meta-post by the way!

V, 26 bytes

jòdf kÄ/-
DÓÓ
ÒC1@"Gòdk

Try it online!

This is a very strange and hacky solution, because V has little to no concept of numbers. Input comes in this format:

6 8 4 1 2 5 3 100
5 3 4 1

With a trailing space on each line.

Hexdump:

00000000: 6af2 6466 206b c42f 122d 0a44 d3d3 0ad2  j.df k./.-.D....
00000010: 0143 311b 4022 47f2 646b                 .C1.@"G.dk

Explanation:

j                   " Move down one line (to N) (1)
 ò                  " Recursively:
  df                "   (d)elete until you (f)ind a space. This will be saved into
                    "   register '-' (2)
     k              "   Move up one line (to M)
      Ä             "   Duplicate line M (3)
       /<C-r>-      "   Move the cursor forward until the next occurence of register '-'
                    "   (the number we deleted from N)
                    "   (4)
D                   "   Delete every character *after* the cursor (5)
 ÓÓ                 "   Remove everything on this line except for whitespace
Ò<C-a>              "   Replace every character on this line with `<C-a>`, which is the
                    "   command for incrementing a number (6)
      C             "   Delete this line into register '"', and enter insert mode
       1<esc>       "   Enter a '1' and return to normal mode
             @"     "   Run register '"' as V code (7)
               G    "   Go to the last line (1)
                ò   " End recursion
                 dk " Delete the last two lines (m and n)

If this doesn't make it clearer, here are examples of the buffer during the various stages the loop goes through:

Stage 1 (| is the cursor)

6 8 4 1 2 5 3 100
|5 3 4 1

Stage 2:

6 8 4 1 2 5 3 100
|3 4 1

Stage 3:

|6 8 4 1 2 5 3 100
6 8 4 1 2 5 3 100
3 4 1

Stage 4:

6 8 4 1 2 |5 3 100
6 8 4 1 2 5 3 100
3 4 1

Stage 5:

6 8 4 1 2 |
6 8 4 1 2 5 3 100
3 4 1

Stage 6:

|<C-a><C-a><C-a><C-a><C-a>
6 8 4 1 2 5 3 100
3 4 1

Stage 7:

|6
6 8 4 1 2 5 3 100
3 4 1

Back to stage 1:

6
6 8 4 1 2 5 3 100
|3 4 1


Write A Program That Outputs Its Mirror Level There are 95 printable ASCII characters:
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

In the Consolas font (the Stack Exchange code block default), some of the characters have mirrors around a vertical axis of symmetry:

These pairs of characters are mirrors of each other: () [] {} <> /\
These characters are mirrors of themselves: ! "'*+-.8:=AHIMOTUVWXY^_ovwx| (Note that space is one.)
These do not have mirrors: #$%&,012345679;?@BCDEFGJKLNPQRSZ`abcdefghijklmnpqrstuyz~

(i, l, 0, #, and probably other characters are their own mirrors in some fonts but we'll stick to the Consolas shapes.)
A string is said to be a mirror of itself if it is made with only the 39 mirror characters, arranged such that the string has a central vertical line of symmetry. So ](A--A)[ is a mirror of itself but ](A--A(] is not.
Write a one-line even-length program that is a mirror of itself. When N copies of its left half have been prepended to it and N copies of its right half have been appended to it, it should output N+1. N is a non-negative integer.
For example, if the program was ](A--A)[ (left half: ](A-, right half: -A)[), then:

Running ](A--A)[ should output 1. (N = 0)
Running ](A-](A--A)[-A)[ should output 2. (N = 1)
Running ](A-](A-](A--A)[-A)[-A)[ should output 3. (N = 2)
Running ](A-](A-](A-](A--A)[-A)[-A)[-A)[ should output 4. (N = 3)
. . .
Running ](A-](A-](A-](A-](A-](A-](A-](A-](A-](A--A)[-A)[-A)[-A)[-A)[-A)[-A)[-A)[-A)[-A)[ should output 10. (N = 9)
etc.

Rules

Output to stdout or your language's closest alternative. There may be an optional trailing newline. No input should be taken.
The process should theoretically work for N up to 215-1 or beyond, given enough memory and computing power.
A full program is required, not just a REPL command.

The shortest initial program (N = 0 case) in bytes wins.

GolfScript, 10 bytes

!:{)::(}:!

Try it online with Web Golfscript: N = 0, N = 1, N = 2, N = 3, N = 41

Web GolfScript has a 1024 character limit, but the Ruby interpreter handles N = 32767 perfectly:

$ curl -Ss http://www.golfscript.com/golfscript/golfscript.rb > golfscript.rb
$ echo '"!:{):"32768*":(}:!"32768*' | ruby golfscript.rb > mirror-level-32767.gs
$ ruby golfscript.rb mirror-level-32767.gs
32768

How it works

Without any input, GolfScript initially has an empty string on the stack.

In the first left half, the following happens:

! applies logical NOT to the empty string. This pushes 1.
:{ saves the integer on the stack in the variable {.

Yes, that is a valid identifier, although there's no way to retrieve the stored value.
) increments the integer on the stack.
: is an incomplete instruction.

The the subsequent left halves, the following happens:

:! (where : is a leftover from before) saves the integer on the stack in the variable !.

Yes, that is also a valid identifier. This breaks the ! command, but we don't use it anymore.
:{, ) and : work as before.

In the first right half, the following happens:

:: (where : is a leftover from before) saves the integer on the stack in the variable :.

Yes, even that is valid identifier. As with {, there's no way to retrieve the stored value.
( decrements the integer on the stack, yielding the number of left halves.
}, since it is unmatched and terminates execution immediately.

This is an undocumented feature. I call them supercomments.

The remaining code is simply ignored.


Construct n-gons with a ruler and compass The task is to draw a regular polygon of n sides using only a compass and an unmarked ruler.

Input (n) is one of the following 10 numbers: 3, 4, 5, 6, 8, 10, 12, 15, 16, 17.

Method: Because you only have a ruler and compass you can only draw points, lines and circles.

A line can only be drawn:

through two existing points.

A circle can only be drawn:

with one point as its centre and with its perimeter passing through a second point.

A point can only be drawn:

at the intersection of two lines,
at the intersection(s) of a line and a circle,
at the intersection(s) of two circles,
at the outset, when you may draw 2 points to get started.

Through this process (and only through this process) you must draw the n lines of the requested n-gon, along with any working required to get to that stage.

EDIT: The position of intersections must be calculated, but lines and circles may be drawn by any means provided by the language.

Output is an image of an n-sided regular polygon, showing working.

Graphically there are no restrictions on image size, format, line thickness or anything else not mentioned here. However it must be possible to visually distinguish distinct lines, circles and their intersections. Additionally:

The n lines that make up your n-gon's sides must be a different colour to your 'working' (i.e. any points, circles or other lines) and a different colour again to your background.
Working can leave the borders of the drawing area, except points, which must all be within the visible bounds of the image.
A circle can be a full circle or just an arc (as long as it shows required intersections).
A line is infinite (i.e. leaves the drawing area) or cut off at the two points it goes through. EDIT: A line may be drawn at any length. Points can only be created where the drawn line visually intersects.
A point can be drawn as you wish, including not marking it.

Scoring is twofold, a submission gets 1 point per input it supports, for a maximum of 10 points. In the event of a draw, shortest byte count wins.

Recognition will be given to submissions that can construct n-gons in the fewest steps or are able to construct n-gons outside of the given range, but it won't help your score.

Background info from Wikipedia

Mathematica, 2 3 4 polygons, 759 bytes

S=Solve;n=Norm;A=Circle;L=Line;c={#,Norm[#-#2]}&{a_,b_List}~p~{c_,d_List}:=a+l*b/.#&@@S[a+l*b==c+m*d,{l,m}]{a_,b_List}~p~{c_,r_}:=a+l*b/.S[n[c-a-l*b]==r,l]{c_,r_}~p~{d_,q_}:={l,m}/.S[n[c-{l,m}]==r&&n[d-{l,m}]==q,{l,m}]q={0,0};r={1,0};a=q~c~r;b=r~c~q;Graphics@Switch[Input[],3,{s=#&@@p[a,b];A@@@{a,b},Red,L@{q,r,s,q}},4,{k={q,r};{d,e}=a~p~b;j={d,e-d};d=k~p~j~c~q;{e,f}=j~p~d;A@@@{a,b,d},L/@Accumulate/@{k,j},Red,L@{q,e,r,f,q}},6,{d={q,r};e=#&@@d~p~a;f=e~c~q;{g,h}=a~p~f;{i,j}=a~p~b;A@@@{a,b,f},L@{#-2#2,#+2#2}&@@d,Red,L@{r,i,g,e,h,j,r}},8,{k={q,r};{d,e}=a~p~b;j={d,e-d};d=k~p~j~c~q;{e,f}=j~p~d;g=e~c~q;h=q~c~e;i=r~c~e;{o,s}=g~p~h;{t,u}=g~p~i;o={o,2s-2o};s={t,2u-2t};{t,u}=o~p~d;{v,w}=s~p~d;A@@@{a,b,d,g,h,i},L/@Accumulate/@{k,j,o,s},Red,L@{q,t,e,v,r,u,f,w,q}}]

Random bullet points:

Input is provided via prompt.
I'm currently supporting inputs 3, 4, 6, 8.
From your options, I chose the following plotting styles:

Full circles.
Lines from endpoint to endpoint, unless a relevant intersection lies outside, in which case I'll hardcode the extent.
No points.
Workings are black, polygons are red - not for aesthetic but for golfing reasons.

There's some serious code duplication between the polygons. I think at some point I'll just do a single construction for all of them, enumerating all lines and points and circles along the way, and then just reduce the Switch to select the relevant circles and lines for each construction. That way I could reuse a lot of primitives between them.
The code contains a lot of boilerplate functions which determine all the relevant intersections, and create circles from two points.
With that in place, I will be adding more polygons in the future.

Here is the ungolfed code:

S = Solve;
n = Norm;
A = Circle;
L = Line;
c = {#, Norm[# - #2]} &
{a_, b_List}~p~{c_, d_List} :=
 a + l*b /. # & @@ S[a + l*b == c + m*d, {l, m}]
{a_, b_List}~p~{c_, r_} := a + l*b /. S[n[c - a - l*b] == r, l]
{c_, r_}~p~{d_, q_} := {l, m} /.
  S[n[c - {l, m}] == r && n[d - {l, m}] == q, {l, m}]
q = {0, 0};
r = {1, 0};
a = q~c~r;
b = r~c~q;
Graphics@Switch[Input[],
  3,
  {
   s = # & @@ p[a, b];
   A @@@ {a, b},
   Red,
   L@{q, r, s, q}
   },
  4,
  {
   k = {q, r};
   {d, e} = a~p~b;
   j = {d, e - d};
   d = k~p~j~c~q;
   {e, f} = j~p~d;
   A @@@ {a, b, d},
   L /@ Accumulate /@ {k, j},
   Red,
   L@{q, e, r, f, q}
   },
  6,
  {
   d = {q, r};
   e = # & @@ d~p~a;
   f = e~c~q;
   {g, h} = a~p~f;
   {i, j} = a~p~b;
   A @@@ {a, b, f},
   L@{# - 2 #2, # + 2 #2} & @@ d,
   Red,
   L@{r, i, g, e, h, j, r}
   },
  8,
  {
   k = {q, r};
   {d, e} = a~p~b;
   j = {d, e - d};
   d = k~p~j~c~q;
   {e, f} = j~p~d;
   g = e~c~q;
   h = q~c~e;
   i = r~c~e;
   {o, s} = g~p~h;
   {t, u} = g~p~i;
   o = {o, 2 s - 2 o};
   s = {t, 2 u - 2 t};
   {t, u} = o~p~d;
   {v, w} = s~p~d;
   A @@@ {a, b, d, g, h, i},
   L /@ Accumulate /@ {k, j, o, s},
   Red,
   L@{q, t, e, v, r, u, f, w, q}
   }
  ]

And here are the outputs:


Circle Through Three Points Given the Cartesian coordinates of three points on a plane, find the equation of the circle through them all. The three points will not be on a straight line.

Each line of input to your program will contain the x and y coordinates of three points, in the order A(x),A(y),B(x),B(y),C(x),C(y). These coordinates will be real numbers less than 1,000,000 separated from each other by space.

The solution is to be printed as an equation of the form (x-h)^2 + (y-k)^2 = r^2. Values for h, k, r are to be printed with three digits after the decimal point. Plus and minus signs in the equations should be changed as needed to avoid multiple signs before a number.

Sample Inputs

7.0 -5.0 -1.0 1.0 0.0 -6.0
1.0 7.0 8.0 6.0 7.0 -2.0

Sample Outputs

(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2
(x - 3.921)^2 + (y - 2.447)^2 = 5.409^2

Python, 176 189 chars

import sys,re
for s in sys.stdin:x,y,z=eval(re.sub(r'(\S+) (\S+)',r'\1+\2j,',s));w=z-x;w/=y-x;c=(x-y)*(w-abs(w)**2)/2j/w.imag-x;print'(x%+.3f)^2+(y%+.3f)^2=%.3f^2'%(c.real,c.imag,abs(c+x))

Does all its work in the complex plane.  I go the math from the bottom of this page.  -c is the center of the circle.


cat file reader with line numbering You must do a program that reads a file given in first argument and print it's content to STDOUT and number the lines on the file, the numbers should be followed by a space.
For instance, assuming that your program is named cat, we could write
./cat "myfile.txt" (or execute it with its interpreter)

With myfile.txt:

Hello, world, this
is a file with
multiple characters..0

And the program should output to STDOUT :

1  Hello, world, this
2  is a file with
3  multiple characters..0

The shortest program in bytes win.

For example :

Perl

$r++&print"$r ".$_ while<>

LabVIEW, 32 LabVIEW Primitives

Reads line by line and concatenates numbers space and newlines, then deletes a trailing number, space and newline.