text:
Piet (Mondrian)'s Puzzle
For more information, watch this video, and go to A276523 for a related sequence.
The Mondrian Puzzle (for an integer n) is the following:
Fit non-congruent rectangles into a n*n square grid. What is the smallest difference possible between the largest and the smallest rectangle?
For 6, the optimal difference for M(6) is 5, and can be demonstrated like so:
 ___________
| |S|_______|
| | |   L   |
| |_|_______|
| |     |   |
| |_____|___|
|_|_________| (fig. I)

The largest rectangle (L) has an area of 2 * 4 = 8, and the smallest rectangle (S) has an area of 1 * 3 = 3. Therefore, the difference is 8 - 3 = 5.
Keep in mind that currently, no optimal solutions for n > 44 have been found.
Your task is to create a program that generates a Mondrian grid that contains a (non-optimal) solution, given an integer n.
You will be tested on the numbers from 100 to 150. Your score for each test will be the difference between the largest and smallest rectangle. Your total score is the sum of your scores for all the tests from 100 to 150.
You must present your output like so:
{number}
{grid}

Where number is the score (the difference between largest and smallest), and grid is either:

A multi-lined string, or
A two-dimensional list.

The grid MUST clearly show where a rectangle starts and ends.
Rules:

Your program must fit within your answer.
Your program must output a value for any number between 100 and 150 within 1 hour on a modern laptop.
Your program must generate the same solution for an integer n every time the program is run.
You must provide a link to the outputs of all 51 solutions (using Pastebin, Github Gist... anything, really).
You must have at least two rectangles on the square grid for your solution.

OEIS A276523. Note that the upper bounds listed there are very easy to improve.

Ha. I watched the same video a week ago, and my first thought was trying to make a program to solve it. I ended up completely forgetting about it though.

Just to put it out there, we need a Piet answer. Maybe a bounty for it...

Piet, 9625
(It finally works!)
The people demanded it, so here it is. This is an extremely naive solution (essentially the same as the loose upper bounds on the OEIS page): it divides each square into just two rectangles.
This gist contains the details in two files:

The program's output (using npiet v1.3) for all required inputs. Note that I only captured stdout, so the ? is the input prompt, followed immediately by the output score, then the grid.
The "pseudo-assembly" source I used to plan out the program.

Explanation
This program takes a single number N as input. If the number is odd, the score is the number; if even, the score is twice the number.
After outputting the score, the rest of the left-hand side of the program is spent filling the stack with five lots of the following information:

The grid width (which is N)
A number of lines to print
A character to print across the grid (either _ or space)
A character to print at each edge of the grid (either space or |)

The right-hand side of the program takes each set of four values and prints out that part of the grid.

You get a bounty anyway!

Solutions have to be valid to be posted.

@mbomb007 Ok, I didn't realize that. I hope this is completed in 7 days.

C 6108
This uses a recursive (really iterative) version of the minimal solution.  Instead of dividing the square into two rectangles where one is a little bit bigger than half the area, it divides it into N rectangles.  So the first rectangle is a bit larger than 1/N the total area. Then taking the remainder, the program splits off a rectangle a bit larger than 1/(N-1) of the remainder and so on until it just takes the remainder as the last rectangle.  The rectangles are cut off of the remainder in a clockwise spiral, so first at the top, then on the right, etc.
Since this a very direct method instead of a search of a broad space, it runs quickly - taking about 25 seconds (on a Raspberry Pi) to look at 74 solutions each for the given problem set.
My intent is to use these results to better inform a search algorithm for a more sophisticated approach.
The output gives the score and both an (ascii) drawing and coordinates for the vertices of the rectangles.  The vertices are in clockwise order, starting from the upper left hand corner of the rectangle in question.
Developed using gcc 4.9.2-10.
Results at https://github.com/JaySpencerAnderson/mondrian
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
typedef struct {
    int y, x, height, width;
} rectangle;
#define min(x,y) (((x)<(y))?(x):(y))
#define max(x,y) (((x)>(y))?(x):(y))
#ifndef TRUE
#define TRUE -1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define MAXCOUNT 75

void initstack(rectangle *s, int n){
    int i;
    for(i=0;i<n;i++){
        s[i].y=s[i].x=s[i].height=s[i].width=0;
    }
}
int valid(rectangle *s,int n){
    int i,j;
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if(min(s[i].height,s[i].width) == min(s[j].height,s[j].width) && max(s[i].height,s[i].width) == max(s[j].height,s[j].width)){

                initstack(s, n);
                return FALSE;
            }
        }
    }
    return TRUE;
}
int horizontal(rectangle s, int y, int x){
    if(s.y == y && x >= s.x && x < s.x+s.width){
        return TRUE;
    }
    else if(s.y+s.height == y && x >= s.x && x < s.x+s.width){
        return TRUE;
    }
    return FALSE;
}
int vertical(rectangle s, int y, int x){
    if(s.x == x && y > s.y && y <= s.y+s.height){
        return TRUE;
    }
    else if(s.x+s.width == x && y > s.y && y <= s.y+s.height){
        return TRUE;
    }
    return FALSE;
}
void graph(rectangle *s, int n, int side){
    unsigned int row,col,i;
    unsigned int line;
    printf("{\n");
/* vertical lines take precedence since "1" cell is 1 char high and 2 char wide */
    for(row=0;row<=side;row++){
        for(col=0;col<=side;col++){
            line=0;
/* Possible values are "  " (0), "__" (1), "| " (2) or "|_" (3). */
            for(i=0;i<n;i++){
                if(horizontal(s[i],row,col)){
                    line|=1;
                }
                if(vertical(s[i],row,col)){
                    line|=2;
                }
            }

            switch(line){
            case 0: printf("  ");   break;
            case 1: printf("__");   break;
            case 2: printf("| ");   break;
            case 3: printf("|_");   break;
            default: printf("##");  break;
            }
        }
        printf("\n");
    }
    printf("}\n");
}
unsigned int score(rectangle *s, int n){
    int i;
    unsigned int smallest,biggest;

    smallest=biggest=s[0].width*s[0].height;

    for(i=0;i<n;i++){
        smallest=min(smallest,s[i].width*s[i].height);
        biggest=max(biggest,s[i].width*s[i].height);
    }
    return biggest-smallest;
}
void report(rectangle *s, int n, int side){
    int i;

    printf("{%d}\n",score(s,n));
    graph(s, n, side);
    printf("{\n");
    for(i=0;i<n;i++){
        printf("[%d,%d] ",s[i].x,s[i].y);
        printf("[%d,%d] ",s[i].x+s[i].width,s[i].y);
        printf("[%d,%d] ",s[i].x+s[i].width,s[i].y+s[i].height);
        printf("[%d,%d]\n",s[i].x,s[i].y+s[i].height);
    }
    printf("\n}\n");
}
void locateandrotate(rectangle *stack, int n){
    unsigned int scratch,i;
    for(i=1;i<n;i++){
        /* Odd rectangles are on their side */
        if(i&1){
            scratch=stack[i].width;
            stack[i].width=stack[i].height;
            stack[i].height=scratch;
        }
        switch(i%4){
        case 0:
            stack[i].x=stack[i-1].x+stack[i-1].width;
            stack[i].y=stack[i-1].y;
            break;
        case 1:
            stack[i].x=stack[i-1].x+stack[i-1].width-stack[i].width;
            stack[i].y=stack[i-1].y+stack[i-1].height;
            break;
        case 2:
            stack[i].x=stack[i-1].x-stack[i].width;
            stack[i].y=stack[i-1].y+stack[i-1].height-stack[i].height;
            break;
        case 3:
            stack[i].x=stack[i-1].x;
            stack[i].y=stack[i-1].y-stack[i].height;
            break;
        default:
            printf("Woops!\n");
        }
    }
}
/* These are the height and width of the remaining area to be filled. */
void door(rectangle *stack, unsigned int height, unsigned int width, unsigned int n, unsigned int totaln){
    unsigned int thisheight, thiswidth;
    int i;

    for(i=0;i<totaln;i++){
/* Not yet used */
        if(stack[i].width == 0){
            stack[i].width=width;
            if(i+1 == totaln){
                stack[i].height=height;
            }
            else {
/* Sometimes yields congruent rectangles, as with 16x16, 8 rectangles */
                if(totaln&1 || height%n){
                    int j;
                    stack[i].height=height-(((n-1)*height)/n);
                }
                else {
                    stack[i].height=height-((((n-1)*height)-1)/n);
                }
                /* Exchange height and width to rotate */
                door(stack,width,height-stack[i].height,n-1,totaln);
            }
            return;
        }
    }
}
void usage(char *argv[],int side){
    printf("Usage: %s -s <side-length>\n",argv[0]);
    printf("Purpose: Calculate N non-congruent rectangles arranged to exactly fill a square with the specified side length.\n");
    printf("Defaults: %s -s %d\n",argv[0],side);
    exit(0);

}
int main(int argc, char *argv[]){
    int side=16;
    int n,bestscore,bestn=2;
    int status;

    while((status=getopt(argc,argv,"s:h")) >= 0){
        switch(status){
        case 's':
            sscanf(optarg,"%d",&side);
            break;
        case 'h':
        default:
            usage(argv,side);
        }
    }

    bestscore=side+side;

    rectangle stack[MAXCOUNT],best[MAXCOUNT];
    for(n=2;n<=MAXCOUNT;n++){
        initstack(stack,MAXCOUNT);
        door(stack, side, side, n, n);
        locateandrotate(stack, n);
        if(valid(stack,n)){
            if(score(stack,n) < bestscore){
                bestn=n;
                initstack(best,MAXCOUNT);
                door(best, side, side, n, n);
                locateandrotate(best, n);

                bestscore=score(best,n);
            }
        }
    }
    report(best,bestn,side);
}

Ummm... could you give the final score in the header? Thanks. Nice solution, though - wasn't expecting a solution ('cause no one answered for a few days).

C - 2982
This program implements a search through a broad results set.  The important part of making this search practical was to fail early and/or not go down bad paths.  This generates a set of rectangles to be considered for the solution.  The set of rectangles generated avoids those with dimensions that would not be useful.  For instance, if the program is trying to find the solution to a 128x128 square, divided into 8 rectangles, it will generate a rectangle that is 128x16.  It will not generate that one is 120x17 because there is no prospect of a generating rectangle that is 8 wide to fill in the gap at the end of 120.
The initial strategy for placing rectangles is to place them on the inside of the perimeter of the square (buildedge function).  In that way, the algorithm gets pretty quick feedback at each corner as to whether there is a problem with the sequence chosen.  While placing rectangles, the logic keeps watching to see if any gaps of space develop which are too narrow for any rectangle.  After the perimeter has been populated successfully, the strategy changes to trying to match the space remaining with the remaining rectangles (match function).
One other thing that might be of interest is that this implements transactions with rollback for the stacks of rectangles.
This program doesn't try to find the best possible fit.  It is given a budget (64) and quits when it finds the first solution.  If it never finds a solution, we bump up the budget (by 16) and try again.
The time required (on a Dell laptop with an I7 processor) ranged from well under a minute to 48 minutes for 150 on a side (149 on a side took less than 2 minutes).  All 51 solutions used 11 rectangles.  The scores of the 51 solutions ranged from 41 to 78.  The reasons I used 11 rectangles were that the score was lower than with fewer rectangles and it looked like 12 rectangles would take much more than the hour allotted.
The solutions and code may be found at https://github.com/JaySpencerAnderson/mondrian . They are the two my4* files.
BTW, if you compile this to "my4" and execute it as follows: "./my4 -h", it will give you usage.  If you want to see it in action working away, try something like "./my4 -l 50 -n 8".  If you change the one "#if 0" to "#if 1" it will render the remaining space on the screen.  If you want to change this to render the rectangles, look for the one spot where the code executes "graph(space,side)" and change that to "graph(callstack,side)" instead.  I'd also suggest changing the initial budget from 64 to 32 if you want to play around with solutions for squares that are about 50 wide.  The solution for smaller squares will have a better score with a smaller budget.The program below is functional.  Check github for the complete code (with usage, comments, etc).
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
typedef struct {
    int y, x, height, width, created, deleted;
} rectangle;
#define NOTYET -1
#define TOPEDGE 1
#define RIGHTEDGE 2
#define BOTTOMEDGE 4
#define LEFTEDGE 8
#define CENTER 16
#define nextEdge(e) (e<<=1)
#define min(x,y) (((x)<(y))?(x):(y))
#define max(x,y) (((x)>(y))?(x):(y))
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define MAXFACTORS 1000
#define EOL printf("\n")
#define isCurrent(r) (r.created != NOTYET && r.deleted == NOTYET)
#define deleteTxn(r,t) (r.deleted=t)
int area(rectangle r){
    return r.width*r.height;
}
void pop(rectangle *s){
    unsigned int k=0;
    while(s[k].width){
        k++;
    }
    s[k-1].width=s[k-1].height=0;
}
void rpush(rectangle *s, rectangle x){
    unsigned int k=0;
    while(s[k].width){
        k++;
    }
    x.deleted=NOTYET;
    s[k++]=x;
    s[k].width=s[k].height=0;

    return;
}
void dumprectangle(rectangle r){
    printf("%dX%d@[%d,%d] (%d,%d)\t",r.width, r.height, r.x, r.y, r.created, r.deleted);
}
void dumpstack(rectangle *s){
    unsigned int k=0;
    while(s[k].width){
        dumprectangle(s[k]);
        k++;
    }
}
rectangle initrectangle(int width, int height){
    rectangle r;
    r.x=r.y=0;
    r.width=width;
    r.height=height;
    r.created=0;
    r.deleted=NOTYET;
    return r;
}
void initstack(rectangle *s, int n){
    int i;
    for(i=0;i<n;i++){
        s[i].y=s[i].x=s[i].height=s[i].width=0;
    }
}
int bitcount(int x){
    int count=0;
    while(x){
        if(x&1){
            count++;
        }
        x>>=1;
    }
    return count;
}
int congruent(rectangle a, rectangle b){
    return min(a.height,a.width) == min(b.height,b.width) && max(a.height,a.width) == max(b.height,b.width);
}
void report(rectangle *s, int side){
    int i;
    unsigned int smallest,biggest,area=0;

    smallest=side*side;
    biggest=0;

    for(i=0;s[i].width;i++){
        if(isCurrent(s[i])){
            smallest=min(smallest,s[i].width*s[i].height);
            biggest=max(biggest,s[i].width*s[i].height);
        }
    }
    printf("{%d}\n",biggest-smallest);
    printf("{\nDimensions\tLocation\n");
    for(i=0;s[i].width;i++){
        printf("%dx%d\t\t[%d,%d]\n",
            s[i].width,         s[i].height,
            s[i].x,             s[i].y);
    }
    printf("}\n");
}
unsigned int sumstack(rectangle *s){
    unsigned int sum=0;
    int i;
    for(i=0;s[i].width;i++){
        if(isCurrent(s[i])){
            sum+=s[i].width*s[i].height;
            s++;
        }
    }
    return sum;
}
unsigned int minstack(rectangle *s){
    unsigned int area=400000;
    int i;

    for(i=0;s[i].width;i++){
        if(isCurrent(s[i])){
            area=min(area,s[i].width*s[i].height);
        }
    }
    return area;
}
void rollback(rectangle *r, int txn){
    int i;

    if(txn != NOTYET){
        for(i=0;r[i].width;i++){
            if(r[i].created == txn){
                r[i].created=r[i].deleted=NOTYET;
                r[i].x=r[i].width=r[i].y=r[i].height=0;
            }
            else if(r[i].deleted == txn){
                r[i].deleted=NOTYET;
            }
        }
    }
}
int overlap(rectangle a, rectangle b){
    if((a.x < b.x+b.width && a.x+a.width > b.x) && (b.y < a.y+a.height && b.y+b.height > a.y)){
        return TRUE;
    }
    return FALSE;
}
int stackoverlap(rectangle *callstack, rectangle next){
    int i,j;
    for(i=0;callstack[i].width;i++){
        if(overlap(callstack[i], next)){
            return TRUE;
        }
    }
    return FALSE;
}
rectangle rotate(rectangle a){
    int x=a.width;
    a.width=a.height;
    a.height=x;
    return a;
}
int buildedge(rectangle *stack, rectangle *callstack,int side, rectangle *space){
    int i,j,edge,goal,nextgoal,x,y,d,mindim,minarea,result=FALSE,spacetxn,stacktxn;
    mindim=side;
    minarea=side*side;
    for(i=0;stack[i].width;i++){
        mindim=min(mindim,min(stack[i].width,stack[i].height));
        minarea=min(minarea,area(stack[i]));
    }
    x=y=0;
    edge=TOPEDGE;
    i=0;
    while(edge == TOPEDGE && callstack[i].width != 0){
        if(callstack[i].x == x && callstack[i].y == y){
            x+=callstack[i].width;
            if(x == side){
                nextEdge(edge);
                y=0;
            }
            i=0;
        }
        else {
            i++;
        }
    }
    while(edge == RIGHTEDGE && callstack[i].width != 0){
        if(callstack[i].x+callstack[i].width == x && callstack[i].y == y){
            y+=callstack[i].height;
            if(y == side){
                nextEdge(edge);
                x=side;
            }
            i=0;
        }
        else {
            i++;
        }
    }
    while(edge == BOTTOMEDGE && callstack[i].width != 0){
        if(callstack[i].x+callstack[i].width == x && callstack[i].y+callstack[i].height == y){
            x-=callstack[i].width;
            if(x == 0){
                nextEdge(edge);
                y=side;
            }
            i=0;
        }
        else {
            i++;
        }
    }
    while(edge == LEFTEDGE && callstack[i].width != 0){
        if(callstack[i].x == x && callstack[i].y+callstack[i].height == y){
            y-=callstack[i].height;
            if(y == 0){
                nextEdge(edge);
            }
            i=0;
        }
        else {
            i++;
        }
    }
    if(edge == CENTER){
        /* rectangles are placed all along the perimeter of the square.
         * Now match will use a different strategy to match the remaining space
         * with what remains in stack */
        if(match(stack,callstack,space)){
            report(callstack,side);
            return TRUE;
        }
        return FALSE;
    }
    switch(edge){
    case TOPEDGE:
        goal=side-x;
        break;
    case RIGHTEDGE:
        goal=side-y;
        break;
    case BOTTOMEDGE:
        goal=x;
        break;
    case LEFTEDGE:
        /* Still a good assumption that callstack[0] is at 0,0 */
        goal=y-callstack[0].height;
        break;
    default:
        fprintf(stderr,"Error: buildedge has unexpected edge (b): %d\n",edge);
        exit(0);
    }
    nextgoal=goal-mindim;
    for(i=0;stack[i].width;i++){
        if(isCurrent(stack[i])){
            for(d=0;d<2;d++){
                switch(edge){
                case TOPEDGE:
                    if(stack[i].width == goal || stack[i].width <= nextgoal){
                        stack[i].x=x;
                        stack[i].y=y;
                        if(!stackoverlap(callstack, stack[i])){
                            spacetxn=nexttransaction(space);
                            stacktxn=nexttransaction(stack);
                            deleteTxn(stack[i],stacktxn);
                            removerectangle(space, stack[i], spacetxn);
                            if(narrow(space) >= mindim && smallest(space) >= minarea){
                                rpush(callstack, stack[i]);
                                if(buildedge(stack, callstack, side, space)){
                                    return TRUE;
                                }
                                pop(callstack);
                            }
                            rollback(space, spacetxn);
                            rollback(stack, stacktxn);
                            stack[i].x=stack[i].y=0;
                        }
                    }
                    break;
                case RIGHTEDGE:
                    if(stack[i].height == goal || stack[i].height <= nextgoal){
                        stack[i].x=x-stack[i].width;
                        stack[i].y=y;
                        if(!stackoverlap(callstack, stack[i])){
                            spacetxn=nexttransaction(space);
                            stacktxn=nexttransaction(stack);
                            deleteTxn(stack[i],stacktxn);
                            removerectangle(space, stack[i], spacetxn);
                            if(narrow(space) >= mindim && smallest(space) >= minarea){
                                rpush(callstack, stack[i]);
                                if(buildedge(stack, callstack, side, space)){
                                    return TRUE;
                                }
                                pop(callstack);
                            }
                            rollback(space, spacetxn);
                            rollback(stack, stacktxn);
                            stack[i].x=stack[i].y=0;
                        }
                    }
                    break;
                case BOTTOMEDGE:
                    if(stack[i].width == goal || stack[i].width <= nextgoal){
                        stack[i].x=x-stack[i].width;
                        stack[i].y=y-stack[i].height;
                        if(!stackoverlap(callstack, stack[i])){
                            spacetxn=nexttransaction(space);
                            stacktxn=nexttransaction(stack);
                            deleteTxn(stack[i],stacktxn);
                            removerectangle(space, stack[i], spacetxn);
                            if(narrow(space) >= mindim && smallest(space) >= minarea){
                                rpush(callstack, stack[i]);
                                if(buildedge(stack, callstack, side, space)){
                                    return TRUE;
                                }
                                pop(callstack);
                            }
                            rollback(space, spacetxn);
                            rollback(stack, stacktxn);
                            stack[i].x=stack[i].y=0;
                        }
                    }
                    break;
                case LEFTEDGE:
                    if(stack[i].height == goal || stack[i].height <= nextgoal){
                        stack[i].x=x;
                        stack[i].y=y-stack[i].height;
                        if(!stackoverlap(callstack, stack[i])){
                            spacetxn=nexttransaction(space);
                            stacktxn=nexttransaction(stack);
                            deleteTxn(stack[i],stacktxn);
                            removerectangle(space, stack[i], spacetxn);
                            if(narrow(space) >= mindim && smallest(space) >= minarea){
                                rpush(callstack, stack[i]);
                                if(buildedge(stack, callstack, side, space)){
                                    return TRUE;
                                }
                                pop(callstack);
                            }
                            rollback(space, spacetxn);
                            rollback(stack, stacktxn);
                            stack[i].x=stack[i].y=0;
                        }
                    }
                    break;
                default:
                    fprintf(stderr,"Error: buildedge has unexpected edge (c): %d\n",edge);
                    exit(0);
                }
                if(callstack[0].width != 0 && stack[i].width != stack[i].height){
                    stack[i]=rotate(stack[i]);
                }
                else {
                    break;
                }
            }
        }
    }
    return FALSE;
}
int populatestack(rectangle *stack, int score, int side, int rectangles){
    int offset,negative,area,mindim;
    rectangle local;

    int avg_area=(side*side)/rectangles;

    if(avg_area < 4){
        /* It's getting too small - really */
        return FALSE;
    }
    local.x=0;
    local.y=0;
    local.created=0;
    local.deleted=NOTYET;

    initstack(stack,MAXFACTORS);
    for(offset=1;offset<=score;offset++){
        negative=offset&1;
        area=avg_area + (negative?(0-(offset>>1)):(offset>>1));
        mindim=area/side;

        if(side*(area/side) == area){
            local.width=side;
            local.height=area/side;
            rpush(stack,local);
        }

        if(area > 0){
            for(local.width=side-mindim;local.width>=area/local.width;local.width--){
                if(local.width*(area/local.width) == area){
                    local.height=area/local.width;
                    rpush(stack,local);
                }
            }
        }
    }
    return TRUE;
}
int solve(int side,int rectangles,int score){
    rectangle stack[MAXFACTORS],callstack[MAXFACTORS];
    rectangle space[MAXFACTORS];
    rectangle universe;

    if(!populatestack(stack, score, side, rectangles)){
        return FALSE;
    }
    if(sumstack(stack) >= side*side){
        initstack(callstack,MAXFACTORS);
        initstack(space,MAXFACTORS);

        /* Initialize space (not occupied by a rectangle) to be side by side
         * where side is the height/width of the square into which the rectangles fit. */
        universe.width=universe.height=side;
        universe.x=universe.y=0;
        universe.created=0;
        universe.deleted=NOTYET;
        rpush(space, universe);

        if(buildedge(stack,callstack,side,space)){
            return TRUE;
        }
    }
    return FALSE;
}
int containsPoint(rectangle a, int x, int y){
    return a.x <= x && a.y <= y && a.x+a.width > x && a.y+a.height > y;
}
int containsRectangle(rectangle a, rectangle b){
    return containsPoint(a, b.x, b.y) && containsPoint(a, b.x+b.width-1, b.y) && containsPoint(a, b.x, b.y+b.height-1) && containsPoint(a, b.x+b.width-1, b.y+b.height-1);
}
int areEqual(rectangle a, rectangle b){
    return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
}
int nexttransaction(rectangle *r){
    int i,n=NOTYET;

    for(i=0;r[i].width;i++){
        n=max(n,max(r[i].created,r[i].deleted));
    }
    return n+1;
}
void splitrectanglevertically(rectangle *space, int i, int x, int txn){
    rectangle left, right;
    left=right=space[i];
    right.x=x;
    left.width=right.x-left.x;
    right.width-=left.width;
    left.created=right.created=space[i].deleted=txn;
    rpush(space,left);
    rpush(space,right);
}
void splitrectanglehorizontally(rectangle *space, int i, int y, int txn){
    rectangle top, bottom;
    top=bottom=space[i];
    bottom.y=y;
    top.height=bottom.y-top.y;
    bottom.height-=top.height;
    top.created=bottom.created=space[i].deleted=txn;
    rpush(space,top);
    rpush(space,bottom);
}
int smallest(rectangle *space){
    int i,j,smallest;
    rectangle current;
    smallest=0;
    for(i=0;space[i].width;i++){
        if(isCurrent(space[i])){
            current=space[i];
            for(j=0;space[j].width;j++){
                if(isCurrent(space[j]) && i != j){
                    if(current.x+current.width == space[j].x
                    && space[j].y <= current.y && space[j].y+space[j].height >= current.y+current.height){
                        current.width+=space[j].width;
                    }
                    else if(space[j].x+space[j].width == current.x
                    && space[j].y <= current.y && space[j].y+space[j].height >= current.y+current.height){
                        current.x=space[j].x;
                        current.width+=space[j].width;
                    }
                    else if(current.y+current.height == space[j].y
                    && space[j].x <= current.x && space[j].x+space[j].width >= current.x+current.width){
                        current.height+=space[j].height;
                    }
                    else if(space[j].y+space[j].height == current.y
                    && space[j].x <= current.x && space[j].x+space[j].width >= current.x+current.width){
                        current.y=space[j].y;
                        current.height+=space[j].height;
                    }
                }
            }
            if(smallest == 0){
                smallest=current.width * current.height;
            }
            else if(smallest > current.width * current.height){
                smallest=current.width * current.height;
            }
        }
    }
    return smallest;
}
int narrow(rectangle *space){
    int i,j;
    rectangle smallest,current;

    smallest.width=0;
    for(i=0;space[i].width;i++){
        current=space[i];
        if(isCurrent(current)){
            for(j=0;space[j].width;j++){
                if(isCurrent(space[j]) && i != j){
                    if(current.width <= current.height
                    && current.x+current.width == space[j].x
                    && space[j].y <= current.y && space[j].y+space[j].height >= current.y+current.height){
                        current.width+=space[j].width;
                    }
                    else if(current.width <= current.height
                    && space[j].x+space[j].width == current.x
                    && space[j].y <= current.y && space[j].y+space[j].height >= current.y+current.height){
                        current.x=space[j].x;
                        current.width+=space[j].width;
                    }

                    if(current.width >= current.height
                    && current.y+current.height == space[j].y
                    && space[j].x <= current.x && space[j].x+space[j].width >= current.x+current.width){
                        current.height+=space[j].height;
                    }
                    else if(current.width >= current.height
                    && space[j].y+space[j].height == current.y
                    && space[j].x <= current.x && space[j].x+space[j].width >= current.x+current.width){
                        current.y=space[j].y;
                        current.height+=space[j].height;
                    }
                }
            }
            if(smallest.width == 0){
                smallest=current;
            }
            else if(min(smallest.width,smallest.height) > min(current.width,current.height)){
                smallest=current;
            }
        }
    }
    return min(smallest.width,smallest.height);
}
int notEmpty(rectangle *space){
    int i,count;

    for(i=0,count=0;space[i].width;i++){
        if(isCurrent(space[i])){
            count++;
        }
    }
    return count;
}
int isAdjacent(rectangle r, rectangle s){
    if(r.y == s.y+s.height && r.x < s.x+s.width && s.x < r.x+r.width){
        return TOPEDGE;
    }
    if(s.x == r.x+r.width && r.y < s.y+s.height && s.y < r.y+r.height){
        return RIGHTEDGE;
    }
    if(s.y == r.y+r.height && r.x < s.x+s.width && s.x < r.x+r.width){
        return BOTTOMEDGE;
    }
    if(r.x == s.x+s.width && r.y < s.y+s.height && s.y < r.y+r.height){
        return LEFTEDGE;
    }
    return NOTYET;
}

int adjacentrectangle(rectangle *space, int k, int k0){
    int i,edge;
    for(i=k0+1;space[i].width;i++){
        if(i != k && isCurrent(space[i])){
            if(isAdjacent(space[k],space[i]) != NOTYET){
                return i;
            }
        }
    }
    return NOTYET;
}
int expanse(rectangle *space, int j, int d){ /* Returns how far space[j] can expand in the d direction */
    int extent,k,giveUp,distance;
    rectangle result=space[j];

    extent=0;
    giveUp=FALSE;
    distance=0;
    if(d == TOPEDGE || d == BOTTOMEDGE){
        while(extent < space[j].width && !giveUp){
            giveUp=TRUE;
            for(k=0;space[k].width;k++){
                if(k != j && isCurrent(space[k]) && isAdjacent(space[j],space[k]) == d){
                    if(space[j].x+extent == space[k].x){
                        extent+=space[k].width;
                        if(distance == 0){
                            distance=expanse(space,k,d);
                        }
                        else {
                            distance=min(distance,expanse(space,k,d));
                        }
                        giveUp=FALSE;
                    }
                    else if(space[j].x+extent > space[k].x && space[j].x+extent < space[k].x+space[k].width){
                        extent=space[k].x+space[k].width-space[j].x;
                        if(distance == 0){
                            distance=expanse(space,k,d);
                        }
                        else {
                            distance=min(distance,expanse(space,k,d));
                        }
                        giveUp=FALSE;
                    }
                }
            }
        }
        if(extent < space[j].width){
            return 0;
        }
        return space[j].height+distance;
    }
    else if(d == LEFTEDGE || d == RIGHTEDGE){
        while(extent < space[j].height && !giveUp){
            giveUp=TRUE;
            for(k=0;space[k].width;k++){
                if(k != j && isCurrent(space[k]) && isAdjacent(space[j],space[k]) == d){
                    if(space[j].y+extent == space[k].y){
                        extent+=space[k].height;
                        if(distance == 0){
                            distance=expanse(space,k,d);
                        }
                        else {
                            distance=min(distance,expanse(space,k,d));
                        }
                        giveUp=FALSE;
                    }
                    else if(space[j].y+extent > space[k].y && space[j].y+extent < space[k].y+space[k].height){
                        extent=space[k].y+space[k].height-space[j].y;
                        if(distance == 0){
                            distance=expanse(space,k,d);
                        }
                        else {
                            distance=min(distance,expanse(space,k,d));
                        }
                        giveUp=FALSE;
                    }
                }
            }
        }
        if(extent < space[j].height){
            return 0;
        }
        return space[j].width+distance;
    }
    return 0;
}
int match(rectangle *stack, rectangle *callstack, rectangle *space){
    int i,j,k,d,goal,mn;
    int height;
    int spacetxn, stacktxn, calltxn;
    int map;
    rectangle r;

    for(i=0,goal=0;space[i].width;i++){
        if(isCurrent(space[i])){
            goal+=space[i].width*space[i].height;
        }
    }
    if(goal == 0){
        return TRUE;
    }
    mn=minstack(stack);
    if(goal < mn){
        /* The goal (space available) is smaller than any rectangle left in the stack */
        return FALSE;
    }
    spacetxn=nexttransaction(space);
    stacktxn=nexttransaction(stack);
    calltxn=nexttransaction(callstack);
    for(j=0;space[j].width;j++){
        for(i=0;stack[i].width;i++){
            if(isCurrent(stack[i]) && isCurrent(space[j])){
                if(congruent(space[j], stack[i]) && adjacentrectangle(space,j,NOTYET) == NOTYET){
                    r=space[j];
                    r.created=calltxn;
                    rpush(callstack, r);
                    deleteTxn(stack[i],stacktxn);
                    deleteTxn(space[j],spacetxn);
                }
            }
        }
    }
    if(!notEmpty(space)){
        return TRUE;
    }
    rectangle e;
    for(j=0;space[j].width;j++){
        if(isCurrent(space[j])){
            e=space[j];
            for(k=0,map=0;space[k].width;k++){
                if(k != j && isCurrent(space[k])){
                    d=isAdjacent(space[j], space[k]);
                    if(d != NOTYET){
                        map|=d;
                    }
                }
            }
            if(bitcount(map) == 1){ /* space[j] has adjacent space on only one side */
                if(map == TOPEDGE || map == BOTTOMEDGE){
                    e.height=expanse(space,j,map);
                }
                else if(map == LEFTEDGE || map == RIGHTEDGE){
                    e.width=expanse(space,j,map);
                }
                for(i=0;stack[i].width;i++){
                    if(isCurrent(stack[i])){
                        if(congruent(e, stack[i])){
                            e.created=calltxn;
                            rpush(callstack, e);
                            deleteTxn(stack[i],stacktxn);
                            if(!removerectangle(space, e, spacetxn)){
                                printf("Logic error in match/expanse.  Terminating\n");
                                exit(0);
                            }
                            if(match(stack,callstack,space)){
                                return TRUE;
                            }
                            else {
                                rollback(stack,stacktxn);
                                rollback(callstack,calltxn);
                                rollback(space,spacetxn);
                                return FALSE;
                            }
                        }
                        else if(congruent(space[j], stack[i])){
                            r=space[j];
                            r.created=calltxn;
                            rpush(callstack, r);
                            deleteTxn(stack[i],stacktxn);
                            if(!removerectangle(space, r, spacetxn)){
                                printf("Logic error in match/expanse.  Terminating\n");
                                exit(0);
                            }
                            if(match(stack,callstack,space)){
                                return TRUE;
                            }
                            else {
                                rollback(stack,stacktxn);
                                rollback(callstack,calltxn);
                                rollback(space,spacetxn);
                                return FALSE;
                            }
                        }
                    }
                }
            }
        }
    }
    if(notEmpty(space)){
        rollback(stack,stacktxn);
        rollback(callstack,calltxn);
        rollback(space,spacetxn);
        return FALSE;
    }
    return TRUE;
}
int removerectangle(rectangle *space, rectangle r, int ntxn){
    int i,status=TRUE;
    for(i=0;space[i].width;i++){
        if(space[i].deleted == NOTYET){
            if(areEqual(space[i], r)){
                space[i].deleted=ntxn;
                return TRUE;
            }
            else if(containsRectangle(space[i], r)){
                if(r.x > space[i].x){
                    splitrectanglevertically(space, i, r.x, ntxn);
                }
                else if(r.y > space[i].y){
                    splitrectanglehorizontally(space, i, r.y, ntxn);
                }
                else if(r.x+r.width < space[i].x+space[i].width){
                    splitrectanglevertically(space, i, r.x+r.width, ntxn);
                }
                else if(r.y+r.height < space[i].y+space[i].height){
                    splitrectanglehorizontally(space, i, r.y+r.height, ntxn);
                }
            }
            else if(overlap(space[i], r)){  /* we have to split both */
                rectangle aux;
                if(r.x < space[i].x){
                    aux=r;
                    aux.width=space[i].x-r.x;
                    r.x+=aux.width;
                    r.width-=aux.width;
                    if(!removerectangle(space,aux,ntxn)){
                        return FALSE;
                    }
                }
                if(r.x+r.width > space[i].x+space[i].width){
                    aux=r;
                    aux.x=space[i].x+space[i].width;
                    aux.width=r.x+r.width-aux.x;
                    r.width-=aux.width;
                    if(!removerectangle(space,aux,ntxn)){
                        return FALSE;
                    }
                }
                if(r.y < space[i].y){
                    aux=r;
                    aux.height=space[i].y-aux.y;
                    r.y+=aux.height;
                    r.height-=aux.height;
                    if(!removerectangle(space,aux,ntxn)){
                        return FALSE;
                    }
                }
                if(r.y+r.height > space[i].y+space[i].height){
                    aux=r;
                    aux.y=space[i].y+space[i].height;
                    aux.height=r.y+r.height-aux.y;
                    r.height-=aux.height;
                    if(!removerectangle(space,aux,ntxn)){
                        return FALSE;
                    }
                }
                if(areEqual(space[i], r)){
                    space[i].deleted=ntxn;
                    return TRUE;
                }
                else {
                    if(!removerectangle(space,r,ntxn)){
                        return FALSE;
                    }
                    return TRUE;
                }
            }
        }
    }
    return TRUE;
}
int main(int argc, char *argv[]){
    int side=15;
    int n=5;
    int budget=0;
    int status;
    while((status=getopt(argc,argv,"l:n:")) >= 0){
        switch(status){
        case 'l':
            sscanf(optarg,"%d",&side);
            break;
        case 'n':
            sscanf(optarg,"%d",&n);
            break;
        }
    }
    budget=64;
    while(solve(side,n,budget) == FALSE){
        budget+=16;
    }
}


text:
Make a regex polyglot
Write a regex that works in at least 2 regex flavors (or versions), and match a different string in each flavor (or version) it is running in.
The strings to be matched in this challenge are the first words of the Ubuntu code names, which are listed below. Your regex has to match from the top of the list. That is, if your regex works in 3 flavors, it has to match Warty Hoary and Breezy, and not others.
Warty
Hoary
Breezy
Dapper
Edgy
Feisty
Gutsy
Hardy
Intrepid
Jaunty
Karmic
Lucid
Maverick
Natty
Oneiric
Precise
Quantal
Raring
Saucy
Trusty
Utopic
Vivid
Wily
Xenial
Yakkety
Zesty
17.10
18.04
18.10
19.04
19.10
...

If your regex works in more than 26 flavors, you can match the Ubuntu version numbers instead. Starting from 17.10, for each new flavor, change the second number to 10 if it was 04, and increment the first number and change the second to 04 otherwise.
In each flavor, your regex should match only the supposed string and nothing else (not limited to the code names). Trailing newlines doesn't matter. That means your regex could either match only the string without the trailing newline, match only the string with the trailing newline, or match both. And it doesn't have to be consistent in different flavors. You can assume the input is in printable ASCII (except for the trailing newline, if there is one).
Your score is (the length of your code+10)/((number of flavors)^2). Lowest score wins.

Just to check - by "In each flavor, your regex should match only the supposed string and nothing else.", does this mean each regex should only match one Ubuntu version name and none of the other names but can potentially match other non-version name strings, or does it mean that the regex can only match that exact string and no other strings, even if it isn't a version name in the list above?

@Sp3000 It should match that exact string, and no other strings.

87 bytes, 5 flavours, (87+10)/25 = 3.88
^(((?=W)[[:word:]&&]art|Ho(?=a)\ar|Bre(?=ez)[]e]\z|E(?=dg)[[d]]g)y|(?=Da)[D-[E]]apper)$

I've gone with the easy to test flavours for now, which are:

Regex101: PCRE (PHP), Javascript, Python
Regex Storm: .NET
Rubular: Ruby

The general structure is ^((...)y|...)$, i.e. factoring out the trailing ys and adding anchors.
Warty (PCRE)
(?=W)[[:word:]&&]art

In PCRE and Ruby, [[:word:]] is a POSIX character class matching a word character — in other flavours you get a [[:word:] character class then literal &&], which fails the (?=W) assert. To make Ruby fail, && is used to intersect the POSIX class with nothing, whereas in PCRE && has no special meaning.
Hoary (Javascript)
Ho(?=a)\ar

For whatever reason, Javascript is the only flavour out of the bunch where \a is a literal a — in other flavours it matches the bell character (ASCII 7).
Breezy (Python)
Bre(?=ez)[]e]\z

In Python and Javascript, \z is a literal z — in the other flavours it is equivalent to the $ end of string anchor. To make Javascript fail we use the char class []e], which is an empty char class [] then literal e] in Javascript, and a two-char class []e] in Python.
Dapper (.NET)
(?=Da)[D-[E]]apper

In .NET, [D-[E]] is a set difference, removing the set [E] from [D]. In PCRE, Javascript and Python, we have the class [D-[E] then a literal ]. Ruby's a little different, but for some reason it parses as a class [D-[E]] which only matches E, and I have yet to figure out why...
Edgy (Ruby)
E(?=dg)[[d]]g

Ruby allows char classes inside char classes, so [[d]] is actually equivalent to [d], or just d. In the other flavours, we have [[d] then a literal ].

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Uniquely removable subsequences
Introduction
Consider a sequence of integers and one of its subsequences, say A = [4 2 2 4 4 6 5] and B = [2 4 5].
We want to remove the elements of B from A in order, and there are several ways of doing that:
A = 4 2 2 4 4 6 5
B =   2   4     5
 -> 4   2   4 6

A = 4 2 2 4 4 6 5
B =     2 4     5
 -> 4 2     4 6

A = 4 2 2 4 4 6 5
B =   2     4   5
 -> 4   2 4   6

A = 4 2 2 4 4 6 5
B =     2   4   5
 -> 4 2   4   6

In all cases, the remaining sequence is the same, [4 2 4 6].
If this happens, we say that B is uniquely removable from A.
The task
Your inputs are two sequences of nonnegative integers, A and B, where B is guaranteed to be a subsequence of A.
The inputs may be equal, and they may be empty.
You can take them in any order you want, in any reasonable format.
Your output shall be a truthy value if B is uniquely removable from A, and a falsy value if not.
Rules and scoring
You can write a full program or a function.
The lowest byte count wins.
Test cases
[] [] -> True
[0,3] [] -> True
[1,0,1] [1] -> False
[0,2] [0,2] -> True
[2,2,1,1,2,2,2] [2,1] -> True
[4,2,2,4,4,6,5] [4,5] -> False
[10,5,10,10,5,10] [10,5,10] -> False
[4,2,2,4,4,6,5] [2,4,5] -> True
[1,1,1,0,0,0,1,1,1,0] [1,0,1,1] -> True
[0,1,0,0,0,0,1,1,0,1] [1,0,1,1] -> False
[0,4,0,0,4,1,4,2,2] [0,0,0,1,4] -> True
[0,2,2,25,0,2,2,26,0,0,2] [2,0,0,0,2] -> True
[1,1,1,3,2,1,3,2,2,3,3,2] [1,1,2,3,2] -> False
[0,3,2,0,1,3,2,0,0,0,3,2] [0,1,2,0,3] -> False
[5,7,2,7,7,1,7,7,5,2,7,7,5,2,2,7,5] [2,7,5,7,7,2] -> False
[5,4,0,5,4,5,4,1,0,4,2,1,1,2,4,4,0,2,2,1] [4,0,1,1,2,1] -> False
[0,1,4,0,1,4,0,1,5,1,4,4,2,0,0,1,1,1,2,4] [0,1,0,0,2,0,1,4] -> True

Haskell, 90 84 bytes
a%[]=[a]
(t:z)%x@(s:y)=[a|a<-z%y,t==s]++[t:s|s<-z%x]
_%_=[]
((all=<<(==).head).).(%)

Construct the list of all possible subtracted sequences nondeterministically and checks whether they are all equal.
Usage:
*Main> mapM_(\(a,b)->let r=(((all=<<(==).head).).(%)) a b in putStrLn$concat[show a," ",show b," -> ",show r]) [([],[]), ([0,3],[]), ([1,0,1],[1]), ([0,2],[0,2]), ([2,2,1,1,2,2,2],[2,1]), ([4,2,2,4,4,6,5],[4,5]), ([10,5,10,10,5,10],[10,5,10]), ([4,2,2,4,4,6,5],[2,4,5]), ([1,1,1,0,0,0,1,1,1,0],[1,0,1,1]), ([0,1,0,0,0,0,1,1,0,1],[1,0,1,1]), ([0,4,0,0,4,1,4,2,2],[0,0,0,1,4]), ([0,2,2,25,0,2,2,26,0,0,2],[2,0,0,0,2]), ([1,1,1,3,2,1,3,2,2,3,3,2],[1,1,2,3,2]), ([0,3,2,0,1,3,2,0,0,0,3,2],[0,1,2,0,3]), ([5,7,2,7,7,1,7,7,5,2,7,7,5,2,2,7,5],[2,7,5,7,7,2]), ([5,4,0,5,4,5,4,1,0,4,2,1,1,2,4,4,0,2,2,1],[4,0,1,1,2,1]), ([0,1,4,0,1,4,0,1,5,1,4,4,2,0,0,1,1,1,2,4],[0,1,0,0,2,0,1,4])]
[] [] -> True
[0,3] [] -> True
[1,0,1] [1] -> False
[0,2] [0,2] -> True
[2,2,1,1,2,2,2] [2,1] -> True
[4,2,2,4,4,6,5] [4,5] -> False
[10,5,10,10,5,10] [10,5,10] -> False
[4,2,2,4,4,6,5] [2,4,5] -> True
[1,1,1,0,0,0,1,1,1,0] [1,0,1,1] -> True
[0,1,0,0,0,0,1,1,0,1] [1,0,1,1] -> False
[0,4,0,0,4,1,4,2,2] [0,0,0,1,4] -> True
[0,2,2,25,0,2,2,26,0,0,2] [2,0,0,0,2] -> True
[1,1,1,3,2,1,3,2,2,3,3,2] [1,1,2,3,2] -> False
[0,3,2,0,1,3,2,0,0,0,3,2] [0,1,2,0,3] -> False
[5,7,2,7,7,1,7,7,5,2,7,7,5,2,2,7,5] [2,7,5,7,7,2] -> False
[5,4,0,5,4,5,4,1,0,4,2,1,1,2,4,4,0,2,2,1] [4,0,1,1,2,1] -> False
[0,1,4,0,1,4,0,1,5,1,4,4,2,0,0,1,1,1,2,4] [0,1,0,0,2,0,1,4] -> True

Thanks to @Zgarb for saving 6 bytes!

You can rearrange things and have x%_=x for the second case of %. Also, I think the main function would be shorter in pointful form.

@Zgarb x%_=x won't work because the types won't match but _%_=[] saves a byte.

JavaScript (ES6), 141 152 156 159
Recursive function - quite long
f=(a,b,i=0,j=0,r=a,S=new Set)=>(1/b[j]?1/a[i]&&f(a,b,i+1,j,r,S,a[i]-b[j]||f(a,b,i+1,j+1,r=[...r],r[i]=S)):S.add(0+r.filter(x=>1/x)),S.size<2)

Less golfed
f=(a, b,
   i = 0, // current position to match in a
   j = 0, // current position to match in b
   r = a, // current result so far, A with elements of B removed - start == A
   S = new Set // set of possible "A removed B"
) => (
    1 / b[j] // check if j is still inside B
    ? 1 / a[i] // if i is inside A
      && (
        // in any case try to find current element of B in the remaining part of A
        f(a, b, i+1, j, r, S),
        a[i] == b[j] // if match was found between A and B
        &&
          // mark current element in a copy of r and
          // look for the next element of B in the remaining part of A
          f(a, b, i+1, j+1, r=[...r], r[i]=S),
      )
    // else - j is not inside B, we have a solution in r
    // use filter to get a copy without the marked elements
    //  (note: 1/any_number == number_not_0, 1/Object == NaN)
    // then convert to string, to use as a key in S
    : S.add(0+a.filter(x=>1/x)),
    S.size<2 // return true if S has only 1 element
)

Test

f=(a,b,i=0,j=0,r=a,S=new Set)=>(1/b[j]?1/a[i]&&f(a,b,i+1,j,r,S,a[i]-b[j]||f(a,b,i+1,j+1,r=[...r],r[i]=S)):S.add(0+r.filter(x=>1/x)),S.size<2)

out=(...x)=>O.textContent+=x.join` `+'\n'
;`[] [] -> True
[0,3] [] -> True
[1,0,1] [1] -> False
[0,2] [0,2] -> True
[2,2,1,1,2,2,2] [2,1] -> True
[4,2,2,4,4,6,5] [4,5] -> False
[10,5,10,10,5,10] [10,5,10] -> False
[4,2,2,4,4,6,5] [2,4,5] -> True
[1,1,1,0,0,0,1,1,1,0] [1,0,1,1] -> True
[0,1,0,0,0,0,1,1,0,1] [1,0,1,1] -> False
[0,4,0,0,4,1,4,2,2] [0,0,0,1,4] -> True
[0,2,2,25,0,2,2,26,0,0,2] [2,0,0,0,2] -> True
[1,1,1,3,2,1,3,2,2,3,3,2] [1,1,2,3,2] -> False
[0,3,2,0,1,3,2,0,0,0,3,2] [0,1,2,0,3] -> False
[5,7,2,7,7,1,7,7,5,2,7,7,5,2,2,7,5] [2,7,5,7,7,2] -> False
[5,4,0,5,4,5,4,1,0,4,2,1,1,2,4,4,0,2,2,1] [4,0,1,1,2,1] -> False
[0,1,4,0,1,4,0,1,5,1,4,4,2,0,0,1,1,1,2,4] [0,1,0,0,2,0,1,4] -> True`
.split('\n').forEach(t=>{
  var [a,b,_,k]=t.match(/\S+/g)
  var r=f(eval(a),eval(b))
  out(r==(k[0]=='T')?'OK':'KO',a,b,r,k)
})

Pyth - 27 bytes
On mobile in school right now, so not fully golfed.
JE!t{.DLQfqJ@LQT{I#{SM^UQlJ

Test Suite

JavaScript (ES6), 116 114 113 bytes
Returns false or true.
(a,b,p)=>((F=(a,i,m)=>1/b[i]?a.map((n,j)=>m>j|n-b[i]||F(a.filter((_,k)=>j-k),i+1,j)):p?r|=p!=a:p=a+'')(a,r=0),!r)

Formatted and commented
(                                     // given:
  a, b,                               // - a, b = input arrays
  p                                   // - p = reference pattern, initially undefined
) => (                                //
  (F = (                              // F is our recursive search function, with:
    a,                                // - a = current working copy of the main array
    i,                                // - i = index in 'b'
    m                                 // - m = minimum index of matching values in 'a'
  ) =>                                //
    1 / b[i] ?                        // if we haven't reached the end of 'b':
      a.map((n, j) =>                 //   for each element 'n' at index 'j' in 'a':
        m > j | n - b[i] ||           //     if 'n' is a valid matching value,
        F(                            //     do a recursive call to F(), using:
          a.filter((_, k) => j - k),  //     - a copy of 'a' without the current element
          i + 1,                      //     - the next index in 'b'
          j                           //     - 'j' as the new minimum index in 'a'
        )                             //
      )                               //
    :                                 // else:
      p ?                             //   if the reference pattern is already set:
        r |= p != a                   //     check if it's matching the current 'a'
      :                               //   else:
        p = a + ''                    //     set the current 'a' as the reference pattern
  )(a, r = 0),                        //  initial call to F() + initialization of 'r'
  !r                                  //  yields the final result
)                                     //

Test cases

let f =

(a,b,p)=>((F=(a,i,m)=>1/b[i]?a.map((n,j)=>m>j|n-b[i]||F(a.filter((_,k)=>j-k),i+1,j)):p?r|=p!=a:p=a+'')(a,r=0),!r)

console.log(f([],[]));                                                        // -> true
console.log(f([0,3],[]));                                                     // -> true
console.log(f([1,0,1],[1]));                                                  // -> false
console.log(f([0,2],[0,2]));                                                  // -> true
console.log(f([2,2,1,1,2,2,2],[2,1]));                                        // -> true
console.log(f([4,2,2,4,4,6,5],[4,5]));                                        // -> false
console.log(f([10,5,10,10,5,10],[10,5,10]));                                  // -> false
console.log(f([4,2,2,4,4,6,5],[2,4,5]));                                      // -> true
console.log(f([1,1,1,0,0,0,1,1,1,0],[1,0,1,1]));                              // -> true
console.log(f([0,1,0,0,0,0,1,1,0,1],[1,0,1,1]));                              // -> false
console.log(f([0,4,0,0,4,1,4,2,2],[0,0,0,1,4]));                              // -> true
console.log(f([0,2,2,25,0,2,2,26,0,0,2],[2,0,0,0,2]));                        // -> true
console.log(f([1,1,1,3,2,1,3,2,2,3,3,2],[1,1,2,3,2]));                        // -> false
console.log(f([0,3,2,0,1,3,2,0,0,0,3,2],[0,1,2,0,3]));                        // -> false
console.log(f([5,7,2,7,7,1,7,7,5,2,7,7,5,2,2,7,5],[2,7,5,7,7,2]));            // -> false
console.log(f([5,4,0,5,4,5,4,1,0,4,2,1,1,2,4,4,0,2,2,1],[4,0,1,1,2,1]));      // -> false
console.log(f([0,1,4,0,1,4,0,1,5,1,4,4,2,0,0,1,1,1,2,4],[0,1,0,0,2,0,1,4]));  // -> true

Wow! I tried to find a way to recurse with a reduced copy of A, but no success

JavaScript (Firefox 30+), 159 147 bytes
f=(a,b,i=f(a,b,0))=>i?i.every(x=>x+""==i[0]):b+b?a+a&&[for(n of a)if(a[i++]==b[0])for(x of f(a.slice(i),b.slice(1),0))[...a.slice(0,i-1),...x]]:[a]

Here's a couple of alternate approaches, both anonymous functions:
(a,b,f=(a,b,i=0)=>b+b?a+a&&[for(n of a)if(a[i++]==b[0])for(x of f(a.slice(i),b.slice(1)))[...a.slice(0,i-1),...x]]:[a],c=f(a,b))=>c.every(x=>x+""==c[0])
(a,b,f=(a,b,i=0)=>b+b?a+a&&[for(n of a)if(a[i++]==b[0])for(x of f(a.slice(i),b.slice(1)))[...a.slice(0,i-1),...x]]:[a])=>new Set(f(a,b).map(btoa)).size<2

Test snippet

f=(a,b,i=f(a,b,0))=>i?i.every(x=>x+""==i[0]):b+b?a+a&&[for(n of a)if(a[i++]==b[0])for(x of f(a.slice(i),b.slice(1),0))[...a.slice(0,i-1),...x]]:[a]

T.textContent = T.textContent.split`
`.map(x => x + ` (${f(...x.split` `.slice(0,2).map(eval))})`).join`
`

[] [] -> True
[0,3] [] -> True
[1,0,1] [1] -> False
[0,2] [0,2] -> True
[2,2,1,1,2,2,2] [2,1] -> True
[4,2,2,4,4,6,5] [4,5] -> False
[10,5,10,10,5,10] [10,5,10] -> False
[4,2,2,4,4,6,5] [2,4,5] -> True
[1,1,1,0,0,0,1,1,1,0] [1,0,1,1] -> True
[0,1,0,0,0,0,1,1,0,1] [1,0,1,1] -> False
[0,4,0,0,4,1,4,2,2] [0,0,0,1,4] -> True
[0,2,2,25,0,2,2,26,0,0,2] [2,0,0,0,2] -> True
[1,1,1,3,2,1,3,2,2,3,3,2] [1,1,2,3,2] -> False
[0,3,2,0,1,3,2,0,0,0,3,2] [0,1,2,0,3] -> False
[5,7,2,7,7,1,7,7,5,2,7,7,5,2,2,7,5] [2,7,5,7,7,2] -> False
[5,4,0,5,4,5,4,1,0,4,2,1,1,2,4,4,0,2,2,1] [4,0,1,1,2,1] -> False
[0,1,4,0,1,4,0,1,5,1,4,4,2,0,0,1,1,1,2,4] [0,1,0,0,2,0,1,4] -> True

I like the snippet too

MATL, 27 bytes
n:inXN!"1G@&)w2G=?}x]]tvdz~

The longest test cases run out of time in the online compiler.
Try it online!

Mathematica, 128 bytes
h=Length;n=ToExpression;g=ToString;y=Array;h@Union@ReplaceList[#2,n@Riffle[y["a"<>g@#<>"___"&,t=h@#+1],#]->n@y["a"<>g@#&,t]]==1&

Unnamed function taking two list arguments, where the first is the subsequence and the second is the full sequence; outputs True or False.
The core part is the following sequence, ungolfed for readability:
ReplaceList[#2, ToExpression @
  Riffle[
    Array["a" <> ToString@# <> "___" &, Length@# + 1]
    , #
  ] -> ToExpression @
    Array["a" <> ToString@#& , Length@# + 1 ]
]

Here # represents the subsequence—for example, {2,4,5}. The first Array command creates a list of strings like {"a1___","a2___","a3___","a4___"}, which is then Riffled together with # to yield a weird list like {"a1___",2,"a2___",4,"a3___",5,"a4___"}; then this list is cast into an actual Mathematica expression. For the example {2,4,5}, a partial evaluation of this core code is
ReplaceList[#2, {a1___,2,a2___,4,a3___,5,a4___} -> {a1,a2,a3,a4}]

which exactly gives a list of all possible ways to remove the subsequence {2,4,5} from #2 and leave the rest of the list alone.
After this list is generated, we simply remove duplicates using Union and test whether the length of the resulting output is 1 or not.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
All-pairs shortest return paths without reusing edges
All-pairs shortest paths is a standard pathfinding problem. This is a twist on that.
Definitions
We are searching for paths on a directed graph. Graphs are defined by square matrices, for example
0  3  2.5
1  0  1
0 -1  0

Write M(r,c) = value in M at row r, column c is the cost to travel from node r to node c. The graph is in general asymmetric, costs may be negative, and M(i,i)=0 for all i. An edge with cost zero does not exist, i.e. treat zeros as infinities in the input.
Indexing from zero, the above graph can be visualised thus:

Goal
For a given valid, input matrix of any size output the matrix MOUT(r,c)=cost of the shortest path from r to c and back to r
The twist is: you must make a return trip, without visiting any edges on the return trip which you used on the outward trip. That is, M(r,c) and M(c,r) are considered to be the same edge albeit with a cost which depends on the direction of travel.
For example, the shortest path from 0 -> 1 -> 0 may not include both the edges (0,1) and (1,0).
Nor may you re-use an edge in the outward trip.
Each return trip is considered independently of the others. If you use (0,1) in the path from 0 -> 1 -> 0 then you may use either (0,1) or (1,0) in the path from 0 -> 2 -> 0.
Input/Output Format
Input is on stdin and output on stdout.
The input and output is a matrix with columns separated by a number of spaces, and rows separated by a single \n.
Input entries are floating point numbers conforming to /^-?[0-9]+(\.[0-9]*)?$/. Output entries are numbers of the same kind or Inf, Infinity, or NaN or some equivalent symbol in the event that no return route exists between those nodes. A zero in the input matrix represents an infinite cost (non-existant edge) but zeroes in the output represent a cost-free journey.
Your program behaviour is undefined in the event that the input is not a finite real-valued square matrix.
Requirements
Test against the following input matrices and post the results with your code.
A:
 0   6  -5  -2   9
-3   0   0  -4   5
 7   2   0  -8   1
-6   3   4  0  -9
 8  -3  -1  2    0

B:
 0  -0.3  2.4  -1
 1   0    0.9   9.3
10   4    0   -2
 8  -6  -7  0

C:
0  1   0   2
0  0   3   1
4  0   0   2
0  1   0   1

Shortest code wins.

"you must make a return trip, without visiting any edges on the return trip which you used on the outward trip" So it's ok to visit the same edge twice on the outward trip?

Edited. No edge may be used twice within any one trip.

How is this truly scored? If it's scored by shortest code, then does it really matter how their program did on your test cases? Also, you should make it clearer how the matrix represents a graph.

The program must produce correct output. Isn't that a given for all these contests? And I'm not sure what's unclear about the representation -- algebraic definition with an example and diagram, what else do you need?


text:
Connecting Wires?
Your goal is to create a program. It must take input indefinitely.
Here is a sample run (the > shows that the line is the output from the program)
2,6
> 0
5,6
> 0
7,5
> 0
2,7
> 1

Since 2 is connected to 6, which in turn is connected to 5 and then 7, 2 and 7 are hence connected.
5,2
> 1

...

Clarifications
Whenever the user writes any two numbers (separated by any delimiter you prefer), the program must output whether they are connected or not. If they are not connected, the program must output a falsy value (0), however if the wires are connected, the program must output a true value (1).
"We are to interpret the pair p-q as meaning “p is connected to q.” We assume the relation “is
connected to” to be transitive: If p is connected to q, and q is connected
to r, then p is connected to r."
The input must be separated from the output by a newline \n
The input will always be integers in base ten and never floats.
This is code-golf, so the program with the shortest bytecount wins!

It's not very clear how the program is supposed to work. How exactly do we connect wires?

Its up to you? The user will enter the Input part i just wrote above, and the program should output whether the wires are already connected or they aren't.

Are all the input/output examples a part of 1 run of the program, or are they over multiple runs? If the latter is true, then can we store files?

@KritixiLithos I assume you just infinitely loop for input, would be weird to do it otherwise imo.

Yes they are a part of 1 run of the program.

Yes you infinitely loop for input.

Also, I think this question might be a bit trivial, so if there was a winning criteria, it would be easy to see the winner by judging the programs' byte count

@MuhamedCicak Can I edit your question to make it clearer?

@KritixiLithos Yes i would really appreciate that. Please edit it so it is clearer.

@BassdropCumberwubwubwub I edited it to allow more flexible output options

@MuhamedCicak I edited the challenge so that it would be more specific and have more flexible I/O options. Feel free to edit it if you feel I missed out anything :)

@KritixiLithos I didn't wanted to make code golf. Just "Programming Puzzle" so the goal is to just make the program no matter how many bytes it is. Everything else you edited is perfect :)

@MuhamedCicak But if it just is a puzzle, there really won't be a way of selecting the winner from the multiple answers there will be. But if it is code-golf, then it will be easy to select a winner :)

@KritixiLithos Ok then its ok to stay code-golf. I dont know why this question is still on hold.

@MuhamedCicak I have nominated it for reopening (and so has one other person). If it gets more reopen votes, then it won't be on hold any longer

I still see a few problems. 1. There is a self-contradiction in giving > The wires were not connected. Connecting them... as an example of a falsy value. 2. The assumption of transitivity is not sufficient to make the sample run correct. It requires also assuming symmetry. It is not clear whether in addition you expect answers to assume reflexivity. 3. The requirement to separate input from output by a newline seems to assume stdio, but there is no explicit requirement to use stdio. 4. Numbers in base 10 are decimals, so "integers in base ten and never decimals" is self-contradictory.

Note that after editing this is likely also to be a borderline dupe of http://codegolf.stackexchange.com/q/69926/194 and/or http://codegolf.stackexchange.com/q/8647/194

So this will remain on hold ... ?

If you think the question is still incomprehensible (even if it is edited to be comprehensible). Could you please edit it to be comprehensible ?

Can numbers be connected to more than two other numbers?

I think that editing this to be clear will basically make it into a duplicate of this challenge; the only difference is that it has a different input/output format, which doesn't really change the fundamental nature of the challenge. As such, if this doesn't get closed as unclear, it'll probably get closed as a duplicate.

@steenbergh Sure. They can.

@ais523 I guess i have to ask another challenge that is not being asked :)


text:
Addition/Multiplication table generator
Given a number and either "+" or "*", return an addition or multiplication table with the dimensions of that number.
Specifications

The input will be formatted as dimension, operation.
The program should not return anything if the operation input is not + or *.
The program should not return anything if the dimension input is less than 1.

(4,*):
1 2 3 4
2 4 6 8
3 6 9 12
4 8 1216

(4,+):
1234
2456
3567
4678

The spaces between the numbers in the table should be equal to one less than the number of digits in dimension^2 for multiplication, and for addition one less than the number of digits in dimension * 2.

A couple of quite similar questions.  I'm not slamming my dup hammer just yet - I'll see what others have to say.

If the dimension is 10, how would one display the number 100 when there are only 2 digits in 99?

I suggest you allow a somewhat flexible output format. Having to conform to a very specific format is usually boring

Also input format checking is generally considered to be a tedious task that doesn't really add anything to a [tag:code-golf] challenge. *The program should not return anything if the operation input is not + or . The program should not return anything if the dimension input is less than 1.

Could you add an example of output for (4,+)?

Sorry for the mistakes. Please leave this question alone.

Mistakes are natural. The question is just on hold to give time for them to be cleared up, then it can be reopened. I find it useful to post my challenge ideas in the sandbox first to get feedback and spot any mistakes I made. I recommend it for future challenges.

Your example addition table is wrong. The top-left entry should be 2, for example.

I not see why limitate the number of operators in "•The program should not return anything if the operation input is not + or *." Until they are 2 arg to 1: Where is the problem?

Mathematica, 46 bytes
Grid@Outer[If[#2=="+",Plus,Times],r=Range@#,r]&

Unnamed function taking two arguments, a number and one of the characters "+" or "*".
Sample output for the arguments 12,"*":

Does this actually meet the requirements? it looks like would output a multiplication table for any non + input, rather than only outputing a multiplication table on * and a addition table on +

@Taylor You are right! This answer seems to be invalid.

Bash + BSD Utils, 62 bytes
l=$[$1*$1-1]
eval echo \$[{1..$1}$2{1..$1}]|rs -g${#l} $[$1+1]

This calculates the number of spaces as per "number of digits in (dimension^2)-1", and not as shown in the example output, as currently written.
Try it online!
This answer is very similar to this one.
Works out-of-the-box on macOS.  rs may need to be installed on Linux systems:
sudo apt-get install rs

Excel, 74 bytes
Worksheet funtion that takes input of dimension, operation from A1, B1 and output a square array starting at the calling cell. Error handling accounts for a large portion of this response, and it is likely that large optimizations may be made to it.
=IfError(Let(r,Sequence(A1),c,Transpose(r),Ifs(B1="*",r*c,B1="+",r+c)),"")

05AB1E, 22 bytes
FN>¹L².VvyDg¹ngs-ú}J,}

Try it online!
Also works with -, ^, m and many more. See here for a list of commands this could work with by searching for "pop a,b".
Output (4,+):
 2 3 4 5
 3 4 5 6
 4 5 6 7
 5 6 7 8

Output (4,*):
 1 2 3 4
 2 4 6 8
 3 6 912
 4 81216

Output (4,^) [XOR]:
 0 3 2 5
 3 0 1 6
 2 1 0 7
 5 6 7 0

Output (4,c) [nCr]:
 1 2 3 4
 0 1 3 6
 0 0 1 4
 0 0 0 1

Output (4,Q) [a == b]:
 1 0 0 0
 0 1 0 0
 0 0 1 0
 0 0 0 1

This breaks rule 2.

APL (Dyalog Classic), 11 bytes
{(⍳∘.⍺⍺⍳)⍵}

Try it online!
APL NARS, 22 bytes, 11 chars
{(⍳∘.⍺⍺⍳)⍵}

test:
  h←{(⍳∘.⍺⍺⍳)⍵}
  ×h 4
1 2  3  4
2 4  6  8
3 6  9 12
4 8 12 16
  +h 4
2 3 4 5
3 4 5 6
4 5 6 7
5 6 7 8
  *h 7
1  1   1    1     1      1      1
2  4   8   16    32     64    128
3  9  27   81   243    729   2187
4 16  64  256  1024   4096  16384
5 25 125  625  3125  15625  78125
6 36 216 1296  7776  46656 279936
7 49 343 2401 16807 117649 823543

even if {(⍳∘.⍺⍺⍳)⍵} seems to be ok, {(⍳∘.⍵⍵⍳)⍺} it seems not ok
  f←{(⍳∘.⍵⍵⍳)⍺}
  4 f×
SYNTAX ERROR

Possible spaces are not as the examples in the question too...
h with g h n is the operator generator of table nxn For each diadic function g. In particular =h n is unit matrix for nxn.

Can you add a TIO (or equivalent). The output in your tests is incorrect but, without being able to test it, I don't know if it's due to an error in your solution or human error in pasting the wrong data into the solution.

@Shaggy the table + start from 0, where the table x start from 1 (in the examples of question)... Here start all from 1

In that case, your solution is invalid as it's not outputting what the challenge specifies it should.

The output for exponents *h 7 shouldn't be included. It doesn't include the exponent values as the top row like it should.

@mbomb007 *h 7 first row 1^1 .. 1^7 2th row 2^1..2^7 3th row 3^1 3^2..3^7 where is the problem?

@RosLuP I took it as each function should have the values of n across each axis. I guess that's not required.

AWK, 111 bytes
{s=$2=="*"?2:$2=="+"?1:0;for(i=s-2;s&&++i<=$1;print"")for(j=s-2;++j<=$1;)printf("%"(s==1?2:$1)"s",s>1?i*j:i+j)}

Try it online!
Output formatting may be slightly different than requested.
Input:
4,+
4,*
6,+

Output:
0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8

1   2   3   4
2   4   6   8
3   6   9  12
4   8  12  16

0 1 2 3 4 5 6
1 2 3 4 5 6 7
2 3 4 5 6 7 8
3 4 5 6 7 8 9
4 5 6 7 8 910
5 6 7 8 91011
6 7 8 9101112

C (gcc), 123 bytes
-Dp(i,c)for(i==0;i++<n;c)
-Df(c)if(x===*#c)p(i,puts(""))p(j,printf("%d ",i c j));
n;x;main(i,j){scanf("%d%c",&n,&x);f(+)f(*)}

Try it online!

Japt -R, 22 bytes
+17 bytes for the input validation and output formatting! :o
õ ïV ú f@©"*+"øVÃòU mq

Try it

JavaScript, 137 bytes
f=(n,s,b="")=>{for(i=0;i++<n;b+="\n")for(j=0;j++<n;b+=(r=s=='*'?i*j:s=='+'?i+j:"")+" ".repeat((n**2+"a").length-(r+"").length));return b}

Creates function f that returns the string. This calculates the number of spaces as per number of digits in (dimension^2)-1, and not as shown in the example output, as currently written. Outputs nothing if there is something other than + or *. I'm open to golfing tips.
Explanation
f=(n,s,b="")=>{
  for(i=0;i++<n;b+="\n")
    for(j=0;j++<n;b+=(r=s=='*'?i*j:s=='+'?i+j:"")+" ".repeat((n**2+"a").length-(r+"").length));
  return b
}

I like when most of my code is just in my for-loops :)
n is the number; s is the operator; b is the string that contains the output; r contains the actual value of the table cells
This is a system of two nested for-loops, I add b by i*j or i+j depending on the operator (r=s=='*'?i*j:s=='+'?i+j:""), and then add the spaces afterward " ".repeat((n**2+"a").length-(r+"").length).
At the end of the j-for-loop, I concatenate a newline to b.
Snack Snippet

f=(n,s,b="")=>{for(i=0;i++<n;b+="\n")for(j=0;j++<n;b+=(r=s=='*'?i*j:s=='+'?i+j:"")+" ".repeat((n**2+"a").length-(r+"").length));return b}

console.log(f(10,'+'));

Python 3 - 154 133 127 bytes
def s(d,o):R,s=range(1,d+1),' '*len(str((d,2)[o=='+']*d-1));return''.join([str((i*j,i+j)[o=='+'])+s+'\n'*(i==d)for j in R for i in R])

Edit : Changed spacing between number according to the new changes in the question.

Input :
8 +
Output :
2  3  4  5  6  7  8  9
3  4  5  6  7  8  9  10
4  5  6  7  8  9  10  11
5  6  7  8  9  10  11  12
6  7  8  9  10  11  12  13
7  8  9  10  11  12  13  14
8  9  10  11  12  13  14  15
9  10  11  12  13  14  15  16

JavaScript (ES6), 160 bytes
(n,s,w=`${s==`*`?n*n:n+n}`.length)=>[...Array(n)].map((_,i,a)=>a.map((_,j)=>((s==`*`?++j*i+j:s==`+`?i+j+2-!(i&&j):``)+` `.repeat(w)).slice(0,w)).join``).join`\n`

Where \n represents the literal newline character. Takes care to space the grid properly for both + and - versions, and ensures the first row and column are the dimensions and not the sum.

You might want to replace \n with an actual new line character, considering js thinks it ok to have a backtick string span multiple lines, that saves another character

@Luke_ As my description states, the byte count already takes that into account.

R, 48 bytes
function(n,o)write(format(outer(1:n,1:n,o)),1,n)

Try it online!
Same I/O as the accepted answer.

This breaks rule 2.

Vyxal, 18 bytes
ɾ?\vdpĖ:vvS$fGL↲Ṡ⁋

Try it Online!
Without strict IO formats, the whole :vvS$fGL↲Ṡ⁋ could be omitted

Python 3 - 140 bytes
a=lambda d,o:print(*map(lambda f:(' '*~-len(str([d,2][o>'*']*d))).join([str([i*f,i+f][o>'*'])for i in range(1,d+1)]),range(1,d+1)),sep='\n')

This breaks rule 2.

JavaScript (Node.js), 91 bytes
(n,_)=>[...'.'.repeat(n)].map((a,i)=>Array.from({length:n},(v,k)=>_='*'?(k+1)*(i+1):k+i+1))

Try it online!

This breaks rule 2.

It needs to be a string an not an array

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/