答:
MATLAB, <s>81</s> <s>72</s> 69 bytes

```<code>@()image(shiftdim(reshape(evalin('base','char(ans)'),3,1,23)/255,1.))
</code>```

This creates an anonymous function which can be pasted into the command window and run using ans(). When run this creates a 23-pixel image (a prime) therefore the most square representation is a simple array of pixels.

Explanation

When pasted into the command window, the anonymous function will automatically assign itself to the variable ans. Then from within the anonymous function, we use:

```<code>evalin('base', 'char(ans)')
</code>```

which evaluates char(ans) within the namespace of the command window rather than within the local namespace of the anonymous function. It is therefore able to convert the anonymous function itself into a string representation.

Then we have the following operations which are more straightforward:

```<code>%// Reshape the result into a 3 x 1 x 23 matrix where the first dimension is RGB
%// due to column-major ordering of MATLAB
R = reshape(string, 3, 1, 23);

%// Divide the result by 255. This implicitly converts the char to a double
%// and in order for RGB interpreted properly by MATLAB, doubles must be
%// normalized between 0 and 1.
R = R / 255;

%// Shift the dimensions to the left 1 to move the RGB channel values into
%// the third dimension. Note the extra decimal point. This is because it
%// is far shorter to lengthen the code by one byte than to pad the string
%// to give us a length divisible by 3
R = shiftdim(R, 1.);

%// Display the RGB image
image(R);
</code>```

Title: Compress your code in an image

Body:
MATLAB, <s>81</s> <s>72</s> 69 bytes

@()image(shiftdim(reshape(evalin('base','char(ans)'),3,1,23)/255,1.))

This creates an anonymous function which can be pasted into the command window and run using ans(). When run this creates a 23-pixel image (a prime) therefore the most square representation is a simple array of pixels.

Explanation

When pasted into the command window, the anonymous function will automatically assign itself to the variable ans. Then from within the anonymous function, we use:

evalin('base', 'char(ans)')

which evaluates char(ans) within the namespace of the command window rather than within the local namespace of the anonymous function. It is therefore able to convert the anonymous function itself into a string representation.

Then we have the following operations which are more straightforward:

%// Reshape the result into a 3 x 1 x 23 matrix where the first dimension is RGB
%// due to column-major ordering of MATLAB
R = reshape(string, 3, 1, 23);

%// Divide the result by 255. This implicitly converts the char to a double
%// and in order for RGB interpreted properly by MATLAB, doubles must be
%// normalized between 0 and 1.
R = R / 255;

%// Shift the dimensions to the left 1 to move the RGB channel values into
%// the third dimension. Note the extra decimal point. This is because it
%// is far shorter to lengthen the code by one byte than to pad the string
%// to give us a length divisible by 3
R = shiftdim(R, 1.);

%// Display the RGB image
image(R);


问:
KOTH: TNT Run Challenge
This was inspired by a Minecraft mini-game. The rules are pretty simple: you run and jump around, and every block you step on disappears once you've stepped on it. The goal is to be the last one left.

Your bot should be a complete program. It should accept input as a command line argument. The input will be a map of the "world"; here is an example:

```<code>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxx xxxxxxxxxxxxxxxxxxxxxxxxxxx
xxx xxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxx x xxxxxxxxxxxxx@xxxxxxxxxxx
xxxxxx1xxxxxxxxxxxxx xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx
xxxxxxxxxx           xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx
xxxxxxxxxxxxxxxxx x x xxxxxxxxxx
xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx
xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxx xxx xx3xxxxxxxxxx
xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx  x
xxxxxxxxxxxxxxxxxxxxxxxxxxx   xx
xxxxxxxxxxxxxxxxxxxxxxxxx      2
xxxxxxxxxxxxxxxxxxxxxxx
</code>```

The legend is as follows:

x: solid block

 : empty air

@: your bot

1,2,3,4,5,6,7,8,9,0: other bots

Your bot should output your move as a pair of integers. Example: -1, 2 will move 1 block to the left and 2 blocks down (coordinates origin is in the top left corner).

You may move up to four blocks, manhattan distance, from your current location. If you try to move further than that, the move is invalid. Any move that would move you past the edge will put you on the edge instead. Invalid moves will be ignored.

Once you land on a block it is removed; if you remain on the same block next turn you will fall. Two bots may land on the same block on the same turn and both survive; if this happens, both bots will only see themselves and not the other bot.

If you need to store files for persistence, please do so in a folder with the name of your bot. You may not read other bots' persistent data if any exists.

The match controller is available at https://paste.ee/p/Xf65d.

Please use languages that can be run on a standard Linux or OSX install.

Current results (100 rounds):

```<code>JumpBot                   31
LookBot                   27
ShyBot                    26
Slow Bot                  15
KnightBot                 2
Moat Builder              0
UpBot                     0
Random Bot                0
</code>```

答:
ShyBot (Python)

This bot really doesn't like other bots and will try to keep itself away if possible. ShyBot is also really careful about where it steps; it won't even step on other bots. However, ShyBot still looses often which makes insecure.

```<code>import sys
map = sys.argv[1]
map = map.split("\n")
map = [list(r) for r in map]

def find(map,bot):
   r,c=-1,-1
   for row in range(len(map)):
      for col in range(len(map[row])):
         if map[row][col]==bot:
            r,c=row,col
   return r,c

mer,mec=find(map,'@')
bots=[(mer,mec)]

for b in range(10):
   r,c=find(map,str(b))
   if r != -1:
      bots.append((r,c))

avg=[0,0]

for b in bots:
   avg[0]+=b[0]
   avg[1]+=b[1]

avg[0] = avg[0]/len(bots)
avg[1] = avg[1]/len(bots)

def get(map,r,c):
   if r<0 or r>=len(map) or c<0 or c>=len(map[r]):
      return ' '
   return map[r][c]

def dist(r1,c1,r2,c2):
   return abs(r1-r2)+abs(c1-c2)

pos=[]
for r in range(-4,5):
   for c in range(-4,5):
      if abs(r)+abs(c)<=4 and get(map,mer+r,mec+c)=='x':
         pos.append((r,c))

if len(pos)==0:
   bestr,bestc=0,0
else:
   bestr,bestc=pos[0]

for r,c in pos:
   if dist(mer+r,mec+c,avg[0],avg[1])>dist(mer+bestr,mec+bestc,avg[0],avg[1]):
      bestr,bestc=r,c

print(str(bestc)+" "+str(bestr))
</code>```

ContentLicense: CC BY-SA 3.0

Title: KOTH: TNT Run Challenge

Body:
ShyBot (Python)

This bot really doesn't like other bots and will try to keep itself away if possible. ShyBot is also really careful about where it steps; it won't even step on other bots. However, ShyBot still looses often which makes insecure.

import sys
map = sys.argv[1]
map = map.split("\n")
map = [list(r) for r in map]

def find(map,bot):
   r,c=-1,-1
   for row in range(len(map)):
      for col in range(len(map[row])):
         if map[row][col]==bot:
            r,c=row,col
   return r,c

mer,mec=find(map,'@')
bots=[(mer,mec)]

for b in range(10):
   r,c=find(map,str(b))
   if r != -1:
      bots.append((r,c))

avg=[0,0]

for b in bots:
   avg[0]+=b[0]
   avg[1]+=b[1]

avg[0] = avg[0]/len(bots)
avg[1] = avg[1]/len(bots)

def get(map,r,c):
   if r<0 or r>=len(map) or c<0 or c>=len(map[r]):
      return ' '
   return map[r][c]

def dist(r1,c1,r2,c2):
   return abs(r1-r2)+abs(c1-c2)

pos=[]
for r in range(-4,5):
   for c in range(-4,5):
      if abs(r)+abs(c)<=4 and get(map,mer+r,mec+c)=='x':
         pos.append((r,c))

if len(pos)==0:
   bestr,bestc=0,0
else:
   bestr,bestc=pos[0]

for r,c in pos:
   if dist(mer+r,mec+c,avg[0],avg[1])>dist(mer+bestr,mec+bestc,avg[0],avg[1]):
      bestr,bestc=r,c

print(str(bestc)+" "+str(bestr))


问:
Grow a Treemote!
This is my friend Thomas. He is half tree, half emoticon.

```<code>|    |
| :D |
|    |
</code>```

He is lonely. Let's make him some friends!

Given a text-based emoticon as input (e.g. ಠ_ಠ, :P, >_>, not , , or ), output the corresponding treemote.

A treemote's length is how many characters it is lon (basically most builtin length functions for strings). So ಠ_ಠ has length 3.

The syntax for a treemote of length n is as follows:

```<code>|< 2+n spaces>| * ceil(n/2)
| <emote> | (note the spaces)
|< 2+n spaces>| * ceil(n/2)
</code>```

So any treemote of length 3 would look like:

```<code>|     |
|     |
| ಠ_ಠ |
|     |
|     |
</code>```

He has ceil(n/2) newline separated trunk segments on either side, each with 2 + n spaces inside.

Challenge: Given the text-based emoticon, output the corresponding treemote.

Other rules:

This is code-golf, which means I want you to write short code.

Standard loopholes disallowed.

You must support non-ascii characters unless your language can't handle them.

Test Cases:

```<code>^_^

|     |
|     |
| ^_^ |
|     |
|     |

\o/

|     |
|     |
| \o/ |
|     |
|     |

(✿◠‿◠)

|        |
|        |
|        |
| (✿◠‿◠) |
|        |
|        |
|        |

D:

|    |
| D: |
|    |

( ͡° ͜ʖ ͡°)

|             |
|             |
|             |
|             |
|             |
|             |
| ( ͡° ͜ʖ ͡°) |
|             |
|             |
|             |
|             |
|             |
|             |
</code>```

答:
Ruby, 57 bytes

Uses integer division tricks and takes advantages of the quirks in Ruby's puts function.

```<code>->e{s=e.size+1;puts k=[?|+' '*-~s+?|]*(s/2),"| #{e} |",k}
</code>```

Title: Grow a Treemote!

Body:
Ruby, 57 bytes

Uses integer division tricks and takes advantages of the quirks in Ruby's puts function.

->e{s=e.size+1;puts k=[?|+' '*-~s+?|]*(s/2),"| #{e} |",k}


问:
Actually Integer Metagolf

Background

Actually (the successor to Seriously) is a stack-based imperative golfing language I created in November of 2015. Like many other golfing languages, it has one-byte commands that perform different functions based on the contents of the stack. One of its specialties is mathematics - it has a wide variety of mathematics-based commands. However, in order to perform math operations, you have to put (one or more) numbers on the stack. Pushing a specific value in as few bytes as possible is tricky, because there are many different options. In this challenge, you will be doing exactly that: representing numbers (specifically, integers) in Actually in as few bytes as possible.

The Challenge

Given an integer N as input, output valid Actually code that results in N being pushed to the stack.

The input will be within the range of a 32-bit signed two's complement integer (i.e. the integers in the inclusive range [-2147483648, 2147483647]).

The result must be an integer (not a float, string, list, or function), and must be on top of the stack.

You may not make any assumptions about the contents of the stack (like whether or not it is empty). Any existing values on the stack must not be modified or rearranged.

The latest commit of Actually at the time I am writing this challenge is to be used. If I make bug fixes or performance enhancements (or any other minor change that does not remove or change functionality of the allowed commands), I will update this version.

Your solution must do at least as well as the trivial solution (prepend : to the input to make a numeric literal).

Your score will be the sum of the lengths of the trivial solutions minus the sum of the lengths of the outputs for the selection of 1000 32-bit signed two's complement integers used for scoring, which can be found below. I reserve the right to change the scoring integers at any time, if there is a need (such as optimizing for the test cases or the test cases not being thorough enough).

Solutions must output a valid answer within 30 seconds for each input. Timing will be done on a standard free Cloud9 workspace.

Commands

For simplicity, only 141 out of the (currently) 208 commands may be used, and many overloads of those 141 that are unrelated to number-crunching have been removed. Here is the list of allowed commands (format is <hex code> (<symbol>): <descriptions of functions based on stack values and types>:

```<code>0B (♂): take the next command and map it over the top of the stack (for example, ♂A is equivalent to `A`M)
1F (▼): pop a,b: push b//gcd(a,b),a//gcd(a,b); pop [a]: push [x//gcd([a]) for x in [a]]
20 ( ): push the # of elements on the stack (push len(stack))
21 (!): pop a: push a! (factorial(a))
22 ("): string literal, reads until next " and pushes value onto stack. An implied " is present at EOF if needed.
23 (#): pop a: push list(a)
25 (%): pop a,b: push a%b
26 (&): pop a,b: push a & b (bitwise AND)
27 ('): pushes next character onto stack as character literal (length-1 string)
28 ((): rotates stack right by 1
29 ()): rotates stack left by 1
2A (*): pop a,b: push a*b; pop a,[b] or [b],a: apply a* to each element in the array; pop [a],[b]: push dot product of [a] and [b] (sum([a[i]*b[i] for i in len(a)])) (shorter is padded with 0s)
2B (+): pop a,b: push a+b; pop [a],[b]: push [a][b] (append [b] to [a]); pop a,[b] or [b],a: apply a+ to each element in the array
2D (-): pop a,b: push a-b; pop [a],[b]: push [a]-[b] (all elements of [a] not in [b])
2F (/): pop a,b: push a/b (float division); pop [a]: rotate [a] right by 1, push [a]
30 (0): push 0
31 (1): push 1
32 (2): push 2
33 (3): push 3
34 (4): push 4
35 (5): push 5
36 (6): push 6
37 (7): push 7
38 (8): push 8
39 (9): push 9
3A (:): numeric literal delimiter: pushes the longest string of characters in '0123456789+-.ij' as a numeric
3B (;): pop a: push a,a (duplicates top element)
3C (<): pop a,b: push 1 if a<b else 0
3D (=): pop a,b: push 1 if a==b else 0
3E (>): pop a,b: push 1 if a>b else 0
40 (@): pop a,b: push a,b (rotate top 2 elements)
41 (A): pop a: push abs(a)
43 (C): pop a: push cos(a)
44 (D): pop a: push a-1; pop [a]: push stddev([a])
45 (E): pop a: push erf(a); pop [a],b: push [a][b] (bth item in [a])
46 (F): pop a: push Fib(a) (Fib(0)=0, Fib(1)=Fib(2)=1); pop [a]: push a[0]
48 (H): pop [a],b: push [a][:b]
49 (I): pop a,b,c: push b if a is truthy, else push c
4B (K): pop a: push ceil(a)
4C (L): pop a: push floor(a)
4D (M): pop f,[a], execute f for each element in [a], using the element as a temporary stack, push [a] (similar to map(f,[a])); pop [a]: push max([a])
4E (N): pop [a]: push a[-1]
50 (P): pop a: push the a-th prime (zero-indexed)
52 (R): pop f,[a]: call f, using [a] as a temporary stack, push [a] (similar to reduce(f,[a])); pop [a]: push [a][::-1] (reverse); pop a: push [1,2,...,a] (range(1,a+1))
53 (S): pop a: push sin(a); pop [a]: push sorted(a)
54 (T): pop a: push tan(a); pop [a],b,c: set [a][b] to c, push [a]
55 (U): pop [a],[b]: push union of [a] and [b]
57 (W): loop delimiter: peek top of stack, repeat code in loop while a evaluates to true
58 (X): pop a: discard
59 (Y): pop a: push !bool(a) (logical negate, opposite of b)
5A (Z): pop [a],[b]: push zip([a],[b]); pop a, zip the next a lists
5B ([): begin list literal, values are delimited by commas (,)
5C (\): pop a,b: push a/b (integer division); pop [a]: rotate [a] left by 1, push [a]
5D (]): end list literal
5E (^): pop a,b: push a XOR b
5F (_): pop a: push ln(a)
60 (`): function literal delimiter, pushes function whose body contains all of the commands until the next `. An implied ` is present at EOF if needed.
61 (a): invert the stack ([a,b,c,d] -> [d,c,b,a])
62 (b): pop a: push 0 if a==0 else 1; pop "a" or [a]: push 0 if len(a)==0 else 1; pop f: push 0 if len(f)==0 else 1
63 (c): pop a: push character at ordinal a%256; pop [a],b: push [a].count(b)
64 (d): pop [a]: dequeue b from [a], push [a],b
65 (e): pop a: push exp(a)
66 (f): pop a: push the Fibonacci index of a if a is a Fibonacci number, else -1
67 (g): pop a,b: push gcd(a,b); pop [a]: push gcd([a])
68 (h): pop a,b: push sqrt(a*a+b*b) (Euclidean norm)
69 (i): pop [a]: push each element from [a], starting from end (flatten)
6B (k): pop all elements from stack, convert to list (in the order they were on the stack, starting from the top), and push
6C (l): pop [a]: push len([a])
6D (m): pop a: push int(a),frac(a) (modf(a)); pop [a]: push min([a])
6E (n): pop a,b: push a b times
6F (o): pop [a],b: push b to [a], push [a]
70 (p): pop a: push 1 if a is prime else 0; pop [a]: pop b from [a], push [a],b
71 (q): pop [a],b: enqueue b in [a], push [a]
72 (r): pop a: push [0,1,...,a-1] (range(0,a))
75 (u): pop a: push a+1
77 (w): pop a: push the full positive prime factorization of |a| (18 -> [[2,1],[3,2]], -5 -> [[5,1]])
78 (x): pop a,b: push [a,b) (range(a,b)); pop [a]: push range(*a)
79 (y): pop a: push the positive prime factors of |a| (18 -> [2,3], -5 -> [5])
7B ({): pop a: rotate stack right a times
7C (|): pop a,b: push a | b (bitwise OR)
7D (}): pop a: rotate stack left a times
7E (~): pop a: push ~a (unary bitwise negate)
80 (Ç): pop a,b: push a+bi; pop [a]: pop pairs of real numerics b,c from [a] and push b+ci (appending 0 to [a] if len([a]) is odd)
83 (â): pop a: push asin(a)
84 (ä): pop a: push acos(a)
85 (à): pop a: push atan(a)
86 (å): pop a,b: push atan2(a,b)
87 (ç): pop a: push asinh(a)
88 (ê): pop a: push acosh(a)
89 (ë): pop a: push atanh(a)
8B (ï): push i, the imaginary unit (sqrt(-1) or 0+1i)
8C (î): pop a, push 0+ai; pop [a], push [a] with every element multiplied by i
8D (ì): pop a: push 1/a
8E (Ä): pop a: push sinh(a)
8F (Å): pop a: push cosh(a)
90 (É): pop a: push tanh(a)
91 (æ): pop [a]: push mean([a])
9A (Ü): pop [a]: push mode([a])
9B (¢): pop a,b: push abs(a)*sgn(b)
9D (¥): pop [a],[b]: push the result of pairwise addition of [a] and [b], padding the shorter with 0s
9E (₧): pop z: push phase(z)
A0 (á): pop z: push the complex conjugate of z
A1 (í): pop [a],b: push [a].index(b) (0-based, -1 if not found)
A7 (º): pop a: push degrees(a)
A8 (¿): pop a,b: push int(a,b) (interpret a as a base-b int)
A9 (⌐): pop a: push a+2
AA (¬): pop a: push a-2
AB (½): pop a: push a/2 (float division)
AC (¼): pop a: push a/4 (float division)
AD (¡): pop a,b: push a string representing a in base b
B0 (░): pop [a],[b]: push [[b][i] if [a][i] for i in len(b)], pads [a] with 0s if necessary
B1 (▒): pop a: push totient(a) (# of integers <= a that are coprime with a)
B2 (▓): pop a: push pi(a) (# of primes <= a)
B3 (│): duplicate stack ([a,b,c] => [a,b,c,a,b,c])
B4 (┤): pop a,b: push 1 if a and b are coprime else 0
B9 (╣): pop a: push the ath row in Pascal's triangle
C5 (┼): duplicate each element on stack ([a,b,c] => [a,a,b,b,c,c])
C6 (╞): pop a: make a total copies of each element on stack (3 [a,b,c] -> [a,a,a,b,b,b,c,c,c])
C7 (╟): pop a: pop a elements and push a list containing those elements in their original order
CB (╦): push pi
CC (╠): push e
D1 (╤): pop a: push 10**a
D2 (╥): pop a: push log(a) (log base 10)
D3 (╙): pop a: push 2**a
D4 (╘): pop a: push lg(a) (log base 2)
D5 (╒): push ln(2)
DB (█): pop a,b: push C(a,b) (aCb)
DC (▄): pop a,b: push P(a,b) (aPb)
E2 (Γ): pop a: push Gamma(a)
E3 (π): pop [a]: push product([a])
E4 (Σ): pop [a]: push sum([a])
E7 (τ): pop a: push 2*a
ED (φ): push phi (golden ratio)
F1 (±): pop a: push -a (unary negate)
F2 (≥): pop a,b: push a>=b
F3 (≤): pop a,b: push a<=b
F7 (≈): pop a: push int(a)
F8 (°): pop a: push radians(a)
FB (√): pop a: push sqrt(a)
FC (ⁿ): pop a,b: push pow(a,b)
FD (²): pop a: push a*a

[a] refers to an iterable (list, string, etc.), "a" refers to a string, f refers to a function, and a (and b, and c, and so on) refers to a numeric (or any data type, if the command is type-agnostic).
</code>```

It is likely that many of these commands will not be used, but I have included them just in case they are useful.

Scoring

Here are the integers that will be used for scoring:

```<code>-2124910654
-2117700574
-2098186988
-2095671996
-2083075613
-2058271687
-2052250777
-2024215903
-2019485642
-2016095616
-2009838326
-2009173317
-2007673992
-2000014444
-1999825668
-1992515610
-1989566707
-1975506037
-1955473208
-1950731112
-1949886423
-1920624450
-1918465596
-1916287469
-1905036556
-1903956118
-1888944417
-1865221863
-1856600057
-1842797147
-1835637734
-1812631357
-1805740096
-1798015647
-1726688233
-1723609647
-1713776890
-1700307138
-1687644479
-1645515069
-1617635994
-1610444000
-1579053372
-1556891649
-1549652116
-1537732956
-1535180388
-1527162056
-1524851611
-1524658412
-1523244369
-1521379172
-1520191198
-1519035741
-1516978241
-1508892332
-1489938422
-1482102944
-1481823232
-1470621147
-1469145091
-1446844485
-1441790509
-1437843276
-1435359182
-1434186947
-1429816311
-1429393781
-1419752032
-1400387846
-1385152926
-1372620863
-1369257355
-1361933674
-1360480816
-1334846204
-1323741718
-1323660173
-1312800992
-1308824840
-1304658551
-1287829999
-1283767920
-1276288210
-1264275838
-1263965596
-1262866901
-1255421887
-1251428680
-1244825786
-1243200329
-1235305532
-1233977691
-1220537074
-1214100716
-1199414474
-1190725823
-1190401800
-1178717689
-1172378149
-1147869245
-1142875190
-1138538768
-1137864183
-1124917489
-1102987222
-1095920186
-1083001017
-1080902655
-1047122002
-1031842676
-1029877334
-1020849489
-1001684838
-998419619
-990915088
-985235989
-982515261
-979074894
-974195629
-973832940
-965324937
-944246431
-938387588
-933873331
-932692878
-928039285
-927947459
-914008773
-907981688
-906376330
-903502449
-898112547
-887444438
-862658502
-843628573
-822463032
-786051095
-776932426
-776033951
-752042328
-746532472
-743149468
-740225710
-734414418
-725435852
-708101516
-699674783
-694869277
-693246525
-690571518
-689249770
-688581912
-686864294
-681445866
-647992869
-641101583
-631409299
-624686189
-613079884
-593711206
-591688546
-591331185
-574790069
-573024823
-565387051
-565137163
-556338668
-556291492
-541411509
-538932064
-500479857
-482419890
-468050561
-424532545
-420534171
-408741873
-406973874
-387664799
-382084509
-367095703
-352332569
-352195997
-346430007
-324596389
-320119776
-306594578
-305952425
-283718911
-267302378
-243302738
-242955859
-232180029
-225394407
-217418127
-212286453
-208344820
-191300139
-186177744
-175765723
-161763935
-157025501
-140389149
-132298608
-126175769
-70566352
-68748576
-53985905
-52674668
-50228620
-39678495
-19825663
-8349922
-8186722
-8125700
-8073135
-8043230
-7994382
-7874433
-7863624
-7784916
-7782477
-7696343
-7607278
-7531250
-7388060
-7368780
-7367625
-7353084
-7334489
-7281141
-7267149
-7140057
-7119066
-7010389
-6992089
-6975258
-6863360
-6784772
-6741079
-6585985
-6550401
-6520011
-6495144
-6459702
-6294273
-6178342
-6169344
-6139663
-6090928
-6022637
-5992707
-5971334
-5925304
-5880940
-5873707
-5807953
-5703992
-5692895
-5535131
-5488812
-5468330
-5404148
-5290247
-5274221
-5264144
-5234715
-5224048
-5179837
-5084014
-5043990
-5028537
-5011679
-4998333
-4922901
-4880159
-4874060
-4787390
-4749096
-4736217
-4502308
-4480611
-4424319
-4363262
-4349743
-4290050
-4240069
-4239657
-4174072
-4093051
-4045363
-4037689
-4033352
-3839265
-3766343
-3716899
-3680075
-3679053
-3581776
-3539227
-3461158
-3282526
-3205947
-3183427
-3169708
-3166430
-3089822
-3061531
-2947574
-2930733
-2919246
-2872882
-2830770
-2739228
-2713826
-2634018
-2613990
-2525529
-2439507
-2432921
-2376201
-2335005
-2307524
-2265548
-2176176
-2123133
-2108773
-2105934
-2075032
-2073940
-2045837
-2045648
-1978182
-1945769
-1935486
-1881608
-1654650
-1602520
-1506746
-1505294
-1475309
-1457605
-1327259
-1312217
-1178723
-1027439
-880781
-833776
-666675
-643098
-593446
-468772
-450369
-443225
-418164
-402004
-319964
-307400
-279414
-190199
-176644
-66862
-32745
-32686
-32352
-32261
-32035
-31928
-31414
-31308
-30925
-30411
-29503
-29182
-28573
-28500
-28093
-27743
-27716
-27351
-27201
-26834
-25946
-25019
-24469
-24341
-24292
-24151
-23732
-22769
-22242
-22002
-20863
-20762
-20644
-20189
-20009
-19142
-19036
-18980
-18616
-18196
-18123
-17942
-17915
-17601
-17494
-16669
-16417
-16317
-15051
-14796
-14742
-14600
-14443
-14159
-14046
-13860
-13804
-13745
-13634
-13498
-13497
-12688
-12471
-12222
-11993
-11467
-11332
-10783
-10250
-10114
-10089
-9930
-9434
-9336
-9128
-9109
-8508
-8460
-8198
-8045
-7850
-7342
-7229
-6762
-6302
-6245
-6171
-5957
-5842
-4906
-4904
-4630
-4613
-4567
-4427
-4091
-4084
-3756
-3665
-3367
-3186
-2922
-2372
-2331
-1936
-1683
-1350
-1002
-719
-152
-128
-127
-124
-122
-121
-119
-116
-113
-112
-111
-107
-104
-102
-101
-100
-95
-94
-91
-90
-87
-81
-80
-79
-78
-73
-72
-69
-68
-66
-65
-63
-57
-54
-52
-51
-48
-47
-46
-45
-43
-41
-37
-33
-31
-30
-27
-25
-21
-18
-15
-12
-8
-1
0
1
3
4
5
6
11
14
17
23
25
26
27
28
29
31
32
39
41
46
49
51
52
56
58
61
64
66
67
70
74
79
80
86
88
89
92
93
99
102
104
109
113
117
120
122
123
127
695
912
1792
2857
3150
3184
4060
4626
5671
6412
6827
7999
8017
8646
8798
9703
9837
10049
10442
10912
11400
11430
11436
11551
11937
12480
13258
13469
13689
13963
13982
14019
14152
14259
14346
15416
15613
15954
16241
16814
16844
17564
17702
17751
18537
18763
19890
21216
22238
22548
23243
23383
23386
23407
23940
24076
24796
24870
24898
24967
25139
25176
25699
26167
26536
26614
27008
27087
27142
27356
27458
27800
27827
27924
28595
29053
29229
29884
29900
30460
30556
30701
30815
30995
31613
31761
31772
32099
32308
32674
75627
80472
103073
110477
115718
172418
212268
242652
396135
442591
467087
496849
675960
759343
846297
881562
1003458
1153900
1156733
1164679
1208265
1318372
1363958
1411655
1522329
1559609
1677118
1693658
1703597
1811223
1831642
1838628
1884144
1931545
2085504
2168156
2170263
2239585
2308894
2329235
2364957
2432335
2435551
2596936
2684907
2691011
2705195
2738057
2851897
2925289
2995414
3051534
3216094
3267022
3271559
3338856
3440797
3638325
3651369
3718696
3724814
3811069
3854697
3866969
3893228
3963455
3984546
4098376
4100957
4128113
4200719
4256344
4286332
4306356
4316314
4438803
4458063
4461638
4552228
4563790
4584831
4607992
4884455
4907501
5045419
5066844
5150624
5157161
5190669
5314703
5337397
5434807
5440092
5502665
5523089
5547122
5566200
5582936
5634068
5690330
5776984
5778441
5818505
5826687
5827184
5885735
6010506
6084254
6131498
6138324
6250773
6292801
6306275
6315242
6331640
6484374
6502969
6545970
6666951
6690905
6763576
6766086
6895048
6912227
6929081
6941390
6978168
7045672
7085246
7193307
7197398
7270237
7276767
7295790
7375488
7472098
7687424
7840758
7880957
7904499
7948678
7974126
8015691
8037685
8112955
8131380
8140556
8142384
8220436
8308817
8331317
22581970
45809129
48103779
78212045
79674901
97299830
110308649
131744428
136663461
138485719
139842794
152061792
152685704
153070991
156228213
164884737
174776199
189346581
193148547
208582124
223891881
227308187
237373798
241214067
242476929
245495851
260606593
275202667
285717038
317009689
322759532
325369206
339724742
340122632
345010859
352375176
355826263
359695034
366118516
370008270
382712922
386379440
401153345
404986391
426084981
442843409
473909474
475192613
492302667
494747879
506279889
509813998
537558350
548423414
548467404
566383324
574188786
574792333
591678147
596558084
597423476
602432742
603067874
629552047
630893263
635249783
644959276
650710927
664859367
669433203
684329599
699991513
714451929
723556530
739294558
750895264
757618344
781123405
796973385
801637715
804776709
829003666
829219068
840167037
854882202
860066192
864304878
864808449
867107161
871871263
880591851
883020336
883178082
920223781
936008673
939417822
956776353
958281059
962183717
964059257
967860573
974322643
974999286
980009921
1032949015
1044249483
1064892676
1075628270
1080848022
1085571657
1173635593
1174809080
1176744978
1209783795
1212074975
1252323507
1254757790
1301450562
1302240953
1314501797
1315121266
1339304157
1364304289
1376260506
1383883477
1395158643
1411117754
1440755058
1448365702
1466814914
1468433821
1490105126
1493912601
1495600372
1509536621
1511014977
1545693948
1548924199
1566583103
1569747154
1574097219
1597784674
1610710480
1618324005
1646105187
1649417465
1655649169
1660619384
1668826887
1671093718
1672456990
1673477565
1678638502
1682302139
1682515769
1687920300
1690062315
1706031388
1713660819
1772170709
1778416812
1833443690
1861312062
1876004501
1876358085
1882435551
1916050713
1944906037
1950207172
1951593247
1973638546
1976288281
1994977271
2020053060
2025281195
2029716419
2033980539
2052482076
2058251762
2069273004
2073978021
2111013213
2119886932
2134609957
2140349794
2143934987
</code>```

Here is a Python 3 program that can be used to verify and score a submission:

#!/usr/bin/env python3

import shlex
import os
import sys
import subprocess

try:
    from seriously import Seriously
except:
    print("Unable to load Seriously. Run 'pip3 install seriously' to install it.")
    exit()

if len(sys.argv) < 2:
    print("Usage: python3 {} 'command_to_call_your_program'".format(sys.argv[0]))
    exit()

sys.stdin = open(os.devnull, 'r')

with open('nums.txt') as f:
    nums = [int(x) for x in f]

total = 0

for num in nums:
    p = subprocess.Popen(shlex.split(sys.argv[1]), stdin=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True)
    try:
        out = p.communicate(str(num), timeout=30)[0].strip()
    except subprocess.TimeoutExpired:
        print("Program failed to finish within 30 seconds for {}".format(num))
        exit()
    val = Seriously().eval(out)[0]
    if not len(out) <= len(':'+str(num)):
        print("Failed to do at least as well as naive on {} ({})".format(num, out))
        exit()
    elif val != num or not isinstance(val, int):
        print("Incorrect output: {} instead of {}".format(val, num))
        exit()
    else:
        print("{}: {} ({})".format(num, out, len(out)))
        total += len(out)

print("Total:", total)
```

答:
Python 3, 34 39 bytes saved

This program simply calculates every number it can reach using simple combinations of the binary and unary operators, which covers 366k out of 4B integers, for a total of a couple of dozen of the test cases. Then I output those results or the trivial solution. This is technically against the rules, because it is certain there is a better solution for some of the cases, but I am confident no one is going to come up with a solution that certainly passes that rule.

Also, I'm just producing all the output at once, because 30 seconds of setup time is bearable once, not 1000 times. The commented out sections increase the runtime significantly while barely reducing the score.

```<code>#!/usr/bin/env python3
# -*- coding: cp437 -*-

import math
import gmpy
import json
import random

from seriously import chr_cp437

# MAX=2**31
MAX = 2**31

best = {}

def l(n,force_colon=False):
    if force_colon:
        return ':'+str(n)
    if n>=0 and n<10:
        return str(n)
    elif n<0 and n>-10:
        return str(-n)+chr_cp437(0xF1)
    return ':'+str(n)

def l2(n,m):
    if n<10 or best_or_l(n)[-1] in "0123456789":
        rep = l(n)+best_or_l(m)
    else:
        rep = best_or_l(n)+best_or_l(m,True)
    return rep

def cand(n,rep):
    # print(n,rep,len(rep),best[n] if n in best else "")
    if n!=int(n):
        return False
    n=int(n)
    if n<=MAX and len(rep)<len(l(n)) and (n not in best or len(rep)<len(best[n])):
        best[n] = rep
        return True
    return False

def best_or_l(n,force_colon=False):
    if n in best:
        return best[n]
    if -n in best and n>0:
        return best[-n]+chr_cp437(0xF1)
    return l(n,force_colon)

# digits
for i in range(0,10):
    best[i]=str(i)

# factorials
for i in range(4,13):
    cand(math.factorial(i),l(i)+'!')

# 10**i
for i in range(2,12):
    cand(10**i,l(i)+chr_cp437(0xD1))

# 2**i
for i in range(2,32):
    cand(2**i,best_or_l(i)+chr_cp437(0xD3))

# a choose b
for a in range(2,1000): # 466 is the highest a for MAX=2**24
    for b in range(2,int(a/2+1)):
        n = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
        if n>MAX:
            break
        cand(n,l2(b,a)+chr_cp437(0xDB))

# a P b
for a in range(2,1000): # 257 is the highest a for MAX=2**24
    for b in range(2,int(a/2+1)):
        n = math.factorial(a)/math.factorial(a-b)
        if n>MAX:
            break
        cand(n,l2(b,a)+chr_cp437(0xDC))

# fibonacci
def fib_formula(n):
    golden_ratio = (1 + math.sqrt(5)) / 2
    val = (golden_ratio**n - (1 - golden_ratio)**n) / math.sqrt(5)
    return int(round(val))
for i in range(3,47):
    cand(fib_formula(i),best_or_l(i)+'F')

# i^2 and ^4
for i in range(5,int(math.sqrt(MAX)+1)):
    cand(i*i,best_or_l(i)+chr_cp437(0xFD))

# a^b
for a in range(2,int(math.pow(MAX,1.0/3))+1):
    for b in range(3,int(math.log(MAX)/math.log(3))+1):
        n = a**b
        cand(n,l2(b,a)+chr_cp437(0xFC))

# exp(i)
for i in range(3,22):
    cand(int(math.ceil(math.exp(i))),best_or_l(i)+'eK')
    cand(int(math.floor(math.exp(i))),best_or_l(i)+'eL')

# primes
def primes():
    n = 2
    while True:
        yield n
        n = gmpy.next_prime(n)
n = 0
for p in primes():
    # print(p)
    if p>MAX/1000:
        break
    rep = best_or_l(n)+'P'
    cand(p,rep)
    n=n+1

# +1 +2 -1 -2 *2 /2 /4
for key,value in sorted(best.items()):
    cand(key+1,value+'u')
    cand(key+2,value+chr_cp437(0xA9))
    cand(key-1,value+'D')
    cand(key-2,value+chr_cp437(0xAA))
    cand(key*2,value+chr_cp437(0xE7))
    if float(key)/2 == int(float(key)/2):
        cand(int((float(key)/2)),value+chr_cp437(0xAB))
    cand(int(math.floor(float(key)/2)),value+chr_cp437(0xAB)+'L')
    cand(int(math.ceil(float(key)/2)),value+chr_cp437(0xAB)+'K')
    if float(key)/4 == int(float(key)/4):
        cand(int((float(key)/4)),value+chr_cp437(0xAC))
    cand(int(math.floor(float(key)/4)),value+chr_cp437(0xAC)+'L')
    cand(int(math.ceil(float(key)/4)),value+chr_cp437(0xAC)+'L')

# bitwise invert
for key,value in sorted(best.items()):
    cand(~key,value+'~')

# arithmetic with small second operands
for key,value in sorted(best.items()):
    for op in ["+","-","/","/K","\\","*"]:
        for i in range(3,10):
            if op == "+":
                n = key+i
            elif op == "-":
                n = key-i
            elif op == "/":
                if i==4:
                    continue
                n = float(key)/i
                if int(n)!=n:
                    continue
                n = int(n)
            elif op == "/K":
                if i==4:
                    continue
                n = int(math.ceil(float(key)/i))
                if n == float(key)/i:
                    continue
            elif op == "\\":
                if i==4:
                    continue
                n = int(math.floor(float(key)/i))
                if n == float(key)/i:
                    continue
            elif op == "*":
                n = key*i
            rep = value+best_or_l(i)+op
            cand(n,rep)

# for key,value in sorted(best.items()):
#     print(key,value)

# def maybe(n,rep):
#     if len(rep)<len(best_or_l(n)):
#         return True
#     return False

# b=[]
# for k in sorted(best.keys()):
#     b.append(k)
#     if k>100000000:
#         break

# def search_for_better(n):
#     if n in best:
#         return best[n]
#     for i in b:
#         if n+i in best:
#             rep = best[n+i]+best[i]+'-'
#             if maybe(n,rep):
#                 return rep
#     for i in b:
#         if n-i in best:
#             rep = best[n-i]+best[i]+'+'
#             if maybe(n,rep):
#                 return rep
#     return l(n)

for key,value in sorted(best.items()):
    if random.random()<0.001:
        print(key,value)

score = 0
for i in [-2124910654, -2117700574, -2098186988, -2095671996, -2083075613, -2058271687, -2052250777, -2024215903, -2019485642, -2016095616, -2009838326, -2009173317, -2007673992, -2000014444, -1999825668, -1992515610, -1989566707, -1975506037, -1955473208, -1950731112, -1949886423, -1920624450, -1918465596, -1916287469, -1905036556, -1903956118, -1888944417, -1865221863, -1856600057, -1842797147, -1835637734, -1812631357, -1805740096, -1798015647, -1726688233, -1723609647, -1713776890, -1700307138, -1687644479, -1645515069, -1617635994, -1610444000, -1579053372, -1556891649, -1549652116, -1537732956, -1535180388, -1527162056, -1524851611, -1524658412, -1523244369, -1521379172, -1520191198, -1519035741, -1516978241, -1508892332, -1489938422, -1482102944, -1481823232, -1470621147, -1469145091, -1446844485, -1441790509, -1437843276, -1435359182, -1434186947, -1429816311, -1429393781, -1419752032, -1400387846, -1385152926, -1372620863, -1369257355, -1361933674, -1360480816, -1334846204, -1323741718, -1323660173, -1312800992, -1308824840, -1304658551, -1287829999, -1283767920, -1276288210, -1264275838, -1263965596, -1262866901, -1255421887, -1251428680, -1244825786, -1243200329, -1235305532, -1233977691, -1220537074, -1214100716, -1199414474, -1190725823, -1190401800, -1178717689, -1172378149, -1147869245, -1142875190, -1138538768, -1137864183, -1124917489, -1102987222, -1095920186, -1083001017, -1080902655, -1047122002, -1031842676, -1029877334, -1020849489, -1001684838, -998419619, -990915088, -985235989, -982515261, -979074894, -974195629, -973832940, -965324937, -944246431, -938387588, -933873331, -932692878, -928039285, -927947459, -914008773, -907981688, -906376330, -903502449, -898112547, -887444438, -862658502, -843628573, -822463032, -786051095, -776932426, -776033951, -752042328, -746532472, -743149468, -740225710, -734414418, -725435852, -708101516, -699674783, -694869277, -693246525, -690571518, -689249770, -688581912, -686864294, -681445866, -647992869, -641101583, -631409299, -624686189, -613079884, -593711206, -591688546, -591331185, -574790069, -573024823, -565387051, -565137163, -556338668, -556291492, -541411509, -538932064, -500479857, -482419890, -468050561, -424532545, -420534171, -408741873, -406973874, -387664799, -382084509, -367095703, -352332569, -352195997, -346430007, -324596389, -320119776, -306594578, -305952425, -283718911, -267302378, -243302738, -242955859, -232180029, -225394407, -217418127, -212286453, -208344820, -191300139, -186177744, -175765723, -161763935, -157025501, -140389149, -132298608, -126175769, -70566352, -68748576, -53985905, -52674668, -50228620, -39678495, -19825663, -8349922, -8186722, -8125700, -8073135, -8043230, -7994382, -7874433, -7863624, -7784916, -7782477, -7696343, -7607278, -7531250, -7388060, -7368780, -7367625, -7353084, -7334489, -7281141, -7267149, -7140057, -7119066, -7010389, -6992089, -6975258, -6863360, -6784772, -6741079, -6585985, -6550401, -6520011, -6495144, -6459702, -6294273, -6178342, -6169344, -6139663, -6090928, -6022637, -5992707, -5971334, -5925304, -5880940, -5873707, -5807953, -5703992, -5692895, -5535131, -5488812, -5468330, -5404148, -5290247, -5274221, -5264144, -5234715, -5224048, -5179837, -5084014, -5043990, -5028537, -5011679, -4998333, -4922901, -4880159, -4874060, -4787390, -4749096, -4736217, -4502308, -4480611, -4424319, -4363262, -4349743, -4290050, -4240069, -4239657, -4174072, -4093051, -4045363, -4037689, -4033352, -3839265, -3766343, -3716899, -3680075, -3679053, -3581776, -3539227, -3461158, -3282526, -3205947, -3183427, -3169708, -3166430, -3089822, -3061531, -2947574, -2930733, -2919246, -2872882, -2830770, -2739228, -2713826, -2634018, -2613990, -2525529, -2439507, -2432921, -2376201, -2335005, -2307524, -2265548, -2176176, -2123133, -2108773, -2105934, -2075032, -2073940, -2045837, -2045648, -1978182, -1945769, -1935486, -1881608, -1654650, -1602520, -1506746, -1505294, -1475309, -1457605, -1327259, -1312217, -1178723, -1027439, -880781, -833776, -666675, -643098, -593446, -468772, -450369, -443225, -418164, -402004, -319964, -307400, -279414, -190199, -176644, -66862, -32745, -32686, -32352, -32261, -32035, -31928, -31414, -31308, -30925, -30411, -29503, -29182, -28573, -28500, -28093, -27743, -27716, -27351, -27201, -26834, -25946, -25019, -24469, -24341, -24292, -24151, -23732, -22769, -22242, -22002, -20863, -20762, -20644, -20189, -20009, -19142, -19036, -18980, -18616, -18196, -18123, -17942, -17915, -17601, -17494, -16669, -16417, -16317, -15051, -14796, -14742, -14600, -14443, -14159, -14046, -13860, -13804, -13745, -13634, -13498, -13497, -12688, -12471, -12222, -11993, -11467, -11332, -10783, -10250, -10114, -10089, -9930, -9434, -9336, -9128, -9109, -8508, -8460, -8198, -8045, -7850, -7342, -7229, -6762, -6302, -6245, -6171, -5957, -5842, -4906, -4904, -4630, -4613, -4567, -4427, -4091, -4084, -3756, -3665, -3367, -3186, -2922, -2372, -2331, -1936, -1683, -1350, -1002, -719, -152, -128, -127, -124, -122, -121, -119, -116, -113, -112, -111, -107, -104, -102, -101, -100, -95, -94, -91, -90, -87, -81, -80, -79, -78, -73, -72, -69, -68, -66, -65, -63, -57, -54, -52, -51, -48, -47, -46, -45, -43, -41, -37, -33, -31, -30, -27, -25, -21, -18, -15, -12, -8, -1, 0, 1, 3, 4, 5, 6, 11, 14, 17, 23, 25, 26, 27, 28, 29, 31, 32, 39, 41, 46, 49, 51, 52, 56, 58, 61, 64, 66, 67, 70, 74, 79, 80, 86, 88, 89, 92, 93, 99, 102, 104, 109, 113, 117, 120, 122, 123, 127, 695, 912, 1792, 2857, 3150, 3184, 4060, 4626, 5671, 6412, 6827, 7999, 8017, 8646, 8798, 9703, 9837, 10049, 10442, 10912, 11400, 11430, 11436, 11551, 11937, 12480, 13258, 13469, 13689, 13963, 13982, 14019, 14152, 14259, 14346, 15416, 15613, 15954, 16241, 16814, 16844, 17564, 17702, 17751, 18537, 18763, 19890, 21216, 22238, 22548, 23243, 23383, 23386, 23407, 23940, 24076, 24796, 24870, 24898, 24967, 25139, 25176, 25699, 26167, 26536, 26614, 27008, 27087, 27142, 27356, 27458, 27800, 27827, 27924, 28595, 29053, 29229, 29884, 29900, 30460, 30556, 30701, 30815, 30995, 31613, 31761, 31772, 32099, 32308, 32674, 75627, 80472, 103073, 110477, 115718, 172418, 212268, 242652, 396135, 442591, 467087, 496849, 675960, 759343, 846297, 881562, 1003458, 1153900, 1156733, 1164679, 1208265, 1318372, 1363958, 1411655, 1522329, 1559609, 1677118, 1693658, 1703597, 1811223, 1831642, 1838628, 1884144, 1931545, 2085504, 2168156, 2170263, 2239585, 2308894, 2329235, 2364957, 2432335, 2435551, 2596936, 2684907, 2691011, 2705195, 2738057, 2851897, 2925289, 2995414, 3051534, 3216094, 3267022, 3271559, 3338856, 3440797, 3638325, 3651369, 3718696, 3724814, 3811069, 3854697, 3866969, 3893228, 3963455, 3984546, 4098376, 4100957, 4128113, 4200719, 4256344, 4286332, 4306356, 4316314, 4438803, 4458063, 4461638, 4552228, 4563790, 4584831, 4607992, 4884455, 4907501, 5045419, 5066844, 5150624, 5157161, 5190669, 5314703, 5337397, 5434807, 5440092, 5502665, 5523089, 5547122, 5566200, 5582936, 5634068, 5690330, 5776984, 5778441, 5818505, 5826687, 5827184, 5885735, 6010506, 6084254, 6131498, 6138324, 6250773, 6292801, 6306275, 6315242, 6331640, 6484374, 6502969, 6545970, 6666951, 6690905, 6763576, 6766086, 6895048, 6912227, 6929081, 6941390, 6978168, 7045672, 7085246, 7193307, 7197398, 7270237, 7276767, 7295790, 7375488, 7472098, 7687424, 7840758, 7880957, 7904499, 7948678, 7974126, 8015691, 8037685, 8112955, 8131380, 8140556, 8142384, 8220436, 8308817, 8331317, 22581970, 45809129, 48103779, 78212045, 79674901, 97299830, 110308649, 131744428, 136663461, 138485719, 139842794, 152061792, 152685704, 153070991, 156228213, 164884737, 174776199, 189346581, 193148547, 208582124, 223891881, 227308187, 237373798, 241214067, 242476929, 245495851, 260606593, 275202667, 285717038, 317009689, 322759532, 325369206, 339724742, 340122632, 345010859, 352375176, 355826263, 359695034, 366118516, 370008270, 382712922, 386379440, 401153345, 404986391, 426084981, 442843409, 473909474, 475192613, 492302667, 494747879, 506279889, 509813998, 537558350, 548423414, 548467404, 566383324, 574188786, 574792333, 591678147, 596558084, 597423476, 602432742, 603067874, 629552047, 630893263, 635249783, 644959276, 650710927, 664859367, 669433203, 684329599, 699991513, 714451929, 723556530, 739294558, 750895264, 757618344, 781123405, 796973385, 801637715, 804776709, 829003666, 829219068, 840167037, 854882202, 860066192, 864304878, 864808449, 867107161, 871871263, 880591851, 883020336, 883178082, 920223781, 936008673, 939417822, 956776353, 958281059, 962183717, 964059257, 967860573, 974322643, 974999286, 980009921, 1032949015, 1044249483, 1064892676, 1075628270, 1080848022, 1085571657, 1173635593, 1174809080, 1176744978, 1209783795, 1212074975, 1252323507, 1254757790, 1301450562, 1302240953, 1314501797, 1315121266, 1339304157, 1364304289, 1376260506, 1383883477, 1395158643, 1411117754, 1440755058, 1448365702, 1466814914, 1468433821, 1490105126, 1493912601, 1495600372, 1509536621, 1511014977, 1545693948, 1548924199, 1566583103, 1569747154, 1574097219, 1597784674, 1610710480, 1618324005, 1646105187, 1649417465, 1655649169, 1660619384, 1668826887, 1671093718, 1672456990, 1673477565, 1678638502, 1682302139, 1682515769, 1687920300, 1690062315, 1706031388, 1713660819, 1772170709, 1778416812, 1833443690, 1861312062, 1876004501, 1876358085, 1882435551, 1916050713, 1944906037, 1950207172, 1951593247, 1973638546, 1976288281, 1994977271, 2020053060, 2025281195, 2029716419, 2033980539, 2052482076, 2058251762, 2069273004, 2073978021, 2111013213, 2119886932, 2134609957, 2140349794, 2143934987]:
    print(i)
    print(best_or_l(i,True))
    score = score + (len(l(i))-len(best_or_l(i,True)))
print("Score:",score)

# print(len(best))

with open("aim.json","w") as outfile:
    outfile.write(json.dumps(best,sort_keys=True,indent=2))
</code>```

Here's a random sampling of the sorts of Actually programs that end up found by this algorithm:

```<code>15875 49█²D
178085 :422²u
6195119 :2489²¬
11276166 :3358²⌐
14516098 :3810²¬
32924643 :5738²D
35003345 :8367²½K
66438802 :8151²u
95664294 3:363ⁿτ
100915813 3:847█¬
111894084 :10578²
219662043 :14821²⌐
220849321 :14861²
236390625 :15375²
282710596 :16814²
296511180 :34439²¼L
375584401 :19380²u
460188303 :21452²D
465157056 :43135²¼L
509991890 :22583²u
510963420 :45209²¼L
606981768 :24637²D
659407868 8FeK½K
697212482 :18671²τ
805764994 :28386²¬
852225612 :41285²½L
941078331 :30677²⌐
1034715540 :45491²½L
1193771602 :34551²u
1326125054 :36416²¬
2030403600 :45060²
2078904023 :45595²¬
</code>```

Title: Actually Integer Metagolf

Body:
Python 3, 34 39 bytes saved

This program simply calculates every number it can reach using simple combinations of the binary and unary operators, which covers 366k out of 4B integers, for a total of a couple of dozen of the test cases. Then I output those results or the trivial solution. This is technically against the rules, because it is certain there is a better solution for some of the cases, but I am confident no one is going to come up with a solution that certainly passes that rule.

Also, I'm just producing all the output at once, because 30 seconds of setup time is bearable once, not 1000 times. The commented out sections increase the runtime significantly while barely reducing the score.

#!/usr/bin/env python3
# -*- coding: cp437 -*-

import math
import gmpy
import json
import random

from seriously import chr_cp437

# MAX=2**31
MAX = 2**31

best = {}

def l(n,force_colon=False):
    if force_colon:
        return ':'+str(n)
    if n>=0 and n<10:
        return str(n)
    elif n<0 and n>-10:
        return str(-n)+chr_cp437(0xF1)
    return ':'+str(n)

def l2(n,m):
    if n<10 or best_or_l(n)[-1] in "0123456789":
        rep = l(n)+best_or_l(m)
    else:
        rep = best_or_l(n)+best_or_l(m,True)
    return rep

def cand(n,rep):
    # print(n,rep,len(rep),best[n] if n in best else "")
    if n!=int(n):
        return False
    n=int(n)
    if n<=MAX and len(rep)<len(l(n)) and (n not in best or len(rep)<len(best[n])):
        best[n] = rep
        return True
    return False

def best_or_l(n,force_colon=False):
    if n in best:
        return best[n]
    if -n in best and n>0:
        return best[-n]+chr_cp437(0xF1)
    return l(n,force_colon)

# digits
for i in range(0,10):
    best[i]=str(i)

# factorials
for i in range(4,13):
    cand(math.factorial(i),l(i)+'!')

# 10**i
for i in range(2,12):
    cand(10**i,l(i)+chr_cp437(0xD1))

# 2**i
for i in range(2,32):
    cand(2**i,best_or_l(i)+chr_cp437(0xD3))

# a choose b
for a in range(2,1000): # 466 is the highest a for MAX=2**24
    for b in range(2,int(a/2+1)):
        n = math.factorial(a)/(math.factorial(b)*math.factorial(a-b))
        if n>MAX:
            break
        cand(n,l2(b,a)+chr_cp437(0xDB))

# a P b
for a in range(2,1000): # 257 is the highest a for MAX=2**24
    for b in range(2,int(a/2+1)):
        n = math.factorial(a)/math.factorial(a-b)
        if n>MAX:
            break
        cand(n,l2(b,a)+chr_cp437(0xDC))

# fibonacci
def fib_formula(n):
    golden_ratio = (1 + math.sqrt(5)) / 2
    val = (golden_ratio**n - (1 - golden_ratio)**n) / math.sqrt(5)
    return int(round(val))
for i in range(3,47):
    cand(fib_formula(i),best_or_l(i)+'F')

# i^2 and ^4
for i in range(5,int(math.sqrt(MAX)+1)):
    cand(i*i,best_or_l(i)+chr_cp437(0xFD))

# a^b
for a in range(2,int(math.pow(MAX,1.0/3))+1):
    for b in range(3,int(math.log(MAX)/math.log(3))+1):
        n = a**b
        cand(n,l2(b,a)+chr_cp437(0xFC))

# exp(i)
for i in range(3,22):
    cand(int(math.ceil(math.exp(i))),best_or_l(i)+'eK')
    cand(int(math.floor(math.exp(i))),best_or_l(i)+'eL')

# primes
def primes():
    n = 2
    while True:
        yield n
        n = gmpy.next_prime(n)
n = 0
for p in primes():
    # print(p)
    if p>MAX/1000:
        break
    rep = best_or_l(n)+'P'
    cand(p,rep)
    n=n+1

# +1 +2 -1 -2 *2 /2 /4
for key,value in sorted(best.items()):
    cand(key+1,value+'u')
    cand(key+2,value+chr_cp437(0xA9))
    cand(key-1,value+'D')
    cand(key-2,value+chr_cp437(0xAA))
    cand(key*2,value+chr_cp437(0xE7))
    if float(key)/2 == int(float(key)/2):
        cand(int((float(key)/2)),value+chr_cp437(0xAB))
    cand(int(math.floor(float(key)/2)),value+chr_cp437(0xAB)+'L')
    cand(int(math.ceil(float(key)/2)),value+chr_cp437(0xAB)+'K')
    if float(key)/4 == int(float(key)/4):
        cand(int((float(key)/4)),value+chr_cp437(0xAC))
    cand(int(math.floor(float(key)/4)),value+chr_cp437(0xAC)+'L')
    cand(int(math.ceil(float(key)/4)),value+chr_cp437(0xAC)+'L')

# bitwise invert
for key,value in sorted(best.items()):
    cand(~key,value+'~')

# arithmetic with small second operands
for key,value in sorted(best.items()):
    for op in ["+","-","/","/K","\\","*"]:
        for i in range(3,10):
            if op == "+":
                n = key+i
            elif op == "-":
                n = key-i
            elif op == "/":
                if i==4:
                    continue
                n = float(key)/i
                if int(n)!=n:
                    continue
                n = int(n)
            elif op == "/K":
                if i==4:
                    continue
                n = int(math.ceil(float(key)/i))
                if n == float(key)/i:
                    continue
            elif op == "\\":
                if i==4:
                    continue
                n = int(math.floor(float(key)/i))
                if n == float(key)/i:
                    continue
            elif op == "*":
                n = key*i
            rep = value+best_or_l(i)+op
            cand(n,rep)

# for key,value in sorted(best.items()):
#     print(key,value)

# def maybe(n,rep):
#     if len(rep)<len(best_or_l(n)):
#         return True
#     return False

# b=[]
# for k in sorted(best.keys()):
#     b.append(k)
#     if k>100000000:
#         break

# def search_for_better(n):
#     if n in best:
#         return best[n]
#     for i in b:
#         if n+i in best:
#             rep = best[n+i]+best[i]+'-'
#             if maybe(n,rep):
#                 return rep
#     for i in b:
#         if n-i in best:
#             rep = best[n-i]+best[i]+'+'
#             if maybe(n,rep):
#                 return rep
#     return l(n)

for key,value in sorted(best.items()):
    if random.random()<0.001:
        print(key,value)

score = 0
for i in [-2124910654, -2117700574, -2098186988, -2095671996, -2083075613, -2058271687, -2052250777, -2024215903, -2019485642, -2016095616, -2009838326, -2009173317, -2007673992, -2000014444, -1999825668, -1992515610, -1989566707, -1975506037, -1955473208, -1950731112, -1949886423, -1920624450, -1918465596, -1916287469, -1905036556, -1903956118, -1888944417, -1865221863, -1856600057, -1842797147, -1835637734, -1812631357, -1805740096, -1798015647, -1726688233, -1723609647, -1713776890, -1700307138, -1687644479, -1645515069, -1617635994, -1610444000, -1579053372, -1556891649, -1549652116, -1537732956, -1535180388, -1527162056, -1524851611, -1524658412, -1523244369, -1521379172, -1520191198, -1519035741, -1516978241, -1508892332, -1489938422, -1482102944, -1481823232, -1470621147, -1469145091, -1446844485, -1441790509, -1437843276, -1435359182, -1434186947, -1429816311, -1429393781, -1419752032, -1400387846, -1385152926, -1372620863, -1369257355, -1361933674, -1360480816, -1334846204, -1323741718, -1323660173, -1312800992, -1308824840, -1304658551, -1287829999, -1283767920, -1276288210, -1264275838, -1263965596, -1262866901, -1255421887, -1251428680, -1244825786, -1243200329, -1235305532, -1233977691, -1220537074, -1214100716, -1199414474, -1190725823, -1190401800, -1178717689, -1172378149, -1147869245, -1142875190, -1138538768, -1137864183, -1124917489, -1102987222, -1095920186, -1083001017, -1080902655, -1047122002, -1031842676, -1029877334, -1020849489, -1001684838, -998419619, -990915088, -985235989, -982515261, -979074894, -974195629, -973832940, -965324937, -944246431, -938387588, -933873331, -932692878, -928039285, -927947459, -914008773, -907981688, -906376330, -903502449, -898112547, -887444438, -862658502, -843628573, -822463032, -786051095, -776932426, -776033951, -752042328, -746532472, -743149468, -740225710, -734414418, -725435852, -708101516, -699674783, -694869277, -693246525, -690571518, -689249770, -688581912, -686864294, -681445866, -647992869, -641101583, -631409299, -624686189, -613079884, -593711206, -591688546, -591331185, -574790069, -573024823, -565387051, -565137163, -556338668, -556291492, -541411509, -538932064, -500479857, -482419890, -468050561, -424532545, -420534171, -408741873, -406973874, -387664799, -382084509, -367095703, -352332569, -352195997, -346430007, -324596389, -320119776, -306594578, -305952425, -283718911, -267302378, -243302738, -242955859, -232180029, -225394407, -217418127, -212286453, -208344820, -191300139, -186177744, -175765723, -161763935, -157025501, -140389149, -132298608, -126175769, -70566352, -68748576, -53985905, -52674668, -50228620, -39678495, -19825663, -8349922, -8186722, -8125700, -8073135, -8043230, -7994382, -7874433, -7863624, -7784916, -7782477, -7696343, -7607278, -7531250, -7388060, -7368780, -7367625, -7353084, -7334489, -7281141, -7267149, -7140057, -7119066, -7010389, -6992089, -6975258, -6863360, -6784772, -6741079, -6585985, -6550401, -6520011, -6495144, -6459702, -6294273, -6178342, -6169344, -6139663, -6090928, -6022637, -5992707, -5971334, -5925304, -5880940, -5873707, -5807953, -5703992, -5692895, -5535131, -5488812, -5468330, -5404148, -5290247, -5274221, -5264144, -5234715, -5224048, -5179837, -5084014, -5043990, -5028537, -5011679, -4998333, -4922901, -4880159, -4874060, -4787390, -4749096, -4736217, -4502308, -4480611, -4424319, -4363262, -4349743, -4290050, -4240069, -4239657, -4174072, -4093051, -4045363, -4037689, -4033352, -3839265, -3766343, -3716899, -3680075, -3679053, -3581776, -3539227, -3461158, -3282526, -3205947, -3183427, -3169708, -3166430, -3089822, -3061531, -2947574, -2930733, -2919246, -2872882, -2830770, -2739228, -2713826, -2634018, -2613990, -2525529, -2439507, -2432921, -2376201, -2335005, -2307524, -2265548, -2176176, -2123133, -2108773, -2105934, -2075032, -2073940, -2045837, -2045648, -1978182, -1945769, -1935486, -1881608, -1654650, -1602520, -1506746, -1505294, -1475309, -1457605, -1327259, -1312217, -1178723, -1027439, -880781, -833776, -666675, -643098, -593446, -468772, -450369, -443225, -418164, -402004, -319964, -307400, -279414, -190199, -176644, -66862, -32745, -32686, -32352, -32261, -32035, -31928, -31414, -31308, -30925, -30411, -29503, -29182, -28573, -28500, -28093, -27743, -27716, -27351, -27201, -26834, -25946, -25019, -24469, -24341, -24292, -24151, -23732, -22769, -22242, -22002, -20863, -20762, -20644, -20189, -20009, -19142, -19036, -18980, -18616, -18196, -18123, -17942, -17915, -17601, -17494, -16669, -16417, -16317, -15051, -14796, -14742, -14600, -14443, -14159, -14046, -13860, -13804, -13745, -13634, -13498, -13497, -12688, -12471, -12222, -11993, -11467, -11332, -10783, -10250, -10114, -10089, -9930, -9434, -9336, -9128, -9109, -8508, -8460, -8198, -8045, -7850, -7342, -7229, -6762, -6302, -6245, -6171, -5957, -5842, -4906, -4904, -4630, -4613, -4567, -4427, -4091, -4084, -3756, -3665, -3367, -3186, -2922, -2372, -2331, -1936, -1683, -1350, -1002, -719, -152, -128, -127, -124, -122, -121, -119, -116, -113, -112, -111, -107, -104, -102, -101, -100, -95, -94, -91, -90, -87, -81, -80, -79, -78, -73, -72, -69, -68, -66, -65, -63, -57, -54, -52, -51, -48, -47, -46, -45, -43, -41, -37, -33, -31, -30, -27, -25, -21, -18, -15, -12, -8, -1, 0, 1, 3, 4, 5, 6, 11, 14, 17, 23, 25, 26, 27, 28, 29, 31, 32, 39, 41, 46, 49, 51, 52, 56, 58, 61, 64, 66, 67, 70, 74, 79, 80, 86, 88, 89, 92, 93, 99, 102, 104, 109, 113, 117, 120, 122, 123, 127, 695, 912, 1792, 2857, 3150, 3184, 4060, 4626, 5671, 6412, 6827, 7999, 8017, 8646, 8798, 9703, 9837, 10049, 10442, 10912, 11400, 11430, 11436, 11551, 11937, 12480, 13258, 13469, 13689, 13963, 13982, 14019, 14152, 14259, 14346, 15416, 15613, 15954, 16241, 16814, 16844, 17564, 17702, 17751, 18537, 18763, 19890, 21216, 22238, 22548, 23243, 23383, 23386, 23407, 23940, 24076, 24796, 24870, 24898, 24967, 25139, 25176, 25699, 26167, 26536, 26614, 27008, 27087, 27142, 27356, 27458, 27800, 27827, 27924, 28595, 29053, 29229, 29884, 29900, 30460, 30556, 30701, 30815, 30995, 31613, 31761, 31772, 32099, 32308, 32674, 75627, 80472, 103073, 110477, 115718, 172418, 212268, 242652, 396135, 442591, 467087, 496849, 675960, 759343, 846297, 881562, 1003458, 1153900, 1156733, 1164679, 1208265, 1318372, 1363958, 1411655, 1522329, 1559609, 1677118, 1693658, 1703597, 1811223, 1831642, 1838628, 1884144, 1931545, 2085504, 2168156, 2170263, 2239585, 2308894, 2329235, 2364957, 2432335, 2435551, 2596936, 2684907, 2691011, 2705195, 2738057, 2851897, 2925289, 2995414, 3051534, 3216094, 3267022, 3271559, 3338856, 3440797, 3638325, 3651369, 3718696, 3724814, 3811069, 3854697, 3866969, 3893228, 3963455, 3984546, 4098376, 4100957, 4128113, 4200719, 4256344, 4286332, 4306356, 4316314, 4438803, 4458063, 4461638, 4552228, 4563790, 4584831, 4607992, 4884455, 4907501, 5045419, 5066844, 5150624, 5157161, 5190669, 5314703, 5337397, 5434807, 5440092, 5502665, 5523089, 5547122, 5566200, 5582936, 5634068, 5690330, 5776984, 5778441, 5818505, 5826687, 5827184, 5885735, 6010506, 6084254, 6131498, 6138324, 6250773, 6292801, 6306275, 6315242, 6331640, 6484374, 6502969, 6545970, 6666951, 6690905, 6763576, 6766086, 6895048, 6912227, 6929081, 6941390, 6978168, 7045672, 7085246, 7193307, 7197398, 7270237, 7276767, 7295790, 7375488, 7472098, 7687424, 7840758, 7880957, 7904499, 7948678, 7974126, 8015691, 8037685, 8112955, 8131380, 8140556, 8142384, 8220436, 8308817, 8331317, 22581970, 45809129, 48103779, 78212045, 79674901, 97299830, 110308649, 131744428, 136663461, 138485719, 139842794, 152061792, 152685704, 153070991, 156228213, 164884737, 174776199, 189346581, 193148547, 208582124, 223891881, 227308187, 237373798, 241214067, 242476929, 245495851, 260606593, 275202667, 285717038, 317009689, 322759532, 325369206, 339724742, 340122632, 345010859, 352375176, 355826263, 359695034, 366118516, 370008270, 382712922, 386379440, 401153345, 404986391, 426084981, 442843409, 473909474, 475192613, 492302667, 494747879, 506279889, 509813998, 537558350, 548423414, 548467404, 566383324, 574188786, 574792333, 591678147, 596558084, 597423476, 602432742, 603067874, 629552047, 630893263, 635249783, 644959276, 650710927, 664859367, 669433203, 684329599, 699991513, 714451929, 723556530, 739294558, 750895264, 757618344, 781123405, 796973385, 801637715, 804776709, 829003666, 829219068, 840167037, 854882202, 860066192, 864304878, 864808449, 867107161, 871871263, 880591851, 883020336, 883178082, 920223781, 936008673, 939417822, 956776353, 958281059, 962183717, 964059257, 967860573, 974322643, 974999286, 980009921, 1032949015, 1044249483, 1064892676, 1075628270, 1080848022, 1085571657, 1173635593, 1174809080, 1176744978, 1209783795, 1212074975, 1252323507, 1254757790, 1301450562, 1302240953, 1314501797, 1315121266, 1339304157, 1364304289, 1376260506, 1383883477, 1395158643, 1411117754, 1440755058, 1448365702, 1466814914, 1468433821, 1490105126, 1493912601, 1495600372, 1509536621, 1511014977, 1545693948, 1548924199, 1566583103, 1569747154, 1574097219, 1597784674, 1610710480, 1618324005, 1646105187, 1649417465, 1655649169, 1660619384, 1668826887, 1671093718, 1672456990, 1673477565, 1678638502, 1682302139, 1682515769, 1687920300, 1690062315, 1706031388, 1713660819, 1772170709, 1778416812, 1833443690, 1861312062, 1876004501, 1876358085, 1882435551, 1916050713, 1944906037, 1950207172, 1951593247, 1973638546, 1976288281, 1994977271, 2020053060, 2025281195, 2029716419, 2033980539, 2052482076, 2058251762, 2069273004, 2073978021, 2111013213, 2119886932, 2134609957, 2140349794, 2143934987]:
    print(i)
    print(best_or_l(i,True))
    score = score + (len(l(i))-len(best_or_l(i,True)))
print("Score:",score)

# print(len(best))

with open("aim.json","w") as outfile:
    outfile.write(json.dumps(best,sort_keys=True,indent=2))

Here's a random sampling of the sorts of Actually programs that end up found by this algorithm:

15875 49█²D
178085 :422²u
6195119 :2489²¬
11276166 :3358²⌐
14516098 :3810²¬
32924643 :5738²D
35003345 :8367²½K
66438802 :8151²u
95664294 3:363ⁿτ
100915813 3:847█¬
111894084 :10578²
219662043 :14821²⌐
220849321 :14861²
236390625 :15375²
282710596 :16814²
296511180 :34439²¼L
375584401 :19380²u
460188303 :21452²D
465157056 :43135²¼L
509991890 :22583²u
510963420 :45209²¼L
606981768 :24637²D
659407868 8FeK½K
697212482 :18671²τ
805764994 :28386²¬
852225612 :41285²½L
941078331 :30677²⌐
1034715540 :45491²½L
1193771602 :34551²u
1326125054 :36416²¬
2030403600 :45060²
2078904023 :45595²¬


问:
Flatten the Array!
In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] should output [10,20,30,40,50].

Input

The input will be a nested array (eg. [10,20,[[[10]]]]). It will contain only Integers (both negative and positive), Strings and Arrays. You can take the input as function argument, STDIN or whatever suits your language. You can assume that the input array won't have an empty array.

Output

The output will be a flatted single-dimensional array with the same elements of same type as in the nested array and in the SAME order.

Test Cases

```<code>[10,20,30] -> [10,20,30]
[[10]] -> [10]
[["Hi"],[[10]]] -> ["Hi",10]
[[[20],["Hi"],"Hi",20]] -> [20,"Hi","Hi",20]
[[["[]"],"[]"]] -> ["[]","[]"]
</code>```

Feel free to ask for any clarification by using comments. This is code-golf, so the shortest code in bytes wins!

Note: If your language contains a built-in for this, then you must NOT use it.

Edit

Please also include a link to a website where your code can be executed.

答:
K, 3 bytes

```<code>,//
</code>```

This is a fairly common idiom. "Join over converge".

try it here with oK.

How it works:

Join (,) fuses together atoms or lists to produce a list. Over (/) takes a verb (in this case join) and applies it between each element of a list, left to right. Thus, the compound ,/ will flatten all the top level elements of the list. The symbol / actually has different meanings depending on the valence (number of arguments) of the verb with which it is compounded. When we provide ,/ as the verb, the final / acts as "converge"- it repeatedly applies ,/ to the input until it stops changing. Some other languages call a feature like this a "fixed point combinator". By repeatedly fusing bottom level lists, you will eventually arrive at a single flat list, and none of the operations will perturb the order of elements. This seems to solve the problem.

Title: Flatten the Array!

Body:
K, 3 bytes

,//

This is a fairly common idiom. "Join over converge".

try it here with oK.

How it works:

Join (,) fuses together atoms or lists to produce a list. Over (/) takes a verb (in this case join) and applies it between each element of a list, left to right. Thus, the compound ,/ will flatten all the top level elements of the list. The symbol / actually has different meanings depending on the valence (number of arguments) of the verb with which it is compounded. When we provide ,/ as the verb, the final / acts as "converge"- it repeatedly applies ,/ to the input until it stops changing. Some other languages call a feature like this a "fixed point combinator". By repeatedly fusing bottom level lists, you will eventually arrive at a single flat list, and none of the operations will perturb the order of elements. This seems to solve the problem.


问:
What is the most frequent word?

What is the most frequent word?

Given a sentence, your program must make its way through it, counting the frequencies of each word, then output the most used word. Because a sentence has no fixed length, and so can get very long, your code must be as short as possible.

Rules/Requirements

Each submission should be either a full program or function. If it is a function, it must be runnable by only needing to add the function call to the bottom of the program. Anything else (e.g. headers in C), must be included.

There must be a free interpreter/compiler available for your language.

If it is possible, provide a link to a site where your program can be tested.

Your program must not write anything to STDERR.

Your program should take input from STDIN (or the closest alternative in your language).

Standard loopholes are forbidden.

Your program must be case-insensitive (tHe, The and the all contribute to the count of the).

If there is no most frequent word (see test case #3), your program should output nothing.

Definition of a 'word':

You get the list of words by splitting the input text on spaces. The input will never contain any other type of whitespace than plain spaces (in particular no newlines). However, the final words should only contain alphanumerics (a-z, A-Z, 0-9), hyphens (-) and apostrophes ('). You can make that so by removing all other characters or by replacing them by space before doing the word splitting. To remain compatible with previous versions of the rules, apostrophes are not required to be included.

Test Cases

```<code>The man walked down the road.
==> the

-----

Slowly, he ate the pie, savoring each delicious bite. He felt like he was truly happy.
==> he

-----

This sentence has no most frequent word.
==>

-----

"That's... that's... that is just terrible!" he said.
==> that's / thats

-----

The old-fashioned man ate an old-fashioned cake.
==> old-fashioned

-----

IPv6 looks great, much better than IPv4, except for the fact that IPv6 has longer addresses.
==> IPv6

-----

This sentence with words has at most two equal most frequent words.
==>
</code>```

Note: The third and seventh test cases have no output, you may choose either on the fourth.

Scoring

Programs are scored according to bytes. The usual character set is UTF-8, if you are using another please specify.

When the challenge finishes, the program with the least bytes (it's called code-golf), will win.

Submissions

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code># Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code># Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code># Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the leaderboard snippet:

```<code># [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 79576; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 53406; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];

  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '
' + c.body.replace(OVERRIDE_REG, '') + '
';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });

  });

  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

答:
Python 3, 106 bytes

```<code>def f(s):s=s.split();z=sorted([s.count(i)for i in set(s)]);return("",max(set(s),key=s.count))[z[-2]<z[-1]]
</code>```

Title: What is the most frequent word?

Body:
Python 3, 106 bytes

def f(s):s=s.split();z=sorted([s.count(i)for i in set(s)]);return("",max(set(s),key=s.count))[z[-2]<z[-1]]


答:
Python, 57 bytes

f=lambda a:sum([list==type(x)and f(x)or[x]for x in a],[])
```

Try it online: Python 2, Python 3

Thanks to Kevin Lau for the list==type(x) trick.

Title: Flatten the Array!

Body:
In this challenge, your task is to create a program which takes in a nested array and returns a single-dimensional flattened array. For Example [10,20,[30,[40]],50] should output [10,20,30,40,50].

Input

The input will be a nested array (eg. [10,20,[[[10]]]]). It will contain only Integers (both negative and positive), Strings and Arrays. You can take the input as function argument, STDIN or whatever suits your language. You can assume that the input array won't have an empty array.

Output

The output will be a flatted single-dimensional array with the same elements of same type as in the nested array and in the SAME order.

Test Cases

```<code>[10,20,30] -> [10,20,30]
[[10]] -> [10]
[["Hi"],[[10]]] -> ["Hi",10]
[[[20],["Hi"],"Hi",20]] -> [20,"Hi","Hi",20]
[[["[]"],"[]"]] -> ["[]","[]"]
</code>```

Feel free to ask for any clarification by using comments. This is code-golf, so the shortest code in bytes wins!

Note: If your language contains a built-in for this, then you must NOT use it.

Edit

Please also include a link to a website where your code can be executed.

Body:
Python, 57 bytes

f=lambda a:sum([list==type(x)and f(x)or[x]for x in a],[])

Try it online: Python 2, Python 3

Thanks to Kevin Lau for the list==type(x) trick.


答:
Ruby, <s>43</s> <s>42</s> 34 bytes

Recursive solution. Now with exception handling! (might as well credit @akostadinov for inspiring the change though)

```<code>f=->a{a.map(&f).inject:+rescue[a]}
</code>```

IDEOne link

Title: Flatten the Array!

Body:
Ruby, <s>43</s> <s>42</s> 34 bytes

Recursive solution. Now with exception handling! (might as well credit @akostadinov for inspiring the change though)

f=->a{a.map(&f).inject:+rescue[a]}

IDEOne link


答:
JavaScript (ES6), 41 bytes

f=a=>[].concat(...a.map(v=>v.pop?f(v):v))```
<pre class="snippet-code-html lang-html prettyprint-override"><code><textarea id="input" rows="6" cols="40">[[[20],["Hi"],"Hi",20]]</textarea><br /><button onclick="result.textContent=JSON.stringify(f(eval(input.value)))">Go</button><pre id="result">``````

Title: Flatten the Array!

Body:
JavaScript (ES6), 41 bytes

f=a=>[].concat(...a.map(v=>v.pop?f(v):v))

<textarea id="input" rows="6" cols="40">[[[20],["Hi"],"Hi",20]]</textarea><br /><button onclick="result.textContent=JSON.stringify(f(eval(input.value)))">Go</button><pre id="result"></pre>


答:
Racket, 63 bytes

(define(f l)(apply append(map(λ(x)(if(list? x)(f x)`(,x)))l)))
```

Title: Flatten the Array!


答:
JavaScript (ES6), 35 bytes

Inspired by @user81655's answer:

```<code>f=a=>a.map?[].concat(...a.map(f)):a
</code>```

Title: Flatten the Array!

Body:
JavaScript (ES6), 35 bytes

Inspired by @user81655's answer:

f=a=>a.map?[].concat(...a.map(f)):a


答:
Retina, 30 bytes

```<code>1>`("(\\.|[^"])+")|[][]
$1
$
]
</code>```

Try it online! (The first line is only used to run multiple test cases at once.)

Retina has no concept of arrays, string literals or numbers, so I decided to go with a "common" input format of [...,...] style arrays and "-delimited strings, where \ can be used inside the strings to escape any character (in particular " and \ itself).

The program itself simply matches either a full string or a square bracket, and replaces them with $1 which keeps strings and removes square brackets. The limit 1> skips the first match so that we don't remove the leading [. However, this does remove the trailing ], so we add it back in in a separate stage.

Title: Flatten the Array!

Body:
Retina, 30 bytes

1>`("(\\.|[^"])+")|[][]
$1
$
]

Try it online! (The first line is only used to run multiple test cases at once.)

Retina has no concept of arrays, string literals or numbers, so I decided to go with a "common" input format of [...,...] style arrays and "-delimited strings, where \ can be used inside the strings to escape any character (in particular " and \ itself).

The program itself simply matches either a full string or a square bracket, and replaces them with $1 which keeps strings and removes square brackets. The limit 1> skips the first match so that we don't remove the leading [. However, this does remove the trailing ], so we add it back in in a separate stage.


答:
Mathematica, <s>16</s> 14 bytes

```<code>{##&@@#&//@#}&
</code>```

An unnamed function which takes and returns a list, e.g.:

```<code>{##&@@#&//@#}& @ {{{20}, {"Hi"}, "Hi", 20}}
(* {20, "Hi", "Hi", 20} *)
</code>```

Explanation

Syntactic sugar party!

To understand how this works, note that every expression in Mathematica is either an atom (e.g. numbers, strings, symbols) or a compound expression of the form f[a, b, c, ...], where f, a, b, c are themselves arbitrary expressions. Here, f is called the head of the expression. Everything else on top of that is just syntactic sugar. E.g. {a, b, c} is just List[a, b, c].

We start with //@ which maps a functions over all levels of a list. For instance:

```<code>f //@ {{{20}, {"Hi"}, "Hi", 20}}
(* f[{f[{f[{f[20]}], f[{f["Hi"]}], f["Hi"], f[20]}]}] *)
</code>```

Note that this maps f over atoms as well as compound expressions. What we're now looking for is a way to get rid of the list heads and keep everything else.

The Apply function is normally used to feed the elements of a list as separate arguments to a function, but its actual definition is more general and simply replaces the head of an expression. E.g. Apply[g, f[a, b]] gives g[a, b].

Now there's a special "head" called Sequence that simply vanishes. E.g. {a, Sequence[b, c], d} just evaluates to {a, b, c, d}. The idea for flattening the list is to replace the heads of all inner lists with Sequence so that they get splatted into their surrounding list. So what we want is to Apply the head Sequence to the lists. Conveniently if we Apply something to an atom, it just leaves the atom unchanged, so we don't have to distinguish between types of expressions at all.

Finally, there's one small issue: f is also applied to the outermost level, so that it also removes the outermost List, which we don't want. The shortest way to counter that is simply to wrap the result in a list again, such that the surrounding Sequence can safely vanish.

Note that there's neither Apply nor Sequence in the code. @@ is an operator form of Apply and ##& is a standard golfing trick to shorten the long built-in name Sequence. So ungolfing everything a bit, we get something like:

```<code>flatten[list_] := { MapAll[Apply[Sequence], list] }
</code>```

For more details on how and why the ##& works, see the section on "Sequences of arguments" in my answer for the Mathematica tips.

Title: Flatten the Array!

Body:
Mathematica, <s>16</s> 14 bytes

{##&@@#&//@#}&

An unnamed function which takes and returns a list, e.g.:

{##&@@#&//@#}& @ {{{20}, {"Hi"}, "Hi", 20}}
(* {20, "Hi", "Hi", 20} *)

Explanation

Syntactic sugar party!

To understand how this works, note that every expression in Mathematica is either an atom (e.g. numbers, strings, symbols) or a compound expression of the form f[a, b, c, ...], where f, a, b, c are themselves arbitrary expressions. Here, f is called the head of the expression. Everything else on top of that is just syntactic sugar. E.g. {a, b, c} is just List[a, b, c].

We start with //@ which maps a functions over all levels of a list. For instance:

f //@ {{{20}, {"Hi"}, "Hi", 20}}
(* f[{f[{f[{f[20]}], f[{f["Hi"]}], f["Hi"], f[20]}]}] *)

Note that this maps f over atoms as well as compound expressions. What we're now looking for is a way to get rid of the list heads and keep everything else.

The Apply function is normally used to feed the elements of a list as separate arguments to a function, but its actual definition is more general and simply replaces the head of an expression. E.g. Apply[g, f[a, b]] gives g[a, b].

Now there's a special "head" called Sequence that simply vanishes. E.g. {a, Sequence[b, c], d} just evaluates to {a, b, c, d}. The idea for flattening the list is to replace the heads of all inner lists with Sequence so that they get splatted into their surrounding list. So what we want is to Apply the head Sequence to the lists. Conveniently if we Apply something to an atom, it just leaves the atom unchanged, so we don't have to distinguish between types of expressions at all.

Finally, there's one small issue: f is also applied to the outermost level, so that it also removes the outermost List, which we don't want. The shortest way to counter that is simply to wrap the result in a list again, such that the surrounding Sequence can safely vanish.

Note that there's neither Apply nor Sequence in the code. @@ is an operator form of Apply and ##& is a standard golfing trick to shorten the long built-in name Sequence. So ungolfing everything a bit, we get something like:

flatten[list_] := { MapAll[Apply[Sequence], list] }

For more details on how and why the ##& works, see the section on "Sequences of arguments" in my answer for the Mathematica tips.


问:
How should you arrange your chairs?
You teach a class of students with interesting preferences for how their chairs are arranged. There are 3 very specific requirements they have for how the chairs are arranged:

They most be arranged in a rectangle, even if it means some chairs go empty.

There must be as few empty chairs as possible.

They must be as "squarey" as possible. Squarey-ness is determined by the distance between the width and the height of the rectangle, lower is better. For example, a rectangle that is 4x7 has a squarey-ness of 3.

To be more specific, the "score" of an arrangement is the distance between the width and height plus the number of chairs that would go empty.

Let's take an example. Let's say you have 13 students. You could arrange the chairs any of these ways:

```<code>1x13
2x7
3x5
4x4
</code>```

1x13 is not very squarey. In fact, 1 and 13 are 12 apart, so we give this arrangement 12 points. It also has 0 empty chairs, so we add 0 points, giving this arrangement a score of 12. Not that great.

2x7 is certainly better. 2 and 7 are only 5 apart, so we give this arrangement 5 points. However, if you actually arranged 2 rows of seven chairs, that would take 14 chairs, meaning one chair would be empty. So we add one point, giving this arrangement a score of 6.

We could also do 3x5. 3 and 5 are 2 apart, so +2 points. It takes 15 chairs, meaning we'd have two extra chairs, so another +2 points, for a score of 4.

Last option, 4x4. 4 and 4 are 0 apart, so we give this +0 points. 4x4 takes 16 chairs, so 3 chairs go empty, for a total score of 3. This is the optimal solution.

In case of a tie, the optimal solution is the one with less empty chairs.

The challenge

You must write a program or function that takes an integer and outputs the optimal arrangement of chairs for that number of students. IO can be in any reasonable format. Here is sample output for any number of students from 1 to 100:

```<code>1:  (1, 1)
2:  (1, 2)
3:  (2, 2)
4:  (2, 2)
5:  (2, 3)
6:  (2, 3)
7:  (3, 3)
8:  (3, 3)
9:  (3, 3)
10: (2, 5)
11: (3, 4)
12: (3, 4)
13: (4, 4)
14: (4, 4)
15: (4, 4)
16: (4, 4)
17: (3, 6)
18: (3, 6)
19: (4, 5)
20: (4, 5)
21: (3, 7)
22: (5, 5)
23: (5, 5)
24: (5, 5)
25: (5, 5)
26: (4, 7)
27: (4, 7)
28: (4, 7)
29: (5, 6)
30: (5, 6)
31: (4, 8)
32: (4, 8)
33: (6, 6)
34: (6, 6)
35: (6, 6)
36: (6, 6)
37: (5, 8)
38: (5, 8)
39: (5, 8)
40: (5, 8)
41: (6, 7)
42: (6, 7)
43: (5, 9)
44: (5, 9)
45: (5, 9)
46: (7, 7)
47: (7, 7)
48: (7, 7)
49: (7, 7)
50: (5, 10)
51: (6, 9)
52: (6, 9)
53: (6, 9)
54: (6, 9)
55: (7, 8)
56: (7, 8)
57: (6, 10)
58: (6, 10)
59: (6, 10)
60: (6, 10)
61: (8, 8)
62: (8, 8)
63: (8, 8)
64: (8, 8)
65: (6, 11)
66: (6, 11)
67: (7, 10)
68: (7, 10)
69: (7, 10)
70: (7, 10)
71: (8, 9)
72: (8, 9)
73: (7, 11)
74: (7, 11)
75: (7, 11)
76: (7, 11)
77: (7, 11)
78: (9, 9)
79: (9, 9)
80: (9, 9)
81: (9, 9)
82: (7, 12)
83: (7, 12)
84: (7, 12)
85: (8, 11)
86: (8, 11)
87: (8, 11)
88: (8, 11)
89: (9, 10)
90: (9, 10)
91: (7, 13)
92: (8, 12)
93: (8, 12)
94: (8, 12)
95: (8, 12)
96: (8, 12)
97: (10, 10)
98: (10, 10)
99: (10, 10)
100: (10, 10)
</code>```

As usual, this is code-golf, so standard loopholes apply, and the winner is the shortest answer in bytes.

答:
Pyth, <s>24</s> <s>22</s> 21 bytes

Edit: in the sorting key, I realize that there is no need to find the number of empty chairs. It is equivalent to score the total number of chairs. This saved me 2 bytes.

```<code>h.m_+B*FbaFbm,d.EcQdS
</code>```

Try it online!

Title: How should you arrange your chairs?

Body:
Pyth, <s>24</s> <s>22</s> 21 bytes

Edit: in the sorting key, I realize that there is no need to find the number of empty chairs. It is equivalent to score the total number of chairs. This saved me 2 bytes.

h.m_+B*FbaFbm,d.EcQdS

Try it online!


答:
JavaScript (Firefox 30-57), 43 bytes

```<code>f=a=>a.map?[for(b of a)for(c of f(b))c]:[a]
</code>```

Just because I could even avoid using concat.

Title: Flatten the Array!

Body:
JavaScript (Firefox 30-57), 43 bytes

f=a=>a.map?[for(b of a)for(c of f(b))c]:[a]

Just because I could even avoid using concat.


问:
Restricted average (arithmetic mean) – i.e. without obvious built-ins

Introduction

The arithmetic mean is defined as being equal to the sum of the numerical values of each and every observation divided by the total number of observations. Symbolically, if we have a data set containing the values a1,…,an. The arithmetic mean A is defined by the formula

Objective

The challenge here is, given a non-empty list of observations, to calculate the arithmetic mean without any built-ins for mean, sum, division, or count. All other operations are allowed, e.g. median, product, multiplication, and sequence generation.

If your language cannot process lists without knowing the number of elements it has, you may use a counting built-in for such (looping, loading, etc.) purpose only, but not for the actual computation.

Test cases

[5] → 5

[1,-2] → -0.5

[6,1,3] → 3.333333333

If your language can handle complex numbers:

[5,1+3i] → 3+1.5i

答:
Pyth, 13 bytes

```<code>l@*F^L2Qhe.ek
</code>```

Try it online!

Uses exponential arithmetic to replace sum and division.

Uses enumerate to find number of elements.

Body:
Pyth, 13 bytes

l@*F^L2Qhe.ek

Try it online!

Uses exponential arithmetic to replace sum and division.

Uses enumerate to find number of elements.


答:
Retina, <s>46</s> 37 bytes

```
+`x;
;x
;x
;;:x
;
x
^(x+):(\1)*x*
$#2
```

Try it online!

It's quite a trouble not to use arithmetic...

Title: Restricted average (arithmetic mean) – i.e. without obvious built-ins

Body:
Introduction

The arithmetic mean is defined as being equal to the sum of the numerical values of each and every observation divided by the total number of observations. Symbolically, if we have a data set containing the values a1,…,an. The arithmetic mean A is defined by the formula

Objective

The challenge here is, given a non-empty list of observations, to calculate the arithmetic mean without any built-ins for mean, sum, division, or count. All other operations are allowed, e.g. median, product, multiplication, and sequence generation.

If your language cannot process lists without knowing the number of elements it has, you may use a counting built-in for such (looping, loading, etc.) purpose only, but not for the actual computation.

Test cases

[5] → 5

[1,-2] → -0.5

[6,1,3] → 3.333333333

If your language can handle complex numbers:

[5,1+3i] → 3+1.5i

Body:
Retina, <s>46</s> 37 bytes

+`x;
;x
;x
;;:x
;
x
^(x+):(\1)*x*
$#2

Try it online!

It's quite a trouble not to use arithmetic...


答:
Matlab(174)(146)121

```<code>  function g(n),f=@(n,i)ceil(n/i);x=[];for i=1:n,x=[sortrows(x); f(n,i)*i-1/(f(n,i)*i)+abs(f(n,i)-i) i f(n,i)];end,x(1,2:3)
</code>```

trick 1: i added the amount 1-1/length*width as tie-scoring

trick 2: i calculated number_students/length ceiled for the width of rectangle, <s>upper bound is the square but ceiled too</s>

I'm sure it can be golfed further ...

try it

Edit : referenced to @StewieGriffin 's remarks .

Edit 2 :

1 and n are constants no need to add 'em to the overall score.

A function is few bytes less than stdin standalone program.

I used ascendent sorting technique it saves too much bytes though.

Edit 3: peformance test.

Title: How should you arrange your chairs?

Body:
You teach a class of students with interesting preferences for how their chairs are arranged. There are 3 very specific requirements they have for how the chairs are arranged:

They most be arranged in a rectangle, even if it means some chairs go empty.

There must be as few empty chairs as possible.

They must be as "squarey" as possible. Squarey-ness is determined by the distance between the width and the height of the rectangle, lower is better. For example, a rectangle that is 4x7 has a squarey-ness of 3.

To be more specific, the "score" of an arrangement is the distance between the width and height plus the number of chairs that would go empty.

Let's take an example. Let's say you have 13 students. You could arrange the chairs any of these ways:

```<code>1x13
2x7
3x5
4x4
</code>```

1x13 is not very squarey. In fact, 1 and 13 are 12 apart, so we give this arrangement 12 points. It also has 0 empty chairs, so we add 0 points, giving this arrangement a score of 12. Not that great.

2x7 is certainly better. 2 and 7 are only 5 apart, so we give this arrangement 5 points. However, if you actually arranged 2 rows of seven chairs, that would take 14 chairs, meaning one chair would be empty. So we add one point, giving this arrangement a score of 6.

We could also do 3x5. 3 and 5 are 2 apart, so +2 points. It takes 15 chairs, meaning we'd have two extra chairs, so another +2 points, for a score of 4.

Last option, 4x4. 4 and 4 are 0 apart, so we give this +0 points. 4x4 takes 16 chairs, so 3 chairs go empty, for a total score of 3. This is the optimal solution.

In case of a tie, the optimal solution is the one with less empty chairs.

The challenge

You must write a program or function that takes an integer and outputs the optimal arrangement of chairs for that number of students. IO can be in any reasonable format. Here is sample output for any number of students from 1 to 100:

```<code>1:  (1, 1)
2:  (1, 2)
3:  (2, 2)
4:  (2, 2)
5:  (2, 3)
6:  (2, 3)
7:  (3, 3)
8:  (3, 3)
9:  (3, 3)
10: (2, 5)
11: (3, 4)
12: (3, 4)
13: (4, 4)
14: (4, 4)
15: (4, 4)
16: (4, 4)
17: (3, 6)
18: (3, 6)
19: (4, 5)
20: (4, 5)
21: (3, 7)
22: (5, 5)
23: (5, 5)
24: (5, 5)
25: (5, 5)
26: (4, 7)
27: (4, 7)
28: (4, 7)
29: (5, 6)
30: (5, 6)
31: (4, 8)
32: (4, 8)
33: (6, 6)
34: (6, 6)
35: (6, 6)
36: (6, 6)
37: (5, 8)
38: (5, 8)
39: (5, 8)
40: (5, 8)
41: (6, 7)
42: (6, 7)
43: (5, 9)
44: (5, 9)
45: (5, 9)
46: (7, 7)
47: (7, 7)
48: (7, 7)
49: (7, 7)
50: (5, 10)
51: (6, 9)
52: (6, 9)
53: (6, 9)
54: (6, 9)
55: (7, 8)
56: (7, 8)
57: (6, 10)
58: (6, 10)
59: (6, 10)
60: (6, 10)
61: (8, 8)
62: (8, 8)
63: (8, 8)
64: (8, 8)
65: (6, 11)
66: (6, 11)
67: (7, 10)
68: (7, 10)
69: (7, 10)
70: (7, 10)
71: (8, 9)
72: (8, 9)
73: (7, 11)
74: (7, 11)
75: (7, 11)
76: (7, 11)
77: (7, 11)
78: (9, 9)
79: (9, 9)
80: (9, 9)
81: (9, 9)
82: (7, 12)
83: (7, 12)
84: (7, 12)
85: (8, 11)
86: (8, 11)
87: (8, 11)
88: (8, 11)
89: (9, 10)
90: (9, 10)
91: (7, 13)
92: (8, 12)
93: (8, 12)
94: (8, 12)
95: (8, 12)
96: (8, 12)
97: (10, 10)
98: (10, 10)
99: (10, 10)
100: (10, 10)
</code>```

As usual, this is code-golf, so standard loopholes apply, and the winner is the shortest answer in bytes.

Body:
Matlab(174)(146)121

  function g(n),f=@(n,i)ceil(n/i);x=[];for i=1:n,x=[sortrows(x); f(n,i)*i-1/(f(n,i)*i)+abs(f(n,i)-i) i f(n,i)];end,x(1,2:3)

trick 1: i added the amount 1-1/length*width as tie-scoring

trick 2: i calculated number_students/length ceiled for the width of rectangle, <s>upper bound is the square but ceiled too</s>

I'm sure it can be golfed further ...

try it

Edit : referenced to @StewieGriffin 's remarks .

Edit 2 :

1 and n are constants no need to add 'em to the overall score.

A function is few bytes less than stdin standalone program.

I used ascendent sorting technique it saves too much bytes though.

Edit 3: peformance test.


Title: How should you arrange your chairs?

Body:
JavaSCript (ES6), 83 bytes

n=>[...Array(m=n)].map((_,i)=>(d=(n+i++)/i|0)>i||(s=i*d-n+i-d)>m||(m=s,r=[d,i]))&&r