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

These features can however also apply to any other animal.
Specification
Given an image of an animal (technically can be anything), you must apply the Downgoat properties to it.
Border pixels are the outer most pixels of the image.
The background color is defined as the most common color in the border pixels. When that color is interpreted as an (r, g, b, a) color, with each channel from [0, 256), the background is defined as the area where the every channel of the given pixels' is within 50 of the "background color".
The process:

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

Rules

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

Examples
Input:
Output:

Input:

Output:

Input:
Output:

Input:
Output:

Input:
Output:

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

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

-1 First test case not an animal -_-

-1ˢᵗ test case not an animal either.

@Geobits okay, fine fixed

Not a fan of demon dennis

You could eliminate the worry about whether it's an animal by changing "animal" to "avatar" in the title and throughout the question.

What is the point of enforcing the font to use? The only thing this does is penalize languages where changing font takes more bytes

@Fatalize because image input can be taken as an array of channels, I want this to be more complex than some basic array transformation and drawing a vertical line in the middle and calling that a one

@Downgoat You have removed the penguin image. Does this mean that the program does not need to work with image formats having an "alpha" channel?

The background definition makes this way harder than necessary. You could also have said to provide a B/W image, or transparent/non-transparent. I thought about heading for a CSS3 solution, but like that it's simply impossible.

I suspect that your example "output" for the dennis-the-menace image was generated from a different (better, without JPEG artifacts) original.  I was not able to avoid getting JPEG artifacts in my result.

@GlennRanders-Pehrson you shouldn't have a problem with the fuzziness if the threshold is implemented correctly. Perhaps check that?

Well, "fuzz 8%" works better but still not an exact repro of your result.  It appears that in that case my script was using 50/65k rather than 50/255 as the threshold.

ImageMagick 7.0.3 + bash + sed, 379 bytes
M=magick K=\#232323 P='-chop x%[fx:u[0].h-2]-0+1'
$M $1 -depth 8 ppm:W;$M W $P T;$M W -rotate 90 -shave 1x $P L
C=`$M T L +append -statistic mode +0 txt:-|sed -e "1d;s/.*#/#/;s/ .*//;q"`
$M W -background $K -flatten -fill $K -fuzz 20% -opaque $C +fuzz -fill \#FC0D1B +opaque $K -flip -pointsize %[fx:.282*min\(u[0].w,u[0].h\)] -fill white -draw 'gravity center text 0,0 "-1"' x:

Ungolfed
# Make aliases for things we'll use repeatedly
M=magick K=\#232323 P='-chop x%[fx:u[0].h-2]-0+1'

# Copy the input file to a PPM file
$M $1 -depth 8 ppm:W

# Extract the border pixels into "T" (top and bottom), and "L" (left and right)
# PPM files, removing the ends from the "L" because they were already counted
$M W $P T;$M W -rotate 90 -shave 1x $P L

# Put the borders into one strip and reduce to a txt image of the "mode"
# color on stdout, then convert the first pixel to hex format string "C"
C=`$M T L +append -statistic mode +0 txt:-|sed -e "1d;s/.*#/#/;s/ .*//;q"`

# Make background "#232323" and compose transparent pixels against it
# Convert any pixels with color within "fuzz" distance of background to #232323
# Convert any remaining pixels to "#FC0D1B"
# Flip the image vertically
# Determine pointsize for text, 1/5 of min(w,h). 1 pixel == 1.44 points
# Draw text "-1" centered on the image
# Display the result to an X window

$M W -background $K -flatten                     \
-fill $K -fuzz 20% -opaque $C                    \
+fuzz -fill \#FC0D1B +opaque $K                  \
-flip                                            \
-pointsize %[fx:.282*min\(u[0].w,u[0].h\)]       \
-fill white -draw 'gravity center text 0,0 "-1"' \
x:

I'm getting a quite different answer for the dennis image, probably because ImageMagick's "-fuzz" computes a sphere with diameter of 2N units in rgb coordinates while the rules call for computing a cube with sides of 101 units in rgb coordinates. Varying the "fuzz" helped some.  Also, the JPEG artifacts in the original seem to be interfering with the conversion.

I'm not familliar with imageMagick, so this may be very uneducated, but can you replace the #0000 color code with simply #0?

No, #0 doesn't work.  Neither does #000 because that's opaque black and we need transparent black here.

The bug that I mentioned, # ImageMagick 7.0.1 through 7.0.3-7 fails here has been reported to the IM developers and is fixed in version 7.0.3-8.

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

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

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

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

Ungolfed version:
#include <windows.h>

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

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

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

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

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

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

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


text:
Quine Anagrams! (Robbers' Thread)
This is the robbers' thread. For the cops' thread, click here.
Cops' Task
For the cops' thread, click here.
Robbers' Task

Find an uncracked submission on the cops' thread. (A submission may only be cracked once.)
Unscramble the code to find a working quine.
Post an answer on the robbers' thread. Include the language, the byte count, the user who posted the scrambled code, a link to that answer, and the unscrambled code.

Here is an example of a robber submission:

Python, 29 bytes, Oliver
_='_=%r;print _%%_';print _%_

Scoring
The user with the most cracks will be the winner of this section.

What is up with the link?!

Vim, 22 bytes, Loojvo
qtiqtqx0l"tp^V^[^[qx0l"tp

Try it online!
Explanation:
qt                  " Start recording in register 'q'
  i                 " Enter insert mode
   qtqx0l"tp        " Enter this string
            ^V^[    " Enter a literal 'esc' character
                ^[  " Exit insert mode
                  q " Stop recording

At this point, the buffer looks like this:
qtqx0l"tp^[

And the cursor is on the last column (the 'esc' key).
x                   " Delete the esc character
 0l                 " Move to the second character on this line
   "tp              " And paste register 't'

Underload, 20 bytes, ais523
(:a~*(*S)):a~*(*S)*S

Try it online!
Explanation
The basic quine in Underload is this:
(:aSS):aSS

Here is how it works:
                                  Stack:               Output:
(:aSS)      # Push string.        (:aSS)
      :     # Duplicate.          (:aSS) (:aSS)
       a    # Wrap in (...).      (:aSS) ((:aSS))
        S   # Print.              (:aSS)               (:aSS)
         S  # Print.                                   (:aSS):aSS

The first issue was to reduce the number of S we need, because we've only got 3 for use here. We can do this by making use of swapping (~) and concatenation (*):
(:a~*S):a~*S

Here, instead of printing twice, we put the (...) version and the plain version of the string together and print that only once.
The bigger puzzle is how print an odd number of * and S. I'm not even sure how I actually arrived at the final solution, but it turns out that we can do this by putting the tail of the output in a separate string. That string itself is duplicated in the first string, but the contents are not, which gives us the extra occurrences of * and S we need. Here is a breakdown of the final solution:
                        Stack:                       Output:
(:a~*(*S))              (:a~*(*S))
          :             (:a~*(*S)) (:a~*(*S))
           a            (:a~*(*S)) ((:a~*(*S)))
            ~           ((:a~*(*S))) (:a~*(*S))
             *          ((:a~*(*S)):a~*(*S))
              (*S)      ((:a~*(*S)):a~*(*S)) (*S)
                  *     ((:a~*(*S)):a~*(*S)*S)
                   S                                 (:a~*(*S)):a~*(*S)*S

MATL, 20 bytes, Luis Mendo
'wo&GzL0fk'tl#DwI-ch

Try it online!
I've never used MATL before, so my understanding may be slightly off, but this is basically how it works:
'wo&GzL0fk' This is a string representation of the code, offset by 3
t           Creates a duplicate copy of the string
l#D         Adds quotes to the second copy
w           Swap the unquoted version to the top of the stack
I-          Offset the characters in that version by 3
c           Convert back to characters
h           Join with the quoted string

Impressive! Especially considering this is your first Matlab answer. Well done!

Python 2, 54 bytes, Loojvo
l= ['l=', ';print l[0],`l`,l[1]'] ;print l[0],`l`,l[1]

Had a hard time finding it, as I have basically almost never touched python

Retina, 20 bytes, Martin Ender

\)1S*`\(?
\)1S*`\(?
Try it online
I found this simply by messing around attempting to create a quine. I found the "shorter quine" that he hinted at first (or a similar one, at least), simply by experimenting (14 bytes):

\)1S*`
\)1S*`
Try it online
It took me about half an hour to an hour. Very clever, Martin!

Nice job! :) There are about 6 variants of the 14-byte quine, I think.

@MartinEnder I started by trying to shuffle your anagram around, but that wasn't helping, so I started with the known quine and modified that.

@MartinEnder Did you add the new quine to the "Golf you a quine" question?

Yes.

JavaScript ES6, 49 bytes, Mama Fun Roll
function f(){return    `${(((((k=>f+'')(f)))))}`}

Pretty much the standard JS function quine, with a little obfuscation.

><>, 36 bytes, Erik the Golfer
'''000**rd3*:::?!;od0.!!+..233??dfrr

Try it online!
I'm quite sure that this is not the intended solution. However, ><> quines make it fairly easy to get rid of most unwanted characters, except the '. Fortunately, the : made it quite easy to take care of those as well.
Explanation
'''                                    Push everything except these quotes onto the stack.
   000**                               In effect, pushes a zero.
        r                              Reverse the stack.
         d3*                           Push 39 (the quote character).
            ::                         Make two copies. The stack now holds
                                       a null-terminated representation of the
                                       entire code.
                                       The print loop begins here...
              :                        Duplicate top of stack.
               ?!;                     Terminate if zero.
                  o                    Otherwise, print.
                   d0.                 Jump back to position 13, i.e. the
                                       beginning of the print loop.
                      !!+..233??dfrr   Unused characters.

Yep, not the indended solution :P Well done.

JavaScript, 147 bytes, jrich
+function e(){window[(w=[``>``]+``)[i=9/9]+w[i+i]+"ert"]('+'+e+'()');"  +./;;;;;=======>[]````````ccddddddeeeeeeeefiinnnnoooooorrrrrrrsttuwwx{}"}()

With all those extra chars, this is definitely not the intended solution :-)

Yep, definitely not the intended solution, but I'm impressed! Good job!

@jrich The trickiest part was figuring out how to balance the brackets and parens so that I wasn't using any extra ones. I see you didn't realize that the (false+"")[1] trick would be useful here? ;)

Didn't think about it to be honest... my solution was... a little more difficult to say the least

Haskell, 86 bytes, Laikoni
y!r=r:y:r:[y]>>=id;main=putStr$[succ$'!']!"y!r=r:y:r:[y]>>=id;main=putStr$[succ$'!']!"

Nice idea to get the " via succ$'!' (ascii char after !). There were some missing chars to get them the usual way, i.e. implicitly via show or print.

Befunge, 15 bytes, James Holderness
<:0:+1_@#%9,:g-

Try it online!
Explanation
The catch here is that the loop terminates when the current character is divisible by 9, which is only the case for -. Hence, that needs to go at the end.
<                 Run code from right to left.
              -   There will always be 2 zeros on top of the stack at this
                  point, and this just reduces them to 1 zero.
             g    Get the character at the coordinates given by the top
                  two stack values, (0, 0) initially.
           ,:     Print a copy of that character.
         %9       Modulo 9.
      _@#         Terminate if that is 0.
    +1            Increment the x coordinate.
   :              Duplicate it.
 :0               Push two zeros.

PHP, 110 bytes, Oliver
<?php $x='<?php $x=0; echo strtr($x, array(chr(39).$x.chr(39)));'; echo strtr($x, array(chr(39).$x.chr(39)));

Thanks, I had fun and the strtr([]) trick was a new one for me that I hope will save me some bytes in the future.

Jelly, 3 bytes, Erik the Golfer
”ṘṘ

Try it online!
There aren't really that many options... (Plus, this is the standard quine.)

Python 2, 105 bytes, Erik the Golfer
a='a=%r;print a%%a ###(((())))**-01::@@@@@[[]]gggiiirrr~';print a%a ###(((())))**-01::@@@@@[[]]gggiiirrr~

It's just the standard Python string formatting quine...

Ruby, 53 bytes, wat
puts <<ENDIT*2,"ENDIT"
puts <<ENDIT*2,"ENDIT"
ENDIT

Just a modification of the standard heredoc quine:
puts <<2*2,2
puts <<2*2,2
2

source: Stack Exchange

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

sort: votes


text:
Self compressing/decompressing program
Challenge:
Write a lossless encoder/decoder that is able to compress its own source code.
Usage:
progname encode
Encodes data provided on the standard input, writes the encoded representation of the data to the standard output.
progname decode
Decodes data produced by progname encode. Reads the encoded data from the standard input, writes the decoded data to standard output. Must perfectly restore the original data.
Example:
$ progname encode < /usr/include/stdlib.h > encoded
$ progname decode < encoded > decoded
$ diff -qs /usr/include/stdlib.h decoded
Files /usr/include/stdlib.h and decoded are identical

Requirements:

It must be a real lossless encoder/decoder for all inputs - encoding any data and then decoding it must produce the original data.
If the input is identical to the program's source code, the size of encoded output must be less than the size of the input.

Score:
Size of the program's source code + the size of its encoded source code
Clarification:
The program doesn't need to be a general purpose compressor/decompressor. That's why its commands are called encode/decode. It may also use existing tools predating this question.

The problem I see is that it doesn't necessarily have to be good compression. You could simply map the program input to a single byte and all other inputs to themselves, and get a crazy good score. Basically like lenpeg but recognizing it's own source code instead

@DrMcMoylex That's OK. I intentionally didn't add restrictions preventing such an implementation.

It has been put on hold while I was writing my answer. I think this is a perfectly valid and interesting challenge.

NodeJS, 330 bytes: b=";c=require('fs').readFileSync('/dev/stdin','ascii');p=process.argv[2][0];s='b='+JSON.stringify(b)+b;process.stdout.write(p=='e'?((c==s)?'':'0'+c):(c?c.slice(1):s))";c=require('fs').readFileSync('/dev/stdin','ascii');p=process.argv[2][0];s='b='+JSON.stringify(b)+b;process.stdout.write(p=='e'?((c==s)?'':'0'+c):(c?c.slice(1):s))

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


text:
Taxicab in San Francisco
You are a taxicab driver in San Francisco. As is typical of taxicab drivers, you are navigating a grid where the only valid directions you can move are the left, right, up, and down. However, San Fransisco is very hilly so the distance between two adjacent intersections is not necessarily the same. More specifically, the distance between an intersection at altitude a and an adjacent intersection at altitude b would be 1 + |a - b|. Your goal is to find all the shortest paths from your origin at the top left of the map to your destination at the bottom right.
Input
A two-dimensional grid of integer altitudes in whichever format is most convenient (two-dimensional array, one-dimensional array with width and/or height, etc.).
Output
A sequence of directions to travel to arrive at the bottom right corner of the input from the top left in the shortest distance possible given the distance between two adjacent intersections of altitudes a and b is given by the formula 1 + |a - b|. If there are multiple solutions output all solutions.
Though I use U, D, L, and R for up, down, left, and right in the examples below your program may use any four distinct strings to represent the directions so long as it is consistent with them in and across all inputs.
Examples
Input:
0 3 0 0 0
0 2 0 2 0
0 0 0 3 0
Output:
D D R R U U R R D D

Input:
3
Output:
<empty>

Input:
11 11 11
11 11 11
11 11 11
Output:
R R D D
R D R D
R D D R
D R R D
D R D R
D D R R

Input:
7 8 1 -1 0
4 4 6 -1 7
3 4 4  2 8
2 5 2 -1 2
Output:
D R D R R D R
D R D R D R R

This is code-golf so the answer with the shortest byte count wins.

Are the altitudes always less than 10 ? (they are on the examples, but will they always be?)

@Dada the altitudes are not necessarily less than 10 (they can also be negative), I have updated the examples accordingly.

when i saw that this post was active i was suuuuuuper excited - i thought someone had posted an answer in taxi ! maybe one day

JavaScript (ES6), 228 212 200 194 bytes
a=>w=>(B=1/0,(F=(r,p,s,b=a[p])=>p-a.length+1?1/b&&([...a[p]='RDUL'].map((c,d)=>d|p%w<w-1&&d-3|p%w&&F(r+c,P=p+[1,w,-w,-1][d],s+1+Math.abs(b-a[P]))),a[p]=b):R=s>B?R:s<B?(B=s,r):R+' '+r)('',0,0),R)

Input
One-dimensional array a and width w in currying syntax (a)(w)
Output
A space-separated list of solutions such as "DRDRRDR DRDRDRR"
Formatted and commented
a => w => (                            // given an array 'a' and a width 'w'
  B = 1 / 0,                           // B = best score so far, initialized as +Infinity
  (                                    //
    F = (                              // F = recursive function with:
      r,                               //   - r = current path (string)
      p,                               //   - p = current position in grid
      s,                               //   - s = current score
      b = a[p]                         //   - b = backup of current cell
    ) =>                               //
    p - a.length + 1 ?                 // if we haven't reached our destination:
      1 / b && (                       //   if the current cell is valid:
        [...a[p] = 'RDUL']             //     invalidate the current cell
        .map((c, d) =>                 //     for each possible direction:
          d | p % w < w - 1 &&         //       check right boundary
          d - 3 | p % w &&             //       check left boundary
          F(                           //       do a recursive call with:
            r + c,                     //         - new direction appended to the path
            P = p + [1, w, -w, -1][d], //         - updated position
            s + 1 + Math.abs(b - a[P]) //         - updated score
          )                            //
        ),                             //
        a[p] = b                       //     restore current cell value
      )                                //
    :                                  // else:
      R = s > B ?                      //   if the current score is worse than B:
        R                              //     keep the previous solution
      : s < B ?                        //   if the current score is better than B:
        (B = s, r)                     //     update best score / store path as new solution
      : R + ' ' + r                    //   if it's just as good: append path to solution
  )('', 0, 0),                         // initial call to F with r = '', p = 0, s = 0
  R                                    // return solution
)                                      //

Test cases

let f =

a=>w=>(B=1/0,(F=(r,p,s,b=a[p])=>p-a.length+1?1/b&&([...a[p]='RDUL'].map((c,d)=>d|p%w<w-1&&d-3|p%w&&F(r+c,P=p+[1,w,-w,-1][d],s+1+Math.abs(b-a[P]))),a[p]=b):R=s>B?R:s<B?(B=s,r):R+' '+r)('',0,0),R)

console.log(f([
  0, 3, 0, 0, 0,
  0, 2, 0, 2, 0,
  0, 0, 0, 3, 0
])(5));

console.log(f([
  3
])(1));

console.log(f([
  11, 11, 11,
  11, 11, 11,
  11, 11, 11
])(3));

console.log(f([
  7, 8, 1, -1, 0,
  4, 4, 6, -1, 7,
  3, 4, 4,  2, 8,
  2, 5, 2, -1, 2
])(5));

Python3, 383 bytes
E=enumerate
def f(b):
 d,D={(x,y):v for x,r in E(b)for y,v in E(r)},{}
 q=[(0,0,0,'',[(0,0)])]
 for x,y,c,m,p in q:
  if(x,y)==(len(b)-1,len(b[0])-1):D[c]=D.get(c,[])+[m];continue
  for U,X,Y in[('R',0,1),('L',0,-1),('U',-1,0),('D',1,0)]:
   if(n:=(x+X,y+Y))not in d:continue
   C=1+abs(d[(x,y)]-d[n])
   if n not in p and(D=={}or C<=min(D)):q+=[(*n,c+C,m+U,p+[n])]
 return D[min(D)]

Try it online!

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


text:
Identify the IP address
Identify whether an IP address is internal, global, link-local, or reserved.
Input should be an IPv4 address in decimal octets separated by periods.
Output should be 0 for link-local (RFC 3927), 1 for internal (RFC 1918), 2 for global IPs (Internet), and 3 for otherwise reserved addresses.
All these address types are described in RFC 5735:

Global and Other Specialized Address Blocks

0.0.0.0/8 - Addresses in this block refer to source hosts on "this"    network.  Address 0.0.0.0/32 may be used as a source address for this
host on this network; other addresses within 0.0.0.0/8 may be used to
refer to specified hosts on this network ([RFC1122], Section
3.2.1.3).
10.0.0.0/8 - This block is set aside for use in private networks.    Its intended use is documented in [RFC1918].  As described in that
RFC, addresses within this block do not legitimately appear on the
public Internet.  These addresses can be used without any
coordination with IANA or an Internet registry.
127.0.0.0/8 - This block is assigned for use as the Internet host    loopback address.  A datagram sent by a higher-level protocol to an
address anywhere within this block loops back inside the host.  This
is ordinarily implemented using only 127.0.0.1/32 for loopback.  As
described in [RFC1122], Section 3.2.1.3, addresses within the entire
127.0.0.0/8 block do not legitimately appear on any network anywhere.
169.254.0.0/16 - This is the "link local" block.  As described in    [RFC3927], it is allocated for communication between hosts on a
single link.  Hosts obtain these addresses by auto-configuration,
such as when a DHCP server cannot be found.
172.16.0.0/12 - This block is set aside for use in private networks.    Its intended use is documented in [RFC1918].  As
described in that    RFC, addresses within this block do not
legitimately appear on the    public Internet.  These addresses can be
used without any    coordination with IANA or an Internet registry.
192.0.0.0/24 - This block is reserved for IETF protocol assignments.    At the time of writing this document, there are no
current    assignments.  Allocation policy for future assignments is
given in    [RFC5736].
192.0.2.0/24 - This block is assigned as "TEST-NET-1" for use in    documentation and example code.  It is often used in conjunction with
domain names example.com or example.net in vendor and protocol
documentation.  As described in [RFC5737], addresses within this
block do not legitimately appear on the public Internet and can be
used without any coordination with IANA or an Internet registry.  See
[RFC1166].
192.88.99.0/24 - This block is allocated for use as 6to4 relay    anycast addresses, in [RFC3068].  In contrast with previously
described blocks, packets destined to addresses from this block do
appear in the public Internet.  [RFC3068], Section 7, describes
operational practices to prevent the malicious use of this block in
routing protocols.
192.168.0.0/16 - This block is set aside for use in private networks.    Its intended use is documented in [RFC1918].  As
described in that    RFC, addresses within this block do not
legitimately appear on the    public Internet.  These addresses can be
used without any    coordination with IANA or an Internet registry.
198.18.0.0/15 - This block has been allocated for use in benchmark    tests of network interconnect devices.  [RFC2544] explains that this
range was assigned to minimize the chance of conflict in case a
testing device were to be accidentally connected to part of the
Internet.  Packets with source addresses from this range are not
meant to be forwarded across the Internet.
198.51.100.0/24 - This block is assigned as "TEST-NET-2" for use in    documentation and example code.  It is often used in conjunction with
domain names example.com or example.net in vendor and protocol
documentation.  As described in [RFC5737], addresses within this
block do not legitimately appear on the public Internet and can be
used without any coordination with IANA or an Internet registry.
203.0.113.0/24 - This block is assigned as "TEST-NET-3" for use in    documentation and example code.  It is often used in conjunction with
domain names example.com or example.net in vendor and protocol
documentation.  As described in [RFC5737], addresses within this
block do not legitimately appear on the public Internet and can be
used without any coordination with IANA or an Internet registry.
224.0.0.0/4 - This block, formerly known as the Class D address    space, is allocated for use in IPv4 multicast address assignments.
The IANA guidelines for assignments from this space are described in
[RFC3171].
240.0.0.0/4 - This block, formerly known as the Class E address    space, is reserved for future use; see [RFC1112], Section 4.
The one exception to this is the "limited broadcast" destination
address 255.255.255.255.  As described in [RFC0919] and [RFC0922],
packets with this destination address are not forwarded at the IP
layer.
4.  Summary Table
Address Block       Present Use                Reference
0.0.0.0/8           "This" Network             RFC 1122, Section 3.2.1.3
10.0.0.0/8          Private-Use Networks       RFC 1918
127.0.0.0/8         Loopback                   RFC 1122, Section 3.2.1.3
169.254.0.0/16      Link Local                 RFC 3927
172.16.0.0/12       Private-Use Networks       RFC 1918
192.0.0.0/24        IETF Protocol Assignments  RFC 5736
192.0.2.0/24        TEST-NET-1                 RFC 5737
192.88.99.0/24      6to4 Relay Anycast         RFC 3068
192.168.0.0/16      Private-Use Networks       RFC 1918
198.18.0.0/15       Network Interconnect
                    Device Benchmark Testing   RFC 2544
198.51.100.0/24     TEST-NET-2                 RFC 5737
203.0.113.0/24      TEST-NET-3                 RFC 5737
224.0.0.0/4         Multicast                  RFC 3171
240.0.0.0/4         Reserved for Future Use    RFC 1112, Section 4
255.255.255.255/32  Limited Broadcast          RFC 919, Section 7
                                               RFC 922, Section 7

Rules

Standard loopholes apply.
This is code-golf, shortest answer wins.

For those of us who do not know this stuff, how do the single values here identify "blocks" and what values are "in" said blocks? Also which blocks are (2) and which are (3) (or are all non RFC3927/1918 (3) and everything else (2))?

@JonathanAllan The number after the slash in the IP address is the bitmask. http://networkengineering.stackexchange.com/questions/3697/the-slash-after-an-ip-address-cidr-notation

That does not help me - I did not even think we would have that part in the input - "decimal octets separated by periods".

@JonathanAllan That's not for the input - it is the explanation of the blocks.

So the effective test for each block is to check if the bitwise-and of the slash-identified number of leading 1s matches the dot-delimited-identified value?

@JonathanAllan I guess...

Let us continue this discussion in chat.

Could you please reformat the summary table so that it exactly shows what should return 0, what should return 1, etc.

@orlp The summary table is actually directly taken from the linked document.

This question should have some example inputs and outputs.

JavaScript, 261 207 bytes
v=>["169.254","10.|172.1[6789].|172.2\\d.|172.3[01]|192.168","x","0.|127|192.0.[02].|192.88.99|198.1[89].|198.51.100|203.0.113|2[345]\\d|22[^0123]"].reduce((a,x,i)=>v.search(x.replace(/\./g,"\\."))==0?i:a,2)

Readable version
v=>[
    "169.254",
    "10.|172.1[6789].|172.2\\d.|172.3[01]|192.168",
    "x",
    "0.|127|192.0.[02].|192.88.99|198.1[89].|198.51.100|203.0.113|2[345]\\d|22[^0123]"]
    .reduce((a,x,i)=>v.search(x.replace(/\./g,"\\."))==0?i:a,2)

Create an array with matching patterns, loop through the patterns and compare to input.  Return 0,1,2,3 as appropriate.
Edit: Fix bugs and streamline

I think you can save 18 bytes using (a,x,i)=>x.every(t=>v.search("^"+t.replace(".","\.")))?a:i.

V('172.16.0.1') => 2 (INVALID),V('172.17.1.1')=> 2 (INVALID), basically the whole "172.16" block does not work correctly. Have you tested this ?
There is a syntax error - "\d" not escaped properly, resulting in a literal "d" match, and the patterns for this block are simply not correct too.

172.16.0.1 returns 1 if you use the short version.  I made an error when copying and pasting the "readable" version.  As for the patterns being wrong, I made a mistake when calculating that subnet.

The mask for 172.16.0.0 is 12 bits, which means that the address range is: 172.16.0.0-172.31.255.255 (i.e. 172.16.X, 172.17 (!) e.t.c.)).
Test: I("172.17.0.1") => 2 (should be 1 instead)

(you can compute the address ranges at https://www.iplocation.net/subnet-calculator, to avoid doing that by hand)

@Neil thanks for the hint about .search

looks good now (downvote revoked)

ES6 (Javascript), 204, 200, 182, 178 bytes
EDIT: Rewritten hex padding code, removed extra parenthesis, -4 bytes
EDIT: RegExp cleanup, streamline the result extraction, shorten the hex conversion code
EDIT: Refactored result extraction to bring it down to 200 bytes
Note, this should be pretty easy to shorten even further, by compressing the RegExp (as I never really bothered to do this)
Golfed
a=>/(^(?:00|7f|c0(?:5863|0{3}[02])|c6(?:1[23]|3364)|cb0071|e|f))|(^a9fe)|(^0a|^ac1|^c0a8)|./.exec(a.replace(/\d+./g,o=>(o|256).toString(16).slice(1))).reverse().findIndex(a=>a)^1

Explanation
IP addresses are shorter to write and easier to match, when converted to hexadecimal form, as CIDR masks tend to end on the 4 bit boundaries (with an exception of 198.18.0.0/15).
E.g.
0A000000-0AFFFFFF //10.0.0.0/8
AC100000-AC1FFFFF //172.16.0.0/12
C0A80000-C0A8FFFF //192.168.0.0/16

can be matched as
/^0a|^ac1|^c0a8/

Test
I=a=>/(^(?:00|7f|c0(?:5863|0{3}[02])|c6(?:1[23]|3364)|cb0071|e|f))|(^a9fe)|(^0a|^ac1|^c0a8)|./.exec(a.replace(/\d+./g,o=>(o|256).toString(16).slice(1))).reverse().findIndex(a=>a)^1;

T=(i,o)=>{
  block=I(i);
  console.log(i,(block==o)?"OK":"NOT OK");
}

T("0.0.0.0",3)
T("10.0.0.0",1)
T("11.0.0.0",2)
T("127.0.0.0",3)
T("169.254.0.0",0)
T("169.253.0.0",2)
T("172.16.0.0",1)
T("172.31.0.0",1)
T("172.32.0.0",2)
T("192.0.0.0",3)
T("192.0.2.0",3)
T("192.88.99.0",3)
T("192.168.0.0",1)
T("192.167.0.0",2)
T("198.18.0.0",3)
T("198.51.100.0",3)
T("203.0.113.0",3)
T("224.0.0.0",3)
T("239.255.255.255",3)
T("240.0.0.0",3)
T("255.255.255.255",3)
T("241.0.0.1",3)
T("151.101.192.71",2)

Batch, 356 bytes
@echo off
set s=%1
if not %s==%s:.=% %0 %s:.= %
if %1.%2==169.254 exit/b0
if %1==10 exit/b1
if %1.%2==172.16 if %3 lss 32 exit/b1
if %1.%2==192.168 exit/b1
if %1==0 exit/b3
if %1==127 exit/b3
if %1 geq 224 exit/b3
for %%a in (18 19)do if %1.%2==192.%a exit/b3
for %%a in (192.0.0 192.0.2 198.51.100 203.0.113)do if %1.%2.%3==%%a exit/b3
exit/b2

Takes input as a command-line parameter and returns the result by setting the errorlevel.

The "224.0.0.0/4 Multicast" range has a 4 bit mask, which means that it covers the addresses from 224.0.0.0 – 239.255.255.255 (and you only match 224). The same for "240" block.

@zeppelin Ah, so in fact anything >= 224 counts?

Yep, correct, everything > 224 is either multicast, reserved or broadcast, all of which map to the same output value.


text:
Add weight to one side of a see-saw to balance it
Balancing Act
A see-saw (supposedly from the French 'ci-ça', meaning 'this-that') forms a third of the holy trinity of playground equipment, along with the similarly ubiquitous slide and swing. A see-saw is in perfect balance if, and only if, the sum of the moments on each side are equivalent. A see-saw can therefore be balanced by adding a specific quantity of weight to the side with the lower moment sum; achieving this is your goal for this challenge.
Challenge
Your challenge is to take a depiction of a see-saw as input and output it again, with weight added to one end of the see-saw to balance it.
Input
Your program must take, in any reasonable format, an ASCII see-saw such as the following:
100             100
-------------------
         ^

The first line contains two numbers, each representing weights on the see-saw. Exactly one weight is present on each side, each acting on the very end of its side of the plank. Weights are guaranteed to be integers, and always align with their corresponding end of the plank. These numbers will never overlap the fulcrum (^).
The second line represents the 'plank' of the see-saw. Each dash (-) represents an equal length to each other dash, with the sole exception of the dash directly over the fulcrum (^), which has no length.
The third line represents the fulcrum of the see-saw. This fulcrum is marked by the only character that is not a space on this line, a circumflex ('^'). The fulcrum can be positioned anywhere along the length of the plank in a valid input so long as enough space is left so that the numbers representing weights do not overlap the fulcrum in either the input or the output.
The input is guaranteed to have three lines, and have no white-space prior to or after the characters that constitute the see-saw (excepting, of course, the third line, which requires it).
Output
For output, the same see-saw depiction should be printed to stdout, but with one (and only one) of the weights replaced with a larger weight, so as to balance the see-saw. Inputs are guaranteed to make this possible using integers alone. Therefore, weights must be shown without decimal points or any other similar notations. If your language does not use stdout you should go by community / meta consensus on output. Trailing newlines are fine but any other changes to the depiction format are probably not OK.
Exemplification
Test Inputs and Corresponding Outputs
Input 1
12                22
--------------------
             ^

Output 1
12                26
--------------------
             ^

Input 2
42       42
-----------
     ^

Output 2
42       42
-----------
     ^

Input 3
3             16
----------------
        ^

Output 3
14            16
----------------
        ^

Input 4
1                56
-------------------
    ^

Output 4
196              56
-------------------
    ^

Reference Implementation - Python 3
# Takes a list of strings as input
def balance_seesaw(lines):
    weights = [int(w.strip()) for w in lines[0].split()]

    length  = len(lines[1])
    pivot   = lines[2].find("^")
    left_length    = pivot
    right_length   = length - 1 - pivot

    left_torque  = weights[0] * left_length
    right_torque = weights[1] * right_length

    if left_torque > right_torque:
        weights[1] = left_torque // right_length
    elif right_torque > left_torque:
        weights[0] = right_torque // left_length

    weights = [str(w) for w in weights]

    string_gap = " " * (length - sum(len(w) for w in weights))
    lines[0] = weights[0] + string_gap + weights[1]

    print("\n".join(lines))

balance_seesaw(["1                56",
                "-------------------",
                "    ^              "])

Rules

This is code-golf, so the shortest code wins counted in bytes. Check meta if counting bytes is awkward in your language.
Standard rules/loopholes apply.
Input must be taken in a reasonable format. A non-exhaustive list of appropriate formats are given as follows:

A single string with lines separated by newline characters
A list of strings, each string represented a line
A 2D Array or Matrix of characters

Related Challenges

Balance a set of weights on a see-saw - Proposed Aug 2015 by samgak

Is there any reason you want output to stdout? We generally allow functions to output via their return value.

@corvus_192 I envisaged this as a 'display' type challenge, like an ASCII art one or 'Draw a flag' or whatever. A list of strings as output isn't really 'human friendly' as such. If a language has no inbuilt stdout support other output forms are allowed though.

Welcome to PPCG! Nice first challenge. (and props for using the sandbox on it, too!)

@TimmyD thanks, it's been good fun seeing how people tackle the problem.

05AB1E, 60 51 50 49 47 45 bytes
Saved 10 bytes thanks to Emigna and 1 byte thanks to Adnan.
All input lines must have the same amount of characters.
#õKD³'^¡€gDŠ*¬-Os÷1®‚*D0›*+¬?DJg²gs-ð×?¤,²,³,

#                                             Split the first input line on spaces
 õKD                                          Push [first weight, second weight] twice
    ³'^¡€gD                                   Push both lengths from either side of the pivot '^' as an array [left, right] twice
           Š*                                 Multiply by weights to get torque
             ¬-O                              Evaluate rightTorque-leftTorque
                s÷                            Divide by each side's length to get the weights to add: [deltaLeft, deltaRight], keep integer values
                  1®‚                         Push [1,-1]
                     *D                       Yield [deltaLeft, -deltaRight]
                       0›*                    Replace the negative value by 0
                          +                   Add weights: old + deltaWeight
                           ¬?                 Print left weight
                             DJg              Take the size of total decimal representation
                                ²gs-ð×?       Print a string composed of filler spaces between both new weights
                                       ¤,     Print right weight and newline
                                         ²,³, Print the last two lines from input (unchanged)

Try it online!
There should be a rule of thumb, like "if your 05AB1E code is longer than 40 bytes, you're probably doing it wrong".
It seems so golfable, any idea is welcome!

Good answer! It's pretty unintelligible to me, but it passes every test I could think of :)

For a start ¬s¤s\‚ can be õK.

I'm currently editing my answer to add an explanation, but it's still like dark magic. I'm waiting for a two-byte long answer in another esolang. And welcome by the way :) .

@Osable Well, I checked esolang wiki and I'm pretty sure there isn't a language in which an empty file balances an ASCII see-saw.... but one can never be certain!

kD²g->(‚ can be ¡€g if you add the missing spaces in bottom row of the test case

Thanks for golfing my code, I'm not very familiar with accented letters and euro symbol in 05AB1E

You have a typo: tumb

Thanks for the explanation. I see it's quite similar to the reference algorithm (no bad thing) but there's some clever tricks in there too. Something about 05AB1E means that it seems to promote cleverer answers than some other golfing languages - it's perhaps my favourite especially when there's an included explanation.

With 05AB1E I'm used to avoiding conditional statements as often as possible because they generally increase code size. So I have to think about other ways to mathematically encompass the if/else statements. However I haven't tried to use such statements - like in the reference algorithm -. It might have been shorter but it isn't very likely. I'm no 05AB1E pro though, I always write code as it comes to my mind.

Nice answer! You can replace 31SÍ with 1®‚ :)

Thanks! I didn't know that register_c evaluates to -1 when left uninitialized.

Can you perhaps also replace /         ï with ÷.?

Correct! I don't know why I didn't think about it when I wrote the code. Now we are below 50 bytes!

I also just figured out that at least two bytes can be saved if the first line is built in order, instead of first computing the filler spaces. It saves two swap operations.

JavaScript (ES6), 136
Probably not working in Chrome,as it uses destructured assignment and default parameters.
Note that the standard JS output method alert is particularly unsuited for the task, because of the proportional font used.
(m,n,o,[p,q]=m.split(/ +/),l=n.length,h=o.indexOf`^`,g=l-h-1,c=p*h<q*g?q*g:p*h)=>alert((c/h+o).slice(0,h)+(o+c/g).slice(h-l)+`
${n}
`+o)

Less golfed
( m,n,o, // input parameters, 3 strings
  // default parameters used as local variables
  [p,q] = m.split(/ +/), // left and right weight
  l = n.length, // bar length
  h = o.indexOf`^`, // left length
  g = l-h-1, // right length
  // p*h left torque
  // q*g right torque
  c = p*h<q*g ? q*g : p*h // max torque
) => alert( (c/h+o).slice(0,h)+(o+c/g).slice(h-l) // o has enough spaces to pad left and right
     +`\n${n}\n`+o )

Test

F=
(m,n,o,[p,q]=m.split(/ +/),l=n.length,h=o.indexOf`^`,g=l-h-1,c=p*h<q*g?q*g:p*h)=>alert((c/h+o).slice(0,h)+(o+c/g).slice(h-l)+`
${n}
`+o)

function go()
{
  var [a,b,c]=I.value.split('\n')
  if(a.length!=b.length || a.length < c.length)
    alert('The strings are not of the same length')
  else
  {
    if (a.length > c.length)
      c = c+' '.repeat(a.length-c-length)
    F(a,b,c)
  }
}
<textarea id=I>3             16
----------------
        ^      </textarea>
<button onclick='go()'>go</button>

According to http://kangax.github.io/compat-table/es6/, Chrome 54 fully supports default parameters and destructuring, so I don't think you have to worry too much.

Works on Chrome for me.

Perl, 149+2=151 characters
Requires command line options -p0 (this gives me a 2 byte penalty on top of the 149 bytes in the program itself).
($_,$b,$c,$d)=map length,/(\d+) +(.+)
(-+)
( +)/;$r=$d/($c-$d-1);($x,$y)=$1*$r>$2?($1,$1*$r):($2/$r,$2);$_="$x$,$y",$,.=$"while$c>length;$\="
$3
$4^"

Explanation:

The -p0 switch reads the entire input up to the first NUL byte or EOF. This problem doesn't allow NULs, so we'll get the entire input in the variable $_ that's used for regexes, etc., by default.
We start with a regex that parses the input (between the first and second slash). There are several ways we could parse the first weight (e.g. .+?), but I can't get it below 3 characters so I may as well use the obvious \d+. The second number is at the end of the line so it can be parsed as .+ (2 characters). The central line is used to determine how wide the scales are; it's parsed as -+ (many other representations would work). The spaces before the caret on the last line are  +. Once the caret (or indeed any nonspace) appears, we ignore the rest of the input.
Perl automatically captures the four groups of the regex (first weight, second weight, row of hyphens, spaces before the caret) into $1, $2, $3, $4. Giving a regex as an argument to map additionally uses an array of those groups as the array to map over. We therefore take their lengths; this is a convenient way to store the lengths of $3 and $4 without having to write length twice. We also overwrite $_ with the length of $1; we don't really care about the value of this (the number of digit in the left input is kind-of useless), but the fact that it's short ($_'s length is now the number of digits in the number of digits in the first weight, which is necessarily very small compared to the width of the scales).
We measure the ratio $r in which the scales are divided.
$1*$r>$2 checks to see which side is heavier. We store the new weights in $x and $y; these have very simple calculations once the ratio of weights is known.
We concatenate $x, $,, and $y into $_ to produce the top row, then keep adding spaces ($" contains a single space by default, and is shorter than a literal space ' ' would be) onto $, until it's the same length as the middle row (i.e. has length $c). (I chose the variable $, as it's a built-in variable that can safely be changed in this context and starts empty by default.) As length operates on $_ by default, we don't need to give it an argument explicitly. I used a Yoda conditional because it needs considerably less disambiguating syntax to parse correctly.
Finally, I redefine Perl's idea of the output line ending convention ($\) to contain the rest of the set of scales (which is the same as in the input, so I can simply use $3 and $4 directly to produce the bulk of it). Note that this means that there's no trailing whitespace on the third line; adding it would make the program slightly longer and doesn't seem to serve any purpose, so I left it out.
At the end of the program, the -p switch triggers again; this time, it outputs $_ followed by a "newline" ($\). Because I redefined the output newline, these two implicit prints generate the new set of scales between them (although as a side effect, there's no newline on the output).
The -p switch now tries to read input again, but we already slurped the entire file, so it reads EOF and ends the program.

PHP, 212 209 205 bytes
probably golfable
preg_match("#(\d+)( +)(\d+)\s*(-+)[\r\n]+( +)\^#",$s=$argv[1],$m);echo preg_replace("#\d+( +)\d+#",(($r=$m[3])>($q=$m[1]*($p=strlen($m[5]))/(-$p-1+$e=strlen($m[4])))?$r*$e/($p+1)-$q=$r:$m[1]).$m[2].$q,$s);

Takes input from command line argument; escape newlines. Run with -r.

Replacing with a placeholder did not work as expected; so I had to add more parens to the first regex.

Python 2, 184 183 bytes
Definitely golfable
i=raw_input
j=int
w=map(j,i().split())
W=len(i())
I=i().find('^')
R=W-I-1
a=[w[1]*R/I,w[0]*I/R]
h=a[1]>w[1]
w[h]=j(a[h])
k='\n'
print(' '*(W-len(str(w))+4)).join(map(str,w))+k+'-'*W+k+' '*I+'^'

Pretty straightforward. Just take the adjusted weights for adjusting both sides, see which one's larger than the original, and change that one, and output.
EDIT Switched multiplication and division because integer division is evile (thanks to @JonathanAllan for noticing this)
EDIT -1 byte Changed i().index('^') to i().find('^') (thanks to @JonathanAllan [again!])

You should swap the multiplication and division since the division is integer division - i.e. a=[w[1]*R/I,w[0]*I/R] (a simple example that would not work would be a 1 and 2 with I and R both 3). Currently 194 not 184 by the way since the newlines count as a byte each, but j and k are costing more bytes than they save.

You can use I=i().find('^'), and the short form of __repr__, backticks to make the last line print`w[0]`+' '*(W-len(`w`)+4)+`w[1]`+'\n'+'-'*W+'\n'+' '*I+'^' and get down to 182 - https://repl.it/EW8f

Befunge, 223 217 bytes
&:00p&10p~$0>~#<2#+%#1_:20p0~>8#~%#+!#1_:3v
v\g01/g03*g01_v#!\g04`*g01g04:*g03p04-1-p0<
>#g>#0>#0>#/>#<:.2\5>5>#\+/#1:#\_$50p:50g\5>5>#\+/#1:#\_$20g\-v>
1#,>#*-#4:#8_$.55+,20g>:#,1#*-#9\#5_55+,30g>:#,1#*-#8\#4_"^",@>>

Try it online!

215 bytes, I think

@Zacharý I'm afraid not. At least one of those arrows is needed, otherwise it'll fail whenever left torque > right torque (the first test case for example). The other > I think was just left for aesthetic reasons. That said, I do seem to have a 215 byte solution in my notes, so it may be possible (it my also have bugs which would explain why I never submitted it - don't have time to test it now).

C++ 14, 482 bytes
include<iostream>#include<string>#include<math.h>usingnamespacestd;intmain(){stringa,b,c,d;intj=0;inte[2];getline(cin,a);getline(cin,b);getline(cin,c);for(inti=0;i<a.size();i){if(isdigit(a.at(i))){while(i<a.size()&&isdigit(a.at(i))){d=a.at(i);i;}e[j]=stoi(d);d="";}}strings(b.size()-(int)log10(e[0])-(int)log10(e[1])-2,'');intl1=(c.size()-1);intl2=(b.size()-c.size());intl=e[0]*l1;intr=e[1]*l2;if(l>r)e[1]=l/l2;elsee[0]=r/l1;cout<<e[0]<<s<<e[1]<<endl;cout<<b<<endl;cout<<c;return0;}

more readable version:
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
    string a,b,c,d;
    int j=0;
    int e[2];
    // input
    getline(cin,a);// 1st line
    getline(cin,b);// 2nd line
    getline(cin,c);// 3rd line
    for (int i=0;i<a.size();i++) {
        if(isdigit(a.at(i))){
            while(i<a.size() && isdigit(a.at(i))){
                d+=a.at(i);
                i++;
            }
            e[j++]=stoi(d);
            d="";
        }
    }
    // amount of white space in between 2 numbers
    string s(b.size()-(int)log10(e[0])-(int)log10(e[1])-2,' ');
    int l1 = (c.size()-1);
    int l2 = (b.size()-c.size());
    int l = e[0]*l1;
    int r = e[1]*l2;
    // change the side with smaller torque
    if (l>r)
        e[1]=l/l2;
    else
        e[0]=r/l1;
    // output
    cout<<e[0]<<s<<e[1]<<endl;// 1st line
    cout<<b<<endl;// 2nd line
    cout<<c;// 3rd line
    return 0;
}

Python 3, 235 230 bytes (minimized reference)
I just minimized the reference, since I'm very new to code-golfing.
def s(l):
 w,i,t=[int(z.strip())for z in l[0].split()],len(l[1]),l[2].find("^");k,o=i-1-t,w[0]*t;p=w[1]*k
 if o>p:w[1]=o//k
 else:w[0]=p//t
 w=[str(z)for z in w];s=" "*(i-sum(len(z)for z in w));l[0]=w[0]+s+w[1];print("\n".join(l))

You use it exactly the same as the example, but the function is s instead of balance_seesaw.

Lines 5 and 6 could become w[o>p]=[o//k,p//t][o>p]. Also, most of the lines could be joined to get rid of some extra whitespace.

Thanks, as I said, I'm very new, so I overlook even the simplest fixes.

Except, it doesn't work, instead providing 0,56 instead of 196,56.