Three triangular numbers Description
There have been quite a few other challenges concerning these numbers before, and I hope this one is not among them.
The n th triangular number equals the sum of all natural numbers up to n, simple stuff. There are a wikipedia page and an entry at OEIS, for those who wish to inform themselves further.
Now, Gauss found out that every natural number may be expressed as a sum of three triangular numbers (these include 0), and it is fine to have one number more than once, e.g. 0 + 1 + 1 = 2.
Challenge
Your task is to write a program or function, given a natural number (including 0), prints three triangular numbers that sum up to the argument. You may print the numbers separeted by spaces, as an array, or by another method you like. However, it is forbidden to use any builtin functions to directly get an array, a range or any other form of collection containing a list of triangular numbers (for instance a single atom that yields the range).
Test cases
9 -> 6 + 3 + 0 or 3 + 3 + 3
12 -> 6 + 6 + 0 or 6 + 3 + 3 or 10 + 1 + 1
13 -> 6 + 6 + 1
1 -> 1 + 0 + 0
0 -> 0 + 0 + 0

Note: If there is more than one possible combination, you may print any or all, but you must print any combination only once, eliminating all combinations that are a result of rearranging other combinations.
I'd really appreciate a try-it link and an explanation, I really love to see how you solve the problem ;)
This is code-golf, so standard loopholes apply. May the shortest answer in bytes win!

05AB1E, 10 bytes

Code:

ÝηO3ãʒOQ}¬

Explanation:

Ý             # Compute the range [0 .. input]
 η            # Get the prefixes
  O           # Sum each prefix to get the triangle numbers
   3ã         # Cartesian repeat 3 times
     ʒ  }     # Keep elements that
      OQ      #   have the same sum as the input
         ¬    # Retrieve the first element

Uses the 05AB1E encoding. Try it online!


Simulate the Wireworld cellular automaton Wireworld is a cellular automaton that was designed to be resemble electrons flowing through wires. Its simple mechanics allow the construction of digital circuits.  It has even permitted the construction of an entire computer.

Your mission is to create the shortest Wireworld implementation in your language of choice.

Each cell in the grid has one out of four states.  The four states are "blank," "copper," "electron head," or "electron tail."

A blank cell will always remain a blank cell
An electron head will always become an electron tail
An electron tail will always become copper
A copper cell will become an electron head iff exactly one or two out of its eight neighbors are electron heads, otherwise it will remain copper

This competition will have a similar style to the Shortest Game of Life competition, but with a few changes.

The grid must be at least 40 by 40 cells
The edges of the grid must NOT wrap around (not a torus). Treat cells outside of the field as being constantly "blank."
It must be possible for the users to enter their own starting configuration.
Staring at blank screens is not fun.  The program must visually display the simulation as it is running.

This is code golf,  fewest bytes wins.

APL, Dyalog (131)

{h t c←1↓⍵∘=¨F←' htc'⋄⎕SM∘←1 1,⍨⊂N←F[1+⊃+/H h(t∨c≠H←c∧S↑1 1↓1 2∊⍨⊃+/+/K∘.⊖(K←2-⍳3)∘.⌽⊂¯1⌽¯1⊖h↑⍨2+S←25 79)×¨⍳3]⋄∇N⊣⎕DL÷4}↑{79↑⍞}¨⍳25

The output is displayed in the ⎕SM window. The simulation runs endlessly. The grid is 79x25 because that's the default size of the ⎕SM window. The electron head is h, tail is t, copper is c. The program reads the starting configuration from the keyboard as 25 lines.

Explanation:

↑{79↑⍞}¨⍳25: read the 79x25 grid
h t c←1↓⍵∘=¨F←' htc': get three matrices, one with the heads, one with the tails and one with the copper. Also set F to the string ' htc'.
⎕SM∘←1 1,⍨⊂N←F[1+⊃+/...×¨⍳3]: The "..." part is a vector of length three, where the elements are matrices showing the new heads, tails, and copper respectively. The heads are multiplied by 1, the tails by 2, and the copper by 3, then we sum these matrices together and add one, giving a matrix of indices into F. N becomes the new state, in the same format as the input, and it is shown on the ⎕SM screen starting from the top-left corner.
¯1⌽¯1⊖h↑⍨2+S←25 79: Add a border of blanks to h by growing it by two rows and columns, then rotating it one right and one down.
⊃+/+/K∘.⊖(K←2-⍳3)∘.⌽⊂: Rotate the matrix in all eight directions and then sum the resulting matrices together, giving the amount of neighbours that are heads on each position.
1 2∊⍨: Set only those positions to 1 which have 1 or 2 neighbours.
S↑1 1↓: Remove the border we added earlier.
H←c∧: The new heads are all those copper cells that have 1 or 2 head neighbours.
t∨c≠H: The new copper cells are all old tails, and all old copper cells that have not become heads.
H h(...): The new heads are H as calculated above, the new tails are the old heads, and the new copper cells are as calculated above.
∇N⊣⎕DL÷4: Wait 1/4th of a second, then run the function again on N.


Create and write to a file Challenge

Create a new file and write the string Hello World to it.

Restrictions

Your challenge must write to a file on disk, in the file system.
The file may not be a log file generated during normal operation of the interpreter.
The file must contain only the string Hello World. It is allowed to contain a trailing newline or minimal whitespace. No other content.
No command-line flags/pipes (etc) allowed, except when necessary to run the program. (e.g. perl -p)

Notes

This is code-golf, so shortest program in bytes wins.
Follow the spirit, not the letter, of the rules.

Python 2, 32 bytes

print>>open(*"ww"),"Hello World"

Yes, this is valid python.


Move my liquid to make me equal You are given 4 positive integers: volume of the first container (v1), volume of the second container (v2), volume of the liquid in the first container (l1), and volume of the liquid in the second container (l2). Your task is to move some of the liquid from container 1 to container 2, making the amount of empty space in the containers equal to each other, outputting how much liquid should be moved.

An example

Here is an example of some possible input (formatted for the ease of test cases. The input isn't formatted.):

8 11
6  5

Here, you need to make sure that the differences between the volumes and the containers are equal. Currently the difference is not equal:

  8 11
- 6  5
======
   6 2

So we need to try to make them equal, by taking some of the values in one container to another container:

  8 11
- 4  7
======
  4  4

After you have succeeded, output how much liquid you need to take from container 1 to container 2. Therefore the above example should output 2.

Test cases

15 16
 9  2

We move into this state:

 15 16
- 5  6
======
 10 10

Therefore 4 is the expected result.

Test case #2

16 12
13  1

We move into this state:

 16 12
- 9  5
======
  7  7

Therefore 4 is the expected output.

Test case #3

20 12
10 2

Moved:

 20 12
-10 2
======
 10 10

Therefore 0 is the expected output.

More test cases

(They don't have explanations as this should be quite clear)

12 5
9  0 -> 1

9 11
7  3 -> 3

Rules

The test cases will be made so that the result is always possible as a positive integer. The result will never be a decimal.
Input can be taken in any convenient and reasonable format.
Output can be given in any convenient and reasonable format.
The input string will be made so that a moving is always possible without involving decimals or negative numbers. Also there will not be more liquid than how much a container can hold.
Of course, this is code-golf, so the answer in each language consisting of the fewest number of bytes wins. Happy golfing!
An extra restriction for the test cases: you can assume that there is always going to be space available in the second container. So a test case like this:

10 2
 2 2

is not going to be a valid testcase.

JavaScript (ES6) / C#, 21 bytes

(v,V,q,Q)=>V-Q-v+q>>1

Try it online! (JS)
Try it online! (C#)


Solving less-than inequalities with positive integers Write a program or function that takes in a nonempty list of mathematical inequalities that use the less than operator (<). Each line in the list will have the form
[variable] < [variable]

where a [variable] may be any nonempty string of lowercase a-z characters. As in normal math and programming, variables with the same name are identical.
If a positive integer can be assigned to each variable such that all the inequalities are satisfied, then print or return a list of the variables with such an assignment. Each line in this list should have the form
[variable] = [positive integer]

and all variables must occur exactly once in any order.
Note that there may be many possible positive integer solutions to the set of inequalities. Any one of them is valid output.
If there are no solutions to the inequalities, then either don't output anything or output a falsy value (it's up to you).
The shortest code in bytes wins.
Examples
If the input were
mouse < cat
mouse < dog

then all of these would be valid outputs:
mouse = 1
cat = 2
dog = 2
mouse = 37
cat = 194
dog = 204
mouse = 2
cat = 2000000004
dog = 3
If the input were
rickon < bran
bran < arya
arya < sansa
sansa < robb
robb < rickon

then no assignment is possible because it boils down to rickon < rickon, so there either is no output or a falsy output.
More examples with solutions:
x < y

x = 90
y = 91

---

p < q
p < q

p = 1
q = 2

---

q < p
q < p

p = 2
q = 1

---

abcdefghijklmnopqrstuvwxyz < abcdefghijklmnopqrstuvwxyzz

abcdefghijklmnopqrstuvwxyz = 123456789
abcdefghijklmnopqrstuvwxyzz = 1234567890

---

pot < spot
pot < spot
pot < spots

pot = 5
spot = 7
spots = 6

---

d < a
d < b
d < c
d < e

d = 1
a = 4
b = 4
c = 5
e = 4

---

aa < aaaaa
a < aa
aaa < aaaa
aa < aaaa
a < aaa
aaaa < aaaaa
aaa < aaaaa
a < aaaaa

aaaa = 4
aa = 2
aaaaa = 5
a = 1
aaa = 3

---

frog < toad
frog < toaster
toad < llama
llama < hippo
raccoon < science
science < toast
toaster < toad
tuna < salmon
hippo < science
toasted < toast

raccoon = 1
frog = 2
toaster = 3
toasted = 4
toad = 5
llama = 6
hippo = 7
science = 8
toast = 9
tuna = 10
salmon = 11

More examples with no solutions: (separated by empty lines)
z < z

ps < ps
ps < ps

q < p
p < q

p < q
q < p

a < b
b < c
c < a

d < a
d < b
d < c
d < d

abcdefghijklmnopqrstuvwxyz < abcdefghijklmnopqrstuvwxyz

bolero < minuet
minuet < bolero

aa < aaaaa
a < aa
aaa < aaaa
aa < aaaa
aaaaa < aaaa
a < aaa
aaaa < aaaaa
aaa < aaaaa
a < aaaaa

g < c
a < g
b < a
c < a

g < b
a < g
b < a
c < a

g < b
a < g
b < a
c < b

g < c
a < g
b < a
c < b

geobits < geoborts
geobrits < geoborts
geology < geobits
geoborts < geology

Pyth, 39 bytes

V>1f.A<MxMLTN.pS{s=Nm%2cd).zVNjd[H\==hZ

Try it online: Demonstration

Brute-forces through all possible permutations (and interpret them as sortings), check if they match the inequalities, and assign them the values 1, 2, ...., n.

Explanation

f.A<MxMLTN.pS{s=Nm%2cd).z
                 m     .z  map each input line d to:
                    cd)       split d by spaces
                  %2          and remove the second element
               =N          save this list of pairs to N
              s            combine these pairs to a big list of variable names
             {             set (remove duplicates)
          .pS              generate all permutations
f                          filter for permutations T, which satisfy:
     xMLTN                    replace each variable in N by their index in T
 .A<M                         check if each pair is ascending

V>1...VNjd[H\==hZ          implicit: Z = 0
 >1                        remove all but the last filtered permutation (if any)
V                          for each permutation N in ^ (runs zero times or once):
      VN                      for each variable H in N:
          [                      generate a list containing:
           H                        H
            \=                      "="
              =hZ                   Z incremented by 1 (and update Z)
        jd                       join this list by spaces and print


Find arsonist's lullaby Imagine an arsonist walking around the town and picking its victims according to a very specific pattern (Or, alternatively, Imagine a bee flying around the garden and picking its flowers to pollenize according to a very specific pattern). Let's say the town is an N × N matrix, where N is an integer higher than or equal to 2. The arsonist starts from the upper-left corner and successively sets the house M spots in front of them (where M is the number of the house they're currently in), while changing the direction it's moving in after each fire, in the order East ⟶ South ⟶ West ⟶ North ⟶ East ⟶ South... and so on. The lullaby of the arsonist is the value of M that makes them exit the town (i.e. the last house they visit before stopping the abomination). This is way easier to understand with an example. Take the following matrix for instance:

3 2 3 2 7
3 1 4 1 6
2 5 3 1 1
4 4 3 2 4
1 1 1 1 1

We start in the upper-left corner, so M = 3 (X marks the current and previous positions of the arsonist):

X 2 3 2 7
3 1 4 1 6
2 5 3 1 1
4 4 3 2 4
1 1 1 1 1

According to the known order, it first goes east M (3) spots and lands on a 2 so M changes accordingly:

X 2 3 X 7
3 1 4 1 6
2 5 3 1 1
4 4 3 2 4
1 1 1 1 1

Then it goes south 2 spots and M is now 1:

X 2 3 X 7
3 1 4 1 6
2 5 3 X 1
4 4 3 2 4
1 1 1 1 1

Now it moves 1 spot to the West and M becomes 3:

X 2 3 X 7
3 1 4 1 6
2 5 X X 1
4 4 3 2 4
1 1 1 1 1

After it moves 3 spots north, it exits the town! Therefore, 3 is this arsonist's lullaby:

    X
X 2 3 X 7
3 1 4 1 6
2 5 X X 1
4 4 3 2 4
1 1 1 1 1

Given an N × N matrix (you can optionally take N as input too), find the lullaby of the arsonist. I've written a program with which you can generate more test cases and visualise the path of the arsonist: Try it online!

You may assume that the arsonist does have a lullaby (that is, it can actually get out of the matrix).
The matrix will only contain positive integers less than or equal to 9 (digits), for simplicity. Solutions that handle any positive integer are completely welcome.
Note that the arsonist can land on a spot they've already burned, in case the sense they're moving in is different from the first time. In such a scenario, just take the value of that element and move again as usual.
You can compete in any programming language and can take input and provide output through any standard method, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (in bytes) for every language wins.

Test cases

-------------
9 2 3
1 7 2
8 7 6

Lullaby: 9
-------------
2 1 2 1
3 1 1 2
1 2 2 1
1 1 1 3

Lullaby: 2
-------------
3 2 3 2 7
3 1 4 1 6
2 5 3 1 1
4 4 3 2 4
1 1 1 1 1

Lullaby: 3
-------------
1 2 1 2 1 2
1 2 1 2 1 2
1 2 1 2 1 2
1 2 1 2 1 2
1 2 1 2 1 2
1 2 1 2 1 2

Lullaby: 2
-------------
3 2 1 2 1 1 1
2 3 2 3 2 1 1
2 1 1 1 3 1 2
3 1 1 1 1 1 1
4 5 2 3 1 1 1
1 2 1 2 1 2 2
1 2 2 3 2 1 2

Lullaby: 3
-------------

The matrices in a different format:

[[9, 2, 3], [1, 7, 2], [8, 7, 6]]
[[2, 1, 2, 1], [3, 1, 1, 2], [1, 2, 2, 1], [1, 1, 1, 3]]
[[3, 2, 3, 2, 7], [3, 1, 4, 1, 6], [2, 5, 3, 1, 1], [4, 4, 3, 2, 4], [1, 1, 1, 1, 1]]
[[1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 1, 2]]
[[3, 2, 1, 2, 1, 1, 1], [2, 3, 2, 3, 2, 1, 1], [2, 1, 1, 1, 3, 1, 2], [3, 1, 1, 1, 1, 1, 1], [4, 5, 2, 3, 1, 1, 1], [1, 2, 1, 2, 1, 2, 2], [1, 2, 2, 3, 2, 1, 2]]

The fifth test case is very interesting to visualise.

MATL, 32 bytes
JQ6*`G5thYay&Zj3$)wyJ2@-^*+8M]b&

Try it online! Or verify all test cases.
How it works
The input matrix is padded with a frame of five zeros, so for example
3 2 3 2 7
3 1 4 1 6
2 5 3 1 1
4 4 3 2 4
1 1 1 1 1

becomes
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 3 2 3 2 7 0 0 0 0 0
0 0 0 0 0 3 1 4 1 6 0 0 0 0 0
0 0 0 0 0 2 5 3 1 1 0 0 0 0 0
0 0 0 0 0 4 4 3 2 4 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The frame of zeros is used to detect when the arsonist bee has exited the matrix. The extension with five zeros ensures that a modular displacement of length up to 9 in any direction from any of the nonzero entries will correctly land in a zero without wrapping around to some non-zero entry.
In matrix coordinates, the bee starts at entry (6,6) of the extended matrix. It reads that entry, and updates the coordinates as required, applying a (modular) displacement of the read length in the corresponding direction. This is repeated in a loop until the read value is 0. The entry that was read before that one (i.e. the last non-zero entry) is the output.
The coordinates are actually stored as a complex number, so for example (6,6) becomes 6+6j. This way the four cyclic directions can be realized as powers of the imaginary unit. The corresponding power (j, 1, -j or -1) is multiplied by the read entry to obtain the complex displacement which is used for updating the coordinates.
The successively read values are kept on the stack. When the loop is exited, the stack contains all non-zero read values in order, then the last read value which is 0, then the latest complex coordinates. So the third-top element is the required output.


Determine the degree of a polynomial Background:
For this challenge, a polynomial looks like this:
$$P(x)=a_nx^n+a_{n-1}x^{n-1}+\dots+a_2x^2+a_1x+a_0$$
The degree, \$n\$, is the highest power \$x\$ is raised to. An example of a degree 7 polynomial would be:
$$P(x)=4x^7+2x^6-7x^4+x^2-6x+17$$
All powers are integers \$n\ge0\$. This means \$x\$, \$-2\$, and \$0\$ could all be considered polynomials, but not \$\frac{1}{x}\$ or \$\sqrt{x}\$.
Challenge:
Write a program or functions which takes a number of pairs \$(x, P(x))\$, and finds the smallest possible degree of \$P(x)\$. The values of \$x\$ will be incrementing; \$\{(0, 1), (1, 0), (2, 1)\}\$ is a valid input, but \$\{(0, 2), (10, 20), (11, 22)\}\$ is not.
Given \$\{(0, 1), (1, 0), (2, 1)\}\$, for example, the degree is \$2\$ (and \$P(x)=x^2-2x+1\$).
Input:
Input will consist of at least \$n+1\$ pairs of integer values, and at least \$2\$, representing \$x\$ and \$P(x)\$. The \$x\$ values will all be one higher than the previous one.
Input can be taken in any reasonable format. Invalid inputs do not need to be handled. Optionally, you can input only the \$P(x)\$ values (and ignore \$x\$ altogether).
Output:
Output will be an integer \$n\ge0\$, representing the degree of \$P(x)\$.
As with the input, any reasonable format is valid.
Tip:
A simple way to find the degree of a polynomial function (like \$P(x)\$) when you have a list of inputs with incrementing \$x\$ values is to create a list of the \$P(x)\$ values, then repeatedly find the difference between adjacent items. For example, given the inputs \$\{(-3, 14), (-2, 4), (-1, -2), (0, -4), (1, -2)\}\$:
$$\{14, 4, -2, -4, -2\}$$
$$\{10, 6, 2, -2\}$$
$$\{4, 4, 4\}$$
After some number of iterations, \$2\$ in this case, all of the items will be the same number. That number of iterations is \$n\$.
Test cases:
(-1, 8), (0, 8), (1, 8)                                    0
(0, 0), (1, 0), (2, 0)                                     0
(1, 0), (2, 1)                                             1
(0, 0), (1, 2), (2, 4), (3, 6), (4, 8)                     1
(-4, -20), (-3, -12), (-2, -6)                             2
(6, 1296), (7, 2401), (8, 4096), (9, 6561), (10, 10000)    4

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

Husk, 8 6 bytes
←VE¡Ẋ-

Try it online!
-2 bytes from Leo.
Explanation
←VE¡Ẋ- Input: list of P(x)
   ¡Ẋ- repeatedly take deltas and put in infinite list
 V     First index where
  E    all elements are equal
←      decrement


Reverse busy beaver problem In this challenge, Turing machines operate on a zero-initialized binary tape that is infinite in both directions.
You are given an integer \$N\$, where \$1 \le N \le 20000\$. Your program has to output a Turing machine that takes exactly \$N\$ steps to halt, including the final step. Alternatively, you can write a program that outputs all 20000 machines.
Your program should complete within 2 hours for all 20000 inputs, when tested on my computer (AMD Ryzen 2600 12-thread CPU). If your program solves all test cases on the same thread, sequentially and independently, your program's running time is divided by 4.
Your score is the total number of states in all 20000 outputs of your program. The lowest-scoring program wins.
Output
Below is described the (recommended) output format for a single test case.
In the first line, output a number \$M\$, the number of states of the machine. In the next \$M\$ lines, output the transitions from the states, in order from the first to the last, if the cell under the pointer is zero. In the next \$M\$ lines, output the corresponding transitions, if the cell under the pointer is one.
The output format for transitions is movement newval newstate, where movement stands for either L - move left, R - move right, S - do not move, or H - halt, newval is the new value of the cell under the pointer (it can be equal to the original one), and newstate is an integer from \$1\$ to \$M\$, the state the machine will be in in the next step.
Python 3 checker that inputs in the format described above and outputs the number of steps the Turing machine takes to halt. If you use a different output format, please include a link to a program that can  be used to simulate your Turing machines (it's likely a good idea to simply modify my checker).

Python 3, 275,467 255,540 states
Thanks @mypronounismonicareinstate for suggesting to add \$I\$ into the \$B \rightarrow C\$ loop, which ultimately saves about \$20k\$ states.

def print_machine(states):
 print(len(states[0]))
 for i in 0,1:
  for s in states[i]:
   # if s is None (state unused), puts dummy value in there
   move, new_val, new_state = s or ["H", 0, 0]
   print(move, new_val, new_state+1)

# simple machine that uses ceil(step/2) states
# used for small cases
def generate_simple_machine(steps):
 n_states = (steps+1)//2
 # states[cur_char][state_id]
 states = [[], []]
 for i in range(n_states):
  states[0].append(["S", 1, i])
  states[1].append(["S", 0, i+1])
 states[1][-1][0] = "H"
 if steps%2==1: states[0][-1][0] = "H"
 return states

BASE_STEPS = [(1<<i+2)-i-3 for i in range(20)]
BASE_STEPS[0] = -999

def generate_counter_machine(steps, do_print=True):
 # how many bits/states needed?
 for n_bits, max_steps in enumerate(BASE_STEPS):
  if max_steps > steps:
   break
 n_bits -= 1
 n_states = n_bits + 2
 extra = steps - BASE_STEPS[n_bits]
 if extra >= (1 << (n_bits+1)):
  n_states += 1

 # if small number of steps, use simple machine
 n_states_simple = (steps+1)//2
 if not do_print:
  return min(n_states_simple, n_states)
 if n_states >= n_states_simple :
  states = generate_simple_machine(steps)
  print_machine(states)
  return n_states_simple

 # states[cur_char][state_id]
 # use 0 indexed state
 states = [[None]*n_states, [None]*n_states]

 # state indices
 I_STATE  = 0
 B_STATE  = 1
 E_STATE  = n_states - 1
 C_STATES = [i+2 for i in range(n_bits)]

 # initial state
 states[0][I_STATE] = ["R", 1, C_STATES[0]]
 states[1][I_STATE] = ["H", 0, 0]  # not used initially

 # go back state
 states[0][B_STATE] = ["L", 0, B_STATE]
 states[1][B_STATE] = ["R", 1, C_STATES[0]]

 # ith-digit check states
 for i in C_STATES:
  states[0][i] = ["L", 1, B_STATE]
  states[1][i] = ["R", 0, i+1]
 states[1][C_STATES[-1]][0] = "H"

 # dealing with extras
 # first, figure out how many half-state
 # goes between B_1 -> C1_x
 t = 1<<n_bits
 q1 = t - 1
 q2 = q1 + t
 q3 = q2 + t
 if  extra < q1:
  extra_state = I_STATE
 elif extra < q2:
  # connect B_1 -> I_0 -> C1_?
  states[1][B_STATE] = ["S", 0, I_STATE]
  extra -= q1
  extra_state = I_STATE
 elif extra < q3:
  # connect B_1 -> I_0 -> I_1 -> C1_x
  states[1][B_STATE] = ["S", 0, I_STATE]
  states[0][I_STATE] = ["S", 1, I_STATE]
  states[1][I_STATE] = ["R", 1, C_STATES[0]]
  extra -= q2
  extra_state = E_STATE
 else:
  # connect B_1 -> I_0 -> I_1 -> E_0 -> C1_x
  states[1][B_STATE] = ["S", 0, I_STATE]
  states[0][I_STATE] = ["S", 1, I_STATE]
  states[1][I_STATE] = ["S", 0, E_STATE]
  states[0][E_STATE] = ["R", 1, C_STATES[0]]
  extra -= q3
  extra_state = E_STATE

 # then put a half-state between Cx_0 -> B
 # if needed
 if extra > 0:
  states[1][extra_state] = ["L", 1, B_STATE]
  for i in reversed(C_STATES):
   if extra%2==1:
    states[0][i] = ["S", 1, extra_state]
   extra //= 2
 print_machine(states)
 return n_states

Try it online! or Verify all machines from 1 to 20k
Big idea
We want to construct a Turing machine that has a large time complexity compared to the number of states. In this answer, I used a binary counter to count all integers with \$n\$ bits, which has a time complexity of \$O(2^n)\$. The binary counter was chosen because it is very simple to construct, easy to scale, and flexible enough to add any small number of steps.
Binary counter
Let's say we want to count all integers with 4 bits. The tape layout will be as follows:
1 x x x x
e.g.
1 0 0 0 0
1 1 0 0 0
....
1 0 1 1 1
1 1 1 1 1

where the left most 1 is used to mark the start of the number, and xxxx is the current number in binary, in reverse order (the least significant bit first). We start with 10000, and end with 11111.
At each cycle, we increase the number by 1 as follows:

Find the left most 0. E.g.

1 1 1 0 1
      ^

Set that digit to 1, and all previous digits to 0. The previous example becomes 1 0 0 1 1.

We then repeat these steps until the tape is 1 1 1 1 1.
Binary counter Turing machine
The counter machine for \$b\$-bit integers will have \$b+2\$ states: the initial state \$I\$, \$b\$ digit check states \$C_1\$ to \$C_b\$, and the "go back" state \$B\$:

The initial state \$I\$ simply sets the left most cell to 1: R 1 C1 / x x x.

The \$i^{th}\$ digit check state \$C_i\$ is only called if all previous digits are 1, and the pointer is currently on the \$i^{th}\$ left most digit.

If the current digit is 0, then we've found the left most 0. Set the current digit to 1, and enter "go back" state: L 1 B.
If the current digit is 1, set that digit to 0 and enter the next digit check state: R 0 C(i+1). If this is the last digit check state (\$C_b\$), then halts, since this means the current number is 111..1.

"Go back" state \$B\$ is called after the number is incremented, to reset the pointer to the unit digit and start a new cycle. This state simply moves left until it sees the 1 that marks the start of the number. It then moves one step right to the unit digit, and calls the first digit check state \$C_1\$: L 0 B / R 1 C1.

Time complexity
With \$n\$ states (counting \$n-2\$ bit integers), a counter machine runs for \$2^n-n-1\$ steps.
states  steps
     3      4
     4     11
     5     26
     6     57
     7    120
     8    247
     9    502
    10   1013
    11   2036
    12   4083
    13   8178
    14  16369
    15  32752

Bridging the gap
The above scheme only allows us to generate machines with the exact number of steps in the table above. This means that we are stuck if the number of steps falls in the "gaps" between the above numbers. Thankfully, there is a simple scheme that allow us to add some extra steps to a machine, at the cost of at most 1 state.
For example, from the above table, we know that a counter with 6 states runs for 57 steps, and a machine with 7 states runs for 120 steps. There are 62 numbers in the gap between them (58 to 119). This means that we need to be able to extend a 6-state machine to have 1 to 62 extra steps. (In general, we need a scheme to extend an \$n\$-states machine by 1 to \$2^n-2\$ steps).
First, some notation: let's \$S^0\$ and \$S^1\$ be the "half-states" of \$S\$, aka \$S\$ when the current cell is 0 or 1.
Let's look at how many time each half-state is called in an original 6-state counter machine:
                I    B   C1   C2   C3   C4
cur_char = 0    1   11    8    4    2    1
cur_char = 1    0   15    8    4    2    1

Observation 1
The number of times each digit check half-state is called is always a power of 2. Furthermore, the transition afterward is always \$C_i^0 \rightarrow B^x\$ (refer to the state transition diagram above). This means that we can add an extra half-state in between (aka \$C_i^0 \rightarrow X \rightarrow B^x\$). The extra half-state simply wastes a step before transitioning to \$B\$. The number of extra steps gained is equal to the number of times \$C_i^0\$ is called.
By selecting which \$C_i^0\$ are connected to this extra half-state \$X\$, we can add any number of extra steps from 1 to 15 (since \$15=8+4+2+1\$), at the cost of 1 extra half-state.

For example, in the modified counter above, \$C_1^0\$ and \$C_3^0\$ transitions through \$X\$ before reaching \$B\$. Since \$C_1^0\$ is called 8 times and \$C_3^0\$ is called 2 times, \$X\$ is called 10 times in total, adding an extra 10 steps to the machine.
Observation 2:
Both \$B^1\$ and \$I^0\$ transitions to state \$C_1\$. Furthermore, both \$B^1\$ and \$I^0\$ sets the current cell to 1, then moves right. Thus, we can have \$B^1 \rightarrow I^0 \rightarrow C_1^x\$. This gives us an extra 15 steps for free.
Furthermore, for each additional half-state inserted between \$I^0\$ and \$C_1^x\$, the machine runs for 16 extra steps. For example, using 2 extra half-state, we can gain \$15+16+16=47\$ extra steps.
By combining the 2 observations, we can reach any number of extra steps between 1 and 62 inclusive, using at most 3 extra half-states (1 half-state in observation 1, 2 in observation 2, which gives at most \$15 + 47 = 62\$ extra steps).

For example, in the machine above, \$I^0\$ and 2 extra half-states are added between \$B^1\$ and \$C_1^x\$, adding \$15+16+16 = 47\$ extra steps. Another extra half-state is added between the digit checks and \$B\$, adding 10 extra steps. In total, this machine has 57 extra steps compared to the base machine.
This process can be generalized to any \$n\$-state counter machine.
Note that since \$I^1\$ is unused in the base machine, we already start with a free half-state. This means that we only need at most 1 extra state \$E\$ (aka 2 half-states \$E^0\$ and \$E^1\$).
Code explanation
If you want to take a look at the code, the states are ordered as follow:

Initial state \$I\$
Go back state \$B\$
Digit check states from \$C_1\$ to \$C_b\$
Extra state \$E\$ (if needed)


ECHO! Echo! echo. (echo) Your challenge, should you choose to accept it, is simple:

Implement RFC 862, also known as the Echo Protocol:

The Echo protocol

An echo service simply sends back to the originating source any data it receives.

TCP Based Echo Service

One echo service is defined as a connection based application on TCP. A server listens for TCP connections on TCP port 7.  Once a connection is established any data received is sent back.  This continues until the calling user terminates the connection.

UDP Based Echo Service

Another echo service is defined as a datagram based application on UDP.  A server listens for UDP datagrams on UDP port 7.  When a datagram is received, the data from it is sent back in an answering datagram.

Scoring

The score is one point for every byte of code as encoded in UTF-8 or a language-specific code page, whichever is smaller.
If the program incompletely implements RFC 862 by providing only UDP or only TCP, the score is doubled.
If the program incorrectly implements RFC 862 by either using a port other than 7 or by dropping or transforming certain bytes due to language limitations or corner cutting, the score is quadrupled. (This stacks with the preceding point if applicable.)
If the program is invalid, the score is ω.

Rules

A valid program:

Does not use standard loopholes.
Per connection:

Accepts connections and receive incoming data.
Sends outgoing data in an amount that is always less than or equal to the amount of data received.

Does not invoke programs external to itself. (Spawning children to deal with multiple connections is fine, spinning up inetd or its local equivalent is not.)
Does not use library functions specifically designed to start and maintain an echo service.

This is code golf, so lowest score wins.

Python, 299 295 265 263
from threading import*
from socket import*
a='',7;S=socket
u=S(2,2);u.bind(a)
def U():
 while 1:u.sendto(*u.recvfrom(4**8))
Thread(None,U).start()
def C(c,x):
 while c.send(c.recv(1)):1
s=S(2,1);s.bind(a);s.listen(1)
while 1:Thread(None,C,args=s.accept()).start()

handles both udp and tcp.
@MorganThrapp helped saving 33 (!) chars


Array Escape - get out of there One day you awake only to find yourself caught in an array. You try to just walk out of there, taking one index at the time, but it seems there are other rules:

The array is completely filled with natural numbers.

If you find yourself on an index n, you go to the index array[n], except:
If you find yourself on an index n which is a prime number, you take array[n] steps back

Example:
You start on index 4, in this array (start index is 0):

array = [1,4,5,6,8,10,14,15,2,2,4,5,7];
-----------------^ you are here

As the value of the field you are on is 8, you go to the index 8 as the first step. The field you land on contains the value 2. You then go to index 2 as your second step. As2is a prime number, you take 5 steps back, which is your third step. As there is no index -3, you successfully escaped the array in a total of 3 steps.

Your task is:

To write a program or function, which accepts an array and a start index as parameter, and outputs the amount of steps to escape the array. If you can't escape the array (e.g. [2,0,2] with start-index 2 => you constantly go from index 2 to 0), output a falsy value. You may use one-based indexing or zero-based indexing, but please specify which you use.

Test cases

Input: [2,5,6,8,1,2,3], 3

Output: 1

Input: [2, 0, 2], 2

Output: false

Input: [14,1,2,5,1,3,51,5,12,3,4,41,15,4,12,243,51,2,14,51,12,11], 5;

Output: 6

The shortest answer wins.

Python, 161 138 bytes

Credits for factorial.

g=lambda x:0**x or x*g(x-1)
f=lambda a,i,n=0,l=[]:(i<0)+(i>=len(a))and n or(0 if i in l else f(a,[a[i],i-a[i]][i and-g(i-1)%i],n+1,l+[i]))

Ideone it!

How it works

Wilson's theorem is used for prime checking.

Loop detection by storing seen indices to an array (l) and checking whether current index is in l.


Find the angle between two points Given two points A and B, find the angle from line AO to line BO about point O where O is the origin ((0,0)). Additionally, the angle may be positive or negative depending on the positions of the points (see examples). Input will be points A and B, and may be given in any convenient form. Output will be the angle in degrees (but it is positive if AO is rotated counter-clockwise about the origin to get BO and negative if it is rotated clockwise). If the angle is 180 degrees you may return a negative or positive output. Similarly, the angle can be the positive or negative version of the same angle (90 deg is equal to -270 deg). Examples:

Input: A(5,5) B(5,-5) Output: -90 (AO is rotated -90 degrees to get BO).
Input: A(5,-5) B(5,5) Output: 90 (AO is rotated 90 degrees to get BO).

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

TI-BASIC, 13 bytes
For TI-83+/84+ series calculators.
Degree
Input Y
min(ΔList(R►Pθ(Ans,∟Y

To use this program, enter the list {x1,x2} through the Ans variable, and {y1,y2} at the prompt.


building circuit for divisibility by 3 A boolean circuit in TCS is basically a DAG consisting of And, Or, Not gates, and by  what is known is "functional completeness" they can compute all possible functions. eg this is the basic principle in an ALU.

  Challenge: create a circuit to determine whether an 8-binary-digit number is divisible by 3 and somehow visualize your result (ie in some kind of picture)

The judging criteria for voters is based on whether the code to generate the circuit generalizes nicely to arbitrary size numbers, and whether the algorithmically-created visualization is compact/balanced but yet still human-readable (ie visualization by hand arrangement not allowed). ie the visualization is for n=8 only but the code will ideally work for all 'n'. winning entry is just top voted.

Somewhat similar question: Build a multiplying machine using NAND logic gates

Depth:7 (logarithmic), 18x AND, 6x OR, 7x XOR, 31 gates (linear)

Let me calculate the digit sum in base four, modulo three:

circuit drawn in Logisim

Generalisation, formally (hopefully somewhat readable):

balance (l, h) = {
  is1: l & not h,
  is2: h & not l,
}

add (a, b) =
  let aa = balance (a.l, a.h)
      bb = balance (b.l, b.h)
  in  { l:(a.is2 & b.is2) | (a.is1 ^ b.is1),
        h:(a.is1 & b.is1) | (a.is2 ^ b.is2)}

pairs [] = []
pairs [a] = [{h:0, l:a}]
pairs [rest.., a, b] = [pairs(rest..).., {h:a, l:b}]

mod3 [p] = p
mod3 [rest.., p1, p2] = [add(p1, p2), rest..]

divisible3 number =
  let {l: l, h: h} = mod3 $ pairs number
  in  l == h

now in english:

While there are more than two bits in the number, take two lowest pairs of bits and sum them modulo 3, then append the result to the back of the number, then return if the last pair is zero modulo 3. If there is an odd number of bits in the number, add an extra zero bit to the top, then polish with constant value propagation.

Appending to the back instead of to the front ensures the addition tree is a balanced tree rather than a linked list. This, in turn, ensures logarithmic depth in the number of bits: five gates and three levels for pair cancellation, and an extra gate at the end.

Of course, if approximate planarity is desired, pass the top pair unmodified to the next layer instead of wrapping it to the front. This is easier said than implemented (even in pseudocode), however. If the number of bits in a number is a power of two (as is true in any modern computer system as of March 2014), no lone pairs will occur, however.

If the layouter preserves locality / performs route length minimisation, it should keep the circuit readable.

This Ruby code will generate a circuit diagram for any number of bits (even one). To print, open in Logisim and export as image:

require "nokogiri"

Port = Struct.new :x, :y, :out
Gate = Struct.new :x, :y, :name, :attrs
Wire = Struct.new :sx, :sy, :tx, :ty

puts "Please choose the number of bits: "
bits = gets.to_i

$ports = (1..bits).map {|x| Port.new 60*x, 40, false};
$wires = [];
$gates = [];

toMerge = $ports.reverse;

def balance a, b
y = [a.y, b.y].max
$wires.push Wire.new(a.x   , a.y , a.x   , y+20),
          Wire.new(a.x   , y+20, a.x   , y+40),
          Wire.new(a.x   , y+20, b.x-20, y+20),
          Wire.new(b.x-20, y+20, b.x-20, y+30),
          Wire.new(b.x   , b.y , b.x   , y+10),
          Wire.new(b.x   , y+10, b.x   , y+40),
          Wire.new(b.x   , y+10, a.x+20, y+10),
          Wire.new(a.x+20, y+10, a.x+20, y+30)
$gates.push Gate.new(a.x+10, y+70, "AND Gate", negate1: true),
          Gate.new(b.x-10, y+70, "AND Gate", negate0: true)
end

def sum (a, b, c, d)
y = [a.y, b.y, c.y, d.y].max
$wires.push Wire.new(a.x   , a.y , a.x   , y+40),
          Wire.new(a.x   , y+40, a.x   , y+50),
          Wire.new(a.x   , y+40, c.x-20, y+40),
          Wire.new(c.x-20, y+40, c.x-20, y+50),
          Wire.new(b.x   , b.y , b.x   , y+30),
          Wire.new(b.x   , y+30, b.x   , y+50),
          Wire.new(b.x   , y+30, d.x-20, y+30),
          Wire.new(d.x-20, y+30, d.x-20, y+50),
          Wire.new(c.x   , c.y , c.x   , y+20),
          Wire.new(c.x   , y+20, c.x   , y+50),
          Wire.new(c.x   , y+20, a.x+20, y+20),
          Wire.new(a.x+20, y+20, a.x+20, y+50),
          Wire.new(d.x   , d.y , d.x   , y+10),
          Wire.new(d.x   , y+10, d.x   , y+50),
          Wire.new(d.x   , y+10, b.x+20, y+10),
          Wire.new(b.x+20, y+10, b.x+20, y+50)
$gates.push Gate.new(a.x+10, y+90, "XOR Gate"),
          Gate.new(b.x+10, y+80, "AND Gate"),
          Gate.new(c.x-10, y+80, "AND Gate"),
          Gate.new(d.x-10, y+90, "XOR Gate")
$wires.push Wire.new(a.x+10, y+90, a.x+10, y+100),
          Wire.new(b.x+10, y+80, b.x+10, y+90 ),
          Wire.new(b.x+10, y+90, a.x+30, y+90 ),
          Wire.new(a.x+30, y+90, a.x+30, y+100),
          Wire.new(d.x-10, y+90, d.x-10, y+100),
          Wire.new(c.x-10, y+80, c.x-10, y+90 ),
          Wire.new(c.x-10, y+90, d.x-30, y+90 ),
          Wire.new(d.x-30, y+90, d.x-30, y+100)
$gates.push Gate.new(d.x-20, y+130, "OR Gate"),
          Gate.new(a.x+20, y+130, "OR Gate")
end

def sum3 (b, c, d)
y = [b.y, c.y, d.y].max
$wires.push Wire.new(b.x   , b.y , b.x   , y+20),
          Wire.new(b.x   , y+20, b.x   , y+30),
          Wire.new(b.x   , y+20, d.x-20, y+20),
          Wire.new(d.x-20, y+20, d.x-20, y+30),
          Wire.new(c.x   , c.y , c.x   , y+60),
          Wire.new(c.x   , y+60, b.x+30, y+60),
          Wire.new(b.x+30, y+60, b.x+30, y+70),
          Wire.new(d.x   , d.y , d.x   , y+10),
          Wire.new(d.x   , y+10, d.x   , y+30),
          Wire.new(d.x   , y+10, b.x+20, y+10),
          Wire.new(b.x+20, y+10, b.x+20, y+30),
          Wire.new(b.x+10, y+60, b.x+10, y+70)
$gates.push Gate.new(b.x+10, y+60 , "AND Gate"),
          Gate.new(d.x-10, y+70 , "XOR Gate"),
          Gate.new(b.x+20, y+100, "OR Gate" )
end

while toMerge.count > 2
puts "#{toMerge.count} left to merge"
nextToMerge = []
while toMerge.count > 3
 puts "merging four"
 d, c, b, a, *toMerge = toMerge
 balance a, b
 balance c, d
 sum *$gates[-4..-1]
 nextToMerge.push *$gates[-2..-1]
end
if toMerge.count == 3
 puts "merging three"
 c, b, a, *toMerge = toMerge
 balance b, c
 sum3 a, *$gates[-2..-1]
 nextToMerge.push *$gates[-2..-1]
end
nextToMerge.push *toMerge
toMerge = nextToMerge
puts "layer done"
end

if toMerge.count == 2
b, a = toMerge
x = (a.x + b.x)/2
x -= x % 10
y = [a.y, b.y].max
$wires.push Wire.new(a.x , a.y , a.x , y+10),
          Wire.new(a.x , y+10, x-10, y+10),
          Wire.new(x-10, y+10, x-10, y+20),
          Wire.new(b.x , b.y , b.x , y+10),
          Wire.new(b.x , y+10, x+10, y+10),
          Wire.new(x+10, y+10, x+10, y+20)
$gates.push Gate.new(x, y+70, "XNOR Gate")
toMerge = [$gates[-1]]
end

a = toMerge[0]
$wires.push Wire.new(a.x, a.y, a.x, a.y+10)
$ports.push Port.new(a.x, a.y+10, true)

def xy (x, y)
"(#{x},#{y})"
end
circ = Nokogiri::XML::Builder.new encoding: "UTF-8" do |xml|
xml.project version: "1.0" do
xml.lib name: "0", desc: "#Base"
xml.lib name: "1", desc: "#Wiring"
xml.lib name: "2", desc: "#Gates"
xml.options
xml.mappings
xml.toolbar do
  xml.tool lib:'0', name: "Poke Tool"
  xml.tool lib:'0', name: "Edit Tool"
end #toolbar
xml.main name: "main"
xml.circuit name: "main" do
  $wires.each do |wire|
    xml.wire from: xy(wire.sx, wire.sy), to: xy(wire.tx, wire.ty)
  end #each
  $gates.each do |gate|
    xml.comp lib: "2", name: gate.name, loc: xy(gate.x, gate.y) do
      xml.a name: "facing", val: "south"
      xml.a name: "size", val: "30"
      xml.a name: "inputs", val: "2"
      if gate.attrs
        gate.attrs.each do |name, value|
          xml.a name: name, val: value
        end #each
      end #if
    end #comp
  end #each
  $ports.each.with_index do |port, index|
    xml.comp lib: "1", name: "Pin", loc: xy(port.x, port.y) do
      xml.a name: "tristate", val: "false"
      xml.a name: "output",   val: port.out.to_s
      xml.a name: "facing",   val: port.out ? "north" : "south"
      xml.a name: "labelloc", val: port.out ? "south" : "north"
      xml.a name: "label",    val: port.out ? "out" : "B#{index}"
    end #port
  end #each
end #circuit
end #project
end #builder

File.open "divisibility3.circ", ?w do |file|
file << circ.to_xml
end

puts "done"

finally, when asked to create an output for 32 bits, my layouter generates this. Admittedly, it's not very compact for very wide inputs:


What's next, Achilles? Powerful numbers are positive integers such that, when expressed as a prime factorisation:
$$a = p_1^{e_1} \times p_2^{e_2} \times p_3^{e_3} \cdots \times p_k^{e_k}$$
all exponents \$e_1, e_2, ...\$ are greater than or equal to \$2\$. Note that the exponents do not include zero exponents, as exampled by \$200 = 2^3 \times 3^0\times  5^2 = 2^3 \times 5^2\$ being a powerful number. This includes all perfect powers, and a few "extra" numbers that are not perfect powers.
Achilles numbers are powerful numbers that are not perfect powers. The smallest Achilles number is \$72 = 2^3 \times 3^2\$. The Achilles numbers less than or equal to \$500\$ are \$72, 108, 200, 288, 392, 432\$ and \$500\$.
You are to take an Achilles number as input and output the smallest Achilles number greater than the input.
You may input and output in any convenient method. This is code-golf so the shortest code in bytes wins
Test Cases
input output
   72    108
  108    200
  200    288
  800    864
 1152   1323
 4500   4563
 3456   3528
 4563   4608
43808  43904
90828  91592
28800  29403
64800  64827
29768  30375

The program I used to generate these test cases. Contains spoilers for anyone who can understand Jelly.

J, 26 bytes
_(]+1-1</@(=],+./)q:)^:_>:

Try it online!
I started with the "do-until" idiom f^:g^:_ with g boolean (apply f while g is true), but soon realized that the "find next integer" can be written in a single fixpoint (]+1-g)^:_. The only problem is that we don't have a straightforward/more golfy way to express the boolean negation of g other than 1-g.
How it works
_(]+1-1</@(=],+./)q:)^:_>:  NB. Input: n
                        >:  NB. n+1
_(                  )^:_    NB. Fixpoint with left arg of _ (infinity)...
                  q:    NB. (_ q: n) gives prime exponents including zeros
                        NB. _ q: 700 -> 2 0 2 1 (2^2 * 5^2 * 7^1)
          ( ],+./)      NB. Append GCD of ^ to itself
      1    =            NB. Test if each number equals 1 (gives boolean vector)
       </@   NB. Test if the only 1 is the last item
  ]+1-       NB. Negate the condition and add to the input number


Print your code backwards - reverse quine Write a program that prints its own source code out backwards, in other words an eniuq.

Scoring:

+50 if you use pull data from the Internet.
+25 if you read your own source code.
+1 point per character
Lowest score wins.

Rules:

No using other files (e.g. reverse.txt)
Minimum code length is two characters.
Your program cannot be a palindrome.

huh?, 5 characters

!hcuO

I actually have NO idea how it works, but If you download the interpreter, and if you write !hcuO, then you get Ouch!

To run this, you need to execute the program like this:

huh.exe !hcuO

It will actually look for a file called !hcuO, but it doesn't exist, so it outputs Ouch!


A British find-a-movie challenge This is a more difficult version of  It's a find-a-movie challenge .

Input

Your code should take a BBFC rating and a number from 1 to 5 as input. It can do this in any way you find convenient.

Output

Your code should return the name of any movie which has a) that film rating and b) that number of stars in a Guardian film review.

If there is no such movie it can output anything you like.

The possible BBFC film ratings are U, PG, 12, 12A, 15, 18, R18, TBC.

Your code may report one or more movies, that is up to you.

To clarify, your code is meant to access the web to get the answers to queries.

Example

Say the input is U, 5 then your code could output "My Neighbour Totoro".

Please show an example of your code working with the film rating PG and score 4 along with your answer.

Notes

The Guardian does have an API but this requires registration.  For this challenge you may not use it.

Example code

The following Python 3 code gets all the movies along with their score out of 5, although not 100% perfectly.

from bs4 import BeautifulSoup
import requests
import sys

for i in range(1,837):
    print("Page", i,file=sys.stderr)
    result = requests.get("https://www.theguardian.com/film+tone/reviews?page={0}".format(i))
    data = result.text
    soup = BeautifulSoup(data, "lxml")

    tags = soup.find_all("div", {"class":"stars"})

    for tag in tags:
        stars = 0
        for star in tag.find_all("span", {"class":"star__item--grey"}):
            stars +=1
        main = tag.parent
        title = main.find("h2")
        if title:
            a = title.find("span", {"class":"js-headline-text"})
            print("{} - {}".format(5 - stars, a.text))

NodeJS

I'm an awful golfer tho

The inputs must be passed like this node filename 12,12A,15,18 4 for fetching a movie with one of the ratings comma separated and at least 4 stars

var fetch=require('node-fetch');
var {JSDOM, VirtualConsole}=require('jsdom');

var f=x=>fetch(x).then(r=>r.text());
var vc = new VirtualConsole(); // ignore annoying css errors
var [bbfc='U,PG,12',stars='3']=process.argv.slice(2);

var Z=async()=>{
    for(var i=0;i<10;i++){ // 10 max pages, can be anything
        var t= await f(`https://www.theguardian.com/film+tone/reviews?page=${i}`);
        var w=new JSDOM(t, {virtualConsole:vc}).window;
        for(var h of w.document.querySelectorAll('.fc-item__header')){
            if (h.querySelectorAll('.star__item--golden').length>=stars){
                var title=h.querySelector('.js-headline-text').textContent.split(' review')[0].trim();
                var t=await f('http://www.bbfc.co.uk/search/releases/'+title);
                var rating=t.match(/BBF\w_(\w+)_/)[1];
                if(bbfc.includes(rating)) return title;
            }
        }
    }
};

Z()
.then(console.log)
.catch(console.error)


Design a commutative injective function between any (restricted) infinite set and unordered pairs thereof Related, but this only requires positive integers and does not have to be commutative

The Cantor Pairing Function is described in this Wikipedia article. Essentially, it is an operation such that when it is applied to two values X and Y, one can obtain the original values X and Y given the result.

Your task is to design two functions: one which performs X, Y -> Z and the other which performs Z -> X, Y. Here's the catch: X, Y -> Z must be commutative. This means that Z -> X, Y won't be able to determine if the input was X, Y or Y, X.

The formal definition of this challenge would be:

Choose an countable infinite set S of numbers.
Design two functions that perform the following tasks:

Given an unordered pair of values in S, return a value in S
Given a return value from the initial function, return the unordered pair of values which evaluates to the input integer when passed through the first function. I don't care about the behaviour of this inverse function if the input isn't a return value from the first function.

Requirements

The result should be identical between runs.
{a, a} is an unordered pair

Note: your answer is more likely to get an upvote from me if you provide a proof, but I will test answers when I get to it and upvote it once I'm fairly sure it works.

Haskell, 65 + 30 = 95 bytes

a#b=length.fst$span(<(max a b,min a b))[(a,b)|a<-[1..],b<-[1..a]]

Try it online!

([(a,b)|a<-[1..],b<-[1..a]]!!)

Try it online!

Note: When the two functions may share code, this is only 75 bytes:

(l!!)
a#b=length.fst$span(<(max a b,min a b))l
l=[(a,b)|a<-[1..],b<-[1..a]]

Try it online! The domain is the positive integers. The function (#) performs the pairing, the function (l!!) its inverse. Usage example: Both (#) 5 3 and (#) 3 5 yield 12, and (l!!) 12 yields (5,3).

This works by explicitly listing all sorted pairs in an infinite list l:

l = [(1,1),(2,1),(2,2),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3),(4,4),(5,1),(5,2),(5,3),(5,4),(5,5),(6,1), ...`

The encoding is then just the index in this list.


Translate ASCII text to braille Write a program that translates ASCII text to braille output. Requirements:

Input may come from stdin, command line, or some other external input source.
Output should be recognisable as braille, the form of output is up to you. An example would be o for a raised dot and . for a non-raised dot. Textual pattern representation such as 1-3-4 is not acceptable. Long line wrapping is not required.
Only the 26 alphabet characters and space are required for a minimal solution. All input characters not supported by your solution should be ignored.

Scoring is by number of characters in the source code. Penalties and bonuses are:

+50 penalty for using Unicode braille characters as output.
-50 bonus for supporting capitals, numbers, and punctuation.
-200 bonus for supporting ligatures and one-letter contractions from English (Grade-2) Braille. (Will make this a separate challenge since it's quite a different problem.)

Sample invocation and output (minimal solution):

$ braille Hello world
o .  o .  o .  o .  o .  . .  . o  o .  o .  o .  o o
o o  . o  o .  o .  . o  . .  o o  . o  o o  o .  . o
. .  . .  o .  o .  o .  . .  . o  o .  o .  o .  . .

Python - 90 75 + 50 = 125
Use lower case letters.
for l in input():
 a=ord(l)-96
 if a<0:a=0
 print("⠀⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵"[a],end="")

One-liner (thanks to ɐɔıʇǝɥʇuʎs)
for l in input():print("⠀⠁⠃⠉⠙⠑⠋⠛⠓⠊⠚⠅⠇⠍⠝⠕⠏⠟⠗⠎⠞⠥⠧⠺⠭⠽⠵"[max(0,ord(l)-96)],end="")


Non-discriminating Programming We say a string is non-discriminating if each of the string's characters appears the same number of times and at least twice.

Examples

"aa!1 1 !a !1" is non-discriminating because each of the characters  , !, a and 1 appear three times.
"abbaabb" is not non-discriminating because b appears more often than a.
"abc" is also not non-discriminating because the characters don't appear at least twice.

Task

Write a non-discriminating program or function which returns a truthy value if a given string is non-discriminating, and a falsy value otherwise.

That is, the program run on its own source code should return a truthy value.

Each submission must be able to handle non-empty strings containing printable ASCII, as well as all characters appearing in the source code of the submission.

Test Cases

Truthy:

<your program's source code>
"aaaa"
"aa!1 1 !a !1"
"aabbccddeeffgg"
"1Q!V_fSiA6Bri{|}tkDM]VjNJ=^_4(a&=?5oYa,1wh|R4YKU #9c!#Q T&f`:sm$@Xv-ugW<P)l}WP>F'jl3xmd'9Ie$MN;TrCBC/tZIL*G27byEn.g0kKhbR%>G-.5pHcL0)JZ`s:*[x2Sz68%v^Ho8+[e,{OAqn?3E<OFwX(;@yu]+z7/pdqUD"

Falsy:

"a"
"abbaabb"
"abc"
"bQf6ScA5d:4_aJ)D]2*^Mv(E}Kb7o@]krevW?eT0FW;I|J:ix %9!3Fwm;*UZGH`8tV>gy1xX<S/OA7NtB'}c u'V$L,YlYp{#[..j&gTk8jp-6RlGUL#_<^0CCZKPQfD2%s)he-BMRu1n?qdi/!5q=wn$ora+X,POzzHNh=(4{m`39I|s[+E@&y>"

Brachylog, 10 bytes

=ᵍbᵐbᵐlᵍ=l

Try it online!

Explanation

=ᵍ                Group all equal elements together
  bᵐbᵐ            Remove the first element of each group twice. This fails if
                  there are fewer than 2 elements
      lᵍ          Group elements together that have the same length
        =         Are all elements of that list equal? This only succeeds if the
                  list has one element
         l        Length. This will always succeed


Get the Systematic Chemical Symbol Background
The systematic chemical symbol is defined as such for \$ 118 < n < 1000 \$:

The first letter corresponds to the first digit, capitalized.
The second letter corresponds to the second digit.
The third letter corresponds to the third digit.

This can be generalized for all \$ n > 0\$:

For each digit, get the corresponding letter.
Capitalize the first character.

Task
Write a function or full program that takes an integer or a list of digits \$n > 0\$ and returns or prints the corresponding systematic chemical symbol.
Digit | Letter
--------------
0     | n
1     | u
2     | b
3     | t
4     | q
5     | p
6     | h
7     | s
8     | o
9     | e

This is code-golf, so shortest code wins.
Test Cases
In - Out
----------
119 - Uue
120 - Ubn
123 - Ubt
999 - Eee
6859 - Hope
1 - U
92 - Eb
987654321 - Eoshpqtbu
1010101 - Unununu

05AB1E, 13 bytes
Input is a list of digits.
.•*Š"—Êo•sèJ™

Try it online! or Try all cases!
Commented:
.•*Š"—Êo•      # compressed alphabet string "nubtqphsoe"
         s     # swap to implicit input
          è    # index each digit into the string
           J   # join into a single string
            ™  # apply title case

See the step-by-step output here.

Lyxal has suggested another 13-byter with a nicer input format:
.•*Š"—Êo•ÅвJ™

Try it online!
This uses Åв, which converts the input integer into the custom base defined by the string.


Tips for golfing in QBasic What general tips do you have for golfing in QBasic? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to QBasic (e.g. "remove comments" is not an answer).

Tips pertaining to the QB64 emulator are also welcome. It has some extra features that aren't in Microsoft QBasic.

Know your looping constructs

QBasic has several looping constructs: FOR ... NEXT, WHILE ... WEND, and DO ... LOOP. You can also use GOTO or (in some situations) RUN to loop.

FOR ... NEXT is pretty good at what it does. Unlike in Python, it's almost always shorter than the equivalent WHILE or GOTO loop, even when it gets a little fancier:

FOR i=1TO 19STEP 2:?i:NEXT
i=1:WHILE i<20:?i:i=i+2:WEND
i=1:9?i:i=i+2:IF i<20GOTO 9

Note that you don't need to repeat the variable name after NEXT, and you can eliminate space between numbers and most following keywords.
WHILE ... WEND is good for when you have a loop that might need to execute 0 times. But if you know the loop will execute at least once, GOTO might be one byte shorter:

WHILE n>1:n=n\2:WEND
1n=n\2:IF n>1GOTO 1

I only use DO ... LOOP for infinite loops (except where RUN can be used instead). While it costs the same number of characters as an unconditional GOTO, it's a little more intuitive to read. (Note that "infinite loop" can include loops that you break out of using a GOTO.) The DO WHILE/DO UNTIL/LOOP WHILE/LOOP UNTIL syntax is too verbose; you're better off using WHILE or GOTO as appropriate.
GOTO is, as mentioned above, the shortest general way to write a do/while loop. Use single-digit line numbers instead of labels. Note that when a GOTO is the only thing in the THEN part of an IF statement, there are two equally terse shortcut syntaxes available:

IF x>y GOTO 1
IF x>y THEN 1

GOTO can also be used to create more complicated control flows. The naysayers refer to this as "spaghetti code," but this is code golf: unreadability is almost a virtue! GOTO pride!
RUN is useful when you need to jump to a fixed place in the program and you don't need to keep any of the variables' values. RUN by itself will restart the program from the top; with a label or line number, it will restart at that line. I've mainly used it to create stateless infinite loops.


Tips for creating polyglots A polyglot is a program that can be run in 2 or more different programming languages.

What general tips do you have for making polyglots, or choosing languages that are easy to write polyglots for a specific task?

Please post the tips that could be applied in most situations. I.e. they shouldn't work only in polyglots of two specific languages. (You could simply post an answer to a polyglot question if you have a too specific tip.) But you can introduce features of a language that makes it easy to work with many languages, or easy to be added to any existing polyglots.

Please post one tip per answer. And feel free to suggest edit if a language-specific tip also applies to another language.

Exploit comment symbols

A simple way to create a two-language polyglot is to have the code divided in two parts as follows:

The first part does the actual work in language A, is harmless in language B (no errors), and ends in a language-A comment symbol, which hides the second part to language A.
The second part does the actual work in language B.

Thus

Language A sees the first part, which does the job, and then a comment.
Language B sees a useless first part and then the second part, which does the job.

The only difficult part here is finding a set of statements (first part) that do the job in language A while not giving errors in language B. Some suggestions for this:

Most stack-based languages allow displaying only the top of the stack at the end of the program (sometimes this is even default, as in 05AB1E).
Some languages ignore undefined statements (for example Golfscript).

A simple example that uses these guidelines can be found here. Languages A and B are MATL and 05AB1E respectively.


Is it within the Cantor set? The Challenge

For this challenge, you are supposed to determine if a given number is in the Cantor set. So first, let's define the Cantor set.

First, start with the numbers between 0 and 1. Any numbers outside this range are not in the Cantor set. Now, let's divide the numbers into three equal parts: [0,1/3], [1/3,2/3], [2/3, 1]. Any numbers not inside the ranges of the first and last parts are not in the Cantor set. Now, you repeat this process for the segments [0,1/3] and [2/3, 1]. Then you repeat on what is leftover. You keep on doing this forever. In the end, all numbers that are remaining are in the Cantor set. Here is a diagram of the first six iterations:

Input

Two integer x and y.
0 < y < 2^15
0 <= x <= y
The greatest common denominator of x and y is 1, unless x == 0.

Output

Truthy if x/y is in the Cantor set.
Falsy if x/y is not in the Cantor set.

Examples

Now, let's see some examples of numbers that are in the Cantor set.

1/3 -> true

It is on a boundary, and boundaries are never removed.

1/4 -> true

1/4 is never in the middle third of a segment, though it is never on the boundary either. If you follow it's path, you will actually find that it alternates between being in the first and last thirds of a section.

1/13 -> true

1/13 alternates between the first, first, and last sections.

1/5 -> false

1/5 falls into the first empty block of the third row in the above diagram, between 1/9 and 2/9.

Other test cases:

0/4 -> true
3/10 -> true
3/4 -> true
10/13 -> true
1/1 -> true
12/19 -> false
5/17 -> false
3/5 -> false
1/7 -> false
1/2 -> false

You can try other numbers with this snippet:

function isCantor(t,r){var n=new Set;if(0>r)return isCantor(-t,-r);if(0==r)return!1;if(0>t||t>r)return!1;for(;;){if(t%r===0)return!0;if(1===Math.floor(t/r))return!1;if(n.has(t))return!0;n.add(t),t=t%r*3}}$("#test").click(function(){var t=parseInt($("#x").val()),r=parseInt($("#y").val());if(isNaN(t)||isNaN(r)||0==r)return void $("#result").text("Invalid input");var n=isCantor(t,r),i=(n?"I":"Not i")+"n the Cantor set.";$("#result").text(i)});
input{width:30px}button{margin-left:7px}
<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script><input id=x>/<input id=y><button id=test>Test</button><p id=result>

Objective

The person with the least bytes wins.

Mathematica, 54 bytes

If[Last@#===1,Most@#,#]&@RealDigits[#,3][[1]]~FreeQ~1&

Unnamed function taking a fraction x/y as input, where y > 0 and 0 ≤ x ≤ y, and returning True or False.

A real number between 0 and 1 is in the Cantor set precisely when none of the digits in its base-3 expansion equals 1; the exception is that a fraction whose denominator is a power of 3 (whose base-3 expansion therefore terminates) is allowed to end in a 1.

RealDigits[#,3][[1]] gives all of the digits in the base-3 expansion of the fractional input #, in a form like {1, 0, 2, {0, 1, 0, 2}}: the last list is the periodic part of the expansion, while the integers beforehand are the digits before the periodicity starts. If the base-3 expansion is periodic right away, the output is like {{0, 1, 0, 2}}; if the base-3 expansion terminates, the form is like {1, 0, 2}.

So we want to check, using ~FreeQ~1, whether the list is free of 1s or not. However, because of the terminating expansion thing, we want to delete the last element of the list if it equals 1; that's what If[Last@#===1,Most@#,#] accomplishes. (The === is needed to compare a potential list with 1: == alone remains unevaluated in that situation.)


Build an ice puzzle generator + solver In Twitch Plays Pokémon, one of the most annoying obstacles one can face is an ice puzzle, where you must travel from one place to another by sliding all the way in one direction until you either hit a wall or a boulder.

Your task is to build a program that will generate a random difficult ice puzzle.

Your program will accept three numbers, M, N, and P, as input (with 10 <= M <= 30, 15 <= N <= 40, and 0 <= P < 65536):

12 18

and will output:

An M by N grid consisting of . and O, representing ice and a boulder respectively.
A position marker representing where the puzzle is entered from. This position marker consists of a letter L, R, T, or B, representing left, right, top, and bottom, followed by a number representing the position (from the left or top) on that side to be entered from.
A similar position marker representing where the puzzle is exited out of.
The shortest solution to the puzzle, consisting of a sequence of L, R, U, and D respectively.

Example output:

..O...O...........
............O.....
..O...............
.......O..........
..................
...........O......
O..O...........O..
..........O.......
..O..........O....
........O.........
O....O.........O..
............O.....
R 4
B 5
LDLDRULD
(Note that this output is actually invalid because it is not actually long enough.)

For an input M and N, the solution to the puzzle must have at least min(M, N) steps and move at least 2 (M + N) total spaces. (For reference, the above puzzle moves a total of 12 steps, moving 69 spaces.) Your puzzle generator must generate a different M by N puzzle with a different solution path (i.e. a different sequence of steps for each solution) for each seed P.

Note that the requirement of a different solution path is to avoid solutions that try to systematically generate rock paths, like Claudiu's solution here. If there are two or three pairs of identical solutions due to quirks in randomness, that will be okay, as long as the program is not intentionally trying to systematically generate puzzles with the same sequence of moves.

The shortest code to do the above wins.

Python, 672 548 characters, more interesting puzzles

Although going strictly by the rules, my other Python program beats this one, I decided to write one that would generate more interesting puzzles anyway. Here it is:

R=range;import random as J;X=J.randint
x=(0,1,-1,0);y=x[2:]+x
g=lambda r,c:(0<=r<H)+(0<=c<W)>1and f[r][c]or x[(r,c)in(A,E)]
l=lambda r,c:g(r+y[d],c+x[d])<1and(r,c)or l(r+y[d],c+x[d])
H,W,P=input();J.seed(P)
while 1:
 A=(-1,X(0,W));E=(H,X(0,W));f=[[X(0,7)for _ in R(W)]for _ in R(H)]
 q=[(A,'')];n=z={}
 while q and n!=E:
    n,O=q.pop()
    for d in R(4):
     N=l(*n)
     if g(n[0]+y[d],n[1]+x[d])and N not in z:q[:0]=[(N,O+"URLD"[d])];z[N]=1
 if(n==E)*len(O)>min(H,W):print"\n".join(''.join('O.'[c>0]for c in T)for T in f),"\nT",A[1],"\nB",E[1],"\n",O;break

Indentation levels are space, tab, tab+space.

Samples:

$ echo [10,15,0] | python ice2.py
.....OO........
...............
...O....O.OO..O
...........O...
..O....O.......
.......O....O..
....O..........
.............O.
..............O
...............
T 1
B 10
DLURDRURULDRD

It uses P as a seed, so each P will generate the same puzzle, and each different P is exceedingly likely to be different:

$ echo [10,15,1] | python ice2.py
.OOO.O.........
...O......O.O.O
.......O.......
..O..........OO
.....O.........
.............O.
.O.............
.O............O
O....O.........
......O........
T 14
B 8
DLDRDLURULD

It works reasonably fast up to sizes of M=25,N=40 but past that it gets really slow. It should theoretically work for M=30, N=40 if you let it run long enough. I've manually written in the trail here since it is hard to follow - the program just outputs the puzzle.

$ echo [25,40,0] | python ice2.py
                   *
...................dO....urrrO..O..O....
....O.....O........dO....u..dO..........
..........O.....O..d....Ou.Odrrrrrrrrrrr
...........O.......d.O..Ou..O.....OOllld
.O....O.OO.........drrrrrrO....Olllud..O
O......O...O.O.....O............dO.ud...
O........OO..........O.........Od..ud..O
.........O......................d..ud...
....O.....O.O....O.....O........d..ud.O.
.....O..O...................O...d..udO..
.........O.........O..O.........d..ud...
.......O.O...O..O.OO....O...OOlldOOld...
........Olllllllllu....OO.OO..dOO...O...
.O.O....Od........u......O....d..O...O..
..O....O.d........u..O........d..O..O...
....O....d..O.....uO.....O....d.........
.........d........u...........d.........
.........d....O...u.O..O.....Od.O.......
........Od...O....u...........d.........
.O.....OuxrrrrO...u...OOOO..O.d.........
........udO..dO.O.u...........d.........
O..O.O..ud...d..urrO..........d.O...O...
........ud...d..u.O.O........Od..O...O..
..OO....ud..Od..u......OllllludO.....O..
..O....OldO..dOOlllllllld...Old...O..O..
             *
T 19
B 13
DRURDRDLDLULDLDLULDLURULDLURD

Explanation:

The program loops, generating a random start position on the top, a random end position on the bottom, and a random grid with a 12.5% chance for a boulder on any given spot. It then solves the puzzle with a breadth-first-search and if the solution exists and is bigger than min(H,W), it prints and exits.


Count occurrences of an integer Based on the question How many positive integers < 1,000,000 contain the digit 2?. I'm looking for the most creative solution to count all the Integers from X to Y containing the Integer Z.  Z can be from 0 to Y.

Every found Integer only counts once, even if the integer Z appears more often.
For example:

Z = 2
123 counts 1
22222 also counts 1

I will start with a really simple algorithm written in Java (because it's beloved by everyone):

public class Count {
    public static void main(String[] args) {
        int count = 0;
        for (int i = Integer.parseInt(args[0]); i <= Integer.parseInt(args[1]); i++) {
            if (Integer.toString(i).contains(args[2])) {
                count++;
            }
        }
        System.out.println(count);
    }
}

if you run this with

java -jar Count.jar 0 1000000 2

you get this as the result:

468559

Because this problem is not hard to solve it's just a popularity-contest. Most upvoted answer posted by 28th of February wins!


Un-pipe an Elixir expression Elixir is a programming language with a feature called the pipe operator, |>, similar to the pipe in Bash and other languages. It passes the result of an expression on the left as the first parameter of a given function on the right.
To clarify, here are some examples.
2 |> myFunction()

is equivalent to
myFunction(2)

Here, the expression 2 is passed as the first parameter of the function myFunction().
Now, consider how an expression with multiple pipes is evaluated. Multiple pipes are evaluated left to right, so all of these lines are equivalent:
other_function() |> new_function() |> baz() |> bar() |> foo()
new_function(other_function()) |> baz() |> bar() |> foo()
baz(new_function(other_function())) |> bar() |> foo()
bar(baz(new_function(other_function()))) |> foo()
foo(bar(baz(new_function(other_function()))))

Here, in each line the leftmost pipe is calculated, which takes the first expression and passes it to the second expression (which is a function).
Challenge
Your challenge will be to write a program or function which, when given an Elixir expression with one or more pipes, will return or output an equivalent expression with no pipes. In real Elixir code the functions may have multiple parameters but to keep this challenge simpler, you may assume all functions will take only one parameter.
Examples
Input                                                       -> Output
2 |> myFunction()                                           -> myFunction(2)
otherfunction() |> newfunction() |> baz() |> bar() |> foo() -> foo(bar(baz(newfunction(otherfunction()))))

Rules

Function names will only contain ASCII letters and underscores, and end in ()
The leftmost expression will only contain alphanumeric ASCII, underscores, and parentheses
You may assume there is no whitespace in the input (the examples here have spaces for readability)
You may also assume there are spaces surrounding the pipe operators like in the examples, if you wish
All functions only take one parameter
Leading or trailing whitespace is allowed in output
Whitespace around parentheses is allowed in output
Any reasonable form of input/output is allowed
No standard loopholes
Shortest code in bytes for each language wins

J, 23 22 bytes
(];/:')'=;)&|._2{.\cut

Try it online!
                    cut    split by space
               _2{.\       only odds
             |.            reverse
   ;/:')'=;                join and sort by equality with ')'


Constructing an Orthogonal-Diagonal Greco-Latin Square Consider a grid of NxN unique elements.  Each element has a letter (from A to the Nth letter, inclusive) and a number (from 1 to N, inclusive).  Hence, each number/letter pair is in the grid exactly once.

Your job is to arrange a grid such that:

Each row, column, and diagonal (including wrapping) contains each letter and number exactly once.

By wrapping, I mean that

* * * # *
* * # * *
* # * * *
# * * * *
* * * * #

is a diagonal, along with all similar diagonals that hit the edges.

An example 5x5 grid is:

A1 B2 C3 D4 E5
C4 D5 E1 A2 B3
E2 A3 B4 C5 D1
B5 C1 D2 E3 A4
D3 E4 A5 B1 C2

Your task is to write a program that accepts a number, N, and print a NxN grid as described above. Your program should work for any 0 < N <= 26.  If a particular grid is not possible, then you should print Impossible.

Hardcoding the answer for any N is not allowed. A program is hard coded if it calculates the grid in different manner (as judged by me) for any N > 26 (or if it fails to calculate).  (This is meant to prevent precalculation, including precalculated invalid grids, or offsets for given grids).

This is a fastest-code problem, and your score is the sum of the times taken to run your program across all possible N on my computer.  In your answer, please have your program run across all N (so I only have to time it once).  If no program can compute it in under 60 seconds, then the winner is the answer that can calculate the grid with the largest N in 60 seconds.  If multiple programs have the same maximum N, then the tiebreaker is the fastest solution.

(I have a decently powered Windows 8 machine, and any compilers or interpreters needed must be freely available for it).

Python 3

letters = []
numbers = []
for n in range(1,27):
    if n%2==0 or n%3==0:
        offsets=False
    else:
        offsets = [x for x in range(0,n,2)]
        offsets.extend([x for x in range(1,n,2)])
    letters.append(chr(96+n))
    numbers.append(n)
    if offsets :
        for y in range(n):
            for x in range(n):
                let=letters[(x+offsets[y])%n]
                num=numbers[(offsets[y]-x)%n]
                print (let+str(num), end= "  " if num<10 else " ")
            print("\n")
    else:
        print("Impossible\n")

How it works?

The naive implementation would be to look through all the possible arrangements of letter and numbers
in an NxN grid and look for one that is also a Orthogonal-Diagonal Latin Square (ODLS)
(and thus, for some it would just have to go through all configurations and return impossible). Such
an  algorithm wouldnt suit this challenge due to absurd time complexity.
So there are three major simplifications and justifications (partial proofs and insights to why it works) to ODLS constructions used in my implementation:

The first is the notion that we only need to generate a valid Diagonal Latin Square (A NxN grid such that each row, column, wrapped-diagonal
contains each element of a set of N distinct elements exactly once) of the first N letters of the alphabet.
If we can construct such a Diagonal Latin Square (DLS) then an ODLS can be constructed
using the DLS with appropriate exchange of elements and flipping. Justification:

Let us first look at an example using the example grid
a1 b2 c3 d4 e5
c4 d5 e1 a2 b3
e2 a3 b4 c5 d1
b5 c1 d2 e3 a4
d3 e4 a5 b1 c2
Every ODLS can be separated into two DLS (by definition), so
we can separate the grid above into two DLS, one containing letters, the other - numbers
a b c d e
c d e a b
e a b c d
b c d e a
d e a b c
and
1 2 3 4 5
4 5 1 2 3
2 3 4 5 1
5 1 2 3 4
3 4 5 1 2
If we transform the number DLS by the mapping 1-->e, 2-->d, 3-->c, 4-->b, 5-->a,
1 2 3 4 5 --> e d c b a
4 5 1 2 3 --> b a e d c
2 3 4 5 1 --> d c b a e
5 1 2 3 4 --> a e d c b
3 4 5 1 2 --> c b a e d
Now if we put the transformed number grid next to the original letter grid,
Original  | Transformed
a b c d e | e d c b a
c d e a b | b a e d c
e a b c d | d c b a e
b c d e a | a e d c b
d e a b c | c b a e d
It can be clearly seen that the number grid is a horizontal flip of
the letter grid withminor letter to number substitutions.
Now this works because flipping guarantees that no two pairs occur more than once,
and each DLS  satisfies the requirements of the ODLS.

The second simplification is the notion that if we found a suitable configuration (SC) of one element (A NxN grid such that each row, column, wrapped-diagonal
contains that element exactly once), then a DLS could be constructed by replacing the element and shifting the SC. Justification:

If "_" is an empty space and "a" the element then a valid SC of a 7x7 grid is
a _ _ _ _ _ _
_ _ a _ _ _ _
_ _ _ _ a _ _
_ _ _ _ _ _ a
_ a _ _ _ _ _
_ _ _ a _ _ _
_ _ _ _ _ a _
or
a _ _ _ _ _ _
_ _ _ a _ _ _
_ _ _ _ _ _ a
_ _ a _ _ _ _
_ _ _ _ _ a _
_ a _ _ _ _ _
_ _ _ _ a _ _
(the second one can actually be obtained from the first one via rotation)
now say we took the second SC, shifted it one unit to the right and
replaced all "a" with "b"
a _ _ _ _ _ _       _ a _ _ _ _ _       _ b _ _ _ _ _
_ _ _ a _ _ _       _ _ _ _ a _ _       _ _ _ _ b _ _
_ _ _ _ _ _ a       a _ _ _ _ _ _       b _ _ _ _ _ _
_ _ a _ _ _ _  -->  _ _ _ a _ _ _  -->  _ _ _ b _ _ _
_ _ _ _ _ a _       _ _ _ _ _ _ a       _ _ _ _ _ _ b
_ a _ _ _ _ _       _ _ a _ _ _ _       _ _ b _ _ _ _
_ _ _ _ a _ _       _ _ _ _ _ a _       _ _ _ _ _ b _
Now if we overlaid the SC of "a" with the SC of "b" we get
a b _ _ _ _ _
_ _ _ a b _ _
b _ _ _ _ _ a
_ _ a b _ _ _
_ _ _ _ _ a b
_ a b _ _ _ _
_ _ _ _ a b _
If we repeated these steps for the other five letters, we would arrive at a DLS
a b c d e f g
e f g a b c d
b c d e f g a
f g a b c d e
c d e f g a b
g a b c d e f
d e f g a b c
This is a DLS, since each SC follows the general requirements of a DLS
and shifting ensured that each element has its own cell.
Another thing to note is that each row contains the string "abcdefg" that is offset
by some cells. This leads to another simplification: we only need to find the
offsets of the string in every row and we are finished.

The last simplification is as follows - all DLS of prime N, except for N=2 or N=3,
can be constructed, and if N can be factored into two numbers whose appropriate
DLS can be constructed, then a DLS of that N can be constructed.
I conjecture that the converse also holds.
(In other words we can only construct an DLS for N that is not divisible by 2 or 3)

Pretty obvious why 2x2 or 3x3 cant be made. For any other prime this can be done
by assigning a each consecutive row a shift that is by two bigger than the previous,
for N=5 and N=7 this looks like (with elements other than "a" ommited)
N=5
a _ _ _ _ offset = 0
_ _ a _ _ offset = 2
_ _ _ _ a offset = 4
_ a _ _ _ offset = 6 = 1 (mod 5)
_ _ _ a _ offset = 8 = 3 (mod 5)
N=7
a _ _ _ _ _ _ offset = 0
_ _ a _ _ _ _ offset = 2
_ _ _ _ a _ _ offset = 4
_ _ _ _ _ _ a offset = 6
_ a _ _ _ _ _ offset = 8 = 1 (mod 7)
_ _ _ a _ _ _ offset = 10 = 3 (mod 7)
_ _ _ _ _ a _ offset = 12 = 5 (mod 7
(Why this works on all prime N (actually all N that are not divisible
by 3 or 2) can probably be proven via some kind of induction but i will
omit that, this is just what my code uses and it works)
Now, the first composite number that is not
divisible by 2 or 3 is 25 (it also occurs in the range our program must test)
Let A denote the DLS of N = 5
a b c d e
d e a b c
b c d e a
e a b c d
c d e a b
Let F be the DLS A where each letter is substituted by the letter five postions after it
a-->f, b-->g etc. So F is
f g h i j
j e f g h
g h i j f
j f g h i
h i j f g
Let K be the DLS a where each letter is substituted by the letter ten postions after it
a-->k, b--> l etc.
Let P be defined likewise (so a-->p, b-->q etc)
Let U be defined likewise (so a-->u, b-->v etc)
Now, since the DLS A could be constructed, then by substituting a --> A, b--> F etc.
we get a DLS of N=5*5 (A has five rows and five columns and each is filled with a
grid of five rows and five columns)
A F K P U
P U A F K
F K P U A
U A F K P
K P U A F
Now since smaller DLS in the big DLS satisfies the
conditions of a DLS and the big one also satisfies the DLS conditions,
then the resulting grid is also a DLS

A picture of what i meant with the smaller - bigger DLS

Now this kind of thing works for all constructible N and can be proven similiarly.

I have a strong sense that the converse (if some N isnt constructible
(2 and 3) then no multiple of that N is constructible) is also true but have a hard time
proving it (test data up to N=30 (took a veeery long time to calculate) confirm it though)


Cycle lengths for Perfect shuffles of decks of any size Challenge

In the shortest amount of code:

Compute the length of the permutation cycle of a perfect shuffle on a deck of cards of any size n (where n ≥ 2 and n is even).
Output a table of all cycle lengths for 2 ≤ n ≤ 1000 (n even).

Note that there are two basic ways of defining a perfect shuffle. There is the out-shuffle, which keeps the first card on top and the last card on bottom, and there is the in-shuffle, which moves the first and last cards one position toward the center. You may choose whether you are doing an out-shuffle or an in-shuffle; the algorithm is almost identical between the two.

out-shuffle of 10-card deck: [1,2,3,4,5,6,7,8,9,10] ↦ [1,6,2,7,3,8,4,9,5,10].
in-shuffle of 10-card deck: [1,2,3,4,5,6,7,8,9,10] ↦ [6,1,7,2,8,3,9,4,10,5].

Graphical example

Here, we see that an out-shuffle on a 20-card deck has a cycle length of 18 steps. (This is for illustration only; your solution is not required to output cycles graphically.) The classic 52-card deck, on the other hand, has an out-shuffle cycle length of only 8 steps (not shown).

An in-shuffle on a 20-card deck has a cycle length of only 6 steps.

Tabular example of output

Your program should output something similar to this, although you may choose any tabular format that you like best. This is for an out-shuffle:

2 1
4 2
6 4
8 3
10 6
12 10
14 12
16 4
18 8
20 18
22 6
24 11
26 20
28 18
30 28
32 5
34 10
36 12
38 36
40 12
...many lines omitted...
1000 36

Questions

Does there seem to be any connection between the number input n and its cycle count, when n is a power of 2?
How about when n is not a power of 2?
Curiously, a 1000-card deck has an out-shuffle cycle count of only 36, while a 500-card deck has an out-shuffle cycle count of 166. Why might this be?
What is the largest number you can find whose cycle count c is vastly smaller than n, meaning that ratio n/c is maximized?

Haskell, 47 46 44 (in shuffle)
[[i|i<-[1..],mod(2^i)n<2]!!0|n<-[3,5..1001]]

the basic realization is that this is the order of 2 in the multiplicative group of modulus n+1.


Copy a file - Windows style This challenge is inspired by xkcd:

Challenge:

You'll simulate the copying a large file (1 Gigabyte). The transfer rate will vary between 10 kB/second to 100 MB/second.
Your task is to output the time remaining of the file transfer. The output should look like:

Time remaining: 03:12    (meaning it's 3 minutes and 12 seconds left)
Time remaining: 123:12   (meaning it's 2 hours, 3 minutes and 12 seconds left)
Time remaining: 02:03:12 (optional output, meaning the same as above)

Leading zeros need not be displayed for minutes and hours (optional), but must be shown for seconds. Showing the time remaining using only seconds is not OK.

The file transfer:

The transfer rate will start at 10 MB/second.
Every second, there will be a 30% chance that the transfer rate will change
The new transfer rate should be picked randomly (uniform distribution) in the range [10 kB/s, 100 MB/s], in steps of 10 kB/s.

Note: You don't need to actually copy a file.

You may choose to use: 1 GB = 1000 MB, 1 MB = 1000 kB, 1 kB = 1000 B, or 1 GB = 1024 MB, 1 MB = 1024 kB, 1 kB = 1024 B.

Output:

You start at 01:40, not 01:39.
You display the time after the transfer rate changes, but before anything is transferred at that rate
The seconds should be displayed as integers, not decimals. It's optional to round up/down/closest.
You should clear the screen every second, unless that's impossible in your language.
The output should be constant: Time remaining: 00:00 when the file transfer is over.

Example:

I have rounded up all decimal seconds.
Assume the lines below are shown with 1 second in between, and the screen is cleared between each one:

Time remaining: 01:40  (Transfer rate: 10 MB/s)
Time remaining: 01:39      1 GB - 10 MB
Time remaining: 01:38      1 GB - 2*10 MB
Time remaining: 01:37      1 GB - 3*10 MB
Time remaining: 01:28:54   1 GB - 4*10 MB  (TR: 180 kB/s)
Time remaining: 01:28:53   1 GB - 4*10 MB - 180 kB
Time remaining: 01:28:52   1 GB - 4*10 MB - 2*180 kB
Time remaining: 00:13      1 GB - 4*10 MB - 3*180 kB  (TR: 75 MB/s)
Time remaining: 00:12      1 GB - 4*10 MB - 3*180 kB - 75 MB
Time remaining: 00:11      1 GB - 4*10 MB - 3*180 kB - 2*75 MB
Time remaining: 00:10      1 GB - 4*10 MB - 3*180 kB - 3*75 MB
Time remaining: 00:09      1 GB - 4*10 MB - 3*180 kB - 4*75 MB
Time remaining: 00:08      1 GB - 4*10 MB - 3*180 kB - 5*75 MB
Time remaining: 14:09:06   1 GB - 4*10 MB - 3*180 kB - 6*75 MB  (TR: 10 kB/s)
Time remaining: 14:09:05   1 GB - 4*10 MB - 3*180 kB - 6*75 MB - 10 kB
Time remaining: 00:06      1 GB - 4*10 MB - 3*180 kB - 6*75 MB - 20 kB  (TR: 88.110 MB/s)
Time remaining: 00:05
Time remaining: 00:04
Time remaining: 00:03
Time remaining: 00:02
Time remaining: 00:01
Time remaining: 00:00     <- Transfer is finished. Display this.

Pyth - 70 68 bytes
K^T5J^T3W>KZ%." r3úBTêî¢¤;¥
í".D/KJ60=J?<OT3O^T4J=-KJ.d1.

Try it online without sleeps.


Binary Numbers Magic Trick The challenge is simply; output the following six 2D integer arrays:
[[ 1, 11, 21, 31, 41, 51],
 [ 3, 13, 23, 33, 43, 53],
 [ 5, 15, 25, 35, 45, 55],
 [ 7, 17, 27, 37, 47, 57],
 [ 9, 19, 29, 39, 49, 59]]

[[ 2, 11, 22, 31, 42, 51],
 [ 3, 14, 23, 34, 43, 54],
 [ 6, 15, 26, 35, 46, 55],
 [ 7, 18, 27, 38, 47, 58],
 [10, 19, 30, 39, 50, 59]]

[[ 4, 13, 22, 31, 44, 53],
 [ 5, 14, 23, 36, 45, 54],
 [ 6, 15, 28, 37, 46, 55],
 [ 7, 20, 29, 38, 47, 60],
 [12, 21, 30, 39, 52]]

[[ 8, 13, 26, 31, 44, 57],
 [ 9, 14, 27, 40, 45, 58],
 [10, 15, 28, 41, 46, 59],
 [11, 24, 29, 42, 47, 60],
 [12, 25, 30, 43, 56]]

[[16, 21, 26, 31, 52, 57],
 [17, 22, 27, 48, 53, 58],
 [18, 23, 28, 49, 54, 59],
 [19, 24, 29, 50, 55, 60],
 [20, 25, 30, 51, 56]]

[[32, 37, 42, 47, 52, 57],
 [33, 38, 43, 48, 53, 58],
 [34, 39, 44, 49, 54, 59],
 [35, 40, 45, 50, 55, 60],
 [36, 41, 46, 51, 56]]

What are these 2D integer arrays? These are the numbers used in a magic trick with cards containing these numbers:

The magic trick asks someone to think of a number in the range [1, 60], and give the one performing the magic trick all the cards which contain this number. The one performing the magic trick can then sum the top-left numbers (all a power of 2) of the given cards to get to the number the person was thinking of. Some additional explanation of why this works can be found here.
Challenge rules:

You can output the six 2D integer arrays in any reasonable format. Can be printed with delimiters; can be a 3D integer array containing the six 2D integer arrays; can be a string-list of lines; etc.
You are allowed to fill the bottom right position of the last four cards with a negative value in the range [-60, -1] or character '*' instead of leaving it out to make the 2D integer arrays rectangular matrices (no, you are not allowed to fill them with 0 or a non-integer like null/undefined as alternative, with the exception of * since a star is also used in the actual cards).
The order of the numbers in the matrices is mandatory. Although it doesn't matter for the physical magic trick, I see this challenge mainly as a matrix-kolmogorov-complexity one, hence the restriction on order.
The order of the matrices themselves in the output list can be in any order, since it's clear from the top-left card which matrix is which.

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 with default I/O rules, 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 (i.e. TIO).
Also, adding an explanation for your answer is highly recommended.

Perl 6, 63 46 bytes

say grep(*+&2**$_,^61)[$_,*+5...*for ^5]for ^6

Try it online!

Outputs as 2D arrays on multiple lines, with the last array of each one cut off if necessary.


Decipher a Vigenère ciphertext The Vigenère cipher was a simple polyalphabetic cipher that basically applied one of several Caesar ciphers, according to a key. Bascially the letters in the key indicate which shifted alphabet to use. To that end there was a simple tool, called the Vigenère square:

Here each row is a separate alphabet, starting with the corresponding letter of the key. The columns then are used to determine the ciphered letter. Decryption works in very much the same fashion, only vice-versa.

Suppose we want to encrypt the string CODEGOLF. We also need a key. In this case the key shall be FOOBAR. When the key is shorter than the plaintext we extend it by repetition, therefore the actual key we use is FOOBARFO. We now look up the first letter of the key, which is F to find the alphabet. It starts, perhaps unsurprisingly, with F. Now we find the column with the first letter of the plaintext and the resulting letter is H. For the second letter we have O as the key letter and the plain text letter, resulting in C. Continuing that way we finally get HCRFGFQT.

Task

Your task now is to decipher messages, given a key. However, since we have outgrown the 16th century and have computers we should at least support a slightly larger alphabet:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789

The construction of the Vigenère square is still very much the same and the cipher still works in the same way. It's just a bit ... unwieldy to give here in full.

Input

Input is given on standard input as two separate lines of text, each terminated by a line break. The first line contains the key while the second contains the ciphertext.

Output

A single line, containing the deciphered message.

Winning condition

Since encryption is sometimes regarded as a weapon, the code should be short to facilitate easy smuggling. The shorter the better, as it reduces the likelihood of discovery.

Sample input 1

Key
miQ2eEO

Sample output 1

Message

Sample input 2

ThisIsAKey
CoqKuGRUw29BiDTQmOpJFpBzlMMLiPb8alGruFbu

Sample output 2

ThisWorksEquallyWellWithNumbers123894576

A week has passed. The currently shortest solution has been accepted. For those interested, in our contest we had the following submissions and lengths:

  130 – Python
  146 – Haskell
  195 – C
  197 – C
  267 – VB.NET

And our own solutions that weren't ranked with the others:

  108 – Ruby
  139 – PowerShell


What's my math assignment? The Challenge

I always write my math assignments down in the same way. For example:

pg. 420: #25, 50-56, 90
pg. 26: #50-60 evens, 70-80 odds, 90-99 3s
pg. 69: #12, 16, 18, 37

But I need you to tell me the individual problem numbers. For example:

input:
pg. 420: #25, 50-56, 90

output:
25, 50, 51, 52, 53, 54, 55, 56, 90

Here are the rules for telling me my problem numbers:

The assignment always starts with pg. (number): #, feel free to discard it.

Each group of problems is separated by a comma, and different patterns mean different things.

A single number (4, 6, 7438, 698236) just means that one problem is in the assignment.

Two numbers with a dash between them means those two numbers and all integers between. For example, 1-6 would become 1, 2, 3, 4, 5, 6

If two numbers have a dash between them, then there's a word, there is a special rule for the numbers.

If the word is evens, then all even numbers between the two are included (1-6 evens -> 2, 4, 6).

If the word is odds, then all odd numbers between the two are included (1-6 odds -> 1, 3, 5).

If the word is 3s, then all numbers where n mod 3 = 0 between the two are included (1-6 3s -> 3, 6);

Test Examples: (inputs then outputs)

pg. 1: #1, 2, 3
1, 2, 3

pg. 82: #76, 84-87, 91, 94-100 evens, 103-112 3s
76, 84, 85, 86, 87, 91, 94, 96, 98, 100, 103, 106, 109, 112

pg. 9001: #9000-9002 odds
9001

This is code-golf, so your score is the number of bytes.

JavaScript (ES7), 138 bytes

F=s=>s.replace(/.*#|(\d+)-?(\d+)? ?(\d|\w*)s?/g,(_,a,b,c)=>b?[for(i of Array(b-a--+1))if(++a*c?(b-a)%c<1:!c||a%2==c>'f')a].join`, `:a||'')

F=s=>s.replace(/.*#|(\d+)-?(\d+)? ?(\d|\w*)s?/g,(_,a,b,c)=>b?[for(i of Array(b-a--+1))if(++a*c?(b-a)%c<1:!c||a%2==c>'f')a].join`, `:a||'')
button.onclick=()=>output.innerHTML=F(range.value)
button, textarea {
  display: block;
  width: 100%;
  margin-bottom: 0.5em;
  box-sizing: border-box;
}
<textarea id="range"></textarea>
<button id="button">submit</button>


Calculate average characters of string Task

Your task is to produce string that contains average characters of string.
First character of result would be average character of first character (which is first character) and second character average of two first characters and so on.

What is average character?

Strings are arrays of bytes. Average character of string can be found by calculating the average of the ASCII values of characters in string and taking corresponding ASCII character.

For example string "Hello!" can be written as byte sequence 72 101 108 108 111 33. Average of ascii values is 533/6 = 88.833... and when it's rounded to nearest integer we get 89 which is ascii code for captial letter Y.

Rules

You can assume that input contains only printable ASCII characters
Input can be read from stdin or as command line arguments or as function arguments
Output must be stdout. If your program is function, you can also return the string you would otherwise print.
It must be whole program or function, not snippet
Standard loopholes apply
Integers are rounded by function floor(x+0.5) or similar function.

How do I win?

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

Examples

Hello! → HW^adY
test → tmop
42 → 43
StackExchange → Sdccd_ccccddd

Brainfuck 106 bytes

,[>,<.[->+<]>>++<[>[->+>+<<]>[-<<-[>]>>>[<[>>>-<<<[-]]>>]<<]>>>+<<[-<<+>>]<<<]>[-]>>>>[-<<<<<+>>>>>]<<<<<]

This is my first participation in a code-golf, please be gentle!
It does work but brainfuck can't handle floats (not that i know of) so the rounded value is always the bottom one (might fix my algorithm later).

Also, the algorithm averages the values 2 by 2, meaning it could be innacurate in some spots.
And I need to fix a bug that is printing a number at the end of the output too.


Does the water ultimately reach the tank? In the ASCII art world, there is water, hash walls and letter mechanisms.

You are in a room made up of hash walls (# signs):

#######
#     #
#     #
#     #
# ### #
#     #
#######

You install an S water source (S sign) and an E water tank (E sign) which can receive water from any direction, but you only have one S source and one E tank.

#######
#  S  #
#     #
#     #
# ### #
#  E  #
#######

So you have to select wisely where to place the source. That's where you pull off your code-golf skills.

The task

You get an input consisting of a string representing a room with the source and the tank:

#######
#  S  #
#     #
#     #
# ### #
#  E  #
#######

You have to find out if the water ultimately reaches the tank. The water flows down, if possible, else to the left and right, if possible. The water doesn't accumulate because it doesn't go up.

So, for the above input, the result is:

#######
#  *  #
#  *  #
#*****#
#*###*#
#**O**#
#######

The water happily reaches the tank, so you must output a truthy value.

But if the water doesn't reach the tank:

#######
#S    #
#     #
#  E  #
# ### #
#     #
#######

#######
#*    #
#*    #
#* X  #
#*### #
#*****#
#######

Then you must output a falsy value.

Write a program to decide whether the water ultimately reaches the tank. Your code should be as short as possible.

Assumptions

Assume that the input is always valid (the entire room is an enclosed rectangular region with the S and E).
Assume there is only one room provided as input.

Test Cases

Your program should return a truthy value for the following test cases:

#######
#  S  #
#     #
#     #
# ### #
#  E  #
#######

#######
#  S  #
#     #
#  E  #
#     #
#     #
#######

#######
#     #
#     #
# SE  #
# ### #
#     #
#######

###############################################
#                      S                      #
#                                             #
#                                             #
#                                             #
#               ###############               #
#                                             #
#  ##################     ##################  #
#                                             #
#                                             #
#                    #####                    #
#                      E                      #
###############################################

#######
#  S  #
#     #
#     #
# ### #
#   # #
### ###
## E ##
#     #
#######

But a falsy value for the following test cases:

#######
#S    #
#     #
#  E  #
# ### #
#     #
#######

#######
#     #
# SE  #
#     #
#     #
#     #
#######

#######
#     #
#  E  #
#     #
#  S  #
#     #
#######

####################################
#                                  #
#                                  #
#                                  #
#S             #                  E#
####################################

The second to last room in the True category and the last room in the False category were shamelessly stolen borrowed from Koth: Jump and Run by Manu (who deleted the sandbox post).

The last room in the True category is from Martin Buttner's answer in Retina.

Snails, 20 bytes

\S{d(=\#n)?^#},!(t\E

Prints 0 for the falsey value and 1 for the truthy value.

Try it online!

\S matches S at the start
d sets direction to down
{...}, matches the stuff in braces 0 or more times
=\# is an assertion which succeeds if there is a # char ahead of the snail, but does not move it
n turns 90 degrees in either direction
(...)? matches the pattern in parentheses 0 or 1 times
\  matches a space and moves the snail onto it
!(... is a negative assertion
t teleports to any unmatched square in the grid
\E matches E