text:
Is the word typeable with keys adjacent to each other?
Before reading this I suggest reading this little puzzle: https://puzzling.stackexchange.com/questions/11408/longest-word-with-adjacent-letters-on-a-keyboard
I want you to make a program that takes one argument, a word (only lowercase letters), and outputs "Yes" if the word can be typed with adjacent keys on the keyboard (see the article) and "No" if the word can't be typed with adjacent letters.
Here's the keyboard layout used in this challenge:
 ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
 | Q | W | E | R | T | Y | U | I | O | P |
 └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┘
   | A | S | D | F | G | H | J | K | L |
   └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┘
     | Z | X | C | V | B | N | M |
     └───┴───┴───┴───┴───┴───┴───┘

Remember: this is codegolf so the the shortest answer wins!

Can we assume that the input consists only of letters? Can we assume that they are all given in a single case?

I'm confused by this: "Two adjacent keys can max have 1.5 * the space of a key between them." Surely adjacent keys are actually adjacent, that is, they have no space between them, as in the linked puzzle?

How to take argument? STDIN? A function?

Pyth, 66
?"Yes".Am>2sm^-.uk2Cm.Dx"qwertyuiopasdfghjkl*zxcvbnm"b9.5dC,ztz"No

Try it here.
I was surprised to learn Pyth doesn't have a hypotenuse function, so this will likely be beat by a different language. I'll propose a hypotenuse function to Pyth, so this atrocity won't happen in the future.
Explanation
I transform the keyboard into this:
┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
| Q | W | E | R | T | Y | U | I | O | P |
└─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┐
  | A | S | D | F | G | H | J | K | L | * |
  └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┴───┘
    | Z | X | C | V | B | N | M |
    └───┴───┴───┴───┴───┴───┴───┘

Which I then encode as "qwertyuiopasdfghjkl*zxcvbnm". Then I used divmod with modulo 9.5 to figure out the 2D coordinates of every key. Then I compute distances between consecutive keys, and check if the squared distance < 2.

CJam, 83 75 74 bytes
l_1>]z["qwertyuiop asdfghjkl  zxcvbnm "[__B>]z+s_W%+_]zsf{\#)}:*"Yes""No"?

Try it online.
Explanation
The general approach is to produce a big adjacency string containing every pair of adjacent keyboard characters and then check that every pair of adjacent input characters is contained in that string.
I'm quite happy with how I managed to build the adjacency string, which uses very simple and compact logic.
l_1>]z          "Read a line of input and create a list of every pair of
                 adjacent input characters. There will be a trailing element
                 of just the final character, but that's okay since any single
                 lowercase letter can be found in the adjacency string.";
["qwertyuiop asdfghjkl  zxcvbnm "
              "^ Create the in-row forward adjacency string.";
[__B>]z         "Create the alternating-row forward adjacency string by
                 interleaving the in-row string with a substring of itself
                 starting with the middle row letters:
                   'q w e r t y u i o p   a s d f g h j k l  zxcvbnm '
                 + ' a s d f g h j k l     z x c v b n m  '[no interleave here]
                 -----------------------------------------------------
                   'qawsedrftgyhujikolp   azsxdcfvgbhnjmk l  zxcvbnm '";
+s              "Append the alternating-row forward adjacency string to the
                 in-row forward adjacency string.";
_W%+            "Append the reverse of the forward adjacency string (the
                 backward adjacency string) to the forward adjacency string.";
_]zs            "Double every character in the adjacency string so every
                 character is adjacent to itself.";
f{\#)}          "Map each pair of input characters to its 1-indexed location in
                 the adjacency string (0 if not found).";
:*              "Calculate the product of each pair's location in the adjacency
                 string. This will be nonzero if and only if every pair of
                 input characters are in fact adjacent.";
"Yes""No"?      "If the product is nonzero, produce 'Yes'; otherwise, produce
                 'No'.";
                "Implicitly print the result.";

That's it, I'm learning CJam.

@octatoan Looks like we'd both be better off learning Pyth, though. :P

Haha, maybe in this case, yes.

J, 77 bytes
No`Yes{::~[:*/2>+/"1@(2|@-/\3(|,.<.@%~+-:@|)'qazwsxedcrfvtgbyhnujmikXolX'i.])

Usage:
   f=.No`Yes{::~[:*/2>+/"1@(2|@-/\3(|,.<.@%~+-:@|)'qazwsxedcrfvtgbyhnujmikXolX'i.])

   f 'redresser'
Yes
   f 'qwergy'
No
   f 'ppcg'
No

Method:
For every input letter I generate it's 2D coordinate (similar to the image in the question) based on it's index in the string 'qazwsxedcrfvtgbyhnujmikXolX'. For every pair of letters in the input I check if their coordinates' Manhattan-distance is smaller than 2. If all are, I output Yes, No otherwise (by abusing the ` operator).
Try it online here.

You forgot the letter p.

@mbomb007 For none-found characters the i. operator returns the index of the last element + 1 so I can save 1 byte by not writing out p and still get it's correct index.

CJam, 75
r(1$+]z[1AB]"qwertyuiop asdfghjkl  zxcvbnm"f/:zSff+s_W%+f{\_|#}W&"No""Yes"?

Try it here (Firefox here).
Overlooked the Yes/No part... Fixed.


text:
Classic Proof Fallacy
The Background
So, we all know the classic proof that goes like this:
a = b
a² = ab
a² - b² = ab - b²
(a-b)(a+b) = b(a-b)
(a+b) = b
b+b = b
2b = b
2 = 1   (Ha ha!)
Of course, the mistake is that you can't divide by 0. Since a = b, a - b = 0, so there was a hidden division by 0.
The Challenge
You have to replicate this proof. First, declare two integers a and b (it doesn't matter what you call them) that equal. Then declare aMod and bMod to be modifiable versions of a and b and initially equal to a and b, respectively. You must multiply them both by a, then subtract b*b from both of them. You must then divide by a - b and then divide them by b (or a) to get. Then, print out aMod and bMod with an equal sign between them.
The Underhanded
Of course, since you declared a and b to equal, a - b = 0, and dividing by 0 causes an error. So you must creatively fake it. Also, because you are trying to replicate the proof, the result on all the operations on aMod and bMod must not equal when printed. They don't have to equal exactly 2 and 1, just two numbers that don't equal.
Here is an example:
#include <iostream>
#define subtract(a, b) a - b

using namespace std;
int main()
{
    int a = 4, b = 4;
    int a_2 = a, b_2 = b;

    a_2 *= a;
    b_2 *= b;

    a_2 -= b * b;
    b_2 -= b * b;

    a_2 = a_2 / subtract(a, b);
    b_2 = b_2 / subtract(-b, -a); // a - b == (-b) - (-a)

    a_2 /= a;
    b_2 /= a;

    cout << a_2 << " = " << b_2 << " because I did the same operations on both of them.";

    return 0;
}

Maybe not the best one, but it illustrates the point.
Bonus Underhanded
Instead of printing the equals sign, you can print out just the two variables (aMod and bMod), and then have code that appears to compare the two variables for equality but in actuality lies that they equal (and prints some form of true).
Remember, this is a popularity contest, so highest number of upvotes wins.
Also, a new version of mathematics called Mathematics 2.0 has made use of standard loopholes automatically invalidate a proof.

Here is a Wikipedia link of the mathematical fallacy so people can better understand

I'm voting to close this question as off-topic because underhanded challenges are no longer on-topic on this site. http://meta.codegolf.stackexchange.com/a/8326/20469

JavaScript
var a=3,b=3,a2=3,b2=3
[a2,b2]=[a2*a,b2*a]
[a2,b2]=[a2-b*b,b2-b*b]
[a2,b2]=[a2/(a-b),b2/(a-b)]
console.log([a2/a,b2/a])

Output:
[1, NaN]

Note that 0/0 = NaN
Hint

 Try add some semicolons.
 This program is actually var a=3,b=3,a2=3,b2=3[a2,b2]=...=[a2/(a-b),b2/(a-b)];console.log([a2/a,b2/a]).
 And the NaN is [3/0,undefined/0]/3.

Wow. That was very clever, "accidentally" forgeting to add semicolons making (almost) the whole program a run-on sentence.

Python 2
I'm pretty sure it's obvious since everyone knows Python, but here's my attempt:
a=b=1
x,y=a*a,a*b
x,y=x-b*b,y-b*b
x,y=a+b/a-b,b
x,y=x/a,y/a
print(x==y)

It outputs True.
Hint:

 Check my division.

since everyone uses Python . I know python, but I rarely use it

@rpax That's what I meant.

Sorry, I didn't read properly your answer.

Ruby
def calculate a,
  b = a
  left, right = a, b
  left, right = [left, right].map { |x| x * a     }
  left, right = [left, right].map { |x| x - b*b   }
  left, right = [left, right].map { |x| x / a - b }
  left, right = [left, right].map { |x| x / b     }
  puts $/=[left, right].join(' = ')
end

calculate 3,
STDOUT.write($/)

ideone
Hint:

 ,

Explanation:

 The two lines that end in commas cause the program to behave differently than it would. Without the commas, the method takes a single argument a, sets b equal to a, performs the transformations from the proof on each one (except due to some missing parentheses, it doesn't divide by 0), and outputs the result (With input of 3, it'd output "-1 = -1". With the trailing comma, however, the b = a line becomes part of the method signature, meaning that it's declaring a second argument with a default value. The method invocation at the end passes in the result of STDOUT.write($/), which is 1 (the number of bytes it wrote to STDOUT, since $/ is predefined to a newline character.) So a is 3 and b is 1, resulting in the equation starting off as "3 = 1". Garbage in, garbage out.

Nice trick there with your newlines.

Could you add an explanation for non-Rubyists?

@kirbyfan64sos Sure, done.

GolfScript
Warning: this program is cheating a bit, in that it doesn't print aMod and bMod
1nt main(){
  int a = 2, b = 2;
  int aMod,bMod;
//The next line should throw and error, but why doesn't it??/
  aMod = (a*a - b*b) / (a-b);
//The next line should throw and error, but why doesn't it??/
  bMod = (b*a - b*b) / (a-b);
//The if should fail, but it works??/
  if(aMod == bMod)
    printf("1");
  return 0;
};

Try it here!
So what's going on?

The first thing you may have noticed are the "forbidden trigraphs". But remember, this is GolfScript, not C! Also, probably noticed that it doesn't actually say "int main()", it says "1nt main()". In GolfScript, the "1" means push 1 onto the stack, and the "nt main" gets processed as two uninitialized variables, which do nothing.  The two parentheses first add 1 to the top number of the stack, and then subtract one, essentially cancelling themselves out. The brackets denote a block that gets pushed onto the stack, and then the semicolon pops it off right away. So, at the end, we just have the original "1" that was pushed on, and at the end of a GolfScript program, the stack gets printed. This answer was inspired by this one.

Trigraphs detected. Activating automatic -1 system. Error: -1 failed (4792, RPLS)

This is sneaky, because it tricks you into thinking it failed to trick you. +1

JavaScript
//Very badly written code!
//No! It is "poetic" code!
while(true){break;}{
let scrollMaxX = 3, screenX = 3;
var scrollBarWithBeerMax = scrollMaxX, Yscroll = screenX; for(var i = 0; i<1; i++){}}

scrollBarWithBeerMax *= scrollMaxX;
Yscroll *= screenX;

scrollBarWithBeerMax -= screenX * screenX;
Yscroll -= screenX * screenX;

scrollBarWithBeerMax /= (scrollMaxX - screenX);
Yscroll /= (scrollMaxX - screenX);

alert(scrollBarWithBeerMax + ' = ' + Yscroll);

Output:
http://jsbin.com/furino/2/edit?js,output
JsBin doesn't seem to be able to execute this code. Use the browser console instead.
Why?

 scrollMaxX and screenX are already existing variables. They are built in in the browser. Thus, the result may vary. The let keyword only temporarily changes their value.

Another JavaScript one:
It doesn't exactly follow the rules, it only outputs if the variables are equal or not.
var a = 2;
var b = 2;

var a_duplicate = a;
var b_duplicate = b;

a_duplicate*=a
b_duplicate*=b;

a_duplicate-=b*b;
b_duplicate-=b*b;

a_duplicate/=(a-b);
b_duplicate/=(a-b);

alert(a_duplicate==b_duplicate);

Why?

 NaN is not equal to NaN by IEEE float specifications. Thanks to Alex Van Liew for pointing out that this doesn't just apply to Javascript.

NaN isn't equal to NaN by IEEE float specifications. In fact, a quick way to test if you have a NaN in C is to compare it with itself. So this applies to all languages, not just JS.

@AlexVanLiew Interesting. I didn't know that! Ok, changing my answer slightly and adding credit where it is due.

Prolog
areEqual(A, B) :-
    Amod = A,
    Bmod = B,

    Amod = Amod * A,
    Bmod = Bmod * B,

    Amod = Amod - B*B,
    Bmod = Bmod - B*B,

    Amod = Amod / (A-B),
    Bmod = Bmod / (A-B),

    Amod = Amod / A,
    Bmod = Bmod / A,

    Amod == Bmod.

The output when areEqual(4,4) is called (or any other couple of numbers really):
false

Why?

 In Prolog, the operator "=" is not affectation ; it's "Unification". Therefore Amod = Amod * A fails because Amodhas already been unified with A, and thus cannot possibly be unified with Amod * A. Prolog then immediatly stops executing the current rule and returns false.

I think it should be the other way around, you have to output "true" when the two value are different, not "false" when they are equals ^^'

Fantom
a := 3
b := 3
duplicates := [a:b]
duplicates = duplicates.map {it * a}
duplicates = duplicates.map {it - b*b}
duplicates = duplicates.map {it / a-b}
echo(duplicates.join("") |Int a_2, Int b_2 ->Str| {"" +  a_2 + " = " + b_2})

Output:
-3 = 3

Why?

 [a:b] is a map, not a list. Not so sneaky, I know :(

You're supposed to have a equal to b at the end.

The end of the original fallacy is 2 = 1, so the end of any answer here should not be "true"

I was thinking of the BONUS underhanded. Never mind. "Instead of printing the equals sign, you can print out just the two variables (aMod and bMod), and then have code that appears to compare the two variables for equality but in actuality lies that they equal (and prints some form of true)."

C
Classic proof fallacy requires classic C syntax misunderstanding. Sadly I have met some "high-level-only" developers who are convinced C is broken because of results similar to this code. If you know how C works it becomes fairly obvious, but if you saw the code and assumed it was a different language, it might not be.
a,b,LHS,RHS;
main(){
    a=2; b=2;
    LHS=a; RHS=b;

    //multiply both sides by a
    LHS,RHS *= a;
    //subtract b squared from both sides
    LHS,RHS -= b*b;
    //assert that it factors correctly
    if (LHS,RHS != (a+b)*(a-b), b*(a-b)) printf("ERROR!\n");
    //'hard' division, just to be sure the compiler doesn't remove it
    LHS,RHS /=! (a-b);
    //assert that a+a really is b+b
    if (a+a != b+b) printf("ERROR!\n");
    //now just divide them by b
    printf("%d = %d ? ", LHS/b, RHS/b);
    if (RHS = LHS)
        printf("true!");
    else
        printf("false!");
}

Of course it doesn't work quite as well when written more idiomatically with #include <stdio.h> and int's thrown in front of the declarations.

How does it work though?

First note that in c if you 'forget' the int in a declaration, it assumes type int in order to be backwards compatible with k&r c. Next look up the , operator in c and pay attention to its precedence. Next note the = instead of == in the last if statement.

source: Stack Exchange

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

sort: votes


text:
Tips for golfing in Whitespace
What general tips do you have for golfing in Whitespace? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Whitespace (e.g. "remove comments" is not an answer).
Please post one tip per answer.

Remove unnecessary whitespace.

s/[^[:space:]]//g

I'm not entirely sure whether this is a joke question or not, so I hope I don't get mocked for taking it seriously, but...
Tip 1: Don't End Your Program
The spec says that a program should be ended by three line-feeds, [LF][LF][LF], where the first is the flow control IMP, and the next two are the quit command, but many interpreters will just run your code without the proper ending. Saves you 3 characters in any program.

Tip 2: Use The Heap As Little As Possible
I used to use the Heap a lot for counting my loops and such, but realised it was actually extremely inefficient; first pushing an address, getting the current count, taking/adding one, re-pushing address, etc.
Now I just push a value on the stack to act as loop counter, then use the [Space][LF][Tab] swap command to get back to it when I need it. It takes a lot of working in/around, but when you get it it can really reduce your char count.

Lower all characters by a fixed amount and add that right before printing in a loop
Credit to @LukStorms, who uses a similar approach in his answer for the Hello World challenge.
(STN used for Space, Tab, and New-line respectively.)
Pushing the values for letters is always 11 bytes (i.e. pushing the value 65 for the character 'A' is SSSTSSSSSTN; pushing the value 122 for the character 'z' is SSSTTTTSTSN). When you want to output large amount of text this can be expensive. Instead, you can lower the values of all the characters you want to print by a fixed amount, and then in the loop to print them add this fixed amount.
This can be done with the following code (let's assume the fixed value is 100 in this case):

Push all values for the characters (minus the fixed amount 100) in reverse order
NSSN (Create a Label_0; basically starting the loop)

SSSTTSSTSSN (Push the fixed amount 100)
TSSS (Add the top two values of the stack together)
TNSS (Pop and print the now correct value as character)
NSNN (Jump to Label_0; go to the next iteration of the loop)

This will stop the program with an error (which is allowed according to the meta) as soon as it tries to do the Add (TSSS) with nothing more on the stack. I've used this to golf this answer of mine (see items 5 and 6 of Things I did to lower the byte-count).
Whether a fixed amount of 100 is the shortest approach depends on what you are printing. @LukStorm for example used 107 in his Hello World answer.
Note that copying the top value (SNS) for two of the same adjacent characters (like the l in Hello), or copying values from another position can still be used in addition to this to golf more bytes.

Use arbitrary heap addresses
Many interpreters allow you to read/write to arbitrary heap addresses instead of starting at 0 or 1 and counting up. You can duplicate an existing stack value (3 bytes) to use as an address instead of pushing a new value (minimum 4 bytes)

+1. Note that this only applies to non-negative heap-addresses. So if the top of the stack is a negative integer, you can't use it as heap-address.

Jumping to undefined labels ends the program (in some interpreters)
This starts to get into implementation specific behaviour, but I believe this is allowed.
TIO (and possibly other interpreters? doesn't work on ideone at least) will stop execution when an attempt is made to jump to a label that doesn't exist. If you need to do a comparison to break out of a loop this allows you to save bytes by not declaring the break label. (See my comment on Print Invisible Text for an example.)

The empty sequence is a valid label
[LF][Space][Space][LF] (Flow Control - Mark with the label '') creates an empty label that is a valid target for jumps or subroutine calls. This saves a byte when declaring the label and a byte every time it is called.
(Observed in the whitespace answer for implement a truth machine)

The value 0 can be declared as a number with no binary digits
The whitespace tutorial mentions that numbers can be any number of bits/binary digits wide. This means a number with no bits (beyond the required sign bit) is a valid representation of the value 0. [Space][Space][Space][LF] and [Space][Space][Space][Space][LF] both push the value 0 to the stack but the former is one byte shorter.

Copying previous integers can be shorter than creating new ones
(STN used for Space, Tab, and New-line respectively.)
STS + Number argument can be used to Copy the nth item on the stack (given by the argument) onto the top of the stack. This can in some cases be used to save bytes.
For example, in this answer of mine I explained in the 4th item of Things I did to lower the byte-count how copying the 1st (0-indexed) value (STSSTN) is shorter than pushing 12 to create the character 'p' (SSSTTSSN) in the part "pop" of the output. (NOTE: I use the value 12 instead of 112 for the character 'p', because I've applied this other tip of lowering all values by a fixed amount, which we add before printing the characters in the loop.)

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

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


text:
Overlapping circle
You should write a program or function that given an N by N equally spaced square grid and a solid inscribed circle outputs or returns the number of grid squares which are overlapped partially or fully by the solid circle.
0-sized overlaps (i.e. when the circle only touches a line) are not counted. (These overlaps occur at e.g. N = 10.)
Example
N = 8 (64 squares), Slices = 60

Input

An integer N > 0. (The grid wil have N * N squares.)

Output

An integer, the number of solid circle slices.

Examples
(input-output pairs)
Inputs:  1 2 3  4  5  6  7  8  9 10  11  12  13  14  15
Outputs: 1 4 9 16 25 36 45 60 77 88 109 132 149 172 201

This is code-golf so shortest entry wins.

Is it just me or is everyone missing the obvious solution here? Edit: Never mind. At first that looked like a simple N^2.

Pyth, 27 26
-*QQ*4lfgsm^d2T*QQ^%2_UtQ2

Try it online: Pyth Compiler/Executor
I use a 2Nx2N grid and count overlapping 2x2 squares. That is a little bit shorter, since I already know the radius N.
And actually I don't count the overlapping squares. I count the non-overlapping squares of the second quadrant, multiply the number by 4 and subtract the result from N*N.
Explanation for the 27 solution:
-*QQ*4lfgsm^-Qd2T*QQ^t%2UQ2   implicit: Q = input()
                     t%2UQ    generates the list [2, 4, 6, ..., Q]
                    ^     2   Cartesian product: [(2, 2), (2, 4), ..., (Q, Q)]
                              These are the coordinates of the right-down corners
                              of the 2x2 squares in the 2nd quadrant.
       f                      Filter the coordinates T, for which:
        gsm^-Qd2T*QQ             dist-to-center >= Q
                                 more detailed:
          m     T                   map each coordinate d of T to:
           ^-Qd2                       (Q - d)^2
         s                          add these values
        g        *QQ                 ... >= Q*Q
    *4l                       take the length and multiply by 4
-*QQ                          Q*Q - ...

Explanation for the 26 solution:
I noticed that I use the coordinates only once and immediately subtract the coordinates from Q. Why not simply generate the values Q - coords directly?
This happens in %2_UtQ. Only one char larger than in the previous solution and saves 2 chars, because I don't have to substract -Q.

Python 2, 72
lambda n:sum(n>abs(z%-~n*2-n+(z/-~n*2-n)*1j)for z in range(~n*~n))+n+n-1

Ungolfed:
def f(n):
    s=0
    for x in range(n+1):
        for y in range(n+1):
            s+=(x-n/2)**2+(y-n/2)**2<(n/2)**2
    return s+n+n-1

The grid points for an (n+1)*(n+1) square. A cell overlaps the circle if its grid point nearest the center is inside the circle. So, we can count grid points, except this misses 2*n+1 grid points at axes (both for even and odd n), so we correct for that manually.
The code saves characters by using complex distances to calculate the distance to the center and a loop collapse to iterate over a single index.

CJam, 36 35 34 27 bytes
This turned out to be the same algorithm as xnor's, but I wonder if there is any better one.
rd:R,_m*{{2*R(-_g-}/mhR<},,

Code explanation:
rd:R                                "Read the input as double and store it in R";
    ,_                              "Get 0 to input - 1 array and take its copy";
      m*                            "Get Cartesian products";
                                    "Now we have coordinates of top left point of each";
                                    "of the square in the N by N grid";
        {               },,         "Filter the squares which are overlapped by the";
                                    "circle and count the number";
         {        }/                "Iterate over the x and y coordinate of the top left";
                                    "point of the square and unwrap them";
          2*                        "Scale the points to reflect a 2N grid square";
            R(-                     "Reduce radius - 1 to get center of the square";
               _g-                  "Here we are reducing or increasing the coordinate";
                                    "by 1 in order to get the coordinates of the vertex";
                                    "of the square closer to the center of the grid";
                    mhR<            "Get the distance of the point from center and check";
                                    "if its less than the radius of the circle";

UPDATE : Using the 2N trick from Jakube along with some other techniques to save 7 bytes!
Try it online here

Pyth,  44  36
JcQ2L^-+b<bJJ2sm+>*JJ+y/dQy%dQqQ1*QQ

Trying to clean it a bit in case I could shave some bytes.
Explanation
                           Q = eval(input())    (implicit)
JcQ2                       calculate half of Q and store in J
L                          define function y(b) that returns
 ^-+b<bJJ2                 (b - J + (1 if b < J else 0)) ^ 2
s                          output sum of
 m                 *QQ      map d over integers 0..(Q*Q-1)
  +
   >*JJ                      J*J is greater than
       +y/dQy%dQ              sum of y(d / Q) and y(d % Q)
                qQ1          or Q is 1; see below

I have to explicitly check for n = 1, since my algorithm only checks the corner of the square nearest to the center (and none are covered in n = 1).

Octave (74) (66) (64)
Here the octave version. Basically finding all the vertices within the circle and then finding all the squares with one or more valid vertices via convolution.
64 Bytes:
x=ndgrid(-1:2/input(''):1);sum(conv2(x.^2+x'.^2<1,ones(2))(:)>0)

66 Bytes:
x=meshgrid(-1:2/input(''):1);sum(conv2(x.^2+x'.^2<1,ones(2))(:)>0)

74 Bytes:
n=input('');x=ones(n+1,1)*(-1:2/n:1);sum(conv2(x.^2+x'.^2<1,ones(2))(:)>0)

R - 64
function(n)sum(rowSums(expand.grid(i<-0:n-n/2,i)^2)<n^2/4)+2*n-1


text:
Detect the main order based on sub-lists
The question is simple but the answer maybe not!
suppose that you have the following lists that all of them are ordered (not consecutive):
x = ['one', 'two', 'four']
y = ['two', 'three', 'five']
z = ['one', 'three', 'four']

as you can see there is a logic in each of the above lists for example in x we have the following order that is true 'one'<'two'<'four' and also for other sub lists.
So the main list contain all the unique elements from preceding lists that contain ['one','two','four','three','five'] and the task is to find the main ordered list :
['one', 'two', 'three', 'four', 'five']

im not looking for a comprehensive or general answer! because it has not a general answer and it all depend on the number of sub-lists!
So whats your idea for this problem or problems like this?

['one', 'two', 'three', 'four', 'five'] is not 'the' main ordered list, ['one', 'two', 'three', 'five', 'four'] is valid as well. And you didn't specify if strict weak ordering is applicable.

@orlp no its not, i say already that sub-lists are ordered and you must find the main ordered list!

Why down vote??

You said that the main order is based on sub-lists. If the order instead is determined by the values themselves, your entire question makes absolutely no sense and is trivial.

@Kasra Could you specify the way in which the order of the main list is to be inferred from the orders of the parts?

@FUZxxl check out the edit!

@orlp i add more explain on question, pls check out the edit!

@Kasra Then explain where in your lists it is said that 'four' < 'five' and not 'five' < 'four'.

@orlp it doesn't and this is the point of the question you need to find it by the relations between other lists

@Kasra Sorry, I don't understand your question, and I think it's ill-defined. I'm voting to close.

@orlp you can real my answer hope that it becomes helpful!

@Kasra Please tell me why 'five' < 'four' stands in conflict with the constraints imposed by the lists in the question resp. why that can't be the case.

@Kasra Here's an explanation for what everyone's been telling you: In your example, the first list states that 1<2<4, or that 1<2, 1<4, and 2<4. The second one states that 2<3, 2<5, and 3<5. The last one states that 1<3, 1<4, and 3<4. Now we know from the sublists that 1<2, 1<3, 1<4, 2<3, 2<4, 2<5, 3<4, and 3<5. If we have [1,2,3,5,4], it states that 1<2, 1<3, 1<4, 1<5, 2<3, 2<4, 2<5, 3<4, 3<5, and 5<4. The bolded rules contain all of the ones taken from the sublists, so it still matches, even though you're looking for [1,2,3,4,5] (which also matches).

Better not try to think this is a logic puzzle that you can "and ...!" while you are coding. From what I have understood, your reference answer is nowhere like a correct one (and it isn't a complete program either, and is not valid for code-golf).

In general, you might want to use a topological sorting algorithm. This procedure runs in O(n) where n is the sum of the number of elements in each list. Create a directed graph where each node is one of the distinct elements in the input lists. For each pair of elements adjacent in one of the element lists, add an edge between these two elements in the graph from the lesser element to the greater. Finally, topologically sort that graph.

Yes you are close, and this idea could be done with combinations! like my answer but i think using graphs is more efficient!

@Kasra you should not be encouraging non-answers. If you are interested in just the algorithm (or optionally code), remove code-golf tag

Python (182)
I think this might be a bit too long. I might try my hand at a J version of the same algorithm.
from itertools import*
def f(i):
 o=[]
 while len(i)>1:i=[a for a in i if a];o+=[a[0]for a,b in combinations(i,2)if a[0]==b[0]];[j.pop(0)for j in i if j[0]==o[-1]]
 o+=i[0]
 return o

Example:
Input:
i = [['one', 'two', 'four'],
     ['two', 'three', 'five'],
     ['one', 'three', 'four']]
print f(i)

Output:
['one', 'two', 'three', 'four', 'five']

Can you explain about your logic?

@Kasra Sure. What this is doing, is taking the element that is in the first place in 2 or more lists, and removes it, until there are no more elements left.

Try [['one','two','four'], ['two','three','four'],['two','four','five']]. I'm not sure what this question is really asking but an infinite loop in this case is probably not what you wanted. (Oh, unless you are thinking this code-trolling...)

@user23013 code-trolling ? What is this ? 2013 ? Its called underhanded now ;)

Mathematica, 115 bytes
Could probably use some Threads here...
Sort[Union@##,Function[{a, b},Less@@Function[c,Mean[Flatten@DeleteCases[FirstPosition@c/@{##},_Missing]]]/@{a,b}]]&

Written as a pure function, used via *code*[<first list>, <second list>, ...]. I don't see how this is dependent on the number of lists. If there is any ambiguity about the order, it chooses a pseudorandom working case.


text:
Decide existence of total orderings
In this task, we consider arrays of positive integers such as this:
3 18 321 17 4 4 51 1 293 17

The input comprises a pair of such arrays both of arbitrary, possibly distinct, positive length. Determine if a total ordering ≤X ⊂ N × N, where N is the set of positive integers, exists such that both input arrays are in order with respect to ≤X.  Notice that (A ≤X B ∧ B ≤X A) ↔ A = B must hold, that is, two numbers are considered equal under ≤X if and only if they are the same number.
For example, if the input was the pair of arrays
7 2 1 1 4 12 3
9 8 7 2 5 1

then you are supposed to figure out if a total ordering ≤X exists such that

7 ≤X 2 ≤X 1 ≤X 1 ≤X 4 ≤X 12 ≤X 3

and

9 ≤X 8 ≤X 7 ≤X 2 ≤X 5 ≤X 1.

Your submission may be a subroutine or program that receives two arrays (as specified above) of input in an implementation-defined way, computes whether a total ordering ≤X satisfying the demands mentioned above exists and returns one value representing “yes” or a different value representing “no.” The choice of these values is arbitrary, please document them.
You may assume that the input arrays contain no more than 215 - 1 elements each and that each of their elements is in the range from 1 to 215 - 1 inclusive. You may require each arrays to be terminated by a constant sentinel outside of the aforementioned range such as 0. Please specify what sentinel is needed. You may require the lengths of the arrays as additional input if the length cannot be inferred from the arrays themselves (e. g. in languages like C). In addition to the prohibition of standard loopholes, you are not allowed to use topological sorting routines.
This challenge is code golf. The submission with the least amount of characters wins.

For the ease of everyone, could you make some example inputs/outputs to test with?

Can one list be paradoxical and has loops itself?

@user23013 yes.

@orlp Sure. Give me some time please.

@FUZxxl By the way, shouldn't it be < rather than ≤, because there is always a trivial total ordering with ≤, where all elements are equal.

@orlp Equality shouldn't be touched by the different ordering, but let me add a paragraph.

@FUZxxl Only topological sorting is disallowed, regular sorting is allowed, right?

@orlp That is correct.

Pyth, 28 22
L.AmqdSdmfhTmxhkbek^b2

Creates a function y that you can call with a tuple containing the two arrays. Returns "True" if a total ordering exists, "False" if not.
A helper program that defines and calls the above function with stdin:
L.AmqdSdmfhTmxhkbek^b2y,rw7rw7

Try it here.
We first read both arrays. Then we will create all combinations of both arrays. Then for each combination we will assume the first array is authoritative, and check if it's consistent with the second array.

Is the positive integer the same for every true output? It is the intent of the specification that there is one integer representing “yes” and one integer representing no.

@FUZxxl Now it does.

I think you're allowed to take input however you want, which would save a lot of characters. Receives two arrays ... in an implementation-defined way. You can save at least 7 characters.

@isaacg Thanks, I can only save 6 though, because I'll have to use a lambda - I have to give either a subroutine or a program.

J, 36 30 26 bytes
[:*/@,(e.~(-:/:~)@#i.)&>/~

Let's call the two input lists a and b. The function checks (with (e.~(-:/:~)@#i.)) whether

a's elements sorted (in regard to a) in b
a's elements sorted (in regard to a) in a
b's elements sorted (in regard to b) in a
b's elements sorted (in regard to b) in b

Input is a list of two integer vectors.
Result is 1 if an ordering exists 0 otherwise. (Runtime is O(n*n).)
Usage:
   f=.[:*/@,(e.~(-:/:~)@#i.)&>/~

   a=.7 2 1 1 4 12 3 [b=.7 2 1 1 4 12 3 1 [c=.9 8 7 2 5 1
   f a;c
1
   f b;c
0

Try it online here.

How can b not be sorted in regard to b?

@FUZxxl e.g. b=1 2 1 or in my second example b=7 2 1 1 4 12 3 1

Ok... Kind of makes sense.

GolfScript, 25 bytes
:A{:a;A{.a--.{a?}$=!},},!

Try this code online.
Takes an array of two (or more!) arrays on the stack; returns 1 (true) if  every pair of input arrays has a compatible total order, or 0 (false) otherwise.
It works by looping over every possible pair of input arrays (including each array paired with itself), sorting the elements in the first array according to the position where they first occur in the second one (ignoring those that are not found), and checking that the resulting order matches the original.
While this code can take an arbitrary number of input arrays, it's worth noting that it only checks for pairwise consistency.  For example, it returns true for the input [[1 2] [2 3] [3 1]], since any two of the three arrays do have a consistent total order.  That's enough for the two-input case, though, which is all that the challenge requires.
Here's a de-golfed version with comments:
:A         # save input to "A", and leave it on the stack to be looped over
{          # run this outer loop for each input array:
  :a;      #   save this array to "a" (and pop it off the stack)
  A{       #   also run this inner loop for each input array:
    .a--   #     remove all elements not in "a" from this array
    .      #     make a copy of the filtered array
    {a?}$  #     sort it by the first location of each element in "a"
    =!     #     check whether the sorted copy differs from the original
  },       #   select those arrays for which there was a difference
},         # select those arrays for which at least one difference was found
!          # return 1 if no differences were found, 0 otherwise

Ps. It would be possible to trivially save one or two bytes by requiring the input to be given directly in the named variable A, and/or by changing the output format to an empty array for "yes" and a non-empty array for "no".  However, that would seem rather cheesy to me.

This is a neat idea. Maybe I'm doing a J port of this solution.

Ruby, 79
!!gets(p).scan(r=/\d+/){|s|$'[/.*/].scan(r){s!=$&&~/\b#$& .*\b#{s}\b/&&return}}

Expects input to be a two-line file of space-separated numbers. Returns true when an ordering exists, nil if it doesn't.

Please obey the output format: Return one value specifying existence of an ordering or another value specifying nonexistence. These values must be independent of input.

Done. Could technically comply with the spec with one fewer character, but returning nil or false just feels too wrong.

Returning nil or false is absolutely ok.

Haskell, 98 bytes
import Data.List
a%b=intersect(r a)$r b
r l=map head$group l
c l=nub l==r l
x#y=c x&&c y&&x%y==y%x

Returns True or False. Example usage: [7,2,1,1,4,12,3] # [9,8,7,2,5,1] -> True.
How it works: remove consecutive duplicates from the input lists (e.g: [1,2,2,3,2] -> [1,2,3,2]. An order exists if both resulting lists do not contain duplicates and the intersection of list1 and list2 equals the intersection of list2 and list1.

This is a neat idea.


text:
How do I get more Klotski in my life?
I really love sliding tile puzzles, but recently, I haven't had time for them.  Hence, I need a program to give me my fix of sliding-tile puzzles, specifically Klotski puzzles.
Your input will be in the following format:
#######
#001gg#
##.222#
.######

where # represents walls, . represents an open area, g represents the goal, and adjacent numbers represent different blocks.  You can assume that:

There will be no more than 10 blocks
There won't be two blocks with the same number
All blocks will be enclosed by walls
The grid is rectangular
The 0 block is large enough to cover all of the goal squares.
There is a valid solution

You need to return a sequence of moves that will put the 0 block so that it covers all of the goal squares.  Blocks cannot pass through walls or other blocks.  For the above puzzle, an appropriate sequence would be
2L,1R,1R,1D,0R,0R,0R

while represents moving the 2 block 1 square left, the 1 block 2 squares right (on top of the goal) then 1 square down, and then 0 block 3 squares right.
There are actually several sequences that will work for the above problem, and producing any of them is acceptable.  Your solution should be optimal, meaning that it should produce a sequence that solves the puzzle in as few as steps as possible.
The sequence should be printed out as above, but can be comma, newline, or space
separated.  I don't care if there are trailing commas or whitespace.  You should produce the output in reasonable time (maximum 120 seconds on the puzzles below).
Puzzle 1:
..####..
..#00#..
###00###
#......#
#.1122.#
##3124##
.#3344#.
.##55##.
..#gg#..
..####..

Puzzle 2:
######
#1002#
#1002#
#3445#
#3675#
#8gg9#
######

Puzzle 3:
.####.
##1g##
#22g3#
#4255#
#4.56#
#.006#
#7008#
######

Puzzle 4:
.####.
##00##
#.00g#
#.0.1#
#..g2#
######

This is code-golf, so the shortest solution (in bytes) wins!

Just a thought - as I read this, I found something a bit confusing. The goals, being "hidden" were hard to see sometimes. In the example you have, they can be "guessed" with resonable accuracy, however, in the event a block is covering the goal entirely, you should have a way to clearly denote the entire goal. What if: Letters for blocks, Upper case when that spot is on a goal? . for space, * for goal ? everything else same ? would that be more clear ?

@Ditto there is never a case where a block starts on a goal square.  The last example simply has two disconnected goal squares.

Can we assume every input puzzle has a solution?

@orlp yes, I'll add that to the problem statement.

@NathanMerrill To make sure we're doing things correct, could you add the optimal amount of moves for puzzle 1-4?

@orlp, I don't want to post all of them, but the first one should take 87 moves if my program is accurate.

@NathanMerrill If you mean Puzzle 1, then I've got a solution in 70 steps. This is a big problem, seeing as we now have no way of making sure an entry is correct.

@orlp I'm assuming that multiple entries will provide a reasonable consensus of what the shortest solution actually is.

Puzzle 1, 70 steps in 67 seconds. Now golfing

@edc65 Need to optimize more then, question states a limit of 30 seconds.

For puzzle 2 & 3, I dubt an optimal solution can be found in 30 second of less

I'm raising the time limit.  I simply don't want dumb brute forcing solutions.

@edc65 You're wrong, my answer solves all optimally in < 30 seconds.

Why unaccepting? Did you spot some mistake in my answer?

@edc65 My current opinion is that all questions are open, and so no answer should be accepted :)  I upvoted your answer so you at least can redeem some of that rep.

Python, 1761
Kind of burnt out on this question, so couldn't bring myself to golf it. Either way, right now it's the only solution that solves everything within the time limit (longest, #3, takes 27 seconds).
pieces = {}
taken = set()
goals = set()

y = 0
while True:
    try:
        for x, c in enumerate(input()):
            if c == ".": continue
            if c == "g":
                goals.add((x, y))
            else:
                if c in "0123456789":
                    if c not in pieces: pieces[c] = set()
                    pieces[c].add((x, y))
                taken.add((x, y))

        y += 1

    except: break

def translate_comp(coords):
    o = min(sorted(coords))
    return set((c[0] - o[0], c[1] - o[1]) for c in coords)

similar = {}
for piece in pieces:
    k = tuple(translate_comp(pieces[piece]))
    if k not in similar: similar[k] = []
    similar[k].append(piece)

seen = set()
states = [(pieces, taken, ())]
while states:
    state = states.pop(0)
    if not goals - state[0]["0"]:
        names = {
            (-1, 0): "L",
            (1, 0): "R",
            (0, 1): "D",
            (0, -1): "U",
        }

        print(len(state[2]))
        print(" ".join(piece + names[d] for d, piece in state[2]))
        break

    for piece in pieces:
        for d in ((-1, 0), (1, 0), (0, 1), (0, -1)):
            new_pieces = state[0].copy()
            new_pieces[piece] = {(c[0] + d[0], c[1] + d[1]) for c in state[0][piece]}
            new_taken = state[1] - state[0][piece]

            # Collision
            if new_pieces[piece] & new_taken:
                continue

            gist = tuple(frozenset().union(*(new_pieces[piece] for piece in similar_set))
                         for similar_set in similar.values())

            if gist in seen:
                continue

            seen.add(gist)
            new_taken |= new_pieces[piece]
            states.append((new_pieces, new_taken, state[2] + ((d, piece),)))

Wow great! And surely not in the fastest language

It seems a totally different approach and I don't understand Python well. But I like the idea of finding pieces with the same shape. That could reduce a lot the space of visited position in my code. May I borrow it for my solution?

@edc65 Sure. It's not a different approach though, I also do a breadth first search - I just do not look into the same board twice (and blocks with the same shape swapped counts as the same board).

JavaScript (ES6), 446 388
Breadth First Search, so the first solution found is the shortest.
While I still think that's a good solution, it's not good enough.
Even after checking millions of position (runtime several minutes), I could not find a solution for example 2 and 3.
Edit ES6 modified version to overcome the javascript execution time limit. Puzzle 3 solved in 7min, 145 steps. Puzzle 2 solved in 10min, 116 steps
Edit 2 Big speedup, using @orlp's idea of considering equal any two blocks with the same shape (excluding block '0' that is special). This reduces the space of visited positions during BSF. For example, for puzzle 2, any position with block 1,2,3 or 5 exchanged is really the same.
Timing: the longest is puzzle 3, ~20 sec on my laptop.
Use Firefox to play with the new JsFiddle to test.
F=g=>(o=>{
for(u=[i=s=''],v={},h=[],b={},k={'.':-1},l={},
g=[...g].map((c,p)=>c>'f'?(h.push(p),'.'):c<'0'?c:
l[k[c]?k[c]+=','+(p-b[c]):k[b[c]=p,c]=~(c>0),k[c]]=c),
b=Object.keys(b),b.map(c=>k[c]=l[k[c]]);
h.some(p=>g[p]!='0');[s,g]=u[++i])
b.map(b=>[-1,1,o,-o].map((d,i)=>
g.every((c,p)=>c!=b?1:(c=g[p+d])!=b&c!='.'?0:m[g[p-d]!=b?m[p]='.':1,p+d]=b,m=g.slice(0))
&&!v[q=m.map(c=>k[c]||'')+'']?v[q]=u.push([s+b+'LRUD'[i]+' ',m]):0))
})(o=~g.search(/\n/))||s

Outdated

EcmaScript 6 (FireFox) JSFiddle
EcmaScript 5 (Chrome) JSFiddle

Example
#######
#001gg#
##.222#
.######
T(ms) 10,Len7
1R 0R 1R 0R 2L 1D 0R

Puzzle 1
..####..
..#00#..
###00###
#......#
#.1122.#
##3124##
.#3344#.
.##55##.
..#gg#..
..####..

T(ms) 8030,Len70
1U 2U 3U 4U 5U 5L 4D 2R 1R 3U 5U 4L 4D 5R 5R 3D 1L 3D 1L 5L 5U 5U 2D 5R
1R 5R 1R 1D 0D 4D 1D 0D 0L 0L 1U 1U 1U 1U 2L 2L 2U 5D 2R 0R 3R 3R 0D 0D
2L 2L 2L 5U 0U 3U 3U 4U 4U 4R 0D 3L 3U 5D 5L 5L 5L 4U 4U 0R 0D 0D

Puzzle 2
######
#1002#
#1002#
#3445#
#3675#
#8gg9#
######

T(ms) 646485, Checked 10566733, Len 116
8R 3D 4L 7U 9L 5D 7R 4R 3U 8L 9L 5L 7D 4R 6U 9U 8R 3D 6L 4L 2D 7D 2D 0R
1R 6U 6U 3U 3U 9L 8L 5L 7L 7U 2D 4R 5U 8R 8R 5D 1D 6R 3U 9U 5L 1D 1D 9R
9U 4L 4L 2U 8R 7D 2L 8U 7R 2D 4R 3D 6L 9U 4R 1U 1U 2L 8L 8D 4D 0D 9R 6R
3U 9R 6R 1U 5U 2U 8L 8L 7L 7L 4D 0D 6D 6R 1R 2U 2U 0L 6D 9D 6D 9D 1R 2R
3R 5U 5U 0L 9L 6U 4U 7R 8R 7R 8R 0D 9L 9L 6L 6L 4U 8U 8R 0R

Puzzle 3
.####.
##1g##
#22g3#
#4255#
#4.56#
#.006#
#7008#
######

T(ms) 433049, Checked 7165203, Len 145
3L 3U 5U 6U 0U 7U 8L 8L 8L 0D 0R 7R 7U 7R 4D 2D 8R 4D 2D 5L 5L 3D 1R 3R
1D 1D 5R 5U 3L 6U 2U 4U 7R 1D 8L 0L 7D 1R 2R 4U 4U 8U 8U 0L 2D 3D 3L 6L
1U 7D 2R 0R 8D 4D 8D 4D 3L 3U 4U 4R 8U 8U 0L 7L 2D 1D 6R 4R 4U 1L 1L 1U
2U 2L 6D 6D 4R 1R 1U 2U 2L 6L 6U 4D 1R 6U 7U 7U 0R 8D 0R 2D 3D 8D 2D 3D
7L 6D 5D 5L 1L 1U 1L 6U 4U 7R 7R 6D 6L 4L 4U 7U 7U 0U 0U 2R 3D 2R 3R 3D
6D 5D 1D 1L 4L 7L 7U 0U 2U 3R 6D 5D 4D 7L 3R 6R 8R 5D 4D 7D 4L 7D 7D 0L
0U

Puzzle 4
.####.
##00##
#.00g#
#.0.1#
#..g2#
######

T(ms) 25,Len6
1L 1D 1L 1L 0D 0R

To verify your solution (and other solutions), can you post the number of moves you get for each problem I posted?


text:
Evening Commute Solver
I recently moved to an apartment overlooking the inner ring-road of town, and every day, a beautiful scene unfolds. The traffic lights are apparently so confusing (mostly because the Dutch are used to complex intersections, and this one is too simple for them to wrap their heads around), that the intersection invariably winds up as something that must have been the inspiration for a certain game which I shall call Evening Commute for copyright reasons which I will undoubtedly have circumvented by my clever renaming...
Please help my fellow confused Dutchmen, and make sure the red car makes it through the maze during Rush Hour!
Explanation of the game
The goal is to have the red car go to the right of a 6x6 grid (all the way off to the right), while only going straight forward or backward in the lengthwise direction of the car (which is 2 grid points long). For simplicity, the red car is always on the 3rd row.
Of course, there are obstacles: other cars and trucks, with length two. They can be placed horizontally and vertically, and can only move in their lengthwise direction. They cannot pass through other cars. All cars move at 1 grid point per move. The game is won when the red car can move off the grid at the right side of the board.
Explanation of the challenge

Input: a valid game board, which is a 6x6 string with dots . for empty tiles, R's for the red (target) car on row 3, hex numbers 0 through B for cars (length 2), and hex numbers C through F for trucks (length 3). You need not worry about invalid boards; we are dealing with a carnage-free intersection.

Example input:
......
11..22
RRC...
..C..3
..C..3
..66..

As can be seen, numbers can be skipped; furthermore, there may be only trucks or only cars.

Output: a sequence of moves. Each move is identified as XY, with X the identifier of the vehicle, and Y the move, which is one of v^<>, or down, up, left and right respectively for those not familiar with a certain programming language. The move Rx means 'move the red car off the board' and will always indicate the end of the sequence (and only appear at the end, of course!). Since the output is fairly unambigious, any easily human readable sequence of moves will do (newlines, leading spaces are allowed; even a single undelimited string will do; however, you are not allowed to use underhanded tricks on the output). A solution to above problem may be, for example, 6<6<CvRx.

In- and output is, if I made the challenge correctly, case-independent, and newlines can be assumed to be convenient to your language (no need for \r\n hell)
Scoring
The number of bytes (code-golf-style) plus the sum of the number of moves it takes you for each of the following test cases (I tried to calibrate the minimum number of moves to be competitive). Your program should be fully capable of solving any other test case I may throw at it, and hard-coding test cases will give you a penalty of 2^64, but if that's favourable, you might want to rethink your strategy.
11...C
D..E.C
DRRE.C
D..E..
2...33
2.FFF.

112.33
442..C
DRR..C
DEEE.C
D..566
77.588

C.1DDD
C.12..
CRR2..
3344.E
.....E
5566.E

C11.2.
C34.2D
C34RRD
EEE5.D
..6577
88699.

...next code-golf, somebody should make me a Rush Hour image recognition system.

This is really close to being a duplicate of the most recent challenge. The only differences are that your grid and goal are fixed, and that tiles are rectangular and can only move along one axis. Well and of course that you don't require an optimal solution, but BFS will probably still make for the shortest code. Also, providing only 3 test cases is dangerous in that people could hardcode 3 optimal solutions. You should at least threaten to swap out the test cases if you suspect anyone of doing that.

@MartinBüttner Oh dear... And there I was, searching the entire site for duplicates, but not the front page. Also, I meant to include a rule about the test cases, but that must have gotten lost in a rewrite.

Related: http://codegolf.stackexchange.com/questions/48236/how-do-i-get-more-klotski-in-my-life (thanks @MartinBüttner)

In your first example, the truck F does not comply with the spec because it has 4 letters instead of 3. I assume this is a typo as it makes the puzzle impossible. In some of the others the red car can only leave by the left hand side (not the right.) I assume this is allowed.

@steveverrill The first was a typo, the rest I double-checked and they are possible to go off on the right hand side. Of course, the red car may go left a few times to achieve this goal. (I didn't say the game is easy)...

Related: Rush Hour - Solving the game

@sanchises Can you please confirm that 180 moves is the least number of moves for all four puzzle inputs?

Javascript (ES6), 1216 1206 1131 + 180 => 1311 bytes
a=>{a=a.replace(/\s/g,'');b=[];d={};e=[];f=[];g=[];h='.';[].concat.apply([],a.split('.').filter(k=>k).map(k=>k.match(/([^.])(\1*)/g)||k)).forEach(k=>k.length>1?(b.push(k[0]),(k.length<3?g:f).push(k[0])):(!e.includes(k)&&e.push(k),d[k]=d[k]?d[k]+1:1));Object.keys(d).forEach(k=>(d[k]<3?g:f).push(k));j=(l,m,n)=>l.substr(0,m)+n+l.substr(m+n.length);o=(p,q)=>~q.indexOf(p);I=(s,r,c)=>s.charAt(r*6+c)||'@';t=(s,r,c,F,G)=>{k=0;while(I(s,r+k*F,c+k*G)==h)k++;return k};u={};w=[];x={};x=(y,z,A)=>u[y]===[][0]?(u[y]=z,x[y]=A,w.push(y)):0;C=B=>{var z=u[B];return (!z?'':C(z))+x[B]};D=(B,r,c,q,E,F,G,n)=>{r+=E*F;c+=E*G;H=I(B,r,c);if(!o(H,q))return;L=o(H,f)?3:o(H,g)?2:[][0];J=B;for(i=0;i<n;i++){r-=F;c-=G;J=j(J,r*6+c,H);J=j(J,(r+L*F)*6+c+L*G,h);x(J,B,H+(!~F?'v':F?'^':!~G?'>':'<'));B=J}};x(a,null,'');K=!1;while(w.length) {B=w.splice(0,1)[0];if(I(B,2,5)=='R'&&!K){K=!0;break}for(r=0;r<6;r++){for(c=0;c<6;c++){if(I(B,r,c)!=h)continue;nU=t(B,r,c,-1,0);nD=t(B,r,c,1,0);nL=t(B,r,c,0,-1);nR=t(B,r,c,0,1);D(B,r,c,e,nU,-1,0,nU+nD-1);D(B,r,c,e,nD,1,0,nU+nD-1);D(B,r,c,b,nL,0,-1,nL+nR-1);D(B,r,c,b,nR,0,1,nL+nR-1)}}}return C(B).replace(/(R.)+$/,'Rx')}

I followed the algorithm and example from here. Rewriting the algorithm and input in the example to output moves cost a lot of bytes. I'm planning on rewriting the answer using an algorithm specifically designed for outputting moves instead of outputting board states.
Ungolfed:
func = inp => {
    inp = inp.replace(/\s/g, '');

    HORZS = [];
    tVERTS = {};
    VERTS = [];
    LONGS = [];
    SHORTS = [];
    EMPTY = '.';

    [].concat.apply([], inp.split('.').filter(k => k).map(k => k.match(/([^.])(\1*)/g) || k)).forEach(k =>
        k.length > 1 ? (
            HORZS.push(k[0]),
            (k.length < 3 ? SHORTS : LONGS).push(k[0])
        ) : (
            !VERTS.includes(k) && VERTS.push(k),
            tVERTS[k] = tVERTS[k] ? tVERTS[k] + 1 : 1
        )
    );
    Object.keys(tVERTS).forEach(k => (tVERTS[k] < 3 ? SHORTS : LONGS).push(k));

    setCharAt = (str, index, character) => str.substr(0, index) + character + str.substr(index + character.length);

    isType = (entity, type) => ~type.indexOf(entity);

    at = (state, r, c) => state.charAt(r * 6 + c) || '@';

    countSpaces = (state, r, c, dr, dc) => {
        k = 0;
        while (at(state, r + k * dr, c + k * dc) == EMPTY) k++;
        return k;
    };

    pred = {};
    queue = [];
    moves = {};

    propose = (next, prev, move) => pred[next] === [][0] ? (pred[next] = prev, moves[next] = move, queue.push(next)) : 0;

    trace = current => {
        var prev = pred[current];
        return (!prev ? '' : trace(prev)) + moves[current];
    };

    slide = (current, r, c, type, distance, dr, dc, n) => {
        r += distance * dr;
        c += distance * dc;
        car = at(current, r, c);
        if (!isType(car, type)) return;
        L = isType(car, LONGS) ? 3 : isType(car, SHORTS) ? 2 : [][0];
        sb = current;
        for (i = 0; i < n; i++) {
            r -= dr;
            c -= dc;
            sb = setCharAt(sb, r * 6 + c, car);
            sb = setCharAt(sb, (r + L * dr) * 6 + c + L * dc, EMPTY);
            propose(sb, current, car + (!~dr ? 'v' : dr ? '^' : !~dc ? '>' : '<'));
            current = sb;
        }
    };

    propose(inp, null, '');
    solved = !1;
    while (queue.length) {
        current = queue.splice(0, 1)[0];
        if (at(current, 2, 5) == 'R' && !solved) {
            solved = !0;
            break;
        }

        for (r = 0; r < 6; r++) {
            for (c = 0; c < 6; c++) {
                if (at(current, r, c) != EMPTY) continue;
                nU = countSpaces(current, r, c, -1, 0);
                nD = countSpaces(current, r, c, 1,  0);
                nL = countSpaces(current, r, c, 0, -1);
                nR = countSpaces(current, r, c, 0,  1);
                slide(current, r, c, VERTS, nU, -1, 0, nU + nD - 1);
                slide(current, r, c, VERTS, nD, 1,  0, nU + nD - 1);
                slide(current, r, c, HORZS, nL, 0, -1, nL + nR - 1);
                slide(current, r, c, HORZS, nR, 0,  1, nL + nR - 1);
            }
        }
    }

    return trace(current).replace(/(R.)+$/, 'Rx');
}

Example usage and output:
func(`......
11..22
RRC...
..C..3
..C..3
..66..`); // ==> "6<6<CvRx"

func(`11...C
D..E.C
DRRE.C
D..E..
2...33
2.FFF.`); // ==> "1>D^2^Cv3<3<3<CvCvEvF<F<EvRx"

func(`112.33
442..C
DRR..C
DEEE.C
D..566
77.588`); // ==> "3<C^R>R>2vE>E>2v2v2v1>4>D^D^R<R<E<E<E<5^5^5^Cv6<Cv8<Cv3>5^Rx"

func(`C.1DDD
C.12..
CRR2..
3344.E
.....E
5566.E`); // ==> "4>3>CvCvD>2^Rx"

func(`C11.2.
C34.2D
C34RRD
EEE5.D
..6577
88699.`); // ==> "D^9>5vE>E>E>E>Cv1<4^R<3v3vR<5^5^5^5^R>R>E<E<Dv7<Dv9<DvRx"

Python3, 602 bytes + 174 moves = 776
E=enumerate
D=[(0,1),(0,-1),(1,0),(-1,0)]
K=lambda x:{I:x[I]for I in sorted(x)}
def f(b):
 d={(x,y):v for x,r in E(b)for y,v in E(r)}
 u={d[i]:[(X,Y)for X,Y in D if d[i]==d.get((i[0]+X,i[1]+Y))][0]for i in d if'.'!=d[i]}
 q,s=[(d,[])],[K(d)]
 for d,p in q:
  j,k=max([i for i in d if'R'==d[i]])
  if all(d[(j,i)]=='.'for i in range(k+1,len(b[0]))):return p
  for i in u:
   for X,Y in[D[:2],D[2:]][abs(u[i][0])]:
    U=[((x+X,y+Y),(x,y))for x,y in d if d[(x,y)]==i]
    if all(d.get(j)in['.',i]for j,_ in U)and(O:=K({**d,**{t:'.'for _,t in U},**{t:i for t,_ in U}}))not in s:q+=[(O,p+[(i,X,Y)])];s+=[O]

Try it online!

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


text:
Build a top-front-side puzzle solver
A top-front-side puzzle is a puzzle where you are required to construct a 3-D shape of (usually cubic) blocks given three orthogonal views: a top view, a front view, and a side view.
For example, given a top, front, and side view as follows:
Top:        Front:      Side:
. . . .     . . . .     . . . .
. x x .     . x x .     . x x .
. x x .     . x x .     . x x .
. . . .     . . . .     . . . .

In this problem, the side view is taken from the right.

A 2x2x2 cube (with volume 8) would satisfy this solution, but it's doable in volume 4, if we have the following layer structure:
. . . .     . . . .
. x . .     . . x .
. . x .     . x . .
. . . .     . . . .

There are also some unsolvable arrangements. Take, for example:
Top:        Front:      Side:
. . . .     . . . .     . . . .
. . . .     . . x .     . . . .
. x . .     . . . .     . x . .
. . . .     . . . .     . . . .

If the top view says the block is second from the left, there's no way that can match the front view that says the block must be third from the left. So this arrangement is impossible.

Your task is to build a program that, given an arbitrary 4x4 top-front-side puzzle, attempts to solve it in the fewest number of cubes, or declares it unsolvable.
Your program will take as input a series of 48 bits, representing the top, front, and side views. They may be in any format you want (a 6-byte string, a string of 0's and 1's, a 12-digit hex number, etc.), but the order of the bits must map as such:
Top: 0x00   Front: 0x10 Side: 0x20
0 1 2 3     0 1 2 3     0 1 2 3
4 5 6 7     4 5 6 7     4 5 6 7
8 9 a b     8 9 a b     8 9 a b
c d e f     c d e f     c d e f

In other words, the bits go in a left-to-right, top-to-bottom order, in the top, then front, then side view.
Your program will then output either a series of 64 bits indicating the cubes in the 4x4x4 grid that are filled in, or indicate that the grid is unsolvable.

Your program will be scored by running a battery of 1,000,000 test cases.
The test data will be generated by taking the MD5 hashes of the integers "000000" through "999999" as strings, extracting the first 48 bits (12 hexits) of each of these hashes, and using them as input for the top-front-side puzzle. As an example, here are some of the test inputs and the puzzles they generate:
Puzzle seed: 000000   hash: 670b14728ad9
Top:        Front:      Side:
. x x .     . . . x     x . . .
x x x x     . x . x     x . x .
. . . .     . x x x     x x . x
x . x x     . . x .     x . . x

Puzzle seed: 000001   hash: 04fc711301f3
Top:        Front:      Side:
. . . .     . x x x     . . . .
. x . .     . . . x     . . . x
x x x x     . . . x     x x x x
x x . .     . . x x     . . x x

Puzzle seed: 000157   hash: fe88e8f9b499
Top:        Front:      Side:
x x x x     x x x .     x . x x
x x x .     x . . .     . x . .
x . . .     x x x x     x . . x
x . . .     x . . x     x . . x

The first two are unsolvable, while the last one has a solution with the following layers, front to back:
x . . .   . . . .   x x x .   x x x .
. . . .   x . . .   . . . .   . . . .
x . . .   . . . .   . . . .   x x x x
x . . .   . . . .   . . . .   x . . x

There are a total of 16 blocks here, but it can probably be done in less.

Your program's score will be determined by the following criteria, in descending order of priority:

The highest number of solved cases.
The lowest number of blocks required to solve those cases.
The shortest code in bytes.

You must submit and calculate the score by yourself, which requires your program to be able to run through all 1,000,000 test cases.

I learned while trying to generate test cases for this problem that more cases are unsolvable than not. I wonder how this will turn out.

If it's an optimization problem, there should be a time limit, so people don't brute-force it.

The time limit is however long they take to test it. A solution that takes forever to run will never produce a result that can be posted here. That's how all the optimization problems I write work.

State that explicitly then, so people don't get confused. Something like A submission is only valid once the battery is complete.

Related: http://codegolf.stackexchange.com/questions/34547/check-if-three-letters-can-form-a-godel-escher-bach-cube

This is a more general form of that challenge.

I actually thought about asking a continuous version of this after seeing this question on Mathematica.SE. :)

Because I deleted my shown to be incorrect answer, I'd like to copy some comments by Jakube from it to here. The first solvable seed is "00143". The first seed with '6-letter' seeds is "000157", and there are 3326 solvable test-cases out of the million.

So only about 1 in 300 TFS puzzles are solvable. Interesting.

@JoeZ. I get 1 in 200 with my code for counting.

@JoeZ. orlp is right. I had a bug in my md5-to-puzzle conversion. 551 solvable puzzles in 00000-99999 and 5360 solvable puzzles in 000000-999999.

I spent days playing this game once :)

You can remove 4 blocks from the back layer.

cool project. where/how did you come up with this?

It was a game I came across a while back. A Java app, probably still available somewhere on the Internet.

@JoeZ. Is it allowed to exclude optimizations in your golfed submissions that do not affect correctness, compared to the less golfed submission? If not, how would you enforce this?

Python: 5360 test-cases solved using 69519 blocks, 594 bytes
This should be the optimal values.
Approach:
First I'll test if the test-case is actual solvable. I do this by initializing a list of length 64 by ones and set all positions to zero, if there the corresponding pixel of the three views is zero.
Then I simple view at the puzzle from all 3 directions, and look if the views are the same as the input views. If there're equal, the puzzle is solvable (we already found the worst solution), otherwise it's unsolvable.
Then I do a branch-and-bound approach for finding the optimal solution.
Branching: I have a recursive function. The recursion depth tells how many values are fixed already. In each call of the function I call itself twice, if the value at the current index is 1 (this value can be 0 or 1 in the optimal solution), or once, if the value is 0 (it has to be zero in the optimal solution).
Bounding: I use two different strategies here.

I calculate the views from the 3 sides in each function call and look If they still match the input values. If they don't match, I don't call the function recursively.
I keep the best solution in memory. It there already more fixed ones in the current branch than in the best solution, I can already close that branch. Additionally I can estimate a lower bound for the number of activated blocks, which are not fixed. And the condition becomes #number of activated fixed blocks + #lower bound of activated blocks (under the not fixed blocks) < #number of activated blocks in the best solution.

Here's the Python code. It defines a function f which expects 3 lists containing 1s and 0s and returns either 0 (not solvable) or a list of 1s and 0s representing the optimal solution.
S=sum;r=range
def f(t,f,s):
 for i in r(4):s[4*i:4*i+4]=s[4*i:4*i+4][::-1]
 c=[min(t[i%16],f[(i//16)*4+i%4],s[i//4])for i in r(64)]
 m=lambda:([int(S(c[i::16])>0)for i in r(16)],[int(S(c[i+j:i+j+16:4])>0)for i in r(0,64,16)for j in r(4)],[int(S(c[i+j:i+j+4])>0)for i in r(0,64,16)for j in r(0,16,4)])==(t,f,s)
 Z=[65,0];p=[]
 def g(k):
  if k>63and S(c)<Z[0]:Z[:]=[S(c),c[:]]
  if k>63or S(c[:k])+p[k]>=Z[0]:return
  if c[k]:c[k]=0;m()and g(k+1);c[k]=1
  m()and g(k+1)
 for i in r(64):h,R=(i//16)*4+4,(i//4)%4;p+=[max(S(f[h:]),S(s[h:]))+max((R<1)*S(f[h+i%4-3:h]),S(s[h+R-3:h]))]
 g(0);return Z[1]

The code length is 596 bytes/chars. And here's the test framework:
from hashlib import md5
from time import time

N = 1000000
start=time();count=blocks=0
for n in range(N):
 bits = list(map(int,"{:048b}".format(int(md5("{:06}".format(n).encode("utf-8")).hexdigest()[:12], 16))))
 result = f(bits[:16], bits[16:32], bits[32:])
 if result:
  count += 1
  blocks += sum(result)
  print("Seed: {:06}, blocks: {}, cube: {}".format(n, sum(result), result))
print()
print("{} out of {} puzzles are solvable using {} blocks.".format(count, N, blocks))
print("Total time: {:.2f} seconds".format(time()-start))

You can find an ungolfed version of the program here. It's also a little bit faster.
Results:
5360 out of 1000000 puzzles are solvable. In total we need 69519 blocks. The number of blocks varies from 6 blocks to 18 blocks. The hardest puzzle took about 1 second to solve. It's the puzzle with the seed "347177", which looks like
Top:      Front:    Side:
x x . .   x x x x   x . x .
x x x x   x x x x   x x x x
x x x x   x x x x   x x x x
x x . x   x x x x   x . x x

and has an optimal solution with 18 cubes. The following is a few from top for each of the layers:
Top 1:    Top 2:    Top 3:    Top 4:
. . . .   . x . .   . x . .   x . . .
. . x x   . . x .   x . . .   . x x .
. . . .   . . . x   x x x .   . . . .
x x . .   x . . .   . . . x   . . . x

The total running time for all test-cases was about 90 seconds. I used PyPy to execute the my program. CPython (the default Python interpreter) is a bit slower, but also solves all puzzles in only 7 minutes.
You can find the complete output here: The output is self-explanatory. E.g. the output for the puzzle above is:
Seed: 347177, blocks: 18, cube: [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1]

5360 cases solved with 69519 blocks; 923 bytes
This is also optimal. Call with an array of ones and zeroes. Throws a NullPointerException for invalid input. Some efficiency is sacrificed to golf it. It still completes within a reasonable time for all 1000000 test inputs.
import java.util.*;int[]a(int[]a){a b=new a(a);b=b.b(64);return b.d();}class a{List<int[]>a=new ArrayList();List b=new ArrayList();int c;a(int[]d){int e=0,f,g,h,i[]=new int[48];for(;e<64;e++){f=e/16;g=(e%16)/4;h=e%4;if(d[f+12-4*h]+d[16+f+g*4]+d[32+h+g*4]>2){i[f+12-4*h]=i[16+f+g*4]=i[32+h+g*4]=1;a.add(new int[]{f,g,h});c++;}}if(!Arrays.equals(d,i))throw null;b=f();}a(){}a b(int d){if(c-b.size()>d|b.size()<1)return this;a e=c();e.a.remove(b.get(0));e.b.retainAll(e.f());e.c--;e=e.b(d);d=Math.min(e.c,d);a f=c();f=f.b(d);return e.c>f.c?f:e;}a c(){a c=new a();c.a=new ArrayList(a);c.b=new ArrayList(b);c.b.remove(0);c.c=this.c;return c;}int[]d(){int[]d=new int[64];for(int[]e:a)d[e[2]*16+e[1]*4+e[0]]=1;return d;}List f(){List d=new ArrayList();int e,f,g;for(int[]h:a){e=0;f=0;g=0;for(int[]p:a)if(p!=h){e|=h[0]==p[0]&h[1]==p[1]?1:0;f|=h[0]==p[0]&h[2]==p[2]?1:0;g|=h[1]==p[1]&h[2]==p[2]?1:0;}if(e+f+g>2)d.add(h);}return d;}}

Strategy:
I actually used to play this puzzle quite a bit when I was 10. This uses my approach.
Step 1:
Form the cube with the most blocks that fits the given views.
Step 2:
Create a list of removable pieces. (Any piece with that has another piece on the row its in, the column its in, and the beam its in.)
Step 3:
Test every possible way to keep or remove each removable piece. (Via recursive brute-force with pruning.)
Step 4:
Keep the best valid cube.
Ungolfed:
int[] main(int[] bits) {
    Cube cube = new Cube(bits);
    cube = cube.optimize(64);
    return cube.bits();
}

class Cube {

    List<int[]> points = new ArrayList();
    List removablePoints = new ArrayList();
    int size;

    Cube(int[] bits) {
        int i = 0,x,y,z,placed[] = new int[48];
        for (; i < 64; i++) {
            x = i / 16;
            y = (i % 16) / 4;
            z = i % 4;
            if (bits[x + 12 - 4 * z] + bits[16 + x + y * 4] + bits[32 + z + y * 4] > 2) {
                placed[x + 12 - 4 * z] = placed[16 + x + y * 4] = placed[32 + z + y * 4] = 1;
                points.add(new int[]{x, y, z});
                size++;
            }
        }

        if (!Arrays.equals(bits, placed))
            throw null;

        removablePoints = computeRemovablePoints();
    }

    Cube() {
    }

    Cube optimize(int smallestFound) {
        if (size - removablePoints.size() > smallestFound | removablePoints.size() < 1)
            return this;

        Cube cube1 = duplicate();
        cube1.points.remove(removablePoints.get(0));

        cube1.removablePoints.retainAll(cube1.computeRemovablePoints());
        cube1.size--;

        cube1 = cube1.optimize(smallestFound);
        smallestFound = Math.min(cube1.size, smallestFound);

        Cube cube2 = duplicate();

        cube2 = cube2.optimize(smallestFound);

        return cube1.size > cube2.size ? cube2 : cube1;

    }

    Cube duplicate() {
        Cube c = new Cube();
        c.points = new ArrayList(points);
        c.removablePoints = new ArrayList(removablePoints);
        c.removablePoints.remove(0);
        c.size = size;
        return c;
    }

    int[] bits() {
        int[] bits = new int[64];
        for (int[] point : points)
            bits[point[2] * 16 + point[1] * 4 + point[0]] = 1;
        return bits;
    }

    List computeRemovablePoints(){
        List removablePoints = new ArrayList();
        int removableFront, removableTop, removableSide;
        for (int[] point : points) {
            removableFront = 0;
            removableTop = 0;
            removableSide = 0;
            for (int[] p : points)
                if (p != point) {
                    removableFront |= point[0] == p[0] & point[1] == p[1] ? 1 : 0;
                    removableTop |= point[0] == p[0] & point[2] == p[2] ? 1 : 0;
                    removableSide |= point[1] == p[1] & point[2] == p[2] ? 1 : 0;
                }
            if (removableFront + removableTop + removableSide > 2)
                removablePoints.add(point);
        }
        return removablePoints;
    }

    public String toString() {

        String result = "";
        int bits[] = bits(),x,y,z;

        for (z = 0; z < 4; z++) {
            for (y = 0; y < 4; y++) {
                for (x = 0; x < 4; x++) {
                    result += bits[x + 4 * y + 16 * z] > 0 ? 'x' : '.';
                }
                result += System.lineSeparator();
            }
            result += System.lineSeparator();
        }

        return result;

    }
}

Full program:
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Example cube:
 *
 * origin
 * |   ........
 * |  .      ..
 * | . top  . .
 * v.      .  .
 * ........   .  <- side
 * .      .  .
 * . front. .
 * .      ..
 * ........
 *
 *     / z
 *    /
 *  /
 * .-----> x
 * |
 * |
 * |
 * V y
 */

public class PPCG48247 {

    public static void main(String[] args) throws Exception{
        MessageDigest digest = MessageDigest.getInstance("MD5");
        int totalSolved = 0;
        int totalCubes = 0;

        for (int i = 0; i < 1000000; i++){
            byte[] input = String.format("%06d", i).getBytes();

            byte[] hash = digest.digest(input);
            int[] bits = new int[48];

            for (int j = 0, k = 0; j < 6; j++, k += 8){
                byte b = hash[j];
                bits[k] = (b >> 7) & 1;
                bits[k + 1] = (b >> 6) & 1;
                bits[k + 2] = (b >> 5) & 1;
                bits[k + 3] = (b >> 4) & 1;
                bits[k + 4] = (b >> 3) & 1;
                bits[k + 5] = (b >> 2) & 1;
                bits[k + 6] = (b >> 1) & 1;
                bits[k + 7] = b & 1;
            }

            try {
                int[] solution = new PPCG48247().a(bits);
                totalSolved++;
                for (int b : solution){
                    totalCubes += b;
                }
            } catch (NullPointerException ignored){}

        }
        System.out.println(totalSolved);
        System.out.println(totalCubes);
    }

    int[] main(int[] bits) {
        Cube cube = new Cube(bits);
        cube = cube.optimize(64);
        return cube.bits();
    }

    class Cube {

        List<int[]> points = new ArrayList();
        List removablePoints = new ArrayList();
        int size;

        Cube(int[] bits) {
            int i = 0,x,y,z,placed[] = new int[48];
            for (; i < 64; i++) {
                x = i / 16;
                y = (i % 16) / 4;
                z = i % 4;
                if (bits[x + 12 - 4 * z] + bits[16 + x + y * 4] + bits[32 + z + y * 4] > 2) {
                    placed[x + 12 - 4 * z] = placed[16 + x + y * 4] = placed[32 + z + y * 4] = 1;
                    points.add(new int[]{x, y, z});
                    size++;
                }
            }

            if (!Arrays.equals(bits, placed))
                throw null;

            removablePoints = computeRemovablePoints();
        }

        Cube() {
        }

        Cube optimize(int smallestFound) {
            if (size - removablePoints.size() > smallestFound | removablePoints.size() < 1)
                return this;

            Cube cube1 = duplicate();
            cube1.points.remove(removablePoints.get(0));

            cube1.removablePoints.retainAll(cube1.computeRemovablePoints());
            cube1.size--;

            cube1 = cube1.optimize(smallestFound);
            smallestFound = Math.min(cube1.size, smallestFound);

            Cube cube2 = duplicate();

            cube2 = cube2.optimize(smallestFound);

            return cube1.size > cube2.size ? cube2 : cube1;

        }

        Cube duplicate() {
            Cube c = new Cube();
            c.points = new ArrayList(points);
            c.removablePoints = new ArrayList(removablePoints);
            c.removablePoints.remove(0);
            c.size = size;
            return c;
        }

        int[] bits() {
            int[] bits = new int[64];
            for (int[] point : points)
                bits[point[2] * 16 + point[1] * 4 + point[0]] = 1;
            return bits;
        }

        List computeRemovablePoints(){
            List removablePoints = new ArrayList();
            int removableFront, removableTop, removableSide;
            for (int[] point : points) {
                removableFront = 0;
                removableTop = 0;
                removableSide = 0;
                for (int[] p : points)
                    if (p != point) {
                        removableFront |= point[0] == p[0] & point[1] == p[1] ? 1 : 0;
                        removableTop |= point[0] == p[0] & point[2] == p[2] ? 1 : 0;
                        removableSide |= point[1] == p[1] & point[2] == p[2] ? 1 : 0;
                    }
                if (removableFront + removableTop + removableSide > 2)
                    removablePoints.add(point);
            }
            return removablePoints;
        }

        public String toString() {

            String result = "";
            int bits[] = bits(),x,y,z;

            for (z = 0; z < 4; z++) {
                for (y = 0; y < 4; y++) {
                    for (x = 0; x < 4; x++) {
                        result += bits[x + 4 * y + 16 * z] > 0 ? 'x' : '.';
                    }
                    result += System.lineSeparator();
                }
                result += System.lineSeparator();
            }

            return result;

        }
    }

}


text:
Reverse every word in a line in vim
Your task is to build a vim script or provide a sequence of keystrokes that will operate on a single line of text with up to 140 printable ASCII characters (anywhere in a file, with the cursor starting anywhere in the line) and reverse every space-separated string in the sentence while keeping the strings in the same order.
For example, the input:
roF emos nosaer m'I gnisu a retcarahc-041 timil no siht noitseuq neve hguoht ti t'nseod evlovni .rettiwT RACECAR

should return:
For some reason I'm using a 140-character limit on this question even though it doesn't involve Twitter. RACECAR

The script with the fewest characters, or the sequence of the fewest keystrokes, to achieve this result is the winner.

Can the cursor be anywhere on the line or can we assume it's at the start? (Or somewhere else?) Will this be just one line in a larger text file or the only contents of the file? Will it be only printable ASCII or could the be tabs, say? If so, to tabs delimit words or not? Also, does this have to be limited to vim? Wouldn't the challenge make just as much sense in emacs or some other scriptable editor?

The cursor can be anywhere on the line. This will be a single line in a larger text file. Only printable ASCII characters will appear on the line. For the purposes of this question it's vim only, but feel free to post the Emacs equivalent.

"For the purposes of this question it's vim only" seems as arbitrary a language-restriction as posting a normal code golf challenge and asking only for answers in C. (And I don't seem to be alone with this opinion.)

I admit that it seems that way, but I haven't seen anybody else post editor-agnostic puzzles, and vim-golf is generally a much larger community than, say, emacs-golf or nano-golf (the latter of which returns something entirely different when put into a Google search).

"I haven't seen anybody else post editor-agnostic puzzles" doesn't mean you can't be the first person to make it better. Also it's not like you will lose the "much larger community" of vim golfers by making your challenge inclusive of other editors, too.

I had a feeling you might say that. If you can post an Emacs solution that bests the winning vim solution, I'll consider it.

Why is RACECAR not reversed?

Because it's a palindrome. Try reversing it yourself.

Wow, I'm stupid. Derp.

@orlp Lol. I thought you were joking.

@mbomb007 Sometimes your brain freezes for a second :)

Is the space at the end of the line intentional? If the space isn't there I can get it pretty short.

@Caek It would be unfair to me to remove it now - I had to work around it too. Changing the requirements during a challenge (assuming the change isn't necessary) basically invalidates all work by previous competitors and is frowned upon.

@Caek: Even if the space weren't there, your program should be able to work around initial and terminal spaces.

@orlp I didn't mean to change the question I was just curious.
JoeZ: noted.

28 25 24 keystrokes
:se ri<CR>^qqct <C-r>"<Esc>f l@qq@q

Recursive macro, I assume that Ctrl-r counts as one keystroke.
The hardest part was to make sure the macro stays on the same line and does not destroy the rest of the file.

You could use cE instead of ct , if it wasn't ending the macro. But you can use W instead of f l to save 2 strokes.

@Caek Wrong x2. Guess what cE does when the cursor is at the beginning of a retcarahc-041? And guess what W does when we're at the end of the line?

Note the capital E. lowercase e would go until the dash, capital E would go until the next space. I just tried it to confirm.

try: :set ri<Enter>^qqct <C-r>"<Esc>W@qq@q for 23.

@Caek That won't work. And regarding E, I know what it does. I was referring that cE<C-r><Esc> would turn a retcarahc-041 into 140-character a, AKA it would swap the words.

Ah, I only tried it with the space at the end. Without a space, like in your example, I admit it didn't work. Can also save a character with :se ri

24 keystrokes
ma:s/ /\r/g
V'a:!rev
gvJ

I know this question is very old, but I love vimgolf so I couldn't not post an answer on one of the few vim-specific challenges on the site. Plus this solution is tied with Orlp's.
Just like Orlp said, the hardest part was making sure that the rest of the buffer was unmodified. If it weren't for that restriction, we could simply do:
:s/ /\r/g
!{rev
V}J

(19 keystrokes) but we need a little bit more to keep it buffer-safe. This assumes a unix environment.


text:
Remove an unobstructed rectangle
This image was made by overlaying 7 differently colored rectangles on top of each other:

The black and maroon rectangles are unobstructed, that is, no other rectangles are above them.
Write a program that takes in an image such as this and remove any single unobstructed rectangle, outputting the resulting image.

Example
If you ran your program on the image above and kept re-running it on the output, it might progress like this.
Run 1 - Black removed (could have been maroon):

Run 2 - Maroon removed (only choice):

Run 3 - Yellow removed (only choice):

Run 4 - Blue removed (could have been green):

Run 5 - Green removed (only choice):

Run 6 - Brown removed (only choice):

Run 7 - Red removed (only choice):

Any additional runs should produce the same white image.
Hopefully Stack Exchange has not lossily compressed any of these
images.

The image will always have a white background and each rectangle will be a unique RGB color that isn't white.
You can assume that the image can always be interpreted as a set of overlapping rectangles. Specifically, you can assume that, for a particular color, the pixel with that color closest to the top of the image is part of the top edge of that color's rectangle. The same holds for the bottom, left, and right edges.
So, for example, in this image, the top edge of the red rectangle would be just below the bottom edge of the yellow rectangle, as the the orange rectangle covered the old red top edge:

In this image, the red rectangle could be removed first (along with black/maroon/orange/gray):

When the order of the lower rectangles is ambiguous, you can give them any order.
For example, the left image here could become the middle or the right:

The output should not have paradoxical overlaps (so making it with the painter's algorithm should be possible). So in this image (thanks user23013), it would have to be green under the orange rectangle:

Additional Details

The image and rectangles may have any dimensions.
The rectangles may touch the image border.
There may be up to 2563 - 1 rectangles.
If the input is entirely white, the output should be as well.
You may use image libraries.
The input should be the image file name or the raw image data. It can come from stdin or the command line.
The output can be written to the same or another image file, spewed raw to stdout, or simply displayed.
Any common lossless truecolor image file format is allowed.

The submission with the fewest bytes wins.

A test case (and the flipped version).

Technically there's nothing in the requirements that says that the output may not have paradoxical overlaps. Should it be added, or are both interpretations of the test case OK?

Can you please clarify “truecolor”?

@FUZxxl RGB with 8 bits per channel

@JanDvorak I had hope that was implied but, you're right, it's unclear, so I've added a note about it.

Can rectangles be a single pixel?

@NathanMerrill Yes, any (nonzero) dimensions

CJam, 241 bytes
(with newlines removed.)
rri:Hri:Vri:Q[q~]3/_Qa3*a+_|$W%:Pf{\a#}:AH/:B0ff*
P,,[AHAW%HBz:+_W%V\V]2/
ff{~@@f=/::|1#}0Ua4*t:R;
P0f<
V{H{BI=J=_2$=
0R{"I>! I+V<J>! J+H<"4/+4/z{~~}%:&1$*\)}%);2$-|t
}fJ}fI
[P,{_La#\1$0t1$f-}*;;]
{:TR=2/~\~V\-,>\f{\_3$=@~H\-,>{Tt}/t}~}/
:~Pf=:~
~]S*N

It uses the ppm file format. Example usage (using ImageMagick):
convert IVYvE.png -compress none ppm:-| (time /path/to/cjam-0.6.4.jar 1.cjam) |display

Well, it is too long and too slow... Runs about a minute for the example.
I resized the test cases (and added some others) to make testing easier.

It seems the color space informations are lost so the colors are slightly different.

Python, 690 651 610 606 594  569 bytes
The script reads the image name from stdin.
It detects the edges of every rectangles, sort them by the number of different colors they contain (the unobstructed rectangles contains only 1 color, and then appear at the end of the list)
This list is used to redraw an image. The redraw order is decided by choosing the permutation of the list that would generate an output image that have the least pixel difference with the input.

from PIL import Image as l,ImageDraw as D;from itertools import*;O,R,I,Z,k=[],range,l.open(raw_input()),{},lambda x:-x[1];(W,H),Q=I.size,I.load()
for i,j in product(R(W),R(H)):
 c=Q[i,j]
 if c in Z:x,y,X,Y=Z[c];Z[c]=[x,y,max(X,i),max(Y,j)]
 else:Z[c]=[i,j,0,0]
for n in permutations(sorted([(c,len({Q[g] for g in product(R(x,X),R(y,Y))})) for c,(x,y,X,Y) in Z.items()],key=k)[1:-1]):o=l.new(I.mode,I.size,0xFFFFFF);[D.Draw(o).rectangle(Z[c],fill=c) for c,_ in n];O+=[(o,sum(abs(a-b) for t,T in zip(I.getdata(), o.getdata()) for a,b in zip(t,T)))]
max(O,key=k)[0].show()

Java - 1483 bytes
I'm not a great code golfer, let that be clear; so the verbosity is not entirely Java's fault ;-) Nevertheless, this seemed like a really fun challenge. I've solved it in a way that - I think - is a bit boring and verbose, but hey. It works, it's (relatively) fast and, especially, it was fun!
The idea is as follows:
Check each pixel from starting at the top left corner all the way to bottom right. Is it a white pixel? Ignore. Is it coloured? Cool, let's keep track of it and try to determine its boundaries (top left, top right, bottom left, bottom right).
Once that's done, check each rectangle's area. Does it contain a different colour than the rectangle's colour? Then find out what rectangle belongs to that colour and update that overlapping rectangle's z-index by 1.
And finally, draw all rectangles while taking the z-indices into account. It works actually like a z-index you know from CSS and other 3D stuff. The rectangles with the lowest z-index are drawn first, the highest z-index last.
import java.awt.*;import java.awt.image.*;import java.io.File;import java.util.*;import java.util.List;import javax.imageio.*;class A{class R{public Color k=new Color(-1);public int z;public Point a;public Point b;public Point c;public Point d;}public static void main(String[]w)throws Exception{BufferedImage i=ImageIO.read(new File(w[0]));List<R>r=new Vector<R>();for(int y=0;y<i.getHeight();y++){for(int x=0;x<i.getWidth();x++){Color c=new Color(i.getRGB(x,y));if(c.getRGB()==-1){continue;}R t=null;for(R s:r){if(s.k.equals(c)){t=s;}}if(t==null){t=new A().new R();r.add(t);}if(t.a==null){t.a=new Point(x, y);t.b=new Point(x, y);t.c=new Point(x, y);t.d=new Point(x, y);t.k=new Color(c.getRGB());}if(x<t.a.x){t.a.x=x;t.c.x=x;}if(x>t.b.x){t.b.x=x;t.d.x=x;}t.c.y=y;t.d.y=y;}}for(R s:r){List<Color>b=new Vector<Color>();for(int y=s.a.y;y<=s.c.y;y++){for(int x = s.a.x;x<=s.b.x;x++){if(i.getRGB(x, y)!=s.k.getRGB()){Color a=new Color(i.getRGB(x,y));boolean q=false;for(Color l:b){if(l.equals(a)){q=true;}}if(!q){b.add(a);} else {continue;}R f=null;for(R k:r){if(k.k.equals(a)){f=k;}}f.z=s.z+1;}}}}Collections.sort(r,new Comparator<R>(){public int compare(R a, R b){return a.z>b.z?1:(a.z==b.z?0:-1);}});for(int ii=r.size();ii>0;ii--){BufferedImage d=new BufferedImage(i.getWidth(),i.getHeight(),2);Graphics2D g=(Graphics2D)d.getGraphics();for(R s : r.subList(0, ii)){g.setColor(s.k);g.fillRect(s.a.x,s.a.y,s.b.x-s.a.x,s.c.y-s.a.y);}ImageIO.write(d,"png",new File(r.size()-ii+".png"));}}}

The complete code which is a bit - and that's an understatement ;-) - written more clearly, can be found here: http://pastebin.com/UjxUUXRp
Also, now that I see dieter's submission, I could have made some parts easier. It's not really necessary to find the rectangle whose colour is overlapping another rectangle. I could indeed just count the number of 'invading' colours.


text:
Shortest Substring Index
I'm a lazy but efficient person, as many of you probably are as well. So, whenever I'm doing something I want to do it with minimal effort. Which is why I'm asking you to solve this problem for me.
What I have here is a document of sorts. On every line of this document is a single word or short phrase. The document is not sorted, but that's ok I know where everything is. I could use some help finding things faster, and for that I need a second list. This is where you come in. For every line of text in this document, I need some identifier. Something I can CTRL+F, but it can't be longer than absolutely necessary for getting that one result.
Example input:
(blank)
an apple
spiderman 3
7pm pick up laundry
tequila
fake mustache
dishes on wednesday
banana
biscuits
(blank)

Example output:
ap,3,7,q,f,w,ba,bi

I'm going to repeat myself here, to make sure we're on the same page:

The input is an unformatted text file containing a list of items, separated by line breaks. I have it here in .txt format, it's called "STUFF.TXT"
The first and last line of the document are empty. Every other line contains an entry of length >0.
The file contains only alfanumeric characters (all lower case), spaces, and line breaks.
Desired output is a list of identifiers, in the same order as my original list.
I don't want more than one search word for every list item. If there are multiple answers, pick one, I don't care which. In the above example I picked 'ap' for an apple, but you could have picked 'n ', ' a', 'pp', 'pl' or 'le'. Not 'an', because that's in banana.
I can assure you, the file is never empty, and it never contains duplicates.
If necessary, you can match on the line terminator. But that's a last resort only to be used when there's no other way to distinguish between list items (e.g. 'apple' and 'apples').

Standard loopholes are not allowed. Also, this is code golf so shortest code wins.
One more example:
(blank)
ban
any
king
bean
yen
rake
raki
bar
(blank)

And its output:
ban,ny,g,be,ye,ke,aki,ar

@CarpetPython it has to be the shortest possible. Spaces can be in input and output, added that to the question.

Can we also use newlines at the beginning of the search term, if one string is a suffix of another?

@MartinBüttner yes. That's why the document starts and ends with a blank line, so you have those newlines at the start and end of each list item.

I'm pretty sure this problem is NP-complete. I think I can construct a reduction of the exact cover problem to this one.

@VisualMelon yes, I added this to the question.

@FUZxxl I can put a line length or line count restriction on the text file if necessary, but your query doesn't have to resolve within finite time for all imaginable input sizes. If the query works for files as large as the examples included in the question, that's good enough for me. Bigger is better, I suppose.

It's more that you won't see any creative solutions as there is no better solution than brute force.

Sooo. You're looking for a golfed perfect hash generator

Pyth, 39 bytes
Lsm.:bdtUbKfT.zj\,mhf!}Yjb-Kk+yky++bkbK

Bruteforces all subsets of every string in increasing length and checks if that string occurs inside any other. If that doesn't work, it will do the same except for all subsets of \nstring\n.

I get a bad type combination error when I test this. https://pyth.herokuapp.com/?code=Lsm.%3AbdtUbKfT.zj%5C%2Cmhf!%7DYjb-Kk%2Byky%2B%2BbkbK&input=%0Aban%0Aany%0Aking%0Abean%0Ayen%0Arake%0Araki%0Abar%0A

@freekvd Heroku must have an outdated version of Pyth, because calling .: with first type string and second type int is not an error. Try using Pyth from the repo: https://github.com/isaacg1/pyth