text:
Find a maximal rectangle of 1s
Background
I want to buy an plot of land and build my house on it.
My house should be rectangular, and as large as possible; however, the available plots have lots of rocky areas that I cannot build on, and I'm having trouble fitting a potential house on the plots.
I want you to write a program that analyzes the plots for me.
Input and output
Your input is a rectangular 2D array of bits, of size at least 1×1, in any reasonable format.
The array represents a plot of land; 1s are "good" areas where I could build my house, and 0s are "rocky" areas where the house cannot be built.
Your output shall be the maximal area of a solid rectangle of 1s in the input array.
It represents the area of the largest house I could build on the plot.
Note that if there are no 1s in the input, then the output is 0.
Example
Consider the input
101
011
111

The largest rectangle of 1s is the 2×2 rectangle in the lower right corner.
This means that the correct output is 4.
Rules and scoring
You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
Test cases
0
-> 0

1
-> 1

00
00
-> 0

01
10
-> 1

01
11
-> 2

111
010
111
-> 3

101
011
111
-> 4

0111
1110
1100
-> 4

1111111
1110111
1011101
-> 7

111011000
110111100
001111110
011111111
001111110
000111100
000011000
-> 20

000110000
110110010
110111110
110011100
010011111
111111111
111101110
-> 12

Bulldozer, 4 bytes: plow.

Is it OK if my solution only works for rectangles of up to 30×30?

@Neil No, it should (at least theoretically) work for about as large inputs as your language can handle.

I was hoping to do some sneaky bit-twiddling but in that case I won't bother.

Could we have the option to receive the dimensions of the land also?

@miles Only if your language can't extract them from the array in another way.

@neil do it in Ruby or Python then. Both support arbitrary precision integers. That said, "as large as your language can handle" is a bit open to interpretation. 8x8 in brainfuck would be mighty impressive, but I'm sure it's (theoretically) possible to go bigger :-S

@LevelRiverSt Fortunately I found a way of doing it without limiting myself to 30.

Does the solution need to account for rotation?

@YiminRong No, the sub-rectangle of 1s will not be rotated. Although I'm not entirely sure that's what you meant.

Jelly, 21 20 18 17 bytes
ṡṂ€€×"
‘×¥\ç"Ụ€FṀ

Try it online! or verify all test cases.
Background
Let M be a matrix of bits such as
0 0 0 1 1 0 0 0 0
1 1 0 1 1 0 0 1 0
1 1 0 1 1 1 1 1 0
1 1 0 0 1 1 1 0 0
0 1 0 0 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 0

We start by counting the number of 1 bits in each column of M, resetting the count every time we encounter a 0 bit.
For our example matrix, this gives
0 0 0 1 1 0 0 0 0
1 1 0 2 2 0 0 1 0
2 2 0 3 3 1 1 2 0
3 3 0 0 4 2 2 0 0
0 4 0 0 5 3 3 1 1
1 5 1 1 6 4 4 2 2
2 6 2 2 0 5 5 3 0

Next, we compute all contiguous sublists of each row. We achieve this by generating all slices of length k, where k varies between 1 and the number of entries in each row.
For the penultimate row, this gives
[1], [5], [1], [1], [6], [4], [4], [2], [2]
[1, 5], [5, 1], [1, 1], [1, 6], [6, 4], [4, 4], [4, 2], [2, 2]
[1, 5, 1], [5, 1, 1], [1, 1, 6], [1, 6, 4], [6, 4, 4], [4, 4, 2], [4, 2, 2]
[1, 5, 1, 1], [5, 1, 1, 6], [1, 1, 6, 4], [1, 6, 4, 4], [6, 4, 4, 2], [4, 4, 2, 2]
[1, 5, 1, 1, 6], [5, 1, 1, 6, 4], [1, 1, 6, 4, 4], [1, 6, 4, 4, 2], [6, 4, 4, 2, 2]
[1, 5, 1, 1, 6, 4], [5, 1, 1, 6, 4, 4], [1, 1, 6, 4, 4, 2], [1, 6, 4, 4, 2, 2]
[1, 5, 1, 1, 6, 4, 4], [5, 1, 1, 6, 4, 4, 2], [1, 1, 6, 4, 4, 2, 2]
[1, 5, 1, 1, 6, 4, 4, 2], [5, 1, 1, 6, 4, 4, 2, 2]
[1, 5, 1, 1, 6, 4, 4, 2, 2]

Next, we map each slice to the product of its minimum and its length. For each slice, this computes the area of the rectangle of 1 bits of maximum height that has the given slice as bottom row.
For the slices of length 3 of the penultimate row of our example matrix, this gives
3 3 3 3 12 6 6

All that's left to do is take the maximum across all slices of all rows.
For our example matrix, this gives 12.
How it works
‘×¥\ç"Ụ€FṀ  Main link. Argument: M (2D list of bits)

   \        Reduce the columns of M by the link to the left.
  ¥           Combine the two atoms to the left into a dyadic chain.
‘               Increment the left argument.
 ×              Multiply the result with the right argument.
      Ụ€    Grade up each; yield the indices of each row of M, sorted by their
            values. The order is not important here; we just need the indices.
    ç"      Apply the helper link to each element of the result to the left and
            the corresponding element of the result to the right.
        F   Flatten the resulting, nested list.
         Ṁ  Extract the maximum.

ṡṂ€€×"      Helper link. Arguments: R (row), X (indices of R)

ṡ           For each k in X, split R into overlapping slices of length k.
 Ṁ€€        Compute the minimum of each individual slice.
    ×"      Multiply the minima of all slices of length k by k.

I didn't know you where this rich, Dennis. €$€€€

It's all about the money. Exchanging $ for ¥ saved 2 bytes.

How on our mother earth do you always come up with clever approaches like this?

Because one does not simply outgolf Dennis!

MATL, 32 31 27  bytes
n:"@:"@1M2$ltntG4$bZ+=a*vX>

This uses a brute-force 2D convolution-based approach. All possible rectangle sizes are created and convolved with the terrain. The maximum result of all convolutions is the maximal rectangle area.
This is an extremely inefficient solution because in order to save bytes, I create kernels for all rectangles between [1, 1] and [numel(input) numel(input)] rather than actually determining the number of rows/columns in the input to determine the proper rectangle dimension ranges.
Thanks to @Luis for suggesting the usage of M and omitting the ]].
Try it Online!
Explanation
        % Implicitly grab input as a 2D numeric array
n       % Compute the number of elements in the input (over estimation of max kernel size)
:       % Create array 1:n
"       % For each value
  @     % Current loop index
  :     % Create an array from 1:(current_index)
  "     % For each of these values
    @   % Push the current index onto the stack
    1M  % Grab the input to the previous function call (the outer index)
    2$l % Create an array of 1's whose dimensions are specified by top two stack elements
    tn  % Duplicate this array and compute number of elements
    t   % Duplicate this number
    G   % Explicitly grab input
    4$b % Bubble up the 4th element from the stack (the kernel)
    Z+  % Perform 2D convolution of this kernel and the input
    =a  % Determine if any convolution result (in each column) is equal to the area of the kernel.
        % This yields a row vector
    *   % Multiply the logical result by the area
    v   % Vertically concatenate all results (forces the row vectors above to be column vectors)
    X>  % Compute the maximum yielding the largest area
        % Implicitly display the result.

Julia, 83 60 57 53 bytes
!M=M⊆1?sum(M):maximum(t->!rotr90(M,t)[2:end,:],0:3)

Try it online! The last test case exceeds TIO's time limit, but I've verified it locally.
How it works
First, ! checks if its matrix argument M consists entirely of 1's.

If so, ! returns the sum of M's entries, which is equal to its area.
If not, ! does the following:

Rotate M by 0°, 90°, 180° and 270° clockwise.
Remove the first row of each of the four rotations, effectively removing one of top row, bottom row, leftmost column and rightmost column of M.
Call itself recursively on each of the submatrices.
Return the maximum of the return values from the recursive calls.

JavaScript (ES6), 97 bytes
a=>a.map((b,i)=>a.slice(i).map((c,j)=>c.map((d,k)=>(n=(b[k]&=d)&&n+j+1)>r?r=n:0,n=0),c=[]),r=0)|r

Turns out bit twiddling still wins. Accepts an array of array of integers. Ungolfed:
function rect(array) {
    var max = 0;
    for (var i = 0; i < array.length; i++) {
        var bits = array[i];
        for (var j = 0; i + j < array.length;) {
            var row = array[i + j];
            j++;
            var size = 0;
            for (var k = 0; k < row.length; k++) {
                if (!row[k]) bits[k] = 0;
                size = ones[k] ? size + j : 0;
                if (size > max) max = size;
            }
        }
    }
    return max;
}

The array is sliced by rows as per the other answers, so each possible range of rows is looped over. Given a range of rows, the next step is to measure the available rectangles. This is achieved by ANDing the rows together bitwise; the result is a list of bits which were set in the entire range of rows. It then remains to find the maximal length of set bits in the row and multiply that by the height of the range. Test shamelessly stolen from @ed65:

f=
a=>a.map((b,i)=>a.slice(i).map((c,j)=>c.map((d,k)=>(n=(b[k]&=d)&&n+j+1)>r?r=n:0,n=0),c=[]),r=0)|r

// test cases as strings, converted to 2d arrays
result.textContent = [
  ['0', 0],
  ['1', 1],
  ['00 00', 0],
  ['01 10', 1],
  ['01 11', 2],
  ['111 010 111', 3],
  ['101 011 111', 4],
  ['0111 1110 1100', 4],
  ['1111111 1110111 1011101', 7],
  ['111011000 110111100 001111110 011111111 001111110 000111100 000011000', 20],
  ['000110000 110110010 110111110 110011100 010011111 111111111 111101110', 12]
].map(t => t[0].replace(/ /g, '\n') + '\n' + t[1] + '\n' + f(t[0].split` `.map(r => [...r]))).join`\n\n`

I would upvote, but as your reputation is exactly 10000000000000 in binary, I think I'll leave it a while.

i m taking turn to mess it :D ,a similar idea came upto my mind but i use to come always too late :p

Python 2.7, 93 91 89 81 79 bytes
f=lambda M,t=1:max(f(M[1:]),f(zip(*M)[::-1],t+1))if`t/3`in`M`else`M`.count(`t`)

Input is a list of tuples. Verify the smaller test cases here and the larger test cases here.
Without memoization, the last two test cases exceed Ideone's time limit, as they require, resp., 1,530,831,935 and 2,848,806,121 calls to f, which takes 39 and 72 minutes on my machine.
Algorithm
For a given matrix M, the general idea is to iterate over all submatrices of M by removing top rows and rotating quarter turns counterclockwise, keeping track of the sizes of encountered submatrices that consist entirely of 1 bits.
Golfing a straightforward recursive implementation of the above idea lead to a function f(M) that does the following.

If M doesn't contain any 0 bits, return its number of 1 bits.
If we have rotated M two times already and it doesn't contain any 1 bits, return 0.
If we have rotated M five times already, return 0.
Recursively call f on M without its top row.
Recursively call f on M rotated a quarter turn counterclockwise.
Return the maximum of the return values from the recursive calls.

Code
In the implementation, we use an additional function argument t that defaults to 1 to keep track of how many times we have rotated this particular matrix already. This allows condensing steps 1 to 3 into a single step by testing `t/3`in`M` and returning `M`.count(`t`) if the test fails.

If t = 1, we haven't rotated this particular submatrix previously in this branch.
t / 3 = 0, so `t/3`in`M` will return True iff the string representation of M contains the character 0.
If it doesn't, we return `M`.count(`t`), the number of times the character 1 appears in the string representation of M.
Note that a matrix without 0 bits can occur only if t = 1, since we do not recurse in this case.
If 3 ≤ t ≤ 5, we've previously rotated this particular submatrix at least two times in this branch.
t / 3 = 1, so `t/3`in`M` will return True iff the string representation of M contains the character 1.
If it doesn't, we return 0 computed as `M`.count(`t`), the number of times the string representation of t (i.e., the character 3, 4 or 5) appears in the string representation of M.
If t = 6, we've previously rotated this particular submatrix five times in this branch.
t / 3 = 2, so `t/3`in`M` will return False, because the string representation of M does not contain the character 2.
We return 0 computed as `M`.count(`t`), the number of times the character 6 appears in the string representation of M.

If f didn't return already, the remaining steps are executed.

f(M[1:]) calls f on M without its top row. Since t isn't specified, it defaults to 1, signaling that this is the first time f encounters this particular submatrix in this branch.
f(zip(*M)[::-1],t+1) calls f on M rotated a quarter turn counterclockwise, incrementing t to keep track of the time we've rotated this particular submatrix in this branch.
The quarter turn is obtained by zipping the rows of M with each other, returning tuples of the corresponding elements of M's rows, thus transposing M, then reversing the order of rows (i.e., placing the top row at the bottom and vice versa).
Finally max returns the maximum of the return values from the recursive calls.

hmm all those submissions are distinguished ideas ? pretty fascinating, what does the zip function do ?

zip returns a list of tuples of the corresponding elements of its arguments. With an unpacked 2D list (matrix) *M, it essentially transposes rows and columns, so zip(*M[::-1]) performs a 90° rotation clockwise.

thx, python is a charm, i ll learn it someday.

APL (Dyalog Extended), 27 23 20 bytes
-3 bytes by Adám and ngn
{⌈/∊(×/×⍵⍷⍨⍴∘1)¨⍳⍴⍵}

Try it online!
{⌈/∊(×/×⍵⍷⍨⍴∘1)¨⍳⍴⍵}    Monadic function taking an argument ⍵:
                 ⍳⍴⍵     Indices: e.g. for a 3x7 array
                                       (1 1) (1 2) ...  (1 7)
                                       (2 1) (2 2)  ... (2 7)
                                       (3 1) (3 2)  ... (3 7)
    (×/×⍵⍷⍨⍴∘1)         Helper fn: Takes ⍵ and x (e.g. (2 2))
            ⍴∘1             Make an array of 1s of shape x. Call it a.
        ⍵⍷⍨                 All places where a exists in x
     ×/                      Product of x's dims (size of a)
       ×                 Size of a where a is in ⍵, and 0 elsewhere.
    (×/×⍵⍷⍨⍴∘1)¨        Call the helper function on x and each (¨) index.
                            We now have a nested list containing sizes of blocks in ⍵
                            and many 0s.
   ∊                        Flatten
 ⌈/                        Find the maximum value.

{⌈/,(×/×1∊⍵⍷⍨⍴∘1)¨⍳⍴⍵} is shorter and simpler (doesn't even require Extended).

@lirtosiast @Adám {⌈/∊(×/×⍵⍷⍨⍴∘1)¨⍳⍴⍵}

JavaScript (ES6), 154 176
Edit tried to shorten a bit, but cannot compete against @Neil's solution
Try every possible rectangle, return the max size. Probably the same algorithm of the Matl answer, just 6 times longer.
Input as a 2d array of integers
g=>g.map((r,i)=>r.map((x,j)=>v=s(r,j,(_,l)=>s(g,i,(_,k)=>!s(g,k,r=>s(r,l,x=>!x,l+j+1),k+i+1)))&(t=-~i*-~j)>v?t:v),s=(a,i,l,j)=>a.slice(i,j).some(l),v=0)|v

Less golfed
This is the original algorithm, the golfed version abuse a lot of array traversing function istead of for loops
g=>{
  v = 0
  for(i = h = g.length; i; i--)
    for(j = w = g[0].length; j; j--)
    {
      p = true
      for(k=0; p && k <= h-i; k++)
        for(l=0; p && l <= w-j; j++)
          p = g.slice(k, k+i).some(r=>r.slice(l, l+j).some(x=>!x));
      if (!p && i*j<v)
        v = i*j
    }
  return v
}

Test

f=g=>g.map((r,i)=>r.map((x,j)=>v=s(r,j,(_,l)=>s(g,i,(_,k)=>!s(g,k,r=>s(r,l,x=>!x,l+j+1),k+i+1)))&(t=-~i*-~j)>v?t:v),s=(a,i,l,j)=>a.slice(i,j).some(l),v=0)|v

console.log=(...x)=>O.textContent+=x+'\n'

// test cases as strings, converted to 2d arrays
;[
  ['0',0],['1',1],['00 00',0],['01 10',1],['01 11',2],
  ['111 010 111',3],['101 011 111',4],
  ['0111 1110 1100',4],['1111111 1110111 1011101',7],
  ['111011000 110111100 001111110 011111111 001111110 000111100 000011000',20],
  ['000110000 110110010 110111110 110011100 010011111 111111111 111101110',12]
].forEach(t=>{
  var k=t[1]
  var p=t[0].split` `.map(r=>[...r].map(x=>+x))
  var r=f(p)
  console.log((r==k?'OK':'KO')+' '+r+(r==k?'':' expected '+k)+'\n'+p.join`\n`+'\n')
  })

Brachylog, 20 17 15 bytes
Thanks to Kroppeb for 2 bytes
{s\sc≡ᵛ¹l}ᶠ⌉|hh

Try it online!
Explanation
{        }ᶠ      Find all possible outputs of the following predicate:
 s                Find a sublist of the array (i.e. remove 0 or more rows from the top
                  and/or bottom)
  \               Transpose the array
   s              Find a sublist again
                  The result is some sub-rectangle of the array
    c             Concatenate all the rows in that rectangle into one list
     ≡ᵛ¹          Verify that all the elements are 1
        l         Get the length (i.e. how many 1's make up the rectangle)
                 Now we have a list of the sizes of all possible 1-rectangles
           ⌉     Take the maximum

            |    If no 1-rectangles could be found:
             hh   Take the head of the head of the array (i.e. the top left element)
                 Since the array contains no 1's in this case, this will give 0

aa can be replaced by s
Try it online!

R, 129 122 bytes
function(M,D=dim(M),L=`for`){L(i,1:D,L(j,1:D[2],L(r,0:(D-i),L(c,0:(D[2]-j),F<-max(F,i*j*(i*j==sum(M[r+1:i,c+1:j])))))))
F}

Try it online!
Plain and simple brute force approach.
Unrolled code and explanation :
function(M){                       # M is the matrix of 0/1
n = 0                              # n is the biggest rectangle found
R=nrow(M)
C=ncol(M)
for(i in 1:R)                      # for each possible num of rows of the rectangle
  for(j in 1:C)                    # for each possible num of cols of the rectangle
    for(r in 0:(R-i))              # for each possible position offset on the rows
      for(c in 0:(C-j){            # for each possible position offset on the cols

         subM = M[1:i+r,1:j+c]     # sub-set the matrix given the size of rectangle and offsets

         if(sum(subM)==i*j)        # if sub-matrix is full of 1's
            rec = i*j              # (i.e. nrow*ncol == sum of values in sub-matrix)
         else                      # store the rectangle area
            rec = 0                # otherwise store 0

         n = max(n,rec)            # keep the maximum rectangle found
      }
}

Stax, 14 bytes
π└ÿ§L▓═J║φ§╦╢9

Run and debug it

Matlab 106 bytes
x=input('');[n,k]=size(x);r=0;for p=1:n;for m=1:k;r=max([p*m*(any(conv2(x,ones(p,m))==p*m)),r]);end;end;r

Ungolfed:
x=input(''); %//Take input
[n,k]=size(x); %//Determine array size
r=0; %//Variable for output. Initially zero
for p=1:n; %// Loop through the columns
    for m=1:k; %// Loop through the rows
        r=max([p*m*(any(conv2(x,ones(p,m))==p*m)),r]);%//See explanation below
    end;
end;
r %//Display result

The operation in the loop starts with 2D convolution conv2() of input array with the p*m array of ones. ==p*m checks if the resulting array contains an element equal to p*m. The corresponding element is turned to 1, all other elements are turned to 0. any() turns the array into vector. Columns containing at least one nonzero entry are turned to 1, otherwise 0. p*m*() multiplies the vector by p*m thereby turning all 1-s into p*m. [__,r] square brackets concatenate the obtained result with the previous maximum area stored in r. Finally, max() finds the maximum value in the resulting vector.

what does the function any do ?

@Agawa001 for every column in 2D arrayany() returns 1 if the column contains a nonzero element and 0 otherwise.

Matlab (222)(209)
Actually ,this solution brings me shame for being double-sized the actual same-language solution but ... blimey, i had been thinking of it for 6 hours! and the trick is a slightly different build off from Dennis and Neil 's answers.
    function p=g(x,a,u,i,j),i=i+~u;j=j+u;p=0;if(j*u+i*~u>=size(a,2-u))return;end,x=circshift(x,[0-u -1+u]),a=(x+a).*~~x.*~~a;for h=0+u:1,p=max([p,reshape(a(1:end-j,1:end-i),1,[]),g(~u*(a*h+x*~h)+u*x,a,h,i,j)]);end

The function is called as
y=[1 1 1 0 1 1 0 0 0;
1 1 0 1 1 1 1 0 0;
0 0 1 1 1 1 1 1 0;
0 1 1 1 1 1 1 1 1;
0 0 1 1 1 1 1 1 0;];
t=g(y,y,[],0,0,0);t,

I could save more bytes if introduced matrix length in function's dimentions, eventhough, more golfing is ongoing.
How does this proceed?
This algorithm adds the actual matrix to itself shifted of it to left direction, with a bit twiddling (&). in any stage the resulted matrix is set as initial and added to itself shifted upward repeatedly,then reloop from the beginning with the new matrix.
All sub-elements of all the matrices generated by this operation (original_matrix+shifted_matrix)&shifted_and_original_matrices) are maximized to the output.

example:
     1 1 1         1 1 0                      2 2 0                  0 2 0                        0 4 0
 M0= 0 1 1  M0<<1= 1 1 0  M1=(M0+M0<<1)&both= 0 2 0    shift(M1,up)= 2 0 0  M2=(M1+sh(M1,u)&both= 0 0 0
     1 1 0         1 0 0                      2 0 0                  0 0 0                        0 0 0
                        2 0 0                               4 0 0
 M3=(M0<<1+M0<<2)&both= 2 0 0 , M4=(M3+shift(M3,up))&both=  0 0 0
                        0 0 0                               0 0 0

                3 0 0
 M5=(M1+M0<<2)= 0 0 0 , M6=(M5+shift(M5,up))&both=zeros(3,3).
                0 0 0

 Max_of_all_values=Max(0,1,2,3,4)=4

Japt, 30 bytes
®åÏ*°X}ÃÕ®£ZãYÄÃm®rm *Zl}Ãc rw

Try all test cases
Approximately a port of Dennis's Jelly answer. The test cases are simply 2D arrays of numbers, converted from the question's format using this.
Explanation:
®      Ã                          #For each row:
 å    }                           # Replace each number with this running total:
    °X                            #  Increment the previous total
  Ï*                              #  Multiply it by the current number
        Õ                         #Transpose rows and columns
         ®               Ã        #For each column:
          £    Ã                  # Iterate over the range [0..length) as Y:
           ZãYÄ                   #  Get the subsections of that column with length Y+1
                m®      }         # For each subsection:
                  rm              #  Get the minimum
                     *Zl          #  Multiply it by the length
                          c       #Flatten everything to a single list of possible rectangle sizes
                            rw    #Get the maximum

J, 38 bytes
,"0/&(1+i.)/@$>./@,@:((#**/)@,;._3"$)]

Try it online!
how
,"0/&(1 + i.)/@$ >./@,@:((# * */)@,;._3"$) ]
              @$                             NB. pass the shape of
                                             NB. the input (rows, cols)
                                             NB. to...
,"0/&(1 + i.)/                               NB. this verb, which will
    &(1 + i.)/                               NB. will first create 2
                                             NB. lists: 1...num rows
                                             NB. and 1...num cols.
,"0/                                         NB. and then creat a cross
                                             NB. of every possible
                                             NB. concatenation of the two,
                                             NB. giving us all possible
                                             NB. rectangle sizes. pass
                                             NB. that and...
                                           ] NB. the original input
                 >./@,@:((# * */)@,;._3"$)   NB. to this verb, which
                                   ;._3"$    NB. will take every
                                             NB. possible rectangle of
                                             NB. every size,
                                 @,          NB. flatten it and...
                         (# * */)            NB. multiply the size of
                                             NB. the list by the list's
                                             NB. product, yielding the
                                             NB. size of the list if it's
                                             NB. all ones, zero otherwise.
                     ,@:                     NB. Flatten all those results
                                             NB. into one big list
                 >./@                        NB. and take the max.


text:
Drawing the Number ASCIIuare
You have to write a function/program that will draw an ASCII art of a square made with numbers.
Challenge
This program will take one input n as a positive integer and draw a hollow square using this number. The inside must be filled with spaces. The borders also must have the same width. The width and height of the square must also be equal.
Examples
n=1
1

n=2
22
22

n=3
333
333
333

n=10
10101010101010101010
10101010101010101010
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10                10
10101010101010101010
10101010101010101010

As you can see, this is quite straightforward until you reach the double digits. Since 10 has two digits, you must add an extra inside layer to make all the borders have width 2.
So, each square will be nxn, plus the appropriate border.
This is codegolf, so lowest byte count wins. Tie-breaker is earlier submission.

What are the limits?

@CᴏɴᴏʀO'Bʀɪᴇɴ I don't think the additional lines on the top and bottom border are enough of a difference for this to not be a duplicate.

@TimmyD I think so too, I said that to be safe.

Hmm, I did not realize that there was already a question like this already.

So this is considered a duplicate?

@ericw31415 Yes, it is :(

Are you planning on making it different by filling in the area?

This is a dupe, please don't edit again. It puts in for review, but this is a duplicate and can't be reopened.

So, why is 3 solid but 10 isn't?

@EᴀsᴛᴇʀʟʏIʀᴋ Questions closed as duplicates can be reopened; it's not impossible. If the post is edited such that it differs significantly from the post it was marked a duplicate of, it should absolutely make it back into the review queue. That's what the review queue is for.

source: Stack Exchange

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

sort: votes


text:
Double run-length encoding
Everyone knows what run-length encoding is. It has been the subject of many code-golf challenges already. We'll be looking at a certain variation.
Example
Normal: 11222222222222222222233333111111111112333322
Run-length: 112(19)3(5)1(11)2333322

The number in parentheses specifies the number of times the previous symbol occurred. In the example, only runs of 5 or more characters were encoded. This is because encoding runs of 4 or less doesn't improve the character count.
Challenge
Write a function/program that implements this variation of run-length encoding, but can also encode runs of two symbols. The runs of two symbols must also be enclosed in parentheses. A group will also be enclosed in parentheses. Your program must accept a string as input, and output the modified string with modifications that shorten the string.
Example
Normal: 111244411144411144411167676767222222277777222222277777123123123123
Double run-length: 1112((444111)(3))67676767((2(7)7(5))(2))123123123123

Notes

111 was not encoded because encoding it (1(3)) is not shorter.
The string 444111 occurs 3 times so it is encoded.
676767 was not encoded because ((67)(4)) is longer than before.
222222277777222222277777 was not encoded as ((222222277777)(2)). Why? Because 222222277777 itself can be reduced to 2(7)7(5).
123123123123 isn't encoded because your program is supposed to handle runs of two symbols, not three.

This is code-golf so shortest code wins. Tie-breaker is early submission.

If I missed anything, or if you are unsure of anything please notify me in the comments.

But there are 4 67s.

Will we have to handle 441444144414 -> ((4414)(3))?

I have fixed it.

@KennyLau No, you will not. 4414 is technically a series of 4. My wording is just bad.

Can 111111111 be encoded as (1)(9)?

It should be encoded as 1(9), because it's shorter than (1)(9).

((4(9)1)(2)) or 4(9)14(9)1?

The second one. Remember, pick whichever is shorter.

You might want to add more testcases (hint: they are in my solution)

Um, (67(4)) [7 characters] is definitely shorter than 67676767 [8 characters].

(67(4)) implies 67777.

Yoinks! (I need sleep, apparently.)

@ppperry I believe that should be (4(1111)).

Retina, 162 bytes
+{`((\d)\2*(?!\2)(\d)\3*|\d)(?<1>\1)+
<<$1><$#1>>
<<([^<>]{1,7})><2>>
$1$1
<<([^<>]{1,3})><3>>
$1$1$1
<<([^<>]{1,2})><4>>
$1$1$1$1
}`<<(.)><(\d+)>>
$1($2)
T`<>`()

Try it online!

If you input 10101010100100100100100, the output is ((10)(5))0((100)(4)), yet ((10)(4))((100)(5)) would be one character shorter.

Do you really have to use such marginal testcases....

Yes, thats all the fun! :^)

It's funny how this is the only answer currently here.

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


text:
Jordan Decomposition
Important note: Because this challenge only applies to square matrices, any time I use the term "matrix", it is assumed that I am referring to a square matrix. I am leaving off the "square" description for brevity's sake.
Background
Many matrix-related operations, such as computing the determinant, solving a linear system, or extending scalar-valued functions to matrices are made easier by using a diagonal matrix (one whose elements that are not on the main diagonal are 0) that is similar to the original matrix (meaning, for the input matrix A and the diagonal matrix D, there exists some invertible matrix P such that D = P^(-1) * A * P; also, D and A share some important properties, like eigenvalues, determinant, and trace). For matrices with distinct eigenvalues (the roots to the matrix's characteristic polynomial, given by solving det(A-λI) = 0 for λ, where I is the identity matrix with the same dimensions as A), diagonalization is simple: D is a matrix with the eigenvalues on the main diagonal, and P is a matrix formed from eigenvectors corresponding to those eigenvalues (in the same order). This process is called eigendecomposition.
However, matrices with repeated eigenvalues cannot be diagonalized in this manner. Luckily, the Jordan normal form of any matrix can be computed rather easily, and is not much harder to work with than a regular diagonal matrix. It also has the nice property that, if the eigenvalues are unique, then Jordan decomposition is identical to eigendecomposition.
Jordan decomposition explained
For a square matrix A whose eigenvalues all have a geometric multiplicity of 1, the process of Jordan decomposition can be described as such:

Let λ = {λ_1, λ_2, ... λ_n} be the list of eigenvalues of A, with multiplicity, with repeated eigenvalues appearing consecutively.
Create a diagonal matrix J whose elements are the elements of λ, in the same order.
For each eigenvalue with multiplicity greater than 1, place a 1 to the right of each of the repetitions of the eigenvalue in the main diagonal of J, except the last.

The resulting matrix J is a Jordan normal form of A (there can be multiple Jordan normal forms for a given matrix, depending on the order of the eigenvalues).
A worked example
Let A be the following matrix:

The eigenvalues of A, with multiplicity, are λ = {1, 2, 4, 4}. By putting these into a diagonal matrix, we get this result:

Next, we place 1s to the right of all but one of each of the repeated eigenvalues. Since 4 is the only repeated eigenvalue, we place a single 1 next to the first 4:

This is a Jordan normal form of A (a single matrix can potentially have several valid Jordan normal forms, but I'm glossing over that detail for the purpose of explanation).
The task
Given a square matrix A as input, output a valid Jordan normal form of A.

The input and output may be in any reasonable format (2D array/list/whatever, list/array/whatever of column or row vectors, a builtin matrix data type, etc.).
The elements and eigenvalues of A will always be integers in the range [-200, 200].
For the sake of simplicity, all of the eigenvalues will have a geometric multiplicity of 1 (and thus the above process holds).
A will at most be a 10x10 matrix and at least a 2x2 matrix.
Builtins that compute eigenvalues and/or eigenvectors or perform eigendecomposition, Jordan decomposition, or any other kind of decomposition/diagonalization are not allowed. Matrix arithmetic, matrix inversion, and other matrix builtins are allowed.

Test cases
[[1, 0], [0, 1]] -> [[1, 1], [0, 1]]
[[3, 0], [0, 3]] -> [[1, 1], [0, 1]]
[[4, 2, 2], [1, 2, 2],[0, 3, 3]] -> [[6, 0, 0], [0, 3, 0], [0, 0, 0]]
[[42, 48, 40, 64, 64], [41, 47, 31, 58, 42], [-55, -47, -27, -74, -46], [-46, -58, -46, -70, -68], [30, 20, 12, 34, 18]] -> [[10, 0, 0, 0, 0], [0, -18, 0, 0, 0], [0, 0, 6, 1, 0], [0, 0, 0, 6, 1], [0, 0, 0, 0, 6]]

Mathematica, 140 139 105 bytes
Total[DiagonalMatrix@@@{{#},{1-Sign[Differences@#^2],1}}]&@(x/.Solve[#~CharacteristicPolynomial~x==0,x])&

I just found the builtin DiagonalMatrix which allows for an easy way to place the 0s and 1s along the superdiagonal.
Usage

What about Last@JordanDecomposition@#&? Or is it cheating?

@Ruslan Yes, one of the rules is that builtins that perform Jordan decomposition are not allowed. Thanks though.

Sage, 79 bytes
lambda A:block_diagonal_matrix([jordan_block(*r)for r in A.charpoly().roots()])

Try it online
Since nobody else is posting solutions, I might as well go ahead and post one.
A.charpoly.roots() computes the roots (and algebraic multiplicities) of the characteristic polynomial of A (aka the eigenvalues and multiplicities). jordan_block constructs a Jordan block from the given root and multiplicity. block_diagonal_matrix forms a matrix with the Jordan blocks on the diagonal, which is exactly the definition of a Jordan normal form.

J, 78 71 bytes
1(#\.|."_1#{."1],.2=/\,&_)@>@{[:p.@>[:-&.>/ .(+//.@(*/)&.>)],&.>[:-@=#\

Try it online!
The two challenging portions of this task, getting the eigenvalues and performing the diagonalization, ending up both taking about the same number of bytes. These were disallowed by the rules but in case any are curious, J has builtins for QR decomposition (128!:0) as well as LAPACK addons which could be used to find eigenvalues.
Explanation (Outdated)
There are two major portions to this verb: finding the eigenvalues and performing the diagonalization. First, in order to find the eigenvalues, the roots of the characteristic polynomial for the input matrix will have to be found. Using the same input matrix from the example,
   ] m =: _4 ]\ 5 4 2 1 0 1 _1 _1 _1 _1 3 0 1  1 _1 2
 5  4  2  1
 0  1 _1 _1
_1 _1  3  0
 1  1 _1  2

The characteristic polynomial for a matrix M can be found using |M - λI| = 0 where I is the identity matrix with the same dimensions as M. The expression M - λI can be modeled in J by boxing each element in M with a -1 if it is on the diagonal else otherwise a 0. Each box represents a polynomial in coefficient form.
   (],&.>[:-@=#\) m
┌────┬────┬────┬────┐
│5 _1│4 0 │2 0 │1 0 │
├────┼────┼────┼────┤
│0 0 │1 _1│_1 0│_1 0│
├────┼────┼────┼────┤
│_1 0│_1 0│3 _1│0 0 │
├────┼────┼────┼────┤
│1 0 │1 0 │_1 0│2 _1│
└────┴────┴────┴────┘

The determinant in J is -/ .* however, that operates on numbers, not boxed polynomials. Instead of multiplication, the polynomial product is needed which can be found using convolution ([:+//.*/). Folded subtraction is still used, and both these verbs need to operate within boxes so under (&.) unbox (>) is used.
   ([:-&.>/ .(+//.@(*/)&.>)],&.>[:-@=#\) m0
┌───────────────┐
│32 _64 42 _11 1│
└───────────────┘

These are the coefficients of the characteristic polynomial. The roots can be found using p. which converts the representation of a polynomial between coefficients and roots form.
   ([:p.@>[:-&.>/ .(+//.@(*/)&.>)],&.>[:-@=#\) m0
┌─┬───────┐
│1│4 4 2 1│
└─┴───────┘

The roots are [4, 4, 2, 1] and those are the eigenvalues of M.
Second, the diagonalization must be performed. Each continuous pair of values is tested for equality.
   (2=/\]) 4 4 2 1
1 0 0

A zero is appended and those values are columinized together with the eigenvalues.
   (],.0,~2=/\]) 4 4 2 1
4 1
4 0
2 0
1 0

Then each row is padded to the same length as the number of eigenvalues to form a square matrix.
   (#{."1],.0,~2=/\]) 4 4 2 1
4 1 0 0
4 0 0 0
2 0 0 0
1 0 0 0

Finally each row is shifted right with values falling off at the right and zeros being pushed in on the left. The first row is shifted zero times, the second once, the third twice, and so on.
   (-@i.@#|.!.0"_1#{."1],.0,~2=/\]) 4 4 2 1
4 1 0 0
0 4 0 0
0 0 2 0
0 0 0 1

The output is the Jordan decomposition of M.

Octave, 60 bytes
@(a)diag(1-sign(diff(v=round(roots(poly(a)))).^2),1)+diag(v)

Try it online!
A port of my Mathematica solution.

MATL, 29 bytes, non-competing
1$Yn1$ZQYotdUZS~0hXdF1hYSwXd+

Try it online!
This is my first MATL submission so there are bound to be improvements. I spent a while learning it and only at the end did I remember that this might not have worked using the MATL from May 7, 2016. Sure enough, I checked out the penultimate commit to that day and it did not run.
I would have liked to use diag but it seems MATL only supports the single argument version. The second argument would be needed to place values along the superdiagonal (or any other diagonal for different problems).


text:
Print 100 Circles
Goal: Create the smallest possible code to open a separate window, in which there are 100 circles of random sizes and colors.
Rules: All circles must be visible to the unassisted, naked eye, so in other words more than 2 pixels across, the background must be black, at least 5 different colors must be recognizable, and at all circles must fit within the window.

what do you mean by random sizes? what size should the window be? Can they be overlapping? Do the positions have to be random? Does it have to be filled or only have an outline?

Bash, 5 bytes. feh f Must be ran in a directory containg a file named 'f' that is an image containing 100 circles of random sizes and colors, and feh must be installed. This is technically not against the rules since their aren't any.

I like the challange but as it stands, this is way to broad. As @DrGreenEggsandHamDJ said, you should definitely think about some limiting rules.

Mathematica 106 bytes
The code is fairly straightforward.  A palette is a floating window. The 100 circles are stored in an array. The first ryields coordinates; the second r yields a radius.
CreatePalette[{Graphics[Array[{RandomColor[],Disk[99~(r=RandomReal)~{2},r@5]}&,100],Background->Black]}]

Java, 352 Bytes
Yeah, I know, an applet, but still...
import java.applet.*;import java.awt.*;import java.util.*;public class C extends Applet{public void paint(Graphics a){Random b=new Random();int x,y,diameter;setBackground(Color.black);for(int c=1;c<=100;c++){a.setColor(new Color(b.nextInt(0xFFFFFF)));d=b.nextInt(getWidth()/10);x1=b.nextInt(getWidth());y1=b.nextInt(getHeight());a.drawOval(x,y,d,d);}}}

Ungolfed Code:
import java.applet.*;
import java.awt.*;
import java.util.*;

public class C extends Applet {
    public void paint(Graphics a) {

        Random b = new Random();

        int x, y, d;

        setBackground(Color.black);

        for (int c = 1; c <= 100; c++) {
            a.setColor(new Color(b.nextInt(0xFFFFFF)));

            d = b.nextInt(getWidth() / 10);
            x = b.nextInt(getWidth());
            y = b.nextInt(getHeight());

            a.drawOval(x, y, d, d);
        }

    }
}

@EᴀsᴛᴇʀʟʏIʀᴋ Nope.

Have you tried using Math.random()*getWidth() in place of b.nextInt(getWidth())? It may save you a few bytes (you'd remove the Random b definition too)

how about c<101 rather than c<=100

Python 2 PIL - 199 bytes
Making some assumptions of the rules based on OP's answer. Not optimally golfed in the sense that the image could be 5 pixels across and the circles could be all the same place with grayscale colors, but goes with the spirit of the rules.
import Image,ImageDraw,random
h=999
i=Image.new('RGB',(h,h))
g=random.randint
exec"r,x,y=g(0,50),g(0,h),g(0,h);ImageDraw.Draw(i).ellipse((x-r,y-r,x+r,y+r),(g(0,255),g(0,255),g(0,255)));"*100
i.show()


text:
Rotation-safe Latin squares
A Latin square is a square that has no repeated symbols in either the X or Y columns.  For example:
ABCD
DABC
CDAB
BCDA

is one such square.  Notice how every column and row contains a permutation of the same 4 letters.
However, our Latin square has a problem:  If I were to rotate the second row (DABC) 1 to the left, I'd end up with ABCD, which is identical to the permutation above it.  If it is impossible to rotate any 1 column/row and obtain another column/row, then we consider the square to be rotation safe.
For example:
ABCD
BDAC
CADB
DCBA

is rotation safe.  The grid has the following properties:

Point [0,N] uses the Nth symbol
Point [0,N] and [N,0] are always the same symbol.  (I'd like to also say that [x,y] and [y,x] are also always the same letter, but I can't prove it)

Your task is to print out 1 rotation-safe Latin square, when passed N.  I don't care if you output letters, numbers, a list, or a 2D array.  If you use numbers, the top column and row must be 0,1,2,3,... (in that order).  If you use letters, then it must be A,B,C,D,....
For example, if your input was 4, you should either print:
0,1,2,3            0,1,2,3
1,3,0,2     or     1,0,3,2
2,0,3,1            2,3,1,0
3,2,1,0            3,2,0,1

There are no rotation-safe Latin squares of size less than 4.  I don't care what your program does if N is less than 4.  For the curious, the number of rotation-safe squares is (starting at 4):  2,5,5906,(too long to calculate)
This is a code-golf, so try to make answers as short as possible in your favorite language!

Is there a time limit? (Related: Are Monte Carlo methods allowed if they are technically not guaranteed to terminate for high values of N due to insufficient random number quality?)

No time limit, but your solution should be guaranteed to terminate.

For 1-indexed languages, can the first row be 1,2,3,...?

related,related

@miles yes, that is fine

that is easily done with some built in functions in matlab but they spend eras to finish, are they allowed ?

@Agawa001 if the built-in specifically calculates rotation-safe Latin squares, then it isn't allowed. Otherwise, you are OK.

@Maltysen just one.

@Agawa001 I'm curious what those builtins are...

@LuisMendo , nathan builtins for unique row permutations combined in a sort they generate unique matrix column permutations, but they take forever.

@Sp3000 That sequence is different:  It counts rotation-safe latin squares, but it doesn't count them multiple times.  I won't claim that I didn't make a mistake, but I'm not sure if that sequence is sufficient evidence.

Is there a maximum number that N can be? That is, what's the largest N that the code has to be able to handle?

@GlenO Whatever integer size your language supports.

Pyth - 29 bytes
Brute force.
hf&!@JsCBTsm.>RdJStQ.A{IMJ^.p

Does not finish online even for n=4, but you can try it out locally, or run this modified version online for one more byte.

Sqlserver 2012 - 918 bytes
On my box this runs for @k = 5, although it takes 16 seconds.
This is code building code(watch out Skynet, you have competition)
Is there a price for the longest script?
DECLARE @k int = 4;

DECLARE @t VARCHAR(max)='WITH C as(SELECT
top '+left(@k,1)+'row_number()over(order by 1/0)n
FROM sys.messages),D(nÆ)as(SELECT
concat(~),~
FROM Ø
WHERE |)SELECT top 1~ FROM Å
WHERE 1=1',@
varchar(999)=''SELECT @+=','+CHAR(x+65)FROM(values(0),(1),(2),(3),(4),(5))x(x)WHERE x<@k
SELECT
@t=REPLACE(REPLACE(REPLACE(REPLACE(@t,'Æ',@),'Ø',STUFF(REPLACE(@,',',',C '),1,1,'')),'Å',STUFF(REPLACE(@,',',',D
'),1,1,'')),'~',STUFF(REPLACE(@,',','.n,'),1,3,'')+'.n'),@='';WITH C as(SELECT top(@k)x
FROM(values(0),(1),(2),(3),(4),(5))x(x))SELECT @+=' AND
'+char(65+C.x)+'.n<>'+char(65+D.x)+'.n'FROM c,c d WHERE C.x<D.x
SELECT @t=REPLACE(@t,'|',STUFF(@,1,4,''));WITH A
as(SELECT top(@k)x
FROM(values(65),(66),(67),(68),(69),(70))x(x))SELECT @t+='AND
'+char(A.x)+'.'+char(C.x)+'<>'+CHAR(B.x)+'.'+char(C.x)+' AND
'+char(A.x)+'.n+'+char(A.x)+'.n'+'
not like''%''+'+char(B.x)+'.n+''%'''FROM A,A B,A C
WHERE A.x<>B.x and C.x<>B.x
EXEC(@t)

Try online!


text:
Calculate the Fermat Point of a Triangle
This is somewhat similar to The centers of a triangle, but with a different point. The Fermat Point is the point P in triangle ABC such that the value of AP + BP + CP is minimized. There are two cases:
If there is an angle greater than 120 degrees, that vertex is the fermat point. Otherwise, draw equilateral triangles on each of the sides of ABC. Connect the far vertex of each equilateral triangle to the opposite vertex of triangle ABC. Doing this for each of the three equilateral triangles results in a single common point of intersection for all three lines, which is the Fermat Point.
It should run within 5 seconds on a reasonable machine.
Input: A set of 3 points, not necessarily integers. This can be taken as a nested array, string, list of tuples, etc. (whatever suits your language).
Output: The coordinates of the Fermat point, again, however your language best handles points. Floating point inaccuracies will not be counted against you.
Test Cases:
[[1, 1], [2, 2], [1, 2]] --> [1.2113248654051871, 1.788675134594813]
[[-1, -1], [-2, -1], [0, 0]] --> [-1, -1]
[[-1, -1], [1, -1], [0, 1]] --> [0, -0.42264973081037427]
[[0, 0], [0.5, 0.8660254037844386], [-5, 0]] --> [0, 0]
[[0, 0], [0, -5], [-0.8660254037844386, 0.5]] --> [0, 0]

This is code golf so shortest code wins!

Is it OK to try all points in increments of floating point precision and select the one that minimizes the total distance?

@xnor If you can do it within 5 seconds.

Up to how many significant figures must the output be accurate to? Also, is it okay if -0.0 is output in place of some 0.0s?

@R. Kap I'd say about 5 or 6 significant figures. There isn't so much much that rounding errors should be a problem. As for the second question, that seems fine.

Mathematica, 39 bytes
Sum[Norm[p-{x,y}],{p,#}]~NArgMin~{x,y}&

Constructs an equation based on the distances between the vertices and a point {x,y}. Then uses the NArgMin function to find a global minimum for that equation, which will be the Fermat Point by definition.

39 bytes, when the next shortest answer is 285...

Haskell, 346 291 295 bytes
infixl 5£
z=zipWith
(?)=z(-)
t[a,b]=[-b,a]
a¤b=sum$z(*)a b
a%b=t a¤b
r a b c=[c%b/a%b,c%a/a%b]
x£y=2*x¤y<= -sqrt(x¤x*y¤y)
f[a,b,c]|a?b£c?b=b|a?c£b?c=c|b?a£c?a=a|[n,m,p,o]<-c?k a b c++a?k b c a=r[m,o][n,p][c%[n,m],a%[p,o]]
k a b c=map(/2)$z(+)a b?map(signum((b?a)%(c?a))*sqrt 3*)(t$b?a)

The same code with some explanations
infixl 5£
z=zipWith

-- operator ? : difference of two vectors
(?)=z(-)

-- function t : rotate a vector by +90 degrees
t[a,b]=[-b,a]

-- operator ¤ : scalar product of two vectors ( a¤b = a0 * b0 + a1 * b1 )
a¤b=sum$z(*)a b

-- operator % : "cross product" of two vectors ( a%b = a0 * b1 - a1 * b0 )
--      this returns actually the z coordinate of the 3d cross vector
--      other coordinates are nul since a and b are in the xy plan
a%b=t a¤b

-- function r : solves the system of two linear equations with two variables x0,x1 :
--      a0*x0 - b0*x1 = c0
--      a1*x0 - b1*x1 = c1
r a b c=[c%b/a%b,c%a/a%b]

-- operator £ : returns true if the angle between two vectors is >= 120 degrees
--      x¤y = ||x|| * ||y|| * cos(xyAngle)
--      so xyAngle>=120° is equivalent to : x¤y / (||x|| * ||y||) <= -0.5
x£y=2*x¤y<= -sqrt(x¤x*y¤y)

-- function k : takes 3 points A B C of a triangle and constructs the point C'
--              of the equilateral triangle ABC' which is opposite to C:
--              C' = (A+B)/2 - ((+/-) sqrt(3)/2 * t(AB))
--
--      the sign +/- is given by the sign of the cross vector of AB an AC ((b?a)%(c?a))
--      which is >0 if the angle between AB and AC is positive
--      and <0 otherwise.
k a b c=map(/2)$z(+)a b?map(signum((b?a)%(c?a))*sqrt 3*)(t$b?a)

-- function f : returns the fermat point of a triangle
f[a,b,c]
    |a?b£c?b=b  -- return B if angle ABC >= 120°
    |a?c£b?c=c  -- return C if angle BCA >= 120°
    |b?a£c?a=a  -- return A if angle CAB >= 120°
    |[n,m,p,o]<-c?k a b c++a?k b c a= -- calculate the two segments C'C and A'A
        r[m,o][n,p][c%[n,m],a%[p,o]]  -- return their intersection

Tests:
main = do
    print $ f [[1, 1], [2, 2], [1, 2]]
    print $ f [[-1, -1], [-2, -1], [0, 0]]
    print $ f [[-1, -1], [1, -1], [0, 1]]
    print $ f [[0, 0], [0.5, 0.8660254037844386], [-5, 0]]
    print $ f [[0, 0], [0, -5], [-0.8660254037844386, 0.5]]

Output:
[1.2113248654051871,1.7886751345948126]
[-1.0,-1.0]
[0.0,-0.42264973081037427]
[0.0,0.0]
[0.0,0.0]

How are you counting bytes? £ and ¤ are 2 bytes each in UTF-8, and I don’t know of a Haskell compiler that accepts ISO-8859-1. (You have plenty of free 1-byte ASCII operators, though, so this is easy to fix.)

I'm counting it with my editor which actually counts characters. I didn't know that these were 2 bytes, but anyway, as you said, I could replace it by other 1 byte operators. This code compiles with GHC 7.8.3

GHC compiles your code when encoded as UTF-8 with £ and ¤ as 2 byte operators, but not when encoded as ISO-8859-1 with £ and ¤ as 1 byte operators. The available 1 byte operators in UTF-8 are !, #, %, &, ?. You should replace the 2 byte operators or adjust your byte count.

Python, 475 448 440 bytes
Any help to golf further is appreciated.
from math import *
d=lambda x,y:((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5
s=lambda A,B,C:(d(B,C), d(C,A), d(A,B))
j=lambda a,b,c:acos((b*b+c*c-a*a)/(2*b*c))
t=lambda a,b,c:1/cos(j(a,b,c)-pi/6)
b=lambda A,B,C,p,q,r:[(p*A[i]+q*B[i]+r*C[i])/(p+q+r) for i in [0,1]]
f=lambda A,B,C:A if j(*s(A,B,C)) >= 2*pi/3 else B if j(*s(B,C,A)) >= 2*pi/3 else C if j(*s(C,A,B)) >= 2*pi/3 else b(A,B,C,d(B,C)*t(*s(A,B,C)),d(C,A)*t(*s(B,C,A)),d(A,B)*t(*s(C,A,B)))

Ungolfed:
from math import *
#distance between two points
d = lambda x,y: ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5

#given the points, returns the sides
s = lambda A,B,C : (d(B,C), d(C,A), d(A,B))

#given the sides, returns the angle
j = lambda a,b,c : acos((b*b+c*c-a*a)/(2*b*c))

#given the sides, returns secant of that angle
t = lambda a,b,c: 1/cos(j(a,b,c)-pi/6)

#given the sides and the Trilinear co-ordinates, returns the Cartesian co-ordinates
b = lambda A,B,C,p,q,r: [(p*A[i]+q*B[i]+r*C[i])/(p+q+r) for i in [0,1]]

#this one checks if any of the angle is >= 2π/3 returns that point else computes the point
f = lambda A,B,C: A if j(*s(A,B,C)) >= 2*pi/3 else B if j(*s(B,C,A)) >= 2*pi/3 else C if j(*s(C,A,B)) >= 2*pi/3 else b(A,B,C,d(B,C)*t(*s(A,B,C)),d(C,A)*t(*s(B,C,A)),d(A,B)*t(*s(C,A,B)))

Input:
print('{}'.format(f([1, 1], [2, 2], [1, 2])))
print('{}'.format(f([-1, -1], [-2, -1], [0, 0])))
print('{}'.format(f([-1, -1], [1, -1], [0, 1])))
print('{}'.format(f([0, 0], [0.5, 0.8660254037844386], [-5, 0])))
print('{}'.format(f([0, 0], [0, -5], [-0.8660254037844386, 0.5])))

Output:
[1.2113248652983113, 1.7886751347016887]
[-1, -1]
[0.0, -0.42264973086764884]
[0, 0]
[0, 0]

from math import* is a pretty common golf. This will also let you use pi instead of hard coding it (same length for 2*pi/3). You can also drop a lot of whitespace like: d=lambda x,y:(....

Python 3.5, 1019 1016 998 982 969 953 bytes:
from math import*
def H(z,a,b):c=complex;T=lambda A,B:abs(c(*A)-c(*B));d=T(z,a);e=T(z,b);f=T(a,b);g=[d,e,f];h=max(g);g.remove(h);i=acos((sum(i*i for i in g)-(h*h))/(2*g[0]*g[-1]));_=[[z,a],[z,b],[a,b]];j,s,t=cos,sin,atan;N=[[b,a]for a,b in zip([b,a,z],[max(i,key=i.get)if i!=''else''for i in[{(g[0]+(h*j(t(l))),g[1]+(h*s(t(l)))):T(k,(g[0]+(h*j(t(l))),g[1]+(h*s(t(l))))),(g[0]-(h*j(t(l))),g[1]-(h*s(t(l)))):T(k,(g[0]-(h*j(t(l))),g[1]-(h*s(t(l)))))}if l else{(g[0]+h,g[1]):T(k,(g[0]+h,g[1])),(g[0]-h,g[1]):T(k,(g[0]-h,g[1]))}if l==0else''for g,h,l,k in zip([((a[0]+b[0])/2,(a[1]+b[1])/2)for a,b in _],[(3**0.5)*(i/2)for i in[d,e,f]],[-1/p if p else''if p==0else 0for p in[((a[1]-b[1])/(a[0]-b[0]))if a[0]-b[0]else''for a,b in _]],[b,a,z])]])if b!=''];I=N[0][0][1];J=N[0][0][0];K=N[1][0][1];G=N[1][0][0];A=(N[0][1][1]-I)/(N[0][1][0]-J);B=I-(A*J);C=(K-N[1][1][1])/(G-N[1][1][0]);D=K-(C*G);X=(D-B)/(A-C);Y=(A*X)+B;return[[X,Y],[[a,b][h==d],z][h==f]][i>2.0943]

Incredibly long compared to other answers, but hey, at least it works! I could not be happier with the result I got as this has got to be one of the hardest challenges I have ever done. I am just so happy that it actually works! :D Now, onto the more technical notes:

This function takes each ordered pair in as a list or a tuple. For instance, H((1,1),(2,2),(1,2)) will work, but so will H([1,1],[2,2],[1,2]).
Outputs the coordinates of the points in either a list of integers or floating points depending on whether or not one angle more than or equal to 120º exists.
This may output -0.0 in place of 0.0 for some inputs. For instance, the output for the input [-1, -1], [1, -1], [0, 1] is [-0.0, -0.4226497308103744]. I hope this is okay, although if it isn't, I will change it, though it will cost me a few more bytes. This is okay, as confirmed by OP.
Should be accurate up to at least 13 to 14 significant figures.

I will try and golf this more over time. An explanation, possibly very long, coming soon.
Try It Online! (Ideone)

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


text:
Convert header levels to numbers
Introduction
Nodes in tree structures (e.g. headings in a long document, law paragraphs, etc.) are often created by assigning a specific header level (h1, h2, etc.) to each item, but outputted with additional node numbers for each level (1., 1.1., etc.), e.g.:
1. Intro (h1)
1.1. About this (h2)
1.2. Target audience (h2)
2. Actual stuff (h1)
3. More stuff (h1)
3.1. Details (h2)
3.1.1. Special points (h3)
3.2. Specifics (h2)
3.2.1. Minutiae (h3)
3.2.2. Petitesses (h3)
3.3. Specifications (h2)
4. Index (h1)
5. Appendices (h1)

Input
Given (by any means) a list of header levels (the X's in hX above) like:
[1,2,2,1,1,2,3,2,3,3,2,1,1]

Input will always begin with a 1, and Inputn+1 is in the range [1,1+Inputn].
Input will only contain numbers in the range [1,256].
Output
Return (by any means) the list of lists (or matrix - see below) of node numbers (dot-separated above):
[[1],[1,1],[1,2],[2],[3],[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],[4],[5]]

You may return scalars instead of one-element sub-lists:
[1,[1,1],[1,2],2,3,[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],4,5]

You may return a matrix (or list of lists) which is padded with zeros so that all rows (sub-lists) have the same length:
[[1,0,0]
 [1,1,0]
 [1,2,0]
 [2,0,0]
 [3,0,0]
 [3,1,0]
 [3,1,1]
 [3,2,0]
 [3,2,1]
 [3,2,2]
 [3,3,0]
 [4,0,0]
 [5,0,0]]

Additional rules
The reverse process of all this is just the length of each sub-list. You must also include a reverse program in the same language. Your score is the total byte count of your two programs. If you return zero-padded results on the first prgram, your reverse code must handle such input.
Please explain your code so we all can learn from it.
This is code golf, because I'll need to read it on a phone screen and type it into a computer. - No, really, this is not meme-ness!

What would [1,3,1] return?

Why should people bother to write a reverse program if it will not contribute to the score?

Can I only make it work to, you know, 9? (Like 3.2.9 will work but not 3.2.10)

Maybe you could add some test cases?

@KennyLau I updated the rules to state that [1,3,1] is invalid input and that any positive input number below 257 is valid.

@BassdropCumberwubwubwub Now it IS counted.

@R.Kap What is lacking in the existing test case?

You should be more up front that the total score is the sum of the original and reversed program. It's easy to miss tucked away in an additional rule.

@xnor forgot to say I did that

Returning scalars and one-element lists is both allowed, but what about mixing the two? Is [1, [1, 1], [1, 2], [2], [3], ...] an acceptable output for first program if the reverse program can handle it?

@Dennis Allowed if reverse can handle it. In any case, it would be trivial to force all elements into lists/scalarize singletons.

CJam (15 + 4 = 19 bytes)
Mq~{1$0+<))+}%`

Online demo
To reverse,
q~:,

JavaScript (ES6), 47 + 21 = 68 bytes
a=>a.map(l=>b=[...b.slice(0,--l),-~b[l]],b=[])

Explanation:
a=>a.map(l=>            Loop over each header level
 b=[                    Make a new sublist using
  ...b.slice(0,--l),    First l-1 elements from the previous sublist
  -~b[l]],              Plus increment the lth element or default to 1
 b=[])                  Start with an empty sublist

The bitwise not operator is used because it will coerce its operand to a signed 32-bit integer, which will be zero if this is a new level. Negating the result conveniently returns one more than the original number, or 1 in the case of a new level. Reverse process:
a=>a.map(b=>b.length)

Could you maybe explain?

@Nᴮᶻ Writing the explanation exposed a bug in the code. The new code is sadly a byte longer.

Jelly, 10 8 bytes
Forward, 8 6 bytes
ḣ+Ṭ}ð\

Try it online!
Backward, 2 bytes
L€

Try it online!
How it works
Forward
ḣ+Ṭ}ð\  Main link. Argument: A (list of integers)

    ð\  Cumulatively reduce A by the dyadic chain to the left. Arguments: x, y
ḣ       Head; Truncate x to y items.
  Ṭ}    Untruth; yield a list of y-1 zeroes and 1 one.
 +      Compute the vectorized sum of both results.

Backward
L€      Main link. Argument: A (nested list)

L       Length.
 €      Map the previous link over all items in A.

Pyth, 27 22 + 2 = 24 bytes
This is embarrassingly more than 1 less than half of the bytes that javascript used.
JylQjRJ.uhs*N^JY-VtQQ1

Try it online!
Reverse, 2 bytes
lM

Try it online!

Even more embarrassingly, it's longer than the CJam solution.

At least the reverse solution is better. (And with the scores combined you're now only just over a third of the bytes of ES6.)

Pyth, 11 + 2 = 13 bytes
Forward:
m=X_1<+Y0d1

Demonstration
Backward:
lM

I like this one.
How it works:
m=X_1<+Y0d1
               Implicit: Y = []
m              Map over the input, with d being the map variable
      +Y0      Add a 0 on to the end of Y
     <   d     Slice down to the first d elements
  X_1     1    Increment the last one
 =             Assign the result back to Y

The resultant list will contain each value that Y takes on, which is the desired sequence.
Embarrassment cured.

Ruby, 44 + 17 = 61 bytes
Forward:
->x{l=[]
x.map{|e|l=l[0,e-=1]<<(l[e]||0)+1}}

Backward:
->x{x.map &:size}


text:
Shortest paths in a divisor graph
Introduction
In this challenge, we will be dealing with a certain infinite undirected graph, which I call the high divisor graph.
Its nodes are the integers starting from 2.
There is an edge between two nodes a < b if a divides b and a2 ≥ b.
The subgraph formed by the range from 2 to 18 looks like this:
16-8 12 18
  \|/ |/|
   4  6 9 10 15 14
   |  |/   |/   |
   2  3    5    7  11 13 17

It can be shown that the infinite high divisor graph is connected, so we can ask about the shortest path between two nodes.
Input and output
Your inputs are two integers a and b.
You can assume that 2 ≤ a ≤ b < 1000.
Your output is the length of the shortest path between a and b in the infinite high divisor graph.
This means the number of edges in the path.
You may find the following fact useful: there always exists an optimal path from a to b that's first increasing and then decreasing, and only visits nodes that are strictly less than 2b2.
In particular, since b < 1000 you only need to consider nodes less than 2 000 000.
Examples
Consider the inputs 3 and 32.
One possible path between the nodes 3 and 32 is
3 -- 6 -- 12 -- 96 -- 32

This path has four edges, and it turns out there are no shorter paths, so the correct output is 4.
As another example, an optimal path for 2 and 25 is
2 -- 4 -- 8 -- 40 -- 200 -- 25

so the correct output is 5.
In this case, no optimal path contains the node 50 = lcm(2, 25).
Rules and scoring
You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
There are no time or memory limits, so brute forcing is allowed.
Test cases
2 2 -> 0
2 3 -> 4
2 4 -> 1
2 5 -> 5
3 5 -> 4
6 8 -> 2
8 16 -> 1
12 16 -> 2
16 16 -> 0
2 25 -> 5
3 32 -> 4
2 256 -> 3
60 77 -> 3
56 155 -> 3
339 540 -> 2
6 966 -> 4
7 966 -> 2
11 966 -> 4
2 997 -> 7
991 997 -> 4

i have an idea which is not a brute force as i assumed, it does count the smallest multiple of two numbers, multiply gradually by the power two until it appears, then dividing gradually by the sqrt until the second number appears, i have no time to implement iy now eventhough :/

Zgarb,  Does Mathematica's FindShortestPath  violate the constraint about standard loopholes?  If it does, just let me know and I'll delete my submission.

@DavidC I don't consider it a loophole. The relevant answer actually has a score of 0.

Matlab, 218 190 175 bytes
function f(a,b);q=a;l(b)=0;l(a)=1;while~l(b);x=q(1);q=q(2:end);l(end+1:x^2)=0;g=x+1:x^2;s=2:x-1;u=[g(~mod(g,x)),s(~mod(x,s)&s.^2>=x)];u=u(~l(u));q=[q,u];l(u)=l(x)+1;end;l(b)-1

Thanks @beaker for the shortcut in in the list lengthening step!
This is a relatively straightforward dijkstra implementation:
q=a;                  %queue
l(b)=0;       %list of path lengths
l(a)=1;
while~l(b);         %if there is no predecessor to b
    x=q(1);         %get first queue element
    q=q(2:end);
    %add edges
    l(end+1:x^2)=0;% lengthen predecessor list if too short
    g=x+1:x^2;      % g=greater neighbours
    s=2:x-1;        % s=smaller neighbours %keep only valid/unvisited neighbours
    u=[g(~mod(g,x)),s(~mod(x,s)&s.^2>=x)]; %-1byte
    u=u(~l(u));
    q=[q,u];      %add only hte valid nodes edges to queue
    l(u)=l(x)+1;       %mark x as predecessor
end;
l(b)-1 %output length to the end of the path

 no convolution today

Instead of l=zeros(1,a*b); you can use l(a*b)=0;, which does the same

alas .... still 10 bytes long behind you.

JavaScript (ES6), 186 bytes
(m,n)=>(g=i=>{for(q=[i],r=[],r[i]=j=0;i=q[j++];)for(k=i+i;k<=i*i&(k<m*m*2|k<n*n*2);k+=i)r[k]-r[i]<2?0:r[q.push(k),k]=r[i]+1},g(m),s=r,g(n),Math.min(...r.map((i,j)=>i+s[j]).filter(i=>i)))

Uses a helper function g to calculate all the ascending paths from m and n in turn up to the provided limit, then sums the paths together and returns the lowest value.

Mathematica 98 bytes
I am assuming that the built-in function, FindShortestPath does not violate the constraint about standard loopholes.  If it does, just let me know and I'll delete this submission.
Brute force, hence slow with large values of b. I'm still thinking of ways to speed it up.
h@{a_,b_}:=Length@FindShortestPath[Graph[Apply[Join,Thread[#<->Range[2,#] #]&/@Range[b^2]]],a,b]-1

This sets up a graph with appropriate edges between the nodes from a to b^2. FindShortestPathfinds the shortest path in the graph. Lengthcounts the nodes; Length -1 is the number of edges.
Thread[# <-> Range[2, #] #] & produces the edges of the full graph. For example,  Thread[# <-> Range[2, #] #]&[5] would produce the edges {5 <-> 2*5, 5 <-> 3*5, 5 <-> 4*5, 5 <-> 5*5}, that is, {5 <-> 10, 5 <-> 15, 5 <-> 20, 5 <-> 25}.

Matlab (195)(185)(181)(179)(173)

Note: Me the user Agawa001 personally I attest that I won over the user @flawr making use of his assistance

 function t(a,b,p),for r=0:1,d=(b*~r+r*a)/gcd(a,b);while(d>1)p=p+1;e=find(~rem(d,1:d));f=max(e(a^(1-r/2)>=e));a=a*min([find(1:a*a>=b) a])^~(f-1);d=d/f;a=a*f^(1-2*r);end,end,p

This function is different drom others, it does follow a bunch of pure mathematical calculations and factorisations but has nothing to do with paths or graphs.
Example of function call:
 t(2,3,0)

 p =

 4

All test cases are satisfied
Explanation:

Before beginning with explanations lets prove some lemmas "not green ones":
Lemma(1): An optimal path between any two numbers (a,b) exists in a way the nodes are firstly increasing then decreasing.
Why ? This is simply proven because the maximal integer amount that divides any number a is respectively big as the number a itself, so as a clever approach we must choose to multiply a as much as possible to make it sufficiently bigger, then dividing by bigger values. If ever we do the way round, the number a shrinks, so we need needlessly more iterations to multiply it gradually that we are dispensed with.
Lemma(2): From a number a to b, if gcd(a,b)=1 a is multiplied by b, if b is bigger than a it will be multiplied by a known number c, if gcd>1 a must be multiplied gradually by the biggest divisor of b/gcd named d that verifies the condition a >= d also when all d's namely the minimum are bigger than a, a receives a*c again.
This assumption is simple to prove any starting node a must be multiplied until it reaches the smallest multiple of a and b so either we multiply by proportions of b*gcd beginning by the maximum which verifies the main condition, that guarantees always the shortest path to smp before division process begins, or when d isnt available a number c is multiplied by a to make a valid condition a>=d for this first stage.
Lemma(3): From a graph-ultimum multiple of a to b, the gcd of this number and b is b itself
Well this is just a consequence of the previous manipulations, and the last remaining steps are also done gradually dividing by the biggest divisor which doesnt exceed its square root.
Dilemma: What is the optimum number c to be iteratively multiplied by a that would lead straight along to the opening condition for stage 1 then the ultimum?
Good question, for any simple situation there is a simple parry, so assuming an example of two ends (a,b)=(4,26) factorized like this:
  2 | 2
  2 | 13

Apart from the gcd=2 the smallest integer wich must be multiplied by 2 to reach 13 is 7, but it is obviously ruled out, cuz it is bigger than 2, so a is squared.
  2 | 2
  5 | 13

Appearenlty in the second example (a,b)=(10,26) above c is measured as the lowest integer from 1 to 5 which exceeds 13/5 hence it satisfies the condition of graph-scaling, which is 3, so the next step here is multiplying by 3
  2 | 2
  5 | 13
  3 |

Why ? this is because , once we have to multiply by 2*13/gcd=13 to match the second side of the table, the junk amount we added before is optimally smallest, and moving along the graph is minimized, if ever we multiplied by bigger value like 10 the chance of dividing by the least times reduces, and it would have been increased by 1 another dividing step to reach our goal 2*13. which are enumerated to: 13*2*5*10/2*5 then 13*2*5/5.
Whilst, obviously here the number to be divided by is 5*3<13*2
and one more thing ........ HAIL MATHS...

These are my comparative results with @flawr 's ones just pay attention that i made an upper bound for time execution consering flawr's algorithm, it takes too much time!
You may insert the starting and ending scanning ranges as variables a and b in the header of online compilable code.

Wow, this is surprising. I didn't expect that optimal paths could be constructed in a straightforward way. Looking forward to the explanation...

@Zgarb i made a trivial explanation within main post comments , i will moe elaborate when i finish golfing, btw, what a unique nice challenge!

@Zgarb the proof is fresh out the oven !!!!


text:
Tips for golfing in Lisp
What general tips are these for golfing in Lisp (any dialect)? Please post one tip per answer, and only answers that are specific to a dialect of Lisp (e.g. "remove comments" is not an answer).
Please post the dialect of Lisp your tip applies to with your tip.

https://xkcd.com/297/

Do you imagine these will be distinct from the tips for golfing in Scheme and Racket?

I would advise using tinylisp, a smaller, stripped-down version of Lisp for your golfing pleasure.

Order function parameters to minimize whitespace
Instead of
(defun f(a b)(...))
...
(f x(1+ y))

try something like
(defun f(b a)(...))
...
(f(1+ y)x)

Conditional Output
GNU Common Lisp
~v^
The up-and-out directive ~^ is most commonly used in a list formatting operation to terminate after the last list item. However, it can also be used with a v modifier to consume an argument, in which case it terminates if that argument is zero. This is particularly useful for dealing with the zero produced by dotimes.
(loop as n from 1 to 10 do(format t"~d~%"n))

(dotimes(n 11)(if(> n 0)(format t"~d~%"n)))

(dotimes(n 11)(format t"~v^~d~%"n n))

format(condition)
The first argument to format can be one of t, nil a.k.a. (), or a stream. If passed t, it will output to stdout, if nil it will return the formatted output as a string. This can be used conditionally output. The above example could be written equally as short as:
(dotimes(n 11)(format(> n 0)"~d~%"n))

If a value was output, the return value will be nil. Because of this, it can also be used as the terminating condition for a do loop:
(do((n 11))((<(decf n)1))(format t"~d~%"n))

(do((n 11))((format(>(decf n)0)"~d~%"n)))

~[...~]
The conditional formatter consumes an argument, and selects a formatting string from a list by index. A common use case is with the default formatter ~:; to select between zero and not zero.
(dotimes(n 11)(format t"~v^~[~r~:;~d~]~%"n(mod n 3)n))

Conditional formatters can also be nested, in which case each will consume an argument in turn.

~&
In each of the examples above, ~% is used to emit a newline. In most cases, this could be replaced by a literal newline. Another option is to use ~&, which will emit a newline if and only if the output cursor is not at the start of a line, a.k.a. a fresh-line.
Both ~% and ~& can also take an argument, with a v modifier or as a constant, and will produce as many newlines. They will also both happily accept a negative argument, in which case they emit nothing.

External References
Practical Common Lisp
18. A Few FORMAT Recipes
Common Lisp the Language, 2nd Edition
22.3.3. Formatted Output to Character Streams

Use loop and format, which is like printf on steroids. format includes iteration and conditions, as well as roman numerals, English numbers and English plurals. It is very, very ugly, and very compact.

Print strings consisting of capital letters via printing atoms
The princ function in Common Lisp is short, and will print objects without escape characers. If you print Common Lisp symbols, which have the synax 'symbol-name, this saves you from needing quotes around what you want to print, and can also save on whitespace. Note that when printing symbols, they will be capitalized. Also, it does not add a newline or a space, so you don't need concatenation.
For example,
(princ'hai)

will print HAI.
And
(princ'hai)(princ(read))

will print HAI, ask for input, and print it back out, e.g. if you type hello, the result is
HAIhellohello

Use 1+ and 1- for increment and decrement
Instead of (+ a 1) or (- b 1) try (1+ a) or (1- b).

I don't understand this. Isn't 1+ parsed as two tokens, 1 and +? I thought it was +1.

@Challenger5 1+ and 1- are parsed as a single token Common Lisp HyperSpec Function 1+, 1-

I thought that names couldn't start with digits?

@EsolangingFruit this is Lisp...


text:
Help golfing MIPS assembly
I want to write 7 assembly instructions (28 bytes) that runs a logical equivalent of this C snippet:
c = a + b + 6;
while (c > 5) {
  c = c - a;
  b = b + 1;
}

However, there are restrictions to the allowed instructions:
add, addi, sub, subi, slt, slti, bne

a, b, and c are located in registers $t0, $t1, and $s0 respectively. Assume they are declared as signed 32 bit integers. You may use other registers as necessary but you may not assume an initial value for any registers except $0 which is wired to ground (always 0, even if assigned to).
The best attempt to date is thanks to @Smac89 with the following assembly:
      addi $s1, $t0, 6     # d = a + 6
      add $s0, $s1, $t1    # c = d + b
loop: slti $t2, $s0, 6     # f = (c < 6)
      bne $t2, $0, exit    # (c < 6) ? exit
      sub $s0, $s0, $t0    # c = c - a;
      addi $t1, $t1, 1     # b = b + 1;
      bne $s1, $t0, loop   # (d != a) ? loop; always true
exit:

I don't understand, your goal is to do it in 7 instructions, and you post an example that solves it in 7 instructions. What is missing?

The label is on the 8th instruction, which feels kind of "cheaty." I'd like a more definitive way of doing it in exactly 7 lines (or less if you're feeling Godly).

Labels are not instructions.