text:
Verify the queens puzzle
If you don't know what a queen is in chess, it doesn't matter much; it's just a name :)
Your input will be a square of arbitrary width and height containing some amount of queens. The input board will look like this (this board has a width and height of 8):
...Q....
......Q.
..Q.....
.......Q
.Q......
....Q...
Q.......
.....Q..

There are 8 queens on this board. If there were, say, 7, or 1, or 10 on here, the board wouldn't be valid.
Here we  use a . for an empty space, and a Q for a queen. You may, alternatively, use any non-whitespace character you wish instead.
This input can be verified as valid, and you should print (or return) a truthy value (if it is was not valid, you should print (or return) a falsy value). It is valid because no queen is in the same row, column, diagonal or anti-diagonal as another.
Examples (don't output things in brackets):
...Q....
......Q.
..Q.....
.......Q
.Q......
....Q...
Q.......
.....Q..

1

...Q.
Q....
.Q...
....Q
..Q..

0

Q.
Q.

0

..Q
...
.Q.

0 (this is 0 because there are only 2 queens on a 3x3 board)

..Q.
Q...
...Q
.Q..

1

Q

1 (this is valid, because the board is only 1x1, so there's no queen that can take another)

Let me stress that an input is only valid, if no queen is in the same row, column, diagonal or anti-diagonal as another.
Rules

You will never receive an empty input
If the input contains fewer queens than the sqaure root of the area of the board, it is not valid.
Note there are no valid solutions for a 2x2 or 3x3 board, but there is a solution for every other size square board, where the width and height is a natural number.
The input may be in any reasonable format, as per PPCG rules
The input will always be a sqaure
I used 1 and 0 in the examples, but you may use any truthy or falsy values (such as Why yes, sir, that is indeed the case and Why no, sir, that is not the case)

As this is code-golf, the shortest code wins!

Let us continue this discussion in chat.

Would {(x, y, v)} with v in [., Q] be a valid input format?

@DuctrTape I don't think that makes much sense.

@Okx In other words, they're asking about receiving a list of coordinates and values as input. For example: (0, 0, Q), (0, 1, .), (1, 0, Q), (1, 1, .) would be the third test case.

Can I take a string with no linebreaks?

@Titus That would not make sense.

"Sqaure"? Also, √area is the geometric mean of x and y.

Snails, 14 bytes
&
o.,\Q!(z.,\Q

Try it online!
Nothing like a 2D pattern matching language for a 2D decision problem. :)
Explanation
The & on the first line is a match mode option which requires the pattern on the second line to match from every possible position in the input. If that's the case, the program prints 1, otherwise it prints 0.
As for the pattern itself, note that there's an implicit ) at the end.
o       ,, Move in any orthogonal direction (up, down, left or right).
.,\Q    ,, Make sure that there's a Q somewhere in that direction from the
        ,, starting position of the match.
!(      ,, After finding the Q, make sure that the following part _doesn't_ match:
  z     ,,   Move in any orthogonal or diagonal direction.
  .,\Q  ,,   Try to find another Q in a straight line.
)

Why this works is easiest to see by starting from the negative lookahead: by ensuring that there is no Q in a straight line from the other Q we've already found, we make sure that there are no more than N queens (otherwise, there would have to be two in one row, and it wouldn't be possible to find these queens without finding another). Then the first part, making sure that there's a queen reachable in an orthogonal direction from any position, makes sure that there are exactly N queens. If one was missing, there would be a row and a column without a queen. Starting from the intersection of these, it wouldn't be possible to find a queen by going only in an orthogonal direction.

Jelly, 17 or 15 bytes
ỴµUŒD;ŒD;ZVṀ;V=1Ṃ

Try it online!
Uses ‘ for a queen and ¹ for blank space. (This is mostly a consequence of the ban on taking input as an array, because it forces the input to be strings; converting strings to integers is difficult in Jelly, with the easiest method being evaluation, and it turns out that instead of 1 and 0, using "add 1" (‘) and "add 0" (¹) make it possible to omit several sum and map instructions, because we can count the queens in a list by evaluating it.) The truthy and falsey values are Jelly's normal 1 and 0.
EDIT: The question's been changed since I wrote this answer to allow taking input as a matrix. This allows dropping the leading Ỵµ, saving 2 bytes. It also probably allows changing the input format to something more normal, using S to sum rather than V to evaluate, but I don't think that saves bytes and I kind-of like this funky format.
Explanation
ỴµUŒD;ŒD;ZVṀ;V=1Ṃ
Ỵ                    Split on newlines.
 µ                   Set this value as the default for missing arguments.
     ;  ;            Concatenate the following three values:
  UŒD                - the antidiagonals;
      ŒD             - the diagonals;
         Z           - and the columns.
          V          Evaluate (i.e. count the queens on) all of those.
           Ṁ         Take the largest value among the results.
            ;V       Append the evaluation (i.e. queen count) of {each row}.
              =1     Compare each value to 1.
                Ṃ    Take the minimum (i.e. most falsey) result.

So the basic idea is that we ensure that there's at most one queen on each antidiagonal, diagonal, and column; and exactly one queen on each row. These conditions are together enough to require that there's at most one queen on each of the four sorts of line, and a number of queens equal to the side length of the board.
Incidentally, Jelly could probably do with a built-in for antidiagonals, but AFAICT it doesn't seem to have one, so I need to settle for reflecting the board and then taking the diagonals.
Another interesting note is that changing =1Ṃ to E (all equal) gives a generalized n-queens checker, which will also accept an n×n board where each row, column, diagonal, and antidiagonal contains no more than k queens, and the board contains exactly kn queens. Restricting k to equal 1 actually cost two bytes.

Rules were updated, now "The input may be in any reasonable format, as per PPCG rules", that should make it shorter :) EDIT - I see you noted it.

Octave, 57 70 67 51 52 bytes
Saved 1 byte using flip instead of rot90 thanks to @LuisMendo, but found a bug on the 1x1 case
@(A)all(sum([A A' (d=@spdiags)(A) d(flip(A))],1)==1)

Takes input as a binary matrix with 1 representing a Queen and 0 representing an empty space.
Creates an anonymous function that first concatenates the input matrix and its transpose.
spdiags creates a matrix with the same number of rows as the argument, with the diagonals turned into columns (zero-padded as necessary), so concatenate spdiags of the input matrix to get the diagonals and spdiags of the matrix flipped horizontally to get the antidiagonals.
Now take the sum of each column of the concatenated matrix and make sure each column is exactly 1.
Sample run on ideone.

I think you can use flip instead of rot90

@LuisMendo Yep, that'll work too. Thanks!

Also, can't you avoid all()?

@LuisMendo Ugh... probably... but it'll have to wait until after dinner ;)

MATL, 38 34 bytes
4 bytes off thanks to @beaker!
sG!sGt&n_w&:&XdsGP5M&Xdsv2<GnGzU=*

The input is a 2D array of zeros and ones, using semicolons as row separators.
This outputs a column vector of ones as truthy, and a column vector containing at least one zero as falsy.
Try it online! The footer code is an if branch to demonstrate truthiness or falsyhood.
Or verify all test cases.
Explanation
s      % Input binary matrix implicitly. Sum of columns. Gives a row vector
G!     % Paste input again. Transpose
s      % Sum of columns (rows in the original matrix). Gives a row vector
G      % Paste input again
t&n    % Duplicate. Push number of rows and number of columns (will be equal)
_w     % Negate, flip
&:     % Binary range. Gives [-n -n+1 ... n] for input of size n×n
&Xd    % Get diagonals -n through n. This gives all diagonals as colums
s      % Sum of each column (diagonals of original matrix). Gives a row vector
GP     % Paste input again. Flip vertically
5M     % Push [-n -n+1 ... n] again
&Xd    % Get diagonals -n through n (anti-diagonals of original matrix)
s      % Sum of each column. Gives a row vector
v      % Concatenate everything into a column vector
2<     % True for elements that are less than 2
Gn     % Paste input again. Number of elements
Gz     % Paste input again. Number of nonzeros (i.e. of queens)
U      % Square
=      % True if equal
*      % Mutiply, element-wise

You can save 2 bytes now that you can take a binary matrix as input.

SnakeEx, 67 bytes
m:({q<>}({q<R>}[{q<RF>}{n<RF>}].)*{e<>}<R>)%{4}
e:.$
q:_*Q_*$
n:_+$

Uses _ in place of . in the input. Returns 1 or more matches for truthy, 0 matches for falsey. You can find an online interpreter at the link in the header.
Explanation
SnakeEx is a language from the 2-D Pattern Matching challenge. It defines "snakes" that move around the grid matching stuff. Snakes can spawn other snakes, making the language quite powerful.
Let's look at this program from the bottom up.
n:_+$

This defines a snake n that matches 1 or more underscores and then the edge of the grid. Note that this may be in any of the 8 cardinal directions--the direction is determined when the snake is spawned.
q:_*Q_*$

Similar to n above, this defines q as a snake that matches any number of underscores, a single Q, any number of underscores, and the edge of the grid. In other words, a row/column/diagonal that has only one queen in it.
e:.$

e is a snake that matches one character and the edge of the grid.
m:({q<>}({q<R>}[{q<RF>}{n<RF>}].)*{e<>}<R>)%{4}

The main snake m  uses these building blocks to check the whole board. Conceptually, it runs around the outside edges of the grid, spawning other snakes to check that all columns and rows have exactly one queen, and all diagonals have at most one queen. If any of the spawned snakes fails to match, the entire match fails. Let's break it down.

(    )%{4} runs what's inside the parentheses 4 times, once for each side. (In what follows, it's helpful to picture a particular side--say, the top edge of the grid, starting from the top left corner and moving right.)
{q<>} spawns a q snake in the same direction that the main snake is moving. This verifies that the current edge meets the "exactly one queen" rule. Note that spawned snakes do not move the main snake's match pointer, so we're still at the beginning of the edge.
(    )* matches 0 or more of what's inside the parentheses.
{q<R>} spawns a q snake turned rightward from the main snake's direction. (E.g. if the main snake is moving rightward along the top edge, this snake moves downward.) This checks each column/row.
[    ] matches either one of the options inside the brackets:

{q<RF>} spawns a q snake turned 45 degrees rightward (i.e. Right and Forward) from the main snake's direction. The q snake matches if the diagonal contains exactly one queen.
{n<RF>} spawns an n snake instead. The n snake matches if the diagonal contains no queens.

. matches any character, moving the match pointer forward.
After checking as many horizontals and diagonals as possible, we verify that we're at the edge by spawning {e<>}.
Finally, <R> turns the main snake right, ready to match the next edge.

Weird stuff

There's nothing in the program to ensure that matching starts at an outside corner. In fact, the truthy test cases yield several matches, some of which start on the inside somewhere. Despite this, none of the falsey cases I've tried have generated any false positives.
If I'm reading the language spec right, I should have been able to use X (branch in all diagonal directions) in place of RF. Unfortunately, the online interpreter said that was a syntax error. I also tried * (branch in all directions), but that hung the interpreter.
Theoretically, something like _*Q?_*$ ought to work for matching "at most one queen" in the diagonals, but that also hung the interpreter. My guess is that the possibility of empty matches causes problems.

Python 3, 232 200 155 bytes
d=1
f=input()
Q=[]
for i in f:d=[0,d][i.count('Q')==1];Q+=[(len(Q),i.index('Q'))]
print[0,d][sum(k[1]==i[1]or sum(k)==sum(i)for k in Q for i in Q)==len(Q)]

Try it online!
-32 bytes thanks to @beaker noticing a change in the input specifications; I have changed the language from Python 3 to 2, thus allowing for me to use input to take input as an array of strings or an array of character arrays.
-45 bytes thanks to @Leaky Nun

The input requirements have been relaxed, if that helps you any.

@beaker Okay, thanks. I'll take input as an array of strings instead. Thanks for pointing that out!

157 bytes

J, 37 bytes
(+/&,=#)*1=[:>./+//.,+//.&|.,+/,+/&|:

Anonymous function train which takes Boolean matrix as argument.
Try it online!
( +/ the sum & of , the ravel = equals # the tally of rows )
* and (lit. times)
1 one = equals [: the >./ maximum of
+/ the sums /. diagonally , and (lit. catenated to)
+/ the sums /. diagonally & of |. the reverse , and
+/ the sums across , and
+/ the sums & of |: the transpose

Ruby, 120 bytes
Lambda function based on the original spec that required input as a string.
->s{t=k=0
a=[]
s.bytes{|i|i>65&&(a.map{|j|t&&=((k-j)**4).imag!=0};a<<k)
k=i<11?k.real+1:k+?i.to_c}
t&&~a.size**2>s.size}

converts the Q's into complex numbers and subtracts them from each other. If the difference between the coordinates of any two queens is horizontal, vertical or diagonal, raising it to the 4th power will yield a real number and the arrangement is invalid.
Ungolfed in test program
f=->s{                                 #Take input as string argument.
  t=k=0                                #k=coordinate of character. t=0 (truthy in ruby.)
  a=[]                                 #Empty array for storing coordinates.
  s.bytes{                             #Iterate through all characters as bytes.
    |i|i>65&&(                         #If alphabetical, compare the current value of k to the contents of a
      a.map{|j|t&&=((k-j)**4).imag!=0} #If k-j is horizontal, vertical or diagonal, (k-j)**4 will be real and t will be false
      a<<k)                            #Add the new value of k to the end of a.
    k=i<11?k.real+1:k+?i.to_c          #If not a newline, increment the imaginary part of k. If a newline, set imaginary to 0 and increment real
  }                                    #s.size should be a*a + a newlines. ~a.size = -1-a.size, so ~a.size**2 = (a.size+1)**2
t&&~a.size**2>s.size}                  #compare a.size with s.size and AND the result with t. Return value.

p f["...Q....
......Q.
..Q.....
.......Q
.Q......
....Q...
Q.......
.....Q.."]

p f["...Q.
Q....
.Q...
....Q
..Q.."]

p f["Q.
Q."]

p f["..Q
...
.Q."]

p f["..Q.
Q...
...Q
.Q.."]

p f["Q"]

JavaScript (ES6), 115 bytes
a=>!a.some((b,i)=>b.some((q,j)=>q&&h[i]|v[j]|d[i+j]|e[i-j]|!(h[i]=v[j]=d[i+j]=e[i-j]=1))|!h[i],h=[],v=[],d=[],e=[])

Ungolfed:

function queens(arr) {
    horiz = [];
    vert = [];
    diag = [];
    anti = [];
    for (i = 0; i < arr.length; i++) {
        for (j = 0; j < arr.length; j++) {
            if (arr[i][j]) { // if there is a queen...
                if (horiz[i]) return false; // not already on the same row
                if (vert[j]) return false; // or column
                if (diag[i + j]) return false; // or diagonal
                if (anti[i - j]) return false; // or antidiagonal
                horiz[i] = vert[j] = diag[i + j] = anti[i - j] = true; // mark it
            }
        }
        if (!horiz[i]) return false; // fail if no queen in this row
    }
    return true;
}

Ruby, 155 bytes
->x{(y=x.map{|r|(i=r.index ?Q)==r.rindex(?Q)?i:p or-2}).zip(y.rotate).map.with_index{|n,i|n.max-n.min==1&&i<y.size-1?-2:n[0]}.inject(:+)*2==(s=x.size)*~-s}

This is horrible to read, so I've got a slightly less golfed version below
->x{
    (y=x.map{|r|(i=r.index ?Q)==r.rindex(?Q)?i:p or-2})
    .zip(y.rotate)
    .map.with_index{|n,i|n.max-n.min==1&&i<y.size-1?-2:n[0]}
    .inject(:+)*2==(s=x.size)*~-s
}

This is the same code, but with some newlines to separate out what's happening.
The code tself is an anonymous lambda function which takes an array of strings (x) in the format ["..Q", "Q..", ".Q."].
The first line is mapping each string to the index of the Q character in that string. If there is no Q character, it's replaced with -21. This new array of indices is assigned to the variable y.
The next line zips this array of indices with itself offset by one (rotated). This results in an array of pairs of consecutive indices.
The next line is particularly complicated. It goes through each of the pairs of indices, and subtracts the smaller from the larger. If this is 1 (and we're not at the last pair2), then there are two queens that are on the same diagonal, and a value of -2 is inserted, otherwise the original index of the queen in the string is inserted.
The last line sums up all the indexes for each and checks to see if it is the triangle number for n-1, where n is the width (or height) of the square.
1: -1 would have been my go-to, but it's 1 apart from 0, so would mess with the checking of diagonals. The negative-ness of it is important to make the final sum wrong. I thought about a high number (with single digits) like 9, but I can't be sure that won't result in an incorrect verification.
2: The board doesn't wrap round, whereas ruby's rotate array function does, and if the last pair is different by one it doesn't matter - that's not a diagonal.

Python 3, 185 176 175 172 171 bytes
lambda x,c=lambda x:x.count("Q")==1:all([*map(c,x+[[l[i]for l in x]for i in range(len(x[0]))])])*~any(map(lambda s:"Q%sQ"%(s*".")in"".join(x),[len(x[0]),len(x[0])-2]))==-1

An anonymous function taking a list of strings as input.
Python 2, 175 bytes
lambda x:all([a.count("Q")==1for a in x]+[[l[i]for l in x].count("Q")==1for i in range(len(x[0]))]+[all(map(lambda s:"Q%sQ"%(s*".")not in"".join(x),[len(x[0]),len(x[0])-2]))])

PHP, 137 143 bytes
inspired by Neil´s solution
for($n=1+strlen($s=$argv[1])**.5|0;($c=$s[$p])&&!(Q==$c&&$v[$x=$p%$n]++|$h[$x=$p/$n]++|$d[$y-$x]++|$a[$y+$x]++);$p++);echo$n-1==count($a)&&!$c;

takes input from first command line argument; run with -r. Requires single byte line breaks.
Actually you can use any character but 0 for the line break.
prints true (1) or false (empty string).
breakdown
for($n=1+strlen($s=$argv[1])**.5|0; // copy input to $s, $n=size+1 (for the linebreak)
    ($c=$s[$p])&&!(                 // loop through characters
        Q==$c&&                         // if queen: test and increment lines
            $v[$x=$p%$n]++|$h[$x=$p/$n]++|$d[$y-$x]++|$a[$y+$x]++
    );                                  // break if a line had been marked before
    $p++);
echo$n-1==count($a)             // print result: true for $n-1(=size) marks
    &&!$c;                      // and loop has finished


text:
If A-B be in A-B A else B eh?
Given two integers, A and B, output A if A-B (A minus B) is in A-B (A to B), otherwise output B.
"A minus B" is standard subtraction.
"A to B" is the range of integers starting at A and ending at B, including both A and B. For example:
1 to 4: 1, 2, 3, 4
-2 to 5: -2, -1, 0, 1, 2, 3, 4, 5
3 to -1: 3, 2, 1, 0, -1
7 to 7: 7

The shortest code in bytes wins.
Test Cases
A B Output
1 4 4
-2 5 5
3 -1 -1
7 7 7
90 30 90
90 -30 -30
-90 30 30
-90 -30 -90
-2 -2 -2
-2 -1 -2
-2 0 -2
-2 1 1
-2 2 2
-1 -2 -2
-1 -1 -1
-1 0 -1
-1 1 1
-1 2 2
0 -2 -2
0 -1 -1
0 0 0
0 1 1
0 2 2
1 -2 -2
1 -1 -1
1 0 1
1 1 1
1 2 2
2 -2 -2
2 -1 -1
2 0 2
2 1 2
2 2 2

Original Chat-Mini-Challenge

Python, 27 bytes
lambda a,b:[a,b][2*b*b>a*b]

Try it online!
An arithmetic formula. Why is the negation of 2*b*b>a*b equivalent to the problem condition a-b in symrange(a,b)?
Note that x in symrange(a,b) is equivalent to 0 in symrange(a-x,b-x). Applying this to x=a-b gives 0 in symrange(b,2*b-a). The value 0 is included in the interval unless it stretches between two positive values or two negative values. This can be stated arithmetically as  "their product b*(2*b-a) is not positive.
Finally, take b*(2*b-a)<=0, and rewrite to 2*b*b<=a*b. A byte is saved by flipping <= to > and switching the cases.

Jelly, 5 bytes
_erị,

Try it online!
How it works
_erị,  Main link. Arguments: a, b

_      Subtraction; Yield a-b.
  r    Range; yield [a, ..., b].
 e     Exists; yield 1 if a-b belongs to [a, ..., b], 0 if not.
    ,  Pair; yield [a, b].
   ị   At-index; yield the element of [a, b] at index 1 (a) or index 0 (b).

05AB1E, 7 bytes
Code:
DŸ¹Æå_è

Uses the CP-1252 encoding. Try it online!
Explanation:
D         # Duplicate the input.
 Ÿ        # Inclusive range.
  ¹Æ      # Push the input [a, b] and compute a - b.
    å     # Check if the number exists in the range.
     _    # Boolean negate
      è   # Index at the first input

@Okx The CMC asked for a Boolean.

PHP, 58 Bytes
<?=in_array(($a=$argv[1])-$b=$argv[2],range($a,$b))?$a:$b;

The $b assignment needs no parentheses.

JavaScript (ES6), 24 bytes
a=>b=>[a,b][2*b*b>a*b|0]

Test cases

let f = a=>b=>[a,b][2*b*b>a*b|0]
let tests = [[1,4,4],[-2,5,5],[3,-1,-1],[7,7,7],[90,30,90],[90,-30,-30],[-90,30,30],[-90,-30,-90],[-2,-2,-2],[-2,-1,-2],[-2,0,-2],[-2,1,1],[-2,2,2],[-1,-2,-2],[-1,-1,-1],[-1,0,-1],[-1,1,1],[-1,2,2],[0,-2,-2],[0,-1,-1],[0,0,0],[0,1,1],[0,2,2],[1,-2,-2],[1,-1,-1],[1,0,1],[1,1,1],[1,2,2],[2,-2,-2],[2,-1,-1],[2,0,2],[2,1,2],[2,2,2]]
tests.map(test => `f(${test[0]})(${test[1]}) == ${test[2]}`).forEach(test => console.log(test, eval(test)))

Python2, 55 52 51 bytes
lambda A,B:[B,A][A-B in range(min(A,B),max(A,B)+1)]

Try it online!
Handles every test case OP has mentioned (at the time of posting this), as the TIO suggests.

Python 2, 37 bytes
lambda*s:s[min(s)<=s[1]-s[0]<=max(s)]

Invoke as f(B, A).

JavaScript ES6, 40 37 bytes
a=>b=>a-b<(a<b?a:b)|a-b>(a<b?b:a)?b:a

Explained:
a=>b=>                                   take a and b as inputs
      a-b<(a<b?a:b)                      if a-b is less than the lowest of a and b
                   |a-b>(a<b?b:a)        or a-b is greater than the largest of a and b
                                 ?b      return b
                                   :a    else return a

Saved 3 bytes thanks to Arnauld.

f=a=>b=>a-b<(a<b?a:b)|a-b>(a<b?b:a)?b:a

function t(){
    var tests = [[1,4,4],[-2,5,5],[3,-1,-1],[7,7,7],[90,30,90],[90,-30,-30],[-90,30,30],[-90,-30,-90],[-2,-2,-2],[-2,-1,-2],[-2,0,-2],[-2,1,1],[-2,2,2],[-1,-2,-2],[-1,-1,-1],[-1,0,-1],[-1,1,1],[-1,2,2],[0,-2,-2],[0,-1,-1],[0,0,0],[0,1,1],[0,2,2],[1,-2,-2],[1,-1,-1],[1,0,1],[1,1,1],[1,2,2],[2,-2,-2],[2,-1,-1],[2,0,2],[2,1,2],[2,2,2]];
    for (var test of tests) {
        console.log(`f(${test[0]},${test[1]}) == ${test[2]}`, f(test[0])(test[1])==test[2]);
    }
}

t();

Mathematica, 16 bytes
If[2#^2>1##,##]&

Pure function taking two arguments in the opposite order as the OP (for example, If[2#^2>1##,##]&[B,A]). A port of xnor's Python answer.

R, 49 30 28 bytes
pryr::f("if"(2*b*b>a*b,b,a))

Uses @xnor's logic for determining whether a-b is in a:b.

unnamed functions are generally allowed

You can lose another 3 bytes using pryr::f(match(a-b,a:b,b))

@mnel thanks for sharing that, I didn't know how %in% worked before; but that fails whenever a-b is in a:b. f(-90,-30) = 31

Indeed. `pryr::f(match(a-b,a:b,0)+b) fixes that (and still saves a byte.

Clojure, 71 41 bytes
-30 bytes by using <= and min/max instead of ranges.
#(if(<=(min % %2)(- % %2)(max % %2))% %2)

Checks if (a - b) is in the range from a to b, dispatching a return accordingly.
(defn eh [a b]
  ; <= accepts any number of argments, and ensures all fall within the range
    (if (<= (min a b) (- a b) (max a b))
      a
      b))

PHP (7.1), 55 bytes
uses the new array destructuring syntax:
[,$a,$b]=$argv;echo in_array($a-$b,range($a,$b))?$a:$b;

Run with -r, provide numbers as command line arguments.

PowerShell, 37 35 32 bytes
($a,$b=$args)[$a-$b-notin$a..$b]

Try it online!
Literal translation of the problem into PowerShell using the -notin operator. Saved three bytes by using multiple assignment and encapsulation. This works because - has a higher operator precedence than -notin, and the ( ) portion of the code is executed first and returned as an array @($a,$b). However, since it's $a,$b rather than $b,$a, we need to use -notin to flip/flop the output result.

Nim, 60 bytes
proc f(a,b:int):int=
  if a-b in min(a,b)..max(a,b):a else:b

Try it online!
Pretty standard as far as answers go, no big tricks in this one.

Batch, 107 bytes
@set/aa=%1,r=b=%2,x=a-b
@if %a% gtr %b% set/aa=b,b=%1
@if %a% leq %x% if %x% leq %b% set/ar=%1
@echo %r%

Pyth - 9 bytes
Was hoping to use more implicit input... :(
@Q!}-FQ}F

Try it online here.

Röda, 30 bytes
f a,b{[b]if[2*b*b>a*b]else[a]}

Try it online!
It uses the formula used in xnor's answer.
Another solution (37 bytes):
f a,b{[a]if[a-b in[seq(a,b)]]else[b]}

Try it online!

Java 7, 84 60 58 bytes
int c(int a,int b){return(a<b?a:b)>a-b|(a<b?b:a)<a-b?b:a;}

Java 8, 37 bytes
a->b->(a<b?a:b)>a-b|(a<b?b:a)<a-b?b:a

Explanation:
int c(int a, int b){          // method with two integer parameters and integer return-type
  return (a<b ? a : b) > a-b  //  if smallest of the input is larger than a-b
       | (a<b ? b : a) < a-b  //    or if the largest of the input is smaller than a-b
    ? b                       //   return b
    :                         //  else
      a                       //   return a
}                             // end of method

Test code: Try it here.

><>, 21 bytes
Makes use of @xnor's trick. We use -v B A to prepopulate the stack. (-v A B is +1 byte).
:01pr:11p::2**r*)1gn;

Try it online!
Explanation
                        Input: [B, A] on stack.
:01pr:11p::2**r*)1gn;
:                       Duplicate.           [B, A, A]
 01p                    Push A to [0,1].     [B, A]
    r                   Reverse              [A, B]
     :                  Duplicate.           [A, B, B]
      11p               Push B to [1,1].     [A, B]
         ::             Duplicate x 2.       [A, B, B, B]
           2            Push 2.              [A, B, B, B, 2]
           2**          Compute 2*B*B.       [A, B, 2*B*B]
              r         Reverse.             [2*B*B, B, A]
               *        Compute A*B.         [2*B*B, A*B]
                )       >                    [2*B*B > A*B]
                 1      Push 1.              [2*B*B > A*B, 1]
                  g     If 2*B*B > A*B
                         get B, else get A.  [2*B*B > A*B ? B : A]
                   n    Output as number.
                    ;   Terminate.

Swift - 38 30  22 bytes
Saved 8 bytes thanks to @Matt
print(a...b~=a-b ?a:b)

Try it at IBM Swift Sandbox online!

Or 21 bytes:
(thanks to @xnor's formula) and saved 8 bytes thanks to @Matt
print(2*b*b>a*b ?a:b)

Swift is not the best language for golfing (it's very rigid), so if you see any other golfing opportunity, I'll totally edit the answer.

Why not put the ternary inside the print like print(a...b~=a-b ? a : b)

Oh, yes, good ideA. Thanks @Matt

Ruby, 27 22 bytes
->a,b{(b*a<2*b*b)?b:a}

Try it online!
Nothing innovative here. The simple math behind it:
(A<=A-B<=B or B<=A-B<=A)

can be written as
(B>=0 and A>=2B) or (B<=0 and A<=2B)

that is: if A-2B has the same sign as B, we are in the range.

SpecBAS - 38 btes
1 INPUT a,b: ?IIF(a-b IN [a TO b],a,b)

IIF is an inline-IF-THEN-ELSE, to print the correct value.

Haskell, 21 bytes
a!b|b*a<2*b*b=b|0<1=a

Try it online!
Readable
func :: Int -> Int -> Int
func a b
    | b*a < 2*b*b = b
    | otherwise = a

Explanation
Uses @xnor's formula to check whether a-b is in range. Nothing special besides that.

PHP 7 - 45 Bytes
echo(in_array($a-$b,range($a,$b))?$a:$b)==$c;

Welcome to the site!

Haskell, 58 bytes
Just recently I fell in love with arrows again. Unfortunately they require us to work with tuples instead of binary functions. And of course Haskell does not have a symmetrical range function.
import Control.Arrow
u=uncurry
app<<<elem.u(-)&&&(u enumFromTo<<<u min&&&u max)

Octave, 55bytes
@(a,b)(c=b*~[find((a:1-2*(b<a):b)==(a-b)) 0](1))+(a*~c)

This could probably be optimised further. I'll add an explanation later.

A simpler approach. +1 for all the "crazy stuff" in there though :P

Ti-Basic (TI-84 Plus CE), 26 24 23 bytes
Prompt A,B
A-B≥A and A-B≤B
AAns+Bnot(Ans

TI-Basic is a tokenized language; all tokens used are one-byte tokens.
Prompt prompts you for the two numbers.
A-B≥A and A-B≤B checks if A-B is between A and B (inclusive); this returns a 1 if true and a zero if false, which is stored to Ans.
Since we are returning A if A-B is between A and B, we multiply A by Ans, which will be A if we are supposed to return A, and 0 otherwise.
Next, we add Bnot(Ans to it. If Ans was 1 (truthy), we not( it and get 0, thus our sum is A. If Ans was 0 (falsy), we not( it to get 1, which we multiply by B and add to 0 to get B.
The last evaluation in TI-Basic is implicitly returned.
-2 bytes thanks to Scott Milner

You can save two bytes by not storing the third line to Y and just using Ans in the fourth line.

Pyt, 32 bytes
←Đ←Đ3Ș⇹Đ3ȘĐ4Ș3Ș-3Ș⇹Ř∈Đ3Ș⇹¢*3Ș⇹*+

Takes A and B from stdin as two separate inputs
Explanation:
AABB -> ABBA -> ABAB -> ABABB -> ABBBA -> ABBBAA -> ABAABB -> ABABBA -> ABABC -> ABCBA -> ABCAB -> ABC[A,...,B] -> ABD -> ABDD -> ADDB -> ADBD -> AD{B*(1-D)} -> {B*(1-D)}AD -> {B*(1-D)}+{A*D}
where:  C=B-A and D=C∈[A,...,B] (1 if true, 0 if false)

Ohm, 10 bytes (CP437)
There's probably a golfier way to do this, but the strictly-typed nature of Ruby makes this difficult.
G┼┘-îε?┼¿┘

Perl 6,  31 29  24 bytes
{$^a-$^b==any($a...$b)??$a!!$b}

Try it
{$^a-$^b∈($a...$b)??$a!!$b}

Try it
->\a,\b{2*b*b>a*b??b!!a}
->\a,\b{2*b²>a*b??b!!a}

Try it

Kotlin, 43 bytes
{a,b->if(a-b in a..b||a-b in b..a)a else b}

This is the one time that I am grateful that kotlin ranges are inclusive.
You could alternatively do it using xnor's algorithm with 28 bytes:
{a,b->if(2*b*b>a*b)b else a}

Test Suite

MATL, 13 bytes
tPdGSl&)&:mo)

Try it at MATL Online
Explanation
    % Implicitly grab input as a 2-element array
t   % Duplicate the input
Pd  % Flip the order and compute the difference
GS  % Grab the input again and sort it
l&) % Break the two elements of the array into two stack elements
&:  % Create the array from the smaller to the larger element
m   % Check for membership (returns FALSE or TRUE)
o   % Convert FALSE to 0 and TRUE to 1
)   % Use this as a modular index into the initial array
    % Implicitly display the result

Japt, 14 bytes
òV bU-V ¨0?U:V

Try it online!

Ohm, 25 bytes
IIGÉ┼┘-E;?┼¿┘;,

Expanation:
IIGÉ┼┘-E;?┼¿┘;,
II              ■Inputs twice
  G             ■Range a..b
   É            ■any {
    ┼┘-E        ■  firstInput-secondInput==element
        ;       ■}
         ? ¿ ;  ■if {
          ┼     ■  firstinput
           ¿    ■}else{
            ┘   ■  secondinput
             ;  ■}
              , ■Print

Google Sheets, 49 bytes
-2 bytes because Google Sheets automatically closes brackets
=MINUS(A1,A2
=IF(AND(GTE(A1,A3),LTE(A2,A3)),A1,A2

Inputs are in the cells A1 and A2. Assumes cell A3 is selected after input is recieved.
The newline isn't actually a newline, it's just pressing enter.
The code is pretty readable, so I doubt an explanation is needed.

Octave, 37 34 bytes
@(a)a(2-ismember(-diff(a),a:a(2)))

This is an anonymous function that takes the input values as an array of two elements: [-90, 30].
Breakdown:
@(a)a(                           )  % Function that takes a variable a as input
                                    % and returns the x'th element (dependent on what's
                                    % inside the parentheses.
                 -diff(a)           % Takes the negative difference between the two

                          a:a(2)))  % A vector: -3 -2 -1 0 1 2 ...
        ismember(-diff(a),a:a(2)))  % Checks if the negative difference (a-b)
                                       % is part of the range. Returns 1 for true
    a(2-ismember(-diff(a),a:a(2)))  % Return the 2-ismember() element of the input
@(a)a(2-ismember(-diff(a),a:a(2)))  % Everything put together

a(1):a(2) is the same as a:a(2) since Octave automatically assumes you want the first element. That saved an additional two bytes.
I could save one more byte by taking the input in the different order [b, a], but I figured it was cleaner this way.

Ly, 39 bytes
nn&s<l>>lRy![plfR11$]p<-s>l~[<<pu;]<<u;

Try it online!

source: Stack Exchange

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

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

sort: votes


text:
You Are the User: Create the Requirements
My boss* does not understand why her programmers react negatively to users changing program requirements. Help her understand! On every answer, create a new requirement. Then, write a program/function that solves that requirement and all prior requirements, while in a new programming language.
Examples
User 1 posts the first answer. He specifies that the program must output "Hello, World." He creates a program in Java that outputs "Hello, World."
User 2 posts the second answer. She specifies that the program must accept input n and output the nth prime, up to the language's number max. She creates a program in C++ that accepts input n and outputs the nth prime and outputs "Hello, World." She could not have created a program in Java.
User 3 posts the third answer. He specifies that the program source cannot contain the text "Hello". He creates a function in Python that accept input n and outputs the nth prime and "Hello, World." while not using the text "Hello" in his source. He could not have created a program in Java or C++.
Answer Format
#Answer # - <language name> [version, if pertinent]

Requirement: <rule>.

[explanations, encoding, TIO link, etc.]

Answer Rules

The answer must follow the above format, or similar.
The answer can be a program or a function.
The answer must fulfill all requirements up to and including the current answer.
The same user may not post two answers in a row.
If two answers are posted with the same number, the one posted later
should be deleted.
Do not edit your requirement unless you messed up badly and no
other answers have been posted.
If your answer does not comply with your rule and all other rules, it
is invalid. Try to fix this before someone else posts the next
answer.
Different versions of the same language only count as different
languages if the program or function created in either version
will behave differently in the other version.
The answer may not accept any input not required, and may not output anything    not required except for necessary whitespace. However, while behind the scenes the program must fulfill all "hidden" (from the user) requirements, it may do whatever else you want it to, especially if you must fulfill an execution time requirement.

Requirement Rules

The requirement must only specify one requirement. This requirement
can be conditional, and if this requirement requires an input and/or
an output, this may be included.
The requirement may not remove or modify prior requirements, or
conflict with them, but may extend one (specify which).
If the requirement restricts the source (restricted-source), or requires text in the source, it may only remove a single string (e.g. 0, Hello), or require a single character.
The requirement cannot require the source to be under 100 bytes,
require a specific encoding, or,
in and of itself, rule out a majority of common languages.
The requirement may not force the source to conform to a certain pattern (for example, starting each line with a certain character, or (@Conor) hashing to a certain value) other than that specified in restricted source.

This is answer-chaining, so all answers build on previous answers. I and maybe others will try to keep a list of all requirements. To see answers in order, you can sort by oldest. To see the newest answer, sort by oldest, then navigate to the end of the list.
How to Win (changed for hold vote):
When no answer is posted for two weeks, the challenge is over, and scores will be calculated. The scores will be calculated by summing the totals number of answers by each user, but weighting posts based on how far into the chain they are (since the later posts have more requirements, they are harder).
Pseudocode:
for each answer in user.Answers {
   score += 1 + (answer.number / 100)
}

Example:
Sally has three answers. She posted answer 5, answer 7, and answer 20.
Her score will be 1.05 + 1.07 + 1.2 = 3.32. If it was a straight sum of answers, her score would be 3, but the weighting of chain depth rewards harder answers.
To start:
Here is the first requirement, given by my boss*:
Requirement 0: The program must output 0 before anything else.
*fictional
List of Requirements and Languages
Note that this may be out of date - please look at the last posted answer immediately prior to posting your answer to ensure you are fulfilling every requirement. I am very sorry if you create an exquisite program, only for someone to snipe it - if you really really want to post it anyway, specify non-competing.

Full (but maybe not current) Requirement: Cannot contain 0, * or ] in the source code, and cannot use a join-on-newline builtin. Outputs 0, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m, followed by a newline, followed by 10^B, where B is the number of bytes in the source code, followed by a newline, followed by the nth 0-indexed (may also be 1-indexed) prime number, followed by a newline, followed by the Greatest Common Divisor of n and m.
0: The program must output 0 before anything else. Language: N/A
  1: The program source cannot contain 0. Language: 05AB1E
  2: The program takes a non-negative integer input n and outputs a newline followed by the 0-indexed  n'th Fibonacci number (may be 1 indexed). Language: dc
  3: The program outputs a newline, followed by the same input n squared. Language: J
  4: The program outputs a newline, followed by n multiplied by a new input m. Language: Ohm
  5: The program cannot contain * (ASCII code 0x2A). Language: Python 3
  6: The program outputs a newline, followed by 10^B, where B is the number of bytes in the source code. Language: Mathematica
  7: The program outputs a newline, followed by the nth 0-indexed (may also be 1-indexed) prime number. Language: JavaScript (ES6)
  8: The program does not use a join-on-newlines builtin, but can use any other join builtin. Language: Jelly
  9: The program outputs a newline followed by the Greatest Common Divisor of n and m. Language: Scala
  10: The program cannot contain ]. Language: Pyth

Current Scores (ordered by first post)

Okx: 1.01
R. Kap: 2.09
Conor O'Brien: 1.03
Nick Clifford: 1.04
Eric Rose: 1.05
Greg Martin: 1.06
Erik the Outgolfer: 2.18
math_junkie: 1.09

Why accept the last answer?  That makes it seem like you win for adding a requirement nobody can meet.

@xnor your program has to fulfill that requirement. So at least you have to be able to meet it. Though if you can obfuscate it enough, kudos to you.

To go along with what xnor said, I'd suggest accepting the second-to-last answer, to make sure that the requirement added in the winning answer is in fact possible.

I believe it would possible to create a requirement that's only possible in the language you answer in, though the rules on restricted-source requirements may have that covered well enough...

(Also, welcome to PPCG!)

For example, "the md5 hash of the program must be ..."

@ETHproductions Thank you! I tried to rule that out with this section: "or, in and of itself, rule out a majority of common languages." Not sure if that is sufficient - I would be OK if a requirement, combined with other requirements created by other users, made it harder for other languages to compete, but not if a single requirement eliminated a swath of languages.

Perhaps something like "The requirement must not rely on hashing" would be sufficient. I'd add a more general rule, but I can't pinpoint what exactly to rule out that's more general than hashing. Randomness or near-randomness, maybe?

Even if the rules hold up to prevent a requirement that ends the chain,  I still think having a "win condition" encourages people to make near-impossible rules rather than fun ones.

@ETHproductions edited in new requirement rule, I believe that should fix that. Thanks!

Hmm... that's not really a win condition, more of another restriction.

@StephenS Well, people seem not be playing to win, so looks like my concern is misplaced.

This should be called 'Scope Creep'

Answer 10 - Pyth
Requirement: Takes two inputs, n (>=0) and m. Outputs 0 without the use of 0, * or ] anywhere in the source code, and without builtins for joining on newlines. Then outputs a newline followed by the 1-indexed nth Fibonacci number (may be 0 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m, followed by a newline, followed by 10^B where B is the number of bytes in the source code, followed by a newline and the nth 1-indexed (may also be 0-indexed) prime number, and finally followed by a newline and the Greatest Common Divisor of n and m.
JU2KE=H2VQ=+Js>2J=+YK=hHW!P_H=hH;jb[ZeJ^Q2sY^T51HiK

Online interpreter

Yes this is also golfed :-)

Also, before commenting, no, I can't just use j instead of jb, since then I would be using a join-on-newlines builtin.

Answer 1 - 05AB1E
Requirement: Prints 0... without a 0 in the source code
¾

Answer 5 - Python 3
Requirements: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m.  Do not use the character *, ASCII code 0x2A.
def f(n, m):
    print(1-1)
    a = 1-1
    b = 1
    for i in range(n):
        c = a+b
        a = b
        b = c
    print(b)
    print(n.__mul__(n))
    print(n.__mul__(m))

Answer 2 - dc
12298P?sa1 1-sb1sc[lblcdsb+scla1-dsa1 1-<y]dsyxlcp

Requirement: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed  n'th Fibonacci number (may be 1 indexed).
Try it online!

@R.Kap No problem :)

When I read the new requirement, for some reason I started laughing. +1.

Answer 3 - J
echo"+(1-1),(*:,~[:+/@:!&i.-)@".1!:1(3)

Requirement: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed n'th Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared.
Try it online!

Answer 4 — Ohm
Requirement: Outputs 0 without 0 in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m.
¼,≡ƒ,²,*,

Answer 6 — Mathematica
Requirement: Outputs 0 without 0 or * in the source code, then takes a non-negative integer input n and outputs a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by the same input n squared, followed by a newline, followed by n multiplied by a new input m, followed by a newline, followed by 10^B where B is the number of bytes in the source code.
((e=Echo)[1-1];e@Fibonacci@#;e[#^2];e[1##];2^# 5^#&@59)&

Yep, hence my hasty edit after I saw that EricRoe beat me by a minute :)

Answer 7 - JavaScript (ES6)
(a,b)=>String.fromCharCode(48)+'\n'+(m=(a)=>a>1?m(a-1)+m(a-2):1)(a)+'\n'+Math.pow(a,2)+'\n'+Math.exp(Math.log(a)+Math.log(b))+'\n'+1E257+'\n'+(T=(u,i=2,l=1-1,m=2)=>l<=u?(p=(o,z=2,s=1-1)=>z<o?p(o,z+1,s+(o%z<1&&z!=o)):s)(i)<1?T(u,i+1,l+1,i):T(u,i+1,l,m):m)(a)

Requirement: A function that takes two inputs, a non-negative integer n and any number m and returns a string containing 0 without the use of 0 anywhere in the source code, then a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m without the use of * anywhere in the source code, followed by a newline, followed by 10^B where B is the number of bytes in the source code, and finally followed by a newline and the nth 0-indexed (may also be 1-indexed) prime number.
Test Snippet

S=(a,b)=>String.fromCharCode(48)+'\n'+(m=(a)=>a>1?m(a-1)+m(a-2):1)(a)+'\n'+Math.pow(a,2)+'\n'+Math.exp(Math.log(a)+Math.log(b))+'\n'+1E257+'\n'+(T=(u,i=2,l=1-1,m=2)=>l<=u?(p=(o,z=2,s=1-1)=>z<o?p(o,z+1,s+(o%z<1&&z!=o)):s)(i)<1?T(u,i+1,l+1,i):T(u,i+1,l,m):m)(a)
m: <input type="number" min=0 id="i1"></input>

n: <input type="number" step="0.01" id="i2"></input>

<input type="button" value="Submit" onclick="console.log(S(document.getElementById('i1').value, document.getElementById('i2').value))"></input>

You could save a considerable amount of bytes by changing String.fromCharCode(48) to 1-1. Not that it really matters ;-) (Also, there are two zeroes later on in the source code, which you can fix in the same way)

Answer 8 - Jelly
Requirement: A function that takes two inputs, a non-negative integer n and any number m and returns a string containing 0 without the use of 0 anywhere in the source code, then a newline followed by the 0-indexed nth Fibonacci number (may be 1 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m without the use of * anywhere in the source code, followed by a newline, followed by 10^B where B is the number of bytes in the source code, and finally followed by a newline and the nth 0-indexed (may also be 1-indexed) prime number. No builtins for joining on newlines allowed, but joining builtins still allowed.
ÆḞṭØDW⁺¤;⁸²¤;×;ȷ25;⁸ÆN¤j⁷

Try it online!

Yes this is golfed.

C (gcc), submission #11, 432 bytes
n,m,z,c,q,a,s,t;A(a,b){return b?A(b,a%b):a;}B(n){if(n<=1)return 1-1;for(int i=2;i<n;i++)if(n%i==1-1)return 1-1;return 1;}C(n,c,z){while(c<n){if(B(z++))c++;}return z-1;}D(n){return(!n||n==1)?n:(D(n-1)+D(n-2));}main(){putchar(48);scanf("%d",&n);t=s=n;while(--t)s+=n;printf("\n%d\n%d\n",D(n),s);scanf("%d",&m);q=A(n, m);a=n;while(--m-1)n+=n;printf("%d\n",n);putchar(49);for(z=0;z<432;z++)putchar(48);printf("\n%d\n%d",C(a,1-1,1-1),q);}

I hereby ban line endings appearing anywhere in the source code :v).
Try it online!

Been a while since I posted this, but I believe your answer must conform to your added requirement :)

The answer must fulfill all requirements up to and including the current answer.
Oh crap! hahaha. I'll get it done in a second

Done! I swapped it to line endings :p

Answer 9 - Scala
Requirements: Takes two inputs, n (>=0) and m. Outputs 0 without the use of 0 or * anywhere in the source code, and without builtins for joining on newlines. Then outputs a newline followed by the 1-indexed nth Fibonacci number (may be 0 indexed), followed by a newline, followed by n squared, followed by a newline, followed by n multiplied by m, followed by a newline, followed by 10^B where B is the number of bytes in the source code, followed by a newline and the nth 1-indexed (may also be 0-indexed) prime number, and finally followed by a newline and the Greatest Common Divisor of n and m.
(n:Int,m:Int)=>{
 val z=1-1;val o=println _;var i=1;var j=z
 o(z)
 o((1 to n).foldLeft(z,1)((a,b)=>(a._2,a._1+a._2))._1)
 o(math.pow(n,2))
 o(List.fill(n)(m).sum)
 o(math.pow(9+1,299))
 while(j!=n){i+=1;if((2 to i-1)forall(i%_!=z))j+=1};o(i)
 o((1 to math.min(n,m)).filter(c=>n%c==z&&m%c==z).last)
}

Try it out here

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


text:
Converting rational numbers to an “alien” data format
For a story I'm writing, I needed to convert 101⅐ (101 + 1/7 if that doesn’t show up for you) into base 47.
Expressing an integer in some base brings back memories of first learning how to program back in the days of 8-bit systems; it’s a fairly easy exercise. Doing so using a floating-point format is a bit harder, though. The final twist, identifying the repeating digits, is more challenging to do elegantly.
So I thought I’d do it in a different language from what I’m used to, just for fun and learning the new dialect.  And I thought it would be good to share, so here I am.  The vast majority of the posts here are (char or byte of source) code golf, but I’m more interested in an elegant expression in the target language.  Cyclomatic complexity isn’t a category, but atomic-code-golf is pretty close.

The program should take a rational number in a natural way, such as supplying three integers on the command line of the script invocation or standard input.  This does not count towards the score (nor does the error checking and defaults if you give it one value only).  The function (or part that is counted for score) should receive the three values; e.g. 101,1,7 for the example above.
The output is a sequence of code points that are transliterated into text output as follows:

digits 0 through 9 inclusive:  ‘0’ through ‘9’ in the normal way
digits 10 through 46: express as ‘[10]’ through ‘[46]’
negative sign: the normal ASCII ‘-’
separator: ‘:’
prefix: ‘#’

A number starts with the prefix ‘#’ and has up to three parts, separated by ‘:’.  Leading parts are omitted if zero.
The basic natural number (BNN) is encoded using the digits in base 47, outputted in little-endian.  That is, 99181 = 11×470 + 42×471 + 44×472 so the digits, in order output, are [11][42][44].
The last (possibly only) part of a number is an integer, which is a leading ‘-’ if the value is negative, followed by the digits of the BNN.  So, 99181 would be encoded as #[11][42][44] and −99181 would be encoded as #-[11][42][44].
The middle part, if needed, is an exponent as for scientific notation.  It states which power of the base (position) is the first digit listed.  In the case of integers, this is 470 so the 0-valued part is omitted.
Suppose you divide that by 47, shifting the radix point by one.  That is, 99181 ÷ 47 is the same digits but starting with 47−1; that is, 11×47−1 + 42×470 + 44×471, and the output becomes #-1:[11][42][44].  There are two parts, the first is the encoding for the integer −1, and the second is the digits as before.
Now it comes out so neat only if you divide by some power of 47.  Normally, a rational number made of small components will end up with a repeating sequence of digits.  In decimal, for example, ⅓ is .3333… and ⅐ (1/7) is .142857142857142857…  in the first case one digit repeats, in the second case 6 digits repeat.
In the alien real number format, the first part, if present, states how many digits are to be repeated.  So, the number 8½ would have a single digit [23] repeating forever, so we just encode one of them and state that 1 repeats: #1:-1:[23]8.  The first part is 1 (the encoded BNN for the value 1) which means that one digit is to be repeated.  The second part (negative sign and BNN) indicates that the first digit given is the 47-1 position.  The third part is the two digits needed: 26×47-1 + 8×470.

Somebody should check my results, but I think the correct output for (101 1 7) is:
#6:-6:[20][13][40][26][33]672.

What counts as an "atom"? Are you using the description in the tag wiki?

I'm new here.  I'm using the established conventions.  So yes, I mean what was stated in the tag wiki.

You might want to make output a bit less stringent.  I personally feel that restrictive output formats make the answers more about the output formatter than the actual algorithm.

I am also not sure why you chose [tag:atomic-code-golf] over plain old [tag:code-golf].  It seems a bit random in the context of the entire question.

Welcome to the site! As WheatWizard has said we encourage looser I/O specs. Other than that it would be good idea to include a table of example inputs and outputs to help people with testing their code.

Ok, I’ll relax the output with some edits tomorrow.  Won’t score the actual output routine, just produce the lists of digits.

@WheatWizard because I want elegance in the target language, not reduced readability and tricks to save source bytes.

Considering how hard the question was to understand due to your I/O formats, it's unlikely that any answer will be readable. Why not just use a list of lists? Why is it little-endian? Why do you use an exponent instead of leading zeros? All these things make it harder to read/write. That may be the format for the story you're writing, but here it'd be best to focus on the actual algorithm, not the format. Maybe pick a few things to keep if they're important and remove some.

Batch, 531 bytes
@echo off
set q=
set s=
set m=
if %1 lss 0 set m=-
set/ai=%m%%1,n=%2,d=%3,p=0
:i
set/ar=i%%47,i/=47
if %r% gtr 9 set r=[%r%]
set s=%s%%r%
if %i% gtr 0 goto i
:p
if %n%==0 goto n
set/ao=n,g=d%%47
if %g% gtr 0 goto g
set/ap+=1,d/=47,r=n/d,n%%=d
if %r% gtr 9 set r=[%r%]
set s=%r%%s%
goto p
:g
set/aq+=1,p+=1,r=n*47/d,n=n*47%%d
if %r% gtr 9 set r=[%r%]
set s=%r%%s%
if %n% neq %o% goto g
if %q% gtr 9 set q=[%q%]
set q=%q%:
:n
if %p% gtr 9 (set q=%q%-[%p%]:)else if %p% gtr 0 set q=%q%-%p%:
echo #%q%%m%%s%

Takes three parameters, whole number, numerator, denominator representing a mixed number in its lowest terms.


text:
Shortest self-analyzing program
Oh, <PROGRAM NAME HERE>, tell me how many character '<CHARACTER HERE>'/s are there in your body.

I do not think it a dupe to this. That question asks for printing a list directly but this one requires some input that will cause problem.
Your work is to write a quine-like program/function that takes an input of one character, and respond with a number telling how many times that character occurs in your program. Comments, indents, trailing spaces, line feeds all count.
The range of acceptable input MUST cover all characters the language you are using can accept (not as string literals or comments) and all characters with lesser index in Unicode. For exmaple, Javascript and Python 3 accept Unicode characters for variable name, then it MUST allow Unicode input. For some stack processing languages, there are characters like ‘Ȯß, so part of the non-ASCII input MUST also be acceptable.
For example, if your program is in pure ASCII and only LF
foo(bar,baz)#there is a space->
    do things

The inputs and outputs should be:

\n -> 1
\r -> 0
\t -> 0
 -> 9
a -> 4
b -> 2
( -> 1
) -> 1
\x01 through \x09 -> 0
＋(U+FF0B) -> undefined behaviour (you can even destroy everything or delete the program itself furiously)

The program with least characters wins.

closely related

@PeterTaylor I don't think it's quite a duplicate, it has a difference and that could affect answers greatly.

@Okx I can see why that would be considered a duplicate...

It's definitely a duplicate.

Well, it filters out all characters but the input in the output. Not sure if it is enough to be considered unique, though.

I'm voting to reopen because I think the input taking part is different enough.

Python, 172 chars
lambda a:'-mbda#l.fn()+1: \\\'i'.find(a)+1#\\\\\\\\\\\\\\((((((((())))))))))fffffffbd####lllll......nnnnnnnn+1+1+1+1+1+1+1+1+1+1+11:::::::::::::              '''''''''''''''iiiiiiiiiiiiiiiii

Using str.find()+1 to generate 0 for any character not in program.
Using comment for complement.


text:
Sign change, loop and display with minimal padding
Input:
Two integers: one negative, one positive.
Output:
On the first line output lowest to highest. On the second line we've removed the highest and lowest numbers and sign-changed all individual numbers. On the third line we've removed the highest and lowest numbers again and sign-changed all individual numbers again. etc. (The example below should make the challenge clearer.)
Important: In addition, we add spaces so the numbers in a column are all aligned (to the right).
The minimal alignment is the main part of this challenge, this means that you can't just make every single number the same width. The width of a column is based on the largest number-width of that specific column (and the sequence with sign-change is to give the numbers some variety in width per column).

For example:
Input: -3,6

Output:
-3,-2,-1, 0, 1, 2, 3, 4,5,6   // sequence from lowest to highest
 2, 1, 0,-1,-2,-3,-4,-5       // -3 and 6 removed; then all signs changed
-1, 0, 1, 2, 3, 4             // 2 and -5 removed; then all signs changed again
 0,-1,-2,-3                   // -1 and 4 removed; then all signs changed again
 1, 2                         // 0 and -3 removed; then all signs changed again
                              // only two numbers left, so we're done

As you can see above, spaces are added at the positive numbers, when they share a column with negative numbers to compensate for the - (the same would apply to 2-digit numbers).
Challenge rules:

Input must be two integers

You can assume these integers are in the -99-99 (inclusive) range.
The first integer will be negative, and the other will be positive.

Output can be in any reasonable format, as long as it's clear there are rows and rightly aligned columns: I.e. STDOUT; returning as String with newlines; returning as list of Strings; etc. Your call.
The output must also contain a delimiter of your own choice (except for spaces, tabs, new-lines, digits or -): I.e. ,; and ; and |; and X; etc. are all acceptable delimiters.
The output lines may not contain a leading or trailing delimiter.
The output may contain ONE trailing new-line, and any line may contain any number of trailing spaces.

General rules:

This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.
Default Loopholes are forbidden.
If possible, please add a link with a test for your code.
Also, please add an explanation if necessary.

Test cases:
Input: -3,6

Output:
-3,-2,-1, 0, 1, 2, 3, 4,5,6
 2, 1, 0,-1,-2,-3,-4,-5
-1, 0, 1, 2, 3, 4
 0,-1,-2,-3
 1, 2

Input: -1,1

Output:
-1,0,1
 0

Input: -2,8

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

Input: -15,8

Output:
-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6,7,8
 14, 13, 12, 11, 10,  9, 8, 7, 6, 5, 4, 3, 2, 1, 0,-1,-2,-3,-4,-5,-6,-7
-13,-12,-11,-10, -9, -8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6
 12, 11, 10,  9,  8,  7, 6, 5, 4, 3, 2, 1, 0,-1,-2,-3,-4,-5
-11,-10, -9, -8, -7, -6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4
 10,  9,  8,  7,  6,  5, 4, 3, 2, 1, 0,-1,-2,-3
 -9, -8, -7, -6, -5, -4,-3,-2,-1, 0, 1, 2
  8,  7,  6,  5,  4,  3, 2, 1, 0,-1
 -7, -6, -5, -4, -3, -2,-1, 0
  6,  5,  4,  3,  2,  1
 -5, -4, -3, -2
  4,  3

Input: -3,15

Output:
-3,-2,-1, 0, 1, 2, 3, 4,  5, 6,  7,  8,  9, 10, 11, 12, 13,14,15
 2, 1, 0,-1,-2,-3,-4,-5, -6,-7, -8, -9,-10,-11,-12,-13,-14
-1, 0, 1, 2, 3, 4, 5, 6,  7, 8,  9, 10, 11, 12, 13
 0,-1,-2,-3,-4,-5,-6,-7, -8,-9,-10,-11,-12
 1, 2, 3, 4, 5, 6, 7, 8,  9,10, 11
-2,-3,-4,-5,-6,-7,-8,-9,-10
 3, 4, 5, 6, 7, 8, 9
-4,-5,-6,-7,-8
 5, 6, 7
-6

Input: -12,12

Output:
-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8,  9, 10,11,12
 11, 10,  9, 8, 7, 6, 5, 4, 3, 2, 1, 0,-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11
-10, -9, -8,-7,-6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10
  9,  8,  7, 6, 5, 4, 3, 2, 1, 0,-1,-2,-3,-4,-5,-6,-7,-8,-9
 -8, -7, -6,-5,-4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6, 7, 8
  7,  6,  5, 4, 3, 2, 1, 0,-1,-2,-3,-4,-5,-6,-7
 -6, -5, -4,-3,-2,-1, 0, 1, 2, 3, 4, 5, 6
  5,  4,  3, 2, 1, 0,-1,-2,-3,-4,-5
 -4, -3, -2,-1, 0, 1, 2, 3, 4
  3,  2,  1, 0,-1,-2,-3
 -2, -1,  0, 1, 2
  1,  0, -1
  0

"Never outside -100-100" does that include never being -100 or 100 too?

@JonathanAllan I think so. It makes sense excluding -100 and 100, because if they were included, a 3rd/4th digit will be added and everything would be changed for just 2 values

Related. (Another challenge where padding and right-aligning a grid is the main component.)

@JonathanAllan I've changed the wording a bit. You can assume the smallest possible negative input is -99 and the largest possible positive input is 99.

Proposed test case: -3,15. Some answers don't work properly.

@betseg I've added the proposed test case, and also added -12,12.

The output may also contain a delimiter of your own choice (except for whitespaces and new-lines): I.e. , and ; and | are all acceptable delimiters. Does this mean that the delimiter between numbers can be a space too, it can be omitted or must it be one of those three?

@EriktheOutgolfer "(except for whitespaces and new-lines)".  :) Can be any single character of your choice, except for spaces, tabs or new-lines.

@KevinCruijssen Yeah, I can't really understand what you exactly mean by that. (Note: your memories might have fainted, it's been over a year now :P) EDIT: Hm, so it is necessary.

@EriktheOutgolfer Well, the outputs should be exactly as in the test cases, except that the comma (',') can be any character you like (except for spaces, tabs, or new-lines). So in the first row of the first test case, -3,-2,-1, 0, 1, 2, 3, 4,5,6 may also be -3~-2~-1~ 0~ 1~ 2~ 3~ 4~5~6 or -3X-2X-1X 0X 1X 2X 3X 4X5X6, etc. The digits and spaces as displayed in the test cases are mandatory exactly as displayed however. (Will edit that digits and - are not acceptable delimiters..)

Jelly, 25 24 20 bytes
rµḊṖNµÐĿZbȷG€Ỵ€Zj€”,

This is a dyadic link that returns an array of rows.
Try it online!
How it works
rµḊṖNµÐĿZbȷG€Ỵ€Zj€”,  Dyadic link. Arguments: a, b

r                      Range; yield [a, ..., b].
 µ   µÐĿ               Apply the enclosed chain until the results are no longer
                       unique. Return the array of results.
  Ḋ                      Dequeue; remove the first item.
   Ṗ                     Pop; remove the last item.
    N                    Negate; multiply all remaining integers by -1.
       Z               Zip; transpose rows and columns.
        bȷ             Base 1000; map each n to [n].
          G€           Grid each; in each row, pad all integers to the same length,
                       separating the (singleton) rows by linefeeds.
            Ỵ€         Split each result at linefeeds.
              Z        Zip to restore the original layout.
               j€”,    Join each row, separating by commata.

Java 8, 483 480 486† 467 bytes
(a,b)->{int f=0,l=b-a+3,z[][]=new int[l][l],y[]=new int[l],i,j,k=0;for(;b-a>=0;k++,a++,b--,f^=1)for(j=0,i=a;i<=b;i++)z[k][j++]=f<1?i:-i;String r="",s;for(i=0;i<l;y[i++]=k)for(j=0,k=1;j<l;k=f>k?f:k)f=(r+z[j++][i]).length();for(i=0;i<l;i++){k=z[i][0];if(i>0&&k==z[i][1]&k==z[i-1][2])break;for(j=0;j<l;){k=z[i][j];s="";for(f=(s+k).length();f++<y[j];s+=" ");f=z[i][++j];if(k==f){r+=(i>0&&z[i-1][1]==z[i][1]?s+0:"")+"\n";j=l;}else r+=s+k+(f==z[i][j+1]?"":",");}}return r;}

† Bytes raised due to bug-fix..
Ok, this took A LOT more time (and bytes) than I thought (in Java that is..). This can definitely be golfed some more, probably by using a completely different approach instead of creating an NxN grid-array to fill and then 'strip out' the zeros (with an annoying edge case for the test-case of -1,1, as well as -12,12).
Try it online.
Explanation:
(a,b)->{        // Method with two integer parameters and String return-type
  int f=0,      //  Flag-integer, starting at 0
      l=b-a+3,  //  Size of the NxN matrix,
                //  plus two additional zeros (so we won't go OutOfBounds)
      z[][]=new int[l][l],
                //  Integer-matrix (default filled with zeros)
      y[] = new int[l],
                //  Temp integer-array to store the largest length per column
      i,j,k=0;  //  Index-integers
  for(;b-a>=0   //  Loop as long as `b-a` is not negative yet
      ;         //    After every iteration:
       k++,     //     Increase `k` by 1
       a++,     //     Increase `a` by 1
       b--,     //     Decrease `b` by 1
       f^=1)    //     Toggle the flag-integer `f` (0→1 or 1→0)
    for(j=0,i=a;i<=b;i++)
                //   Inner loop `i` in the range [`a`, `b`]
      z[k][j++]=//    Set all the values in the matrix to:
        f<1?    //     If the flag is 0:
         i      //      Simply use `i`
        :       //     Else (flag is 1):
         -i;    //      Use the negative form of `i` instead
  String r="",  //  The return-String
         s;     //  Temp-String used for the spaces
  for(i=0;i<l;  //  Loop `i` over the rows of the matrix
      ;y[i++]=k)//    After every iteration: Set the max column-width
    for(j=0,k=1;j<l;
                //   Inner loop `j` over the cells of each row
        k=f>k?f:k)
                //     After every iteration: Set `k` to the highest of `k` and `f`
      f=(r+z[j++][i]).length();
                //    Determine current number's width
                //    (NOTE: `f` is no longer the flag, so we re-use it as temp value)
  for(i=0;i<l;i++){
                //  Loop `i` over the rows of the matrix again
    k=z[i][0];  //   Set `k` to the first number of this row
    if(i>0      //   If this isn't the first row
       &&k==z[i][1]&k==z[i-1][2])
                //   and the first number of this row, second number of this row,
                //   AND third number of the previous row all equal (all three are 0)
      break;    //    Stop loop `i`
    for(j=0;j<l;){
                //   Inner loop `j` over the cells of each row
      k=z[i][j];//    Set `k` to the number of the current cell
      s="";     //    Make String `s` empty again
      for(f=(s+k).length();f++<y[j];s+=" ");
                //    Append the correct amount of spaces to `s`,
                //    based on the maximum width of this column, and the current number
      f=z[i][++j];
                //    Go to the next cell, and set `f` to it's value
      if(k==f){ //    If the current number `k` equals the next number `f` (both are 0)
        r+=     //     Append result-String `r` with:
          (i>0  //      If this isn't the first row
           &&z[i-1][1]==z[i][1]?
                //      and the second number of this and the previous rows
                //      are the same (both are 0):
            s+0 //       Append the appropriate amount of spaces and a '0'
           :    //      Else:
            "") //       Leave `r` the same
          +"\n";//     And append a new-line
         j=l;}  //     And then stop the inner loop `j`
      else      //    Else:
       r+=s     //     Append result-String `r` with the appropriate amount of spaces
          +k    //     and the number
          +(f==z[i][j+1]?"":",");}}
                //     and a comma if it's not the last number of the row
  return r;}    //  Return the result `r`

05AB1E, 59 bytes
Once again I'm screwed over by the same bug I wrote a fix for months ago but never pushed...
Golfing should still be possible though.
Ÿ[Ðg1‹#ˆ¦(¨]\\¯vy€g}})J.Bvyð0:S})øvyZs\})U¯vyvyXNèyg-ú}',ý,

Try it online!

I got pretty close with this: ŸÐ',ý,gÍ;µ¦¨(D',ý,¼, it doesn't quite fit the formatting specs, see if you can improve it ;)

@Okx: Yeah the formatting is definitely the tough part here. Something like Ÿ[Ðg1‹#',ý,¦(¨ would be enough otherwise :)

Doesn't work properly for inputs like -3,15.

@betseg: RIght you are. Reverted back to the old version.

Javascript (ES6), 269 bytes
(a,b,d=~a+b+2,o=Array(~~(d/2)+1).fill([...Array(d)].map(_=>a++)).map((e,i)=>e.slice(i,-i||a.a)).map((e,i)=>i%2==0?e:e.map(e=>e*-1)))=>o.map(e=>e.map((e,i)=>' '.repeat(Math.max(...[...o.map(e=>e[i]).filter(e=>e!=a.a)].map(e=>[...e+''].length))-`${e}`.length)+e)).join`
`

Explained:
(                                     // begin arrow function

  a,b,                                // input

  d=~a+b+2,                           // distance from a to b

  o=Array(~~(d/2)+1)                  // create an outer array of
                                      // (distance divided by 2
                                      // floored + 1) length

    .fill(                            // fill each outer element
                                      // with the following:

      [...Array(d)]                   // create inner array of the
                                      // distance length and
                                      // fill with undefined

        .map(_=>a++)                  // map each inner element
                                      // iterating from a to b
    )
    .map(                             // map outer array

      (e,i)=>e.slice(i,-i||a.a)       // remove n elements from each end
                                      // of the inner array corresponding
                                      // to the outer index with a special
                                      // case of changing 0 to undefined
    )
    .map(                             // map outer array

      (e,i)=>i%2==0?e:e.map(e=>e*-1)  // sign change the inner elements
                                      // in every other outer element
    )
)=>                                   // arrow function return

  o                                   // outer array

    .map(                             // map outer array

      e=>e.map(                       // map each inner array

        (e,i)=>' '.repeat(            // repeat space character the
                                      // following amount:

          Math.max(...                // spread the following array to
                                      // max arguments:

            [...                      // spread the following to an
                                      // array:

              o                       // outer array

                .map(e=>e[i])         // map returning each element of
                                      // the same inner index from the
                                      // outer array

                .filter(e=>e!=a.a)    // remove undefined elements
            ]
            .map(e=>[...e+''].length) // map each element to the
                                      // length of the string

          )                           // returns the max string
                                      // length of each column

          -`${e}`.length              // subtract the current
                                      // element's string length
                                      // from the max string length

      )                               // returns the appropriate amount
                                      // of padding

      +e                              // add the element to the padding
    )
  ).join`
`                                     // join each element of outer
                                      // array as string with newline

const f = (a,b,d=~a+b+2,o=Array(~~(d/2)+1).fill([...Array(d)].map(_=>a++)).map((e,i)=>e.slice(i,-i||a.a)).map((e,i)=>i%2==0?e:e.map(e=>e*-1)))=>o.map(e=>e.map((e,i)=>' '.repeat(Math.max(...[...o.map(e=>e[i]).filter(e=>e!=a.a)].map(e=>[...e+''].length))-`${e}`.length)+e)).join`
`
console.log('Test Case: -1,1')
console.log(f(-1,1))
console.log('Test Case: -3,6')
console.log(f(-3,6))
console.log('Test Case: -2,8')
console.log(f(-2,8))
console.log('Test Case: -15,8')
console.log(f(-15,8))
console.log('Test Case: -3,15')
console.log(f(-3,15))
console.log('Test Case: -12,12')
console.log(f(-12,12))

Can you add the new test cases?

QBIC, 46 bytes
::[0,-1*a+b,2|[a,b|?d*q';`]q=q*-1┘a=a+1┘b=b-1?

How it works:
::           Read the negative and positive ints as a and b
[0,-1*a+b,2| FOR(c = 0; c < range(a, b); c+=2) {} This creates the proper amount of lines.
  [a,b|      For each line, loop from lower to upper
    ?d*q     Print the current point in the range, accounting for the sign-switch
     ';`     And suppress newlines. The ' and ` stops interpreting special QBIC commands.
  ]          NEXT line
  q=q*-1┘    Between the lines, flip the sign-flipper
  a=a+1┘     Increase the lower bound
  b=b-1?     Decrease the upper bound, print a newline
             The outermost FOR loop is auto-closed at EOF.

Fortunately, when printing a number, QBasic auto-adds the necessary padding.

Another case of finding the right language to do the job :) +1

+1 Is there an online compiler for QBIC available? I'd like to see it in action for all the test cases (although I take your word it auto-aligns everything). First time I'm seeing QBIC, so two questions when I read your explanation: If I read it correctly q's default value starts at 1? Do all values in QBIC start at 1, or is there something I'm missing here? And what is the d / where does the d stand for? Or is d the current number in the loop and the ? simply a necessary delimited in the for-loop's code (instead of ? being the current number, which was how I initially read it)?

@KevinCruijssen No online interpreter yet, sorry. I'm working on one, but it is harder than you think to get QBasic 4.5 running in your browser :-). q starts at 1. All lowercase letters are number vars and the letters q-z are initialised to 1-10. And several commands auto-assign numbers in the order they are found in the code. d is indeed the iterator on the inner FOR-loop. For more details, see also the showcase - or this

Perl 6, 146 bytes
{$_:=(($^a..$^b).List,{-«.[1..*-2]}...3>*).List;$/:=[map {"%{.max}s"},roundrobin($_)».chars];map {join ',',map {$^a.fmt: $^b},flat($_ Z $/)},$_}

Try it
Produces a sequence of strings
Expanded:
{  # bare block lambda with placeholder parameters ｢$a｣ and ｢$b｣

  # generate the data
  $_ := (                 # bind to $_ so it isn't itemized

                          # produce a sequence
    ( $^a .. $^b ).List,  # seed the sequence, and declare parameters
    { -«\ .[ 1 .. *-2 ] } # get all the values except the ends and negate
    ...                   # keep producing until
    3 > *                 # the length of the produced list is less than 3

  ).List;                 # turn the Seq into a List

  # generate the fmt arguments
  $/ := [                 # bind an array to ｢$/｣ so it isn't a Seq
    map
      { "%{ .max }s" },   # turn into a ｢.fmt｣ argument ("%2s")

      roundrobin($_)\     # turn the "matrix" 90 degrees
      ».chars             # get the string length of each number
  ];

  # combine them together
  map
    {
      join ',',
        map
          { $^a.fmt: $^b }, # pad each value out
          flat(
            $_ Z $/         # zip the individual number and it's associated fmt
          )
    },
    $_                      # map over the data generated earlier
}

PHP 7.1, 277 Bytes
for([,$a,$b]=$argv,$c=count($r=range($a,$b))/2;$c-->0;$r=range(-$r[1],-$r[count($r)-2]))$y[]=array_map(strlen,$x[]=$r);for($i=0;$i<count($y[0]);$i++)$z[$i]=max(array_column($y,$i));foreach($x as $g){$o=[];foreach($g as$k=>$v)$o[]=sprintf("%$z[$k]d",$v);echo join(",",$o)."\n";}

Online Interpreter

Can you link an online interpreter?

@betseg Done and realize that my version had not worked correctly

oh gawd just using php on codegolf.se. HAVE ALL THE UPVOTES.

C# console application 196 Bytes
static void p(int a,int b){string S="",d ="";int c=-1;for(int i=b;i >=a;i--){c=c==1?c=-1:c=1;for(int j = a;j<=i;j++){S=j!=a?",":S="";d=d+S+(j*c);}d+= "\r\n";a++;}Console.Write(d);Console.Read();}

Welcome to PPCG! You can indent your code using 4 spaces (see my edit). In code golf, you need to have the shortest byte-count (the amount of bytes in your code) possible - that means shorter variable names, and removal of spaces. Also, you should put your byte-count in your header once finished.

Javascript - 196 185 176 bytes
function f(i,j){l=[];for(x=i;x<j+1;x++)l.push(x);h='<table>';while(l.length>0){h+='<tr>';for(x=0;x<l.length;x++){h+='<td align=right>'+l[x];l[x]*=-1}l.shift();l.pop()}return h}

I'm not really up to speed with some of the newer JS techniques so this could probably be golfed much more.
Simply creates a good old-fashioned HTML table with no width defined for the cells so the first row defaults to the width of each entry hense optimal spacing. It also (ab)uses HTML's "feature" of not requiring closing tags if a new opening tag comes along first.

<script>
function f(i,j){l=[];for(x=i;x<j+1;x++)l.push(x);h='<table>';while(l.length>0){h+='<tr>';for(x=0;x<l.length;x++){h+='<td align=right>'+l[x];l[x]*=-1}l.shift();l.pop()}return h}
document.write(f(-1,1))
</script>

<script>
function f(i,j){l=[];for(x=i;x<j+1;x++)l.push(x);h='<table>';while(l.length>0){h+='<tr>';for(x=0;x<l.length;x++){h+='<td align=right>'+l[x];l[x]*=-1}l.shift();l.pop()}return h}
document.write(f(-3,6))
</script>

<script>
function f(i,j){l=[];for(x=i;x<j+1;x++)l.push(x);h='<table>';while(l.length>0){h+='<tr>';for(x=0;x<l.length;x++){h+='<td align=right>'+l[x];l[x]*=-1}h+='</tr>';l.shift();l.pop()}return h}
document.write(f(-2,8))
</script>

<script>
function f(i,j){l=[];for(x=i;x<j+1;x++)l.push(x);h='<table>';while(l.length>0){h+='<tr>';for(x=0;x<l.length;x++){h+='<td align=right>'+l[x];l[x]*=-1}h+='</tr>';l.shift();l.pop()}return h}
document.write(f(-15,8))
</script>

<script>
function f(i,j){l=[];for(x=i;x<j+1;x++)l.push(x);h='<table>';while(l.length>0){h+='<tr>';for(x=0;x<l.length;x++){h+='<td align=right>'+l[x];l[x]*=-1}h+='</tr>';l.shift();l.pop()}return h}
document.write(f(-3,15))
</script>

<script>
function f(i,j){l=[];for(x=i;x<j+1;x++)l.push(x);h='<table>';while(l.length>0){h+='<tr>';for(x=0;x<l.length;x++){h+='<td align=right>'+l[x];l[x]*=-1}h+='</tr>';l.shift();l.pop()}return h}
document.write(f(-12,12))
</script>

Python 2 - 208 bytes
Try it online
d,u=input()
l=[x for x in range(d,u+1)]
M=map(lambda x:~9<x<21-u-u%2and 2or 3,l)
M[-1]-=1
M[-2]-=1
while len(l)>0:print','.join(map(lambda i:('%'+'%d'%M[i]+'d')%l[i],range(len(l))));l=map(lambda e:-e,l[1:-1])

Creates array of padding values and then use it to construct needed formated strings
Explanation:
d,u=input()
# create list of all values
l=[x for x in range(d,u+1)]
# create array of padding values
# by default, padding 2 used for numbers in [-9;9] and 3 for all other (limited with -99 and 99)
# but contracting list moves numbers larger that 9 under ones, that are <=9
# so upper limit of padding 2 is limited with 21-u-u%2
# (~9 == -10)
M=map(lambda x:~9<x<21-u-u%2and 2or 3,l)
# last two elements should have lower padding as there won't be any other numbers it their columns
M[-1]-=1
M[-2]-=1
while len(l)>0:
    # create formatted string for every element in l
    # join all strings with comma
    print','.join(map(lambda i:('%'+'%d'%M[i]+'d')%l[i],range(len(l))))
    # get slice without first and last element and change sigh
    l=map(lambda e:-e,l[1:-1])

Hi, welcome to PPCG! Unfortunately, it currently isn't correct. You've added the same margin to all numbers, as well as add spaces as delimiter. The challenge was to use a delimiter of your choosing (except whitespace), but more importantly: have the alignment based on the number with the largest width in that specific column. Please see the Important section of the challenge, as well as the test cases as example. You aren't the first one to do it incorrect, but currently it's not valid with the specified challenge. Feel free to delete, modify to comply to the rules, and undelete your answer

@KevinCruijssen Thank you for pointing this! I've updated my answer

That indeed looks a lot better! Only one small rule you forgot: "The output may also contain a delimiter of your own choice (except for whitespaces and new-lines): I.e. , and ; and | are all acceptable delimiters." Currently you use a space as delimiter. But the main difficulty of the width has indeed been tackled, so you're doing great so far! Only this small change, and then it should be done. :)

@KevinCruijssen And know it seems that it finaly done. Thanks again for pointing out my mistakes!

Perfect! +1 Good job correcting everything. And once again welcome to PPCG. (Btw, is the space here: %l[i], range required?)

@KevinCruijssen I hope to stick around PPCG for awhile, it seems very interesting (nope, saved one more byte)

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


text:
Solve an equation with (almost) any numbers you like
Given a string of the characters +=- where there is at least one =, insert positive integers between all the symbols and at the start and the end such that the math equations are satisfied.
For example, given the input
+-=-=

you need to insert positive integers A through F like this
A+B-C=D-E=F

such that the equations are all satisfied, i.e. A + B - C and D - E and F are all the same number.
There are many possible ways to do this since, as long as the equations work out, any set of positive integers may be used. Each line here is a possible valid output to input +-=-=:
2+3-4=6-5=1
1+1-1=2-1=1
4+2-4=4-2=2
100+1-10=182-91=91
89+231-77=1024-781=243

Note that the value of the expressions is not required to be a positive integer like the inserted numbers are. For example, given input -=- the outputs 1-10=8-17 (evals to -9) and 10-1=17-8 (evals to 9) are both equally valid. Of course for some inputs such as = it's impossible to have a negative as the expression since only positive numbers like 5=5 can be inserted.
Note also that zero is not a positive integer.
The shortest code in bytes wins.
You may output the numbers as a list instead of inserting them directly into the string. If you do output the string there may be spaces separating symbols and numbers. So, for input +-=-=, outputting
2, 3, 4, 6, 5, 1

or
2 + 3 - 4 = 6 - 5 = 1

is equivalent to outputting
2+3-4=6-5=1

Test Cases
Input | One Possible Output
= | 1=1
== | 2=2=2
+= | 1+3=4
=+ | 2=1+1
-= | 30-10=20
=- | 1=2-1
=-= | 3=7-4=3
=+= | 2=1+1=2
=== | 100=100=100=100
+=- | 3+2=7-2
-=+ | 7-2=3+2
+=+ | 3+3=3+3
-=- | 1-10=8-17
--= | 60-1-1=58
++= | 60+1+1=62
-+= | 60-9+1=52
+-= | 60+9-1=68
+-=-= | 2+3-4=6-5=1
--=-- | 2-1-1=2-1-1
==-== | 47=47=50-3=47=47
=++=+-=-+=--= | 3=1+1+1=3+1-1=1-1+3=5-1-1=3
+--++-=-+-+- | 35+10-16-29+20+107-1000=5-4+3-2+1-876
====== | 8=8=8=8=8=8=8

Related.

Can we assume any upper bound on the length of the formula?

@xnor You may assume the input is less than 2^16 characters long if that helps.

Retina, 58 bytes
[-+]
$&1
\B((\+1)|(-1))*
$._$*1$#3$*1$#2$*_$&
+`1_

1+
$.&

Try it online!
Alternative solution at the same byte count:
((\+)|(-))*
$._$*1$#3$*1$#2$*_$&
+`1_

([+-])1*
$+1
1+
$.&

Try it online!
Explanation
The basic idea is to turn all the +s and -s into simple +1 and -1 operations and then to prepend a sufficiently large number that makes all the equations work. To make the equations match, we can simply prepend the same number to each of them, and then reduce it by one for each +1 and increase it by one for each -1 after it. Since we'll be working with unary numbers, the only catch is that the first number needs to be large enough that we can reduce it by 1 enough times.
[-+]
$&1

We start by inserting a 1 after each - or +.
\B((\+1)|(-1))*
$._$*1$#3$*1$#2$*_$&

The \B ensures that these matches are either at the beginning of the input, or between a = and a + or -, i.e. all the positions where we want to insert the leading number of an expression. The  ((\+1)|(-1))* part then simply counts the number of +1s and -1s in groups 2 and 3 respectively. Now let's break down the substitution string:
$._$*1   # For each character in the current string, insert a 1. This is
         # an offset which is the same for each expression and is guaranteed
         # to be large enough that all subsequent +1s can be cancelled.
$#3$*1   # For each -1, insert a 1.
$#2$*_   # For each +1, insert a _.
$&       # Re-insert the string of +1s and -1s.

+`1_

Repeatedly drop 1_ from the string, applying the required cancellation from the +1s.
1+
$.&

Finally, replace all the strings of 1s with their lengths to convert from unary to decimal.

Python 2, 76 bytes
lambda e:sum([[len(e+s)-2*s.count('+')]+[1]*len(s)for s in e.split('=')],[])

Try it online!

Can you add an explanation?

@HelkaHomba The idea is fairly simple: first take each chunk of the input split by equal signs. Choose the first number of each chunk to be eqtn_len + plus_signs + minus_signs - 2 * plus_signs = eqtn_len + minus_signs - plus_signs. Then since all the other numbers in the chunk are ones, the total for the chunk works out to eqtn_len + minus_signs - plus_signs - minus_signs + plus_signs = eqtn_len. The equation length has to be positive, so everything works out.

Python 2, 199 179 178 172 162 158 156 152 151 bytes
Way too long, but the solution was easy to create.
from itertools import*
i=input()
k='%s'
s=k+k.join(i)+k
for p in product(*[range(1,65537)]*-~len(i)):
    if eval((s%p).replace('=','==')):print s%p;break

Try it online
This will try every possibility until it finds a solution. The program is extremely slow. It also performs the string replacement every iteration. The "172" edit made it drastically slower, since rather than starting with a small range it starts at the max. For example, the inputs -= or =+ have to try 2**32 attempts before reaching a solution.
To speed up the program, use the version with 178 bytes from the edit history.

Doesn't range in python2 create the whole range as a list immediately? IIRC you could speed it up by using xrange instead, as I think that's the lazy-loading version (Python3 uses lazy as the default range)

@Delioth That uses another byte, though. The goal is to remove bytes. Also, that wouldn't actually provide much speedup, since the majority of the slowdown is from the number of iterations, not the creation of the list, which only occurs once. I ran print range(1,65537) and it completed in 0.034 s.

Well, of course- more of a "this could speed it up with exactly the same methodology," on the worry of it taking so long. Memory thrashing could cause significant slowdown. Also, you could cut some bytes (maybe only 1) by not setting l=..., but putting that right in the product(range(...),repeat=len(s)+1). If you need parentheses it only saves one byte (\n)

@Delioth Even if I needed parens around len(s)+1, I could use -~len(s) instead, which wouldn't require parens.

Ah, right. I always forget about bitwise operations and tricks- must be the toll working on frontend javascript is taking on my Python expertise!

k='%s';s=k+k.join(i)+k is slightly shorter than s='%s'+'%s'.join(i)+'%s'

You only need one space of indentation.

@OldBunny2800 That's a tab. SE renders tabs as four spaces, but you can see the actual tab by viewing the post in edit mode or by visiting the Try It Online link.

You can shave off two characters by constructing the repeated argument to product directly: for p in product(*[range(1,65537)]*(len(i)+1)):

@alexwlchan I saved 4 by not using parens around the length.

Shave off another char by replacing exit() with break?

Yeah. This didn't work back when there was a while loop outside, but it will be possible now.

Python 2, 120 119 bytes
-1 byte thanks to mbomb007

a=['1'+(n and('1'.join(n)+'1'))for n in input().split('=')]
print'='.join(`max(map(eval,a))-eval(c)+1`+c[1:]for c in a)

Try it online! or Verify all test cases
First I insert 1 in every position, to check the highest value, then add it as offset on every equation.  This work because you can't add negative numbers, so the minimum result is given by the amount of + in the equation that only have +.

You can remove a couple spaces.

JavaScript (ES6), 92 82 bytes
Golfed 8 bytes with a trick from @xnor

let f =
x=>x.split`=`.map(q=>(x+q).length-2*~-q.split`+`.length+[...q,''].join(1)).join`=`
<input oninput="if(/^[+=-]+$/.test(value))O.innerHTML=f(value)" value="=">

1=1

The trick here is to insert a 1 after every + or -, then prepend to each expression the number that makes the expression equal the length of the input. This way we can guarantee that the number is always positive; since there's always at least 1 = in the string, the number of +s can never reach the length of the string, so the remainder is always at least 1. You can verify this by typing in an arbitrary number of +s in the snippet above.

GNU Prolog, 156 bytes
x(L,R,V)-->{E#>0},({L=[E|R],E=V};x(L,[E|R],X),("+",{V#=X+E};"-",{V#=X-E})).
q(L,R,V)-->x(L,T,V),({T=R};"=",q(T,R,V)).
s(Q,L):-q(L,[],_,Q,[]),fd_labeling(L).

Explanation
We've got a bunch of equations to solve, so why not use an actual equation solver?
x is basically an equation evaluator for equations of the form +-+; in addition to the equation itself, it has two additional arguments (a difference list L,R that contains the values of the equation, and a value V that the equation evaluates to). As usual in Prolog, it can be used any way round (e.g. you can specify V and get an L,R, specify L,R and get a V, specify both and verify that the value is correct, or specify neither in which case appropriate constraints will be placed on both V and L,R). The "current element" of L,R is named E, and we also include an assertion that E is greater than 0 (because the question requires the use of positive numbers). This function is slightly more verbose than I'd like, e.g. I had to write the [E|R] pattern match/unmatch twice, due to the fact that lists are right-associative but addition and subtraction are left-associative. Sadly, we need to use an actual list, rather than inventing our own left-associative list type out of cons cells, for fd_labeling to work.
q is similar to x, but also includes =. It basically just calls x, and itself recursively. Incidentally, it's a very clear demonstration of how difference lists work, showing that you can concatenate two difference lists L,T and T,R into a single difference list L,R. The basic idea is that a difference list is a partial function that takes an argument R and returns a value L which is R with the list itself prepended to it. Thus, by identifying the argument of one difference list and the return value of another, we can compose the functions, and thus concatenate the lists.
Finally, s, which is the funciton that actually solves the task in the question, is a wrapper function that calls q with arguments. We convert the difference list to a regular list by supplying [] as its argument, and use fd_labeling to find a solution to the equation we built up. (By default, it appears to like setting values to 1 if there's no reason to set them to something else. However, it can be configured; value_method(random) gives more "interesting" solutions than putting 1s everywhere, for example, and is still very fast.)
Sample output
With the program as written:
| ?- s("=++=+-=-+=--=", V).

V = [3,1,1,1,3,1,1,3,1,1,5,1,1,3] ?

If I make the program a bit longer to add a value_method(random), the outcome varies, but looks something like this:
| ?- s("=++=+-=-+=--=", V).

V = [68,6,12,50,85,114,131,45,3,26,71,1,2,68] ?

In both cases, the ? at the end of the output means that there may be more than one solution. (Of course, in this case, we know that there's a lot more than one solution!)

Mathematica, 116 bytes
Join@@(Prepend[#^2,1-Min[Tr/@c]+Tr@#]&/@(c=Characters@StringSplit["0"<>#<>"0","="]/."+"->-1/."-"->1/."0"->Nothing))&

Pure function taking a string as input and returning a list of positive integers. Basic strategy: we only ever add 1 and subtract 1, and we choose the initial numbers in each expression to make everything equal.
c=Characters@StringSplit[#,"="]/."+"->-1/."-"->1 would split the input string at every equals sign, then replace each + by -1 and each - by 1. However, if there's an equals sign at the beginning or end, then it would get ignored. Therefore we artificially add a new character at each end ("0"<>#<>"0") and make it go away after the string-splitting is complete (/."0"->Nothing).
The total of each sublist now equals an integer that we can put in front of the +s and -s to make each expression equal. 1-Min[Tr/@c] is the smallest integer that we can add to each total to make them all positive. So Prepend[#^2,1-Min[Tr/@c]+Tr@#]& takes each sublist (the ^2 turns all their entries to 1) and prepends its total shifted by this smallest compensating integer. The resulting lists are Joined together to produce the output.

PHP, 207 204 197 114 bytes
direct approach: much shorter and faster
foreach(explode("=",$argn)as$t)echo"="[!$c],strlen($argn)+($c=count_chars($t))[45]-$c[43],@chunk_split($t,!!$t,1);

Run with echo '<input>' | php -nR '' or test it online.
breakdown
foreach(explode("=",$argn)as$t) // loop through terms
    echo                            // print ...
        "="[!$c],                       // 1. "=" if not first term
        strlen($argn)                   // 2. maximum number
            +($c=count_chars($t))[45]   //    + number of "-"
            -$c[43],                    //    - number of "+"
        @chunk_split($t,!!$t,1);        // 3. each operator followed by "1"

!$c is true in the first iteration, cast to 1 for string indexing; "="[1] is empty.
After that, $c is set and !$c false, cast to 0 and "="[0] is the first character.
The maximum value for any term needs not exceed the number of pluses +1;
so we´re definitely safe with the length of the input. All terms will evaluate to that.
chunk_split($s,$n,$i) inserts $i after every $n characters of $s - and at the end.
To prevent empty terms turning to 1, an error is forced by setting the chunk length to 0.

Ruby, 76
->s{(?1+s.gsub(/./){|a|a+?1}).split(?=).map{|e|e[0]="#{5**8-eval(e)}";e}*?=}

The target value for the expressions is fixed at 5**8 minus 1 for golfing reasons! Originally I was using s.size+1 minus 1.
Ungolfed in test program
f=->s{(?1+s.gsub(/./){|a|a+?1}).           #add a 1 at the beginning and after every symbol
       split(?=).                          #split into an array of expressions at = signs
       map{|e|                             #for each expression string
         e[0]="#{5**8-eval(e)}";e          #change the first number to 5**8-eval(e)
       }*?=                                #and rejoin the strings
}

puts f["="]
puts f["=="]
puts f["+="]
puts f["=+"]
puts f["-="]
puts f["=-"]
puts f["=-="]
puts f["=+="]
puts f["==="]
puts f["+=-"]
puts f["-=+"]
puts f["+=+"]
puts f["-=-"]
puts f["--="]
puts f["++="]
puts f["-+="]
puts f["+-="]
puts f["+-=-="]
puts f["--=--"]
puts f["==-=="]
puts f["=++=+-=-+=--="]
puts f["+--++-=-+-+-"]
puts f["======"]

Output
390624=390624
390624=390624=390624
390623+1=390624
390624=390623+1
390625-1=390624
390624=390625-1
390624=390625-1=390624
390624=390623+1=390624
390624=390624=390624=390624
390623+1=390625-1
390625-1=390623+1
390623+1=390623+1
390625-1=390625-1
390626-1-1=390624
390622+1+1=390624
390624-1+1=390624
390624+1-1=390624
390624+1-1=390625-1=390624
390626-1-1=390626-1-1
390624=390624=390625-1=390624=390624
390624=390622+1+1=390624+1-1=390624-1+1=390626-1-1=390624
390624+1-1-1+1+1-1=390625-1+1-1+1-1
390624=390624=390624=390624=390624=390624=390624

Röda, 112 110 109 bytes
f x{[(`:$x:`/"=")()|{|p|p~=":",""a=p;a~=`\+`,""b=p;b~="-","";["=",#x-#b+#a];{(p/"")|{|o|[o,"1"*#o]}_}}_][1:]}

Try it online!
The split function did not work as I intended with this program. For example, split("", sep="") returns one empty string instead of nothing. How is that logical? Due to this the program is nearly 20 bytes larger than what it could be if the split semantics were ideal.
The idea of this answer is that we know that the length of the input string must be greater or equal to the value of the equation, so we define the value of the equation to be the length of the string. For every part of the equation, we think every operator being +1 or -1 and subtract and add them to value of the equation.
Ungolfed:
function f(x) {
    /* Adds ":"s around the string to prevent "=" being split wrong. */
    [split(`:$x:`, sep="=") | for p do
        p ~= ":", ""          /* Removes colons. */
        a := p; b := p        /* Initializes a and b to be p. */
        a ~= "\\+", ""        /* The lengths of a and are now equal to the */
        b ~= "-", ""          /* numbers of "-" and "+" characters in x. */
        push("=", #x-#b+#a)   /* Prints "=" and the value of the equation */
                              /* minus number of "+"s plus number of "-"s. */
        split(p, sep="") | for o do /* For each operator: */
            push(o)                 /* Prints the operator. */
            push(1) if [o != ""]    /* Prints 1 unless the operator is "". */
        done
    done][1:] /* Removes the first character of the output ("="). */
}