问:
Print every character your program doesn't have
Your task is to build a program (using only printable ASCII characters and/or tabs and newlines) that prints out exactly the characters in the printable ASCII space (0x20 to 0x7e) that don't appear in your program's source code (in any order, however many times you want).

The shortest code to do this in any language wins.

Body:
Mathematica 71 bytes

Taking as the range of "printable" characters ASCII 32-126, this takes the complement of the full set of characters (CharacterRange[32, 126]) and the used set of characters ("Charactes@Rngplm[32,16]").

Complement[CharacterRange[32, 126],Characters@"Charactes@Rngplm[32,16]"]

{"!", "#", "%", "^", "&", "*", "(", ")", "_", "-", "+", "=", "~",
"`", "{", "}", "|", "\", "<", ">", ".", ";", "\"", "?", "'", "/",
":", " ", "0", "4", "5", "7", "8", "9", "A", "b", "B", "d", "D", "E",
"f", "F", "G", "H", "i", "I", "j", "J", "k", "K", "L", "M", "N", "o",
"O", "P", "q", "Q", "S", "T", "u", "U", "v", "V", "w", "W", "x", "X",
"y", "Y", "z", "Z", "$"}


问:
How many steps does it take from n to 1 by subtracting the greatest divisor?
Inspired by this question over at Mathematics.

The Problem

Let n be a natural number ≥ 2. Take the biggest divisor of n – which is different from n itself – and subtract it from n. Repeat until you get 1.

The Question

How many steps does it take to reach 1 for a given number n ≥ 2.

Detailed Example

Let n = 30.

The greatest divisor of:

```<code>1.   30 is 15  -->  30 - 15 = 15
2.   15 is  5  -->  15 -  5 = 10
3.   10 is  5  -->  10 -  5 =  5
4.    5 is  1  -->   5 -  1 =  4
5.    4 is  2  -->   4 -  2 =  2
6.    2 is  1  -->   2 -  1 =  1
</code>```

It takes 6 steps to reach 1.

Input

Input is an integer n, where n ≥ 2.

Your program should support input up to the language's maximum integer value.

Output

Simply output the number of steps, like 6.

Leading/trailing whitespaces or newlines are fine.

Examples

```<code>f(5)        --> 3
f(30)       --> 6
f(31)       --> 7
f(32)       --> 5
f(100)      --> 8
f(200)      --> 9
f(2016^155) --> 2015
</code>```

Requirements

You can get input from STDIN, command line arguments, as function parameters or from the closest equivalent.

You can write a program or a function. If it is an anonymous function, please include an example of how to invoke it.

This is code-golf so shortest answer in bytes wins.

Standard loopholes are disallowed.

This series can be found on OEIS as well: A064097

A quasi-logarithm defined inductively by a(1) = 0 and a(p) = 1 + a(p-1) if p is prime and a(n*m) = a(n) + a(m) if m,n > 1.

答:
Pyke, 11 bytes (noncompeting)

```<code>D3Phf-oRr;o
</code>```

This uses a new behaviour where if there is an exception raised after a goto, it restores the state from before the goto (except variable definitions) and continues. In this case it is equivalent to the following python code:

```<code># Implicit input and variable setup
inp = input()
o = 0
# End implicit
try:
    while 1:
        inp -= factors(inp)[0] # If factors is called on the value 1, it returns an empty
                               # list which when the first element tries to be accessed
                               # raises an exception
        o += 1 # Using `o` returns the current value of `o` and increments it
except:
    print o # This in effect gets the number of times the loop went
</code>```

This is all possible using Pyke without a while loop construction - yay goto!

Try it here!

ContentLicense: CC BY-SA 3.0

Body:
Pyke, 11 bytes (noncompeting)

D3Phf-oRr;o

This uses a new behaviour where if there is an exception raised after a goto, it restores the state from before the goto (except variable definitions) and continues. In this case it is equivalent to the following python code:

# Implicit input and variable setup
inp = input()
o = 0
# End implicit
try:
    while 1:
        inp -= factors(inp)[0] # If factors is called on the value 1, it returns an empty
                               # list which when the first element tries to be accessed
                               # raises an exception
        o += 1 # Using `o` returns the current value of `o` and increments it
except:
    print o # This in effect gets the number of times the loop went

This is all possible using Pyke without a while loop construction - yay goto!

Try it here!


问:
Shortest paths in a divisor graph

Introduction

In this challenge, we will be dealing with a certain infinite undirected graph, which I call the high divisor graph.
Its nodes are the integers starting from 2.
There is an edge between two nodes a < b if a divides b and a2 ≥ b.
The subgraph formed by the range from 2 to 18 looks like this:

```<code>16-8 12 18
  \|/ |/|
   4  6 9 10 15 14
   |  |/   |/   |
   2  3    5    7  11 13 17
</code>```

It can be shown that the infinite high divisor graph is connected, so we can ask about the shortest path between two nodes.

Input and output

Your inputs are two integers a and b.
You can assume that 2 ≤ a ≤ b < 1000.
Your output is the length of the shortest path between a and b in the infinite high divisor graph.
This means the number of edges in the path.

You may find the following fact useful: there always exists an optimal path from a to b that's first increasing and then decreasing, and only visits nodes that are strictly less than 2b2.
In particular, since b < 1000 you only need to consider nodes less than 2 000 000.

Examples

Consider the inputs 3 and 32.
One possible path between the nodes 3 and 32 is

```<code>3 -- 6 -- 12 -- 96 -- 32
</code>```

This path has four edges, and it turns out there are no shorter paths, so the correct output is 4.

As another example, an optimal path for 2 and 25 is

```<code>2 -- 4 -- 8 -- 40 -- 200 -- 25
</code>```

so the correct output is 5.
In this case, no optimal path contains the node 50 = lcm(2, 25).

Rules and scoring

You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
There are no time or memory limits, so brute forcing is allowed.

Test cases

```<code>2 2 -> 0
2 3 -> 4
2 4 -> 1
2 5 -> 5
3 5 -> 4
6 8 -> 2
8 16 -> 1
12 16 -> 2
16 16 -> 0
2 25 -> 5
3 32 -> 4
2 256 -> 3
60 77 -> 3
56 155 -> 3
339 540 -> 2
6 966 -> 4
7 966 -> 2
11 966 -> 4
2 997 -> 7
991 997 -> 4
</code>```

答:
Matlab, <s>218</s> <s>190</s> 175 bytes

```<code>function f(a,b);q=a;l(b)=0;l(a)=1;while~l(b);x=q(1);q=q(2:end);l(end+1:x^2)=0;g=x+1:x^2;s=2:x-1;u=[g(~mod(g,x)),s(~mod(x,s)&s.^2>=x)];u=u(~l(u));q=[q,u];l(u)=l(x)+1;end;l(b)-1
</code>```

Thanks @beaker for the shortcut in in the list lengthening step!

This is a relatively straightforward dijkstra implementation:

```<code>q=a;                  %queue
l(b)=0;       %list of path lengths
l(a)=1;
while~l(b);         %if there is no predecessor to b
    x=q(1);         %get first queue element
    q=q(2:end);
    %add edges
    l(end+1:x^2)=0;% lengthen predecessor list if too short
    g=x+1:x^2;      % g=greater neighbours
    s=2:x-1;        % s=smaller neighbours %keep only valid/unvisited neighbours
    u=[g(~mod(g,x)),s(~mod(x,s)&s.^2>=x)]; %-1byte
    u=u(~l(u));
    q=[q,u];      %add only hte valid nodes edges to queue
    l(u)=l(x)+1;       %mark x as predecessor
end;
l(b)-1 %output length to the end of the path
</code>```

 no convolution today

Title: Shortest paths in a divisor graph

Body:
Matlab, <s>218</s> <s>190</s> 175 bytes

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

Thanks @beaker for the shortcut in in the list lengthening step!

This is a relatively straightforward dijkstra implementation:

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

 no convolution today


问:
Largest Number Printable
Your goal is to write a program that prints a number. The bigger the number, the more points you'll get. But be careful! Code length is both limited and heavily weighted in the scoring function. Your printed number will be divided by the cube of the number of bytes you used for your solution.

So, let's say you printed 10000000 and your code is 100 bytes long. Your final score will be \$\frac {10000000} {100^3} = 10\$.

There are other rules to follow, in order to make this challenge a bit harder.

You cannot use digits in your code (0123456789);

You can use mathematical/physical/etc. constants, but only if they are less than 10. (e.g. You can use \$\pi \approx 3.14\$ but you can't use the Avogadro constant \$= 6\times 10^{23}\$)

Recursion is allowed but the generated number needs to be finite (so infinite is not accepted as a solution. Your program needs to terminate correctly, assuming unbounded time and memory, and generate the requested output);

You cannot use the operations * (multiply), / (divide), ^ (power) nor any other way to indicate them (e.g. 2 div 2 is not allowed);

Your program can output more than one number, if you need it to do that. Only the highest one will count for scoring;

However, you can concatenate strings: this means that any sequence of adjacent digits will be considered as a single number;

Your code will be run as-is. This means that the end-user cannot edit any line of code, nor he can input a number or anything else;

Maximum code length is 100 bytes.

Leaderboard

Steven H., Pyth \$\approx f_{\varphi(1,0,0)+7}(256^{26})\$

Simply Beautiful Art, Ruby \$\approx f_{\varphi(1,0,0)}(3)\$

Peter Taylor, GolfScript \$\approx f_{\varepsilon_0+\omega+1}(17)\$

r.e.s., GolfScript \$\approx f_{\epsilon_0}^9(126)\approx f_{\epsilon_0+1}(9)\$ [1]

Simply Beautiful Art, Ruby \$\approx f_{\omega^{\omega2}+1}(126^22^{126})\$

eaglgenes101, Julia \$\approx f_{\omega^3}(127)\$

col6y, Python 3, \$\approx 127\to126\to\dots\to2\to1\approx f_{\omega^2}(127)\$ [1][3]

Toeofdoom, Haskell, \$\approx a_{20}(1)\approx f_{\omega+1}(18)\$ [1]

Fraxtil, dc, \$\approx 15\uparrow^{166665}15\$ [3]

Magenta, Python, \$\approx\mathrm{ack}(126,126)\approx10\uparrow^{124}129\$

Kendall Frey, ECMAScript 6, \$\approx1000\uparrow^43\$ [1]

Ilmari Karonen, GolfScript, \$\approx10\uparrow^310^{377}\$ [1]

Aiden4, Rust, \$\approx10\uparrow^3127\$

BlackCap, Haskell, \$\approx10\uparrow\uparrow65503\$

recursive, Python, \$\approx2\uparrow\uparrow11\approx10\uparrow\uparrow8.63297\$ [1][3]

n.m., Haskell, \$\approx2\uparrow\uparrow7\approx10\uparrow\uparrow4.63297\$ [1]

David Yaw, C, \$\approx10^{10^{4\times10^{22}}}\approx10\uparrow\uparrow4.11821\$ [2]

primo, Perl, \$\approx10^{(12750684161!)^{5\times2^{27}}}\approx10\uparrow\uparrow4.11369\$

Art, C, \$\approx10^{10^{2\times10^6}}\approx10\uparrow\uparrow3.80587\$

Robert Sørlie, x86, \$\approx10^{2^{2^{19}+32}}\approx10\uparrow\uparrow3.71585\$

Tobia, APL, \$\approx10^{10^{353}}\approx10\uparrow\uparrow3.40616\$

Darren Stone, C, \$\approx10^{10^{97.61735}}\approx10\uparrow\uparrow3.29875\$

ecksemmess, C, \$\approx10^{2^{320}}\approx10\uparrow\uparrow3.29749\$

Adam Speight, vb.net, \$\approx10^{5000\times2^{256}}\approx10\uparrow\uparrow3.28039\$

Joshua, bash, \$\approx10^{10^{15}}\approx10\uparrow\uparrow3.07282\$

Footnotes

If every electron in the universe were a qubit, and every superposition thereof could be gainfully used to store information (which, as long as you don't actually need to know what's being stored is theoretically possible), this program requires more memory than could possibly exist, and therefore cannot be run - now, or at any conceiveable point in the future. If the author intended to print a value larger than ≈10↑↑3.26 all at once, this condition applies.

This program requires more memory than currently exists, but not so much that it couldn't theoretically be stored on a meager number of qubits, and therefore a computer may one day exist which could run this program.

All interpreters currently available issue a runtime error, or the program otherwise fails to execute as the author intended.

Running this program will cause irreparable damage to your system.

Edit @primo: I've updated a portion of the scoreboard using a hopefully easier to compare notation, with decimals to denote the logarithmic distance to the next higher power. For example \$10↑↑2.5 = 10^{10^{\sqrt {10}}}\$. I've also changed some scores if I believed to user's analysis to be faulty, feel free to dispute any of these.

Explanation of this notation:

If \$0 \le b \lt 1\$, then \$a \uparrow\uparrow b = a^b\$.

If \$b \ge 1\$, then \$a \uparrow\uparrow b = a^{a \uparrow\uparrow (b-1)}\$.

If \$b \lt 0\$, then \$a \uparrow\uparrow b = \log_a(a \uparrow\uparrow (b+1))\$

An implementation of this notation is provided in Python that let's you test reasonably sized values.

答:
Lua, Unknown/99^3 ≈ 10↑↑2.945956159

With infinite runtime:

m=math;p=m.pi;t=m.floor(p)s=tostring;h=t+s(p):sub(t)j=h;while(j>t)do io.write(s(h):rep(h))j=j-t;end
```
<p>< 5 seconds:</p>
<pre class="lang-lua prettyprint-override"><code>m=math;p=m.pi;t=m.ceil(p)s=tostring;h=t+s(p):sub(-t)j=h;while(j>t)do io.write(s(h):rep(h))j=j-t;end
</code>```

Ungolfed:

t=math.ceil(math.pi)                -- Acquire the number 4
h=t+tostring(math.pi):sub(-t)       -- Get the last t(4) digits of pi(5898) as a string.
                                    -- Adding t auto converts it to a number and increases our number
j=h;                                -- Set j as a counter to loop
while(j>t)do
    io.write(tostring(h):rep(h))    -- Add h(5902) repitions of h as a string to the output
    j=j-t;                          -- Decrement j by t(4), my only number available
end
```

Extra

Lua's lack of mathematical constants (other than pi) and ++ or -- operators made it tricky to manipulate numbers, but I thought I made good work with what I have. string.rep is the real hero.

If there's a notation that exists to write my score, I'll include it, but I don't know of one. If I was thinking correctly, the < 5 code's number should be (5902 repeated 5902 times) repeated ~5902/4 times.

ContentLicense: CC BY-SA 4.0

Title: Largest Number Printable

Body:
Lua, Unknown/99^3 ≈ 10↑↑2.945956159

With infinite runtime:

m=math;p=m.pi;t=m.floor(p)s=tostring;h=t+s(p):sub(t)j=h;while(j>t)do io.write(s(h):rep(h))j=j-t;end

< 5 seconds:

m=math;p=m.pi;t=m.ceil(p)s=tostring;h=t+s(p):sub(-t)j=h;while(j>t)do io.write(s(h):rep(h))j=j-t;end

Ungolfed:

t=math.ceil(math.pi)                -- Acquire the number 4
h=t+tostring(math.pi):sub(-t)       -- Get the last t(4) digits of pi(5898) as a string.
                                    -- Adding t auto converts it to a number and increases our number
j=h;                                -- Set j as a counter to loop
while(j>t)do
    io.write(tostring(h):rep(h))    -- Add h(5902) repitions of h as a string to the output
    j=j-t;                          -- Decrement j by t(4), my only number available
end

Extra

Lua's lack of mathematical constants (other than pi) and ++ or -- operators made it tricky to manipulate numbers, but I thought I made good work with what I have. string.rep is the real hero.

If there's a notation that exists to write my score, I'll include it, but I don't know of one. If I was thinking correctly, the < 5 code's number should be (5902 repeated 5902 times) repeated ~5902/4 times.


答:
Lua, 94 bytes

```<code>f="l=...for i=32,126 do c=string.char(i)io.write(l:find(c,0,1)and\"\"or c)end"loadstring(f)(f)
</code>```

Writes the algorithm in a string and uses loadstring to run it as a function passing in its string definition as the argument.

Title: Print every character your program doesn't have

Body:
Your task is to build a program (using only printable ASCII characters and/or tabs and newlines) that prints out exactly the characters in the printable ASCII space (0x20 to 0x7e) that don't appear in your program's source code (in any order, however many times you want).

The shortest code to do this in any language wins.

Body:
Lua, 94 bytes

f="l=...for i=32,126 do c=string.char(i)io.write(l:find(c,0,1)and\"\"or c)end"loadstring(f)(f)

Writes the algorithm in a string and uses loadstring to run it as a function passing in its string definition as the argument.


问:
Is the electric garage door open?
My electric garage door works like this:

There is just one push button to control the door

If the door is fully closed and I hit the button, the door starts to open.  It takes 10 seconds to open fully

If the door is fully open and I hit the button, the door starts to close.  It takes 10 seconds to close fully

If the door is part way through opening or closing and I hit the button, then the door stops and is left partially open.

Whenever the door stops moving, either from automatic completion of an open or close action, or from manual interruption by pushing the button partway through an action, then the mechanism will reverse and remember its direction for the next action.

If the button is pushed when the door is stopped but partially open, then the amount of time for it to complete its action will be a fraction of 10 seconds in proportion to the amount it needs to move to complete the action.

Assume the door is fully closed at the start.

An input list of integers will be given.  These integers are the number of seconds I wait between successive pushes of the control button.

Output two things:

a percentage indicating the state of the door once all button pushes are completed and the door has reached a steady state.  Output of % symbol is optional.

an unambiguous indication of what direction the door will travel on the next button push.  This may be up/down, U/D, +/-, 1/0 or whatever you choose.

You may assume the door takes infinitesimally less than 10 seconds to complete an open or close action.

Example inputs:

```<code><empty list>  # button was pushed just once
20            # button was pushed twice with 20 seconds between
10
5
20 20
10 10
5 5
1 2 3
8 9 10 11
11 10 9 8 7
</code>```

Expected outputs corresponding to above inputs

```<code>100% D
0% U
0% U
50% D
100% D
100% D
0% U
100% D
0% U
20% U
</code>```

Worked example of the last test

Door starts off closed.  Button is pushed

Wait 11 seconds.  Door ends up fully opened.  Button is pushed.

Wait 10 seconds.  Door ends up fully closed.  Button is pushed.

Wait 9 seconds.  Button is pushed.  Door stops at 90% open.

Wait 8 seconds.  Button is pushed.  Door starts to close.

Wait 7 seconds.  Button is pushed.  Door stops at 20% open.  Next direction will be up.

Title: Is the electric garage door open?

Body:
Ruby, 152 bytes

->v{u,s,a=!!1,!0,0;v.map{|w|!s ?(a=u ? a+w : a-w;a>=10 ?(s,a=!!1,10):a<=0 ?(s,a=!!1,0):0;u,s=!u,!s):s=!0};!s ?(a=(u=!u)?0:10):0;p"#{10*a}% #{u ??U:?D}"}

Test cases:

f=->v{u,s,a=!!1,!0,0;v.map{|w|!s ?(a=u ? a+w : a-w;a>=10 ?(s,a=!!1,10):a<=0 ?(s,a=!!1,0):0;u,s=!u,!s):s=!0};!s ?(a=(u=!u)?0:10):0;p"#{10*a}% #{u ??U:?D}"}

f[[]]            # => "100% D"
f[[20]]          # => "0% U"
f[[10]]          # => "0% U"
f[[5]]           # => "50% D"
f[[20,20]]       # => "100% D"
f[[10,10]]       # => "100% D"
f[[5,5]]         # => "0% U"
f[[1,2,3]]       # => "100% D"
f[[8,9,10,11]]   # => "0% U"
f[[11,10,9,8,7]] # => "20% U"


问:
Calculate the Fermat Point of a Triangle
This is somewhat similar to The centers of a triangle, but with a different point. The Fermat Point is the point P in triangle ABC such that the value of AP + BP + CP is minimized. There are two cases:

If there is an angle greater than 120 degrees, that vertex is the fermat point. Otherwise, draw equilateral triangles on each of the sides of ABC. Connect the far vertex of each equilateral triangle to the opposite vertex of triangle ABC. Doing this for each of the three equilateral triangles results in a single common point of intersection for all three lines, which is the Fermat Point.

It should run within 5 seconds on a reasonable machine.

Input: A set of 3 points, not necessarily integers. This can be taken as a nested array, string, list of tuples, etc. (whatever suits your language).

Output: The coordinates of the Fermat point, again, however your language best handles points. Floating point inaccuracies will not be counted against you.

Test Cases:

```<code>[[1, 1], [2, 2], [1, 2]] --> [1.2113248654051871, 1.788675134594813]
[[-1, -1], [-2, -1], [0, 0]] --> [-1, -1]
[[-1, -1], [1, -1], [0, 1]] --> [0, -0.42264973081037427]
[[0, 0], [0.5, 0.8660254037844386], [-5, 0]] --> [0, 0]
[[0, 0], [0, -5], [-0.8660254037844386, 0.5]] --> [0, 0]
</code>```

This is code golf so shortest code wins!

答:
Mathematica, 39 bytes

```<code>Sum[Norm[p-{x,y}],{p,#}]~NArgMin~{x,y}&
</code>```

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

Body:
Mathematica, 39 bytes

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

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


问:
Count up forever
Write a program that counts up forever, starting from one.

Rules:

Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.

Your program must be a full, runnable program, and not a function or snippet.

Your program must output each number with a separating character in between (a newline, space, tab or comma), but this must be consistent for all numbers.

You may print the numbers in decimal, in unary or in base 256 where each digit is represented by a byte value.

Your program must count at least as far as 2128 (inclusive) without problems and without running out of memory on a reasonable desktop PC. In particular, this means if you're using unary, you cannot store a unary representation of the current number in memory.

Unlike our usual rules, feel free to use a language (or language version) even if it's newer than this challenge. Languages specifically written to submit a 0-byte answer to this challenge are fair game but not particularly interesting.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

This is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

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 snippet:

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Node.js + Big.js, 63 bytes

Use npm install big.js before running.

```<code>c=new require("big.js")(0);while(1)console.log(c+""),c=c.add(1)
</code>```

Simple enough, and has arbitrary precision. Each number is seperated by newlines.

Title: Count up forever

Body:
Node.js + Big.js, 63 bytes

Use npm install big.js before running.

c=new require("big.js")(0);while(1)console.log(c+""),c=c.add(1)

Simple enough, and has arbitrary precision. Each number is seperated by newlines.


问:
KOTH: Every coin has two sides
Final results available

Introduction

After my previous KOTH with heavy themes (fantasy war, worldwide pandemic...), I'm back with a new lighthearted game. This time, you are facing off in a "board game-like" situation. A pile of upside down coins is placed at the center of a really big table, and you are determined to get your share of the loot!

Glossary

Coins: Tokens that can either be flipped or unflipped.

  Unflipped: Coins placed on the table with their value pointing down. This is the default state of the coins.

  Flipped: Coins placed on the table with their value pointing up.

  Local: Refers to your pile of coins.

  Global: Refers to the pile of coins at the center.

Principle

At the start of the game, each player starts with 0 points and 0 coins (flipped or unflipped). The game is turn-based. During their turn, players can take up to 3 actions interacting either with the pile of coins at the center of the table, their own pile of coins or with other players.

Play order is defined randomly at the start of the game. The order of the players in the argument list represents the turn order, and it goes from left to right in that list. "Next" and "Previous" refer respectively to "on the right in that list" and "on the left in that list" with a loop if you're the last of either side.

The game lasts for 50 rounds or until there are 0 coins at the center at the end of a player turn (meaning that you will finish your 3 actions even if the pile is empty after your first action, and you can put back coins to let the game continue). The starting number of global coins is defined randomly with this formula:

```<code>(2 ^ nb_players) + (nb_players * 10) - random(1 + (nb_players ^ 2))`
</code>```

Each action will get you points (or make you lose some) and at the end of the game, each coin you have will be added to your points (-1 for unflipped, +2 for flipped). The player with the highest score wins.

The controller provides you with input via command arguments, and your program has to output via stdout.

Syntax

Input

Each time your program is called, it will receive arguments in this format:

Round;YourPlayerId;Coins;PlayerId_Points_Flipped_Unflipped;PlayerId_Points_Flipped_Unflipped;...

Rounds are 1-indexed.

Example input

6;2;52;1_20_3_12;0_-2_0_1;2_12_1_0

Here, you see it is the 6th round and you are player 2. There are 52 coins in the central pile. You have 12 points, 1 flipped coin and 0 unflipped coin. Points can be negative.

Output

You have to output three characters (no space, no separator), which each correspond to one action you'll take this turn. The order of the characters determine the order of the actions. You can output the same actions multiple times. In case there is not enough coins to complete your action, it will use the maximum of available coins and count points only for the coins used.

N: Do Nothing

1: Take 1 coin from the central pile [Effects: +1 local unflipped / -1 point / -1 global unflipped]

2: Take 2 coins from the central pile [Effects: +2 local unflipped / -2 points / -2 global unflipped]

3: Take 3 coins from the central pile [Effects: +3 local unflipped / -3 points / -3 global unflipped]

A: Put back 1 coin from your pile [Effects: -1 local unflipped / +1 point / +1 global unflipped]

B: Put back 2 coins from your pile [Effects: -2 local unflipped / +2 points / +2 global unflipped]

C: Put back 3 coins from your pile [Effects: -3 local unflipped / +3 points / +3 global unflipped]

X: Remove 1 coin from your pile [Effects: -1 local unflipped / 0 point]

Y: Remove 2 coins from your pile [Effects: -2 local unflipped / 0 point]

Z: Remove 3 coins from your pile [Effects: -3 local unflipped / 0 point]

R: Rotate coins to previous player [Effects: -1 point per unflipped received, +2 points per flipped received / applies to all players]

T: Rotate coins to next player [Effects: -1 point per unflipped received, +2 points per flipped received / applies to all players]

F: Flip 1 coin [Effects: -1 local unflipped / +1 local flipped / +2 point]

U: Unflip 1 coin [Effects: +1 local unflipped / -1 local flipped / -2 point]

Example output

2FF : Takes two coins and flips two coin, scoring -2 + 2 + 2 = 2 points

If your output is incorrect, controller will assume NNN.

Controller

You can find the controller on GitHub. It also contains two samplebots, written in Java.
To make it run, check out the project and open it in your Java IDE. The entry point in the main method of the class Game. Java 8 required.

To add bots, first you need either the compiled version for Java (.class files) or the sources for interpreted languages. Place them in the root folder of the project. Then, create a new Java class in the players package (you can take example on the already existing bots). This class must implement Player to override the method String getCmd(). The String returned is the shell command to run your bots. You can for example make a Ruby bot work with this command : return "C:\Ruby\bin\ruby.exe MyBot.rb";. Finally, add the bot in the players array at the top of the Game class.

Rules

Bots should not be written to beat or support specific other bots.

Writing to files is allowed. Please write to"yoursubmissionname.txt", the folder will be emptied before a game starts. Other external resources are disallowed.

Your submission has 1 second to respond.

Provide commands to compile and run your submissions.

Supported Languages

I'll try and support every language, but it needs to be available online for free. Please provide instructions for installation if you're not using a "mainstream" language.

As of right now, I can run : Java 6-7-8, PHP, Ruby, Perl, Python 2-3, Lua, R, node.js, Haskell, Kotlin, C++ 11.

Final results

These are the results of 100 games (points are added up) :

```<code>1. BirdInTheHand: 1017790
2. Balance: 851428
3. SecondBest: 802316
4. Crook: 739080
5. Jim: 723440
6. Flipper: 613290
7. Wheeler: 585516
8. Oracle: 574916
9. SimpleBot: 543665
10. TraderBot: 538160
11. EgoisticalBot: 529567
12. RememberMe: 497513
13. PassiveBot: 494441
14. TheJanitor: 474069
15. GreedyRotation: 447057
16. Devil: 79212
17. Saboteur: 62240
</code>```

Individual results of the games are available here : http://pasted.co/63f1e924 (with starting coins and number of rounds per game).

A bounty of 50 reputations is awarded to the winner : Bird In The Hand by Martin Büttner.

Thank you all for your participation, see you next KOTH~

答:
Remember Me, Python 3

This program contains a significant amount of inbuilt data from a test against the fixed SecondBest bot.

It should learn about what moves are the best to use, but it does not use other players' input.

Edit: removed unnecessary point calculation

Edit: uncommented player input

```<code>import sys
file=sys.argv[0].split('\\')[::-1][0]
from copy import deepcopy
from random import randint
In=str(sys.argv[1])
def V(n,f=10,t=14):
 n=str(n);z=0;s='';d='0123456789';d1='N123ABCXYZRTFU'
 for i in n:z=z*f+d.index(i)
 while z:z,m=divmod(z,t);s=d1[m]+s
 while len(s)<3:s='N'+s
 return s
In=In.split(';')
number=In[0:3]
players=In[3:]
for x in range(0,len(players)):players[x]=players[x].split('_')
for x in players:
 if number[1] in x[0]:self=x
for x in range(0,len(players)):
 for y in range(0,len(players[x])):
  players[x][y]=int(players[x][y])
for x in range(0,len(number)):number[x]=int(number[x])
Pos=list(map(V,range(0,14**3)))
B=[]
P1=deepcopy(players)
N1=deepcopy(number)
for x in range(len(Pos)):
    P=True
    y=Pos[x]
    if '1A'in y or '2B'in y or '3C'in y or 'FU'in y or 'A1'in y or 'B2'in y or 'C3'in y or 'UF'in y:
            P=False
    if P:
        players=deepcopy(P1)
        number=deepcopy(N1)
        for x in players:
            if str(number[1]) in str(x[0]):self=x
        for w in range(0,3):
            if y[w] in '3':
                if int(number[2])<3:P=False;break
                else:self[3]+=3;number[2]-=3
            if y[w] in '2':
                if int(number[2])<2:P=False;break
                else:self[3]+=2;number[2]-=2
            if y[w] in '1':
                if int(number[2])<1:P=False;break
                else:self[3]+=1;number[2]-=1
            if y[w] in 'A':
                if int(self[3])<1:P=False;break
                else:self[3]-=3;number[2]+=3
            if y[w] in 'B':
                if int(self[3])<2:P=False;break
                else:self[3]-=2;number[2]+=2
            if y[w] in 'C':
                if int(self[3])<3:P=False;break
                else:self[3]-=1;number[2]+=1
            if y[w] in 'X':
                if int(self[3])<1:P=False;break
                else:self[3]-=1
            if y[w] in 'Y':
                if int(self[3])<2:P=False;break
                else:self[3]-=2
            if y[w] in 'Z':
                if int(self[3])<3:P=False;break
                else:self[3]-=3
            if y[w] in 'F':
                if int(self[3])<1:P=False;break
                else:self[3]-=1;self[2]+=1
            if y[w] in 'U':
                if int(self[3])<1:P=False;break
                else:self[3]+=1;self[2]-=1
            if y[w] in 'R':
                self[2:4]=players[(players.index(self)+1)%len(players)][2:4]
            if y[w] in 'T':
                self[2:4]=players[(players.index(self)-1)%len(players)][2:4]
    if P:
        B.append(y)
Pos=list(B)
B=[]
#
C=[['NNN',0],['NN1',-1],['NN2',-2],['NN3',-3],['NNR',-6],['NNT',-1],['N1N',-1],['N11',-2],['N12',-3],['N13',-4],['N1X',-1],['N1R',-7],['N1T',-2],['N1F',1],['N1U',-3],['N2N',-2],['N21',-3],['N22',-4],['N23',-5],['N2A',-1],['N2X',-2],['N2Y',-2],['N2R',-8],['N2T',-3],['N2F',0],['N2U',-4],['N3N',-3],['N31',-4],['N32',-5],['N33',-6],['N3A',-2],['N3B',-1],['N3X',-3],['N3Y',-3],['N3Z',-3],['N3R',-9],['N3T',-4],['N3F',-1],['N3U',-5],['NRN',-6],['NR1',-7],['NR2',-8],['NR3',-9],['NRA',-5],['NRB',-4],['NRC',-3],['NRX',-6],['NRY',-6],['NRZ',-6],['NRR',-12],['NRT',-7],['NRF',-4],['NRU',-8],['NTN',-1],['NT1',-2],['NT2',-3],['NT3',-4],['NTA',0],['NTX',-1],['NTR',-7],['NTT',-2],['NTF',1],['NTU',-3],['1NN',-1],['1N1',-2],['1N2',-3],['1N3',-4],['1NA',0],['1NX',-1],['1NR',-7],['1NT',-2],['1NF',1],['1NU',-3],['11N',-2],['111',-3],['112',-4],['113',-5],['11B',0],['11X',-2],['11Y',-2],['11R',-8],['11T',-3],['11F',0],['11U',-4],['12N',-3],['121',-4],['122',-5],['123',-6],['12A',-2],['12C',0],['12X',-3],['12Y',-3],['12Z',-3],['12R',-9],['12T',-4],['12F',-1],['12U',-5],['13N',-4],['131',-5],['132',-6],['133',-7],['13A',-3],['13B',-2],['13X',-4],['13Y',-4],['13Z',-4],['13R',-10],['13T',-5],['13F',-2],['13U',-6],['1XN',-1],['1X1',-2],['1X2',-3],['1X3',-4],['1XR',-7],['1XT',-2],['1RN',-7],['1R1',-8],['1R2',-9],['1R3',-10],['1RA',-6],['1RB',-5],['1RC',-4],['1RX',-7],['1RY',-7],['1RZ',-7],['1RR',-13],['1RT',-8],['1RF',-5],['1RU',-9],['1TN',-2],['1T1',-3],['1T2',-4],['1T3',-5],['1TA',-1],['1TX',-2],['1TR',-8],['1TT',-3],['1TF',0],['1TU',-4],['1FN',1],['1F1',0],['1F2',-1],['1F3',-2],['1FR',-5],['1FT',0],['1UN',-3],['1U1',-4],['1U2',-5],['1U3',-6],['1UA',-2],['1UB',-1],['1UX',-3],['1UY',-3],['1UR',-9],['1UT',-4],['1UU',-5],['2NN',-2],['2N1',-3],['2N2',-4],['2N3',-5],['2NA',-1],['2NB',0],['2NX',-2],['2NY',-2],['2NR',-8],['2NT',-3],['2NF',0],['2NU',-4],['21N',-3],['211',-4],['212',-5],['213',-6],['21B',-1],['21C',0],['21X',-3],['21Y',-3],['21Z',-3],['21R',-9],['21T',-4],['21F',-1],['21U',-5],['22N',-4],['221',-5],['222',-6],['223',-7],['22A',-3],['22C',-1],['22X',-4],['22Y',-4],['22Z',-4],['22R',-10],['22T',-5],['22F',-2],['22U',-6],['23N',-5],['231',-6],['232',-7],['233',-8],['23A',-4],['23B',-3],['23X',-5],['23Y',-5],['23Z',-5],['23R',-11],['23T',-6],['23F',-3],['23U',-7],['2AN',-1],['2A2',-3],['2A3',-4],['2AR',-7],['2AT',-2],['2XN',-2],['2X1',-3],['2X2',-4],['2X3',-5],['2XA',-1],['2XX',-2],['2XR',-8],['2XT',-3],['2XF',0],['2XU',-4],['2YN',-2],['2Y1',-3],['2Y2',-4],['2Y3',-5],['2YR',-8],['2YT',-3],['2RN',-8],['2R1',-9],['2R2',-10],['2R3',-11],['2RA',-7],['2RB',-6],['2RC',-5],['2RX',-8],['2RY',-8],['2RZ',-8],['2RR',-14],['2RT',-9],['2RF',-6],['2RU',-10],['2TN',-3],['2T1',-4],['2T2',-5],['2T3',-6],['2TA',-2],['2TX',-3],['2TR',-9],['2TT',-4],['2TF',-1],['2TU',-5],['2FN',0],['2F1',-1],['2F2',-2],['2F3',-3],['2FA',1],['2FX',0],['2FR',-6],['2FT',-1],['2FF',2],['2UN',-4],['2U1',-5],['2U2',-6],['2U3',-7],['2UA',-3],['2UB',-2],['2UC',-1],['2UX',-4],['2UY',-4],['2UZ',-4],['2UR',-10],['2UT',-5],['2UU',-6],['3NN',-3],['3N1',-4],['3N2',-5],['3N3',-6],['3NA',-2],['3NB',-1],['3NC',0],['3NX',-3],['3NY',-3],['3NZ',-3],['3NR',-9],['3NT',-4],['3NF',-1],['3NU',-5],['31N',-4],['311',-5],['312',-6],['313',-7],['31B',-2],['31C',-1],['31X',-4],['31Y',-4],['31Z',-4],['31R',-10],['31T',-5],['31F',-2],['31U',-6],['32N',-5],['321',-6],['322',-7],['323',-8],['32A',-4],['32C',-2],['32X',-5],['32Y',-5],['32Z',-5],['32R',-11],['32T',-6],['32F',-3],['32U',-7],['33N',-6],['331',-7],['332',-8],['333',-9],['33A',-5],['33B',-4],['33X',-6],['33Y',-6],['33Z',-6],['33R',-12],['33T',-7],['33F',-4],['33U',-8],['3AN',-2],['3A2',-4],['3A3',-5],['3AR',-8],['3AT',-3],['3BN',-1],['3B1',-2],['3B3',-4],['3BA',0],['3BX',-1],['3BR',-7],['3BT',-2],['3BF',1],['3BU',-3],['3XN',-3],['3X1',-4],['3X2',-5],['3X3',-6],['3XA',-2],['3XB',-1],['3XX',-3],['3XY',-3],['3XR',-9],['3XT',-4],['3XF',-1],['3XU',-5],['3YN',-3],['3Y1',-4],['3Y2',-5],['3Y3',-6],['3YA',-2],['3YX',-3],['3YR',-9],['3YT',-4],['3YF',-1],['3YU',-5],['3ZN',-3],['3Z1',-4],['3Z2',-5],['3Z3',-6],['3ZR',-9],['3ZT',-4],['3RN',-9],['3R1',-10],['3R2',-11],['3R3',-12],['3RA',-8],['3RB',-7],['3RC',-6],['3RX',-9],['3RY',-9],['3RZ',-9],['3RR',-15],['3RT',-10],['3RF',-7],['3RU',-11],['3TN',-4],['3T1',-5],['3T2',-6],['3T3',-7],['3TA',-3],['3TX',-4],['3TR',-10],['3TT',-5],['3TF',-2],['3TU',-6],['3FN',-1],['3F1',-2],['3F2',-3],['3F3',-4],['3FA',0],['3FB',1],['3FX',-1],['3FY',-1],['3FR',-7],['3FT',-2],['3FF',1],['3UN',-5],['3U1',-6],['3U2',-7],['3U3',-8],['3UA',-4],['3UB',-3],['3UC',-2],['3UX',-5],['3UY',-5],['3UZ',-5],['3UR',-11],['3UT',-6],['3UU',-7],['RNN',-6],['RN1',-7],['RN2',-8],['RN3',-9],['RNA',-5],['RNB',-4],['RNC',-3],['RNX',-6],['RNY',-6],['RNZ',-6],['RNR',-12],['RNT',-7],['RNF',-4],['RNU',-8],['R1N',-7],['R11',-8],['R12',-9],['R13',-10],['R1B',-5],['R1C',-4],['R1X',-7],['R1Y',-7],['R1Z',-7],['R1R',-13],['R1T',-8],['R1F',-5],['R1U',-9],['R2N',-8],['R21',-9],['R22',-10],['R23',-11],['R2A',-7],['R2C',-5],['R2X',-8],['R2Y',-8],['R2Z',-8],['R2R',-14],['R2T',-9],['R2F',-6],['R2U',-10],['R3N',-9],['R31',-10],['R32',-11],['R33',-12],['R3A',-8],['R3B',-7],['R3X',-9],['R3Y',-9],['R3Z',-9],['R3R',-15],['R3T',-10],['R3F',-7],['R3U',-11],['RAN',-5],['RA2',-7],['RA3',-8],['RAA',-4],['RAB',-3],['RAC',-2],['RAX',-5],['RAY',-5],['RAZ',-5],['RAR',-11],['RAT',-6],['RAF',-3],['RAU',-7],['RBN',-4],['RB1',-5],['RB3',-7],['RBA',-3],['RBB',-2],['RBC',-1],['RBX',-4],['RBY',-4],['RBZ',-4],['RBR',-10],['RBT',-5],['RBF',-2],['RBU',-6],['RCN',-3],['RC1',-4],['RC2',-5],['RCA',-2],['RCB',-1],['RCC',0],['RCX',-3],['RCY',-3],['RCZ',-3],['RCR',-9],['RCT',-4],['RCF',-1],['RCU',-5],['RXN',-6],['RX1',-7],['RX2',-8],['RX3',-9],['RXA',-5],['RXB',-4],['RXC',-3],['RXX',-6],['RXY',-6],['RXZ',-6],['RXR',-12],['RXT',-7],['RXF',-4],['RXU',-8],['RYN',-6],['RY1',-7],['RY2',-8],['RY3',-9],['RYA',-5],['RYB',-4],['RYC',-3],['RYX',-6],['RYY',-6],['RYZ',-6],['RYR',-12],['RYT',-7],['RYF',-4],['RYU',-8],['RZN',-6],['RZ1',-7],['RZ2',-8],['RZ3',-9],['RZA',-5],['RZB',-4],['RZC',-3],['RZX',-6],['RZY',-6],['RZZ',-6],['RZR',-12],['RZT',-7],['RZF',-4],['RZU',-8],['RRN',-12],['RR1',-13],['RR2',-14],['RR3',-15],['RRA',-11],['RRB',-10],['RRC',-9],['RRX',-12],['RRY',-12],['RRZ',-12],['RRR',-18],['RRT',-13],['RRF',-10],['RRU',-14],['RTN',-7],['RT1',-8],['RT2',-9],['RT3',-10],['RTA',-6],['RTX',-7],['RTR',-13],['RTT',-8],['RTF',-5],['RTU',-9],['RFN',-4],['RF1',-5],['RF2',-6],['RF3',-7],['RFA',-3],['RFB',-2],['RFC',-1],['RFX',-4],['RFY',-4],['RFZ',-4],['RFR',-10],['RFT',-5],['RFF',-2],['RUN',-8],['RU1',-9],['RU2',-10],['RU3',-11],['RUA',-7],['RUB',-6],['RUC',-5],['RUX',-8],['RUY',-8],['RUZ',-8],['RUR',-14],['RUT',-9],['RUU',-10],['TNN',-1],['TN1',-2],['TN2',-3],['TN3',-4],['TNA',0],['TNX',-1],['TNR',-7],['TNT',-2],['TNF',1],['TNU',-3],['T1N',-2],['T11',-3],['T12',-4],['T13',-5],['T1B',0],['T1X',-2],['T1Y',-2],['T1R',-8],['T1T',-3],['T1F',0],['T1U',-4],['T2N',-3],['T21',-4],['T22',-5],['T23',-6],['T2A',-2],['T2C',0],['T2X',-3],['T2Y',-3],['T2Z',-3],['T2R',-9],['T2T',-4],['T2F',-1],['T2U',-5],['T3N',-4],['T31',-5],['T32',-6],['T33',-7],['T3A',-3],['T3B',-2],['T3X',-4],['T3Y',-4],['T3Z',-4],['T3R',-10],['T3T',-5],['T3F',-2],['T3U',-6],['TAN',0],['TA2',-2],['TA3',-3],['TAR',-6],['TAT',-1],['TXN',-1],['TX1',-2],['TX2',-3],['TX3',-4],['TXR',-7],['TXT',-2],['TRN',-7],['TR1',-8],['TR2',-9],['TR3',-10],['TRA',-6],['TRB',-5],['TRC',-4],['TRX',-7],['TRY',-7],['TRZ',-7],['TRR',-13],['TRT',-8],['TRF',-5],['TRU',-9],['TTN',-2],['TT1',-3],['TT2',-4],['TT3',-5],['TTA',-1],['TTX',-2],['TTR',-8],['TTT',-3],['TTF',0],['TTU',-4],['TFN',1],['TF1',0],['TF2',-1],['TF3',-2],['TFR',-5],['TFT',0],['TUN',-3],['TU1',-4],['TU2',-5],['TU3',-6],['TUA',-2],['TUB',-1],['TUX',-3],['TUY',-3],['TUR',-9],['TUT',-4],['TUU',-5]]
#
points=0
#
dpoints=self[1]-points
z=0
for x in range(len(Pos)):
    y=Pos[x]
    z=0
    for x in C:
     if x[0]==y:z=x[1]
    B.append((z,y))
B.sort()
B=B[::-1]
G=open(file,'r')
H=G.read().split('#')[::-1]
G.close()
G=open(file,'w')
H[3]=H[3].replace(H[3][8:-1],str(self[1]))
J=eval(H[4][3:-1])
A=[B[0][1],dpoints]
P=1
for x in range(0,len(J)):
 if J[x][0]==A[0]:J[x][1]+=A[1];P=0
if P:J.append(A)
H[4]='\nC='+str(J)+'\n'
s=''
for x in H[::-1]:s+=x;s+='#'
G.write(s[:-1])
G.close()
print(B[0][1])
</code>```

Title: KOTH: Every coin has two sides

Body:
Remember Me, Python 3

This program contains a significant amount of inbuilt data from a test against the fixed SecondBest bot.

It should learn about what moves are the best to use, but it does not use other players' input.

Edit: removed unnecessary point calculation

Edit: uncommented player input

import sys
file=sys.argv[0].split('\\')[::-1][0]
from copy import deepcopy
from random import randint
In=str(sys.argv[1])
def V(n,f=10,t=14):
 n=str(n);z=0;s='';d='0123456789';d1='N123ABCXYZRTFU'
 for i in n:z=z*f+d.index(i)
 while z:z,m=divmod(z,t);s=d1[m]+s
 while len(s)<3:s='N'+s
 return s
In=In.split(';')
number=In[0:3]
players=In[3:]
for x in range(0,len(players)):players[x]=players[x].split('_')
for x in players:
 if number[1] in x[0]:self=x
for x in range(0,len(players)):
 for y in range(0,len(players[x])):
  players[x][y]=int(players[x][y])
for x in range(0,len(number)):number[x]=int(number[x])
Pos=list(map(V,range(0,14**3)))
B=[]
P1=deepcopy(players)
N1=deepcopy(number)
for x in range(len(Pos)):
    P=True
    y=Pos[x]
    if '1A'in y or '2B'in y or '3C'in y or 'FU'in y or 'A1'in y or 'B2'in y or 'C3'in y or 'UF'in y:
            P=False
    if P:
        players=deepcopy(P1)
        number=deepcopy(N1)
        for x in players:
            if str(number[1]) in str(x[0]):self=x
        for w in range(0,3):
            if y[w] in '3':
                if int(number[2])<3:P=False;break
                else:self[3]+=3;number[2]-=3
            if y[w] in '2':
                if int(number[2])<2:P=False;break
                else:self[3]+=2;number[2]-=2
            if y[w] in '1':
                if int(number[2])<1:P=False;break
                else:self[3]+=1;number[2]-=1
            if y[w] in 'A':
                if int(self[3])<1:P=False;break
                else:self[3]-=3;number[2]+=3
            if y[w] in 'B':
                if int(self[3])<2:P=False;break
                else:self[3]-=2;number[2]+=2
            if y[w] in 'C':
                if int(self[3])<3:P=False;break
                else:self[3]-=1;number[2]+=1
            if y[w] in 'X':
                if int(self[3])<1:P=False;break
                else:self[3]-=1
            if y[w] in 'Y':
                if int(self[3])<2:P=False;break
                else:self[3]-=2
            if y[w] in 'Z':
                if int(self[3])<3:P=False;break
                else:self[3]-=3
            if y[w] in 'F':
                if int(self[3])<1:P=False;break
                else:self[3]-=1;self[2]+=1
            if y[w] in 'U':
                if int(self[3])<1:P=False;break
                else:self[3]+=1;self[2]-=1
            if y[w] in 'R':
                self[2:4]=players[(players.index(self)+1)%len(players)][2:4]
            if y[w] in 'T':
                self[2:4]=players[(players.index(self)-1)%len(players)][2:4]
    if P:
        B.append(y)
Pos=list(B)
B=[]
#
C=[['NNN',0],['NN1',-1],['NN2',-2],['NN3',-3],['NNR',-6],['NNT',-1],['N1N',-1],['N11',-2],['N12',-3],['N13',-4],['N1X',-1],['N1R',-7],['N1T',-2],['N1F',1],['N1U',-3],['N2N',-2],['N21',-3],['N22',-4],['N23',-5],['N2A',-1],['N2X',-2],['N2Y',-2],['N2R',-8],['N2T',-3],['N2F',0],['N2U',-4],['N3N',-3],['N31',-4],['N32',-5],['N33',-6],['N3A',-2],['N3B',-1],['N3X',-3],['N3Y',-3],['N3Z',-3],['N3R',-9],['N3T',-4],['N3F',-1],['N3U',-5],['NRN',-6],['NR1',-7],['NR2',-8],['NR3',-9],['NRA',-5],['NRB',-4],['NRC',-3],['NRX',-6],['NRY',-6],['NRZ',-6],['NRR',-12],['NRT',-7],['NRF',-4],['NRU',-8],['NTN',-1],['NT1',-2],['NT2',-3],['NT3',-4],['NTA',0],['NTX',-1],['NTR',-7],['NTT',-2],['NTF',1],['NTU',-3],['1NN',-1],['1N1',-2],['1N2',-3],['1N3',-4],['1NA',0],['1NX',-1],['1NR',-7],['1NT',-2],['1NF',1],['1NU',-3],['11N',-2],['111',-3],['112',-4],['113',-5],['11B',0],['11X',-2],['11Y',-2],['11R',-8],['11T',-3],['11F',0],['11U',-4],['12N',-3],['121',-4],['122',-5],['123',-6],['12A',-2],['12C',0],['12X',-3],['12Y',-3],['12Z',-3],['12R',-9],['12T',-4],['12F',-1],['12U',-5],['13N',-4],['131',-5],['132',-6],['133',-7],['13A',-3],['13B',-2],['13X',-4],['13Y',-4],['13Z',-4],['13R',-10],['13T',-5],['13F',-2],['13U',-6],['1XN',-1],['1X1',-2],['1X2',-3],['1X3',-4],['1XR',-7],['1XT',-2],['1RN',-7],['1R1',-8],['1R2',-9],['1R3',-10],['1RA',-6],['1RB',-5],['1RC',-4],['1RX',-7],['1RY',-7],['1RZ',-7],['1RR',-13],['1RT',-8],['1RF',-5],['1RU',-9],['1TN',-2],['1T1',-3],['1T2',-4],['1T3',-5],['1TA',-1],['1TX',-2],['1TR',-8],['1TT',-3],['1TF',0],['1TU',-4],['1FN',1],['1F1',0],['1F2',-1],['1F3',-2],['1FR',-5],['1FT',0],['1UN',-3],['1U1',-4],['1U2',-5],['1U3',-6],['1UA',-2],['1UB',-1],['1UX',-3],['1UY',-3],['1UR',-9],['1UT',-4],['1UU',-5],['2NN',-2],['2N1',-3],['2N2',-4],['2N3',-5],['2NA',-1],['2NB',0],['2NX',-2],['2NY',-2],['2NR',-8],['2NT',-3],['2NF',0],['2NU',-4],['21N',-3],['211',-4],['212',-5],['213',-6],['21B',-1],['21C',0],['21X',-3],['21Y',-3],['21Z',-3],['21R',-9],['21T',-4],['21F',-1],['21U',-5],['22N',-4],['221',-5],['222',-6],['223',-7],['22A',-3],['22C',-1],['22X',-4],['22Y',-4],['22Z',-4],['22R',-10],['22T',-5],['22F',-2],['22U',-6],['23N',-5],['231',-6],['232',-7],['233',-8],['23A',-4],['23B',-3],['23X',-5],['23Y',-5],['23Z',-5],['23R',-11],['23T',-6],['23F',-3],['23U',-7],['2AN',-1],['2A2',-3],['2A3',-4],['2AR',-7],['2AT',-2],['2XN',-2],['2X1',-3],['2X2',-4],['2X3',-5],['2XA',-1],['2XX',-2],['2XR',-8],['2XT',-3],['2XF',0],['2XU',-4],['2YN',-2],['2Y1',-3],['2Y2',-4],['2Y3',-5],['2YR',-8],['2YT',-3],['2RN',-8],['2R1',-9],['2R2',-10],['2R3',-11],['2RA',-7],['2RB',-6],['2RC',-5],['2RX',-8],['2RY',-8],['2RZ',-8],['2RR',-14],['2RT',-9],['2RF',-6],['2RU',-10],['2TN',-3],['2T1',-4],['2T2',-5],['2T3',-6],['2TA',-2],['2TX',-3],['2TR',-9],['2TT',-4],['2TF',-1],['2TU',-5],['2FN',0],['2F1',-1],['2F2',-2],['2F3',-3],['2FA',1],['2FX',0],['2FR',-6],['2FT',-1],['2FF',2],['2UN',-4],['2U1',-5],['2U2',-6],['2U3',-7],['2UA',-3],['2UB',-2],['2UC',-1],['2UX',-4],['2UY',-4],['2UZ',-4],['2UR',-10],['2UT',-5],['2UU',-6],['3NN',-3],['3N1',-4],['3N2',-5],['3N3',-6],['3NA',-2],['3NB',-1],['3NC',0],['3NX',-3],['3NY',-3],['3NZ',-3],['3NR',-9],['3NT',-4],['3NF',-1],['3NU',-5],['31N',-4],['311',-5],['312',-6],['313',-7],['31B',-2],['31C',-1],['31X',-4],['31Y',-4],['31Z',-4],['31R',-10],['31T',-5],['31F',-2],['31U',-6],['32N',-5],['321',-6],['322',-7],['323',-8],['32A',-4],['32C',-2],['32X',-5],['32Y',-5],['32Z',-5],['32R',-11],['32T',-6],['32F',-3],['32U',-7],['33N',-6],['331',-7],['332',-8],['333',-9],['33A',-5],['33B',-4],['33X',-6],['33Y',-6],['33Z',-6],['33R',-12],['33T',-7],['33F',-4],['33U',-8],['3AN',-2],['3A2',-4],['3A3',-5],['3AR',-8],['3AT',-3],['3BN',-1],['3B1',-2],['3B3',-4],['3BA',0],['3BX',-1],['3BR',-7],['3BT',-2],['3BF',1],['3BU',-3],['3XN',-3],['3X1',-4],['3X2',-5],['3X3',-6],['3XA',-2],['3XB',-1],['3XX',-3],['3XY',-3],['3XR',-9],['3XT',-4],['3XF',-1],['3XU',-5],['3YN',-3],['3Y1',-4],['3Y2',-5],['3Y3',-6],['3YA',-2],['3YX',-3],['3YR',-9],['3YT',-4],['3YF',-1],['3YU',-5],['3ZN',-3],['3Z1',-4],['3Z2',-5],['3Z3',-6],['3ZR',-9],['3ZT',-4],['3RN',-9],['3R1',-10],['3R2',-11],['3R3',-12],['3RA',-8],['3RB',-7],['3RC',-6],['3RX',-9],['3RY',-9],['3RZ',-9],['3RR',-15],['3RT',-10],['3RF',-7],['3RU',-11],['3TN',-4],['3T1',-5],['3T2',-6],['3T3',-7],['3TA',-3],['3TX',-4],['3TR',-10],['3TT',-5],['3TF',-2],['3TU',-6],['3FN',-1],['3F1',-2],['3F2',-3],['3F3',-4],['3FA',0],['3FB',1],['3FX',-1],['3FY',-1],['3FR',-7],['3FT',-2],['3FF',1],['3UN',-5],['3U1',-6],['3U2',-7],['3U3',-8],['3UA',-4],['3UB',-3],['3UC',-2],['3UX',-5],['3UY',-5],['3UZ',-5],['3UR',-11],['3UT',-6],['3UU',-7],['RNN',-6],['RN1',-7],['RN2',-8],['RN3',-9],['RNA',-5],['RNB',-4],['RNC',-3],['RNX',-6],['RNY',-6],['RNZ',-6],['RNR',-12],['RNT',-7],['RNF',-4],['RNU',-8],['R1N',-7],['R11',-8],['R12',-9],['R13',-10],['R1B',-5],['R1C',-4],['R1X',-7],['R1Y',-7],['R1Z',-7],['R1R',-13],['R1T',-8],['R1F',-5],['R1U',-9],['R2N',-8],['R21',-9],['R22',-10],['R23',-11],['R2A',-7],['R2C',-5],['R2X',-8],['R2Y',-8],['R2Z',-8],['R2R',-14],['R2T',-9],['R2F',-6],['R2U',-10],['R3N',-9],['R31',-10],['R32',-11],['R33',-12],['R3A',-8],['R3B',-7],['R3X',-9],['R3Y',-9],['R3Z',-9],['R3R',-15],['R3T',-10],['R3F',-7],['R3U',-11],['RAN',-5],['RA2',-7],['RA3',-8],['RAA',-4],['RAB',-3],['RAC',-2],['RAX',-5],['RAY',-5],['RAZ',-5],['RAR',-11],['RAT',-6],['RAF',-3],['RAU',-7],['RBN',-4],['RB1',-5],['RB3',-7],['RBA',-3],['RBB',-2],['RBC',-1],['RBX',-4],['RBY',-4],['RBZ',-4],['RBR',-10],['RBT',-5],['RBF',-2],['RBU',-6],['RCN',-3],['RC1',-4],['RC2',-5],['RCA',-2],['RCB',-1],['RCC',0],['RCX',-3],['RCY',-3],['RCZ',-3],['RCR',-9],['RCT',-4],['RCF',-1],['RCU',-5],['RXN',-6],['RX1',-7],['RX2',-8],['RX3',-9],['RXA',-5],['RXB',-4],['RXC',-3],['RXX',-6],['RXY',-6],['RXZ',-6],['RXR',-12],['RXT',-7],['RXF',-4],['RXU',-8],['RYN',-6],['RY1',-7],['RY2',-8],['RY3',-9],['RYA',-5],['RYB',-4],['RYC',-3],['RYX',-6],['RYY',-6],['RYZ',-6],['RYR',-12],['RYT',-7],['RYF',-4],['RYU',-8],['RZN',-6],['RZ1',-7],['RZ2',-8],['RZ3',-9],['RZA',-5],['RZB',-4],['RZC',-3],['RZX',-6],['RZY',-6],['RZZ',-6],['RZR',-12],['RZT',-7],['RZF',-4],['RZU',-8],['RRN',-12],['RR1',-13],['RR2',-14],['RR3',-15],['RRA',-11],['RRB',-10],['RRC',-9],['RRX',-12],['RRY',-12],['RRZ',-12],['RRR',-18],['RRT',-13],['RRF',-10],['RRU',-14],['RTN',-7],['RT1',-8],['RT2',-9],['RT3',-10],['RTA',-6],['RTX',-7],['RTR',-13],['RTT',-8],['RTF',-5],['RTU',-9],['RFN',-4],['RF1',-5],['RF2',-6],['RF3',-7],['RFA',-3],['RFB',-2],['RFC',-1],['RFX',-4],['RFY',-4],['RFZ',-4],['RFR',-10],['RFT',-5],['RFF',-2],['RUN',-8],['RU1',-9],['RU2',-10],['RU3',-11],['RUA',-7],['RUB',-6],['RUC',-5],['RUX',-8],['RUY',-8],['RUZ',-8],['RUR',-14],['RUT',-9],['RUU',-10],['TNN',-1],['TN1',-2],['TN2',-3],['TN3',-4],['TNA',0],['TNX',-1],['TNR',-7],['TNT',-2],['TNF',1],['TNU',-3],['T1N',-2],['T11',-3],['T12',-4],['T13',-5],['T1B',0],['T1X',-2],['T1Y',-2],['T1R',-8],['T1T',-3],['T1F',0],['T1U',-4],['T2N',-3],['T21',-4],['T22',-5],['T23',-6],['T2A',-2],['T2C',0],['T2X',-3],['T2Y',-3],['T2Z',-3],['T2R',-9],['T2T',-4],['T2F',-1],['T2U',-5],['T3N',-4],['T31',-5],['T32',-6],['T33',-7],['T3A',-3],['T3B',-2],['T3X',-4],['T3Y',-4],['T3Z',-4],['T3R',-10],['T3T',-5],['T3F',-2],['T3U',-6],['TAN',0],['TA2',-2],['TA3',-3],['TAR',-6],['TAT',-1],['TXN',-1],['TX1',-2],['TX2',-3],['TX3',-4],['TXR',-7],['TXT',-2],['TRN',-7],['TR1',-8],['TR2',-9],['TR3',-10],['TRA',-6],['TRB',-5],['TRC',-4],['TRX',-7],['TRY',-7],['TRZ',-7],['TRR',-13],['TRT',-8],['TRF',-5],['TRU',-9],['TTN',-2],['TT1',-3],['TT2',-4],['TT3',-5],['TTA',-1],['TTX',-2],['TTR',-8],['TTT',-3],['TTF',0],['TTU',-4],['TFN',1],['TF1',0],['TF2',-1],['TF3',-2],['TFR',-5],['TFT',0],['TUN',-3],['TU1',-4],['TU2',-5],['TU3',-6],['TUA',-2],['TUB',-1],['TUX',-3],['TUY',-3],['TUR',-9],['TUT',-4],['TUU',-5]]
#
points=0
#
dpoints=self[1]-points
z=0
for x in range(len(Pos)):
    y=Pos[x]
    z=0
    for x in C:
     if x[0]==y:z=x[1]
    B.append((z,y))
B.sort()
B=B[::-1]
G=open(file,'r')
H=G.read().split('#')[::-1]
G.close()
G=open(file,'w')
H[3]=H[3].replace(H[3][8:-1],str(self[1]))
J=eval(H[4][3:-1])
A=[B[0][1],dpoints]
P=1
for x in range(0,len(J)):
 if J[x][0]==A[0]:J[x][1]+=A[1];P=0
if P:J.append(A)
H[4]='\nC='+str(J)+'\n'
s=''
for x in H[::-1]:s+=x;s+='#'
G.write(s[:-1])
G.close()
print(B[0][1])


问:
Convert header levels to numbers

Introduction

Nodes in tree structures (e.g. headings in a long document, law paragraphs, etc.) are often created by assigning a specific header level (h1, h2, etc.) to each item, but outputted with additional node numbers for each level (1., 1.1., etc.), e.g.:

```<code>1. Intro (h1)
1.1. About this (h2)
1.2. Target audience (h2)
2. Actual stuff (h1)
3. More stuff (h1)
3.1. Details (h2)
3.1.1. Special points (h3)
3.2. Specifics (h2)
3.2.1. Minutiae (h3)
3.2.2. Petitesses (h3)
3.3. Specifications (h2)
4. Index (h1)
5. Appendices (h1)
</code>```

Input

Given (by any means) a list of header levels (the X's in hX above) like:

```<code>[1,2,2,1,1,2,3,2,3,3,2,1,1]
</code>```

Input will always begin with a 1, and Inputn+1 is in the range [1,1+Inputn].

Input will only contain numbers in the range [1,256].

Output

Return (by any means) the list of lists (or matrix - see below) of node numbers (dot-separated above):

```<code>[[1],[1,1],[1,2],[2],[3],[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],[4],[5]]
</code>```

You may return scalars instead of one-element sub-lists:

```<code>[1,[1,1],[1,2],2,3,[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],4,5]
</code>```

You may return a matrix (or list of lists) which is padded with zeros so that all rows (sub-lists) have the same length:

```<code>[[1,0,0]
 [1,1,0]
 [1,2,0]
 [2,0,0]
 [3,0,0]
 [3,1,0]
 [3,1,1]
 [3,2,0]
 [3,2,1]
 [3,2,2]
 [3,3,0]
 [4,0,0]
 [5,0,0]]
</code>```

Additional rules

The reverse process of all this is just the length of each sub-list. You must also include a reverse program in the same language. Your score is the total byte count of your two programs. If you return zero-padded results on the first prgram, your reverse code must handle such input.

Please explain your code so we all can learn from it.

This is code golf, because I'll need to read it on a phone screen and type it into a computer. - No, really, this is not meme-ness!

Title: Convert header levels to numbers

Body:
CJam (15 + 4 = 19 bytes)

Mq~{1$0+<))+}%`

Online demo

To reverse,

q~:,


答:
JavaScript (ES6), 186 bytes

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

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

Title: Shortest paths in a divisor graph

Body:
Introduction

In this challenge, we will be dealing with a certain infinite undirected graph, which I call the high divisor graph.
Its nodes are the integers starting from 2.
There is an edge between two nodes a < b if a divides b and a2 ≥ b.
The subgraph formed by the range from 2 to 18 looks like this:

```<code>16-8 12 18
  \|/ |/|
   4  6 9 10 15 14
   |  |/   |/   |
   2  3    5    7  11 13 17
</code>```

It can be shown that the infinite high divisor graph is connected, so we can ask about the shortest path between two nodes.

Input and output

Your inputs are two integers a and b.
You can assume that 2 ≤ a ≤ b < 1000.
Your output is the length of the shortest path between a and b in the infinite high divisor graph.
This means the number of edges in the path.

You may find the following fact useful: there always exists an optimal path from a to b that's first increasing and then decreasing, and only visits nodes that are strictly less than 2b2.
In particular, since b < 1000 you only need to consider nodes less than 2 000 000.

Examples

Consider the inputs 3 and 32.
One possible path between the nodes 3 and 32 is

```<code>3 -- 6 -- 12 -- 96 -- 32
</code>```

This path has four edges, and it turns out there are no shorter paths, so the correct output is 4.

As another example, an optimal path for 2 and 25 is

```<code>2 -- 4 -- 8 -- 40 -- 200 -- 25
</code>```

so the correct output is 5.
In this case, no optimal path contains the node 50 = lcm(2, 25).

Rules and scoring

You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
There are no time or memory limits, so brute forcing is allowed.

Test cases

```<code>2 2 -> 0
2 3 -> 4
2 4 -> 1
2 5 -> 5
3 5 -> 4
6 8 -> 2
8 16 -> 1
12 16 -> 2
16 16 -> 0
2 25 -> 5
3 32 -> 4
2 256 -> 3
60 77 -> 3
56 155 -> 3
339 540 -> 2
6 966 -> 4
7 966 -> 2
11 966 -> 4
2 997 -> 7
991 997 -> 4
</code>```

Body:
JavaScript (ES6), 186 bytes

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

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


问:
Mode (most common element) of a list
Write a snippet to calculate the mode (most common number) of a list of positive integers.

For example, the mode of

```<code>d = [4,3,1,0,6,1,6,4,4,0,3,1,7,7,3,4,1,1,2,8]
</code>```

is 1, because it occurs the maximum of 5 times.

You may assume that the list is stored in a variable such as d and has a unique mode.

e.g.: Python, 49

```<code>max(((i,d.count(i))for i in set(d)), key=lambda x:x[1])
</code>```

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

Title: Mode (most common element) of a list

Body:
jq, 29 characters

group_by(.)|max_by(length)[0]

Sample run:

bash-4.3$ jq 'group_by(.)|max_by(length)[0]' <<< '[4,3,1,0,6,1,6,4,4,0,3,1,7,7,3,4,1,1,2,8]'
1

On-line test


答:
Python 3.5, <s>193</s> <s>187</s> <s>185</s> <s>181</s> <s>175</s> <s>173</s> 172 bytes:

```<code>def G(*p):
 O=100;y=0;l=10;z,v='UG'
 for g in[*p,O]:
  if v=='G':Q=O*g//10;y=min(max(0,[Q,y-Q][z=='D']),O);l=min(10,g);z='UD'[z=='U']
  v='GS'[(O>y>0)*(v!='S')]
 print(y,z)
</code>```

Takes input in the form of comma separated numbers, for instance 1,2,3,4,5 or even 1.2,3.4,7.8,9.2. Outputs whether the door in the next step is going up or down with U or D, respectively. Will golf more over time.

Try It Online! (Ideone) (Here the input is taken in the form of a list consisting of comma separated numbers, e.g. [1,2,3,4,5].)

Title: Is the electric garage door open?

Body:
My electric garage door works like this:

There is just one push button to control the door

If the door is fully closed and I hit the button, the door starts to open.  It takes 10 seconds to open fully

If the door is fully open and I hit the button, the door starts to close.  It takes 10 seconds to close fully

If the door is part way through opening or closing and I hit the button, then the door stops and is left partially open.

Whenever the door stops moving, either from automatic completion of an open or close action, or from manual interruption by pushing the button partway through an action, then the mechanism will reverse and remember its direction for the next action.

If the button is pushed when the door is stopped but partially open, then the amount of time for it to complete its action will be a fraction of 10 seconds in proportion to the amount it needs to move to complete the action.

Assume the door is fully closed at the start.

An input list of integers will be given.  These integers are the number of seconds I wait between successive pushes of the control button.

Output two things:

a percentage indicating the state of the door once all button pushes are completed and the door has reached a steady state.  Output of % symbol is optional.

an unambiguous indication of what direction the door will travel on the next button push.  This may be up/down, U/D, +/-, 1/0 or whatever you choose.

You may assume the door takes infinitesimally less than 10 seconds to complete an open or close action.

Example inputs:

```<code><empty list>  # button was pushed just once
20            # button was pushed twice with 20 seconds between
10
5
20 20
10 10
5 5
1 2 3
8 9 10 11
11 10 9 8 7
</code>```

Expected outputs corresponding to above inputs

```<code>100% D
0% U
0% U
50% D
100% D
100% D
0% U
100% D
0% U
20% U
</code>```

Worked example of the last test

Door starts off closed.  Button is pushed

Wait 11 seconds.  Door ends up fully opened.  Button is pushed.

Wait 10 seconds.  Door ends up fully closed.  Button is pushed.

Wait 9 seconds.  Button is pushed.  Door stops at 90% open.

Wait 8 seconds.  Button is pushed.  Door starts to close.

Wait 7 seconds.  Button is pushed.  Door stops at 20% open.  Next direction will be up.

Body:
Python 3.5, <s>193</s> <s>187</s> <s>185</s> <s>181</s> <s>175</s> <s>173</s> 172 bytes:

def G(*p):
 O=100;y=0;l=10;z,v='UG'
 for g in[*p,O]:
  if v=='G':Q=O*g//10;y=min(max(0,[Q,y-Q][z=='D']),O);l=min(10,g);z='UD'[z=='U']
  v='GS'[(O>y>0)*(v!='S')]
 print(y,z)

Takes input in the form of comma separated numbers, for instance 1,2,3,4,5 or even 1.2,3.4,7.8,9.2. Outputs whether the door in the next step is going up or down with U or D, respectively. Will golf more over time.

Try It Online! (Ideone) (Here the input is taken in the form of a list consisting of comma separated numbers, e.g. [1,2,3,4,5].)


问:
Index of a multidimensional array
Lower level languages, such as C and C++ actually have no concept of multidimensional arrays. (Other than vectors and dynamic arrays) When you create a multidimensional array with

```<code>int foo[5][10];
</code>```

This is actually just syntactic sugar. What C really does is create a single contiguous array of 5 * 10 elements. This

```<code>foo[4][2]
</code>```

is also syntactic sugar. This really refers to the element at

```<code>4 * 10 + 2
</code>```

or, the 42nd element. In general, the index of element [a][b] in array foo[x][y] is at

```<code>a * y + b
</code>```

The same concept applies to 3d arrays. If we have foo[x][y][z] and we access element [a][b][c] we are really accessing element:

```<code>a * y * z + b * z + c
</code>```

This concept applies to n-dimensional arrays. If we have an array with dimensions D1, D2, D3 ... Dn and we access element S1, S2, S3 ... Sn the formula is

```<code>(S1 * D2 * D3 ... * Dn) + (S2 * D3 * D4 ... * Dn) + (S3 * D4 ... * Dn) ... + (Sn-1 * Dn) + Sn
</code>```

The challenge

You must write a program or function that calculates the index of a multidimensional array according to the formula above. Input will be two arrays. The first array is the dimensions, and the second array is the indices. The length of these two arrays will always be equal and at least 1.

You can safely assume that every number in the arrays will be an non-negative integer. You can also assume that you will not get a 0 in the dimension array, although a 0 might be in the indices. You can also assume that indices will not be larger than the dimensions.

Test IO

```<code>Dimensions: [5, 10]
Indices: [4, 2]
Output: 42

Dimensions: [10, 10, 4, 62, 7]
Indices: [1, 2, 3, 4, 5]
Output: 22167

Dimensions: [5, 1, 10]
Indices: [3, 0, 7]
Output: 37

Dimensions: [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
Indices: [3, 1, 5, 5, 3, 0, 5, 2, 5, 4]
Output: 33570178
</code>```

答:
C++, 66 bytes

A quick macro:

```<code>#include<stdio.h>
#define F(d,i) int x d;printf("%d",&x i-(int*)x)
</code>```

Use like:

```<code>int main(){
    F([5][1][10], [3][0][7]);
}
</code>```

This may be a bit of an abuse of the rules. Creates an array with the given size, than checks to see how far the given indexes offset the pointer. Outputs to STDOUT.

This feels so dirty... But I just love the fact that this is valid.

Title: Index of a multidimensional array

Body:
C++, 66 bytes

A quick macro:

#include<stdio.h>
#define F(d,i) int x d;printf("%d",&x i-(int*)x)

Use like:

int main(){
    F([5][1][10], [3][0][7]);
}

This may be a bit of an abuse of the rules. Creates an array with the given size, than checks to see how far the given indexes offset the pointer. Outputs to STDOUT.

This feels so dirty... But I just love the fact that this is valid.


答:
Octave, <s>47</s>/<s>43</s>/31 bytes

@(d,i)sub2ind(flip(d),num2cell(flip(i+1)){:})-1

Test it here.

Having said that, as it was asked in a comment, 1-based indexing was said to be OK when this is natural to the language being used. In this case, we can save 4 bytes:

@(d,i)sub2ind(flip(d),num2cell(flip(i)){:})

In analogy, I argue that if the objective of the code is to linearly index an array within that language, the whole flipping around and accounting for MATLAB/Octave's column major order should not be necessary, either. In that case, my solution becomes

@(d,i)sub2ind(d,num2cell(i){:})

Test that one here.

Title: Index of a multidimensional array

Body:
Lower level languages, such as C and C++ actually have no concept of multidimensional arrays. (Other than vectors and dynamic arrays) When you create a multidimensional array with

```<code>int foo[5][10];
</code>```

This is actually just syntactic sugar. What C really does is create a single contiguous array of 5 * 10 elements. This

```<code>foo[4][2]
</code>```

is also syntactic sugar. This really refers to the element at

```<code>4 * 10 + 2
</code>```

or, the 42nd element. In general, the index of element [a][b] in array foo[x][y] is at

```<code>a * y + b
</code>```

The same concept applies to 3d arrays. If we have foo[x][y][z] and we access element [a][b][c] we are really accessing element:

```<code>a * y * z + b * z + c
</code>```

This concept applies to n-dimensional arrays. If we have an array with dimensions D1, D2, D3 ... Dn and we access element S1, S2, S3 ... Sn the formula is

```<code>(S1 * D2 * D3 ... * Dn) + (S2 * D3 * D4 ... * Dn) + (S3 * D4 ... * Dn) ... + (Sn-1 * Dn) + Sn
</code>```

The challenge

You must write a program or function that calculates the index of a multidimensional array according to the formula above. Input will be two arrays. The first array is the dimensions, and the second array is the indices. The length of these two arrays will always be equal and at least 1.

You can safely assume that every number in the arrays will be an non-negative integer. You can also assume that you will not get a 0 in the dimension array, although a 0 might be in the indices. You can also assume that indices will not be larger than the dimensions.

Test IO

```<code>Dimensions: [5, 10]
Indices: [4, 2]
Output: 42

Dimensions: [10, 10, 4, 62, 7]
Indices: [1, 2, 3, 4, 5]
Output: 22167

Dimensions: [5, 1, 10]
Indices: [3, 0, 7]
Output: 37

Dimensions: [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
Indices: [3, 1, 5, 5, 3, 0, 5, 2, 5, 4]
Output: 33570178
</code>```


问:
Code-Golf: Lattice Points inside a Circle
The following picture shows the problem:

Write a function that, given an integer as the circle radius, calculates the number of lattice points inside the centered circle (including the boundary).

The image shows:

```<code>f[1] = 5  (blue points)
f[2] = 13 (blue + red points)
</code>```

other values for your checking/debugging:

```<code>f[3]    = 29
f[10]   = 317
f[1000] = 3,141,549
f[2000] = 12,566,345
</code>```

Should have a reasonable performance. Let's say less than a minute for f[1000].

Shortest code wins. Usual Code-Golf rules apply.

Please post the calculation and timing of f[1001] as an example.

ContentLicense: CC BY-SA 2.5

Body:
JavaScript (ES6), 80 bytes

n=>(a=[...Array(n+n+1)].map(_=>i--,i=n)).map(x=>a.map(y=>r+=x*x+y*y<=n*n),r=0)|r

Alternative version, also 80 bytes:

n=>[...Array(n+n+1)].map((_,x,a)=>a.map((_,y)=>r+=x*x+(y-=n)*y<=n*n,x-=n),r=0)|r

ES7 version, also 80 bytes:

n=>[...Array(n+n+1)].map((_,x,a)=>a.map((_,y)=>r+=(x-n)**2+(y-n)**2<=n*n),r=0)|r


答:
Mathematica 98 bytes

I am assuming that the built-in function, FindShortestPath does not violate the constraint about standard loopholes.  If it does, just let me know and I'll delete this submission.

Brute force, hence slow with large values of b. I'm still thinking of ways to speed it up.

```<code>h@{a_,b_}:=Length@FindShortestPath[Graph[Apply[Join,Thread[#<->Range[2,#] #]&/@Range[b^2]]],a,b]-1
</code>```

This sets up a graph with appropriate edges between the nodes from a to b^2. FindShortestPathfinds the shortest path in the graph. Lengthcounts the nodes; Length -1 is the number of edges.

Thread[# <-> Range[2, #] #] & produces the edges of the full graph. For example,  Thread[# <-> Range[2, #] #]&[5] would produce the edges {5 <-> 2*5, 5 <-> 3*5, 5 <-> 4*5, 5 <-> 5*5}, that is, {5 <-> 10, 5 <-> 15, 5 <-> 20, 5 <-> 25}.

Title: Shortest paths in a divisor graph

Body:
Mathematica 98 bytes

I am assuming that the built-in function, FindShortestPath does not violate the constraint about standard loopholes.  If it does, just let me know and I'll delete this submission.

Brute force, hence slow with large values of b. I'm still thinking of ways to speed it up.

h@{a_,b_}:=Length@FindShortestPath[Graph[Apply[Join,Thread[#<->Range[2,#] #]&/@Range[b^2]]],a,b]-1

This sets up a graph with appropriate edges between the nodes from a to b^2. FindShortestPathfinds the shortest path in the graph. Lengthcounts the nodes; Length -1 is the number of edges.

Thread[# <-> Range[2, #] #] & produces the edges of the full graph. For example,  Thread[# <-> Range[2, #] #]&[5] would produce the edges {5 <-> 2*5, 5 <-> 3*5, 5 <-> 4*5, 5 <-> 5*5}, that is, {5 <-> 10, 5 <-> 15, 5 <-> 20, 5 <-> 25}.


问:
ASCII Art of the Day #1 - Double Knot
Write a full program or a function that takes a positive integer N as input via STDIN/command line/ARGV or function arguments and prints an ASCII double knot corresponding to the N to STDOUT.

The ASCII double knot looks like this:

```<code>  __  __  __  __  __  __
 /  \/  \/  \/  \/  \/  \
| /\/ /\/ /\/ /\/ /\/ /\ |
| \/ /\/ /\/ /\/ /\/ /\/ |
 \ \/\ \/\ \/\ \/\ \/\ \/
 /\ \/\ \/\ \/\ \/\ \/\ \
| /\/ /\/ /\/ /\/ /\/ /\ |
| \/ /\/ /\/ /\/ /\/ /\/ |
 \__/\__/\__/\__/\__/\__/
</code>```

The above is for N = 6

Here are a few more double knots for other values of N:

If N = 1, the output double knot looks like:

```<code>  __
 /  \
| /\ |
| \/ |
 \ \/
 /\ \
| /\ |
| \/ |
 \__/
</code>```

For N = 2, its

```<code>  __  __
 /  \/  \
| /\/ /\ |
| \/ /\/ |
 \ \/\ \/
 /\ \/\ \
| /\/ /\ |
| \/ /\/ |
 \__/\__/
</code>```

For N = 3, its

```<code>  __  __  __
 /  \/  \/  \
| /\/ /\/ /\ |
| \/ /\/ /\/ |
 \ \/\ \/\ \/
 /\ \/\ \/\ \
| /\/ /\/ /\ |
| \/ /\/ /\/ |
 \__/\__/\__/
</code>```

and similarly, the pattern continues and any larger value of N.

Details:

The input is always a positive integer greater than 0.

Trailing newline is optional

There should either be no trailing spaces in each line, or enough trailing spaces such that each row's length is 4*N + 2.

There should never be any leading space that aren't part of the specified pattern.

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

Series Leaderboard

I am converting this into a series of ASCII art challenges and thus adding a leader board for the series (snippet by Martin). To make sure that your answers show up, please start every 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>```

/* Configuration */

var QUESTION_IDs = [50484, 50521, 50625, 51123, 51222]; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!.FjwQBrX2KXuFkv6p2lChi_RjzM19";

/* App */

var answers = [], page = 1, currentQ = -1;

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

function getAnswers() {
  $.ajax({
    url: answersUrl(page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      if (data.has_more) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SIZE_REG = /\d+(?=[^\d&]*(?:<(?:s>((?!>).)*<\/s>|((?!>).)+>)[^\d&]*)*$)/;
var NUMBER_REG = /\d+/;
var LANGUAGE_REG = /^#*\s*([^\n,]+)(?=,)/;//

function shouldHaveHeading(a) {
  var pass = false;
  var lines = a.body_markdown.split("\n");
  try {
    pass |= /^#/.test(a.body_markdown);
    pass |= ["-", "="]
              .indexOf(lines[1][0]) > -1;
    pass &= LANGUAGE_REG.test(a.body_markdown);
  } catch (ex) {}
  return pass;
}

function shouldHaveScore(a) {
  var pass = false;
  try {
    pass |= SIZE_REG.test(a.body_markdown.split("\n")[0]);
  } catch (ex) {}
  if (!pass) console.log(a);
  return pass;
}

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

function getAuthorId(a) {
  return a.owner.user_id;
}

function process() {
  answers = answers.filter(shouldHaveScore)
                   .filter(shouldHaveHeading);
  answers.sort(function (a, b) {
    var aB = +(a.body_markdown.split("\n")[0].match(SIZE_REG) || [Infinity])[0],
        bB = +(b.body_markdown.split("\n")[0].match(SIZE_REG) || [Infinity])[0];
    return aB - bB
  });

  var users = {};
  answers.forEach(function (a) {
    var headline = a.body_markdown.split("\n")[0];
    var question = QUESTION_IDs.indexOf(a.question_id);
    var size = parseInt((headline.match(SIZE_REG)||[0])[0]);
    var language = headline.match(LANGUAGE_REG)[1];
    var user = getAuthorName(a);
    var userId = getAuthorId(a);
    if (!users[userId]) users[userId] = {name: user, nAnswer: 0, answers: []};
    if (!users[userId].answers[question]) {
      users[userId].answers[question] = {size: Infinity};
      users[userId].nAnswer++;
    }
    if (users[userId].answers[question].size > size) {
      users[userId].answers[question] = {size: size, link: a.share_link}
    }
  });

  var sortedUsers = [];
  for (var userId in users)
    if (users.hasOwnProperty(userId)) {
      var user = users[userId];
      user.score = 0;
      user.completedAll = true;
      for (var i = 0; i < QUESTION_IDs.length; ++i) {
        if (user.answers[i])
          user.score += user.answers[i].size;
        else
          user.completedAll = false;
      }
      sortedUsers.push(user);
    }

  sortedUsers.sort(function (a, b) {
    if (a.nAnswer > b.nAnswer) return -1;
    if (b.nAnswer > a.nAnswer) return 1;
    return a.score - b.score;
  });

  var place = 1;
  for (var i = 0; i < sortedUsers.length; ++i) {
    var user = sortedUsers[i];
    var row = '
'+ place++ +'.	'+user.name+'	';
    for (var j = 0; j < QUESTION_IDs.length; ++j) {
      var answer = user.answers[j];
      if (answer)
        row += ''+answer.size+'	';
      else
        row += '	';
    }
    row += '	';
    if (user.completedAll)
      row += ''+user.score+'	';
    else
      row += ''+user.score+'	';
    row += '
';
    $("#users").append(row);
  }
}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body { text-align: left !important}

#leaderboard {
  width: 500px;
}

#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;
}

td.total {
  font-weight: bold;
  text-align: right;
}

td.missing {
  background: #bbbbbb;
}</code>```

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

Leaderboard

    Missing scores are shown as grey cells. A grey total indicates that the user has not participated in all challenges and is not eligible for the overall victory yet.

	User
        #1
        #2
        #3
        #4
        #5
        	Total

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

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

```

Series so far

1. Double Knot

2. Flow Snakes

3. Chinese Shrines

4. Zodiac Signs

5. Random Diamond Tilings

Title: ASCII Art of the Day #1 - Double Knot

Body:
JavaScript (ES6), <s>158</s> <s>154</s> <s>148</s> 137 bytes

n=>`    __
 /\\/ - \\/
 /\\/\\-__/`.replace(/-/g,` \\
| / /\\ |
|  /\\/ |
 \\/\\`).replace(/(..)(....)/g,(_,l,m)=>l+m.repeat(n).slice(2))

Edit: Saved 11 bytes thanks to @Bálint.


答:
Clojure/ClojureScript, 85 chars

```<code>#(apply + 1(for[m[(inc %)]x(range 1 m)y(range m):when(<=(+(* x x)(* y y))(* % %))]4))
</code>```

Brute forces the first quadrant, including the y axis but not the x axis.  Generates a 4 for every point, then adds them together with 1 for the origin.  Runs in under 2 seconds for input of 1000.

Abuses the hell out of for to define a variable and save a few characters.  Doing the same to create an alias for range doesn't save any characters (and makes it run significantly slower), and it seems unlikely that you're going to save anything by making a square function.

Title: Code-Golf: Lattice Points inside a Circle

Body:
The following picture shows the problem:

Write a function that, given an integer as the circle radius, calculates the number of lattice points inside the centered circle (including the boundary).

The image shows:

```<code>f[1] = 5  (blue points)
f[2] = 13 (blue + red points)
</code>```

other values for your checking/debugging:

```<code>f[3]    = 29
f[10]   = 317
f[1000] = 3,141,549
f[2000] = 12,566,345
</code>```

Should have a reasonable performance. Let's say less than a minute for f[1000].

Shortest code wins. Usual Code-Golf rules apply.

Please post the calculation and timing of f[1001] as an example.

Body:
Clojure/ClojureScript, 85 chars

#(apply + 1(for[m[(inc %)]x(range 1 m)y(range m):when(<=(+(* x x)(* y y))(* % %))]4))

Brute forces the first quadrant, including the y axis but not the x axis.  Generates a 4 for every point, then adds them together with 1 for the origin.  Runs in under 2 seconds for input of 1000.

Abuses the hell out of for to define a variable and save a few characters.  Doing the same to create an alias for range doesn't save any characters (and makes it run significantly slower), and it seems unlikely that you're going to save anything by making a square function.


答:
Pyke, 14 bytes

```<code>QFXQX-_,B)s}}h
</code>```

Try it here!

Body:
Pyke, 14 bytes

QFXQX-_,B)s}}h

Try it here!


Body:
Haskell, 44 bytes

f n|w<-[-n..n]=sum[1|x<-w,y<-w,x*x+y*y<=n*n]


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

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

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

This function is different drom others, it does follow a bunch of pure mathematical calculations and factorisations but has nothing to do with paths or graphs.

Example of function call:

```<code> t(2,3,0)

 p =

 4
</code>```

All test cases are satisfied

Explanation:

Before beginning with explanations lets prove some lemmas "not green ones":

Lemma(1): An optimal path between any two numbers (a,b) exists in a way the nodes are firstly increasing then decreasing.

Why ? This is simply proven because the maximal integer amount that divides any number a is respectively big as the number a itself, so as a clever approach we must choose to multiply a as much as possible to make it sufficiently bigger, then dividing by bigger values. If ever we do the way round, the number a shrinks, so we need needlessly more iterations to multiply it gradually that we are dispensed with.

Lemma(2): From a number a to b, if gcd(a,b)=1 a is multiplied by b, if b is bigger than a it will be multiplied by a known number c, if gcd>1 a must be multiplied gradually by the biggest divisor of b/gcd named d that verifies the condition a >= d also when all d's namely the minimum are bigger than a, a receives a*c again.

This assumption is simple to prove any starting node a must be multiplied until it reaches the smallest multiple of a and b so either we multiply by proportions of b*gcd beginning by the maximum which verifies the main condition, that guarantees always the shortest path to smp before division process begins, or when d isnt available a number c is multiplied by a to make a valid condition a>=d for this first stage.

Lemma(3): From a graph-ultimum multiple of a to b, the gcd of this number and b is b itself

Well this is just a consequence of the previous manipulations, and the last remaining steps are also done gradually dividing by the biggest divisor which doesnt exceed its square root.

Dilemma: What is the optimum number c to be iteratively multiplied by a that would lead straight along to the opening condition for stage 1 then the ultimum?

Good question, for any simple situation there is a simple parry, so assuming an example of two ends (a,b)=(4,26) factorized like this:

```<code>  2 | 2
  2 | 13
</code>```

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

```<code>  2 | 2
  5 | 13
</code>```

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

```<code>  2 | 2
  5 | 13
  3 |
</code>```

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

and one more thing ........ HAIL MATHS...

These are my comparative results with @flawr 's ones just pay attention that i made an upper bound for time execution consering flawr's algorithm, it takes too much time!

You may insert the starting and ending scanning ranges as variables a and b in the header of online compilable code.

Title: Shortest paths in a divisor graph

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

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

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

This function is different drom others, it does follow a bunch of pure mathematical calculations and factorisations but has nothing to do with paths or graphs.

Example of function call:

 t(2,3,0)

 p =

 4

All test cases are satisfied

Explanation:

Before beginning with explanations lets prove some lemmas "not green ones":

Lemma(1): An optimal path between any two numbers (a,b) exists in a way the nodes are firstly increasing then decreasing.

Why ? This is simply proven because the maximal integer amount that divides any number a is respectively big as the number a itself, so as a clever approach we must choose to multiply a as much as possible to make it sufficiently bigger, then dividing by bigger values. If ever we do the way round, the number a shrinks, so we need needlessly more iterations to multiply it gradually that we are dispensed with.

Lemma(2): From a number a to b, if gcd(a,b)=1 a is multiplied by b, if b is bigger than a it will be multiplied by a known number c, if gcd>1 a must be multiplied gradually by the biggest divisor of b/gcd named d that verifies the condition a >= d also when all d's namely the minimum are bigger than a, a receives a*c again.

This assumption is simple to prove any starting node a must be multiplied until it reaches the smallest multiple of a and b so either we multiply by proportions of b*gcd beginning by the maximum which verifies the main condition, that guarantees always the shortest path to smp before division process begins, or when d isnt available a number c is multiplied by a to make a valid condition a>=d for this first stage.

Lemma(3): From a graph-ultimum multiple of a to b, the gcd of this number and b is b itself

Well this is just a consequence of the previous manipulations, and the last remaining steps are also done gradually dividing by the biggest divisor which doesnt exceed its square root.

Dilemma: What is the optimum number c to be iteratively multiplied by a that would lead straight along to the opening condition for stage 1 then the ultimum?

Good question, for any simple situation there is a simple parry, so assuming an example of two ends (a,b)=(4,26) factorized like this:

  2 | 2
  2 | 13

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

  2 | 2
  5 | 13

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

  2 | 2
  5 | 13
  3 |

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

and one more thing ........ HAIL MATHS...

These are my comparative results with @flawr 's ones just pay attention that i made an upper bound for time execution consering flawr's algorithm, it takes too much time!

You may insert the starting and ending scanning ranges as variables a and b in the header of online compilable code.


答:
PHP, <s>128</s> 120 bytes

```<code>$d=$argv[]=10;
foreach($argv as$a)
  if($r){$p=min(max($p+$a*$d,0),100);$r=$p<1||99<$p;$d=-$d;}else$r=1;
echo"$p% ".DU[$d>0];
</code>```

The code is wrapped here to fit in the code box. Put everything on a single line, put the PHP open marker in front of it and save it into a file. Or run it from the command line using php -d error_reporting=0 -r '...the code...' [arguments].

The ungolfed source code, the test suite and examples of usage can be found on github.

Title: Is the electric garage door open?

Body:
PHP, <s>128</s> 120 bytes

$d=$argv[]=10;
foreach($argv as$a)
  if($r){$p=min(max($p+$a*$d,0),100);$r=$p<1||99<$p;$d=-$d;}else$r=1;
echo"$p% ".DU[$d>0];

The code is wrapped here to fit in the code box. Put everything on a single line, put the PHP open marker in front of it and save it into a file. Or run it from the command line using php -d error_reporting=0 -r '...the code...' [arguments].

The ungolfed source code, the test suite and examples of usage can be found on github.


问:
Find how many pair elements sums up to N
Based on a recent question in StackOverflow

Write a program/function that takes in one ARRAY/list and returns the number of pair-values which sums up to a given TOTAL.

Explaining

```<code>TOTAL=4, ARRAY=[1,3,7,1,-3] => RESULT=2
</code>```

The result was 2 because 1 + 3 and 7 + -3 are valid pairs which sums up to TOTAL=4.

When one pair is formed, you should not count any of its values again

Also, you are not allowed to add any value that is not present in the ARRAY.

This is code-golf, shortest in bytes wins

All values will be between your language's int min-max.

Another cases

```<code>9, [1,2,3,5,4,6,7,-10] => 3          // [2,7]  [3,6]  [5,4]
0, [] => 0                           //
0, [1,-2,0,-1,2] => 2                // [1,-1]  [-2,2]
5, [5,5,5,0,-1,1,-5] => 1            // [5,0]
3, [7,-7,8,3,9,1,-1,5] => 0          //
2, [1,1] => 1                        // [1,1]
2, [1,1,1,1,1] => 2                  // [1,1]  [1,1]
4, [1,3,3,3] => 1                    // [1,3]
</code>```

答:
Pyth - 13 bytes

```<code>l{SMfqQsT.PE2
</code>```

Test Suite.

Body:
Pyth - 13 bytes

l{SMfqQsT.PE2

Test Suite.


答:
Matlab(38)

```<code> @(a,b)nnz(sum(nchoosek([b,.5],2)')==a)
</code>```

the 0.5 part is a dodge for second test case

cropped by 2 bytes following Alex' comment.

Title: Find how many pair elements sums up to N

Body:
Based on a recent question in StackOverflow

Write a program/function that takes in one ARRAY/list and returns the number of pair-values which sums up to a given TOTAL.

Explaining

```<code>TOTAL=4, ARRAY=[1,3,7,1,-3] => RESULT=2
</code>```

The result was 2 because 1 + 3 and 7 + -3 are valid pairs which sums up to TOTAL=4.

When one pair is formed, you should not count any of its values again

Also, you are not allowed to add any value that is not present in the ARRAY.

This is code-golf, shortest in bytes wins

All values will be between your language's int min-max.

Another cases

```<code>9, [1,2,3,5,4,6,7,-10] => 3          // [2,7]  [3,6]  [5,4]
0, [] => 0                           //
0, [1,-2,0,-1,2] => 2                // [1,-1]  [-2,2]
5, [5,5,5,0,-1,1,-5] => 1            // [5,0]
3, [7,-7,8,3,9,1,-1,5] => 0          //
2, [1,1] => 1                        // [1,1]
2, [1,1,1,1,1] => 2                  // [1,1]  [1,1]
4, [1,3,3,3] => 1                    // [1,3]
</code>```

Body:
Matlab(38)

 @(a,b)nnz(sum(nchoosek([b,.5],2)')==a)

the 0.5 part is a dodge for second test case

cropped by 2 bytes following Alex' comment.


答:
Pyth, 9 bytes

```<code>/sM{.cSE2
</code>```

Test suite

Takes the number and array newline separated.

Explanation:

```<code>/sM{.cSE2
/sM{.cSE2Q    Implicit variable introduction.
              Implicit: Q = eval(input())
       E      Take the array as input.
      S       Sort the input.
    .c  2     Form all ordered pairs.
   {          Deduplicate.
 sM           Map each to its sum.
/        Q    Count the number of occurrences of Q in the resulting list.
</code>```

Body:
Pyth, 9 bytes

/sM{.cSE2

Test suite

Takes the number and array newline separated.

Explanation:

/sM{.cSE2
/sM{.cSE2Q    Implicit variable introduction.
              Implicit: Q = eval(input())
       E      Take the array as input.
      S       Sort the input.
    .c  2     Form all ordered pairs.
   {          Deduplicate.
 sM           Map each to its sum.
/        Q    Count the number of occurrences of Q in the resulting list.


答:
R, 48 bytes

function(x,y)sum(colSums(combn(unique(x),2))==y)
```


答:
Julia, 48 bytes

x->n->count(p->sum(p)==n,combinations(∪(x),2))
```

This is an anonymous function that accepts an array and an integer and returns an integer. To call it, assign it to a variable and call like f(x)(n).

We get all combinations of size 2 from the unique values in the input array and for each pair test whether the sum is equal to the input integer. We count all such cases and return the result.

Try it online! (includes all test cases)

Body:
Julia, 48 bytes

x->n->count(p->sum(p)==n,combinations(∪(x),2))

This is an anonymous function that accepts an array and an integer and returns an integer. To call it, assign it to a variable and call like f(x)(n).

We get all combinations of size 2 from the unique values in the input array and for each pair test whether the sum is equal to the input integer. We count all such cases and return the result.

Try it online! (includes all test cases)


答:
JavaScript (ES6), 112 67 59 52 bytes

```<code>(a,b)=>{c=0;for(i of a)a.map(j=>c+=i+j==b);return c}
</code>```

Because of amazing for-of loops of ES6, I was able to shave off 42 bytes from my previous solution!

Update : Thanks to @user6188402 for helping me shave off 3 bytes!

Update : Thanks to @Bálint for helping me shave off 15 bytes!

Try it Online!

Note : This fails for repeating numbers.

Body:
JavaScript (ES6), 112 67 59 52 bytes

(a,b)=>{c=0;for(i of a)a.map(j=>c+=i+j==b);return c}

Because of amazing for-of loops of ES6, I was able to shave off 42 bytes from my previous solution!

Update : Thanks to @user6188402 for helping me shave off 3 bytes!

Update : Thanks to @Bálint for helping me shave off 15 bytes!

Try it Online!

Note : This fails for repeating numbers.


问:
Do these squares overlap?
Given the coordinates of the upper left corners of two squares and their side lengths, determine whether the squares overlap. A square includes the top and left lines, but not the bottom and right lines. That is, a point (a,b) is inside a square with side length k that starts at (x,y) if and only if x <= a < x+k and y <= b < y+k. A square with side length 0 is degenerate and will not be considered here, thus, k will be positive.

As usual, all standard rules apply. Input and output may be in whatever form is convenient, so long as it's human readable and there is no precomputation. Be sure to specify what input format you use. Your code should take six numbers and output truthy if the squares overlap and falsy otherwise.

Test Cases

```<code>x1 y1 k1  x2 y2 k2  overlap?
 1  1  1   0  1  1  false
 0  0  3   1  1  1  true
 1  1  1   0  0  3  true
 0  0  3   2  1  2  true
 0  0  2   1  1  2  true
 1  1  2   0  0  2  true
 0  1  2   1  0  2  true
 1  0  2   0  1  2  true
 2  0  2   0  2  2  false
 1  0  3   0  1  1  false
 0  2  3   0  0  2  false
</code>```

All inputs will be non-negative integers. That said, I expect that many or most solutions will also be able to handle negatives and floats.

答:
Python, 33 bytes

lambda x,y,k,X,Y,K:k>X-x>-K<Y-y<k
```
<p>Python supports chains of inequalities even when they point opposite directions.</p>
<p>The x-coordinate intervals <code>[x,x+k)</code> and <code>[X,X+K)</code> overlap as long as neither one is fully to the right of the other, which means that each interval's left endpoint is left of the other interval's right endpoint.</p>
<pre class="lang-python prettyprint-override"><code>x<X+K
X<x+k
</code>```

The can be combined into a joint inequality -K<X-x<k. Writing the same for y-coordinates and splicing them at -K gives the expression

k>X-x>-K<Y-y<k
```

Title: Do these squares overlap?

Body:
Python, 33 bytes

lambda x,y,k,X,Y,K:k>X-x>-K<Y-y<k

Python supports chains of inequalities even when they point opposite directions.

The x-coordinate intervals [x,x+k) and [X,X+K) overlap as long as neither one is fully to the right of the other, which means that each interval's left endpoint is left of the other interval's right endpoint.

x<X+K
X<x+k

The can be combined into a joint inequality -K<X-x<k. Writing the same for y-coordinates and splicing them at -K gives the expression

k>X-x>-K<Y-y<k


答:
JavaScript (ES6), 38 bytes

```<code>(a,b,c,d,e,f)=>d-a<c&a-d<f&e-b<c&b-e<f
</code>```

If d - a ≥ c then the second square is to the right of the first. Similarly the other conditions check that it is not to the left, below or above.

Title: Do these squares overlap?

Body:
Given the coordinates of the upper left corners of two squares and their side lengths, determine whether the squares overlap. A square includes the top and left lines, but not the bottom and right lines. That is, a point (a,b) is inside a square with side length k that starts at (x,y) if and only if x <= a < x+k and y <= b < y+k. A square with side length 0 is degenerate and will not be considered here, thus, k will be positive.

As usual, all standard rules apply. Input and output may be in whatever form is convenient, so long as it's human readable and there is no precomputation. Be sure to specify what input format you use. Your code should take six numbers and output truthy if the squares overlap and falsy otherwise.

Test Cases

```<code>x1 y1 k1  x2 y2 k2  overlap?
 1  1  1   0  1  1  false
 0  0  3   1  1  1  true
 1  1  1   0  0  3  true
 0  0  3   2  1  2  true
 0  0  2   1  1  2  true
 1  1  2   0  0  2  true
 0  1  2   1  0  2  true
 1  0  2   0  1  2  true
 2  0  2   0  2  2  false
 1  0  3   0  1  1  false
 0  2  3   0  0  2  false
</code>```

All inputs will be non-negative integers. That said, I expect that many or most solutions will also be able to handle negatives and floats.

Body:
JavaScript (ES6), 38 bytes

(a,b,c,d,e,f)=>d-a<c&a-d<f&e-b<c&b-e<f

If d - a ≥ c then the second square is to the right of the first. Similarly the other conditions check that it is not to the left, below or above.


答:
TI Basic, 36 bytes

```<code>Prompt X,Y,K,Z,θ,L:Z-X<K and X-Z<L and θ-Y<K and Y-θ<L
</code>```

Title: Do these squares overlap?

Body:
TI Basic, 36 bytes

Prompt X,Y,K,Z,θ,L:Z-X<K and X-Z<L and θ-Y<K and Y-θ<L


答:
Java, 78 bytes

```<code>Object o(int a,int b,int c,int d,int e,int f){return d-a<c&a-d<f&e-b<c&b-e<f;}
</code>```

Title: Do these squares overlap?

Body:
Java, 78 bytes

Object o(int a,int b,int c,int d,int e,int f){return d-a<c&a-d<f&e-b<c&b-e<f;}