Quickly Prove Me Wrong! Introduction

This is the evolution of this previous challenge which was about checking satisfieability of normal formulae in conjunctive normal form (CNF). However, this problem is NP-complete and watching algorithms finish is just boring, so we're gonna simplify the problem!

Specification

Input

You may tune the following input specification to optimally match your language as long as you don't encode additional information.
Your input will be a list of implications. Each implication has a list of variables on the left and a single variable on the right. Variables may be represented using your favorite representation (integer, strings, whatever), for the sake of this specification, characters will be used. The list on the left side may be empty and there may not be a variable on the right. The variable on the right side will not appear on the left side of the same implication.

Example input:

[A -> B; B -> A]
[A,B,C -> D; B,C -> E; -> A; B -> ]

Output

Your output will be a truthy or a falsy value.

What to do?

You need to determine whether the given formula is satisfieable and output truthy if it is satisfieable and falsy if not.
A,B -> C means that if A and B need to hold then C needs to hold as well.
-> C means that C always needs to hold (this is short-hand for True -> C).
A,B -> means that if A and B need to hold, so does falsum and thus there is a contradiction, thus if you find such an implication where A and B hold, you can immediately output falsy (this is short-hand for A,B -> False).
The list of implications all need to hold at the same time.

Because this problem is also known as HORNSAT, it is P-complete and to avoid trivial solutions to this, your solution must run in polynomial time and you must provide reasoning why your solution does so.

Who wins?

This is code-golf, thus the shortest solution in bytes wins! Standard rules apply.

Examples

with Explanation

[A,B -> C; C ->; -> A; A -> B] A needs to hold, thus B needs to hold, thus C needs to hold and thus you found a contradiction.
[A,B -> D; C ->; -> A; A -> B] A needs to hold, thus B needs to hold, thus D needs to hold, however C doesn't need to hold and thus this formula is satisfieable.

without Explanation

[A -> B; B -> A] => 1
[A,B,C -> D; B,C -> E; -> A; B -> ] => 1
[A,B -> C; C ->; -> A; A -> B] => 0
[A,B -> D; C ->; -> A; A -> B] => 1
[P -> ; -> S ; P -> R; Q -> U; R -> X; S -> Q; P,U -> ; Q,U -> W] => 1
[-> P; Q -> ; T -> R; P -> S; S -> T; T,P -> Q ] => 0

Alice, 45 bytes

/;;?dhE..';F>@.>F*.?oK
\'..zi;w!";-$"'!?n-$-/

Try it online!

Input is in the form A->B;B->A with no spaces.  Output is Jabberwocky if the formula is satisfiable, and nothing otherwise.

Explanation

This follows a standard template for programs that run entirely in ordinal mode.  Unwrapped, the program is:

';.diEw.";->".!Fn.$o;.?zh;.!';F$@'>?*-?-K

';.     Push a semicolon and duplicate it
d       Join these two semicolons into a single string and push it, without removing the originals
        This puts ";;" on top of the stack, with a ";" under it (and an irrelevant ";" under that)
i       Take input
E       Insert input between the only pair of characters in ";;"
w       Push return address (start main loop)
.       Duplicate current set of implications
";->"   Push this string
.!      Copy to tape (to get it again later with fewer bytes)
F       Check whether this string is in current set of implications
n       Negate result: "Jabberwocky" if no match, "" if match
.$o     Output this string if nonempty (no unit clauses remain)
;       Discard top of stack: if the previous command didn't output, this puts the implications back on the TOS
        If the previous command did output, this discards the implications and puts ";" on the TOS
.       Duplicate
?z      Remove everything up to and including the first ";->"
h;      Take first character of remaining string: this is the literal in the first unit clause,
        or ";" if the clause is simply "->" (or if "Jabberwocky" was output earlier)
.!      Copy to tape, since we will need it later
';F     Check whether this character contains (i.e., is) a semicolon
$@      If so, terminate
        (Replace "A" in the next two lines with the actual value of the literal in this unit clause)
'>?*-   Remove all instances of ">A"; this destroys all clauses that imply A
?-      Remove all instances of "A"
K       Return to start of main loop

Each command in the main loop takes polynomial time, and each iteration of the loop either terminates the program or destroys at least one clause.  Hence, the entire program runs in polynomial time.


secret language hackerrank.com I tried this contest: https://www.hackerrank.com/challenges/secret-language
Well, the score in this contest said I made 30 out of 30 points. As the score is calculated with the formula 30*(1000-#chars)/1000 this is impossible. Here is my code:

import sys,string as s
b='anbycoduepfxgqhvirjzkslwmt'
a=s.letters
b+=b.upper()
t=s.translate
m=s.maketrans
for l in sys.stdin:
 print{'N':t(l[7:],m(a,b)),'E':t(l[7:],m(b,a)),'O':''}[l[1]],

The contest is over, so asking is no cheating but I would like to get some realistic score. I have 187 chars with newline and 195 with cr-lf. For pythoncode 24.39 (assuming newline) isn't so bad, but I think it can be done better.

For completeness here is the challenge:

Bob and Fred pass notes to each other in class all the time. However their teacher started intercepting their messages and reading the messages out loud to the class. Undeterred, Bob and Fred decided to encode their messages before they pass them so that when the message is intercepted the teacher and class will not understand it.

They got together and decided on using a simple substitution cipher. The substition cipher they agreed upon is listed below:

Old Letter: ABCDEFGHIJKLMNOPQRSTUVWXYZ
New Letter: ANBYCODUEPFXGQHVIRJZKSLWMT

Using this key (Case matters!), A is changed to A, a is changed to a, B is changed to N, b is changed to n, C is changed to B, c is changed to b, … . All other characters remain the same.

However after Bob and Fred started using this method of note transfer they quickly realized that they are very slow at encoding and decoding messages. They have hired you to help them transfer messages faster by writing a program that will encode or decode messages using their substitution cipher. They want the code to be very portable so the smaller the source file is the better.

Input

Input will consist of several lines. Each line will begin with either the string “ENCODE”, “DECODE”, or “DONE”. If the string is “ENCODE” or “DECODE” then a message will follow. This is the message that you will have to either encode (if the first string is “ENCODE”) or decode (if the first string is “DECODE”). Messages will contain spaces and punctuation but will always be on the same line. If the string is “DONE” then this signifies that Bob and Fred are done exchanging messages.

Output

For each line that begins with “ENCODE” print the encoding of the message that follows.

For each line that begins with “DECODE” print the decoding of the message that follows.

Be sure to keep all capitolization and punctuation that is used in the message.

Sample Input

ENCODE This is a message.
DECODE Zuej ej a gcjjadc.
DONE

Sample Output

Zuej ej a gcjjadc.
This is a message.

Scoring

Your score will be 30 * (1000 - #characters) / 1000. The minimum score a correct solution will receive is 0.03.

bash and friends (168 167 chars)

T=ANBYCODUEPFXGQHVIRJZKSLWMT
while read x&&[ "$x" != "DONE" ]
do
[ "$x" \> "E" ]
for((z=1+$?*58;z;z--))do
x=$(tr a-zA-Z `tr A-Z a-z<<<$T`$T<<<$x)
done
echo ${x:6}
done

The magic number isn't so magic: it's obtained by solving a set of simultaneous modular identities obtained from the cycle structure of the permutation.


We had a question once which only failed on Sundays Inspired by We had a unit test once which only failed on Sundays, write a program or function that does nothing but throw an error when it is Sunday, and exit gracefully on any other day.
Rules:

No using input or showing output through the usual IO methods, except to print to STDERR or your language's equivalent. You are allowed to print to STDOUT if it's a by-product of your error.
A function may return a value on non-Sundays as long as it doesn't print anything
Your program may use a Sunday from any timezone, or the local timezone, as long as it is consistent.
An error is a something that makes the program terminate abnormally, such as a divide by zero error or using an uninitialised variable. This means that if any code were to be added after the part that errors, it would not be executed on Sunday.
You can also use statements that manually create an error, equivalent to Python’s raise.
This includes runtime errors, syntax errors and errors while compiling (good luck with that!)
On an error there must be some sign that distinguishes it from having no error
This is code-golf, so the shortest bytecount in each language wins!

I'll have to wait til Sunday to check the answers ;)

Bash + coreutils, 15 14 bytes

`date|grep Su`

Try it online!


Find the identity sandpile This question is about abelian sandpiles. Read this previous challenge and watch this numberphile video to learn more.

An abelian sandpile of size n by n is a grid containing the number 0, 1, 2 and 3 (representing the number of grains of sand). Adding two sandpiles works by first adding element by element, and then toppling any element that goes above 3. The order in which you topple doesn't matter, the end result is the same. When a cell topples its number decreases by 4, and each of its direct neighbors increases by 1. This can cause a chain reaction. If a cell is on the edge of the grid, any grains that fall off the grid while toppling disappear.

For example, I'm adding two 3 by 3 sandpiles (giving a rather extreme chain reaction):

3 3 3   1 2 1   4 5 4    4 6 4    6 2 6    6 3 6    2 5 2    4 1 4    4 2 4    0 4 0    2 0 2    2 1 2
3 3 3 + 2 1 2 = 5 4 5 -> 6 0 6 -> 2 4 2 -> 3 0 3 -> 5 0 5 -> 1 4 1 -> 2 0 2 -> 4 0 4 -> 0 4 0 -> 1 0 1
3 3 3   1 2 1   4 5 4    4 6 4    6 2 6    6 3 6    2 5 2    4 1 4    4 2 4    0 4 0    2 0 2    2 1 2

In this challenge we're interested in a subset of all possible n by n sandpiles. This subset contains any sandpile that you can get by adding an arbitrary sandpile to the all-3s n by n sandpile. For example, just above we saw that 212 | 101 | 212 is in the subset, because we got it by adding something to the all-3 sandpile.

Now this subset has an interesting element: the identity element. If you take this element and add it to any other element in the subset, the sum is unchanged. In other words, this sandpile acts like a zero of this subset. It just so happens that 212 | 101 | 212 is the zero element for the subset of 3 by 3. For example:

2 2 2   2 1 2   4 3 4    0 5 0    2 1 2    2 2 2
2 2 2 + 1 0 1 = 3 2 3 -> 5 2 5 -> 1 6 1 -> 2 2 2
2 2 2   2 1 2   4 3 4    0 5 0    2 1 2    2 2 2

Now this is your challenge: given n, find the identity element of the subset of the n by n grid. Output it by assigning a unique color with sufficient contrast of your choice to each of 0, 1, 2, 3 and outputting an n by n image. Your code must be able to produce the 50 by 50 case in under a minute on a reasonable modern PC.

For example, the 500 by 500 identity element:

Here is blue = 3, green = 2, red = 1, white = 0. But you don't have to use this color scheme in your answer.

Mathematica, 177 157 135 133 bytes
Colorize[f=BlockMap[⌊{l={0,1,0},1-l,l}#/4⌋~Total~2+#[[2,2]]~Mod~4&,#~ArrayPad~1,{3,3},1]&~FixedPoint~#&;k=Table[6,#,#];f[k-f@k]]&

Takes a number n. The output is the identity sandpile. 0 is black, 1 is light gray, 2 is magenta, and 3 is blue-gray.
Sadly, Mathematica does not have a builtin for this...
Uses the algorithm stated in Scott Corry and David Perkinson's paper.
Takes 91.7 seconds on my 5-year-old laptop to calculate the 50x50 identity sandpile. I am confident that a reasonable modern desktop computer is more than 50% faster. (I also have a way faster code at the end).
Explanation
f= ...

Define function f (the input is a sandpile matrix): a function that ...
BlockMap[ ... ]~FixedPoint~#&

... repeats the BlockMap operation until the output does not change. BlockMap operation: ...

#~ArrayPad~1

... pad the input array with one layer of 0 ...
{3,3},1

... partition it into 3x3 matrices, with offset 1 ...
⌊{l={0,1,0},1-l,l}#/4⌋~Total~2+#[[2,2]]~Mod~4&

... and for each partition, add the number of sand grains toppled onto the center cell and the center cell value mod 4.
i.e. the output of f is the stabilized version of the input.

k=Table[6,#,#]

Define k as an n by n array of 6s.
f[k-f@k]]

Compute f(k - f(k)).
Colorize[ ... ]

Apply colors to the result.
Faster version (142 bytes)
Colorize[r=RotateLeft;a=ArrayPad;f=a[b=#~a~1;b+r[g=⌊b/4⌋,s={0,1}]+g~r~-s+r[g,1-s]+r[g,s-1]-4g,-1]&~FixedPoint~#&;k=Table[6,#,#];f[k-f@k]]&

Same code, but uses built-in list rotation instead of BlockMap. Computes n=50 in 4.0 seconds on my laptop.


Minimal cost path in wall-breaking maze Inspired by this Puzzling challenge.
Challenge
Given a 2D rectangular grid where each cell is either an empty space or a wall, find the path (or one of the paths) from the top left cell to the bottom right, which satisfies the following:

Only movement to one of four adjacent cells is allowed.
The path breaks (or passes through) the minimal number of walls possible. In other words, a longer path that breaks fewer walls is preferred over a shorter path that breaks more walls.
Among all paths that satisfy 2., the path is the shortest in terms of the number of cells visited in total.

The input can be taken as a matrix (or any equivalent) containing two distinct values to represent empty spaces and walls. The top left and bottom right cells are guaranteed to be empty.
Output the path as a grid (of the same dimensions as the input) containing two distinct values, one for the cells that are part of the path and the other for the rest.
Standard code-golf rules apply. Shortest code in bytes wins.
Test cases
In the following examples, the input uses .# for empty/wall, and the output uses .+ for non-path/path.
Input
..#..#..

Output
++++++++

Input
.#...
...#.

Output
+.+++
+++.+

Input
....
....
....
....

Output
++++
...+
...+
...+ (or any other path of same length)

Input
..#..
..#..
..#..

Output
+++++
....+
....+ (or any other path of same length that breaks only one walls)

Input
.#.#.
##.##
.###.

Output
+++++
....+
....+ (or 3 other possible answers)

Input
.......
######.
.......
.######
....#..

Output
+++++++
......+
......+
......+
......+

Input
.....#..
#######.
#######.
........
.#######
.#######
....#...

Output
++++++++
.......+
.......+
++++++++
+.......
+.......
++++++++

JavaScript (ES7),  198 185 179  178 bytes
Expects a matrix of integers with -1 for a wall and 0 for an empty cell. Returns a matrix of Boolean values.

m=>(g=(Y,w,n,X)=>w>=W&&w>W|n>N?0:m[Y+1]||1/m[Y][X+1]?m.map((r,y)=>r.map((v,x)=>v>0?1:(X-x)**2+(Y-y)**2^1?0:r[r[x]=1,g(y,w-v,-~n,x),x]=v)):o=g(-1,W=w,N=n))(0,0,W=++m[0][0]/0,0)&&o

Try it online!
Commented
This is a depth-first search. Visited cells are marked with 1. We keep track of the number of broken walls in w and the total number of visited cells in n. We abort as soon as the current path is worse than the best path found so far.
m => (                         // m[] = input matrix
  g = (                        // g is a recursive function taking:
    Y, w, n, X                 //   (X, Y) = current position
                               //   w = number of broken walls
  ) =>                         //   n = number of visited cells
  w >= W && w > W | n > N ?    // if (w, n) is worse than (W, N):
    0                          //   abort
  :                            // else:
    m[Y + 1] ||                //   if there's a cell below the current cell
    1 / m[Y][X + 1] ?          //   or a cell on the right:
      m.map((r, y) =>          //     for each row r[] at position y in m[]:
        r.map((v, x) =>        //       for each value v at position x in r[]:
          v > 0 ?              //         if v is positive:
            1                  //           yield 1
          :                    //         else:
            (X - x) ** 2 +     //           if the squared distance between
            (Y - y) ** 2 ^ 1 ? //           (X, Y) and (x, y) is not equal to 1:
              0                //             do nothing
            :                  //           else:
              r[r[x] = 1,      //             mark r[x] as visited by setting it to 1
                g(y, w - v,    //             do a recursive call at (x, y) with n+1
                  -~n, x),     //             if v = -1, w is also incremented
                x              //             actual index ...
              ] = v            //             ... to restore r[x] to v afterwards
        )                      //       end of inner map()
      )                        //     end of outer map()
    :                          //   else (bottom-right cell):
      o = g(-1, W = w, N = n)  //     update (W, N) and use a last recursive call
                               //     with X undefined and Y=-1 to build the output o
)(0, 0, W = ++m[0][0] / 0, 0)  // initial call to g at (0, 0); set the cell at (0, 0)
                               // to 1 and set W to +inf
&& o                           // return o

The purpose of the last recursive call o = g(-1, W = w, N = n) is to create a copy of the current maze where all visited cells are marked with true and all other cells are marked with false.
For this call, it's important to notice that:

because W = w and N = n, the abort test is always false
because Y = -1, the test on m[Y + 1] is always true
because X is undefined, the squared distance is always NaN

Therefore, what is actually done is simply:
m.map((r, y) => r.map((v, x) => v > 0 ? 1 : 0))


Deranged Rearrangements Your task is to write a computer program such that when it is cut up into lines (split on the newline character) every arrangement of the lines will output a different number between 1 and n! (where n is the total number of lines).  No number should be output by two different arrangements and every arrangement should output a number on this range. Since there are n! ways to arrange the lines of a program this means each number should be output by one rearrangement.

For example the python program

print 1;"""
print 2;"""

Has two arrangements

print 1;"""
print 2;"""

and

print 2;"""
print 1;"""

The first outputs 1 and the second outputs 2.

You may use whatever output formats are standard in the language you are using.  You may not assume any sort of boilerplate. I think this challenge is more interesting if you have to work around whatever formats the language insists on.

Scoring

Your score will be the number of lines in your program with a higher score being better.  You may choose to output numbers from 0 to n!-1 if you would like.

CJam, score: ∞

Each line is of the form

];Lx+:L{__(f<0+:+\,,(;1+:**\(;}h]:+

where x is a number from 0 to n-1. The result is in the range 0 to n!-1.

Try it online! (For n=3.)

Credits to jimmy23013 for the code that computes the actual permutation index. I've only replaced the bit that reads the input with ];Lx+:L which discards the result from the previous line and then adds the index of the current line to the variable L (which is initially an empty array).


Find the largest N digit number in a W by H grid of digits Write a program or function that takes in a positive integer \$N\$ and a grid of decimal digits (\$0\$ to \$9\$) with width \$W\$ and height \$H\$ (which are also positive integers). You can assume that \$N\$ will be less than or equal to the larger of \$W\$ and \$H\$ (\$N \le \max(W,H)\$).
Print or return the largest contiguous \$N\$-digit number that appears horizontally or vertically in the grid, written in normal reading order or in reverse.

Diagonal lines of digits are not considered.
The grid does not wrap around, i.e. it does not have
periodic boundary conditions.

For example, the \$3\times3\$ grid
928
313
049

would have 9 as the output for \$N = 1\$, 94 as the output for \$N = 2\$, and 940 as the output for \$N = 3\$.
The \$4\times3\$ grid
7423
1531
6810

would have 8 as the output for \$N = 1\$, 86 for \$N = 2\$, 854 for \$N = 3\$, and 7423 for \$N = 4\$.
The \$3\times3\$ grid
000
010
000

would have output 1 for \$N = 1\$, and 10 for N = 2 and N = 3 (010 is also valid for N = 3).
The \$1\times1\$ grid
0

would have output 0 for \$N = 1\$.
You can take the input in any convenient reasonable format. e.g. the grid could be a newline separated string of digits, or a multidimensional array, or a list of lists of digits, etc. Leading zeros are allowed in the output if they were part of the grid.
This is code-golf, so the shortest code in bytes wins, but I'll also award brownie points (i.e. more likely upvotes) for answers that can show that their algorithm is computationally efficient.

CJam, 39 36 35 34 bytes

qN/)i\[{zW%_}4*]ff{_,@e<ew:i}e_:e>

Just quickly, before @Dennis wakes up :P

Try it online.

Explanation

The basic algorithm is to take all four rotations of the grid and split each row into chunks of length N (or the row length, whichever's smaller). Then convert the chunks to ints and take the largest.

qN/             Split input by newlines, giving an array of lines
)i\             Drop N from the array and put at bottom
[        ]      Wrap in array...
 {    }4*         Perform 4 times...
  zW%_              Rotate grid anticlockwise and push a copy
                Note that this gives an array of 5 grids [CCW1 CCW2 CCW3 CCW4 CCW4]
ff{         }   For each grid row, mapping with N as an extra parameter...
   _,             Push length of row
     @e<          Take min with N
        ew        Split into chunks
          :i      Convert to ints
e_              Flatten that array
:e>             Take cumulative max


Enumerate all binary trees with n nodes Given an integer n, enumerate all possible full binary trees with n internal nodes. (Full binary trees have exactly 2 children on every internal node). The tree structure should be output as a pre-order traversal of the tree with 1 representing an internal node, and 0 representing an external node (Null).

Here are examples for the first few n:

0:
0

1:
100

2:
11000
10100

3:
1110000
1101000
1100100
1011000
1010100

This is a code golf with the prize going to fewest characters. The trees should be output one per line to stdout. The program should read n from the commandline or stdin.

Perl - 125 79 chars

Count includes 4 chars for "-ln" options.  Takes n from stdin.

New constructive approach:

@a=0;map{%a=();map{$a{"$`100$'"}=1while/0/g;}@a;@a=keys%a}1..$_;print for@a

Form the solution for n by substituting a new internal node ("100") for each leaf ("0"), in turn, in each tree from the solution for n-1.

(I owe this concept to other's solutions that use the internal node to leaf [100->0] substitution for verifying sequentially-generated strings, and I believe I saw--after writing my answer based on that concept--this same 0->100 method of construction in someone's intermediate edit.)

Previous recursive approach:

sub t{my$n=shift;if($n){--$n;for$R(0..$n){for$r(t($R)){for$l(t($n-$R)){push@_,"1$l$r"}}}}else{push@_,"0"}@_}print for t$_

Recursive ungolfed:

sub tree {
  my ($n) = @_;
  my @result = ();
  if ( $n ) {
    for $right_count ( 0 .. $n-1 ) {
      for $right ( tree( $right_count ) ) {
        for $left ( tree( ($n-1) - $right_count ) ) {
          push @result, "1$left$right";
        }
      }
    }
  }
  else {
    push @result, "0";
  }
  return @result;
}
foreach $tree ( tree($_) ) {
  print $tree;
}


Build a minimum-clue Sudoku unsolver My attempt at stating this question, but with a more objective solving criterion.

Your task is to build a program or function that takes a solved Sudoku grid S in the format of your choice and attempts to generate a problem grid with as few clues as possible that has S as its unique solution. (It doesn't matter what method S is the unique solution by, including brute force, as long as the solution is provably unique.)

Your program will be scored by running it through a set of 100,000 solution grids found in this file (7.82 MB download), and adding up the number of clues in all 100,000 problem grids that your solution produces.

The Sudoku solutions in the above test file are expressed as an 81-character string, from left-to-right, then top-to-bottom. The code required to turn the input in the test file into a usable solution will not count towards your solution's byte count.

As in my Flood Paint challenge, your program must actually produce a valid output for all 100,000 puzzles to be considered a valid solution. The program that outputs the fewest total clues for all 100,000 test cases is the winner, with shorter code breaking a tie.

Current scoreboard:

2,361,024 - nutki, C
2,580,210 - es1024, PHP
6,000,000 - CarpetPython, Python 2
7,200,000 - Joe Z., Python

C - 2,361,024 2,509,949 clues

Remove clues starting from the last cell if a brute force solver finds only one unique solution.

Second try: use heuristic to decide in which order to remove clues instead of starting from the last. This makes the code run much slower (20 minutes instead of 2 to calculate the result). I could make the solver faster, to experiment with different heuristics, but for now it will do.

#include <stdio.h>
#include <string.h>
char ll[100];
short b[81];
char m[81];
char idx[81][24];
int s;
char lg[513];
void pri2() {
    int i;
    for(i=0;i<81;i++) putchar(lg[b[i]]);
    putchar('\n');
}
void solve(pos){
int i,p;
if (s > 1) return;
if (pos == 81) { s++; return; }
if (b[pos]) return solve(pos+1);
for (p=i=0;i<24;i++) p |= b[idx[pos][i]];
for (i = 0; i < 9; i++) if (!(p&(1<<i))) {
    b[pos] = 1 << i;
    solve(pos + 1);
}
b[pos] = 0;
}
int main() {
    int i,j,t;
    for(i=0;i<9;i++) lg[1<<i]='1'+i;
    lg[0] = '.';
    for(i=0;i<81;i++) {
    t = 0;
    for(j=0;j<9;j++) if(i/9*9 + j != i) idx[i][t++] = i/9*9 + j;
    for(j=0;j<9;j++) if(i%9 + j*9 != i) idx[i][t++] = i%9 + j*9;
    for(j=0;j<81;j++) if(j/27 == i/27 && i%9/3 == j%9/3 && i!=j) idx[i][t++] = j;
    }
    while(scanf("%s ",ll)>0) {
    memset(m, 0, sizeof(m));
    for(i=0;i<81;i++) b[i] = 1 << (ll[i]-'1');
    for(i=0;i<81;i++) {
    int j,k,l = 99;
    for(k=0;k<81;k++) if (m[k] <= l) l = m[k], j = k;
    m[j] = 24;
    t = b[j]; b[j] = 0;
    s = 0; solve(0);
    if (s > 1) b[j] = t;
    else for(k=0;k<24;k++) m[idx[j][k]]++;
    }
    pri2();
    }
    return 0;
}


Matrix trace for any matrix through... Bresenham’s line rasterisation Inspired by this.

Agatha Stephendale, a sophomore who is really into raster graphics, has taken a course in linear algebra. Now she imagines matrices as rectangles, but in her artistic mind, she attaches diagonal lines to those rectangles and tries to compute traces along them. In fact, she wants to compute traces of all matrices, not just square ones.

Since Agatha is an artist, she knows how to draw lines in her favourite image editor, and the latter uses Bresenham’s algorithm to plot lines. She even checked Wikipedia and found the pseudocode:

 function line(x0, y0, x1, y1)
     real deltax := x1 - x0
     real deltay := y1 - y0
     real deltaerr := abs(deltay / deltax)    // Assume deltax != 0 (line is not vertical),
           // note that this division needs to be done in a way that preserves the fractional part
     real error := 0.0 // No error at start
     int y := y0
     for x from x0 to x1
         plot(x,y)
         error := error + deltaerr
         while error ≥ 0.5 then
             y := y + sign(deltay) * 1
             error := error - 1.0

(Note that this pseudocode works only for slopes less than 1; for tall grids, a similar treatment should be done, but with a loop over y. See this section for the two cases.)

Agatha imagines a matrix as a rectangle, draws a diagonal line in it, and Bresenham’s algorithm determines which elements of a matrix belong to the diagonal. Then she takes their sum, and this is what she wants to implement in as few bytes as possible because she is a poor student and cannot afford large-capacity HDDs to store her code.

Task

Given a matrix A, return the sum of the elements that lie on the rasterised main diagonal (from top left to bottom right), where the latter is determined by Bresenham’s line algorithm. That is, assuming that the matrix represents a m×n grid, draw a line on that grid from A[1, 1] to A[m, n] using Bresenham’s algorithm, and take the sum of all elements on the line. Note that for 1×N and N×1 matrices, the entire matrix becomes its own diagonal (because this is how one would draw a line from the first element of the first row to the last element of the last row).

Input: a real matrix (may be a 1×1 matrix, a row matrix, a column matrix, or a rectangular matrix).
Output: a number.

Note that some sources (e. g. the Wikipedia’s pseudocode above) use the condition check error≥0.5, while other sources use error>0.5. You should use the originally posted one (error≥0.5), but if the alternative error>0.5 is shorter in your code, then you are allowed to implement it (since this is code golf), but mention it explicitly. See test case 4.

Challenge rules

I/O formats are flexible. A matrix can be several lines of space-delimited numbers separated by newlines, or an array of row vectors, or an array of column vectors etc.
This is code-golf, so shortest answer in bytes wins.
Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs.
Default loopholes are forbidden.

Test cases

[[1,2,3],[4,5,6],[7,8,9]] → 1+5+9 → output: 15.

[[1,2,3,4],[5,6,7,8]] → 1+2+7+8 → output: 18.

[[1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16,17,18],[19,20,21,22,23,24]] → 1+8+9+16+17+24 → output: 75.

[[1,2,3,4,5],[6,7,8,9,10]] → 1+2+8+9+10 (using the ≥ error condition) → output: 30.

However, if it would be shorter to use the strict inequality > in your code, then the allowed output is 1+2+3+9+10=25, but you should mention it separately.

[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] → 1+5+8+12 → output: 26.

[[-0.3,0.5]] → output: 0.2.
[[3.1],[2.9]] → output: 6.
[[-5]] → output: -5.

More information on Bresenham’s algorithm

http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm — a collection of algorithms for different languages;
https://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html — a nice explanation featuring different cases for slopes;
https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm;

Jelly, 25 bytes

ZXL>LƲ¡µLḶ÷’Ɗ×XL’Ɗær0ị"OS

Try it online!


Unscramble the letters by letter frequency analysis You know those riddles where every letter is swapped for another letter?
E.g. you get a text like
JME JG EPP IFAPE EPJE CJPPPC BP,
      UIJCG JC EPP EFE GPJB EJIP EJ EJIP,
F EPJIG MPJEPPPP AJUC BJL UP
      GJP BL MICJIJMPPJUIP CJMI.

and are supposed to find out that it stands for
OUT OF THE NIGHT THAT COVERS ME,
      BLACK AS THE PIT FROM POLE TO POLE,
I THANK WHATEVER GODS MAY BE
      FOR MY UNCONQUERABLE SOUL.

This example was created by the following replacement matrix:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ODSXHKARFYGNBIQTJVCEWZMULP

Try to unscramble any given text by doing a letter frequency analysis. Assume that the most common letters in the given input are (left to right):
EARIOTNSLCUDPMHGBFYWKVXZJQ

Replace the most common letter in the input by E, the next most common by A, and so on
Producing a correctly unscrambled text is actually outside the scope of this challenge. That is, we assume that you get a correct result if only the input is large enough. (Testcase 1)
If there is insufficient data, your return value must be consistent with the data provided. (Testcase 2)
You may expect uppercase text only. It can contain digits, punctuations etc., which are not scrambled and to be output as is.

This is a code golf, shortest answer in bytes wins. Standard loopholes apply.
Testcase 1 - The shortest completely solvable one
CCCCCCCCCCCCCCCCCCCCCCCCCCPPPPPPPPPPPPPPPPPPPPPPPPPIIIIIIIIIIIIIIIIIIIIIIIIFFFFFFFFFFFFFFFFFFFFFFFEEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPPPPFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGEEEEEEEEEEEEEEEEEIIIIIIIIIIIIIIIITTTTTTTTTTTTTTTMMMMMMMMMMMMMMJJJJJJJJJJJJJAAAAAAAAAAAAAAAAAAAAAAAWWWWWWWWWWDDDDDDDDDBBBBBBBBBBBBBBBFFFFFFTTTTTJJJJWWWIIP

must output
EEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRRRRRIIIIIIIIIIIIIIIIIIIIIIIOOOOOOOOOOOOOOOOOOOOOOTTTTTTTTTTTTTTTTTTTTTNNNNNNNNNNNNNNNNNNNNSSSSSSSSSSSSSSSSSSSLLLLLLLLLLLLLLLLLLCCCCCCCCCCCCCCCCCUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDPPPPPPPPPPPPPPMMMMMMMMMMMMMHHHHHHHHHHHHGGGGGGGGGGGBBBBBBBBBBFFFFFFFFFYYYYYYYYWWWWWWWKKKKKKVVVVVXXXXZZZJJQ

Testcase 2
HALLO WORLD must output ??EEA<space>?A?E?:

The 3 Ls turn into E
The 2 Os turn into A
The remaining letters are each replaced by an undefined permutation of the letters "RIOTN", without any of these repeating.

JavaScript (V8), 185 bytes

c=>(l={},[...c].map(i=>l[i]=(l[i]|0)+1),e=Object.entries(l).sort((a,b)=>b[1]-a[1]).map(i=>i[0]).filter(i=>parseInt(i,36)>9),[...c].map(i=>"EARIOTNSLCUDPMHGBFYWKVXZJQ"[e.indexOf(i)]||i))

Try it online!
Doesn't currently pass the second test case, but instead is based on OP's description of how the unscrambling works. The test case seems to be incorrect at the moment, as some groups of letters (like F or P) repeat letters.
Explanation:
c=>(                            // Define arrow function with argument c
l={},                           // Create an empty object l
[...c].map(i=>                  // For each character i in c...
  l[i]=(l[i]|0)+1),               // Increment l[i] (the number of times i appears)
e=Object.entries(l)             // Format l as an array ["x", <number of times "x" appears>] in variable e
.sort((a,b)=>b[1]-a[1])         // Sort e so most common characters are first
.map(i=>i[0])                   // Get rid of number of times appeared
.filter(i=>parseInt(i,36)>9),   // Filter out non-letters using base 36 conversion :)
[...c].map(i=>                  // For each character i in c...
  "EARIOTNSLCUDPMHGBFYWKVXZJQ"[   // Get the nth item from the frequency chart...
    e.indexOf(i)]                   // Where n is the index of i in e
    ||i))                         // Unless it isn't a letter, where i stays i


Downgoat-ify Animals! My Downgoat avatar has several distinct features

These features can however also apply to any other animal.

Specification

Given an image of an animal (technically can be anything), you must apply the Downgoat properties to it.

Border pixels are the outer most pixels of the image.

The background color is defined as the most common color in the border pixels. When that color is interpreted as an (r, g, b, a) color, with each channel from [0, 256), the background is defined as the area where the every channel of the given pixels' is within 50 of the "background color".

The process:

Setting the background and all transparent pixels to #232323, RGBA(35, 35, 35, 1.00)
Set all pixels which aren't the background to #FC0D1B, RGBA(252, 13, 27, 1.00).
Vertically reflect the image
Add the text -1 in Arial font, in the center of the image. The total height of the text should be 25% of the image's smallest dimension (i.e. min(width, height) * 0.25).

Rules

Feel free to assume the fonts are already installed
Your threshold is supposed to be 50, however you can take this number as input too. You do not get any decreased byte count anything for doing this however
Refer to our image I/O defaults for any questions related to I/O formats.
Image will always be at least 3x3 in size
If there is no most common "border pixel color", it doesn't matter which border pixel color you use as the "background color", this however must be consistent.

Examples

Input:

Output:

Input:

Output:

Input:

Output:

Input:

Output:

Input:

Output:

More examples?

An online implementation is available here: vihan.org/p/downgoatify/#50

This is code-golf so shortest code in bytes wins. Good luck!

C, 32-bit Windows, 987 bytes

#include <windows.h>
#define A CreateCompatibleDC(c)
#define F z=GetPixel(d,x,y);r=z;g=z>>8;b=z>>16
#define C(X,Y) (X<0||Y<0||X>=s[2]||Y>=s[3]||!GetPixel(e,X,Y))
#define D ((C(x-1,y)||C(x+1,y)||C(x,y-1)||C(x,y+1))&&!C(x,y))
#define E(X,Y) ((Z+X-Y)*(Z+X-Y)<2501)
main(int a,int*n){HDC c,d,e,f,w;int x,y,s[9],z,*o,m,t,Z;unsigned char r,g,b,R,G,B;c=GetDC(w=GetDesktopWindow());d=A;e=A;SelectObject(d,f=LoadImage(0,n[1],0,0,0,16));SelectObject(e,LoadImage(0,n[2],0,0,0,16));GetObject(f,24,s+1);o=LocalAlloc(64/*Fixed,ZeroInit*/,8*s[2]*s[3]);for(x=t=Z=s[1]=s[0]=0;x<s[2];x++)for(y=0;y<s[3];y++)if D{F;for(m=0;m<t&&o[m]!=z;m+=2);o[m]=z;o[m+1]++;t+=2*(m>=t);}for(x=y=1;x<t;x+=2)if(o[x]>o[y])y=x;z=o[y-1];R=z;G=z>>8;B=z>>16;for(x=0;x<s[2];x++)for(y=0;y<s[3];y++){F;SetPixel(c,x,s[3]-y-1,(C(x,y)||(E(r,R)&&E(g,G)&&E(b,B)))?0x232323:0x1B0DFC);}SelectObject(c,CreateFont(-(s[2]>>2),0,0,0,400,0,0,0,0,0,0,0,0,"Arial"));SetBkMode(c,1);SetTextColor(c,0xFFFFFF);DrawText(c,"-1",2,s,37);ReleaseDC(w,c);}

The file is saved with LF as line end, not with CR+LF to save some bytes.
The program is written in a way that compiler warnings are generated to save some more bytes.
The file will probably not compile as 64-bit program because the array "s[]" is used to do some implicit castings...
The program takes two images (file names are given via command line):

The first image (first command line argument) is the R/G/B image in Windows .BMP format
The second image is the Alpha channel (black means: 0%, any other colour means: not 0%); the file is also in .BMP format and must have the same size or be larger than the first image

The output image is displayed in the left upper corner of the screen
I couldn't reproduce the boy with the yellow hair. Yellow seems to be too far away (> 50) from white!

Ungolfed version:

#include <windows.h>

/*
 * Although this line costs us 32 bytes
 * Replacing "CreateCompatibleDC(c)" we'll
 * save 42 bytes in the golfed version later
 * so we save 10 bytes using this define!
 */
#define A CreateCompatibleDC(c)

/*
 * Macro: Get a pixel value at (x,y) to z
 * Also get r, g, b
 */
#define F z=GetPixel(d,x,y); \
    r=z; \
    g=z>>8; \
    b=z>>16

/*
 * Macro checking if a pixel is a
 * transparent colour or lies outside the
 * image
 */
#define C(X,Y) (X<0 || Y<0 || X>=s[2] || Y>=s[3] || !GetPixel(e,X,Y))

/*
 * Macro checking if a pixel at (x,y) is a border pixel
 */
#define D ((C(x-1,y) || C(x+1,y) || C(x,y-1) || C(x,y+1)) && !C(x,y))

/*
 * Macro checking if the difference between X and Y is less than 50
 * The variable "Z" must be type "int" and zero. It is used to
 * perform an implicit cast from "BYTE" to "int".
 */
#define E(X,Y) ((Z+X-Y)*(Z+X-Y)<2501)

/*
 * Note that the second argument is "char **",
 * not "int *".
 * We ignore resulting compiler warnings...
 */
main(int a, int * n)
{
    HDC c, d, e, f, w;
    int x, y, s[9], z, *o, m, t, Z;
    unsigned char r, g, b, R, G, B;

    /*
     * Get the HDC handle to the
     * screen (allowing us to create HDCs
     * for accessing bitmap files as well as
     * drawing directly to the screen!)
     */
    c=GetDC(w=GetDesktopWindow());
    /*
     * Create two virtual HDCs for accessing
     * the bitmap files.
     */
    d=A; /* Macro */
    e=A; /* Macro */
    /*
     * Load the two images:
     * The first argument is the image file with
     * the R/G/B channel
     * The second argument is the image file
     * containing the mask defined by the Alpha
     * channel:
     *   Black means = Alpha=0
     *   White means = Alpha>0
     *   (Any other colour means: Alpha>0)
     *
     * Note that "f" is of the type "HBITMAP",
     * not "HDC". We save 4 bytes in the golfed
     * version using HDC instead of HBITMAP and
     * compile the C file with compiler warnings
     * switched off!
     *
     * The second image should have the same size
     * as the first one. However it may be larger
     * than the first one. It must not be smaller!
     */
    SelectObject(d,f=LoadImage(0,n[1],0,0,0,16 /* 16=LR_LOADFROMFILE */));
    SelectObject(e,LoadImage(0,n[2],0,0,0,16));
    /*
     * Get the image information (size)
     */
    GetObject(f,24,s+1);
    /*
     * Search all background colours
     */
    o=LocalAlloc(64 /* Fixed, ZeroInit */,8*s[2]*s[3]);
    for(x=t=Z=s[1]=s[0]=0;x<s[2];x++)
        for(y=0;y<s[3];y++)
            if D
    {
        F; /* Macro */
        for(m=0;m<t && o[m]!=z;m+=2);
        o[m]=z;
        o[m+1]++;
        t+=2*(m>=t);
    }
    /*
     * Search the most common one
     */
    for(x=y=1;x<t;x+=2) if(o[x]>o[y]) y=x;
    z=o[y-1];
    R=z;
    G=z>>8;
    B=z>>16;
    /*
     * Draw the image directly to the screen
     */
    for(x=0;x<s[2];x++)
        for(y=0;y<s[3];y++)
    {
        F; /* Macro */
        /* C and E are macros: */
        SetPixel(c,x,s[3]-y-1,(C(x,y) ||
            (E(r,R) && E(g,G) && E(b,B)))?
            0x232323:0x1B0DFC);
    }
    /*
     * Draw the text over the image
     */
    SelectObject(c,CreateFont(-(s[2]>>2),0,0,0,400,0,0,0,0,0,0,0,0,"Arial"));
    SetBkMode(c,1 /* TRANSPARENT */);
    SetTextColor(c,0xFFFFFF);
    DrawText(c,"-1",2,s,37 /* center, vcenter, singleline */);
    /*
     * Unfortunately DrawText() won't work
     * when not doing this!
     */
    ReleaseDC(w,c);
}


Perfect, Germain, Vampire, Mersenne! (Don't forget narcissistic) Six is a number perfect in itself, and not because God created all things in six days; rather, the converse is true. God created all things in six days because the number six is perfect.

I am fascinated by numbers. As were Sophie Germain and Marin Mersenne. To be more specific, these two were fascinated by primes: a number with only two integer divisors: itself and 1. In fact, they were so fascinated by primes that classes of primes were named after them:
A Mersenne prime is a prime number which can be generated by the formula 2p - 1 where p is a prime. For example, 7 = 2^3 - 1 therefore 7 is a Mersenne prime.
A Germain prime is similar. It is a prime number that when plugged into the formula 2p + 1 it also produces a prime. E.g. 11 is Germain as 2*11 + 1 = 23 which is prime.
But now let's move on to the next three numbers: perfect, vampire and narcissistic numbers.
A perfect number is very easy to understand. It can be easily defined as

A number where all its divisors except itself sum to itself. For example, 6 is a perfect number as the divisors of 6 (not including 6) are 1,2,3 which sum to make 6.

A vampire number may be the most difficult to code. A vampire number is a number whose digits can be split into two numbers, of equal length, made from all those digits, that when multiplied, produce the original number. Leading 0s aren't allowed in either of the numbers E.g. 136,948 = 146 x 938
Finally a narcissistic number, probably the hardest to understand. A narcissistic number is a number in which the individual digits, raised to the power of the total number of digits sum to make the original number. A single digit number has to be narcissistic.
For example, 8,208 is narcissistic:
84 + 24 + 04 + 84 = 4,096 + 16 + 0 + 4,096 = 8,208
Your task is to create a program that will take an integer and return what category it fits into. The categories are Mersenne, Germain, Perfect, Vampire, Narcissistic and False. Every number that doesn't fit into the first five categories is False. False doesn't have to necessarily be a falsy value.
If a value fits in more than one category, e.g. 3, you may output any correct result.
Output can be in any form, for example, 6 different numbers, as long as you say what it is in your answer.
Even if it is shorter, you aren't allowed to hard code each number as that ruins maths.
This is a code-golf so shortest code wins!
Examples
Input -> Output

10 -> False
7 -> Mersenne
8208 -> Narcissistic
28 -> Perfect
153 -> Narcissistic
2 -> Germain
17 -> False
16,758,243,290,880 -> Vampire
31 -> Mersenne
33,550,336 -> Perfect
173 -> Germain
136,948 -> Vampire

Pyth, 71 bytes

x[.EmqQ*shdsed.cs.pM.cK`Q/lK2 2qsP{*MyPQQ&P_hyQP_Q<.&QhQP_QqQsm^sdlKK)1

Try it here! or Verify the test cases.

Alternative solution, 71  bytes:

x[.EmqQ*shdsed.cs.pM.cK`Q/lK2 2qsP{*MyPQQ&P_hyQP_Q&.AjQ2P_QqQsm^sdlKK)1

Try it here! or Verify the test cases.

This returns -1 for False, 0 for Vampire, 1 for Perfect, 2 for Sophie Germain, 3 for Mersenne and 4 for Narcissistic. In case more are truthy, this picks the one with the lowest index. Unfortunately, this memory errors for the following test cases: 33550336, 16758243290880.

Explanation

Vampire (29 bytes)

.EmqQ*shdsed.cs.pM.cK`Q/lK2 2

                  .c `Q/lK2      Get all combinations of the input's digits of half its length.
                .pM              Get all possible permutations of each.
             .cs            2    Get all possible two-number combinations, flattened.
.EmqQ*shdsed                     Check if any has the product equal to the input.

Let's go through an example. Let's assume our input is 1260.

First of all, we get the all the possible combinations of 2 digits (number_of_digits / 2). We get ['12', '16', '10', '26', '20', '60'].
Then, we get the possible permutations of each, [['12', '21'], ['16', '61'], ['10', '01'], ['26', '62'], ['20', '02'], ['60', '06']].
We flatten that (['12', '21', '16', '61', '10', '01', '26', '62', '20', '02', '60', '06']) and get all the possible 2-element combinations. This list is quite long:

[['12', '21'], ['12', '16'], ['12', '61'], ['12', '10'], ['12', '01'], ['12', '26'], ['12', '62'], ['12', '20'], ['12', '02'], ['12', '60'], ['12', '06'], ['21', '16'], ['21', '61'], ['21', '10'], ['21', '01'], ['21', '26'], ['21', '62'], ['21', '20'], ['21', '02'], ['21', '60'], ['21', '06'], ['16', '61'], ['16', '10'], ['16', '01'], ['16', '26'], ['16', '62'], ['16', '20'], ['16', '02'], ['16', '60'], ['16', '06'], ['61', '10'], ['61', '01'], ['61', '26'], ['61', '62'], ['61', '20'], ['61', '02'], ['61', '60'], ['61', '06'], ['10', '01'], ['10', '26'], ['10', '62'], ['10', '20'], ['10', '02'], ['10', '60'], ['10', '06'], ['01', '26'], ['01', '62'], ['01', '20'], ['01', '02'], ['01', '60'], ['01', '06'], ['26', '62'], ['26', '20'], ['26', '02'], ['26', '60'], ['26', '06'], ['62', '20'], ['62', '02'], ['62', '60'], ['62', '06'], ['20', '02'], ['20', '60'], ['20', '06'], ['02', '60'], ['02', '06'], ['60', '06']]

The next step is getting the product of each pair:

[252, 192, 732, 120, 12, 312, 744, 240, 24, 720, 72, 336, 1281, 210, 21, 546, 1302, 420, 42, 1260, 126, 976, 160, 16, 416, 992, 320, 32, 960, 96, 610, 61, 1586, 3782, 1220, 122, 3660, 366, 10, 260, 620, 200, 20, 600, 60, 26, 62, 20, 2, 60, 6, 1612, 520, 52, 1560, 156, 1240, 124, 3720, 372, 40, 1200, 120, 120, 12, 360]

And then compare to the input:

[False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]

Finally, the last step is checking if any value is truthy. And there is one (at index 19 into the list). Hence, this returns a truthy value for 1260, thanks to the pair [21, 60].

Perfect (10 bytes)

qsP{*MyPQQ

q        Q   Is equal to the input?
 s           Sum.
   {*MyPQ    Its divisors.
  P          Popped (since we want the proper divisors).

Sophie Germain (9 bytes)

&P_hyQP_Q

      P_Q    Is the input prime?
 P_hy        Is the input doubled + 1 prime?
&            Logical AND.

Mersenne (9 bytes)

<.&QhQP_Q

<             Is smaller?
 .&             Bitwise AND between:
   Q              The input
    hQ             And the input + 1
              than:
      P_Q       Is the input prime?

This tests if the input + 1 is a power of two (i.e. if it is a Mersenne number), and then performs the primality test. In Python, bool is a subclass of int, so truthy is treated as 1 and falsy is treated as 0. To avoid checking explicitly that one is 0 and the other is 1, we compare their values using < (since we only have 1 such case).

In the alternative approach, this part is changed to &.AjQ2P_Q. This works as follows:

&.AjQ2P_Q

   jQ2      The input in binary as a list of digits.
 .A         Are all truthy (i.e equal to 1)?
&     P_Q   ... And is prime?

This uses the fact that any number of the form 2n - 1 only consists of 1 when written in binary, and also checks if it is prime.

Narcissistic (10 bytes)

qQsm^sdlKK

q            Is equal?
 Q           The Input
   m     K   Map over the string representation of the input.
    ^sdlK    Raise each digit to the power of the number of digits the input has.
  s          Summed.

When it comes to the rest of the code, [...) builds a list of bool values and x[...)1 gets the index of the first truthy element.


Generate a Graeco-Latin square disclaimer: I'm not aware of any non-bruteforce solutions
A Graeco-Latin square is, for two sets of same length \$n\$, a \$n \times n\$ arrangement of cells, each containing a unique (across the entire square) pair of a element of the first set and a element of the second set, such that all first elements and all second elements of the pairs are unique in their row and column. The most common sets used are, as one could guess, the first \$n\$ letters of the Greek and the Latin alphabets.
Here is a picture of a 4x4 Graeco-Latin square:
Graeco-Latin squares are as useful as they sound (the Wikipedia article mentions "design of experiments, tournament scheduling and constructing magic squares"). Your task is, given a positive integer \$n\$, to generate a \$n\times n\$ Graeco-Latin square.
Input
A positive integer \$n > 2\$; it is guaranteed that a \$n\times n\$ Graeco-Latin square exists (that is, \$n \ne 6\$).
Output
A Graeco-Latin square with side length n as a two-dimensional array, a array of arrays, a flattened array or outputted directly.
Notes

You do not have to use the Greek and Latin alphabets specifically; for example, outputting pairs of positive integers is allowed as well.
If you choose to use a alphabet that can't be extended arbitrarily, you have to (theoretically; your code doesn't have to finish before the heat death of the universe) support a maximal side length of at least 20.

This is code-golf, so the shortest code wins!

05AB1E, 26 23 22 bytes

-3 bytes thanks to Emigna

-1 byte thanks to Kevin Cruijssen

Lãœ.ΔIôDζ«D€í«ε€нÙgQ}P

Try it online!


Where should I put my mirror? This is a mirror: |. I just found out that you can stick a mirror in the middle of a string if the string can be mirrored on itself! For example, the string abccba. If you cut it in half the two halves are mirror images of each other:
abc  <-->  cba

So, we can stick a mirror in the middle of the string, and our new string is abc|cba. Sometimes, only part of the string can be mirrored on itself. For example, the string "mirror". The two r's are mirrored, but the rest of the string isn't. That's OK, we'll just remove the parts of the string that don't mirror each other, and we get the following string:
r|r

Some strings could be mirrored in multiple places. For example, "Hello World, xyzzyx". I like having a lot of text reflected in my mirror, so you need to find the best place to put my mirror. In this case, you should output the longer mirrored string and just like our last example, remove everything else. This string becomes:
xyz|zyx

Some strings look like they can be mirrored, but actually can not. If a string cannot be mirrored anywhere, you should output nothing.
The challenge:
Given a string containing only printable-ascii, find the best place to put my mirror. In other words,

Find the largest even-length palindromic substring, then output it with a pipe character '|' in the middle of it.

The input will be 1-50 characters long.
You can assume that the input will not contain mirrors | or newlines. Beyond that, all printable-ascii characters are fair game. If the longest mirrored substring is tied between two substrings, you can choose which one to output. For example, for the string "abba ollo", you must output "ab|ba" or "ol|lo", but it doesn't matter which one you output. Strings are case-sensitive, e.g. "ABba" should not output "AB|ba", it should output the empty string.
Sample IO:
"Hello World"     --> "l|l"
"Programming Puzzles and Code-Golf"     --> Either "m|m" or "z|z"
"abcba"           --> ""
"Hulluh"          --> "ul|lu"
"abcdefggfedcba"  --> "abcdefg|gfedcba"
"abcdefggfabc"    --> "fg|gf"
"AbbA"            --> "Ab|bA"
"This input is a lot like the last one, but with more characters that don't change the output. AbbA" --> "Ab|bA"

As usual, this is code-golf, so standard loopholes apply, and the shortest answer in bytes wins!

Pyth - 19 17 15 13 bytes
Thanks to @FryAmTheEggman for saving me two bytes.
ARRGH the special case for no answer. Solved that!
e_I#jL\|cL2.:

Test Suite.
e                Last element in list, this works out to longest one
  _I             Invariance under reverse, this detect palindrome
   #             Filter
   jL            Map join
    \|           By "|"
    cL2          Map chop in two pieces
     .:Q)        Substrings. Implicit Q). ) makes it do all substrings.


Play tic-tac-toe and never lose (There exists some challenges that require to use the best strategy, but here we don't. Even if you are able to win, you are allowed to make a tie)

Challenge

Write a program which plays the game tic-tac-toe. It must not lose (therefore, it should end the game either with a tie or by winning).

Allowed I/O methods

Input may be the current board. You can assume that all previous moves of the 2nd player were played by your engine.
Input may be the first player's moves, and your function stores which moves happened in the past. In this case the function is called multiple times, once for each move; or the function/program prompt input for multiple times.
You are allowed to take an extra input saying if you are the first player, or write two (possibly related) functions to solve the first-player problem and the second-player one. If your program need use the input method 2 (multiple call), you can decide what is passed in the first call.
Output may be the board after your turn.
Output may be your move.
A move may be represented as a pair of numbers (can be 0-indexing or 1-indexing), a number in range 0~8, or a number in range 1~9.
The board may be represented as a 3×3 array, or an array of length 9. Even if the language have 0-indexing array, you can use 1-indexing.
The cells on the grid may use any 3 different values to indicate X, O and empty.

Winning criteria

Shortest code in each language win.

Befunge, 181 168 bytes
>>4&5pp20555>>03>16p\::5g8%6p5v
 ^p5.:g605$_ #!<^_|#:-1g61+%8g<
543217539511|:_^#->#g0<>8+00p3+5%09638527419876
v<304p$_v#:->#$$:2`#3_:^
>#\3#13#<111v124236478689189378

Positions on the board are numbered 1 to 9. By default you get the first move, but if you want to allow the computer to go first, you can just enter 0 for your first move. When you've made a move, the computer will respond with a number indicating their move.
There are no checks to make sure you don't enter a valid move, and there also no checks to see if anyone has won or lost. Once their are no more moves to be made, the program just goes into an infinite loop.
It's a bit difficult to test this online, since there are no online interpreters with interactive input. However, if you know what moves you're going to make in advance (which assumes you know how the computer is going to respond), you can kind of test on TIO with those moves preprogrammed.
User plays first: Try it online!
Computer plays first: Try it online!
To makes it easier to see what's going on, I've also got a version that outputs the board between moves.
User plays first: Try it online!
Computer plays first: Try it online!
Note that you'll have to wait for TIO to timeout before you can see the results.
Explanation
The board is stored in the Befunge memory area as a flat array of 9 values, indexed from 1 to 9. This lets us use the zero offset as a special case "no move" when we want to let the computer play first. Player moves are stored as 4, and computer moves as 5. To start with all positions are initialised to 32 (the Befunge memory default), so whenever we access the board we mod with 8, so we'll get back either 0, 4 or 5.
Given that arrangement, if we sum the values of any three positions on the board, we know that the computer is one move away from winning if the total is 10, the player is one move away from winning if the total is 8, and the positions are shared between computer and player (but still one position is free) if the total is 9.
Our entire strategy is based around this concept. We have a routine that takes a list of triples indicating sets of three positions on the board, we calculate the sum of those positions, and if the sum equals a certain total, the computer moves to whichever of the positions in the set is free.
The main list of triples that we test are the winning combinations (1/2/3, 1/5/9, 1/4/7, etc.). We first look for a total of 10 (the computer is about to win), and then a total of 8 (the player is about to win and we need to block that move). Less obviously, we also check for a total of 9 (if the player and computer each have one of the positions, it's a good strategy for the computer to take the third).
Prior to that last scenario, the other strategic move we make is to check all the corner sets (1/2/4, 2/3/6, etc.) as well as two opposing corner combinations (1/8/9 and 3/7/8). If any of these combinations sum to 8, i.e. the player has taken two of the positions, it's a good strategy for the computer to take the remaining free position.
Finally, there are a two special case moves. First, we always try and take the center position before any other move. This is achieved with the same routine as all our other moves, just passing in a single triple, 5/5/5, and a target sum of 0. Additionally, if all other test have failed to find a move, we try to take one of the top corners as a last resort. Again this is simply achieved by testing the triples 1/1/1 and 3/3/3, with a target sum of 0.
I don't think this is necessarily a perfect strategy - there may be games that the computer draws which could potentially have been won - but it's good enough to never lose a match. I've run a test script that tried to play every possible move against the computer, and for every valid sequence of moves, the computer either won or drew the game.


An Array of Challenges #3: Moving Averages Note: This is #3 in a series of array-manipulation challenges. For the previous challenge, click here.

Moving Average of a List

  The moving average of a list is a calculation resulting in a new, smoothed out list, created by averaging small overlapping sublists of the original.

When creating a moving average, we first generate the list of overlapping sublists using a certain 'window size', shifting this window to the right once each time.

For example, given the list [8, 4, 6, 2, 2, 4] and the window size 3, the sublists would be:

[8,  4,  6,  2,  2,  4]          Sublists:
(         )                  <-  [8, 4, 6]
    (         )              <-  [4, 6, 2]
        (         )          <-  [6, 2, 2]
            (         )      <-  [2, 2, 4]

We then calculate the mean average of each sublist to obtain the result: [6.0, 4.0, 3.3, 2.7] (each value rounded to one decimal place).

The Challenge

Your task is to write a program or function which, given a list L, and an integer 1 ≤ n ≤ length(L), calculate the moving average for L using the window size n.

Rules:

Your program may use integer division or float division. In the case of float division, small inaccuracies due to the data type's limitations are permitted, as long as the value is otherwise correct.
You may submit a full program, or a function (but not a snippet).
You may assume that the list will only contain positive integers.
Standard loopholes are forbidden.
This is code-golf, so the shortest answer (in bytes) wins!

Test Cases

Note that, for ease of readability, all values are rounded to one decimal place.

n=5, [1, 2, 3, 4, 5, 6, 7, 8]      ->      [3, 4, 5, 6]
n=3, [100, 502, 350, 223, 195]     ->      [317.3, 358.3, 256]
n=1, [10, 10, 10]                  ->      [10, 10, 10]
n=3, [10, 20, 30]                  ->      [20]
n=2, [90, 40, 45, 100, 101]        ->      [65, 42.5, 72.5, 100.5]

Dyalog APL, 4 bytes

1 byte saved thanks to @Graham

2 bytes saved thanks to @jimmy23013

Did I mention APL is not a golfing language?

⊢+/÷

with n on the right, or

+/÷⊣

with L on the right.

Try it online!

How?

÷ - divide L by n

⊢+/ - reduce + on windows of n


Find a sequence in the binary digits of π Given a binary sequence of finite length, find the starting position where this sequence first appears in the binary digits of π (after the decimal). You can assume that an answer exists for any input sequence.
The binary digits of π start with
11.001001000011111101101010100010001000010110100011...

and digits will be counted such that the first one after the decimal (the first 0 digit) has index 1.
Examples
The requested function is related to OEIS A178707 but differs in that input sequences may have leading zeros. OEIS A178708 and OEIS A178709 provide good test cases for large sequences of 0's and 1's.
Some test cases below 10^9:

00100 → 1
11 → 11
00000000 → 189
11111111 → 645
0101000001101001 → 45038
00000000000000000000 → 726844
11111111111111111111 → 1962901
01000111010011110100110001000110 → 105394114
111111111111111111111111111111 → 207861698
100000000110000001100111100001 → 987654321

Input/output formats
You can use any input and output formats: strings, lists, encoding the binary digits in integers, etc. Just use what is convenient for you.
Limitations
Your program must be able to accept sequences of arbitrary (finite) length if run on an infinite-size computer, and terminate in finite time (assuming that a match always exists, which is what most people seem to believe in 2021 based on the pseudo-randomness of the digits of π).
Scoring
This is code golf, so the shortest program (in bytes or bits/8) wins.

JavaScript (Node.js),  167  165 bytes
This is long and slow ... but it should work for any input in theory.

s=>{for(k=t=1n,l=q=2n,n=0n,r=6n,o='#';!~(i=o.search(s));)n=4n*q+t*~n<r?(o+=n,q+(q+=q)-r)/t-n<<(r+=r+t*n*2n)/r:(q*7n*k+2n-r*++l)/(r=(r-q-q)*l,q*=k++,t*=l++);return i}

Try it online!
This is derived from the C# entry on this Rosetta Code page.
The C# code is derived from Java, which is derived from Icon, which is derived from PicoLisp, which is derived from Haskell, which is based on this paper. :-p


Change the Code, Change the Sequence: Robbers This is a cops-and-robbers challenge. For the cops thread, go here.

This challenge involves two OEIS sequences chosen by the cops -- S1, S2 -- and how well those sequences can be golfed and obfuscated.

The cops are constructing code A that produces S1 and giving a number X that they claim is the best Levenshtein distance possible (in characters) to create B that produces S2.

The Robbers' Challenge

To crack a particular cop's submission, robbers must come up with a program C in the same language (and version) as that answer that produces S2(n) and is Y character changes away from A (with Y <= X). Robbers do not necessarily need to find the exact same B code that the cop (secretly) produced. The robbers' submissions must adhere to the same 0-index or 1-index as specified by the cop's submission.

If you manage this, post an answer with the solution, linking to the cop's answer, and leave a comment on the cop's answer linking back to yours.

Each cop answer can only be cracked once, and of course, you're not allowed to crack your own answer. If the cop's answer turns out to be invalid before or after being cracked, it is not counted towards the robber's score.

Winning and Scoring

Robbers are scored by (X - Y)*5 + 5 for each of their cracks, and the robber with the overall highest score wins.

Further Rules

You must not use any built-ins for hashing, encryption, or random number generation (even if you seed the random number generator to a fixed value).
Either programs or functions are allowed, but the code must not be a snippet and you must not assume a REPL environment.
You may take input and give output in any convenient format. The input/output methods must be the same for both sequences.
The definitive calculator for the Levenshtein distance for this challenge is this one on Planet Calc.
In addition to being a CnR challenge, this is code-golf so all usual golfing rules apply.

Pyke, Levenshtein distance of 1, A036487, A135628 - score 5
Crack of an entry by muddyfish
wX*e

Try it here!
The original code, X*e, squares the input, X, multiplies that by the input *, and halves then floors the result, e.
The trick is that 'X' is 56 in the base 96 representation of w, so wX yields 56, multiply that by the input then floor and halve and you get 28 times the input as needed.


Predict whether a message will be starred or not in 50 bytes Given an input of a string consisting of any message from our site
chatroom taken
from the list described and linked below, output either a truthy or a falsy
value attempting to predict whether that message was starred or not in 50 bytes
or less.

You may use any truthy or falsy
values, but they must be
identical (i.e. there should only be two possible outputs, one truthy and one
falsy). The input will be given as raw HTML with newlines removed, and it may
contain non-ASCII Unicode characters. If you require input in something other
than UTF-8, please say so in your answer.

The winning submission to this challenge will be the one that predicts the
highest percentage of chat messages correctly, out of the list linked below. If
two given submissions have the same success rate, the shorter submission will
win.

Please provide instructions for running your code on the entire set of messages
and calculating the percentage correct. Ideally, this should be a bit of
boilerplate code (not counted towards your 50 bytes) that loops through the
positive test cases and outputs how many of them your code got correct and then
does the same for the negative test cases. (The overall score can then be
calculated manually via (correctPositive + correctNegative) / totalMessages.)

So that your code is reasonably testable, it must complete in 5 minutes or less
for the entire list of chat messages on reasonable modern-day hardware.

The full list of chat messages can be found
here, and it
consists of the 1000 latest starred messages as truthy test cases and the 1000
latest unstarred messages as falsy test cases. Note that there are two files in the gist; scroll about halfway down for the unstarred messages.

Retina, 50 bytes, 71.8% 72.15%

^.*([[CE;ಠ-ﭏ]|tar|ol|l.x|eo|a.u|pin|nu|o.f|"$)

Tried some regex golfing at @MartinBüttner's suggestion. This matches 704 starred messages and doesn't match 739 unstarred messages.

The ^.*( ... ) is to make sure that there is always either 0 or 1 match, since Retina outputs the number of matches by default. You can score the program on the input files by prepending m` for multiline mode, then running

Retina stars.retina < starred.txt

and likewise for unstarred.txt.

Analysis / explanation

I generated the above snippets (and many more) using a program, then selected the ones I wanted manually. Here's some intuition as to why the above snippets work:

C: Matches PPCG, @CᴏɴᴏʀO'Bʀɪᴇɴ
E: Matches @ETHproductions, @El'endiaStarman
;: Because the test cases are HTML, this matches &lt; and &gt;
ಠ-ﭏ: Matches a range of Unicode characters, most prominently for ಠ_ಠ and @Doorknob冰
tar: Matches variations of star, @El'endiaStarman (again) and also gravatar which appears in the oneboxes posted by new posts bots
ol: Matches rel="nofollow" which is in a lot of links and oneboxes
l.x: Matches @AlexA., @trichoplax
eo: Mainly matches people, but also three cases for @Geobits
a.u: Mainly matches graduation, status, feature and abuse
pin: Matches ping and words ending in ping. Also matches a few posts in a discussion about pineapple, as an example of overfitting.
nu: Matches a mixed bag of words, the most common of which is number
o.f: Matches golf, conf(irm|use)
"$: Matches a double quote as a last character, e.g. @phase He means "Jenga."

The [ is nothing special - I just had a character left over so I figured I could use it to match one more case.


Tower of hanoi solver For reference as to what the tower of Hanoi is, either Google it or look on the Wikipedia page.

Your code should be able to do 2 things, and they are the following:

Accept user input that specifies the number of discs at the starting point of the Hanoi tower
Create output in a fashion of your choosing (so long as it is somehow logical) to show the solution to the tower puzzle.

An example of logical output would be the following (using a 4 disc start):

L1L2C1L1R-2R-1L1L2C1C-1R-2C1L1L2C1

L represents the left peg, C represents the center peg and R represents the right peg and the numbers are how far to move the disk on that peg and in what direction. Positive numbers represent the number of pegs moving towards the rightmost peg (because the disks start on the leftmost peg).

The rules to tower of Hanoi are simple:

Only one disk may be moved at a time.
Each move consists of taking the upper disk from one of the pegs and sliding it onto another peg, on top of the other disks that may already be present on that peg.
No disk may be placed on top of a smaller disk.

The disks start on the leftmost peg, largest on the bottom, smallest on the top, naturally.

Python, 76 chars

def S(n,a,b):
 if n:S(n-1,a,6-a-b);print n,a,b;S(n-1,6-a-b,b)
S(input(),1,3)

For instance, for N=3 it returns:

1 1 3  (move disk 1 from peg 1 to peg 3)
2 1 2  (move disk 2 from peg 1 to peg 2)
1 3 2  (move disk 1 from peg 3 to peg 2)
3 1 3  ...
1 2 1
2 2 3
1 1 3


Code-Golf: Lights Off! The shortest code to pass all possibilities wins

Many grid based games have been made that start off with a grid of lights that are switched on.  Pressing any of the lights causes that light and the four lights adjacent to it to be toggled.  When a light is toggled, it is turned off or turned on, depending on if it was intially turned on or off.  The goal is to hit the lights in a sequence that results in all of the lights being turned off at the end.

"X" represents lights that are turned on.  "O" represents lights that are turned off.  "P" represents that square that is pressed.

XOO          XOO      XOX      XOX      XXX
XOX          XOP  ->  XXO  ->  OPO  ->  XOX
OOX          OOX      POO      XXO      XOO

Intial Grid  Press 1  Press 2  Press 3  Ending Grid

Input can be taken directly from a file passed as an argument, or as standard input.  The first line of input will contain x (1 <= x <= 20), the size of the grid of lights, meaning x by x.  The second line will contain y (0 <= y <= (x * 3)2), the number of lights initially lit up.  The next y lines contain coordinates of lit up lights on the grid, in the format of "row column".  Lights that are already switched on (have been toggled previously) should be toggled off again.  The next line will contain z, the number of lights pressed.  The final z lines contain coordinates of the pressed lights, in the order that they were pressed, in the format of "row column".

No input will be incorrect.  All numbers will be within the given boundaries of the grid.

The output will be the final grid after all lights have been toggled.  It should be an n by n grid.  For each area that has a light which is on, the uppercase character "X" should be used.  For each area that has a light which is off, the uppercase character "O" should be used.

Lights that are affected that are off the grid should be ignored.  Toggling a light on the edge of a grid should only affect the lights that are on the grid itself.

Test Cases

Input

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

Output

OXOO
XOXO
XOXO
OXOO

Input

1
3
1 1
1 1
1 1
2
1 1
1 1

Output

X

Python, 209 203 199 characters

I=input
x=I()+1
s=0
C=lambda:eval(raw_input().replace(' ','*%d+'%x))
exec's^=1<<C();'*I()
exec's^=1+(7<<x)/2+(1<<x<<x)<<(C()-x);'*I()
R=range(1,x)
for r in R:print''.join('OX'[s>>r*x+c&1]for c in R)

The state of the lights is kept in a single (big) integer variable, s.  XORs with bitmasks are used to toggle the lights.  I keep an extra bit per row to prevent wraparound.


Decompose a number with bit-xor without the digits 0, 3, 7 Challenge

Write a function or program which takes a positive decimal number, call it A, and output two positive numbers, B and C, such that:

A == B bitxor C
B and C must not contain any of the digits 0, 3 or 7 in its decimal representation.

Examples

>>> decompose(3)
1, 2
>>> decompose(7)
1, 6
>>> decompose(718)
121, 695
>>> decompose(99997)
2, 99999
>>> decompose(4294967296)
4294968218, 922
>>> decompose(5296080632396965608312971217160142474083606142654386510789497504098664630388377556711796340247136376)
6291484486961499292662848846261496489294168969458648464915998254691295448225881546425551225669515922,
1191982455588299219648819556299554251659915414942295896926425126251962564256469862862114191986258666

Since the decomposition is not unique, your function/program does not need to output the exact same results as these provided examples.

Very detailed rules

Submissions should be in the form of a complete function or program. import statements do count towards the final score.
You may assume the input A always contains at least a digit of 0, 3 or 7.
You may assume a decomposition always exist.
You may use BigInt if they are part of the standard libraries of the language, or can be installed through the language's de jure package manager.
The function should be fast. It should take no more than 20 seconds to run on reasonably modern computer when fed a 100-digit number, and no more than 2 seconds when fed a 10-digit number.
The function/program should support input up to at least 100 digits.

If the function/program can only support integers up to N<100 digits, there will be a penalty of +10×(100/N - 1) bytes to the final score. This is to encourage golfers to support a wider range of numbers even if importing may be verbose.

There is no restriction on the presentation of input/outputs as long as they are clearly in decimal representation.

The function may input and output strings/BigInts if the built-in integer types are not sufficient.
The input may come from the function parameter, command line argument or STDIN.
The function may return the result, or just print the result directly to STDOUT.
However, signed overflow in the input/outputs are not allowed.
Approximate answers are not tolerated, the input/outputs must be exact.

Scoring

This is a code-golf. Shortest solution in bytes win.

There is a penalty if the program can only support numbers less than 100 digits:

64-bit integers (19 digits) = +42 bytes
63-bit integers (18 digits) = +45 bytes
53-bit integers (15 digits) = +56 bytes
31/32-bit integers (9 digits) = +101 bytes

Common Lisp, 240 224 183 173 169 bytes

Common Lisp is a bit verbose for golfing. However, this decomposes 100-digit numbers in under a second, and 200-digit integers in less than ten seconds, so no need for penalties. The algorithm is deterministic.

(defun s(z)(and #1=(some(lambda(q)(position q(format()"~a"z)))"037")(+ z(floor z(expt 10 #1#)))))
(defun d(x)(do((y x(or(s y)(s #3=(logxor x y))(return`(,y,#3#)))))(())))

The line feed between the functions is for typographic purposes only. Test run with the 100-digit reference input:

(time (d 5296080632396965608312971217160142474083606142654386510789497504098664630388377556711796340247136376))
took 677,000 microseconds (0.677000 seconds) to run.
      20,989 microseconds (0.020989 seconds, 3.10%) of which was spent in GC.
During that period, and with 8 available CPU cores,
     671,875 microseconds (0.671875 seconds) were spent in user mode
           0 microseconds (0.000000 seconds) were spent in system mode
 54,221,104 bytes of memory allocated.
(1864921261592819619661568919418981552559955289196969112566252282429216186594265918444566258544614425
 5891958562486995519825158818455999516899524658151445485616155916296966645869599949958954491929662561)

As a bonus, I'm including a version of the code that incrementally builds the solution top-down. It can manage a 1000-digit number in less than ten seconds, but cannot compete in golf due to the additional code.

(defun decompose (x)
  (flet ((s (z)
           (mapcan #'(lambda (c) (and #1=(position c #2=(format () "~a" z))
                                 (list (- (length #2#) #1# 1))))
                   '(#\0 #\3 #\7))))
    (do ((y x (let ((p (nconc (s y) (s #3=(logxor x y)))))
                (or p (return`(,y,#3#)))
                (+ y (expt 10 (apply #'max p))))))
        (nil))))

* (time (decompose (parse-integer (make-string 1000 :initial-element #\7))))
took 9,226,000 microseconds (9.226000 seconds) to run.
        90,966 microseconds (0.090966 seconds, 0.99%) of which was spent in GC.
During that period, and with 8 available CPU cores,
     9,234,375 microseconds (9.234375 seconds) were spent in user mode
             0 microseconds (0.000000 seconds) were spent in system mode
 487,434,560 bytes of memory allocated.
(8889898889152488921298888992819221914229899249999918899888899888888889999989141219898898888988988898888888888899142442899924898918898898988988895189988898888924192198992454114198911989191888889898888918888988988998888891421118891899122898888998989898888898988898888999988918888898889189918889888888899888989219188898998888988892119889198888988888894888912188898989952999888888888898899998988898889228918998949999998898898991141888898999988912121292118899889998989899999892889941898888911888898889118998898888911889889888891452888998889288921141888888942189888899988891918889118888888888989892198899199914111188988889421111188889118888918989988912989999998989891119888898888888892621229888988888999619888952462219889189899998899888889989898891118989218888888898962988891188899888888888999888888888888888888888891269188921288888888998898899214191188888888898992188998898889919888889989889899988892115549998888898889218899988998911898989199918898918988898888891889888989119899888889888998918889112189998
 4184469818464841952189561886965821566229261221619858498284264289194458622668559698924621446851546256444641488616184155821914881485164244662156846141894655485889656891849662551896595944656451462198891289692696856414192264846811616261884188919426294584158925218559295881946496911489245664261126565546419851585441144861859822815144162828551969425529258169849412525611662488849586554989254181228254465226521648916188265491499166186964881248156451994924294646681548996645996894665198811511522424996844864211629888924642289925565591484541149414914699289441561496451494562955652129199261462268846144518142486845251946444998812988291119592418684842524648484689261441456645518518812265495165189812912919529151991611962525419626921619824496626511954895189658691229655648659252448158451924925658586522262194585891859285841914968868466462442488528641466655911199816288496111884591648442984864269495264612518852292965985888414945855422266658614684922884216851481646226111486498155591649619266595911992489425412191)
* (apply #'logxor *)
7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777


Compute the Redwolf Checksum™ of some data I will preface this by saying that I made this for fun; I have absolutely no formal knowledge on cryptography or error correction. Do not use this algorithm in anything remotely important.
I was kind of bored a few days ago, so I decided to write a simple function to take some data and return an easily memorable (but not necessarily secure :p) checksum of it. The output format is a number of digits in base 36, between 0 and z (think of it like hexadecimal, but with all the letters used).
Your program or function will take two inputs: data, and block_size. The data will be a list of values 0 to 255, and the block_size will be at least 4. It will return a base 36 string (or list of values 0-36) with the length block_size.
Using [182, 109, 211, 144, 65, 109, 105, 135, 151, 233] and 4 as the inputs, this is how you would find the checksum:

The length of the data is padded with zeroes to a multiple of the block_size
182, 109, 211, 144, 65, 109, 105, 135, 151, 233, 0, 0

The data is broken into blocks based on the block_size
182  109  211  144
 65  109  105  135
151  233    0    0

For each item n of the resulting block, take the sum of all items at position n in one of the above blocks mod 256
  182  109  211  144
+  65  109  105  135
+ 151  233    0    0
--------------------
  142  195   60   23

Take the binary representation of each item in the result
10001110
11000011
00111100
00010111

For each item, add the least significant five bits of the next (wrapping) item, and the least significant bit of the (wrapping) item after that (note that this value can be higher than 256)
   10001110   11000011   00111100   00010111
+     00011      11100      10111      01110
+         0          1          0          1
--------------------------------------------
   10010001   11100000   01010011   00100110

Convert back to decimal, and take the mod 36
1, 8, 11, 2

Covert into base 36
18b2

A reference implementation can be found here. Input and output can be in any reasonable manner.
This is code-golf, so shortest in bytes per language wins!
Test cases
[]; 8                           -> 00000000
[0, 1, 2, 3, 4, 5, 6, 7]; 8     -> 14589cd8
[0, 1, 2, 3, 4, 5, 6, 7]; 6     -> eb589b
[0, 4, 2, 1]; 48                -> 473100000000000000000000000000000000000000000000
[195, 180, 1, 0]; 4             -> 0123
[31, 32, 65, 4]; 4              -> wxyz
[20, 8, 247, 41]; 4             -> tw4p
[250, 175, 225, 200]; 4         -> ewhb
[33]; 3                         -> (does not need to be handled)

K (ngn/k), 84 67 bytes
-17 bytes by reshuffling things, inspired by @Neil's comment.
{(,/($!10),`c$97+!26)36!+/256 32 2!'2(,/|0 1_)\+/-1_(0N;y)#x,0,y#0}

Try it online!

+/-1_(0N;y)#x,0,y#0 take the column-wise sum of the input split into y-length chunks (filling with 0s)
2(,/|0 1_)\ build a list containing the original input, it rotated once, and it rotated twice (this uses the do overload of \ scan)
256 32 2!' mod the original input by 256, the rotated-once input by 32, and the rotated-twice input by 2
36!+/ sum column-wise, modding by 36
(,/($!10),`c$97+!26) build list of base-36 characters (digits followed by lower case letters), which is indexed into by the results of the above


Superstitious hotel elevator Description

Here's a very superstitious hotel elevator in Shanghai:

It avoids the number 13, because thirteen is unlucky in the Western world, and it avoids the digit 4, because four is unlucky in parts of Asia. What if this hotel was taller?

Read a positive even integer n from STDIN, representing the number of floors, and print what the button layout would look like to STDOUT: -1, followed by the next n-1 positive integers that aren't equal to 13 and don't contain digit 4. Arrange these numbers in two columns such as in the above image: print two floor numbers per line, separated by a horizontal tab, so that reading the lines in reverse order from left-to-right yields the sequence in ascending order. (You may optionally print a trailing newline character, too.)

Test cases

For the input 14, output should be as in the above image:

15  16
11  12
9   10
7   8
5   6
2   3
-1  1

where the whitespace in each line is a single horizontal tab character.

For the input 2, you should print -1  1.

For the input 100, you should print:

120 121
118 119
116 117
113 115
111 112
109 110
107 108
105 106
102 103
100 101
98  99
96  97
93  95
91  92
89  90
87  88
85  86
82  83
80  81
78  79
76  77
73  75
71  72
69  70
67  68
65  66
62  63
60  61
58  59
56  57
53  55
51  52
39  50
37  38
35  36
32  33
30  31
28  29
26  27
23  25
21  22
19  20
17  18
15  16
11  12
9   10
7   8
5   6
2   3
-1  1

Goal

This is code-golf. Shortest answer in bytes wins.

Bash + common utils, 51

seq 9$1|sed 13d\;/4/d\;1i-1|rs 0 2|sed $[$1/2]q|tac

seq generates ascending integers from 1 to N with an extra 9 digit in front - more than enough for 64bit integer input
sed filters out the unlucky floors and inserts -1 before line 1
rs reshapes into two tab-separated columns
sed stops after N/2 lines
tac reverses output line order


Descending dungeons of positional systems The sequence discussed in this challenge is a variant of the Descending Dungeons sequence family. Specifically, the sequence generation rules:
(A_b = A's base 10 representation read as a base b number, A = A_10)
A(0) = 10
A(n) = 10_(11_(12_(...(n+9)_(n+10))))

Your goal is to make a program which accepts a nonnegative integer n and returns A(n) of the descending dungeons sequence, using 0-indexing.
Base conversion built-ins are allowed.
Return the result itself in base 10.
Test cases: (A = B means input A returns B)
0 = 10
1 = 11
2 = 13
3 = 16
4 = 20
5 = 25
6 = 31
7 = 38
8 = 46
9 = 55
10 = 65
11 = 87
12 = 135
13 = 239
14 = 463
15 = 943
16 = 1967
17 = 4143
18 = 8751
19 = 18479
20 = 38959

Use OEIS A121263 for further test cases.
This is code golf, so the shortest program wins. Have fun.
Final sidenote: This sequence came to my attention through a recent Numberphile video discussing descending dungeon sequences.

Jelly, 9 bytes
Ż+⁵ṚDḅ¥@/

A monadic Link accepting a non-negative integer which yields a non-negative integer.
Try it online! Or see the test-suite.
How?
Ż+⁵ṚDḅ¥@/                  e.g. 5
Ż         - zero-range          [0,1,2,3,4,5]
  ⁵       - ten                 10
 +        - add                 [10,11,12,13,14,15]
   Ṛ      - reverse             [15,14,13,12,11,10]
        / - reduce by:          f(f(f(f(f(15,14),13),12),11),10)
       @  -   using swapped arguments:         e.g. f(y=15,x=14)
      ɗ   -     last two links as a dyad
    D     -       decimal (x)                       [1,4]
     ḅ    -       convert (that) from base (y)      19
                           i.e. f(f(f(f(f(15,14),13),12),11),10)
                              = f(f(f(f(19,13),12),11),10)
                              = f(f(f(22,12),11),10)
                              = f(f(24,11),10)
                              = f(25,10)
                              = 25


Find the nth Aaron number Background

A Ruth-Aaron pair is a pair of consecutive positive integers n and n+1 such that the sum of the prime factors (counting repeated prime factors) of each integer are equal. For example, (714,715) is a Ruth-Aaron pair, since 714=2*3*7*17, 715=5*11*13, and 2+3+7+17=5+11+13=29. The name Ruth-Aaron pair was chosen by Carl Pomerance in reference to Babe Ruth's career home run total of 714, which stood as the world record from May 25, 1935 until April 8, 1974 when Hank Aaron hit his 715th home run. You can learn more about the fascinating history of these numbers in this Numberphile video.

Goal

Write a complete program or function which, given a positive integer n, outputs the nth Aaron number, where the nth number is defined to be the larger integer of the nth Ruth-Aaron pair. Thus the nth Aaron number is a(n)+1, where a(n) is the nth term in the OEIS sequence A039752.

Test cases

The first few Aaron numbers are

6,9,16,78,126,715,949,1331,1521,1863,2492,3249,4186,4192,5406,5561,5960,6868,8281,8464,10648,12352,14588,16933,17081,18491,20451,24896,26643,26650,28449,28810,33020,37829,37882,41262,42625,43216

Rules

Standard loopholes are forbidden.
Input and output may be in any convenient format.
This is code-golf, the shortest answer (in bytes) wins.

05AB1E, 11 10 9 bytes

-1 byte thanks to Emigna
-1 byte thanks to Adnan

µN>Ð<‚ÒOË

Explanation:

µ            While the counter variable (which starts at 0) is not equal to the input:
 N>          Store the current iteration index + 1, and then create an array with
   Ð<‚       [current iteration index + 1, current iteration index]
      ÒO     Get the sum of the prime factors of each element
        Ë    If all elements in the array are equal,
             implicitly increment the counter variable

1-indexed.

Try it online!


Runs of Digits in Pi Your goal is to output the strictly increasing sequence of consecutive, identical digits of pi (π). Each term in the sequence must be one digit longer than the previous. So 3 (0th digit of pi) is the first time a run of digits occurs (length 1). The next to occur is 33 (digits 24 and 25 of pi). Of course, this sequence requires the digits of pi to be in base 10.

The ones known so far, and the first six all occur within the first 800 digits:

3
33
111
9999
99999
999999
3333333
44444444
777777777
6666666666
... (not in first 2 billion digits)

Note that the consecutive nines all occur together, in the same run, so if the next larger run you found happened to be 1000 consecutive 0s, this would fill in multiple terms of the sequence.

I have not found any more terms with my program. I know there are no more terms within the first 50000 digits or more. My program was taking too long with 500000 digits, so I gave up.

Reference Implementation

You may:

Output the sequence forever
Take an integer n and find the first n numbers in the sequence
Take an integer n and find the numbers in the sequence contained in the first n digits of pi.

Make sure to specify which one your code does. The number n may be zero or one indexed.

Inspired by this mathoverflow question.

Mathematica, 85 bytes

FromDigits/@DeleteDuplicatesBy[Join@@Subsets/@Split@RealDigits[Pi,10,#][[1]],Length]&

Anonymous function. Takes n as input, and returns the elements of the sequence in the first n digits of π. Output is in the form of {0, 3, 33, 111, ...}.


Products that equal a sum and vice versa A fun pair of equivalences is 1 + 5 = 2 · 3 and 1 · 5 = 2 + 3. There are many like these, another one is 1 + 1 + 8 = 1 · 2 · 5 and 1 · 1 · 8 = 1 + 2 + 5. In general a product of n positive integers equals a sum of n positive integers, and vice versa.

In this challenge you must generate all such combinations of positive integers for an input n > 1, excluding permutations. You can output these in any reasonable format. For example, all the possible solutions for n = 3 are:

(2, 2, 2) (1, 1, 6)
(1, 2, 3) (1, 2, 3)
(1, 3, 3) (1, 1, 7)
(1, 2, 5) (1, 1, 8)

The program that can generate the most combinations for the highest n in one minute on my 2GB RAM, 64-bit Intel Ubuntu laptop wins. If your answer uses more than 2GB of RAM or is written in a language I can not test with freely available software, I will not score your answer. I will test the answers in two weeks time from now and choose the winner. Later non-competing answers can still be posted of course.

Since it's not known what the full sets of solutions for all n are, you are allowed to post answers that generate incomplete solutions. However if another answer generates a (more) complete solution, even if their maximum n is smaller, that answer wins.

To clarify, here's the scoring process to decide the winner:

I will test your program with n=2, n=3,  etc... I store all your outputs and stop when your program takes more than a minute or more than 2GB RAM. Each time the program is run for a given input n, it will be terminated if it takes more than 1 minute.
I look at all the results for all programs for n = 2. If a program produced less valid solutions than another, that program is eliminated.
Repeat step 2 for n=3, n=4, etc... The last program standing wins.

C (gcc), n = 50000000 with 6499 results in 59 s

To avoid producing over a terabyte of output consisting almost entirely of 1s, a sequence of (say) 49999995 1s is abbreviated as 1x49999995.

#include <stdio.h>
#include <stdlib.h>

static int n, *a1, k1 = 0, *a2, k2 = 0, s1, p1, *factor;

static void out() {
  if (s1 == p1) {
    for (int i = 0; i < k1 && i < k2; i++) {
      if (a1[i] < a2[i])
        return;
      else if (a1[i] > a2[i])
        break;
    }
  }

  for (int i = 0; i < k1; i++)
    printf("%d ", a1[i]);
  printf("1x%d | ", n - k1);
  for (int i = 0; i < k2; i++)
    printf("%d ", a2[i]);
  printf("1x%d\n", n - k2);
}

static void gen2(int p, int s, int m);

static void gen3(int p, int s, int m, int x, int q) {
  int r = s - n + k2 + 2;
  int d = factor[q];
  do {
    if (x * d <= m)
      x *= d;
    q /= d;
  } while (q % d == 0);
  do {
    if (q == 1) {
      a2[k2++] = x;
      gen2(p / x, s - x, x);
      k2--;
    } else {
      gen3(p, s, m, x, q);
    }
    if (x % d != 0)
      break;
    x /= d;
  } while (p / (x * q) >= r - x * q);
}

static void gen2(int p, int s, int m) {
  int n2 = n - k2;
  if (p == 1) {
    if (s == n2)
      out();
  } else if (n2 >= 1 && m > 1) {
    int r = s - n2 + 1;
    if (r < 2 || p < r)
      return;
    if (m > r)
      m = r;
    if (factor[p] <= m)
      gen3(p, s, m, 1, p);
  }
}

static void gen1(int p, int s, int m) {
  int n1 = n - k1;
  p1 = p;
  s1 = s + n1;
  gen2(s1, p1, s + n1 + 1 - n);
  if (n1 != 0) {
    int *p1 = &a1[k1++];
    for (int x = 2; x <= m && p * x <= s + x + n1 - 1; x++) {
      *p1 = x;
      gen1(p * x, s + x, x);
    }
    k1--;
  }
}

int main(int argc, char **argv) {
  if (argc < 2)
    return 1;
  n = atoi(argv[1]);
  if (n < 2)
    return 1;
  a1 = malloc(n * sizeof(int));
  a2 = malloc(n * sizeof(int));
  factor = calloc(4 * n - 1, sizeof(int));
  for (int p = 2; p < 4 * n - 1; p++)
    if (factor[p] == 0) {
      factor[p] = p;
      for (int i = p; i <= (4 * n - 2) / p; i++)
        factor[p * i] = p;
    } else if (factor[p] < factor[p / factor[p]]) {
      factor[p] = factor[p / factor[p]];
    }
  gen1(1, 0, 3 * n - 1);
  return 0;
}

Try it online!


EASY to memorize numbers Numbers that are easy to remember yet theoretically not easily made
Your challenge is to make a program/function in any language that generates uniformly random numbers that fit these criteria:

Length is 5 digits

There are two separate repeated digit pairs

One set of repeated digits is at the beginning or end and the digits
are next to each other

The odd number out is surrounded by the other pair of digits

The two digit pairs and the other number should all be unique

Your program may support numbers with leading zeroes or not, at your discretion. If leading zeroes are supported, they must be included in the output: 06088, not 6088. If leading zeroes are not supported, then numbers like 06088 should not be generated at all.

Test Cases
Accepted Outputs:

55373
55494
67611
61633
09033
99757
95944
22808
65622
22161

Not accepted outputs:

55555
77787
85855
12345
99233
12131
abcde
5033

More acceptable test cases can be found at this pastebin link.
These were made with this python program:

import random
for i in range(100):

    if random.randint(0,100) >= 50: #Put pair touching at beginning if true
        temp = []                      #working array
        temp.append(random.randint(0,9))  #append random digit
        temp.append(temp[0])              #append the same digit again

        x = random.randint(0,9)
        while x == temp[0]:
            x = random.randint(0,9)
        temp.append(x)                    #append another unique digit

        y = random.randint(0,9)
        while y == temp[0] or y == temp[2]:
            y = random.randint(0,9)
        temp.append(y)                  #append another unique digit, and the previous unique digit
        temp.append(x)

    else:  #Put touching pair at end
        temp = []                      #working array
        temp.append(random.randint(0,9))  #append random digit

        #While not unique, try again
        x = random.randint(0,9)
        while x == temp[0]:
            x = random.randint(0,9)
        temp.append(x)                    #append another unique digit

        temp.append(temp[0])              #append the same 0th digit again

        y = random.randint(0,9)
        while y == temp[0] or y == temp[1]:
            y = random.randint(0,9)
        temp.append(y)                  #append another unique digit twice
        temp.append(y)

    tempstr = ""
    for i in temp:
        tempstr += str(i)
    print tempstr

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

05AB1E, 11 bytes

žh.r3£ûÁÂ)Ω

Try it online!

Explanation

žh            # push "0123456789"
  .r          # random shuffle
    3£        # take the first 3
              # EX: 152
      û       # palendromize
              # EX: 15251
       Á      # rotate right
              # EX: 11525
        Â)    # pair with its reverse
              # EX: [11525, 52511]
          Ω   # pick one at random