答:
><>, 52+2 = 54 bytes

The input number needs to be present on the stack at program start, so there's +2 bytes for the -v flag. Try it online!

```<code>:0)?v~ln;>~$-]
03[}\::
@@:$<    v?=0:-1}+{~$?@@01%@:
</code>```

4 annoying bytes wasted on alignment issues. Bah.

This one works by building the sequence from n to 0 on the stack. Once 0 has been reached, pop it and ouput the length of the remaining stack.

By the way , it runs in O(n^2) time, so I wouldn't try n = 100000...

Title: Divisor reduction

Body:
><>, 52+2 = 54 bytes

The input number needs to be present on the stack at program start, so there's +2 bytes for the -v flag. Try it online!

:0)?v~ln;>~$-]
03[}\::
@@:$<    v?=0:-1}+{~$?@@01%@:

4 annoying bytes wasted on alignment issues. Bah.

This one works by building the sequence from n to 0 on the stack. Once 0 has been reached, pop it and ouput the length of the remaining stack.

By the way , it runs in O(n^2) time, so I wouldn't try n = 100000...


问:
Get the most dominant color!
In this challenge, your task is to write a program that takes in an image and returns the most dominant color in it. Dominant color here means the color with which most of the image is covered (see the test cases for a better understanding).

Input

An image's path. You'll have to load that image in your program. You can take the input as STDIN, function argument or whatever suits your language. You may assume that the image will have only .png extension.

Output

The most dominant color in any format. (But it should be accurate, you can't return Red for #f88379). The type of output depends on you. If there is an equal distribution of colors in the image or there are more than one dominant color, then your program should return "Equal". You can show the output by printing on screen, logging on command line or console, or whatever suits you.

Test Cases

=> Red/#ff0000/rgba(255,0,0)

.

=> "Equal"

=> White (or the same color in any other format)

In these test cases, I have posted images rather than image paths, but you'll be given image paths only as input.

Note If your language contains a built-in for this, then you must NOT use it. Please add a screenshot or a link to a screenshot to prove that your program works.

This is code-golf, so the shortest answer in bytes wins!

答:
PowerShell v2+, 215 bytes

```<code>$a=New-Object System.Drawing.Bitmap $args[0]
$b=@{}
0..($a.Height-1)|%{$h=$_;0..($a.Width-1)|%{$b[$a.GetPixel($_,$h).Name]++}}
if(($c=$b.GetEnumerator()|Sort value)[-1].value-eq$c[-2].value){"Equal";exit}$c[-1].Name
</code>```

(Newlines/semicolons are equivalent, so newlines left in for clarity)

Creates a new Bitmap object, based on the input argument, stores it to $a. Creates a new empty hashtable $b, which will be used for our pixel counting.

We then loop over the image a row at a time with two loops %{...}. Each inner loop we use the .GetPixel method to return a Color object for the particular x/y coordinate we're at. We take the .Name of that color (which is a hexadecimal of the form ARGB, for example ffff0000 would be pure red fully opaque) and use that as the index into $b, incrementing that particular value by one.

So, we've now got a fully populated hashtable of pixel colors, with the values of each entry corresponding to how many pixels of that color there are. We then take $b and pump it through a Sort based on those values, and store that sorted result back into $c. If the last [-1] and second-to-last [-2] values are equal, we output "Equal" and exit. Else, we output the .Name of the last [-1] entry.

ContentLicense: CC BY-SA 3.0

Title: Get the most dominant color!

Body:
PowerShell v2+, 215 bytes

$a=New-Object System.Drawing.Bitmap $args[0]
$b=@{}
0..($a.Height-1)|%{$h=$_;0..($a.Width-1)|%{$b[$a.GetPixel($_,$h).Name]++}}
if(($c=$b.GetEnumerator()|Sort value)[-1].value-eq$c[-2].value){"Equal";exit}$c[-1].Name

(Newlines/semicolons are equivalent, so newlines left in for clarity)

Creates a new Bitmap object, based on the input argument, stores it to $a. Creates a new empty hashtable $b, which will be used for our pixel counting.

We then loop over the image a row at a time with two loops %{...}. Each inner loop we use the .GetPixel method to return a Color object for the particular x/y coordinate we're at. We take the .Name of that color (which is a hexadecimal of the form ARGB, for example ffff0000 would be pure red fully opaque) and use that as the index into $b, incrementing that particular value by one.

So, we've now got a fully populated hashtable of pixel colors, with the values of each entry corresponding to how many pixels of that color there are. We then take $b and pump it through a Sort based on those values, and store that sorted result back into $c. If the last [-1] and second-to-last [-2] values are equal, we output "Equal" and exit. Else, we output the .Name of the last [-1] entry.


问:
Hi, can you draw some odd art? Bye!
Create a program that outputs "Hi, Hello!" in k bytes. By altering n bytes, the code should output all odd numbers in the range 5 <= x <= 25.
Changing another m bytes should result in a code that prints the following frame in ASCII-art:

```<code>+-+
| |
+-+
</code>```

Change another o bytes, and print Hello, bye!.

m, n and o are calculated in Levenshtein distance (cumulative). n is the distance from the first to the second code. m is the distance between the second and third and so on.

The score of your submission will be 0.5*k + n + m + o.

As an example:

```<code>The code that prints `Hi, Hello!` is 30 bytes.              15
Add two bytes and remove one and print the odd numbers     + 3
Alter three bytes in place, and add one to print the box   + 4
Remove four bytes and print `Hello, bye!`                  + 4
Total score:                                                26
</code>```

Rules

All codes must be in the same language

You have to follow the given order (i.e. the first code prints Hi, Hello, the second prints the numbers etc.)

The strings and ASCII-box must be exactly as specified. The list of digits can be on any suitable format

答:
Octave, 34

Managed to get it down to 62 bytes. A Levenshtein distance of 3 takes the score up to 34.

```<code>disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{1})
</code>```

Using double quoted strings, we can use the newline character \n instead of the ASCII value 10.

Tests:

```<code>disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{1})
Hi, Hello!

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{2})
+-+
| |
+-+

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{3})
5    7    9   11   13   15   17   19   21   23   25

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{4})
Hello, bye!
</code>```

Title: Hi, can you draw some odd art? Bye!

Body:
Octave, 34

Managed to get it down to 62 bytes. A Levenshtein distance of 3 takes the score up to 34.

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{1})

Using double quoted strings, we can use the newline character \n instead of the ASCII value 10.

Tests:

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{1})
Hi, Hello!

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{2})
+-+
| |
+-+

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{3})
5    7    9   11   13   15   17   19   21   23   25

disp({'Hi, Hello!',["+-+\n| |\n+-+"],5:2:25,'Hello, bye!'}{4})
Hello, bye!


问:
Calculator that adds char values

Task

Build a calculator, that takes any string, from a file, stdin or whatever, and adds up all the values of the chars.

Example

```<code>Input
Hello World!

Output
1085
</code>```

Rules

The calculator needs to accept just ASCII encoding.

The shortest code wins.

Notes

Regarding to the comment of m.buettner, I need to say, I didn't thought of the multibyte part.

So I leave it as a bonus thing aswell.

The calculator should be run as written, so no need to modify before compiling or interpreting.

Bonus

Thanks to Synthetica, here is one more bonus,

The program that has the lowest output when you use its code as its input wins gets a star.

I don't want to modify it completly.

If you write it additional to output the (right) value in UTF-8 you get a star.

The code that executes fastest on my Laptop (Lenovo Yoga 13 Intel Core i5 3317U 1.7Ghz, 8GB RAM, 128GB SSD, Intel HD 4000, Windows 8) gets a star.

Web codes will run first under IE11 with chakra and then in FireFox 29.0.1 with SpiderMonkey

Linux code will run on a Raspberry Pi with Raspbian.

The teststring is this:

```<code>q/%8hnp>T%y?'wNb\},9krW &D9']K$n;l.3O+tE*$*._B^s!@k\&Cl:EO1zo8sVxEvBxCock_I+2o6 yeX*0Xq:tS^f)!!7=!tk9K<6#/E`ks(D'$z$\6Ac+MT&[s[]_Y(`<g%"w%cW'`c&q)D$0#C$QGf>?A$iawvc,}`9!('`c&q)D$0#C$QGf>?A$iawvc,}`9!(
</code>```

Have fun coding :)

Bonusscoring

I plan to do the scoring at this Saturday so the 07.06.14, all answers after that date won't get bonus points ;)

You can download the code I gonna use for testing here feel free to fork and improve it :)

Little update because of the bonus, my laptop is partially broken so I will do it probably next weekend, I am really sorry for that :(

答:
Hoon, 18 bytes

```<code>|*
*
(roll +< add)
</code>```

This is a wet gate, so that I don't have to specify tape instead of *. This has the added bonus of it being fully generic, so it could actually accept (list @ud) too. Wet gates typecheck at the call site, instead of definition.

+< is the sample of the gate, indexed into the sample with tree navigation syntax because it's shorter than naming the function arguments. |*(a/* a) is longer than |*(* +<).

```<code>> %.  "Hello World!"
  |*
  *
  (roll +< add)
b=1.085
</code>```

Unfortunately, this doesn't work correctly as-is with unicode. Urbit's string literals are lists of UTF8 chars. You can use ++tuba to convert it to UTF32, though.

```<code>> %.  "⚳ℚ⊻"
  |*
  *
  (roll +< add)
b=1.622

> %.  (tuba "⚳ℚ⊻")
  |*
  *
  (roll +< add)
b=27.272
</code>```

Title: Calculator that adds char values

Body:
Hoon, 18 bytes

|*
*
(roll +< add)

This is a wet gate, so that I don't have to specify tape instead of *. This has the added bonus of it being fully generic, so it could actually accept (list @ud) too. Wet gates typecheck at the call site, instead of definition.

+< is the sample of the gate, indexed into the sample with tree navigation syntax because it's shorter than naming the function arguments. |*(a/* a) is longer than |*(* +<).

> %.  "Hello World!"
  |*
  *
  (roll +< add)
b=1.085

Unfortunately, this doesn't work correctly as-is with unicode. Urbit's string literals are lists of UTF8 chars. You can use ++tuba to convert it to UTF32, though.

> %.  "⚳ℚ⊻"
  |*
  *
  (roll +< add)
b=1.622

> %.  (tuba "⚳ℚ⊻")
  |*
  *
  (roll +< add)
b=27.272


问:
Print the nth prime that contains n
This question will be a twist on finding the nth prime number.

Challenge

You must write a program that will take one input n, and output the nth prime number whose decimal representation contains the decimal representation of n as a subtring.

Confused? Here are some examples.

```<code>n=1
Primes: 2, 3, 5, 7, 11
                    ^1 first prime that contains a 1
Output: 11

n=2
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
        ^1                          ^2 second prime that contains a 2
Output: 23

n=3
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
           ^1           ^2          ^3 third prime that contains a 3
Output: 23

n=10
Primes: 2, 3, 5, 7, 11, ..., 97, 101, 103, 107, 109, ..., 997, 1009, 1013, 1019, 1021, 1031, 1033
                                 ^1   ^2   ^3   ^4             ^5    ^6    ^7    ^8    ^9    ^10 tenth prime that contains a 10
Output: 1033
</code>```

This is code-golf, so lowest byte count wins.

If something is confusing, please leave a comment.

答:
Perl 6, 41 bytes

->$n {grep({.is-prime&&/$n/},2..*)[$n-1]}
```

<h3>Explanation:</h3>

<pre class="lang-perl6 prettyprint-override"><code>-> $n { # has one parameter
  grep(
    {
      .is-prime # check that it is prime
      &&        # and
      / $n /    # that it contains the argument in the "string"
    },
    2 .. *      # for all numbers starting with 2
  )[ $n - 1 ]   # only take the $n-th one
                # ( accounting for 0 based array access )
}
</code>```

Test:

#! /usr/bin/env perl6
use v6.c;
use Test;

my &prefix:<ℙ> = ->$n {grep({.is-prime&&/$n/},2..*)[$n-1]}

my @test = (
  1  => 11,
  2  => 23,
  3  => 23,
  10 => 1033,
);

plan +@test;

for @test {
  is ℙ.key, .value, .gist
}
```

<pre class="lang-none prettyprint-override"><code>1..4
ok 1 - 1 => 11
ok 2 - 2 => 23
ok 3 - 3 => 23
ok 4 - 10 => 1033
</code>```

Title: Print the nth prime that contains n

Body:
Perl 6, 41 bytes

->$n {grep({.is-prime&&/$n/},2..*)[$n-1]}

Explanation:

-> $n { # has one parameter
  grep(
    {
      .is-prime # check that it is prime
      &&        # and
      / $n /    # that it contains the argument in the "string"
    },
    2 .. *      # for all numbers starting with 2
  )[ $n - 1 ]   # only take the $n-th one
                # ( accounting for 0 based array access )
}

Test:

#! /usr/bin/env perl6
use v6.c;
use Test;

my &prefix:<ℙ> = ->$n {grep({.is-prime&&/$n/},2..*)[$n-1]}

my @test = (
  1  => 11,
  2  => 23,
  3  => 23,
  10 => 1033,
);

plan +@test;

for @test {
  is ℙ.key, .value, .gist
}

1..4
ok 1 - 1 => 11
ok 2 - 2 => 23
ok 3 - 3 => 23
ok 4 - 10 => 1033


问:
Divisor reduction
A divisor of a number n is any number that evenly divides n, including 1 and n itself. The number of divisors d(n) is how many divisors a number has. Here's d(n) for the first couple n:

```<code>n    divisors    d(n)
1    1           1
2    1, 2        2
3    1, 3        2
4    1, 2, 4     3
5    1, 5        2
6    1, 2, 3, 6  4
</code>```

We can repeatedly subtract the number of divisors from a number. For example:

```<code>16                  = 16
16 - d(16) = 16 - 5 = 11
11 - d(11) = 11 - 2 = 9
 9 - d( 9) =  9 - 3 = 6
 6 - d( 6) =  6 - 4 = 2
 2 - d( 2) =  2 - 2 = 0
</code>```

In this case it took 5 steps to get to 0.

Write a program or function that given a nonnegative number n returns the number of steps it takes to reduce it to 0 by repeated subtraction of the number of divisors.

Examples:

```<code>0, 0
1, 1
6, 2
16, 5
100, 19
100000, 7534
</code>```

答:
><>, 36 + 3 = 39  bytes

```<code>:?v~ln; >~&
:}\0&
+&>1-:?!^:{:}$%0)&
</code>```

The implementation's relatively straightforward, with each iteration being sum(n%k>0 for k in range(1,n-1)). +3 bytes for the -v flag, per meta.

Try it online!

Title: Divisor reduction

Body:
><>, 36 + 3 = 39  bytes

:?v~ln; >~&
:}\0&
+&>1-:?!^:{:}$%0)&

The implementation's relatively straightforward, with each iteration being sum(n%k>0 for k in range(1,n-1)). +3 bytes for the -v flag, per meta.

Try it online!


问:
Make your language unusable
Try to write some code in your language and make it not satisfying our criteria of being a programming language any more.

A language satisfies our criteria (simplified version for this challenge) of being a programming language if:

It can read user input representing tuples of positive integers in some way.

It can output at least two different possible results depending on the input.

It can take two positive integers and add them (and the result can affect the output).

It can take a positive integer and decide whether it is a prime (and the result can affect the output).

For the purpose of this challenge, any kind of output that isn't an allowed output method for a normal challenge is ignored. So it doesn't matter whether the program can also play a piece of music, or posting via HTTP, etc.

Update: You can also choose one or some of the allowed output methods, and ignore all the others. But you must use the same definition everywhere in the following criteria. And if your program can disable more than one output methods — that worths more upvotes.

Examples like making it not able to output, or disabling all the loop constructs so it won't be able to do primality test and making sure the user cannot re-enable them.

You should leave a place for inserting new code. By default, it is at the end of your code. If we consider putting the source code in that place in your answer and running the full code as a complete program the interpreter of a new language, that language should not satisfy the criteria.

But the inserted code must be executed in such a way like a language satisfying the criteria:

The inserted code must be grammatically the same as something (say it's a code block in the following criteria) that generally do satisfy the criteria, from the perspective of whoever wants to write a syntax highlighter. So it cannot be in a string, comment, etc.

The inserted code must be actually executed, in a way it is supposed to satisfy the criteria. So it cannot be in an unused function or sizeof in C, you cannot just execute only a non-functional part in the code, and you cannot put it after an infinite loop, etc.

You can't limit the number of possible grammatically correct programs generated this way. If there is already something like a length limit in the language you are using, it shouldn't satisfy the criteria even if this limit is removed.

You can't modify or "use up" the content of input / output, but you can prevent them from being accessed.

These criteria usually only applies to languages without explicit I/O:

Your code should redirect the user input (that contains informations of arbitrary length) to the inserted code, if a code block isn't usually able to get the user input directly / explicitly in the language you are using.

Your code should print the returned value of the inserted code, if a code block isn't usually able to output things directly / explicitly in the language you are using.

In case you print the returned value, and it is typed in the language you are using, the returned type should be able to have 2 different practically possible values. For example, you cannot use the type struct {} or struct {private:int x;} in C++.

This is popularity-contest. The highest voted valid answer (so nobody spotted an error or all errors are fixed) wins.

Clarifications

You shouldn't modify the code in the text form, but can change the syntax before the code is interpreted or compiled.

You can do other things while the code is running. But the reason that it doesn't satisfy the criteria should be within the inserted code itself. It can error because of the interference of another thread, but not just be killed by another thread.

All the specs basically means it should be grammatically likely satisfying the criteria if all the built-ins were not changed but not actually do. It's fine if you find any non-grammatical workarounds, such as passing the parameters to the code block correctly, but make them not able to be used in some way.

Again, the inserted code must be actually executed. Code after an infinite loop or crashing is considered "not actually executed", thus not valid. Those answers might be interesting, but there are already some other infinite loop or crashing questions on this site, and you may find a more appropriate one to answer. If not, consider asking a new question. Examples of those questions are:

Shortest infinite loop producing no output

Why isn't it ending?

Loop without 'looping'

Challenge: Write a piece of code that quits itself

Ridiculous Runtime Errors

Crash your favorite compiler

Leaderboard

var QUESTION_ID=61115/*,OVERRIDE_USER=8478*/;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,/*getComments()*/(more_answers?getAnswers():process())}})}/*function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}*/function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),score:s.score,language:a[1],lang:jQuery('
').html(a[1]).text(),link:s.share_link})}),e.sort(function(e,s){var r=e.score,a=s.score;return a-r});var s={},r=1,a=null,n=1;e.forEach(function(e){e.score!=a&&(n=r),a=e.score,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",e.n=n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.score).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang.toUpperCase())-(e.lang.toUpperCase()<s.lang.toUpperCase())||(e.lang>s.lang)-(e.lang<s.lang)});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{PLACE}}",o.n).replace("{{LANGUAGE}}",o.language).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.score).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<(?:h\d|(?!.*<h\d>)p)>\s*((?:[^,;(\s]| +[^-,;(\s])+)(?=(?: *(?:[,;(]| -).*?)?\s*<\/(h\d|p)>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;float:left}table{width:250px}table thead{font-weight:700}table td{padding:5px}</code>```

 <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea">

Leaderboard

	Author	Language	Score

Sorted by Language

	Language	User	Score

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

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

```

答:
Hoon

```<code>=<  ~
(your code)
</code>```

Hoon is a odd. It's pretty much entirely unlike other programming languages, not only in syntax but in semantics. Unlike languages like Hexagony, though, it wasn't made to be purposely esoteric.

Hoon compiles to Nock, a minimal combinator based VM. Nock is stupid: the spec can be gzipped to 340 bytes. The only math operation is incrementing. Everything is a noun: an atom (bignum) or a cell (pair of nouns), with the entire memory model arranged in an immutable acyclic binary tree. The only output is the noun that your expression reduces to.

Because of the weird compilation target, Hoon is also weird: it's completely pure. Hoon compiles down to a Nock expression that is evaluated on a "context". The entire kernel and stdlib, along with all variables, are passed implicitly to the program by the context.

To make Hoon unusable we just use =<, which is "evaluate a in the context of b". We are always evaluating ~, which is zero. No matter what b does, it can't change the value it reduces to, and since it can't have side effect it can't do input or output.

Side note: Since you can't actually prompt for input from Hoon (purity!), by the rules it isn't actually a programming language. Input is via function arguments, output via return values (or ~&, which is more of a printf debugging feature and is transparent to the program).

For a program to get input in Urbit, you actually write a program that return a function that accepts input, and the shell asks on your behalf and passes to the callback.

Title: Make your language unusable

Body:
Hoon

=<  ~
(your code)

Hoon is a odd. It's pretty much entirely unlike other programming languages, not only in syntax but in semantics. Unlike languages like Hexagony, though, it wasn't made to be purposely esoteric.

Hoon compiles to Nock, a minimal combinator based VM. Nock is stupid: the spec can be gzipped to 340 bytes. The only math operation is incrementing. Everything is a noun: an atom (bignum) or a cell (pair of nouns), with the entire memory model arranged in an immutable acyclic binary tree. The only output is the noun that your expression reduces to.

Because of the weird compilation target, Hoon is also weird: it's completely pure. Hoon compiles down to a Nock expression that is evaluated on a "context". The entire kernel and stdlib, along with all variables, are passed implicitly to the program by the context.

To make Hoon unusable we just use =<, which is "evaluate a in the context of b". We are always evaluating ~, which is zero. No matter what b does, it can't change the value it reduces to, and since it can't have side effect it can't do input or output.

Side note: Since you can't actually prompt for input from Hoon (purity!), by the rules it isn't actually a programming language. Input is via function arguments, output via return values (or ~&, which is more of a printf debugging feature and is transparent to the program).

For a program to get input in Urbit, you actually write a program that return a function that accepts input, and the shell asks on your behalf and passes to the callback.


答:
Mathcad, [tbd] bytes

Mathcad byte equivalence scheme is yet to be determined.  Using a rough keystroke equivalence, the program uses about 39 "bytes".  Note that the while and for programming operators only take one keyboard operation each to input (ctl-] and ctl-shft-#, respectively) - indeed, they can only be entered this way from the keyboard.

What you see is exactly what gets put down on a Mathcad worksheet.  Mathcad evaluates the equations/programs and puts the output on the same sheet (eg, after the '=' evaluation operator or on the plot).

Title: Divisor reduction

Body:
A divisor of a number n is any number that evenly divides n, including 1 and n itself. The number of divisors d(n) is how many divisors a number has. Here's d(n) for the first couple n:

```<code>n    divisors    d(n)
1    1           1
2    1, 2        2
3    1, 3        2
4    1, 2, 4     3
5    1, 5        2
6    1, 2, 3, 6  4
</code>```

We can repeatedly subtract the number of divisors from a number. For example:

```<code>16                  = 16
16 - d(16) = 16 - 5 = 11
11 - d(11) = 11 - 2 = 9
 9 - d( 9) =  9 - 3 = 6
 6 - d( 6) =  6 - 4 = 2
 2 - d( 2) =  2 - 2 = 0
</code>```

In this case it took 5 steps to get to 0.

Write a program or function that given a nonnegative number n returns the number of steps it takes to reduce it to 0 by repeated subtraction of the number of divisors.

Examples:

```<code>0, 0
1, 1
6, 2
16, 5
100, 19
100000, 7534
</code>```


答:
Haskell, <s>43</s> <s>40</s> 39 bytes

```<code>g 0=0;g n=1+g(sum$min 1.mod n<$>[1..n])
</code>```

Simple recursive approach. Usage example: g 16 -> 5.

Edit: @Lynn saved <s>3</s> 4 bytes. Thanks!

Title: Divisor reduction

Body:
Haskell, <s>43</s> <s>40</s> 39 bytes

g 0=0;g n=1+g(sum$min 1.mod n<$>[1..n])

Simple recursive approach. Usage example: g 16 -> 5.

Edit: @Lynn saved <s>3</s> 4 bytes. Thanks!


答:
Perl 5, 40 bytes

```<code>sub f{@_?(1,f((1)x grep@_%$_,1..@_)):()}
</code>```

Input and output are as lists of the requisite number of copies of 1.

Title: Divisor reduction

Body:
Perl 5, 40 bytes

sub f{@_?(1,f((1)x grep@_%$_,1..@_)):()}

Input and output are as lists of the requisite number of copies of 1.


答:
Ruby, 42 bytes

```<code>f=->n{n<1?0:1+f[n-(1..n).count{|i|n%i<1}]}
</code>```

There's a stack overflow error on the largest test case 100000, so here's an iterative version within 49 bytes. Takes a while, though, considering the O(N^2) complexity.

```<code>->n{c=0;c+=1 while 0<n-=(1..n).count{|i|n%i<1};c}
</code>```

Title: Divisor reduction

Body:
Ruby, 42 bytes

f=->n{n<1?0:1+f[n-(1..n).count{|i|n%i<1}]}

There's a stack overflow error on the largest test case 100000, so here's an iterative version within 49 bytes. Takes a while, though, considering the O(N^2) complexity.

->n{c=0;c+=1 while 0<n-=(1..n).count{|i|n%i<1};c}


答:
Python 2, 66 / 2 + 1 + 1 + 1 = 36

Python 3 answer by @MorganThrapp

Hi, Hello!
```

<p>	</p>

<pre class="lang-py prettyprint-override"><code>print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[0]
</code>```

[5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]
```

<p>	</p>

<pre class="lang-py prettyprint-override"><code>print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[1]
</code>```

+-+
| |
+-+
```

<p>	</p>

<pre class="lang-py prettyprint-override"><code>print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[2]
</code>```

Hello, bye!
```

<p>	</p>

<pre class="lang-py prettyprint-override"><code>print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[3]
</code>```

Title: Hi, can you draw some odd art? Bye!

Body:
Create a program that outputs "Hi, Hello!" in k bytes. By altering n bytes, the code should output all odd numbers in the range 5 <= x <= 25.
Changing another m bytes should result in a code that prints the following frame in ASCII-art:

```<code>+-+
| |
+-+
</code>```

Change another o bytes, and print Hello, bye!.

m, n and o are calculated in Levenshtein distance (cumulative). n is the distance from the first to the second code. m is the distance between the second and third and so on.

The score of your submission will be 0.5*k + n + m + o.

As an example:

```<code>The code that prints `Hi, Hello!` is 30 bytes.              15
Add two bytes and remove one and print the odd numbers     + 3
Alter three bytes in place, and add one to print the box   + 4
Remove four bytes and print `Hello, bye!`                  + 4
Total score:                                                26
</code>```

Rules

All codes must be in the same language

You have to follow the given order (i.e. the first code prints Hi, Hello, the second prints the numbers etc.)

The strings and ASCII-box must be exactly as specified. The list of digits can be on any suitable format

Body:
Python 2, 66 / 2 + 1 + 1 + 1 = 36

Python 3 answer by @MorganThrapp

Hi, Hello!

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[0]

[5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[1]

+-+
| |
+-+

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[2]

Hello, bye!

print('Hi, Hello!',range(5,26,2),'+-+\n| |\n+-+','Hello, bye!')[3]


问:
Largest Distinctly Sum-Free Partition
related and inspired by -- Finding sum-free partitions

A set A is defined here as being distinctly sum-free if

1) it consists of at least three elements, |A| ≥ 3, and

2) its distinct self-sum A + A = { x + y | x, y in A} (with x,y distinct, i.e., x≠y) has no elements in common with A.

(Obsolete - do not use this going forward. Left here only because some answers may have used it. It does not match with the above conditions. Alternatively, the equation x + y = z has no solution for x,y,z ∈ A (again with x,y,z distinct, i.e., x≠y, x≠z, y≠z).)

For a simple example, {1,3,5} is distinctly sum-free, but {1,3,4} is not. {1,3} and {3} are also not, since they're not at least three elements.

The challenge here is to find the largest distinctly sum-free subset of the given input.

Input

An unordered set A of integers in any convenient format.

The integers could be positive, negative, or zero, but can be assumed to fit in your language's native [int] datatype (or equivalent).

The set is guaranteed to have only distinct elements (no multisets here).

The set is not necessarily sorted.

Output

The largest subset of A (which could be A itself), that is distinctly sum-free. Output can be in any suitable format.

If no such subset exists, output an empty set or other falsey value.

If multiple subsets are tied for largest, output any or all of them.

The subset does not necessarily need be sorted, or in the same order as the input. For example, for input {1,3,5} output {5,1,3} is acceptable.

Additional Rules

Standard loopholes are forbidden.

This is code-golf, so all usual golfing rules apply, and the shortest code wins.

Examples

```<code>Input     -> Output (any or all)
{0}       -> {}
{1, 2, 3} -> {}
{1, 3, 5} -> {1, 3, 5}
{1, 2, 3, 4, 5} -> {1, 2, 5}  {1, 2, 4}  {1, 3, 5}  {2, 3, 4}  {2, 4, 5}  {3, 4, 5}
{-5, 4, 3, -2, 0} -> {-5, 4, 3}  {-5, 4, -2}  {4, 3, -2}
{-5, 4, 3, -2} -> {-5, 4, 3}  {-5, 4, -2}  {4, 3, -2}
{-17, 22, -5, 13, 200, -1, 1, 9} -> {-17, 22, -5, 13, 200, -1, 1}  {-17, 22, -5, 200, -1, 1, 9}  {-17, -5, 13, 200, -1, 1, 9}
</code>```

答:
Python, 137 bytes

A naïve approach. Loops over all subsets of the input containing at least 3 values, checking the property for each one. Returns [] when no result is found or [S] if at least one result is found (where S is some tuple).

```<code>from itertools import*
lambda a:[c for n in range(3,len(a)+1)for c in combinations(a,n)if all(x+y-z for(x,y,z)in permutations(c,3))][-1:]
</code>```

Title: Largest Distinctly Sum-Free Partition

Body:
Python, 137 bytes

A naïve approach. Loops over all subsets of the input containing at least 3 values, checking the property for each one. Returns [] when no result is found or [S] if at least one result is found (where S is some tuple).

from itertools import*
lambda a:[c for n in range(3,len(a)+1)for c in combinations(a,n)if all(x+y-z for(x,y,z)in permutations(c,3))][-1:]


答:
Ruby, 107 bytes

Input is an array. Collects one qualifying subset for each subset size from 3 to the input length, then returns the biggest one out of the ones found. Returns nil if no result is found.

Because of the conflicting spec, there are two solutions that currently have the same bytecount.

Using the first definition: ({ x + y | x, y ∈ A } ∩ A = ∅)

```<code>->s{((3..s.size).map{|i|s.combination(i).find{|e|e.combination(2).map{|a,b|a+b}&e==[]}}-[p])[-1]}
</code>```

Using the second definition (∀ x, y, z ∈ A: x + y ≠ z)

```<code>->s{((3..s.size).map{|i|s.combination(i).find{|e|e.permutation(3).all?{|a,b,c|a+b!=c}}}-[p])[-1]}
</code>```

Title: Largest Distinctly Sum-Free Partition

Body:
related and inspired by -- Finding sum-free partitions

A set A is defined here as being distinctly sum-free if

1) it consists of at least three elements, |A| ≥ 3, and

2) its distinct self-sum A + A = { x + y | x, y in A} (with x,y distinct, i.e., x≠y) has no elements in common with A.

(Obsolete - do not use this going forward. Left here only because some answers may have used it. It does not match with the above conditions. Alternatively, the equation x + y = z has no solution for x,y,z ∈ A (again with x,y,z distinct, i.e., x≠y, x≠z, y≠z).)

For a simple example, {1,3,5} is distinctly sum-free, but {1,3,4} is not. {1,3} and {3} are also not, since they're not at least three elements.

The challenge here is to find the largest distinctly sum-free subset of the given input.

Input

An unordered set A of integers in any convenient format.

The integers could be positive, negative, or zero, but can be assumed to fit in your language's native [int] datatype (or equivalent).

The set is guaranteed to have only distinct elements (no multisets here).

The set is not necessarily sorted.

Output

The largest subset of A (which could be A itself), that is distinctly sum-free. Output can be in any suitable format.

If no such subset exists, output an empty set or other falsey value.

If multiple subsets are tied for largest, output any or all of them.

The subset does not necessarily need be sorted, or in the same order as the input. For example, for input {1,3,5} output {5,1,3} is acceptable.

Additional Rules

Standard loopholes are forbidden.

This is code-golf, so all usual golfing rules apply, and the shortest code wins.

Examples

```<code>Input     -> Output (any or all)
{0}       -> {}
{1, 2, 3} -> {}
{1, 3, 5} -> {1, 3, 5}
{1, 2, 3, 4, 5} -> {1, 2, 5}  {1, 2, 4}  {1, 3, 5}  {2, 3, 4}  {2, 4, 5}  {3, 4, 5}
{-5, 4, 3, -2, 0} -> {-5, 4, 3}  {-5, 4, -2}  {4, 3, -2}
{-5, 4, 3, -2} -> {-5, 4, 3}  {-5, 4, -2}  {4, 3, -2}
{-17, 22, -5, 13, 200, -1, 1, 9} -> {-17, 22, -5, 13, 200, -1, 1}  {-17, 22, -5, 200, -1, 1, 9}  {-17, -5, 13, 200, -1, 1, 9}
</code>```

Body:
Ruby, 107 bytes

Input is an array. Collects one qualifying subset for each subset size from 3 to the input length, then returns the biggest one out of the ones found. Returns nil if no result is found.

Because of the conflicting spec, there are two solutions that currently have the same bytecount.

Using the first definition: ({ x + y | x, y ∈ A } ∩ A = ∅)

->s{((3..s.size).map{|i|s.combination(i).find{|e|e.combination(2).map{|a,b|a+b}&e==[]}}-[p])[-1]}

Using the second definition (∀ x, y, z ∈ A: x + y ≠ z)

->s{((3..s.size).map{|i|s.combination(i).find{|e|e.permutation(3).all?{|a,b,c|a+b!=c}}}-[p])[-1]}


问:
The rice and chess problem
An Indian legend tells the story of the alleged inventor of the chess game, who impressed the emperor of India with his game so much that he would get rewarded with anything asked.

The man said he wanted to be paid in rice. He wanted a grain of rice for the first square of the chessboard, two for the second, four for the third, eight for the fourth, and so on, until the 64th square.

The emperor was amazed that the man asked for such a small reward, but as his mathematicians started counting, he ended up losing one of his provinces.

Task

Given the length of the side of a hypothetical chessboard (which is 8 on a default chessboard) and the multiplier between squares (which is 2 in the legend), calculate the number of grains of rice the emperor must pay to the man.

Notes

The side length will always be a positive integer. The multiplier could instead be any kind of rational number.

If your language of choice can't display very large numbers, it's okay as long as your program can correctly process smaller inputs.

Also if your language of choice rounds larger values (with exponential notations), it's okay if those values are approximately correct.

Testcases

```<code>Input (side length, multiplier) => Output
8, 2                            => 18446744073709551615
3, 6                            => 2015539
7, 1.5                          => 850161998.2854
5, -3                           => 211822152361
256, 1                          => 65536
2, 2                            => 15
2, -2                           => -5
</code>```

Please note that the explicit formula

```<code>result = (multiplier ^ (side ^ 2) - 1) / (multiplier - 1)
</code>```

Performs wrong on multiplier = 1, as

```<code>1 ^ (side ^ 2) - 1 = 0
1 - 1 = 0
0 / 0 != side ^ 2 (as it should be)
</code>```

Scoring

This is code-golf. Shortest answer in bytes wins.

答:
Python, 41 Bytes

Totally new at this golfing thing, criticism welcome!

```<code>lambda n,m:sum(m**i for i in range(n**2))
</code>```

Title: The rice and chess problem

Body:
Python, 41 Bytes

Totally new at this golfing thing, criticism welcome!

lambda n,m:sum(m**i for i in range(n**2))


问:
On the Subject of Passwords
In Keep Talking and Nobody Explodes, players are tasked with defusing bombs based on information from their "experts" (other people with a manual). Each bomb is made up of modules, one of which can be passwords, where the expert is given this list of possible passwords, all five letters long:

```<code>about   after   again   below   could
every   first   found   great   house
large   learn   never   other   place
plant   point   right   small   sound
spell   still   study   their   there
these   thing   think   three   water
where   which   world   would   write
</code>```

And the player is given a list of 6 possible letters for each place in the password. Given the possible letter combinations, output the correct password. Input can be in any reasonable format (2D array, string separated by newline, etc.) You may discount the code which you use to compress/generate the list/string/array/whatever of passwords. (Thanks @DenkerAffe)

NOTE: Passwords are case insensitive. You may assume that input will only solve for one password.

Examples / Test Cases

Input here will be represented as a array of strings.

```<code>["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"] => first
["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"] => large
["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"] => still
</code>```

答:
Hoon, 125 bytes

```<code>|=
r/(list tape)
=+
^=
a
|-
?~
r
(easy ~)
;~
plug
(mask i.r)
(knee *tape |.(^$(r t.r)))
==
(skip pass |*(* =(~ (rust +< a))))
</code>```

Ungolfed:

```<code>|=  r/(list tape)
=+  ^=  a
|-
  ?~  r
    (easy ~)
  ;~  plug
    (mask i.r)
    (knee *tape |.(^$(r t.r)))
  ==
(skip pass |*(* =(~ (rust +< a))))
</code>```

Hoon doesn't have regex, only a parser combinator system. This makes it pretty complicated to get everything working: (mask "abc") roughly translates to regex's [abc], and is the core of the parser that we are building.

;~(plug a b) is a monadic bind of two parsers under ++plug, which has to parse the first and then second or else it fails.

++knee is used to build a recursive parser; we give it a type (*tape) of the result, and a callback to call to generate the actual parser. In this case, the callback is "call the entire closure again, but with the tail of the list instead". The ?~ rune tests is the list is empty, and gives (easy ~) (don't parse anything and return ~) or adds on another mask and recurse again.

Having built the parser, we can get to using it. ++skip removes all elements of the list for which the function returns yes for. ++rust tries to parse the element with our rule, returning a unit which is either [~ u=result] or ~ (our version of Haskell's Maybe). If it's ~ (None, and the rule either failed to parse or didn't parse the entire contents), then the function returns true and the element is removed.

What's left over is a list, containing only the word where each letter is one of the options in the list given. I'm assuming that the list of passwords is already in the context under the name pass.

```<code>> =pass %.  :*  "ABOUT"  "AFTER"   "AGAIN"   "BELOW"   "COULD"
   "EVERY"   "FIRST"   "FOUND"   "GREAT"   "HOUSE"
   "LARGE"   "LEARN"   "NEVER"   "OTHER"   "PLACE"
   "PLANT"   "POINT"   "RIGHT"   "SMALL"   "SOUND"
   "SPELL"   "STILL"   "STUDY"   "THEIR"   "THERE"
   "THESE"   "THING"   "THINK"   "THREE"   "WATER"
   "WHERE"   "WHICH"   "WORLD"   "WOULD"   "WRITE"
   ~  ==  limo
> %.  ~["SHWYEU" "YEUTLS" "IHEWRA" "HWULER" "EUELJD"]
  |=
  r/(list tape)
  =+
  ^=
  a
  |-
  ?~
  r
  (easy ~)
  ;~
  plug
  (mask i.r)
  (knee *tape |.(^$(r t.r)))
  ==
  (skip pass |*(* =(~ (rust +< a))))
[i="STILL" t=<<>>]
</code>```

Title: On the Subject of Passwords

Body:
Hoon, 125 bytes

|=
r/(list tape)
=+
^=
a
|-
?~
r
(easy ~)
;~
plug
(mask i.r)
(knee *tape |.(^$(r t.r)))
==
(skip pass |*(* =(~ (rust +< a))))

Ungolfed:

|=  r/(list tape)
=+  ^=  a
|-
  ?~  r
    (easy ~)
  ;~  plug
    (mask i.r)
    (knee *tape |.(^$(r t.r)))
  ==
(skip pass |*(* =(~ (rust +< a))))

Hoon doesn't have regex, only a parser combinator system. This makes it pretty complicated to get everything working: (mask "abc") roughly translates to regex's [abc], and is the core of the parser that we are building.

;~(plug a b) is a monadic bind of two parsers under ++plug, which has to parse the first and then second or else it fails.

++knee is used to build a recursive parser; we give it a type (*tape) of the result, and a callback to call to generate the actual parser. In this case, the callback is "call the entire closure again, but with the tail of the list instead". The ?~ rune tests is the list is empty, and gives (easy ~) (don't parse anything and return ~) or adds on another mask and recurse again.

Having built the parser, we can get to using it. ++skip removes all elements of the list for which the function returns yes for. ++rust tries to parse the element with our rule, returning a unit which is either [~ u=result] or ~ (our version of Haskell's Maybe). If it's ~ (None, and the rule either failed to parse or didn't parse the entire contents), then the function returns true and the element is removed.

What's left over is a list, containing only the word where each letter is one of the options in the list given. I'm assuming that the list of passwords is already in the context under the name pass.

> =pass %.  :*  "ABOUT"  "AFTER"   "AGAIN"   "BELOW"   "COULD"
   "EVERY"   "FIRST"   "FOUND"   "GREAT"   "HOUSE"
   "LARGE"   "LEARN"   "NEVER"   "OTHER"   "PLACE"
   "PLANT"   "POINT"   "RIGHT"   "SMALL"   "SOUND"
   "SPELL"   "STILL"   "STUDY"   "THEIR"   "THERE"
   "THESE"   "THING"   "THINK"   "THREE"   "WATER"
   "WHERE"   "WHICH"   "WORLD"   "WOULD"   "WRITE"
   ~  ==  limo
> %.  ~["SHWYEU" "YEUTLS" "IHEWRA" "HWULER" "EUELJD"]
  |=
  r/(list tape)
  =+
  ^=
  a
  |-
  ?~
  r
  (easy ~)
  ;~
  plug
  (mask i.r)
  (knee *tape |.(^$(r t.r)))
  ==
  (skip pass |*(* =(~ (rust +< a))))
[i="STILL" t=<<>>]


答:
Pyke, 5 bytes

```<code>XUm^s
</code>```

Try it here!

```<code>X     - input()**2
 U   - range(0,^)
  m^  - map(^,^)
    s - sum(^)
</code>```

Title: The rice and chess problem

Body:
An Indian legend tells the story of the alleged inventor of the chess game, who impressed the emperor of India with his game so much that he would get rewarded with anything asked.

The man said he wanted to be paid in rice. He wanted a grain of rice for the first square of the chessboard, two for the second, four for the third, eight for the fourth, and so on, until the 64th square.

The emperor was amazed that the man asked for such a small reward, but as his mathematicians started counting, he ended up losing one of his provinces.

Task

Given the length of the side of a hypothetical chessboard (which is 8 on a default chessboard) and the multiplier between squares (which is 2 in the legend), calculate the number of grains of rice the emperor must pay to the man.

Notes

The side length will always be a positive integer. The multiplier could instead be any kind of rational number.

If your language of choice can't display very large numbers, it's okay as long as your program can correctly process smaller inputs.

Also if your language of choice rounds larger values (with exponential notations), it's okay if those values are approximately correct.

Testcases

```<code>Input (side length, multiplier) => Output
8, 2                            => 18446744073709551615
3, 6                            => 2015539
7, 1.5                          => 850161998.2854
5, -3                           => 211822152361
256, 1                          => 65536
2, 2                            => 15
2, -2                           => -5
</code>```

Please note that the explicit formula

```<code>result = (multiplier ^ (side ^ 2) - 1) / (multiplier - 1)
</code>```

Performs wrong on multiplier = 1, as

```<code>1 ^ (side ^ 2) - 1 = 0
1 - 1 = 0
0 / 0 != side ^ 2 (as it should be)
</code>```

Scoring

This is code-golf. Shortest answer in bytes wins.

Body:
Pyke, 5 bytes

XUm^s

Try it here!

X     - input()**2
 U   - range(0,^)
  m^  - map(^,^)
    s - sum(^)


Title: Divisor reduction

Body:
Java, <s>147</s> 93

a->{int k,i,n=new Integer(a),l=0;for(;n!=0;n-=k)for(l+=k=i=1;i<n;)if(n%i++==0)++k;return l;}


问:
The centers of a triangle
Circles and squares have a single, definite center point. However, the notion of the center of a triangle has long been discussed. Four different centers were known to the Ancient Greeks:

Incenter: The intersection of the angle bisectors of the triangle

Centroid: The intersection of the lines from each vertex of the triangle to the middle of its opposite side

Circumcenter: The intersection of the perpendicular bisectors of the sides

Orthocenter: The intersection of the altitudes of the triangle

Euler later proved that the centroid, circumcenter and orthocenter are collinear in any triangle. The line that these three points are on in a triangle is called the Euler Line. It is defined for every triangle except an equilateral triangle, where all the points coincide.

Your challenge is to create the shortest program or function that, when given two inputs, outputs a specific center or the Euler Line of the triangle. The first specifies the coordinates of each vertex of a triangle. The second is an integer from 1 to 5, determining what to output.

```<code>1 - Incenter
2 - Centroid
3 - Circumcenter
4 - Orthocenter
5 - Equation of Euler Line
    (if the Euler Line is vertical, output the `x` value of the line
      (e.g. output `5` if the equation of the line is `x = 5`))
</code>```

You may assume that the given vertices will never be collinear, and that they will always be integer coordinates (this also excludes the possibility of having an equilateral triangle as an input, as per @R.Kap's comment).

The input array should be a valid nested array in your language, and input should be in any reasonable format. Any float values should be displayed to at least 3 decimal places, but no less. An outputted point should be a valid array in your language, matching with the input format.

Test cases:

```<code>Input: [(-2, 0), (1, 0), (0, 1)] 1
Output: (-0.089, 0.451)

Input: [(-2, 0), (1, 0), (0, 1)] 2
Output: (-0.333, 0.333)

Input: [(-2, 0), (1, 0), (0, 1)] 3
Output: (-0.5, -0.5)

Input: [(-2, 0), (1, 0), (0, 1)] 4
Output: (0, 2)

Input: [(-2, 0), (1, 0), (0, 1)] 5
Output: 5x + 2
</code>```

Clarification: The input can either be from stdin, either space or new-line separated, or as the arguments to a function. The output, however, must be written to stdout.

答:
Python 3.5, <s>851</s> 772 bytes:

```<code>def H(z,a,b,l):c=complex;T=lambda A,B:abs(c(*A)-c(*B));d=T(z,a);e=T(z,b);f=T(a,b);g=[((a[0]+b[0])/2,(a[1]+b[1])/2)for a,b in[[a,b],[z,a],[b,z]]];E=(z[0]+a[0]+b[0])/3;F=(z[1]+a[1]+b[1])/3;m=lambda f:[(a,0)if(b[1][0]-b[0][0])==0else(a,-1/((b[1][1]-b[0][1])/(b[1][0]-b[0][0])))if(b[1][1]-b[0][1])else''for a,b in zip(f,[[a,b],[z,a],[b,z]])];i=[u for u in m(g)if u!=''];C=i[0][1];D=i[0][0][1]-(C*i[0][0][0]);A=i[1][1];B=i[1][0][1]-(A*i[1][0][0]);G=(B-D)/(C-A);H=C*G+D;j=[u for u in m([z,b,a])if u!=''];C=j[0][1];D=j[0][0][1]-(C*j[0][0][0]);A=j[1][1];B=j[1][0][1]-(A*j[1][0][0]);I=(B-D)/(C-A);J=C*I+D;K,L=[((d*b[o])+(e*a[o])+(f*z[o]))/sum([d,e,f])for o in[0,1]];a=(H-J)/(G-I)if(G-I)else'';b=H-(a*G)if a!=''else G;print(['',(K,L),(E,F),(G,H),(I,J),[b,'%sx+%s'%(a,b)][a!='']][l])
</code>```

Takes input as a sequence of comma separated coordinates followed by an integer conveying what to output. For instance, if the input coordinates are (1,0),(2,1),(1,4) and you want the orthocenter of the triangle corresponding to those coordinates you would simply call the function like so:

```<code>H((1,0),(2,1),(1,4),4)
</code>```

Outputs in the format of a tuple if a specific point is needed, in the format of a string with the equation in the form y=mx+b if the Euler line is needed and the line is not vertical, or simply the x value of the line if the Euler line is needed but the line is vertical.

So, using the triangle with vertices (1,0),(2,1),(1,4), the outputs would be:

```<code>1. Incenter: (1.4663911961440428, 1.125967951102358)
2. Centroid: (1.3333333333333333, 1.6666666666666667)
3. Circumcenter: (0.0, 2.0)
4. Orthocenter: (4.0, 1.0)
5. Euler Line: -0.25x+2.0
</code>```

I will try to golf this more over time where and when I can.

Try It Online! (Ideone)

Title: The centers of a triangle

Body:
Python 3.5, <s>851</s> 772 bytes:

def H(z,a,b,l):c=complex;T=lambda A,B:abs(c(*A)-c(*B));d=T(z,a);e=T(z,b);f=T(a,b);g=[((a[0]+b[0])/2,(a[1]+b[1])/2)for a,b in[[a,b],[z,a],[b,z]]];E=(z[0]+a[0]+b[0])/3;F=(z[1]+a[1]+b[1])/3;m=lambda f:[(a,0)if(b[1][0]-b[0][0])==0else(a,-1/((b[1][1]-b[0][1])/(b[1][0]-b[0][0])))if(b[1][1]-b[0][1])else''for a,b in zip(f,[[a,b],[z,a],[b,z]])];i=[u for u in m(g)if u!=''];C=i[0][1];D=i[0][0][1]-(C*i[0][0][0]);A=i[1][1];B=i[1][0][1]-(A*i[1][0][0]);G=(B-D)/(C-A);H=C*G+D;j=[u for u in m([z,b,a])if u!=''];C=j[0][1];D=j[0][0][1]-(C*j[0][0][0]);A=j[1][1];B=j[1][0][1]-(A*j[1][0][0]);I=(B-D)/(C-A);J=C*I+D;K,L=[((d*b[o])+(e*a[o])+(f*z[o]))/sum([d,e,f])for o in[0,1]];a=(H-J)/(G-I)if(G-I)else'';b=H-(a*G)if a!=''else G;print(['',(K,L),(E,F),(G,H),(I,J),[b,'%sx+%s'%(a,b)][a!='']][l])

Takes input as a sequence of comma separated coordinates followed by an integer conveying what to output. For instance, if the input coordinates are (1,0),(2,1),(1,4) and you want the orthocenter of the triangle corresponding to those coordinates you would simply call the function like so:

H((1,0),(2,1),(1,4),4)

Outputs in the format of a tuple if a specific point is needed, in the format of a string with the equation in the form y=mx+b if the Euler line is needed and the line is not vertical, or simply the x value of the line if the Euler line is needed but the line is vertical.

So, using the triangle with vertices (1,0),(2,1),(1,4), the outputs would be:

1. Incenter: (1.4663911961440428, 1.125967951102358)
2. Centroid: (1.3333333333333333, 1.6666666666666667)
3. Circumcenter: (0.0, 2.0)
4. Orthocenter: (4.0, 1.0)
5. Euler Line: -0.25x+2.0

I will try to golf this more over time where and when I can.

Try It Online! (Ideone)


问:
Smallest integers after N divisible by 2, 3, and 4
Give credit to whom credit is due.

Objective Given an integer N > 0, out the smallest integers A, B, and C so that:

All of A, B, and C are strictly greater than N;

2 divides A;

3 divides B;

and 4 divides C.

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

Test cases

```<code>N => A, B, C
1 => 2, 3, 4
4 => 6, 6, 8
43 => 44, 45, 44
123 => 124, 126, 124
420 => 422, 423, 424
31415 => 31416, 31416, 31416
1081177 => 1081178, 1081179, 1081180
</code>```

ContentLicense: CC BY-SA 4.0

Body:
Java <s>70</s> 57

a->System.out.print(a/2*2+2+" "+(a/3*3+3)+" "+(a/4*4+4))


答:
C#, 63 bytes

```<code>int F(int n)=>n<1?0:F(Enumerable.Range(1,n).Count(i=>n%i>0))+1;
</code>```

Title: Divisor reduction

Body:
C#, 63 bytes

int F(int n)=>n<1?0:F(Enumerable.Range(1,n).Count(i=>n%i>0))+1;


答:
Pyth, 27 bytes

```<code>ef!f!*Fm-Fd.pYfqlY3yTfglT3y
</code>```

Test suite.

Title: Largest Distinctly Sum-Free Partition

Body:
Pyth, 27 bytes

ef!f!*Fm-Fd.pYfqlY3yTfglT3y

Test suite.


答:
MATL, <s>47</s> 43 bytes

```<code>nW:qB!ts2#Sw2>)PZ)"1G@)XJ2XN!"@sJ@X-m~*]?J.
</code>```

Try it online!

Explanation

This uses two loops: an outer loop to generate all possible subsets, and an inner loop to take all pairs of elements and see if the sum equals any other element of the subset.

Subsets of at least 3 elements are tested in order of decreasing number of elements. The code stops as soon as a valid subset is found.

```<code>          % Take input implicitly
nW:q      % Generate [0 1 ... 2^n-1] where n is input length
B!        % Convert to binary. Gives a matrix. Each number corresponds to a column.
          % This will be used to select the elements of each subset
ts        % Duplicate. Sum of each column
2#S       % Sort. Output the sorted array and the indices of the sorting. Each index
          % corresponds to one possible subset
w2>       % Swap. Logical index of values that exceed 2. This is used to pick only
          % subsets of more than 2 elements
)         % Keeps only indices of subsets that have at least 3 elements
P         % Flip. This moves subsets with more elements to the front. As soon as a
          % subset fulfills the condition the outer loop will be exited, so we need
          % to start with the bigger subsets
Z)        % Index into columns of binary matrix. Each column is the binary pattern
          % defining a subset with at least 3 elements, starting with bigger subsets
"         % For each column. Each iteration corresponds to a subset
  1       %   Push 1
  G@)     %   Pick actual elements of each subset (logical index into input)
  XJ      %   Copy to clipboard J
  2XN!    %   All pairs of 2 elements from that subset. Each pair is a column
  "       %   For each column. Each iteration corresponds to a pair of elements
    @s    %     Sum of those two elements
    J@X-  %     Array with the other elements (obtained with set difference)
    m~    %     True if the sum of the two elemens is not a member of the array
    *     %     Multiply. Corresponds to logical AND
  ]       %   End for
  ?       %   If result is true: no sum of two elements equalled any element
    J     %     Push found subset (will be displayed implicitly)
    .     %     Exit loop
          %   End if implicitly
          % End for implicitly
          % Display stack implicitly
</code>```

Title: Largest Distinctly Sum-Free Partition

Body:
MATL, <s>47</s> 43 bytes

nW:qB!ts2#Sw2>)PZ)"1G@)XJ2XN!"@sJ@X-m~*]?J.

Try it online!

Explanation

This uses two loops: an outer loop to generate all possible subsets, and an inner loop to take all pairs of elements and see if the sum equals any other element of the subset.

Subsets of at least 3 elements are tested in order of decreasing number of elements. The code stops as soon as a valid subset is found.

          % Take input implicitly
nW:q      % Generate [0 1 ... 2^n-1] where n is input length
B!        % Convert to binary. Gives a matrix. Each number corresponds to a column.
          % This will be used to select the elements of each subset
ts        % Duplicate. Sum of each column
2#S       % Sort. Output the sorted array and the indices of the sorting. Each index
          % corresponds to one possible subset
w2>       % Swap. Logical index of values that exceed 2. This is used to pick only
          % subsets of more than 2 elements
)         % Keeps only indices of subsets that have at least 3 elements
P         % Flip. This moves subsets with more elements to the front. As soon as a
          % subset fulfills the condition the outer loop will be exited, so we need
          % to start with the bigger subsets
Z)        % Index into columns of binary matrix. Each column is the binary pattern
          % defining a subset with at least 3 elements, starting with bigger subsets
"         % For each column. Each iteration corresponds to a subset
  1       %   Push 1
  G@)     %   Pick actual elements of each subset (logical index into input)
  XJ      %   Copy to clipboard J
  2XN!    %   All pairs of 2 elements from that subset. Each pair is a column
  "       %   For each column. Each iteration corresponds to a pair of elements
    @s    %     Sum of those two elements
    J@X-  %     Array with the other elements (obtained with set difference)
    m~    %     True if the sum of the two elemens is not a member of the array
    *     %     Multiply. Corresponds to logical AND
  ]       %   End for
  ?       %   If result is true: no sum of two elements equalled any element
    J     %     Push found subset (will be displayed implicitly)
    .     %     Exit loop
          %   End if implicitly
          % End for implicitly
          % Display stack implicitly


答:
Javascript 246 <s>263</s>

```<code>a=>([...Array(1<<(l=a.length))].map((x,i)=>i.toString(2)).filter(n=>/1.*1.*1/.test(n)).map(s=>('0'.repeat(l)+s).slice(-l).replace(/./g,(b,p)=>+b&&o.push(a[p]),o=[])&&o).filter(u=>u.every((x,i)=>!u.some((y,j)=>j-i&&u.some((z,k)=>k-j&&!(z-x-y))))))
</code>```

So long :( ... But it was a nice coding ..(I think)

Less golfed:

f=a=>(
    [...Array(1<<(l=a.length))]
        .map((x,i)=>i.toString(2))
        .filter(n=>/1.*1.*1/.test(n))
        .map(s=>
            ('0'.repeat(l)+s).slice(-l).replace(/./g,
                (b,p)=>+b&&o.push(a[p])
            ,o=[])&&o
        )
        .filter(u=>
            u.every((x,i)=>
                !u.some((y,j)=>
                    j-i&&u.some((z,k)=>k-j&&!(z-x-y))
                )
            )
        )
)

document.body.innerHTML = JSON.stringify( f([1,2,3,4,5]), null, 1 );```

Title: Largest Distinctly Sum-Free Partition

Body:
Javascript 246 <s>263</s>

a=>([...Array(1<<(l=a.length))].map((x,i)=>i.toString(2)).filter(n=>/1.*1.*1/.test(n)).map(s=>('0'.repeat(l)+s).slice(-l).replace(/./g,(b,p)=>+b&&o.push(a[p]),o=[])&&o).filter(u=>u.every((x,i)=>!u.some((y,j)=>j-i&&u.some((z,k)=>k-j&&!(z-x-y))))))

So long :( ... But it was a nice coding ..(I think)

Less golfed:

f=a=>(
    [...Array(1<<(l=a.length))]
        .map((x,i)=>i.toString(2))
        .filter(n=>/1.*1.*1/.test(n))
        .map(s=>
            ('0'.repeat(l)+s).slice(-l).replace(/./g,
                (b,p)=>+b&&o.push(a[p])
            ,o=[])&&o
        )
        .filter(u=>
            u.every((x,i)=>
                !u.some((y,j)=>
                    j-i&&u.some((z,k)=>k-j&&!(z-x-y))
                )
            )
        )
)

document.body.innerHTML = JSON.stringify( f([1,2,3,4,5]), null, 1 );


答:
MATL, 13 bytes

```<code>tX`t:\ztt]Nq&
</code>```

Try it online

Explanation:

```<code>t               % Duplicate input
 X`      ]      % while loop, consumes 1 input
   t:\z         % calculates n-d(n), by counting number non-divisors
       tt       % dupe twice, for while loop condition, next iteration and to keep in stack
          Nq&   % get stack size, decrement, display that value
</code>```

Title: Divisor reduction

Body:
A divisor of a number n is any number that evenly divides n, including 1 and n itself. The number of divisors d(n) is how many divisors a number has. Here's d(n) for the first couple n:

```<code>n    divisors    d(n)
1    1           1
2    1, 2        2
3    1, 3        2
4    1, 2, 4     3
5    1, 5        2
6    1, 2, 3, 6  4
</code>```

We can repeatedly subtract the number of divisors from a number. For example:

```<code>16                  = 16
16 - d(16) = 16 - 5 = 11
11 - d(11) = 11 - 2 = 9
 9 - d( 9) =  9 - 3 = 6
 6 - d( 6) =  6 - 4 = 2
 2 - d( 2) =  2 - 2 = 0
</code>```

In this case it took 5 steps to get to 0.

Write a program or function that given a nonnegative number n returns the number of steps it takes to reduce it to 0 by repeated subtraction of the number of divisors.

Examples:

```<code>0, 0
1, 1
6, 2
16, 5
100, 19
100000, 7534
</code>```

Body:
MATL, 13 bytes

tX`t:\ztt]Nq&

Try it online

Explanation:

t               % Duplicate input
 X`      ]      % while loop, consumes 1 input
   t:\z         % calculates n-d(n), by counting number non-divisors
       tt       % dupe twice, for while loop condition, next iteration and to keep in stack
          Nq&   % get stack size, decrement, display that value


问:
The Nine Pattern

Introduction

I stumbled across this (useless) pattern the other day while I was watching TV.
I named it "the 9 pattern" because the first number to use it was 9.
The gist of it is, you enter a number (let's say x), and then you get back:

x

x + (x / 3) [let's call this y]

two-thirds of y [let's call this z]

z + 1

So, if I put inside this pattern the number 9 as x, this is what would come out:

9 (9)

12 (9 + 9 / 3) [9 over 3 is 3, and 9 + 3 is 12]

8 (12 times two-thirds) [a third of 12 is 4, and 4 * 2 is 8]

9 (8 + 1 is 9)

Challenge

Write me a function (in any programming language) that takes in a number, and outputs an integer array using the pattern.

Somewhat like this psuedo-code:

```<code>function ninePattern(int myInt) returns IntegerArray {
    int iterationA = myInt + (myInt / 3);
    int iterationB = iterationA * (2 / 3);
    int iterationC = iterationB + 1;
    IntegerArray x = [myInt, iterationA, iterationB, iterationC];
    return x;
}
</code>```

Clarifications

Discussions have been arousing in comments regarding the specifications of the question. This section is meant to clarify some of those.

"better to count in bytes than characters"

I picked characters because (for me, at least) it would be easier to judge. Of course, I can't change that now. (lots of answers are already posted)

"rounding"

Rounding follows this rhyme:

If it's 5 or more, raise the score

  If it's 4 or less, let it rest

Simply, put, if it is something like 4.7 or 3.85, round them to 5 and 4 respectively.

Examples

```<code>Input => Result
9 => [9, 12, 8, 9]
8 => [8, 11, 7, 8]
6 => [6, 8, 5, 6]
23 => [23, 31, 21, 22]
159 => [159, 212, 141, 142]
</code>```

If, however, the numbers are something like 2.3 or 10.435446, round them to 2 and 10 respectively.

"language support"

You are free to not use functions and/or arrays IF AND ONLY IF the language of your choice does not support them.  If it does (even if it will increase your characters count), you must use them.

答:
MATL, 14 bytes

```<code>Xot4*3/tE3/tQv
</code>```

Try it Online

Pretty simple, v concatenates the stack into an array. Xo converts to an integer data-type, and all operations thereafter are integer operations.

Title: The Nine Pattern

Body:
MATL, 14 bytes

Xot4*3/tE3/tQv

Try it Online

Pretty simple, v concatenates the stack into an array. Xo converts to an integer data-type, and all operations thereafter are integer operations.


答:
Java, 86 82 84 85 characters

```<code>class c{int[]i(int I){int a=I+(I/3),b=(int)(a*(2d/3d));return new int[]{I,a,b,b+1};}}
</code>```

The letter d placed right after an integer makes the integer a double.

Ungolfed:

```<code>class c{
    int[] i(int I) {
        int a = I + (I / 3),
            b = (int)(a * (2d / 3d));
        return new int[]{I, a, b, b + 1};
    }
}
</code>```

Without the class (class c{} is 8 chars long), it downsizes to 76 characters:

```<code>int[]i(int I){int a=I+(I/3),b=(int)(a*(2d/3d));return new int[]{I,a,b,b+1};}
</code>```

More accurate version in 110 chars (118 with the enum) - it uses floats because ain't nobody got space for casting Math#round(double):

```<code>int[]i(int I){float a=I+(I/3f),b=(a*(2f/3f));return new int[]{I,Math.round(a),Math.round(b),Math.round(b+1)};}
</code>```

Title: The Nine Pattern

Body:
Introduction

I stumbled across this (useless) pattern the other day while I was watching TV.
I named it "the 9 pattern" because the first number to use it was 9.
The gist of it is, you enter a number (let's say x), and then you get back:

x

x + (x / 3) [let's call this y]

two-thirds of y [let's call this z]

z + 1

So, if I put inside this pattern the number 9 as x, this is what would come out:

9 (9)

12 (9 + 9 / 3) [9 over 3 is 3, and 9 + 3 is 12]

8 (12 times two-thirds) [a third of 12 is 4, and 4 * 2 is 8]

9 (8 + 1 is 9)

Challenge

Write me a function (in any programming language) that takes in a number, and outputs an integer array using the pattern.

Somewhat like this psuedo-code:

```<code>function ninePattern(int myInt) returns IntegerArray {
    int iterationA = myInt + (myInt / 3);
    int iterationB = iterationA * (2 / 3);
    int iterationC = iterationB + 1;
    IntegerArray x = [myInt, iterationA, iterationB, iterationC];
    return x;
}
</code>```

Clarifications

Discussions have been arousing in comments regarding the specifications of the question. This section is meant to clarify some of those.

"better to count in bytes than characters"

I picked characters because (for me, at least) it would be easier to judge. Of course, I can't change that now. (lots of answers are already posted)

"rounding"

Rounding follows this rhyme:

If it's 5 or more, raise the score

  If it's 4 or less, let it rest

Simply, put, if it is something like 4.7 or 3.85, round them to 5 and 4 respectively.

Examples

```<code>Input => Result
9 => [9, 12, 8, 9]
8 => [8, 11, 7, 8]
6 => [6, 8, 5, 6]
23 => [23, 31, 21, 22]
159 => [159, 212, 141, 142]
</code>```

If, however, the numbers are something like 2.3 or 10.435446, round them to 2 and 10 respectively.

"language support"

You are free to not use functions and/or arrays IF AND ONLY IF the language of your choice does not support them.  If it does (even if it will increase your characters count), you must use them.

Body:
Java, 86 82 84 85 characters

class c{int[]i(int I){int a=I+(I/3),b=(int)(a*(2d/3d));return new int[]{I,a,b,b+1};}}

The letter d placed right after an integer makes the integer a double.

Ungolfed:

class c{
    int[] i(int I) {
        int a = I + (I / 3),
            b = (int)(a * (2d / 3d));
        return new int[]{I, a, b, b + 1};
    }
}

Without the class (class c{} is 8 chars long), it downsizes to 76 characters:

int[]i(int I){int a=I+(I/3),b=(int)(a*(2d/3d));return new int[]{I,a,b,b+1};}

More accurate version in 110 chars (118 with the enum) - it uses floats because ain't nobody got space for casting Math#round(double):

int[]i(int I){float a=I+(I/3f),b=(a*(2f/3f));return new int[]{I,Math.round(a),Math.round(b),Math.round(b+1)};}


答:
Mathematica - 21 bytes

Just got Mathematica from my brothers RPi, so trying it out for fun, and what better way than a PPCG challenge.

```<code>{#,4#/3,8#/9,8#/9+1}&
</code>```

Defines an anonymous function. Try it out like:

```<code>In[26]:= x:={#,4#/3,8#/9,8#/9+1}&

In[27]:= x[9]

Out[27]= {9, 12, 8, 9}
</code>```

Title: The Nine Pattern

Body:
Mathematica - 21 bytes

Just got Mathematica from my brothers RPi, so trying it out for fun, and what better way than a PPCG challenge.

{#,4#/3,8#/9,8#/9+1}&

Defines an anonymous function. Try it out like:

In[26]:= x:={#,4#/3,8#/9,8#/9+1}&

In[27]:= x[9]

Out[27]= {9, 12, 8, 9}


答:
Mathematica, 35 bytes

If[#<1,0,#0[#-0~DivisorSigma~#]+1]&
```

<p>Making use of good old <code>DivisorSigma</code>. @MartinBüttner notes the following alternatives:</p>

<pre class="lang-js prettyprint-override"><code>If[#<1,0,#0[#-DivisorSum[#,1&]]+1]&
f@0=0;f@n_:=f[n-DivisorSum[n,1&]]+1
</code>```

Title: Divisor reduction

Body:
Mathematica, 35 bytes

If[#<1,0,#0[#-0~DivisorSigma~#]+1]&

Making use of good old DivisorSigma. @MartinBüttner notes the following alternatives:

If[#<1,0,#0[#-DivisorSum[#,1&]]+1]&
f@0=0;f@n_:=f[n-DivisorSum[n,1&]]+1


答:
Mathematica - <s>89</s> <s>84</s> <s>83</s> <s>77</s> 76 bytes

6 bytes saved thanks to @Sp3000

Probably can be golfed a lot more, is there a shorter way to filter?

```<code>Select[Subsets@#,Length@#>2&&Intersection[#,Tr/@#~Subsets~{2}]=={}&]~Last~0&
</code>```

Anonymous function, returns 0 on no answer.

Title: Largest Distinctly Sum-Free Partition

Body:
related and inspired by -- Finding sum-free partitions

A set A is defined here as being distinctly sum-free if

1) it consists of at least three elements, |A| ≥ 3, and

2) its distinct self-sum A + A = { x + y | x, y in A} (with x,y distinct, i.e., x≠y) has no elements in common with A.

(Obsolete - do not use this going forward. Left here only because some answers may have used it. It does not match with the above conditions. Alternatively, the equation x + y = z has no solution for x,y,z ∈ A (again with x,y,z distinct, i.e., x≠y, x≠z, y≠z).)

For a simple example, {1,3,5} is distinctly sum-free, but {1,3,4} is not. {1,3} and {3} are also not, since they're not at least three elements.

The challenge here is to find the largest distinctly sum-free subset of the given input.

Input

An unordered set A of integers in any convenient format.

The integers could be positive, negative, or zero, but can be assumed to fit in your language's native [int] datatype (or equivalent).

The set is guaranteed to have only distinct elements (no multisets here).

The set is not necessarily sorted.

Output

The largest subset of A (which could be A itself), that is distinctly sum-free. Output can be in any suitable format.

If no such subset exists, output an empty set or other falsey value.

If multiple subsets are tied for largest, output any or all of them.

The subset does not necessarily need be sorted, or in the same order as the input. For example, for input {1,3,5} output {5,1,3} is acceptable.

Additional Rules

Standard loopholes are forbidden.

This is code-golf, so all usual golfing rules apply, and the shortest code wins.

Examples

```<code>Input     -> Output (any or all)
{0}       -> {}
{1, 2, 3} -> {}
{1, 3, 5} -> {1, 3, 5}
{1, 2, 3, 4, 5} -> {1, 2, 5}  {1, 2, 4}  {1, 3, 5}  {2, 3, 4}  {2, 4, 5}  {3, 4, 5}
{-5, 4, 3, -2, 0} -> {-5, 4, 3}  {-5, 4, -2}  {4, 3, -2}
{-5, 4, 3, -2} -> {-5, 4, 3}  {-5, 4, -2}  {4, 3, -2}
{-17, 22, -5, 13, 200, -1, 1, 9} -> {-17, 22, -5, 13, 200, -1, 1}  {-17, 22, -5, 200, -1, 1, 9}  {-17, -5, 13, 200, -1, 1, 9}
</code>```

Body:
Mathematica - <s>89</s> <s>84</s> <s>83</s> <s>77</s> 76 bytes

6 bytes saved thanks to @Sp3000

Probably can be golfed a lot more, is there a shorter way to filter?

Select[Subsets@#,Length@#>2&&Intersection[#,Tr/@#~Subsets~{2}]=={}&]~Last~0&

Anonymous function, returns 0 on no answer.


问:
Golf a golf-scorer
As a kid, I used to play the card game "golf" a lot. Your challenge, should you choose to accept it, is to calculate the score of a golf hand. Since there are over 9000 variations on this card game1, we will go with the rules I remember playing.

Rules (of the game)

You end a round with 6 cards, and you want as few points as possible.

Jokers are not used.

Aces and 2s are worth -1, and -2 points respectively.

Jacks and Kings are both worth 0 points.

Cards from 3 to 10 are worth face value. However, these are cancelled when you pair them off. For example, a 5 is worth 5 points, but two 5s are worth zero. Three 5s are worth 5 points, (since the first 2 are paired off, but the 3rd is not.) and four 5s are worth 0 (since it makes 2 pairs).

Queens are worth 15 points. Queens cannot be cancelled, e.g. 2 queens are worth 30 points.

Rules (of the challenge)

Input will be an array of integers, or 6 individual integers. Whichever one you prefer. 1 represents an ace, 2-10 represents 2-10, and Jack, Queen, and King represents 11, 12, and 13. Output is the score of the hand according to the rules above. You can safely assume that all inputs are valid, e.g. no number appears more than 4 times, and all numbers are in the range [1, 13]. Input and output can be in any reasonable format.

Test IO:

```<code>[11, 10, 3, 1, 2, 2]    --> 8
[4, 5, 5, 3, 8, 7]      --> 22
[2, 2, 2, 2, 1, 1]      --> -10 (The lowest score possible)
[12, 12, 12, 12, 10, 9] --> 79 (The highest score possible)
[9, 9, 9, 9, 11, 1]     --> -1
[8, 8, 8, 8, 11, 13]    --> 0
[10, 9, 3, 7, 12, 2]    --> 42
[1, 2, 3, 4, 5, 6]      --> 15
[10, 9, 2, 3, 4, 1]     --> 23
[10, 3, 12, 3, 7, 12]   --> 47
</code>```

Shortest answer in bytes wins!

1not really, but there are a lot of variations.

答:
Pyth - <s>37</s> <s>36</s> 35

This is seems way too large, but FGITW.

```<code>J<#h;K-QS2++*15/K12sm*d%/Jd2{J_s@S2
</code>```

Test Suite.

Title: Golf a golf-scorer

Body:
Pyth - <s>37</s> <s>36</s> 35

This is seems way too large, but FGITW.

J<#h;K-QS2++*15/K12sm*d%/Jd2{J_s@S2

<a href="http://pyth.herokuapp.com/?code=J%3C%23h%3BK-QS2%2B%2B%2a15%2FK12sm%2ad%25%2FJd2%7BJ_s%40S2&test_suite=1&test_suite_input=%5B11%2C+10%2C+3%2C+1%2C+2%2C+2%5D%0A%5B4%2C+5%2C+5%2C+3%2C+8%2C+7%5D%0A%5B2%2C+2%2C+2%2C+2%2C+1%2C+1%5D%0A%5B12%2C+12%2C+12%2C+12%2C+10%2C+9%5D%0A%5B9%2C+9%2C+9%2C+9%2C+11%2C+1%5D%0A%5B8%2C+8%2C+8%2C+8%2C+11%2C+13%5D%0A%5B10%2C+9%2C+3%2C+7%2C+12%2C+2%5D%0A%5B1%2C+2%2C+3%2C+4%2C+5%2C+6%5D%0A%5B10%2C+9%2C+2%2C+3%2C+4%2C+1%5D%0A%5B10%2C+3%2C+12%2C+3%2C+7%2C+12%5D&debug=0" rel="nofollow noreferrer">Test Suite.


问:
Double-duty quine: quine!dlroW ,olleH
Write a program that will output its own source code when run, and nothing else. Seems easy, right?

The catch is that when the source code is reversed, your program must output "Hello, World!" exactly, without the quotes.

This is code-golf, so lowest byte count wins.

Edit: Your quine must be a proper quine.

答:
Javascript ES6, 55 bytes

```<code>$=_=>`$=${$};$()//"!dlroW ,olleH"`;$()//"!dlroW ,olleH"
</code>```

Quite simple, really.

Title: Double-duty quine: quine!dlroW ,olleH

Body:
Javascript ES6, 55 bytes

$=_=>`$=${$};$()//"!dlroW ,olleH"`;$()//"!dlroW ,olleH"

Quite simple, really.


问:
Find the number I/O shortest algorithm
Find the shortest function/algorithm to translate these numbers to the ones after the dash:

```<code>0 - 0
1 - 10
2 - 20
3 - 30
4 - 40
5 - 50
6 - 60
7 - 70
8 - 80
9 - 90
10 - 100
11 - 115
12 - 130
13 - 150
14 - 175
15 - 200
16 - 230
17 - 260
18 - 300
19 - 350
20 - 400
</code>```

Every integer higher than 20 is calculated by subtracting 10, calculating the corresponding number like done above and then multiplying that by 4.

Some examples (input will be between []):

```<code>[10] -> 100
[17] -> 260
[21] -> 4*115 -> 460
[32] -> 4*[22] -> 4*(4*130)) -> 2080
</code>```

var QUESTION_ID=80271,OVERRIDE_USER=53878;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```

<pre class="lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Title: Find the number I/O shortest algorithm

Body:
Java, 62 bytes

i->' '<i?l(i-10)*4:10*i+")*+-037;AIQ".charAt(i>9?i-10:0)%41*5


答:
Hoon, <s>93</s> 76 bytes

```<code>|=
r/@
?~
r
0
+($(r (sub r (lent (skim (gulf 1^r) |=(@ =(0 (mod r +<))))))))
</code>```

Ungolfed:

```<code>|=  r/@
?~  r
  0
=+  (skim (gulf 1^r) |=(@ =(0 (mod r +<))))
+($(r (sub r (lent -))))
</code>```

Returns a function that takes an atom, r. Create an intermediate value that contains all the devisors of r (Make list [1..n], keep only the elements where (mod r i) == 0). If r is zero return zero, else return the incremented value of recursing with r equal r-(length divisors).

The code as-is takes a stupid amount of time to evaluate for n=100.000, entirely because finding the devisors for big numbers makes a giant list and maps over it. Memoizing the divisors gets the correct output for n=10.000, but I didn't bother waiting around for 100.000

Title: Divisor reduction

Body:
Hoon, <s>93</s> 76 bytes

|=
r/@
?~
r
0
+($(r (sub r (lent (skim (gulf 1^r) |=(@ =(0 (mod r +<))))))))

Ungolfed:

|=  r/@
?~  r
  0
=+  (skim (gulf 1^r) |=(@ =(0 (mod r +<))))
+($(r (sub r (lent -))))

Returns a function that takes an atom, r. Create an intermediate value that contains all the devisors of r (Make list [1..n], keep only the elements where (mod r i) == 0). If r is zero return zero, else return the incremented value of recursing with r equal r-(length divisors).

The code as-is takes a stupid amount of time to evaluate for n=100.000, entirely because finding the devisors for big numbers makes a giant list and maps over it. Memoizing the divisors gets the correct output for n=10.000, but I didn't bother waiting around for 100.000


答:
Python 2, <s>72</s> 70 bytes

f=lambda x,*T:[x*(-1)**T.count(x),~x%2*15,-x][(x-3)/8]+(T>()and f(*T))
```

<p>At one point I wished Python treated <code>0**0 == 0</code> for once so that I could do <code>(-condition)**num</code>. Call like <code>f(11, 10, 3, 1, 2, 2)</code>.</p>

<p>Previous 72-byte version:</p>

<pre class="lang-py prettyprint-override"><code>f=lambda x,*T:[~x%2*15,x*(-1)**(x<3or T.count(x))][x<11]+(T>()and f(*T))
</code>```

Title: Golf a golf-scorer

Body:
As a kid, I used to play the card game "golf" a lot. Your challenge, should you choose to accept it, is to calculate the score of a golf hand. Since there are over 9000 variations on this card game1, we will go with the rules I remember playing.

Rules (of the game)

You end a round with 6 cards, and you want as few points as possible.

Jokers are not used.

Aces and 2s are worth -1, and -2 points respectively.

Jacks and Kings are both worth 0 points.

Cards from 3 to 10 are worth face value. However, these are cancelled when you pair them off. For example, a 5 is worth 5 points, but two 5s are worth zero. Three 5s are worth 5 points, (since the first 2 are paired off, but the 3rd is not.) and four 5s are worth 0 (since it makes 2 pairs).

Queens are worth 15 points. Queens cannot be cancelled, e.g. 2 queens are worth 30 points.

Rules (of the challenge)

Input will be an array of integers, or 6 individual integers. Whichever one you prefer. 1 represents an ace, 2-10 represents 2-10, and Jack, Queen, and King represents 11, 12, and 13. Output is the score of the hand according to the rules above. You can safely assume that all inputs are valid, e.g. no number appears more than 4 times, and all numbers are in the range [1, 13]. Input and output can be in any reasonable format.

Test IO:

```<code>[11, 10, 3, 1, 2, 2]    --> 8
[4, 5, 5, 3, 8, 7]      --> 22
[2, 2, 2, 2, 1, 1]      --> -10 (The lowest score possible)
[12, 12, 12, 12, 10, 9] --> 79 (The highest score possible)
[9, 9, 9, 9, 11, 1]     --> -1
[8, 8, 8, 8, 11, 13]    --> 0
[10, 9, 3, 7, 12, 2]    --> 42
[1, 2, 3, 4, 5, 6]      --> 15
[10, 9, 2, 3, 4, 1]     --> 23
[10, 3, 12, 3, 7, 12]   --> 47
</code>```

Shortest answer in bytes wins!

1not really, but there are a lot of variations.

Body:
Python 2, <s>72</s> 70 bytes

f=lambda x,*T:[x*(-1)**T.count(x),~x%2*15,-x][(x-3)/8]+(T>()and f(*T))

At one point I wished Python treated 0**0 == 0 for once so that I could do (-condition)**num. Call like f(11, 10, 3, 1, 2, 2).

Previous 72-byte version:

f=lambda x,*T:[~x%2*15,x*(-1)**(x<3or T.count(x))][x<11]+(T>()and f(*T))


答:
Actually, 21 bytes

```<code>`;;3@/+;32/*;uk1½+♂≈`
</code>```

This program declares a function that performs the required operations on the top stack value.

Try it online! (the extra . at the end evaluates the function and prints the result)

Explanation:

```<code>`;;3@/+;32/*;uk1½+♂≈`
 ;;                    make two copies of x
   3@/+                divide by 3, add that to x to get y
       ;32/*           make a copy of y and multiply by 2/3 to get z
            ;u         make a copy of z and add one
              k        push stack as a list
               1½+     add 0.5 to each element
                  ♂≈   apply int() to each element (make integers from floats by flooring; this is equivalent to rounding half-up because of adding 0.5)

</code>```

Title: The Nine Pattern

Body:
Actually, 21 bytes

`;;3@/+;32/*;uk1½+♂≈`

This program declares a function that performs the required operations on the top stack value.

Try it online! (the extra . at the end evaluates the function and prints the result)

Explanation:

`;;3@/+;32/*;uk1½+♂≈`
 ;;                    make two copies of x
   3@/+                divide by 3, add that to x to get y
       ;32/*           make a copy of y and multiply by 2/3 to get z
            ;u         make a copy of z and add one
              k        push stack as a list
               1½+     add 0.5 to each element
                  ♂≈   apply int() to each element (make integers from floats by flooring; this is equivalent to rounding half-up because of adding 0.5)


问:
Reverse stdin and place on stdout
Requirements:

Take an input on stdin including new lines / carriage returns of unlimited length (only bounded by system memory; that is, there is no inherent limit in the program.)

Output the reverse of the input on stdout.

Example:

Input:

```<code>Quick brown fox
He jumped over the lazy dog
</code>```

Output:

```<code>god yzal eht revo depmuj eH
xof nworb kciuQ
</code>```

Shortest wins.

Leaderboard:

var QUESTION_ID=242,OVERRIDE_USER=61563;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Tellurium, 5 bytes

```<code>i&r.^
</code>```

The i command gets input and stores it in the selected cell.

& starts string manipulation mode.

r is a string mode command. It reverses whatever is stored in the selected cell.

. exits string mode.

^ outputs the cell's value.

Title: Reverse stdin and place on stdout

Body:
Tellurium, 5 bytes

i&r.^

The i command gets input and stores it in the selected cell.

& starts string manipulation mode.

r is a string mode command. It reverses whatever is stored in the selected cell.

. exits string mode.

^ outputs the cell's value.


答:
Actually, 17 bytes

```<code>";╗R`╜%`░l;"£╬klD
</code>```

Try it online! (note: last test case times out on TIO)

Explanation:

```<code>";╗R`╜%`░l;"£╬klD
"          "£╬     while top of stack is truthy, call the function:
 ;╗                  push a copy of n to reg0
   R                 range(1,n+1) ([1,n])
    `  `░l             push the number of values where the following is truthy:
     ╜%                  k mod n
                       (this computes the number of non-divisors of n)
          ;            make a copy
              klD  push entire stack as list, count number of items, subtract 1
                   (the result is the number of times the function was called)
</code>```

Title: Divisor reduction

Body:
A divisor of a number n is any number that evenly divides n, including 1 and n itself. The number of divisors d(n) is how many divisors a number has. Here's d(n) for the first couple n:

```<code>n    divisors    d(n)
1    1           1
2    1, 2        2
3    1, 3        2
4    1, 2, 4     3
5    1, 5        2
6    1, 2, 3, 6  4
</code>```

We can repeatedly subtract the number of divisors from a number. For example:

```<code>16                  = 16
16 - d(16) = 16 - 5 = 11
11 - d(11) = 11 - 2 = 9
 9 - d( 9) =  9 - 3 = 6
 6 - d( 6) =  6 - 4 = 2
 2 - d( 2) =  2 - 2 = 0
</code>```

In this case it took 5 steps to get to 0.

Write a program or function that given a nonnegative number n returns the number of steps it takes to reduce it to 0 by repeated subtraction of the number of divisors.

Examples:

```<code>0, 0
1, 1
6, 2
16, 5
100, 19
100000, 7534
</code>```

Body:
Actually, 17 bytes

";╗R`╜%`░l;"£╬klD

Try it online! (note: last test case times out on TIO)

Explanation:

";╗R`╜%`░l;"£╬klD
"          "£╬     while top of stack is truthy, call the function:
 ;╗                  push a copy of n to reg0
   R                 range(1,n+1) ([1,n])
    `  `░l             push the number of values where the following is truthy:
     ╜%                  k mod n
                       (this computes the number of non-divisors of n)
          ;            make a copy
              klD  push entire stack as list, count number of items, subtract 1
                   (the result is the number of times the function was called)


问:
Reverse positive runs

Input

Your input is a list of single-digit numbers in any reasonable format, including a string of digits.
The input will not be empty.

Output

Your output shall be the input list, but with each maximal run of nonzero digits being reversed.

Example

Consider the input

```<code>95883007414830
<--->  <---->
</code>```

where the nonzero runs have been marked with arrows.
Reversing each of these runs, we obtain the output

```<code>38859003841470
</code>```

Rules and scoring

You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.

This challenge is related, but much more complex, since it includes additional string processing.

Test cases

```<code>4 -> 4
00 -> 00
123 -> 321
0010 -> 0010
12000345 -> 21000543
18161604 -> 61618104
95883007414830 -> 38859003841470
010230456078912 -> 010320654021987
357509902003550 -> 575309902005530
2492882377675046 -> 5767732882942064
03026302053000357099 -> 03036202035000753099
</code>```

Leaderboard

Here's a Stack Snippet to generate a leaderboard and list of winners by language.
To make sure your answer shows up, start it with a header of the form

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

You can keep old scores in the header by using the strikethrough tags: <s>57</s> will appear as <s>57</s>.

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

  });

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

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

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

    var lang = a.language;
    if (! /<a/.test(lang)) lang = '' + lang + '';
    lang = jQuery(lang).text().toLowerCase();

    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.uniq > b.uniq) return 1;
    if (a.uniq < b.uniq) return -1;
    return 0;
  });

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

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

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

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

table thead {
  font-weight: bold;
}

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Java, 126

```<code>a->{String r="",t[]=a.split("0");for(String s:t){r+=new StringBuilder(s).reverse()+"0";}return r.substring(0, r.length()-1);}
</code>```

Title: Reverse positive runs

Body:
Java, 126

a->{String r="",t[]=a.split("0");for(String s:t){r+=new StringBuilder(s).reverse()+"0";}return r.substring(0, r.length()-1);}