text:
The absent-minded linguist
Background
Your friend, a linguist, has recorded and analyzed some simple conversation snippets in various languages.
Being quite absent-minded, they have forgotten which language each snippet was in.
You must help them by creating a program that analyzes the sentence structures and rules out impossible cases.
Input
Your input is a non-empty string containing the characters SVO, which stand for subject, verb, and object.
It represents a conversation snippet analyzed by the linguist.
Output
Your task is to break the string into sentences, and enter a period . after each sentence.
A sentence contains either a verb, OR a verb and a subject, OR a verb, a subject and an object.
However, you don't know which word order the original language uses; English uses subject-verb-object, but other languages, like Latin, use subject-object-verb.
In fact, all six permutations exist in natural languages, so you must check each of them.
Your output shall contain, in a newline-separated string, each applicable word order, a colon :, and the input string broken into sentences according to that order.
If the string cannot be parsed in some word order, the corresponding line shall be omitted.
The order of the lines does not matter, and it is guaranteed that at least one word order can be parsed.
Example
Consider the input
VSVOSV

In the VOS order, the snipped can be parsed as VS.VOS.V., and in the SVO order, it can be parsed as V.SVO.SV..
The order OSV also works, and the full output is
VOS:VS.VOS.V.
SVO:V.SVO.SV.
OSV:V.SV.OSV.

Rules and scoring
You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
Regular expressions and all built-ins are allowed.
Test cases
Input:
V
Output:
VSO:V.
VOS:V.
SVO:V.
OVS:V.
SOV:V.
OSV:V.

Input:
SVV
Output:
SVO:SV.V.
SOV:SV.V.
OSV:SV.V.

Input:
VSVOV
Output:
SVO:V.SVO.V.

Input:
VSOVS
Output:
VSO:VSO.VS.
OVS:VS.OVS.

Input:
SVOSV
Output:
SVO:SVO.SV.
OSV:SV.OSV.

Input:
VSVOSV
Output:
VOS:VS.VOS.V.
SVO:V.SVO.SV.
OSV:V.SV.OSV.

Input:
VSVVSOVSV
Output:
VSO:VS.V.VSO.VS.V.
OVS:VS.V.VS.OVS.V.
SOV:V.SV.V.SOV.SV.

Input:
SVVSVSOVSVV
Output:
SOV:SV.V.SV.SOV.SV.V.

Input:
VSOVSVSOVSVVS
Output:
VSO:VSO.VS.VSO.VS.V.VS.
OVS:VS.OVS.VS.OVS.V.VS.

I knew I should've implemented a string permutation feature into Japt an hour ago...

Perl 5 - 104 bytes
$a=<>;for(qw/VSO VOS SVO OVS SOV OSV/){$s=s/O//r;print"$_:".$a=~s/($_|$s|V)/$1./gr if$a=~/^($_|$s|V)*$/}

JavaScript (ES7), 172 bytes
x=>[for(i of"V(SO?)?0V(O?S)?0(SVO?|V)0(O?VS|V)0(SO?)?V0(O?S)?V".split(0))if((y=x.match(RegExp(i,"g"))).join``==x)i.match(/\w/g).slice(0,3).join``+":"+y.join`.`+"."].join`
`

Could probably be golfed further. Suggestions welcome!


text:
Finding Exclusive Area in Circle Intersections
Here's a deceptively challenging geometry puzzle for you!
Given a circle A, and n other circles B[n], find the total area contained within A that is not within any circle of B.
Your code should be as short as possible.
Input
Your input should contain the following information:

A floating-point number to represent the radius of circle A.
A list of floating-point numbers to represent the radii of circles in B.
A list of the centers of circles in B. Your program may expect the centers in either polar or Cartesian coordinates.
Optionally, you may receive the number n of circles in B. This input is not required.

It shall be assumed that the center of circle A is the origin, that is, the point (0, 0).
It is guaranteed that no two circles in B are identical, but it is not guaranteed that: all circles of B intersect A, all centers of B are outside A, or no two circles in B intersect each other. Ensure that your solution can handle various edge cases.
You may receive input in any order, and in the form of text input (through stdin or your language's equivalent), function parameters, or command-line arguments.
If you choose to receive text input, there should be one or two-character printable ASCII delimiters between pieces of input.
Output
Your program or function should output a single floating-point number representing the total area of A not within any of the circles of B. Your answers should be accurate to at least three significant figures for all test cases.
General code-golf rules apply.
Your solution should not rely on sampling points within the circles to determine an area.
Built-ins that automatically locate intersections of circles, find areas within intersections of circles, or solve this problem immediately are disallowed.
Test Cases
In each image, circle A is outlined in blue, with circles B outlined in green and filled black. The area that should be returned is filled red.
(Special thanks to Rainer P. for checking my solutions)
Test case 1:
A = {x: 0, y: 0, rad: 50}
B[0] = {x: 0, y: 0, rad: 100}

Result: 0.00

Test case 2:
A = {x: 0, y: 0, rad: 100.000000}
B[0] = {x: 100.000000, y: 0.000000, rad: 50.000000}
B[1] = {x: 30.901699, y: -95.105652, rad: 50.000000}
B[2] = {x: -80.901699, y: -58.778525, rad: 50.000000}
B[3] = {x: -80.901699, y: 58.778525, rad: 50.000000}
B[4] = {x: 30.901699, y: 95.105652, rad: 50.000000}

Result: 1.3878e+04

Test case 3:
A = {x: 0, y: 0, rad: 138}
B[0] = {x: 100, y: 0, rad: 100}
B[1] = {x: -50, y: -86, rad: 100}
B[2] = {x: -93, y: 135, rad: 50}

Result: 1.8969e+04

Test case 4:
A = {x: 0, y: 0, rad: 121.593585}
B[0] = {x: 81.000000, y: 107.000000, rad: 59.841457}
B[1] = {x: -152.000000, y: -147.000000, rad: 50.000000}
B[2] = {x: 43.000000, y: -127.000000, rad: 105.118980}
B[3] = {x: 0.000000, y: -72.000000, rad: 57.870545}
B[4] = {x: -97.000000, y: -81.000000, rad: 98.488578}
B[5] = {x: -72.000000, y: 116.000000, rad: 66.468037}
B[6] = {x: 2.000000, y: 51.000000, rad: 50.000000}

Result: 1.1264e+04

Test case 5:
A = {x: 0, y: 0, rad: 121.605921}
B[0] = {x: 0.000000, y: -293.000000, rad: 250.000000}
B[1] = {x: 0.000000, y: -56.000000, rad: 78.230429}
B[2] = {x: 0.000000, y: -102.000000, rad: 100.000000}

Result: 2.6742e+04

Suggested reading:
Fewell, M. P. "Area of Common Overlap of Three Circles." Oct. 2006. Web. http://dspace.dsto.defence.gov.au/dspace/bitstream/1947/4551/4/DSTO-TN-0722.PR.pdf.

I tried to solve this myself two years ago while working on this, based on how simple the problem is for two circles. I ended up reading the paper you linked... and decided to go with Monte Carlo'ing the area. "Your solution should not rely on sampling points within the circles to determine an area." D:

You don't seem to have a test case where one circle in B contains another. Might be worth adding that.

Could you check your third test case? I'm getting 1.8970e+04.

@MartinBüttner I too came across the problem on accident. I'm not overly pleased with my solution, but it seems to work. I'll try to draw up a little test for that case, thanks!

@LegionMammal978 Yes, it seems that case is wrong. I have the following data for intersections between circles:
B[0] - A intersection: 20653.659515,
B[1] - A intersection: 20757.824115,
B[1] - B[0] intersection: 1841.847766,
B[2] - A intersection: 1289.164541,
which yields 18969.69009 as the answer.

Very nice BrainSteel. I thought up the same problem last night, typed it up, then saw your challenge when I typed in my title. Argh! - wasted work.

Python 2, 631 bytes
from cmath import*
C=input()
O,R=C[0]
def I(p,r,q,s):
 try:q-=p;d=abs(q*q);x=(r*r-s*s+d)/d/2;return[p+q*(x+z*(r*r/d-x*x)**.5)for z in-1j,1j]
 except:return[]
S=sorted
V=S(i.real for p,r in C for c in C for i in[p-r,p+r]+I(p,r,*c)if-R<=(i-O).real<=R)
A=pi*R*R
for l,r in zip(V,V[1:]):
 H=[]
 for p,t in C:
    try:
     for s in-1,1:a,b=[p.imag+s*(t*t-(p.real-x)**2)**.5for x in l,r];H+=[a+b,a,b,s,t,p],
    except:0
 a,b=H[:2];H=S(H[2:]);n=0;c=a
 for d in H:
    s=d[3];z=.5;H*=d<b
    for q,w,e,_,t,y in(c,min(d,b))*(n-s<(a<d)or[0]*n>H):\
g=phase((l+w*1j-y)/(r+e*1j-y));A-=abs(g-sin(g)).real*t*t/2-z*q*(r-l);z=-z
    n-=s
    if(a<d)*s*n==-1:c=d
print A

Line-breaks preceded by \ are for easy reading, and aren't counted in the score.
Reads input through STDIN as a list of (center, radius) pairs, where center is a complex number in the form X+Yj.
The first circle in the list is A (whose center doesn't have to be at the origin), and the rest of the list is B.
Prints the result to STDOUT.
Example
Input:  (0+0j, 138),  (100+0j, 100), (-50+-86j, 100), (-93+135j, 50)
Output: 18969.6900901

Explanation
This is a (longer, and much uglier :P) variation on my solution to Martin Büttner's Area of a Self-Intersecting Polygon challenge.
It uses the same trick of breaking the problem down into small-enough pieces, for which it becomes more manageable.
We find the points of intersection between all pairs of circles (considering both A, and the circles in B), and pass a vertical line through each of them.
Additionally, we pass all the vertical lines tangent to any of the circles.
We throw away all the lines that don't intersect A, so that all the remaining lines are between the left and right tangents of A.

We're looking for the area of the intersection of A and the union of the circles in B—the dark red area in the illustration above.
This is the area that we have to subtract from A to get the result.
Between each pair of consecutive vertical lines, this area can be broken down into a set of vertical trapezoids (or triangles, or line segments, as special cases of trapezoids), with an "excess" arc segment next to each leg.
The fact that we pass as many vertical lines as we do guarantees that the bounded area is indeed no more complicated than that, since otherwise there would have to be an additional point of intersection, and hence an additional vertical line, between the two lines in question.

To find these trapezoids and arc segments, for each pair of consecutive vertical lines, we find the arc segments of each of the circles that properly lie between these two lines (of course, some circles may have no arc segment between a given pair of lines.)
In the illustration below, these are the six (bright and dark) yellow arc segments, when considering the two red vertical lines.
Note that, since we pass all vertical lines tangent to the circles, if a circle has an arc segment between the two lines, it necessarily intersects both lines, which simplifies the rest of the algorithm.
Not all of these arcs are relevant; we're only interested in the ones that are on the boundary of the intersection between A and the union of B.
To find those, we sort the arcs top-to-bottom (note that the arcs may not properly intersect each other, since this would imply the existence of another vertical line between the two we're considering, and so it makes sense to talk about an arbitrary arc being above, or below, any other one.)

We traverse the arcs, in order, while keeping count of the number of B circles we're currently inside, n.
If n changes from 0 to 1 while we're inside A, or if we're at the top arc of A while n is nonzero, then the current arc corresponds to one leg of a trapezoid.
If n changes from 1 to 0 while we're inside A, or if we're at the bottom arc of A while n is nonzero, then the current arc corresponds to the other leg of the same trapezoid.
Once we find such a pair of arcs (the two bright yellow arcs in the above illustration), we calculate the area of the corresponding trapezoid, and of the two arc segments, and add it to the total area to be subtracted from A.
Calculating the area of A, as well as the areas of the trapezoids, is fairly straight forward.
The area of each arc segment is the area of the corresponding circular sector, minus the area of the triangle whose vertices are the two endpoints of the arc segment, and the center of the corresponding circle.

This is the sort of solution I was considering, except I would have found the target area directly by finding the triarcs and trapearcs that were in A but not B (whose areas must be found by subtracting an arc segment from a triangle or trapezoid).

@quintopia This might even be a tiny bit shorter, since it saves us the need to calculate the area of A, and all it takes is probably playing a bit with the condition on n.

@quintopia OTOH, you'll have to account for the possibility of having a positive arc next to one of the legs, if it's an arc segment of A, so who knows...

Excellent solution. A problem almost identical to this was stuck in my head last night, and I really wanted someone to solve it. Your solution is better that the ideas I was working with.

Desmos, 458 438 bytes
g(P,R,n)=E(P,R)-E(P[2...],R[2...])
I=[1...n]
M=[1,-1]
w=join(P.x+R,P.x-R,[P[u].x+h(V.xA+V.yS(4DR[u]^2-AA)^h)/DforS=M,u=I,v=I])
X=w[w=w].sort
a=X[t]
b=X[t+1]
J=I[a-R<P.x<b+R]
Y(s)=(P.y+s(RR-(P.x-h(a+b))^2)^h)[J]
E(P,R)=[\total((s(b-a)P.y+hRR(U((b-P.x)/R)-U((a-P.x)/R)))[J[0=\sum_{j=1}^n\{J=J[j]:0,Y(-1)[j]<Y(s)<Y(1)[j],0\}]])\for s=M,t=[1...X.\length]].\total
U(x)=xp+arctan(x/p)
p=(1-xx)^h
A=D+R[u]^2-R[v]^2
D=V.x^2+V.y^2
V=P[v]-P[u]
h=.5

Try it on Desmos!
-20 bytes thanks to @Aiden Chow. Besides syntax, main optimization was converting D=distance(V,(0,0)) to D=V.x^2+V.y^2, which saved a bunch since (old) D was squared a few times.
The main function is g(P,R,n), where n is the number of points (including A), P is the list of points (starting with A), and R is the corresponding list of radii.
This takes a similar approach as Ell (with the vertical slices). One big difference is that I ignore A pretty much immediately: the desired area is the area of the union of the discs, minus the area of the unions of the discs excluding A. Not sure if this saves bytes.
For reference, the graph before diving deep into syntax-golfing, and the graph when it only calculated the area of the union of discs, with readable variable names.

Bro what am I looking at O_O, you actually too good at Desmos lol

A few minor golfs here and there: 438 bytes

Wolfram Language (Mathematica), 73 bytes
RegionMeasure@RegionDifference[Disk[{0,0},#1],RegionUnion[Disk@@#&/@#2]]&

Try it online!
Input:
RMax, {{{xc1, yc1}, r1}, {{xc2, yc2}, r2},...}

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:
Chess-olition Derby
What could be more polar opposites than chess and demolition derby. You would think that no one who enjoys one would enjoy the other... until today.
Rules
The starting position is a standard chess board:
RNBQKBNR
PPPPPPPP

PPPPPPPP
RNBQKBNR

Looks normal enough, until you find out it's an EVERY PIECE FOR ITSELF, LAST PIECE STANDING competition:

On every turn, each piece on the board gets to make one randomly*-selected valid move (using it's standard move rules). However, the order the pieces move in is randomized every turn.
A piece can capture ANY PIECE, even if it's the same color as it, even a king.
Pawns can capture FORWARD, as well as diagonal. Moreover, like normal, if there is an empty space in front of it, a pawn can move two spaces on its first move (they can also capture that way.) Furthermore, pawns promote to any random piece (including king) other than a pawn.
The winner is the last piece standing. However if after 1000 turns, there is more than one piece left, all of the remaining pieces are winners.
No En Passants, Checks, Castles, etc.

Output
After every turn output the turn number, and what the board looks like. After a piece is killed it is removed from the board. After the first turn, the board may look like this:
1.
   K
RBQ N BR
NP  P P
  PP P P
R PP
BPN PNP
    K  R
       Q

After 1000 moves the board may look like this:
1000.
  Q  K

P  N R

 R  B N

  Q

And the game ends.
Or Maybe after 556 turns the board look like this:

556.

     R

So the game ends there.
*Please ensure all randomization done in this challenge is uniform (every possibility has an equal chance of occurring).

If a pawn can capture without moving diagonally, can it also move diagonally without capturing?

@tri no, it cant.

Can a pawn capture two pieces at once when it does a double move?

@orlp No, i should clarify that. You can only move two, if there's an empty space in front of you.

If a piece cannot move when it takes its turn, is it skipped? What about if it's skipped, then a move opens up due to the piece that moved after it? Can it move before the turn is over?

Also, in your examples, you need to distinguish the pawns as black or white (p black and P white is standard in FEN), because they move different directions.

I think you should use 3 rounds as an example, not just randomized boards.

Python 2, 862 846 844 bytes
from random import*
A=-1;a,b=[(0,1),(0,A),(A,0),(1,0)],[(A,A),(A,1),(1,A),(1,1)]
r=range(8)
C='RNBQK';q=C+'BNR'
def m(x,y,B,t):
 P=B[y][x];M=[]
 for w,z in dict(zip('pP'+C,[[],[],a,zip([A,1,-2,2]*2,[2,2,1,1,-2,-2,A,A]),b]+[a+b]*2))[P]:
	for i in r[1:]:
	 X,Y=x+z*i,y+w*i;M+=(X,Y),
	 if P in'NK'or 1-(8>X>A<Y<8)or' '<B[Y][X]:break
 if P in'pP':d=[A,1][P<'p'];M=zip((x-1,x,x+1)[B[y+d][x-1]<'!':2+(B[y+d][-~x%8]>' ')],(y+d,)*3)+[(x,y+2*d)]*(t*B[y+d][x]<'!')
 return choice([(X,Y)for X,Y in M if-1<X<8>Y>A])
B=map(list,[q,'P'*8]+[' '*8]*4+['p'*8,q])
t=0
while t<1e3:
 t+=1;p=[(x,y)for y in r for x in r if' '<B[y][x]];shuffle(p)
 if len(p)<2:break
 while p:x,y=p.pop();Z=X,Y=m(x,y,B,t<2);B[Y][X],B[y][x]=B[y][x],' ';Z in p and p.remove(Z)
 for j in 0,7:
	for i in r:
	 if B[j][i]in'pP':B[j][i]=choice(C)
 print t
 for l in B:print''.join(l).upper()

Try it online!
Saved 18 bytes thanks to Jonathan Frech

855 bytes (not fully tested).

847 bytes.

I think ...]+[(a+b)]*2 can be either ...]+[a+b]*2 or ...,a+b,a+b].

PHP, 1849 bytes
<?$z=[R,N,B,Q,K,B,N,R];$y=[_,_,_,_,_,_,_,_];$u=shuffle;$b=[$z,[P,P,P,P,P,P,P,P],$y,$y,$y,$y,[p,p,p,p,p,p,p,p],$z];$z=[R,N,B,Q,K];for($i=0;$i<8;$i++)for($j=0;$j<8;$j++)$r[]=[$i,$j];for(;$c++<=999;){for($i=$_=0;$i<8;$i++)for($j=0;$j<8;$j++)if($b[$i][$j]!=_)++$_;if($_<2)break;$u($r);$n=[];foreach($r as$l){list($y,$x)=$l;$a=$y+1;$d=$y-1;$j=$x+1;$t=$x-1;$p=$b[$y][$x];if($n[$y][$x]!=1&&$p!=_){$v=$e=$f=$g=$h=$k=$o=$q=$s=[];if($p==R||$p==K||$p==Q){$m=($p==K)?2:9;for($i=1;$i<$m;$i++){if(!$e&&$y-$i>=0){$v[]=[$y-$i,$x];if($b[$y-$i][$x]!=_)$e=1;}if(!$f&&$y+$i<8){$v[]=[$y+$i,$x];if($b[$y+$i][$x]!=_)$f=1;}if(!$g&&$x-$i>=0){$v[]=[$y,$x-$i];if($b[$y][$x-$i]!=_)$g=1;}if(!$h&&$x+$i<8){$v[]=[$y,$x+$i];if($b[$y][$x+$i]!=_)$h=1;}}}if($p==B||$p==K||$p==Q){$m=($p==K)?2:9;for($i=1;$i<$m;$i++){if(!$k&&$y-$i>=0&&$x-$i>=0){$v[]=[$y-$i,$x-$i];if($b[$y-$i][$x-$i]!=_)$k=1;}if(!$o&&$y-$i>=0&&$x+$i<8){$v[]=[$y-$i,$x+$i];if($b[$y-$i][$x+$i]!=_)$o=1;}if(!$q&&$y+$i<8&&$x-$i>=0){$v[]=[$y+$i,$x-$i];if($b[$y+$i][$x-$i]!=_)$q=1;}if(!$s&&$y+$i<8&&$x+$i<8){$v[]=[$y+$i,$x+$i];if($b[$y+$i][$x+$i]!=_)$s=1;}}}if($p==N){if($y-2>=0&&$t>=0)$v[]=[$y-2,$t];if($y-2>=0&&$j<8)$v[]=[$y-2,$j];if($d>=0&&$x-2>=0)$v[]=[$d,$x-2];if($d>=0&&$x+2<8)$v[]=[$d,$x+2];if($a<8&&$x-2>=0)$v[]=[$a,$x-2];if($a<8&&$x+2<8)$v[]=[$a,$x+2];if($y+2<8&&$t>=0)$v[]=[$y+2,$t];if($y+2<8&&$j<8)$v[]=[$y+2,$j];}if($p==P){if($y==1&&$b[$a][$x]==_)$v[]=[$y+2,$x];if($j<8&&$b[$a][$j]!=_)$v[]=[$a,$j];if($t>=0&&$b[$a][$t]!=_)$v[]=[$a,$t];$v[]=[$a,$x];}if($p==p){if($y==6&&$b[$d][$x]==_)$v[]=[$y-2,$x];if($j<8&&$b[$d][$j]!=_)$v[]=[$d,$j];if($t>=0&&$b[$d][$t]!=_)$v[]=[$d,$t];$v[]=[$d,$x];}$u($v);$v=$v[0];$b[$y][$x]=_;$w=$p;if($w==P&&$v[0]>6&&$u($z)&&$w=$z[0]);if($w==p&&$v[0]<1&&$u($z)&&$w=$z[0]);$b[$v[0]][$v[1]]=$w;$n[$v[0]][$v[1]]=1;}}echo $c.".
";foreach($b as$a)echo str_replace([_,p],[' ',P],join("",$a))."
";}

Try it online!
It can definitely be golfed more, and it looks somewhat like the workings of a madman (which, I suppose, it may be).
I am impressed at how fast random moves can clear the board (I've seen 15 moves do it). Also, I think the only one I saw hit the 1000 limit was two bishops on different colors dancing.

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


text:
Construct ASCII arches
I like ascii art and I get bored a lot, so I found some ascii characters and started to make random things, 8-bit mario castle, mazes, and arches. I found that the arches could easily be stacked in a neat way.
╔═══════╗
║╔═════╗║
║║╔═══╗║║
║║║╔═╗║║║
╨╨╨╨─╨╨╨╨

Challenge
Create a program, function, or any other standard format that accepts an integer that is greater than or equal to 0 (unless you are doing the bonus) and outputs  ascii art with the amount of arches specified.
Test Cases
Input:
7

Output:
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

Alt:
+-------------+
|+-----------+|
||+---------+||
|||+-------+|||
||||+-----+||||
|||||+---+|||||
||||||+-+||||||
||||||| |||||||
---------------

Input:
1

Output:
╔═╗
╨─╨

Alt:
+-+
| |
---

If the integer is 0 then don't output anything
This question will be in utf-8, each character will count as a "byte"
This is codegolf so the shortest answer wins.
You have the option of using +-+ instead of ╔═╗, --- instead of ╨─╨, and | instead of ║

Bonus (not decided whether to allow this on the alternate version because it wouldn't be as hard)
-10% if the program supports negative numbers and flips the arches like so
╥╥╥╥─╥╥╥╥
║║║╚═╝║║║
║║╚═══╝║║
║╚═════╝║
╚═══════╝

AFAIK those are not ASCII characters. [tag:unicode-art]

welp, @flawr you are right. What now...

The world is going to collapse! Don't worry, perhaps just mention that they are not part of standard ASCII, but the ascii-art tag still applies (the unicode-tag was a joke.)

That looks like extended ASCII, though, so you're probably okay.

@ՊՓԼՃՐՊՃՈԲՍԼ There's no standard version of extended ASCII https://en.wikipedia.org/wiki/Extended_ASCII The closest thing there is is codepage 437 https://en.wikipedia.org/wiki/Code_page_437 which was standard in the USA and many other countries but I find when I copy and paste this into a codepage 437 editor and back into windows it "interprets" as arches with +---+ at the top, sides of | and a bottom of ----- which looks fine to me. Juanpotato, if you want to use non-ascii characters, please indicate the encoding in the question. As it stands I'm voting to close as unclear.

@steveverrill I clarified in the question, is it ok now?

@JuanPotato UTF-8 good call. each character will count as a "byte" (for counting purposes) would at first glance seem to remove incentive for codepage 437 anyway, but as you can see from xnor's answer the code would have been less fiddly with single byte characters. Indicating the codepoints in the question would be a useful addition. Closevote canceled and +1.

+1 for specifying characters instead of bytes. I feel the normal scoring (bytes), would have arbitrarily punished/rewarded certain implementations, due to the necessity of outputting extended ASCII. In that spirit, would it be acceptable to you for people to have the option to use +---+ and | | instead, given that it shouldn't affect the scoring now? This might get you additional answers, given some languages/editors/platforms have a much easier time with ordinary 7-bit printable ASCII.

@type_outcast I have now allowed the option to use +-|, but am not sure whether to include the bonus as it would not be as difficult. Maybe lower the percentage?

The ASCII output is too different from the Unicode output (there is an extra line).

But then the first arch has no sides if there is no extra line

CJam, 59 bytes
qi:Lg"^Za"a{_0=1'Z3*tsa\{'[2*\*}%+}L(*'rL*a2*N*a+9462ff+N**

Try it here!

You can now use +-| to build the arches, see op for examples.

Python 2, 106 bytes (94 chars)
n=input();j=1
exec"s=j/2*'║';print s+'╔'+'═'*(2*n-j)+'╗'+s;j+=2;"*n
if n:t='╨'*n;print t+'─'+t

Pretty straightforward. Prints line by line with a changing number of horizontal and vertical bars. The last line is printed separately.
I feel like I'm missing some optimizations. The fact that the chars are multiple bytes means you can't do something like '║╨'[n>0], so I didn't find a good way to print the last line in the loop. It's ugly that there's so much manipulation going on with the counter. I'd like update strings directly, like s+='║', but the index is also used for horizontal bars.

You can now use +-| to build the arches, see op for examples.

@JuanPotato OP stands for original poster. Do you mean the question?

@flagasspam yes, I've just seen uses where it means original post

Perl, 78 82 chars
$n='─';$_='══'x pop;while(s/══//){print"$s╔═$_╗$s\n";$s.="║";$n="╨$n╨"}$s&&print$n

Sadly, I couldn't figure out a way to take advantage of the bonus without increasing the size by more than 10%. I may yet prevail.
Ungolfed
Pretty straightforward, really. Builds up bottom line (╨$n╨) incrementally, while shortening top line (══) by two characters, ending when it can no longer be shortened, so I don't have to mess with counters.
 $n = '─'; # Bottom line
 $_ = '══'x pop; # "Top" line, length from commandline argument
 while (s/══//) { # Shorten top line by two characters
     print "$s╔═$_╗$s\n"; # Print current line with $s (sides)
     $s .= "║";           # Append vertical bar to sides
     $n  = "╨$n╨";        # Widen bottom line
 }
 $s && print $n; # Print bottom line if input is not 0

I think this prints a single ─ for n = 0, but it should print nothing.

@Mauris I just ran it and you are correct

@Mauris Dang! You're absolutely right. My original version was fine, but somewhere along the line I lost the check. Fixed, at the cost of 4 chars. Thanks for spotting that.

I know this is old, but to add to @Abigail's comment, you can save bytes using -n too: Try it online!

Bash, 124 bytes (112 characters)
printf -vh %$1s
b=${h// /╨}
h=${h// /═}
for((n=$1;n--;)){
echo $v╔$h${h:1}╗$v
h=${h#?}
v+=║
}
(($1))&&echo $b─$b

Sample run:
bash-4.3$ bash ascii-arch.sh 7
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

bash-4.3$ bash ascii-arch.sh 1
╔═╗
╨─╨

bash-4.3$ bash ascii-arch.sh 0

Japt -R, 29 bytes
Uses + & -. Sacrificed 4 bytes to handle the bloody input validation!
©Æ'+²¬q-p´UÑÄÃpS û| p-pNÑÄ)ªP

Try it

Explanation
                                  :Implicit input of integer U
©                                 :Logical AND with U
 Æ                                :Map the range [0,U)
  '+                              :  Literal "+"
    ²                             :  Repeat twice
     ¬                            :  Split
      q                           :  Join with
       -                          :   Literal "-"
        p                         :   Repeat
         ´U                       :    Decrement U
           Ñ                      :    Multiply by 2
            Ä                     :    Add 1
             Ã                    :End mapping
              pS                  :Push a space
                 û|               :Centre pad each element with "|" to the length of the longest element
                    p     )       :Push
                     -            : Literal "-"
                      p           : Repeat
                       N          :  The array of inputs (which will be cast to an integer if we perform a mathematical operation on it)
                        ÑÄ        :  Multiply by 2 and add 1
                           ª      :Logical OR
                            P     :The empty string
                                  :Implicitly join with newlines and output

fails on the input 0

@dzaima, what do you mean? How can you have an arch of size 0?

If the integer is 0 then don't output anything from the challenge :/

@dzaima, Oh, I missed that. Thanks. First of all: Boo-urns to input validation! Secondly, Japt can't output nothing - I could output 0, false or an empty string at a cost of some bytes but I don't know if any of those would be acceptable except, maybe, the empty string, which would cost me 5 bytes (0 would only cost me 1).

Swift (209 bytes)
Probably Swift is not the best language for this, this is my first time trying to do a code golf challenge:
func *(l:String,r: Int)->String{return r>0 ?l+(l*(r-1)):""}
let n=Int(readLine()!)!
for i in 0...(n-1){let a=("║"*i)+"╔═";let b=a+("══"*(n-1-i))+"╗"+("║"*i);print(b)};print("╨"*n+"─"+"╨"*n)

Ruby, 90 bytes (74 characters)
->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}

Sample run:
2.1.5 :001 > ->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}[7]
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨
 => nil

2.1.5 :002 > ->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}[1]
╔═╗
╨─╨
 => nil

2.1.5 :003 > ->n{n.times{|i|puts ?║*i+?╔+?═*((n-i)*2-1)+?╗+?║*i}>0&&puts(?╨*n+?─+?╨*n)}[0]
 => false

Haskell, 151 162 bytes
r=replicate
c=concat
f n=putStr$unlines[c[r i '║',"╔",r(2*(n-i)-1)'═',"╗",r i '║']|i<-[0..n-1]]++c[r n '╨',r(signum n)'─',r n '╨']
main=readLn>>=f

Edit: I forgot to deal with 0 as input

JavaScript (ES6), 101 characters
f=(n,i=0)=>n?i-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""

Explanation
Recursive function that prints each line
f=(n,i=0)=>              // f = recursive function, i = current line (default = 0)
  n?                     // if n != 0
    i-n?                 // if we are not in the last line, print the line
      (b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1)               // add the output of the next line
    :(g="╨"[r](n))+"─"+g // if we ARE in the last line, print the last line
  :""                    // print nothing if n = 0

Test
Test does not use default parameter for browser compatibility.

var solution = f=(n,i)=>n?(i|=0)-n?(b="║"[r="repeat"](i))+`╔${"═"[r]((n-i)*2-1)}╗${b}
`+f(n,i+1):(g="╨"[r](n))+"─"+g:""
<input type="number" oninput="result.textContent=solution(+this.value)" />

PHP (109 chars)
$s='';for($b=($n=$argv[1])?'─':'';$n--;){echo$s.'╔═'.str_repeat('══',$n)."╗$s\n";$s.='║';$b="╨{$b}╨";}echo$b;

Still need to get rid of that str_repeat but most alternatives won't handle mulyibyte chars.
$s = '';
// Initialise $b (bottom) to '─' or '' for n==0
for ($b = ($n = $argv[1]) ? '─' : ''; $n--;) {
    // Echo sides + arch + sides
    echo $s . '╔═' . str_repeat('══', $n) . "╗$s\n";
    // Growing sides
    $s .= '║';
    // Growing bottom
    $b = "╨{$b}╨";
}
// Show bottom
echo $b;

Retina, 79 chars
.+
$0$*═$0$*═╗
^═
╔
+`(║*)╔═(═+)═╗║*$
$0¶$1║╔$2╗║$1
(\S+)$
$0¶$1
T`═╔╗║`─╨`\S+$

Try it online.
This uses a new feature in Retina that replaces a decimal number \d+ with a list of that many characters $0$*═.

, 54 chars / 95 bytes
⩥ïⓜᵖ⟮ ⍘|ď⟯$+`+⦃⟮⍘-ď (ï⟯-$)*2-1)}+`+Ⅰ$;ï⅋ᵖⅠï+⬭+Ⅰï,Ⅱ*2+1

Try it here (Firefox only).
Explanation
⩥ïⓜᵖ⟮ ⍘|ď⟯$+`+⦃⟮⍘-ď (ï⟯-$)*2-1)}+`+Ⅰ$;ï⅋ᵖⅠï+⬭+Ⅰï,Ⅱ*2+1 // implicit: ï=input, $=mapped item
                                                       // PHASE 1
⩥ïⓜ                                                   // create a range to map over
    ᵖ                                                  // push to stack:
     ⟮ ⍘|ď⟯$                                            // | repeated $ times
           +`+⦃⟮⍘-ď (ï⟯-$)*2-1)}+`                      // & +[- repeated 2$-1 times]+
                                 +Ⅰ$;                  // & | repeated $ times
                                                       // PHASE 2
                                     ï⅋                // if ï>0
                                       ᵖ               // push to stack 2 items:
                                        Ⅰï+⬭+Ⅰï,      // | repeated $ times & [space] & | repeated $ times
                                                 Ⅱ*2+1 // and - repeated 2ï+1
                                                       // implicit stack output, newline-separated

NOTE: this makes use of good ol' copy blocks to get at the spots where ordinary variable declaring could not reach.

Sed, 97 bytes (81 characters)
(96 bytes (80 characters) code + 1 character command line option)
s/.(.*)/2&\13/
t
:
H
s/(.+)11(.+)/4\1\24/
t
y/1234/─╨╨╨/
H
g
s/\n//
y/1234/═╔╗║/

Input expected as unary integer.
Sample run:
bash-4.3$ sed -r 's/.(.*)/2&\13/;t;:;H;s/(.+)11(.+)/4\1\24/;t;y/1234/─╨╨╨/;H;g;s/\n//;y/1234/═╔╗║/' <<< '1111111'
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

bash-4.3$ sed -r 's/.(.*)/2&\13/;t;:;H;s/(.+)11(.+)/4\1\24/;t;y/1234/─╨╨╨/;H;g;s/\n//;y/1234/═╔╗║/' <<< '1'
╔═╗
╨─╨

bash-4.3$ sed -r 's/.(.*)/2&\13/;t;:;H;s/(.+)11(.+)/4\1\24/;t;y/1234/─╨╨╨/;H;g;s/\n//;y/1234/═╔╗║/' <<< ''

Sed, 105 bytes (75 characters)
(104 bytes (74 characters) code + 1 character command line option)
y/1/═/
s/.(.*)/╔&\1╗/
t
:
H
s/(.+)══(.+)/║\1\2║/
t
y/╔║╗═/╨╨╨─/
H
g
s/\n//

Input expected as unary integer.
Sample run:
bash-4.3$ sed -r 'y/1/═/;s/.(.*)/╔&\1╗/;t;:;H;s/(.+)══(.+)/║\1\2║/;t;y/╔║╗═/╨╨╨─/;H;g;s/\n//' <<< '1111111'
╔═════════════╗
║╔═══════════╗║
║║╔═════════╗║║
║║║╔═══════╗║║║
║║║║╔═════╗║║║║
║║║║║╔═══╗║║║║║
║║║║║║╔═╗║║║║║║
╨╨╨╨╨╨╨─╨╨╨╨╨╨╨

bash-4.3$ sed -r 'y/1/═/;s/.(.*)/╔&\1╗/;t;:;H;s/(.+)══(.+)/║\1\2║/;t;y/╔║╗═/╨╨╨─/;H;g;s/\n//' <<< '1'
╔═╗
╨─╨

bash-4.3$ sed -r 'y/1/═/;s/.(.*)/╔&\1╗/;t;:;H;s/(.+)══(.+)/║\1\2║/;t;y/╔║╗═/╨╨╨─/;H;g;s/\n//' <<< ''

Canvas, 15 bytes
-＊+∔］⤢：↷±ｎ│Ｌ-×∔

Try it here!
Explanation:
{    ]            map over 1..input
 -*                 repeat "-" counter times
   +∔               append "+" to that
      ⤢           transpose
       :          create a duplicate of that
        ↷±        rotated 90°, then reversed horizontally
          n       overlap the 2
           |      and palindromize horizontally with 1 overlap
            L     get the with of that
             -×   repear "-" that many times
               ∔  and add vertically to the rest of the output

Vyxal, 30 bytes
(\|n*\++⁰n--øm,)\|*ð+øm¶+⁰d›-,

Try it Online!
(              )               # Input times...
 \|n*                          # (iteration number) |s
     \++                       # With a plus appended
        ⁰n--                   # And (input - iteration number) minuses
            øm,                # Palindromed and outputted
                \|*            # Input |s
                   ð+          # Plus a space
                     øm        # Palindromised
                       ¶+      # Plus a newline
                         ⁰d›   # (2(iteration number) + 1)
                            -, # Minuses appended, and outputted


text:
Smooth a line graph
Given an input of an integer n and a list of positive integers m1,
m2, ..., output a list of integers m1',
m2', ... where mx' is defined as the average of
mx-n through mx+n.
When calculating these averages, ignore indices that are out of bounds (and
adjust what you are dividing the sum by accordingly). n will always be ≥ 1
but never half of the length of m (rounded down) or more. This means that
the minimum length of m is 4. The elements in m will be positive integers,
but the output must be accurate to at least 3 decimal places.
The input / output elements that are lists may be either
whitespace-/comma-separated strings or arrays/lists/etc. For input, if your
solution is a function, you may additionally take a first argument of n and
additional arguments as mx (this applies to command line arguments
as well).
Here is a visual representation of n=1:
1 4 5 7 10
__/ | | |
L avg(1,4) = 2.5
    | | |
\___/ | |
  L avg(1,4,5) = 3.333
      | |
  \___/ |
    L avg(4,5,7) = 5.333
        |
    \___/
      L avg(5,7,10) = 7.333

      \___
        L avg(7,10) = 8.5

Final output: 2.5 3.333 5.333 7.333 8.5

Since this is code-golf, the shortest code in bytes wins.
Test cases (these were done manually; please notify me of any errors):
In                             Out
----------------------------------------------------------------------
n=1, m=12 6 3 9                9 7 6 6
n=1, m=1 4 5 7 10              2.5 3.333 5.333 7.333 8.5
n=1, m=1 3 3 7 4 2 4 2         2 2.333 4.333 4.666 4.333 3.333 2.666 3
n=2, m=1 3 5 9 10 14 15 16 23  3 4.5 5.6 8.2 10.6 12.8 15.6 17 18
n=3, m=1 1 1 1 1 1 1 1         1 1 1 1 1 1 1 1
n=3, m=1 2 3 4 5 6 7 8         2.5 3 3.5 4 5 5.5 6 6.5

To be clear, this is the same as prepending and appending zeros and then calculating the means of each contiguous subsequence of length 3?

@El'endiaStarman No. avg(0,1,2) is not the same as avg(1,2). For the "edge cases" (ha), you shouldn't be averaging as many elements of the input list.

Ah, right, I see now.

Related

This would have been a better challenge without the restriction that the m_i are positive.

Test case 3, in my opinion 8/3 with 3 digits accuracy should be 2.667 and 14/3  should be 4.667

@PeterTaylor I don't see how that would change the task appreciably.

@AlexA., by eliminating the easy sentinel.

Pyth, 20 bytes
m.O:vzeS,0-dQh+dQUvz

Test suite
Pretty straightforward, just slice the appropriate section out of the list, then average.

@ThomasKwa I tried that, but it seems like you have to store E outside the map because it will keep trying to read a new value if it is inside. This makes it take the same number of bytes.

MATL, 30 28 26 24 bytes
2*1+:g2X53$X+1Mbgbb3$X+/

Tested on Matlab and on Octave. Uses current version (9.1.0) of the language/compiler.
Input is: first the number controlling window length, then the array with format [1 4 5 7 10].
EDIT (20 May 2016): Try it online! The code in the link has X+ replaced by Y+ to conform to version 18.0.0 of the language.
Example
>> matl
 > 2*1+:g2X53$X+1Mbgbb3$X+/
 >
> 1
> [1 4 5 7 10]
2.5 3.333333333333333 5.333333333333333 7.333333333333333               8.5

>> matl
 > 2*1+:g2X53$X+1Mbgbb3$X+/
 >
> 2
> [1 3 5 9 10 14 15 16 23]
3               4.5               5.6 8.199999999999999              10.6               2.8              15.6        17                18

Explanation
The equivalent Matlab code would be
n = 1; %// first input: number controlling window length
x = [1 4 5 7 10]; %// second input: array
result = conv(x,ones(1,2*n+1),'same')./conv(ones(size(x)),ones(1,2*n+1),'same');

The MATL code makes use of the recently added features of implicit input and automatic function-input clipboard:
2*1+          % get implicit input "n". Multipliy by 2 and add 1
:g            % create a vector of 2*n+1 "true" values (will act as "one" values)
2X5           % 'same' string literal
3$X+          % get implicit input "x" (array). Convolution using three inputs
1M            % push all three inputs from last function
bgbb          % convert first input to "true" values. Will act as "one" values
3$X+          % convolution using three inputs
/             % divide element-wise. Implicitly print

APL (Dyalog Unicode), 18 16 bytes
{⍵⌹×⍵}⌺(1+2×⎕)⊢⎕

Try it online!
@ngn suggested an average trick using ⌹, and I took it further to shorten it by two bytes, eliminating the need of ↓.
Since the input is positive integers and the Stencil's padding gives only zeros, it suffices to average the nonzero entries.
The default trick for average using ⌹ (matrix divide/solve linear equation/least squares fit) is "divide a vector by its all ones version", which solves the least squares of something like this:
1x = 1
1x = 3
1x = 5

where the least square solution is exactly the average. I modified it to ignore the zeros when calculating the average:
{⍵⌹×⍵}  Input: a vector of positive integers, possibly with zeros to ignore
   ×⍵   Signum of each number, which gives 1 for positives and 0 for zeros
 ⍵⌹     Matrix-divide the original vector by the above,
        which gives the system of equations, e.g. for 0 0 1 3 5:
0x = 0
0x = 0
1x = 1
1x = 3
1x = 5
        Then the zero-coefficient equations are ignored in the least squares,
        which leads to the average of only positive entries.

Alternatively, Extended can do the same in 15 bytes, exploiting the fact that the left argument is always zero (as opposed to the "padding size" in regular Dyalog version):
APL (Dyalog Extended), 15 bytes
(⊢⌹<)⌺(1+2×⎕)⊢⎕

Try it online!

APL (Dyalog Unicode) 18.0, 18 bytes
(+/÷≢)⍤↓⌺(1+2×⎕)⊢⎕

Try an equivalent 17.x program online!
What a fitting challenge for Dyalog APL's Stencil ⌺.
The Stencil operator extracts the moving window over an array exactly as described in the challenge. Specifically, for odd window size, the window is centered over each element, padded with zeros outside the array as necessary, and then the amount of padding is given as an extra information so that single Drop ↓ will remove such padding. The rest is just specifying the right window size and taking average (+/÷≢) over each subarray.
Illustration
Input array: 12 6 3 9
Input n: 1
Window size: 3 (1+2×n)
Arguments to left operand of Stencil:
  Left  Right
  1     0  12 6  ⍝ Zero padding 1 unit to the left; 1↓ drops 0 from the front
  0     12 6  3
  0     6  3  9
  ¯1    3  9  0  ⍝ Zero padding 1 unit to the right ¯1↓ drops 0 from the back

Matrix multiplication approach is also possible, but it is not short enough:
APL (Dyalog Unicode), 21 bytes
{÷/⍵1+.×¨⊂⍺≥|∘.-⍨⍳≢⍵}

Try it online!
How it works
{÷/⍵1+.×¨⊂⍺≥|∘.-⍨⍳≢⍵}  ⍝ Left:n, Right:m
                 ⍳≢⍵   ⍝ 1..length of m
             ∘.-⍨      ⍝ Self outer product by difference
          ⍺≥|          ⍝ 1 if abs diff is at most n, 0 otherwise
                       ⍝ which gives the band matrix
   ⍵1+.×¨⊂  ⍝ Inner product with m and all-one vector
 ÷/         ⍝ Divide left by right

CJam, 31 30 bytes
ri_S*l~1$++\2*)ew{S-_:+\,d/}%`

Input format is n [m1 m2 ... mx].
Run all test cases. (Automatically converts the test suite to the required input format.)
This works by pre- and append n spaces, then taking all substrings of length 2n+1, and removing the spaces again before computing their means.

Julia, 57 bytes
f(n,m)=[mean(m[max(1,i-n):min(end,i+1)])for i=1:endof(m)]

This is a function that accepts two integers and returns an array of floats.
The approach here is very straightforward. We construct a new array by taking the mean of sections of the input array, truncating at the front and back.

Pyth, 22 bytes
.OMsM.:++J*]YKE]MQJhyK

Explanation:
.OM sM .: +               Means of flattens of sublists of length 2K+1 of
            + J *
                  ] Y     J is E copies of [].
                  K E     Save E to a variable to use it later.
               ]MQ        the input
            J             Put J on both sides of ]MQ.
          h y K           2K+1

Try it here.

JavaScript (ES6), 104
Running total / running sample size. In Javascript, reading a value outside the bounds of an array gives undefined, that can be converted to 0 using ~~
(l,n,p=0)=>l.map((v,i)=>(p+=~l[i-n-1]-~l[i+n])/(n+1+Math.min(n,l.length-1-i,i)),l.map((v,i)=>p+=i<n&&v))

Ungolfed
(l, n) => {
    p = 0;
    for (i = 0; i < n; i++) p += v;
    r = [];
    for (i = 0; i < l.length; i++) {
        p += (l[i + n] || 0) - (i > n ? l[i - n - 1] : 0);
        r.push(p / Math.min(n, l.length - i - 1, i);
    }
    return r;
}

Test

f=(n,l,p=0)=>l.map((v,i)=>(p+=~l[i-n-1]-~l[i+n])/(n+1+Math.min(n,l.length-1-i,i)),l.map((v,i)=>p+=i<n&&v))

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

;[
  [1,[12,6,3,9],[9,7,6,6]]
, [1,[1,4,5,7,10],[2.5,3.333,5.333,7.333,8.5]]
, [1,[1,3,3,7,4,2,4,2],[2,2.333,4.333,4.667,4.333,3.333,2.667,3]]
, [2,[1,3,5,9,10,14,15,16,23],[3,4.5,5.6,8.2,10.6,12.8,15.6,17,18]]
, [3,[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]]
, [3,[1,2,3,4,5,6,7,8],[2.5,3,3.5,4,5,5.5,6,6.5]]
].forEach(t=>{
  var n=t[0],l=t[1],x=t[2],r=f(n,l)
  // verify (limited to 3 decimals)
  var ok = r.every((v,i)=>v.toFixed(3)==x[i].toFixed(3))

  console.log((ok?'OK   ':'Fail ')+n+' '+l+' -> '+r+' ('+x+')')
})

Haskell, 97 95 bytes
import Data.List
n#x|t<-2*n+1=[sum a/sum(1<$a)|a<-take t<$>take t(inits x)++tails x,length a>n]

Usage example: 2 # [1,3,5,9,10,14,15,16,23] -> [3.0,4.5,5.6,8.2,10.6,12.8,15.6,17.0,18.0].
How it works:
t<-2*n+1                      -- assign t to the maximum number of elements of a
                              -- of sublist
     take t(inits x)          -- build the sublists from t elements of the inits
                ++tails x     -- of the input and the tails of the input,
                              -- e.g. x=[1,2,3,4], t=3:
                              -- [[],[1],[1,2]] ++ [[1,2,3,4],[2,3,4],[3,4],[4],[]]
  a<-take t<$>                -- take at most t elements from every sublist
                ,length a>n   -- keep those with a minimum length of n+1
sum a/sum(1<$a)               -- calculate average, "sum(1<$a)" is the length of a

JavaScript (ES6), 82 bytes
code:
F=(n,a)=>a.map((e,i)=>(s=a.slice(i<n?0:i-n,i+n+1))&&s.reduce((l,c)=>l+c)/s.length)

test:

F=(n,a)=>a.map((e,i)=>(s=a.slice(i<n?0:i-n,i+n+1))&&s.reduce((l,c)=>l+c)/s.length)

document.write('
' +
  [
    [1, [12, 6, 3, 9], [9, 7, 6, 6] ],
    [1, [1, 4, 5, 7, 10], [2.5, 3.333, 5.333, 7.333, 8.5] ],
    [1, [1, 3, 3, 7, 4, 2, 4, 2], [2, 2.333, 4.333, 4.667, 4.333, 3.333, 2.667, 3] ],
    [2, [1, 3, 5, 9, 10, 14, 15, 16, 23], [3, 4.5, 5.6, 8.2, 10.6, 12.8, 15.6, 17, 18] ],
    [3, [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1] ],
    [3, [1, 2, 3, 4, 5, 6, 7, 8], [2.5, 3, 3.5, 4, 5, 5.5, 6, 6.5] ]
  ].map(t => {
    var [n, m, e] = t;
    var r = F(n, m);
    // verify to precision of 3 decimals
    var test = r.every((v, i) => v.toPrecision(3) === e[i].toPrecision(3));

    return 'F(' + n + ', [' + m + '])\t' + (test ? 'Pass' : 'Fail') +
      '\n\t{' + r + '} ' + (test ? '=' : '≠') + ' {' + e + '}';
  }).join('\n\n') +
  '
');

05AB1E, 30 bytes
ćU˜©ε®NX@iX·>£ÅAV®¦©YëN>X+£ÅA}

Input is: [n,[list_m]]
Output is: `[list_of_avgs]
Explanation
ćU˜©ε®NX@iX·>£ÅAV®¦©YëN>X+£ÅA}
ć                                  Head extract (get n)
 U                                 Save in variable X
  ˜                                Flat the list
   ©                               Save the list in register c
    ε                        }     Map
     ®                             Get the list from register c
      NX@                          Is the iteration greater than or equal to n
         i                         if true
                     ë             if false
          X·>                      push (n*2)+1
             £                     extract (n*2)+1 elements from head
              ÅA                   Arithmetic mean
                V                  Save the result in variable Y
                 ®                 Push the list from register c again
                  ¦                remove head (first element)
                   ©               save the new list in register c
                    Y              get variable Y (to apply on map returned value)
                      N>X+         push i+1+n  (i=iteration index, loop count)
                          £        extract i+1+n elements from head
                           ÅA      Arithmetic mean

Try it here :)

Wolfram Language (Mathematica), 46 bytes
Mean/@N@Partition[#2,UpTo[2#+1],1,{-#-1,#+1}]&

Try it online!


text:
Output quater-imaginary base numbers in binary
Write a function or program that outputs Quater-imaginary base displayed as binary digits. The number base is 2i, where i is the square root of -1. See Complex Number for more details on i. Each digit position can go from 0 to 3 (quaternary), as each real and imaginary part is -4 times as large as the previous real and imaginary part. The quaternary digits in binary are as follows: 0: 00, 1: 01, 2: 10 & 3: 11.
Breakdown of digit positions:
re   im       16 -8i  -4  2i   1 -0.5i, etc.
 4    0        1   0   3   0   0        (quaternary representation)
              01  00  11  00  00        (binary representation)

The number 100110000 is 1x16 + 3x-4 = 16 + -12 = 4.
re   im       16 -8i  -4  2i   1 -0.5i, etc.
 0    5        0   0   0   3   0   2    (quaternary representation)
              00  00  00  11  00 .10    (binary representation)

The number 1100.1 is 3x2i + 2x-0.5i = 6i + -i = 5i.
Your code will take a pair of numbers, which could be integer or floating point, and will output the complex number as a string of binary digits. The first number will be real, the second input number will be the imaginary value. A binary point must only be printed if there are non-zero number positions below 1 (i.e. if any of the positions for -0.5i, -0.25, 0.125i, etc. have a non-zero digit). Leading and trailing zeros are not allowed, except for a single zero digit immediately before the binary point if there are no other digits. The output must not start with a binary point (*00.1 - wrong, 0.1 - right, *.1 - wrong, *0.10 - wrong). You may assume that all input numbers will have finite binary representations.
Test numbers:
re   im            output
 0    0                 0
 1    0                 1
 2    0                10
 3    0                11
 4    0         100110000
-1    0             10011
-2    0             10010
-3    0             10001
 0    1               100.1
 0    2               100
 0    3              1000.1
 0    4              1000
 0   -1                 0.1
 0   -2           1001100
 0   -3           1001100.1
 3    4              1011
 4    3         100111000.1
 6   -9         101110010.1
-6    9       10011100110.1
-9   -6           1110111
 0.5 14.125   10011001101.001001

Note: The output of all integer values will end in .1 if the imaginary part is odd.
Standard code-golf.

This is a good challenge, but the explanation could be a whole lot clearer. You should clarify the process: it goes from complex numbers, to an interleaved quaternary representation, to a binary representation mapping 0 → 00, 1 → 01, 2 → 10, 3 → 11.

@Mauris I've made a whole bunch of edits to address your comment. Let me know if I can improve it further.

What if it is recurring in binary?

@LeakyNun It says right in the challenge: "You may assume that all input numbers will have finite binary representations."

JavaScript (ES6), 340 bytes
f=x=>[0,...x.toString(16)].reverse().map(d=>s=d<'.'?s:d<`0`?d+s.slice(0,-1):`${(c=+`0x${d}`+(c>>4)+m^m)>>2&3}${c&3}`+s,c=s='.',m=x<0?3:12)&&s
g=(s,t,n=s.indexOf`.`,m=t.indexOf`.`)=>n<m?g(0+s,t):n>m?g(s,0+t):t[s.length]?g(s+0,t):s.replace(/\d/g,(c,i)=>`${t[i]>>1}${t[i]&1}${c>>1}${c&1}`).replace(/^0+(\d)|\.?0*$/g,'$1')
(r,i)=>g(f(r),f(i/2))

f converts a number into base -4 (with trailing . if the number is an integer). g takes two base -4 numbers, pads them at both ends to the same length and . position, shuffles the digits together, converts everything from base 4 to base 2, then finally strips leading and trailing zeros.
Explanation: To represent the given complex number in modified-base 2i we need to represent the real part and half of the complex part (i.e. dividing the imaginary part by 2i) in base 2i² (i.e. -4), shuffle the digits together, and then convert them from base 4 to base 2. To represent a real number in base -4 we start with the base 4 conversion. Alternate digits have the correct sign (in the case of a positive number, these are the digits in the even positions; in the case of a negative number, these are the digits in the odd positions) but the remaining digits have the wrong sign and a correction needs to be applied. Examples:
 0 -> 000 -> 000 (no correction needed)
 4 -> 010 -> 130 }
 8 -> 020 -> 120 } (correction includes carry)
12 -> 030 -> 110 }

As you can see, the correction is 8 minus the original digit, mod 8. However a slightly more convenient calculation is the original digit, plus 3, xor 3 (indeed in 32-bit integer arithmetic we could simply write +0xCCCCCCCC^0xCCCCCCCC to convert the entire number in one go). Finally as the correction applies to alternate digits it is simpler to do an initial conversion to base 16 which automatically picks up pairs of base 4 digits, then correct using a factor of either 3 or 0xC as appropriate. It just remains to ignore the - sign.

Perl - 313 bytes
Since no-one has posted an answer yet I thought I'd kick it off myself.
$r=$ARGV[0];$i=$ARGV[1]/2;$m=1;while($r!=int($r)||$i!=int($i)){$c++;$m*=-1;$i*=4;$r*=4}while($r||$i){$r-=($d[$n++]=$r/$m%4)*$m;$i-=($d[$n++]=$i/$m%4)*$m;$m*=-4}$_=join("",map({sprintf"%02b",$_}reverse splice(@d,$c*2)))||"0";@d and$_.=".".join("",map({sprintf"%02b",$_}reverse@d));s/^0+1/1/;s/(\.\d*1)0+$/$1/;print

I'm sure there are lots of opportunities to golf this further.


text:
Putting square pegs into square holes
I was intrigued by the design of this graphic from the New York Times, in which each US state is represented by a square in a grid. I wondered whether they placed the squares by hand or actually found an optimal placement of squares (under some definition) to represent the positions of the contiguous states.

Your code is going to take on a small part of the challenge of optimally placing squares to represent states (or other arbitrary two-dimensional shapes.) Specifically, it's going to assume that we already have all the geographic centers or centroids of the shapes in a convenient format, and that the optimal representation of the data in a diagram like this is the one in which the total distance from the centroids of the shapes to the centers of the squares that represent them is minimal, with at most one square in each possible position.
Your code will take a list of unique pairs of floating-point X and Y coordinates from 0.0 to 100.0 (inclusive) in any convenient format, and will output the non-negative integer coordinates of unit squares in a grid optimally placed to represent the data, preserving order. In cases where multiple arrangements of squares are optimal, you can output any of the optimal arrangements. Between 1 and 100 pairs of coordinates will be given.
This is code golf, shortest code wins.
Examples:
Input: [(0.0, 0.0), (1.0, 1.0), (0.0, 1.0), (1.0, 0.0)]
This is an easy one. The centers of the squares in our grid are at 0.0, 1.0, 2.0, etc. so these shapes are already perfectly placed at the centers of squares in this pattern:
21
03

So your output should be exactly these coordinates, but as integers, in a format of your choice:
[(0, 0), (1, 1), (0, 1), (1, 0)]

Input: [(2.0, 2.1), (2.0, 2.2), (2.1, 2.0), (2.0, 1.9), (1.9, 2.0)]
In this case all the shapes are close to the center of the square at (2, 2), but we need to push them away because two squares cannot be in the same position. Minimizing the distance from a shape's centroid to the center of the square that represents it gives us this pattern:
 1
402
 3

So your output should be [(2, 2), (2, 3), (3, 2), (2, 1), (1, 2)].
Test cases:
[(0.0, 0.0), (1.0, 1.0), (0.0, 1.0), (1.0, 0.0)] -> [(0, 0), (1, 1), (0, 1), (1, 0)]
[(2.0, 2.1), (2.0, 2.2), (2.1, 2.0), (2.0, 1.9), (1.9, 2.0)] -> [(2, 2), (2, 3), (3, 2), (2, 1), (1, 2)]
[(94.838, 63.634), (97.533, 1.047), (71.954, 18.17), (74.493, 30.886), (19.453, 20.396), (54.752, 56.791), (79.753, 68.383), (15.794, 25.801), (81.689, 95.885), (27.528, 71.253)] -> [(95, 64), (98, 1), (72, 18), (74, 31), (19, 20), (55, 57), (80, 68), (16, 26), (82, 96), (28, 71)]
[(0.0, 0.0), (0.1, 0.0), (0.2, 0.0), (0.0, 0.1), (0.1, 0.1), (0.2, 0.1), (0.0, 0.2), (0.1, 0.2), (0.2, 0.2)] -> [(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1), (0, 2), (1, 2), (2, 2)]
[(1.0, 0.0), (1.0, 0.1), (1.0, 0.2), (1.0, 0.3)] -> [(1, 0), (0, 0), (2, 0), (1, 1)] or [(1, 0), (2, 0), (0, 0), (1, 1)]
[(3.75, 3.75), (4.25, 4.25)] -> [(3, 4), (4, 4)] or [(4, 3), (4, 4)] or [(4, 4), (4, 5)] or [(4, 4), (5, 4)]

Total distance from the centroids of shapes to the centers of the squares that represent them in each case (please let me know if you spot any errors!):
0.0
3.6
4.087011
13.243299
2.724791
1.144123

Just for fun:
Here's a representation of the geographic centers of the contiguous United States in our input format, at roughly the scale the Times used:
[(15.2284, 3.1114), (5.3367, 3.7096), (13.0228, 3.9575), (2.2198, 4.8797), (7.7802, 5.5992), (20.9091, 6.6488), (19.798, 5.5958), (19.1941, 5.564), (17.023, 1.4513), (16.6233, 3.0576), (4.1566, 7.7415), (14.3214, 6.0164), (15.4873, 5.9575), (12.6016, 6.8301), (10.648, 5.398), (15.8792, 5.0144), (13.2019, 2.4276), (22.3025, 8.1481), (19.2836, 5.622), (21.2767, 6.9038), (15.8354, 7.7384), (12.2782, 8.5124), (14.1328, 3.094), (13.0172, 5.3427), (6.142, 8.8211), (10.0813, 6.6157), (3.3493, 5.7322), (21.3673, 7.4722), (20.1307, 6.0763), (7.5549, 3.7626), (19.7895, 7.1817), (18.2458, 4.2232), (9.813, 8.98), (16.8825, 6.1145), (11.0023, 4.2364), (1.7753, 7.5734), (18.8806, 6.3514), (21.3775, 6.6705), (17.6417, 3.5668), (9.9087, 7.7778), (15.4598, 4.3442), (10.2685, 2.5916), (5.3326, 5.7223), (20.9335, 7.6275), (18.4588, 5.0092), (1.8198, 8.9529), (17.7508, 5.4564), (14.0024, 7.8497), (6.9789, 7.1984)]

To get these, I took the coordinates from the second list on this page and used 0.4 * (125.0 - longitude) for our X coordinate and 0.4 * (latitude - 25.0) for our Y coordinate. Here's what that looks like plotted:

The first person to use the output from their code with the above coordinates as input to create a diagram with actual squares gets a pat on the back!

I believe the last point in your second example should be (1, 2), not (1, 1).

Good catch, thanks!

Can you please also post the total of all the distances in each test case? This is certainly a nontrivial problem, and that would allow us to verify whether an alternative solution is actually also optimal.

PS: Have you actually tested that the given map is actualy a valid result of your optimization problem? Because intuitively I do not think it is.

I can add the total distances. The map the Times used is almost certainly not optimal.

The given map also includes the District of Columbia, which isn't a state.

Mathematica, 473 bytes
f@p_:=(s=Flatten@Round@p;v=Array[{x@#,y@#}&,n=Length@p];
  Do[w=Flatten[{g@#,h@#}&/@(b=Flatten@Position[p,x_/;Norm[x-p[[i]]]<=2,{1}])];f=Total[Norm/@(p-v)]+Total[If[#1==#2,1*^4,0]&@@@v~Subsets~{2}]/.Flatten[{x@#->g@#,y@#->h@#}&@@@w]/.Thread[Flatten@v->s];
    c=w∈Integers&&And@@MapThread[Max[#-2,0]<=#2<=Min[#+2,100]&,{Flatten@p[[b]],w}];s=Flatten@ReplacePart[s~Partition~2,Thread[b->Partition[w/.Last@Quiet@NMinimize[{f,c},w,MaxIterations->300],2]]]
    ,{i,n}]~Do~{2};s~Partition~2)

Before golfing:
f[p_]:=(n=Length@p;s=Flatten@Round@p;v=Array[{x[#],y[#]}&,n];
  Do[
    v2=Flatten[{x2[#],y2[#]}&/@(b=Flatten@Position[p,x_/;Norm[x-p[[i]]]<=2,{1}])];
    f2=Total[Norm/@(p-v)]+Total[If[#1==#2,1*^4,0]&@@@Subsets[v,{2}]]/.Flatten[{x[#]->x2[#],y[#]->y2[#]}&@@@v2]/.Thread[Flatten@v->s];
    c2=v2∈Integers&&And@@MapThread[Max[#-2,0]<=#2<=Min[#+2,100]&,{Flatten@p[[b]],v2}];
    s=Flatten@ReplacePart[s~Partition~2,Thread[b->Partition[v2/.Last@Quiet@NMinimize[{f2,c2},v2,MaxIterations->300],2]]];
    ,{i,n}]~Do~{2};
  s~Partition~2)

Explanation:
This optimization problem is not difficult to describe in Mathematica. Given a list of points p of length n,

the variables are x[i] and y[i]: v=Array[{x[#],y[#]}&,n],
the function to minimize is the total of displacements: f=Total[Norm/@(p-v)],
the constraints are: c=Flatten[v]∈Integers&&And@@(Or@@Thread[#1!=#2]&@@@Subsets[v,{2}]).

And, NMinimize[{f,cons},v,MaxIterations->Infinity] will give the result. But unfortunately, such straight forward scheme seems too complicated to converge.
To work around the problem of complexity, two techniques are adopted:

a large "interaction", If[#1==#2,1*^4,0]&, is used to avoid collision between points.
instead of optimize all variable at the same time, we optimize on every point with their neighbors in turn.

We start from an initial guess by rounding the points. When the optimizations are done one by one, collisions are expected to be resolved, and an optimized arrangement is established.
The final solution is at least good, if not optimal. (I believe :P)

Result:
The result of Just for fun is shown below. Dark green points are the inputs, gray squares are the outputs, and black lines shows the displacements.

The sum of displacements is 19.4595. And the solution is
{{15,3},{5,4},{13,4},{2,5},{8,6},{21,6},{20,5},{19,5},{17,1},{17,3},{4,8},{14,6},{15,6},{13,7},{11,5},{16,5},{13,2},{22,8},{19,6},{21,7},{16,8},{12,9},{14,3},{13,5},{6,9},{10,7},{3,6},{22,7},{20,6},{8,4},{20,7},{18,4},{10,9},{17,6},{11,4},{2,8},{19,7},{22,6},{18,3},{10,8},{15,4},{10,3},{5,6},{21,8},{18,5},{2,9},{18,6},{14,8},{7,7}}

Ha! I was just thinking of making a diagram like that last one. Well done.

Good work. Intuitively, your solution to the map of the US looks optimal to me.

Python 3, 877 bytes
This is not a correct implementation. It fails on the second of the "further test cases", producing a solution with a total distance of 13.5325, where the solution provided needs only 13.2433. Further complicating matters is the fact that my golfed implementation doesn't match the ungolfed one I wrote first...
However, nobody else has answered, and this is too interesting a challenge to let slip past. Also, I have a picture generated from the USA data, so there's that.
The algorithm is something like this:

Push all points to the nearest integer coordinates (hereafter called a "square").
Find the square with the greatest number of points.
Find the lowest-cost redistribution of those points to the nine-square neighbourhood of this one, excluding any squares that have already been processed in step 2.

The redistribution is limited to one point per square, unless that wouldn't provide enough squares (although even then, only one point will remain on this square).

Repeat from step 2 until no square has more than one point.
Locate each of the original points, in order, and output their squares, in order.

I have absolutely no proof of optimality for any part of this algorithm, just a strong suspicion that it'll provide "pretty good" results. I think that's what we called a "heuristic algorithm" back in my uni days...!
l=len
I,G,M=-1,101,150
d=lambda x,y,X,Y:abs(x-X+1j*(y-Y))
N=(0,0),(I,0),(0,I),(1,0),(0,1),(I,I),(1,I),(1,1),(I,I)
n=lambda p,e:[(x,y)for(x,y)in(map(sum,zip(*i))for i in zip([p]*9,N))if(x,y)not in e and I<x<G and I<y<G]
def f(p):
 g={};F=[];O=[I]*l(p)
 for P in p:
  z=*map(round,P),
  if z in g:g[z]+=[P]
  else:g[z]=[P]
 while l(g)<l(p):
  L,*P=0,
  for G in g:
   if l(g[G])>l(P):L,P=G,g[G]
  o=n(L,F);h=l(o)<l(P);c=[[d(*q,*r)for r in o]for q in P];r={}
  while l(r)<l(c):
   A=B=C=M;R=S=0
   while R<l(c):
    if R not in r:
     z=min(c[R])
     if z<A:B,A=R,z;C=c[R].index(A)
    R+=1
   while S<l(c):
    if S==B:
     v=0
     while v<l(c[S]):
      if v!=C:c[S][v]=M
      v+=1
    elif C<1or not h:c[S][C]=M
    S+=1
   r[B]=C
  for q in r:
   x,y=P[q],o[r[q]]
   if y==L or y not in g:g[y]=[x]
   else:g[y]+=[x]
  F+=[L]
 for G in g:
  O[p.index(g[G][0])]=G
 return O

And the result of running it on the USA data (thanks to a utility function that turns the results into SVG):

This is slightly worse than the one the ungolfed code produced; the only visible difference is that the top-rightmost square is one further to the left in the better one.

You get a pat on the back! Looks like I need to work on the scaling of the longitude to make this look a bit more like the diagram from the Times.

Out of curiosity, what total distance do you get for you USA map?

I probably should have asked that question of myself... because it's just shown me that my golfed implementation is worse than I thought. My original, ungolfed version got it in 20.9164, but the version I posted gave me 20.9987. *sigh*

MATLAB, 316 343 326 bytes
This one is a work in progress - it's not fast, but it is short. It seems to pass most of the test cases. Currently the one just for fun input of the map is running, but it is still going after 10 minutes, so...
function p=s(a)
c=ceil(a');a=a(:,1)+j*a(:,2);[~,p]=r(a,c,[],Inf);p=[real(p),imag(p)];end
function [o,p]=r(a,c,p,o)
if ~numel(c)
o=sum(abs(p-a));else
x=c(1)+(-1:1);y=c(2)+(-1:1);P=p;
for X=1:3
for Y=1:3
Q=x(X)+j*y(Y);if(x(X)>=0)&(y(Y)>=0)&all(Q~=P)
[O,Q]=r(a,c(:,2:end),[P;Q],o);
if(O<o) o=O;p=Q;disp(o);end
end;end;end;end;end

And in a somewhat more readable format:
function p=squaremap(a)
%Input format: [2.0, 2.1;2.0, 2.2;2.1, 2.0;2.0, 1.9;1.9, 2.0]

    c=ceil(a'); %Convert each point to the next highest integer centre
    a=a(:,1)+j*a(:,2); %Convert each 2D point into a complex number
    [~,p]=r(a,c,[],Inf); %Recurse!
    p=[real(p),imag(p)];
end

function [o,p]=r(a,c,p,o)
    if ~numel(c) %If we are as deep as we can go
        o=sum(abs(p-a)); %See what our overall distance is
    else
        x=c(1)+(-1:1);y=c(2)+(-1:1); %For each point we try 9 points, essentially a 3x3 square
        P=p;
        for X=1:3;
            for Y=1:3
                %For each point
                Q=x(X)+j*y(Y); %Covert to a complex number
                if(x(X)>=0)&(y(Y)>=0)&all(Q~=P) %If the point is not negative and has not already been used this iteration
                    [O,Q]=r(a,c(:,2:end),[P;Q],o); %Otherwise iterate further
                    if(O<o) o=O;p=Q;end %Keep updating the smallest path and list of points we have found
                end
            end
        end
    end
end

The input format is expected to be a MATLAB array, such as:
[2.0, 2.1;2.0, 2.2;2.1, 2.0;2.0, 1.9;1.9, 2.0]

Which is pretty close to the format in the question, which allows some leeway.
The output is in the same format as the input, an array where any given index corresponds to the same point in both the input and output.

Hmm, 8 hours and still running on the map one... this solution is guaranteed to find the most optimal, but it does it via brute force, so takes a very long time.
I've come up with another solution which is much faster, but like the other answer fails to find the most optimal in one of the test cases. Interestingly the map I get for my other solution (not posted) is shown below. It achieves an total distance of 20.72.


text:
Make a Surfin' Word
Your goal is to map a piece of text to a sine curve of the form:
a sin ( mx - b )
Where a and m are non-zero rational numbers, b is a rational number, and the calculations are in radians.
It doesn't really matter where the origin of your graph is, as long as you fit all the letters in your output. Also, it must be ASCII art, no graphical output.
You can take the equation input in as a string OR you can have a separate input for each parameter: a, m, and b.
Also
Examples:
Input: "A-well-a", "3sin(x)" or (3,1,0)
Output:

 -w
       a

A  e
      -
    l
     l

Explanation:
The index of the character is the x-value, and each line represents one y-value. So we take 3sin(x) of the appropriate indices and round them to the nearest integer to get our values:

  'A' : 3sin(0) = 0 => (0,0)
  '-' : 3sin(1) = 2.5244 => (1,3)
  'w' : 3sin(2) = 2.7279 => (2,3)
   etc. , to give you the rest of the word.

Input: "Everybody's", "3.5sin(x-2)" or (3.5,1,2)
Calculations:

3.5sin(x-2), x = 0,1,2,3,...,10
-3.1815,-2.9435,0,2.9435,3.1815,0.4935,-2.6495,-3.3565,-0.9765,2.2995,3.4615,

Output:

   ry     s
         '

  e  b
        y

Ev    od

Input: "heard", "4sin(2x)" or (4,2,0)
4sin(2x) [0-4] = 0,3.636,-3.028,-1.116,3.956,
Output:

 e  d

h
   r

  a

Input: "about","-5sin(x+1)" or (-5,1,-1)
-5sin(x+1) [0-4] : -4.205,-4.545,-0.705,3.785,4.795,
Output:

    t
   u

  o

a
 b

Input: "the word", "-2.4sin(0.5x-1.2)" or (-2.4,0.5,1.2)
-2.4sin(0.5x-1.2) [0-7] : 2.2368,1.5456,0.4776,-0.7104,-1.7208,-2.3136,-2.3376,-1.7904
Output:

th

  e

    word

See also

What is the input format? Do we need to parse the expression as a string?

@Zgarb Actually, if your language supports abstract mathematical functions, you can use that datatype for the expression.

so the input format is flexible? for instance, I could take the function input (in python) as "3*math.sin(x)"?

@quintopia No, only if your language natively supports mathematical expressions as a dataype (like MATLAB or Mathematica).

Otherwise, we have to take the input as a string exactly in the format you described?

@quintopia Ok, it finally hit me what people may have been wondering about, so I have loosened the input rules.

Can we accept the input just separated by spaces? word a m b
EDIT: just realized this would break with words that have spaces in them, so just "word" a m b?

@Juan yes that'll be alright

Related.

Dyalog APL, 37 bytes
{⍉↑v⌽¨⍵↑¨⍨v←(-∘1-⌈/)⌊.5+⎕×1○⎕-⍨⎕×⍳≢⍵}

Takes text as right argument, and then prompts for m, b, and a.

Python 2, 190 159 171 bytes
import math
a,b,c,d=input()
q=len(a)
s=""
m=int(abs(b)+.5)
for i in range(2*m*q+q):s+=""if i%q else"\n";s+=a[i%q]if i/q==-int(round(b*math.sin(i%q*c-d)))+m else" "    print s

Example usage:
$ python2 surfin2.py
"about",-5,1,-1

    t
   u

  o

a
 b

This can probably be golfed further, but I can't see how at the moment. I just wanted to see this question get at least one answer.
EDIT: Decently golfed once I saw how to do it in one pass. May have extra leading and trailing lines, but such was expressly allowed: "It doesn't really matter where the origin of your graph is, as long as you fit all the letters in your output."

Yeah, I wanted one too!

I also wrote a version that parses the expression from a string in the format you describe, but it was longer.

You can include it if you want.

Nah, it wasn't particularly well-golfed. I stopped once I realized it would be considerably longer.


text:
Toilet Paper Mysteries
Today you need to solve a very practical problem: How many loops do you need to have a certain number of sheets on your toilet paper roll? Let's look at some facts:

The diameter of a bare toilet paper cylinder is 3.8cm
The length of one sheet of toilet paper is 10cm.
The thickness of one sheet of toilet paper is 1mm.

Before you wrap around the cylinder the first time, it has a circumference in cm of 3.8*pi. Every time you wrap a sheet around the cylinder its radius increases by .1, therefore its circumference increases by .2*PI. Use this information to find out how many loops it takes to fit n sheets of toilet paper. (Note: Use an approximation of Pi that is at least as accurate as 3.14159).
Test Cases:
n=1:

10/(3.8*pi) = .838 loops

n=2:

(How many full loops can we make?) 1 full loop = 3.8*pi = 11.938.
(How much do we have left after the 1st loop?) 20 - 11.938 = 8.062
(How much of a 2nd loop does the remaining piece make?) 8.062/(4*pi) = .642 loops
Answer: 1.642 loops

n=3:

1st full loop = 3.8*pi = 11.938, 2nd full loop = 4*pi = 12.566
30 - 11.938 - 12.566 = 5.496
5.496/(4.2*pi) = .417
Answer: 2.417 loops

n=100 => 40.874

@FlagAsSpam Because in the first bullet point, I calculate the length of all the full loops.

Also, your calculations are only correct if the bare roll is 3.7cm in diameter. Only then the mean diameter of the first layer is 3.8cm.

@RainerP. o.k. I changed the language a bit. It should agree with what you're saying.

Phew! 1mm thick? Are you sure you're using toilet paper and not cardboard?

I'm getting 2.416499187… for n = 3. That doesn't round to 2.417. Is my calculation off somewhere?

@Pietu1998 It's because when doing it by hand I rounded to 3 decimal places.

So our programs do not have to round?

@CᴏɴᴏʀO'Bʀɪᴇɴ Nope, less rounding is better.

@DigitalTrauma Clearly you don't know about triple-ply :p

Under the assumption that the toilet paper does not make steps but continuously increases the radius, you can get a closed form approximation to requested result. Is this good enough? nloops = sqrt(n+11.34)*0.0564189 - 0.19

@flawr Sorry, no.

Aside from the golfing aspect, I find this question incredibly amusing and even useful, lol. I wouldn't be surprised if this became a programming homework question and we see SO littered with this question!

Proposed test case: 100 -> 40.874

Triple-ply cardboard?! Now that's thick!

I'm not going to lie, I came here because I was expecting something else when I saw "toilet paper mysteries"...

@Ashwin Yeah, that was part off the idea :p

I can't get this shit to work. I think I need to try something different. :)

They see me rolling, they be knockin'.

It is literally a shit challenge.

Pyth, 27 23 bytes
+fg0=-QJc*.n0+18T50)cQJ

Try it online. Test suite.
Explanation
                            Q = input number (implicit)
 f                 )        increment T from 1, for each T:
             +18T             add 18 to T, get radius
         *.n0                 multiply by pi to, get half the circumference
        c        50           divide by 50, get circumference in sheets
       J                      save it to J
    =-Q                       decrement Q by it
  g0                          use this T if Q is now <= 0
+                           add
                     Q        Q (now <= 0)
                    c J       divided by J (the last circumference)
                            and print (implicit)

explanation, please?

@CᴏɴᴏʀO'Bʀɪᴇɴ Added. Explaining Pyth is always so much fun.

Your explanation looks like a potential output for Surfin' Word

Haskell, 59 46 44 bytes
A scale factor of 5/pi is applied, so that a paper cylinder has a circumference of 19,20,21... cm and a sheet is 50/pi cm.
Saved 2 bytes thanks to xnor, by using an unnamed function.
x!s|s>x=1+(x+1)!(s-x)|1>0=s/x
(19!).(50/pi*)

A pretty recursive method. Note that unnamed functions are allowed even when you have other lines (despite Haskell not supporting it), so the last line can be pointfree as (19!).(50/pi*).

Wow, blows my approach out of the water!

Jelly, 29 27 26 bytes
R+18×3.6°µ0;+\³_÷µḞi0©ị+®’

Try it online!

Haskell, 97 bytes
p&((m,x):(n,y):z)|y
0=m+(p-x)/(y-x)
t=(&zip[0..](scanl(+)0$map(*pi)[0.38,0.4..]))

Might be able to golf it further by moving the filtering from the & operator into a takeWhile statement, but given that it's not a golfing language this seems relatively competitive.
Explanation
The stream of lengths of toilet paper that comprise full loops are first calculated as scanl (+) 0 (map (* pi) [0.38, 0.4 ..]]. We zip these with the number of full revolutions, which will also pick up the type Double implicitly. We pass this to & with the current number that we want to calculate, call it p.
& processes the list of (Double, Double) pairs on its right by (a) skipping forward until snd . head . tail is greater than p, at which point snd . head is less than p.
To get the proportion of this row that is filled, it then computes (p - x)/(y - x), and adds it to the overall amount of loops that have been made so far.

C++, 72 bytes
float f(float k,int d=19){auto c=d/15.9155;return k<c?k/c:1+f(k-c,d+1);}

I used C++ here because it supports default function arguments, needed here to initialize the radius.
Recursion seems to produce shorter code than using a for-loop. Also, auto instead of float - 1 byte less!

You almost fooled me, using d for the radius...

Not sure if you were aware, but this was the 69,420th post on CGCC!

Wow, I had no idea the number 69420 had any special significance! Too bad I cannot relate it to either C++ or toilet paper.

Lua, 82 bytes
n=... l,c,p=10*n,11.938042,0 while l>c do l,c,p=l-c,c+.628318,p+1 end print(p+l/c)

Not bad for a general-purpose language, but not very competitive against dedicated golfing languages of course.  The constants are premultiplied with pi, to the stated precision.

OP wasn't specific about what kind of input to accept, so I left out the initialization of n, but the rest would've run as-is (as-was?).  In any case, now it takes n from the command line; e.g. for 3 sheets run it as lua tp.lua 3.

It's not precisely a rule of this question, but a general policy. Unless the question says otherwise, hardcoding the input makes the submission a snippet, which are not allowed by default. More information about site-wide defaults can be found in the code golf tag wiki.

I knew about the "whole program or function" part but didn't know that "hardcoding the input makes the submission a snippet".  Thanks for clarifying.  I think this would actually be longer as a function!

C, 87 bytes
float d(k){float f=31.831*k,n=round(sqrt(f+342.25)-19);return n+(f-n*(37+n))/(38+2*n);}

Uses an explicit formula for the number of whole loops:
floor(sqrt(100 * k / pi + (37/2)^2) - 37/2)

I replaced 100 / pi by 31.831, and replaced floor with round, turning the annoying number -18.5 to a clean -19.
The length of these loops is
pi * n * (3.7 + 0.1 * n)

After subtracting this length from the whole length, the code divides the remainder by the proper circumference.

Just to make it clear - this solution has complexity O(1), unlike many (all?) other solutions. So it's a bit longer than a loop or recursion.

JavaScript, 77 bytes
function w(s,d,c){d=d||3.8;c=d*3.14159;return c>s*10?s*10/c:1+w(s-c/10,d+.2)}

function w(s,d,c){d=d||3.8;c=d*3.14159;return c>s*10?s*10/c:1+w(s-c/10,d+.2)}

function wraps(sheets, diameter, circumference) {
    // Default the value of diameter
    diameter = diameter || 3.8;
    circumference = diameter * 3.14159;
    if (circumference > sheets * 10)
        return sheets * 10 / circumference;
    return 1 + wraps(sheets - circumference / 10, diameter + .2);
}

document.getElementById('text').innerHTML = "0 => " + w(0)
+ "\n1 => " + w(1)
+ "\n2 => " + w(2)
+ "\n3 => " + w(3)
+ "\n100 => " + w(100)

+ "\n\n0 => " + wraps(0)
+ "\n1 => " + wraps(1)
+ "\n2 => " + wraps(2)
+ "\n3 => " + wraps(3)
+ "\n100 => " + wraps(100);

Welcome to PPCG! If you'd like, you can use JavaScript ES6, and get this to 55 bytes: w=(s,d=3.8,c=d*3.14159)=>c>s*10?s*10/c:1+w(s-c/10,d+.2)

C#, 113 bytes
double s(int n){double c=0,s=0,t=3.8*3.14159;while(n*10>s+t){s+=t;c++;t=(3.8+c*.2)*3.14159;}return c+(n*10-s)/t;}

Ungolfed:
double MysteryToiletPaper(int sheetNumber)
    {
        double fullLoops = 0, sum = 0, nextLoop = 3.8 * 3.14159;

        while (sheetNumber * 10 > sum + nextLoop)
        {
            sum += nextLoop;
            fullLoops++;
            nextLoop = (3.8 + fullLoops * .2) * 3.14159;
        }

        return fullLoops + ((sheetNumber * 10 - sum) / nextLoop);
    }

Results:

for 1 sheet

0,837658302760201

for 2 sheets

1,64155077524438

for 3 sheets

2,41650110749198

for 100 sheets

40,8737419532946

PHP, 101 bytes
<?$p=pi();$r=3.8;$l=$argv[1]*10;$t=0;while($r*$p<$l){$t+=($l-=$r*$p)>0?1:0;$r+=.2;}echo$t+$l/($r*$p);

Ungolfed
<?
$pi = pi();
$radius = 3.8;
$length_left = $argv[1]*10;
$total_rounds = 0;
while ($radius * $pi < $length_left) {
    $total_rounds += ($length_left -= $radius * $pi) > 0 ? 1 : 0;
    $radius += .2;
}
echo $total_rounds + $length_left/( $radius * $pi );

I feel like this could be done a little shorter, but I ran out of ideas.

Python 3, 114 109 99 bytes
This function tracks the circumference of each layer until the sum of the circumferences is greater than the length of the number of sheets. Once this happens the answer is:

One less than the number of calculated layers + length of leftover sheets / circumference of most recent layer

def f(n):
    l,s=0,[]
    while sum(s)<n:s+=[.062832*(l+19)];l+=1
    return len(s)-1+(n-sum(s[:-1]))/s[-1]

Update

-10 [16-05-09] Optimized my math-ing
-5 [16-05-04] Minimized number of lines

JavaScript, 44 bytes
w=(i,d=19,c=d/15.9155)=>i<c?i/c:1+w(i-c,d+1)

I used anatolyg's idea and translated the code into JavaScript.

><>, 46 44 bytes
a*0"Gq",:&a9+*\
?\:{$-{1+{&:&+>:{:})
;>{$,+n

Expects the number of sheets to be present on the stack at program start.
This uses an approximation of pi of 355/113 = 3.14159292..., storing pi/5 in the register. The current iteration's circumference lives on the stack, and pi/5 is added on each iteration.
Edit: Refactored to store the circumference directly - previous version stored pi/10 and started the diameter as 38, which was 2 bytes longer.

PHP, 79 bytes
function p($s,$d=3.8){$c=$d*pi();return $c>$s*10?$s*10/$c:1+p($s-$c/10,$d+.2);}

Run code in Sandbox
I have pretty much only translated Ross Bradbury's answer for JavaScript into a PHP function, which is also recursive.

Please don't just copy another answer into another language.


text:
The pirate world's rules of distribution
There is an existing "game" where pirates rationally divide gold coins according to certain rules. Quoting from Wikipedia:

There are 5 rational pirates, A, B, C, D and E. They find 100 gold coins. They must decide how to distribute them.
The pirates have a strict order of seniority: A is superior to B, who is superior to C, who is superior to D, who is superior to E.
The pirate world's rules of distribution are thus: that the most senior pirate should propose a distribution of coins. The pirates, including the proposer, then vote on whether to accept this distribution. In case of a tie vote the proposer has the casting vote. If the distribution is accepted, the coins are disbursed and the game ends. If not, the proposer is thrown overboard from the pirate ship and dies, and the next most senior pirate makes a new proposal to begin the system again.
Pirates base their decisions on three factors. First of all, each pirate wants to survive. Second, given survival, each pirate wants to maximize the number of gold coins each receives. Third, each pirate would prefer to throw another overboard, if all other results would otherwise be equal. The pirates do not trust each other, and will neither make nor honor any promises between pirates apart from a proposed distribution plan that gives a whole number of gold coins to each pirate.

Challenge
Take as input an integer n, 1<=n<=99, where n is the number of pirates - and output the distribution of coins, starting with the first pirate.
Test cases (first line is input; the second output):
1
100

2
100 0

3
99 0 1

5
98 0 1 0 1

This is code-golf, so the shortest solution in bytes wins.

I think this was asked before, but I wouldn't know where to find it.

@feersum http://codegolf.stackexchange.com/questions/54235/famous-greedy-pirates-problem (deleted)

Args[0]. Java now has a reason to use this.

I wouldn't remove it just yet, but the challenge is rather easy. You basically have to print X, 0, 1, 0, ..., where X is chosen so that the sum is 100.

Why limit n < 100? Over-staffed, under-gilded pirate ships need distributional help as well.

Surely rational pirates would simply distribute 100/n coins to each pirate.

@Neil that is a terrible idea.  If that is what "rational" pirates do, then all pirate other than A will try to kill A so that they get $100/(n-1)$ instead.  This will quickly kill off everyone except the last two pirates.

Jelly, 11 10 bytes
R%2ḊµSȷ2_;

Try it online! or verify all test cases at once.
How it works
For input n, the task boils down to creating the list x, 0, 1, 0, … of length n whose sum is 100.
R%2ḊµSȷ2_;  Main link. Input: n

R           Yield [1, 2, ..., n].
 %2         Replace each integer by its parity. Yields [1, 0, 1, 0, ...].
   Ḋ        Dequeue; remove the first 1. This yields the list a = [0, 1, ...].
    µ       Begin a new, monadic link. Argument: a
     S      Compute the sum of a.
      ȷ2_   Subtract the sum from 100. (ȷ2 is 1e2 in Python syntax)
         ;  Prepend the difference to a.

Python, 33 bytes
lambda n:([-n/2+101]+[0,1]*n)[:n]

Computes the first value, appends some 0, 1, 0, 1..., truncates to length n.
Note that -n/2+101 can't be shortened to 101-n/2 because unary and binary - have different precedence: the former is parsed as (-n)/2 and the latter as 101-(n/2).
Recursion was much longer (45):
f=lambda n,i=100:1/n*[i]or f(n-1,i-n%2)+[n%2]

MATL, 12 bytes
:2\ts_101+l(

This uses current version (9.2.2) of the language/compiler, which is earlier than this challenge.
Example
>> matl :2\ts_101+l(
> 5
98  0  1  0  1

Explanation
:         % implicitly input number "n". Generate vector [1, 2, ..., n]
2\        % modulo 2. Gives [1, 0, 1, ...]
ts        % duplicate and compute sum
_101+     % negate and add 101
l(        % assign that to first entry of [1, 0, 1, ...] vector. Implicitly display

Pyth, 13 bytes
+-100sJ%R2tQJ

Test suite.

Python, 62 58 bytes
EDIT: Glad I made it a one-liner. But I lose for Python. Therefore, this is just for reference. Thanks @Zgarb
def x(i):n=[~j%2for j in range(i)];n[0]=101-sum(n);print n

It takes the input, creates a list pf parity of all numbers from 1 to i. Then sets the first element in i to 101-sum(n) and prints.
Try it here

Javascript ES6, 45 bytes
a=>[...Array(a)].map((x,y)=>y?--y%2:202-a>>1)

Thanks to @Neil for 1 byte saved!

202-a>>1 saves a byte.

, 14 chars / 26 bytes
⩥ï⒨?‡$%2:ỉ-ï»1

Try it here (Firefox only).
Not bad, but not good either...
Explanation
⩥ï⒨?‡$%2:ỉ-ï»1 // implicit: ï=input, ṥ=101
⩥ï⒨            // map over a range [0,ï) and return:
    ?‡$%2       // (if mapitem>0) then ($-1) mod 2
         :ỉ-ï»1 // (else) 202-ï>>1
                // implicit output

Seriously, 23 17 bytes
EDIT: Thanks @quintopia
,R`2@%`M;Σ2╤u-0(T

Uses the same approach as my Python answer, but I do the modulo 2 using mapping, and several times, I rotate my stack.
Explanation:
This code pushes input (I will call it i). Next pushes range(1,i+1) and makes a function.  Then pushes 2, rotates stack, and finally takes modulo.
Next, map this function onto the range iterable. This gives the parity of each element in the list.
Finally, duplicates the stack, sums the parity list, push 2, 10^2, and 100+1, and subtracts the sum (let me call this value n). Next the code pushes 0, rotates the stack by 1, and sets the list's index 0 element to n. The resulting list is implicitly printed.

This should be no more than 17 bytes: ,R`2@%`M;Σ2╤u-0(T

Japt, 14 bytes
Yet another challenge where I find myself wishing for a built-in I had just considered adding...
1oU mv u#Ê-UÁ1

Try it online!
1oU mv u#Ê-UÁ1  // Implicit: U = input integer
1oU             // Create the range [1, U).
    mv          // Map each item to 1 if even, 0 otherwise.
       u        // Unshift (add to the beginning of the array)
        #Ê-UÁ1  //  the char code of Ê (202), minus U >>> 1 (floor of U / 2).

Actionscript 3, 87 bytes
function x(n){var l=[],i=1;for (l[0]=int(101-n/2);i<n;){l[i]=++i%2;}return l.join(" ")}
It's not the best golfing language, but I enjoy posting as3 answers.

05AB1E, 12 bytes (Non-comp)
<LÈDOTns-s)˜

Try it online!

s)˜ can be ¸ì.

Japt -S, 8 bytes
ov hL-Uz

Try it

Perl 51 49 44 bytes
$,=$";@"=map{$i++%2}2..<>;say 100-(@">>1),@"

Need the following perlrun options -E
$ perl -E'$,=$";@"=map{$i++%2}2..<>;say 100-(@">>1),@"'<<<5
98
0
1
0
1

QBIC, 28 25 bytes
:?100-(a-1)'\`2[2,a|?b%2

Explanation
:               Get command line parameter, assign to 'a'
                Determine the part of the treasure for the crew:
      (a-1) \ 2 Integer Divide 'a'-1 by 2. The -1 compensates for even cases.
           ' `  Make \ a direct command for QBasic instead of substituting it for ELSE.
?100-           Print 100 coins, minus the crew-share --> Captain's booty.
[2,a|           FOR b=2; b <= a; b++; ie for every other crew member
?b%2            Give every odd crewman a coin.
                [FOR loop implicitly closed by QBIC]

Arn, 13 bytes
¾*†^…wu½►♦ž]#

Try it!
Explained
Unpacked: [101-:^:-_{!}->
[           Begin sequence
          --First entry--
     101    Literal `101`
 -          Subtract
   :^       Ceiling
     :-     Halve
       _    A variable ≡ STDIN
          --Other entries--
    {       Block
      !     Boolean NOT
        _   Implied; last entry
    }       End block
  ->        To final length of
    _       Implied
]           End sequence; implied

I am pretty sure this can be golfed further, but I'm leaving it here for now.

Husk, 13 bytes
Ṡ:o`-100Σt↑İ¬

Try it online!