问:
Closest 7-Distinct-Prime Product
(via chat)

The OEIS entry A123321 lists the sequence of numbers that are the product of seven distinct primes. For brevity, we'll call this a 7DP number. The first few numbers and their corresponding divisors are below:

```<code>510510 = 2 * 3 * 5 * 7 * 11 * 13 * 17
570570 = 2 * 3 * 5 * 7 * 11 * 13 * 19
690690 = 2 * 3 * 5 * 7 * 11 * 13 * 23
746130 = 2 * 3 * 5 * 7 * 11 * 17 * 19
</code>```

The challenge here will be to find the closest 7DP number, in terms of absolute distance, from a given input.

Input

A single positive integer n in any convenient format.

Output

The closest 7DP number to n, again in any convenient format. If two 7DP numbers are tied for closest, you can output either or both.

Rules

Numbers can be assumed to fit in your language's default [int] datatype (or equivalent).

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

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

Examples

```<code>5 -> 510510
860782 -> 870870
1425060 -> 1438710 (or 1411410, or both)
</code>```

答:
Brachylog, <s>44</s> <s>40</s> 16 bytes

Crossed out 44 is still regular 44 ;(

```<code>:I=+.>0,.$pPdPl7
</code>```

Example:

```<code>?- run_from_atom(':I=+.>0,.$pPdPl7',1425060,Z).
Z = 1438710 .
</code>```

Could it be that this language doesn't always suck? I beat Jelly and MATL!

The test case with 5 is the longest and takes about 10 seconds on my machine.

This would be 12 bytes if $p was not bugged (we wouldn't need the >0,. part)

Explanation

Brachylog uses constraint logic programming by default for all integer arithmetic. Moreover, the labeling built-in = works on possibly infinite domains.

It successively unifies a variable with no constraints (i.e. in (-inf, inf)) as such: 0, 1, -1, 2, -2, 3, ….

Therefore, we can get the closest 7DP number by looking for the first number I unified in (-inf, inf) (using automatic backtracking), for which Input + I is a 7DP number.

```<code>:I=                Label variables in [Input, I]. I has no constraints and Input is known
   +.              Unify Output with Input + I
     >0,           Output > 0 (wouldn't be needed if $p failed for numbers less than 1)
        .$pP       Unify P with the list of prime factors of Output
            dP     Check that P with duplicates removed is still P
              l7   Check that the length of P is 7
</code>```

Title: Closest 7-Distinct-Prime Product

Body:
Brachylog, <s>44</s> <s>40</s> 16 bytes

Crossed out 44 is still regular 44 ;(

:I=+.>0,.$pPdPl7

Example:

?- run_from_atom(':I=+.>0,.$pPdPl7',1425060,Z).
Z = 1438710 .

Could it be that this language doesn't always suck? I beat Jelly and MATL!

The test case with 5 is the longest and takes about 10 seconds on my machine.

This would be 12 bytes if $p was not bugged (we wouldn't need the >0,. part)

Explanation

Brachylog uses constraint logic programming by default for all integer arithmetic. Moreover, the labeling built-in = works on possibly infinite domains.

It successively unifies a variable with no constraints (i.e. in (-inf, inf)) as such: 0, 1, -1, 2, -2, 3, ….

Therefore, we can get the closest 7DP number by looking for the first number I unified in (-inf, inf) (using automatic backtracking), for which Input + I is a 7DP number.

:I=                Label variables in [Input, I]. I has no constraints and Input is known
   +.              Unify Output with Input + I
     >0,           Output > 0 (wouldn't be needed if $p failed for numbers less than 1)
        .$pP       Unify P with the list of prime factors of Output
            dP     Check that P with duplicates removed is still P
              l7   Check that the length of P is 7


答:
Jelly, 17 bytes

```<code>Pµạ³,
×⁹ÆRœc7Ç€ṂṪ
</code>```

Works in theory, but takes many years to complete.

Here is a version that actually works for the given inputs, but theoretically fails for large inputs:

```<code>Pµạ³,
50ÆRœc7Ç€ṂṪ
</code>```

Try it here. This generates all primes up to 50, then finds all 7-combinations of primes in that list, and then all their products. Finally, it simply finds the closest element from that list to the given argument.

Of course, once our 7DPs contain primes higher than 50, this will fail. The theoretical version generates all primes up to 256n for an input n, but otherwise works the same way.

Proof

Let p(x) denote the next prime after x. An (extremely loose) upper bound for the closest 7DP product to x is:

```<code>p(x) * p(p(x)) * p(p(p(x))) * ... * p(p(p(p(p(p(p(x)))))))
</code>```

So we only need to check primes in [2…p(p(p(p(p(p(p(x)))))))]. Bertrand's
postulate says that p(x) ≤ 2x, so it suffices to check all primes up to 128x.

ContentLicense: CC BY-SA 3.0

Title: Closest 7-Distinct-Prime Product

Body:
(via chat)

The OEIS entry A123321 lists the sequence of numbers that are the product of seven distinct primes. For brevity, we'll call this a 7DP number. The first few numbers and their corresponding divisors are below:

```<code>510510 = 2 * 3 * 5 * 7 * 11 * 13 * 17
570570 = 2 * 3 * 5 * 7 * 11 * 13 * 19
690690 = 2 * 3 * 5 * 7 * 11 * 13 * 23
746130 = 2 * 3 * 5 * 7 * 11 * 17 * 19
</code>```

The challenge here will be to find the closest 7DP number, in terms of absolute distance, from a given input.

Input

A single positive integer n in any convenient format.

Output

The closest 7DP number to n, again in any convenient format. If two 7DP numbers are tied for closest, you can output either or both.

Rules

Numbers can be assumed to fit in your language's default [int] datatype (or equivalent).

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

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

Examples

```<code>5 -> 510510
860782 -> 870870
1425060 -> 1438710 (or 1411410, or both)
</code>```

Body:
Jelly, 17 bytes

Pµạ³,
×⁹ÆRœc7Ç€ṂṪ

Works in theory, but takes many years to complete.

Here is a version that actually works for the given inputs, but theoretically fails for large inputs:

Pµạ³,
50ÆRœc7Ç€ṂṪ

Try it here. This generates all primes up to 50, then finds all 7-combinations of primes in that list, and then all their products. Finally, it simply finds the closest element from that list to the given argument.

Of course, once our 7DPs contain primes higher than 50, this will fail. The theoretical version generates all primes up to 256n for an input n, but otherwise works the same way.

Proof

Let p(x) denote the next prime after x. An (extremely loose) upper bound for the closest 7DP product to x is:

p(x) * p(p(x)) * p(p(p(x))) * ... * p(p(p(p(p(p(p(x)))))))

So we only need to check primes in [2…p(p(p(p(p(p(p(x)))))))]. Bertrand's
postulate says that p(x) ≤ 2x, so it suffices to check all primes up to 128x.


问:
Remove more than n consecutive vowels from input string
I don't like strings with more than three vowels in a row. Can you write a program that removes all the vowels I don't want from words?

You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.

Input is a string containing only printable ASCII character (0x20 to 0x7E, inclusive).

Output is a string containing only runs of at most 3 consecutive vowels. If there is a run of more than 3 consecutive vowels in the input string, your program should produce an output string including the first three vowels encountered in that run, discarding any further consecutive vowels.

Y is not a vowel for the purposes of this challenge.

This is code golf, so the shortest code (in bytes) wins.

Test Cases

```<code>"Aeiou" => "Aei"
"screeeen" => "screeen"
"We're queueing up for the Hawaiian movie." => "We're queung up for the Hawaiin movie."
"Spaces break runs: aei iou." => "Spaces break runs: aei iou."
</code>```

答:
Java, 115 bytes

```<code>class a{public static void main(String[] a){System.out.println(a[0].replaceAll("(?i)([aeiou]{3})[aeiou]*","$1"));}}
</code>```

Expects input as program parameter.

Unit test output:

```<code>Aei
screeen
We're queung up for the Hawaiin movie.
</code>```

Body:
Java, 115 bytes

class a{public static void main(String[] a){System.out.println(a[0].replaceAll("(?i)([aeiou]{3})[aeiou]*","$1"));}}

Expects input as program parameter.

Unit test output:

Aei
screeen
We're queung up for the Hawaiin movie.


答:
Pyke, 32 bytes

```<code>#PDl 7q.ID}lRlqi*(#)DF-X,)R],She
</code>```

Try it here!

Note this doesn't work online - it times out. This Version only checks for 2 distinct primes and should work faster. When there are 2 numbers of the same distance away from the target, it chooses the lower one.

This goes through all the numbers until it finds one that is bigger than the input and is a 7DP. For each number, it gets rid of it if it isn't a 7DP. It then has a list of 7DPs up to the input with one that is bigger. It then picks the one that is closest to the input.

Title: Closest 7-Distinct-Prime Product

Body:
Pyke, 32 bytes

#PDl 7q.ID}lRlqi*(#)DF-X,)R],She

Try it here!

Note this doesn't work online - it times out. This Version only checks for 2 distinct primes and should work faster. When there are 2 numbers of the same distance away from the target, it chooses the lower one.

This goes through all the numbers until it finds one that is bigger than the input and is a 7DP. For each number, it gets rid of it if it isn't a 7DP. It then has a list of 7DPs up to the input with one that is bigger. It then picks the one that is closest to the input.


问:
Find the smallest number bigger than the input whose digital sum is the input
"Digital sum" refers to the sum of all the digits in a number.

For example, the digital sum of 1324 is 10, because 1+3+2+4 = 10.

The challenge is to write a program/function to calculate the smallest number bigger than the input whose digital sum is the input.

Example with walkthrough

As an example, take the number 9 as the input:

```<code>9 = 1+8 -> 18
9 = 2+7 -> 27
9 = 3+6 -> 36
...
9 = 8+1 -> 81
9 = 9+0 -> 90
</code>```

The valid output would be the smallest number above, which is 18.

Specs

Note that 9 is not the valid output for this example, because the reversed number must be greater than the original number.

Note that the input will be positive.

Test-Cases:

```<code> 2 => 11      (2 = 1 + 1)
 8 => 17      (8 = 1 + 7)
12 => 39     (12 = 3 + 9)
16 => 79     (16 = 7 + 9)
18 => 99     (18 = 9 + 9)
24 => 699    (24 = 6 + 9 + 9)
32 => 5999   (32 = 5 + 9 + 9 + 9)
</code>```

References:

This is OEIS A161561.

Edit: Added an additional Testcase (18)

Thanks to Martin Ender for the Leaderboard Snippet

var QUESTION_ID=81047,OVERRIDE_USER=31373;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

```

答:
Hexagony, <s>40 31</s> 30 bytes

```<code><_:->.(.+><.'!.\@"9!%>!/{.}|.?
</code>```

Or, if you prefer your code to be a little less linear and a little more polygonal:

```<code>    < _ : -
   > . ( . +
  > < . ' ! .
 \ @ " 9 ! % >
  ! / { . } |
   . ? . . .
    . . . .
</code>```

Try it online!

Thanks to @FryAmTheEggman for some ideas and inspiration :o)

Previous version: <.:->+_.!(..'!.\><9!%>@.{.}|.?"

Previouser version: <><.-_|@"'!{|(.9+!8=@>{/".'/:!?$.%\1$..\

Body:
Hexagony, <s>40 31</s> 30 bytes

<_:->.(.+><.'!.\@"9!%>!/{.}|.?

Or, if you prefer your code to be a little less linear and a little more polygonal:

    < _ : -
   > . ( . +
  > < . ' ! .
 \ @ " 9 ! % >
  ! / { . } |
   . ? . . .
    . . . .

Try it online!

Thanks to @FryAmTheEggman for some ideas and inspiration :o)

Previous version: <.:->+_.!(..'!.\><9!%>@.{.}|.?"

Previouser version: <><.-_|@"'!{|(.9+!8=@>{/".'/:!?$.%\1$..\


问:
Count up folks!

Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

Title: Count up folks!

Body:
k/kona, 3 Bytes

1+!

e.g.

k)1+!15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15


问:
Color count, sorted by occurences
This one is simple to describe and I could hardly believe that this was not golfed before:

For a given image (whatever format is supported by your language), find the unique colors and output a list of the colors.

Print the color code in hex RGB, that is a hash sign # followed by 2 digits for R, 2 digits for G and 2 digits for B. (#xxxxxx where x can be 0-9, A-F and/or a-f).

The hex code shall be followed by a space  and the decimal pixel count, then a newline (\n or \r\n).

The list shall be sorted by count descending (most frequent color at the top).

If there's a tie (two colors with the same amount), the order is not important.

The image will not contain transparency, so any alpha value is not important. The alpha value may not be part of the output.

An image size of 4000x3000 must be supported (that may matter to type definitions)

Sample image "10red 20blue 30black 40white":

Expected output:

```<code>#FFFFFF 40
#000000 30
#0000FF 20
#FF0000 10
</code>```

Sample image "blue gradient":

One of the expected outputs (since the order of same colors may vary):

```<code>#718DFF 19
#5571FF 15
#3855FF 11
#8DAAFF 11
#1C38FF 7
#AAAAFF 7
#8D8DFF 6
#AAC6FF 6
#C6C6FF 5
#C6E2FF 4
#001CFF 3
#E2E2FF 3
#FFFFFF 3
</code>```

Sample image "testImage", kindly provided by @Luis Mendo:

Expected output:

```<code>#FFFFFF 18042
#000000 1754
#FF3300 204
</code>```

Similar to this question, but the output is text, not an image.

答:
PowerShell v2+, 187 bytes

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

Re-uses almost all of the code from my answer on Get the most dominant color. So, please reference that for full explanation.

The changes here are in indexing $b in the third line to match the explicit output format requirements, and in the last line we sort by value in -descending order, then pipe to Format-Table with -HideTableHeaders and -AutoSize as parameters. It's very rare to actually use FT here on PPCG, since output is implicit at the end of execution, but here it's very useful to ensure we get only the correct parts output.

Examples

The first is the "red" test image from the Dominant Color challenge, the second is the "testimage" from this challenge.

```<code>PS C:\Tools\Scripts\golfing> .\color-count.ps1 C:\Tools\Scripts\golfing\img\red.png

#ff0000 139876
#dcd9cf 3056
#f2f1ed 1512
#ffffff 1508
#ffe6e6 1488
#ffe3e3 8
#eae8e2 4
#fffbfb 4

PS C:\Tools\Scripts\golfing> .\color-count.ps1 C:\Tools\Scripts\golfing\img\z07VA.gif

#ffffff 18042
#000000 1754
#ff3300 204
</code>```

Title: Color count, sorted by occurences

Body:
PowerShell v2+, 187 bytes

$a=New-Object System.Drawing.Bitmap $args[0]
$b=@{}
0..($a.Height-1)|%{$h=$_;0..($a.Width-1)|%{$b["#"+-join($a.GetPixel($_,$h).Name[2..7])]++}}
$b.GetEnumerator()|Sort value -des|FT -h -a

Re-uses almost all of the code from my answer on Get the most dominant color. So, please reference that for full explanation.

The changes here are in indexing $b in the third line to match the explicit output format requirements, and in the last line we sort by value in -descending order, then pipe to Format-Table with -HideTableHeaders and -AutoSize as parameters. It's very rare to actually use FT here on PPCG, since output is implicit at the end of execution, but here it's very useful to ensure we get only the correct parts output.

Examples

The first is the "red" test image from the Dominant Color challenge, the second is the "testimage" from this challenge.

PS C:\Tools\Scripts\golfing> .\color-count.ps1 C:\Tools\Scripts\golfing\img\red.png

#ff0000 139876
#dcd9cf 3056
#f2f1ed 1512
#ffffff 1508
#ffe6e6 1488
#ffe3e3 8
#eae8e2 4
#fffbfb 4

PS C:\Tools\Scripts\golfing> .\color-count.ps1 C:\Tools\Scripts\golfing\img\z07VA.gif

#ffffff 18042
#000000 1754
#ff3300 204


答:
Python, <s>89</s> <s>86</s> 85 bytes

f=lambda n,k=0:126^sum(1>>n%i<<7*(n/i%i<1)for i in range(2,n))and f(n+k,k%2*2+~k)or n
```

<p>The algorithm is <strong>O(scary)</strong> to begin with and the recursion doesn't really help, but it works well as long as <strong>n</strong> is sufficiently close to a 7DP number.</p>

<p><em>Thanks to @xnor for golfing off 3 bytes!</em></p>

<p>Test it on repl.it.</p>

<h3>How it works</h3>

<p>Python has no primality or factorization built-ins, but we can identify 7DP numbers by the amount and nature of their divisors.</p>

<p>By the multiplication principle, the number of divisors of an integer can be computed as the product of the incremented exponents of its prime factorization. Thus, <strong>σ<sub>0</sub>(n)</strong> (divisor function) is <strong>2<sup>m</sup></strong> whenever <strong>n</strong> is a mDP number.</p>

<p><strong>σ<sub>0</sub>(n) = 128</strong> is thus a necessary condition, but it is not sufficient; for example, <strong>σ<sub>0</sub>(2<sup>127</sup>) = 128</strong>, but <strong>2<sup>127</sup></strong> is clearly not a 7DP number. However, if both <strong>σ<sub>0</sub>(n) = 128</strong> and no perfect square divides <strong>n</strong> evenly, then <strong>n</strong> is a 7DP number.</p>

<p>For the input <strong>n</strong>, the algorithm consists in inspecting the integers <strong>n</strong>, <strong>n - 1</strong>, <strong>n + 1</strong>, <strong>n - 2</strong>, <strong>n + 2</strong>, etc. and returning the first one that is a 7DP number.</p>

<p>When <strong>f</strong> is called with argument <strong>n</strong>, the following happens:</p>

<ul>
<li><p>The code</p>

<pre class="lang-python prettyprint-override"><code>126^sum(1>>n%i<<7*(n/i%i<1)for i in range(2,n))
</code>```

tests if n is not a 7DP number as follows.

For all integers i such that 1 < i < n, 1>>n%i<<7*(n/i%i<1) gets evaluated.

If n is divisible by i but not by i2, 1>>n%i yields 1 and (n/i%i<1) yields 0, resulting in

1 · 27 · 0 = 1.

If n is divisible by i2, 1>>n%i and (n/i%i<1) both yield 1, resulting in 1 · 27 · 1 = 128.

If n not not divisible by i, 1>>n%i yields 0, resulting in 0 · 27 · x = 0.

The sum of the resulting integers will be 2m - 2 if n is a mDP number (its 2m divisors, excluding 1 and n) and a number greater than 127 if n has a perfect square factor. Thus, the sum will be 126 if and only if n is a 7DP number.

For 7DP numbers, the sum is 126, so XORing it with 126 yields 0, which is falsy. Thus, the or part of the lambda is executed and f returns the current value of n.

If n is not a 7DP number, XOR will return a non-zero, truthy value. Thus, the and part of the lambda is executed.

f(n+k,k%2*2+~k)
```

recursively calls f with updated values of n (the next potential 7DP number) and k (the difference between the the new candidate and the one after that).

If k is an even, non-negative integer, k%2*2 yields 0 and ~k yields -(k + 1). The sum of both results is -(k + 1), which is an odd, negative integer that is 1 greater in absolute value than k.

If k is an odd, negative integer, k%2*2 yields 2 and ~k yields -(k + 1). The sum of both results is 2 - (k + 1) = -(k - 1), which is an even, non-negative integer that is 1 unit greater in absolute value than k.

This means that k takes the values 0, -1, 2, -3, 4, ⋯.

When added cumulatively to n0 (the initial value of n), the resulting integers are

n0 + 0

(n0 + 0) - 1 = n0 - 1

(n0 - 1) + 2 = n0 + 1

(n0 + 1) - 3 = n0 - 2

(n0 - 2) + 4 = n0 + 2

etc.

making sure the first 7DP number we encounter is as close to n0 as possible.

Title: Closest 7-Distinct-Prime Product

Body:
Python, <s>89</s> <s>86</s> 85 bytes

f=lambda n,k=0:126^sum(1>>n%i<<7*(n/i%i<1)for i in range(2,n))and f(n+k,k%2*2+~k)or n

The algorithm is O(scary) to begin with and the recursion doesn't really help, but it works well as long as n is sufficiently close to a 7DP number.

Thanks to @xnor for golfing off 3 bytes!

Test it on repl.it.

How it works

Python has no primality or factorization built-ins, but we can identify 7DP numbers by the amount and nature of their divisors.

By the multiplication principle, the number of divisors of an integer can be computed as the product of the incremented exponents of its prime factorization. Thus, σ0(n) (divisor function) is 2m whenever n is a mDP number.

σ0(n) = 128 is thus a necessary condition, but it is not sufficient; for example, σ0(2127) = 128, but 2127 is clearly not a 7DP number. However, if both σ0(n) = 128 and no perfect square divides n evenly, then n is a 7DP number.

For the input n, the algorithm consists in inspecting the integers n, n - 1, n + 1, n - 2, n + 2, etc. and returning the first one that is a 7DP number.

When f is called with argument n, the following happens:

The code

126^sum(1>>n%i<<7*(n/i%i<1)for i in range(2,n))

tests if n is not a 7DP number as follows.

For all integers i such that 1 < i < n, 1>>n%i<<7*(n/i%i<1) gets evaluated.

If n is divisible by i but not by i2, 1>>n%i yields 1 and (n/i%i<1) yields 0, resulting in

1 · 27 · 0 = 1.

If n is divisible by i2, 1>>n%i and (n/i%i<1) both yield 1, resulting in 1 · 27 · 1 = 128.

If n not not divisible by i, 1>>n%i yields 0, resulting in 0 · 27 · x = 0.

The sum of the resulting integers will be 2m - 2 if n is a mDP number (its 2m divisors, excluding 1 and n) and a number greater than 127 if n has a perfect square factor. Thus, the sum will be 126 if and only if n is a 7DP number.

For 7DP numbers, the sum is 126, so XORing it with 126 yields 0, which is falsy. Thus, the or part of the lambda is executed and f returns the current value of n.

If n is not a 7DP number, XOR will return a non-zero, truthy value. Thus, the and part of the lambda is executed.

f(n+k,k%2*2+~k)

recursively calls f with updated values of n (the next potential 7DP number) and k (the difference between the the new candidate and the one after that).

If k is an even, non-negative integer, k%2*2 yields 0 and ~k yields -(k + 1). The sum of both results is -(k + 1), which is an odd, negative integer that is 1 greater in absolute value than k.

If k is an odd, negative integer, k%2*2 yields 2 and ~k yields -(k + 1). The sum of both results is 2 - (k + 1) = -(k - 1), which is an even, non-negative integer that is 1 unit greater in absolute value than k.

This means that k takes the values 0, -1, 2, -3, 4, ⋯.

When added cumulatively to n0 (the initial value of n), the resulting integers are

n0 + 0

(n0 + 0) - 1 = n0 - 1

(n0 - 1) + 2 = n0 + 1

(n0 + 1) - 3 = n0 - 2

(n0 - 2) + 4 = n0 + 2

etc.

making sure the first 7DP number we encounter is as close to n0 as possible.


问:
1, 2, Fizz, 4, Buzz

Introduction

In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other catalogue challenges, there is "Hello World!" and "Is this number a prime?".

Challenge

Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Output

The output will be a list of numbers (and Fizzes, Buzzes and FizzBuzzes) separated by a newline (either \n or \r\n). A trailing newline is acceptable, but a leading newline is not.  Apart from your choice of newline, the output should look exactly like this:

```<code>1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
</code>```

The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation.

Further Rules

This is not about finding the language with the shortest approach for playing FizzBuzz, this is about finding the shortest approach in every language. Therefore, no answer will be marked as accepted.

Submissions are scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score--if in doubt, please ask on Meta.

Nothing can be printed to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge. If anyone wants to abuse this by creating a language where the empty program generates FizzBuzz output, then congrats for paving the way for a very boring answer.

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

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Alphuck and ???), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

Because the output is fixed, you may hardcode the output (but this may not be the shortest option).

You may use preexisting solutions, as long as you credit the original author of the program.

Standard loopholes are otherwise disallowed.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the authors actually had to put effort into golfing the code.

Catalogue

var QUESTION_ID=58615;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=30525;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,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\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,});else console.log(body)});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;lang=jQuery(''+lang+'').text();languages[lang]=languages[lang]||{lang:a.language,lang_raw:lang.toLowerCase(),user:a.user,size:a.size,link:a.link}});var langs=[];for(var lang in languages)if(languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function(a,b){if(a.lang_raw>b.lang_raw)return 1;if(a.lang_raw<b.lang_raw)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:700}table td{padding:5px}</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Oration, 98 bytes

```<code>literally, for i in range(1,100):x=""if i%3 else'Fizz';x+=""if i%5 else "Buzz";print x if x else i
</code>```

ContentLicense: CC BY-SA 4.0

Title: 1, 2, Fizz, 4, Buzz

Body:
Oration, 98 bytes

literally, for i in range(1,100):x=""if i%3 else'Fizz';x+=""if i%5 else "Buzz";print x if x else i


答:
Oration, 31 bytes

```<code>literally, print range(input())
</code>```

Title: Count up folks!

Body:
Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

Body:
Oration, 31 bytes

literally, print range(input())


问:
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>```

答:
Desmos, <s>141</s> 136 bytes

```<code>a=1
b=2\operatorname{ceil}\left(.5a+.1\right)
c=3\operatorname{ceil}\left(\frac{a}{3}+0.1\right)
d=4\operatorname{ceil}\left(.25a+.1\right)
</code>```

Demonstration

Fixed the outputs while shaving off a few bytes.

Body:
Desmos, <s>141</s> 136 bytes

a=1
b=2\operatorname{ceil}\left(.5a+.1\right)
c=3\operatorname{ceil}\left(\frac{a}{3}+0.1\right)
d=4\operatorname{ceil}\left(.25a+.1\right)

Demonstration

Fixed the outputs while shaving off a few bytes.


答:
MATL, <s>21</s> <s>17</s> <s>16</s> <s>14</s> 13 bytes

Thanks to Dennis for a suggestion that removed 4 bytes, and another that saved 1 more byte!

```<code>t17*Zq7XN!pYk
</code>```

This works in theory, but runs out of memory for inputs above 6 (online compiler).

A more efficient version uses 21 bytes, and computes all test cases in about one second:

```<code>t3e4/k16+_YqZq7XN!pYk
</code>```

Try it online!

Memory-inefficient version

Memory-efficient version

Memory-efficient version, all test cases

Explanation

Memory-efficient version

Take input N = 860782 as an example. It suffices to consider primes up to M = 29, which is the first prime that multiplied by 2*3*5*7*11*13 exceeds N. In this example, 2*3*5*7*11*13*29 = 870870. The next prime is 31. Any product involving that prime or greater will be at least 2*3*5*7*11*13*31 = 930930, and so it's guaranteed not to be the solution, because it exceeds 870870 which exceeds N.

M is computed as the first prime greater than max(N/(2*3*5*7*11*13), 16). The max function is used for ensuring that at least 17 is picked. To save a few bytes, the code replaces 2*3*5*7*11*13 = 30030 by 30000, and function max by addition. These changes are valid because they give a larger value.

```<code>t      % Take input implicitly. Duplicate
3e4/k  % Divide input by 30000 and round down (rounding here is only needed
       % due to a bug in the "next prime" function)
16+    % Add 16
_Yq    % Next prime
Zq     % Prime numbers up to that value
7XN    % Combinations of those primes taken 7 at a time. Gives a 2D array
       % with each combination on a different row
!p     % Product of each row
Yk     % Output product that is closest to the input. Implicitly display
</code>```

Memory-inefficient version

To further reduce the number of bytes the division can be removed; in fact, it suffices to multiply by 17 (thanks, @Dennis). This ensures that the next prime is included (by Bertrand's postulate) and that the result is at least 17. This works in theory, but runs out of memory for inputs larger than about 6.

In the code, the section

```<code>3e4/k  % Divide input by 30000 and round down (rounding here is only needed
       % due to a bug in the "next prime" function)
16+    % Add 16
_Yq    % Next prime
</code>```

is replaced by

```<code>17*    % Multiply by 17
</code>```

Title: Closest 7-Distinct-Prime Product

Body:
MATL, <s>21</s> <s>17</s> <s>16</s> <s>14</s> 13 bytes

Thanks to Dennis for a suggestion that removed 4 bytes, and another that saved 1 more byte!

t17*Zq7XN!pYk

This works in theory, but runs out of memory for inputs above 6 (online compiler).

A more efficient version uses 21 bytes, and computes all test cases in about one second:

t3e4/k16+_YqZq7XN!pYk

Try it online!

Memory-inefficient version

Memory-efficient version

Memory-efficient version, all test cases

Explanation

Memory-efficient version

Take input N = 860782 as an example. It suffices to consider primes up to M = 29, which is the first prime that multiplied by 2*3*5*7*11*13 exceeds N. In this example, 2*3*5*7*11*13*29 = 870870. The next prime is 31. Any product involving that prime or greater will be at least 2*3*5*7*11*13*31 = 930930, and so it's guaranteed not to be the solution, because it exceeds 870870 which exceeds N.

M is computed as the first prime greater than max(N/(2*3*5*7*11*13), 16). The max function is used for ensuring that at least 17 is picked. To save a few bytes, the code replaces 2*3*5*7*11*13 = 30030 by 30000, and function max by addition. These changes are valid because they give a larger value.

t      % Take input implicitly. Duplicate
3e4/k  % Divide input by 30000 and round down (rounding here is only needed
       % due to a bug in the "next prime" function)
16+    % Add 16
_Yq    % Next prime
Zq     % Prime numbers up to that value
7XN    % Combinations of those primes taken 7 at a time. Gives a 2D array
       % with each combination on a different row
!p     % Product of each row
Yk     % Output product that is closest to the input. Implicitly display

Memory-inefficient version

To further reduce the number of bytes the division can be removed; in fact, it suffices to multiply by 17 (thanks, @Dennis). This ensures that the next prime is included (by Bertrand's postulate) and that the result is at least 17. This works in theory, but runs out of memory for inputs larger than about 6.

In the code, the section

3e4/k  % Divide input by 30000 and round down (rounding here is only needed
       % due to a bug in the "next prime" function)
16+    % Add 16
_Yq    % Next prime

is replaced by

17*    % Multiply by 17


问:
Shortest code to produce infinite output
Write the shortest code you can that produces an infinite output.

That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code wins.

Here's a list of answers that I think are really clever, so they can get credit:

The comma is both code and data

Infinite errors (that counts)

Infinite warnings (that also counts)

What's Marbelous?

Leaderboard

var QUESTION_ID=13152,OVERRIDE_USER=8611;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

```

答:
Oration, 21 bytes

```<code>to iterate, 1
listen,
</code>```

40 bytes:

```<code>to iterate, 1
listen,
capture,
that's it
</code>```

The first does print() (but it's python 2, so prints infinite ()), the second does print('') (the capture begins a string and the that's it ends it).

Body:
Oration, 21 bytes

to iterate, 1
listen,

40 bytes:

to iterate, 1
listen,
capture,
that's it

The first does print() (but it's python 2, so prints infinite ()), the second does print('') (the capture begins a string and the that's it ends it).


问:
Golf the xᵗʰ root of x
While bored in high-school (when I was half my current age...), I found that \$f(x) = x^{x^{-1}}\$ had some interesting properties, including e.g. that the maximum \$f\$ for \$0 ≤ x\$ is \$f(e)\$, and that the binding energy per nucleon of an isotope can be approximated as \$6 × f(x ÷ 21)\$...

Anyway, write the shortest function or program that calculates the xth root of x for any number in your language's domain.

Examples cases

For all languages

```<code>     -1   >       -1
   ¯0.2   >    -3125
   ¯0.5   >        4
    0.5   >     0.25
      1   >        1
      2   >    1.414
      e   >    1.444
      3   >    1.442
    100   >    1.047
  10000   >    1.001
</code>```

For languages that handle complex numbers

```<code>   -2   >        -0.7071i
    i   >            4.81
   2i   >    2.063-0.745i
 1+2i   >   1.820-0.1834i
 2+2i   >   1.575-0.1003i
</code>```

For languages that handle infinities

```<code>-1/∞   >   0    (or ∞ or ̃∞)
   0   >   0    (or 1 or ∞)
 1/∞   >   0
   ∞   >   1
  -∞   >   1
</code>```

For languages that handle both infinities and complex numbers

```<code> -∞-2i   >   1      (or ̃∞)
</code>```

 ̃∞ denotes directed infinity.

答:
Desmos, 14 bytes

```<code>a=1
\sqrt[a]{a}
</code>```

Demonstration

Title: Golf the xᵗʰ root of x

Body:
Desmos, 14 bytes

a=1
\sqrt[a]{a}

Demonstration


问:
Self-Interpreting Interpreter
Based on a comment by George Edison to this question, write the smallest self-interpreting interpreter.

You may use the language of your choosing.

Empty languages do not count.  Your program must be at least two characters long.

The program does not need to interpret the entire language, just a Turing-complete subset of language features (that contains the interpreter).

Quines don't count.

Do not use your language's built-in eval function or equivalent. Same goes for apply, etc.

答:
CHIQRSX9+ , 2 bytes

```<code>+I
</code>```

There's no way to write a self-interpreting interpreter in this HQ9+-based language without using I, which runs a built-in interpreter that processes STDIN.

ContentLicense: CC BY-SA 2.5

Title: Self-Interpreting Interpreter

Body:
CHIQRSX9+ , 2 bytes

+I

There's no way to write a self-interpreting interpreter in this HQ9+-based language without using I, which runs a built-in interpreter that processes STDIN.


问:
Evolution of "Hello World!"
This contest is officially over, the winner is jimmy23013. Congratulations!

The challenge is to make a program that prints Hello World! to stdout. The catch is that your program must have a Levenshtein distance of 7 or less from the program in the answer submitted before yours.

How This Will Work

Below I have already submitted the first answer using Python: print("Hello World!").

The next person to answer must modify the string print("Hello World!") with up to 7 single character insertions, deletions, or substitutions so that when it is run in any language that hasn't been used so far (only Python in this case) the output is still Hello World!.

For example the second answerer might use 1 substitution (r -> u), 2 deletions (in), and 1 insertion (s) to make the string puts("Hello World!") which prints Hello World! when run in Ruby.

The third person to answer must do the same thing in a new language, but using the program of the second person's answer (e.g. puts("Hello World!")) as their starting point. The fourth answer will be in relation to the third answer and so on.

This will continue on until everyone get stuck because there is no new language the last answer's program can be made to run in by only changing 7 characters. The communal goal is to see how long we can keep this up, so try not to make any obscure or unwarranted  character edits (this is not a requirement however).

Formatting

Please format your post like this:

```<code># Answer N - [language]

    [code]

[notes, explanation, observations, whatever]
</code>```

Where N is the answer number (increases incrementally, N = 1, 2, 3,...).

You do not have to tell which exact characters were changed. Just make sure the Levenshtein distance is from 0 to 7.

Rules

The key thing to understand about this challenge is that only one person can answer at a time and each answer depends on the one before it.

There should never be two answers with the same N. If two people happen to simultaneously  answer for some N, the one who answered later (even if it's a few seconds difference) should graciously delete their answer.

Furthermore...

A user may only submit one answer per 8 hour period. i.e. Each of your answers must be at least 8 hours apart. (This is to prevent users from constantly watching the question and answering as much as possible.)

A user may not submit two answers in a row.  (e.g. since I submitted answer 1 I can't do answer 2, but I could do 3.)

Each answer must be in a different programming language.

Different versions of the same language count as the same language.

Languages count as distinct if they are traditionally called by two different names. (There may be some ambiguities here but don't let that ruin the contest.)

You may only use tabs, newlines, and printable ASCII. (Newlines count as one character.)

The output should only be Hello World! and no other characters (a leading/trailing newline is not an issue).

If your language doesn't has stdout use whatever is commonly used for quickly outputting text (e.g. console.log or alert in JavaScript).

Please make sure your answer is valid. We don't want to realize there's a break in the chain five answers up. Invalid answers should be fixed quickly or deleted before there are additional answers.

Don't edit answers unless absolutely necessary.

Scoring

Once things settle down, the user who submits the most (valid) answers wins. Ties go to the user with the most cumulative up-votes.

Leaderboard: (out of date)

(user must have at least 2 valid answers)

11 Answers

Optimizer - CJam, Groovy, HTML, Forth, Rebol, Markdown, CASIO BASIC, SpeakEasy, REXX, RegXy, Pawn

jimmy23013 - GNU dc, Zsh, Burlesque, bc, Hack, GDB, QBasic, MediaWiki Markup, itflabtijtslwi, Squirrel, AGOL 68

7 Answers

Nit - APL, Clipper, Falcon, MUMPS, FreeBASIC, csh, Dart

Timmy - Lua, Lisp, Oz, Algoid, KTurtle, Alice, OCaml

6 Answers

Stacey - VHDL, GNU Octave, M4, Logo, Microsoft Batch, Matlab

Dennis - Dash, tcsh, TeX, ///, HQ9+-, Alore

5 Answers

plannapus - Stata, Scheme, SQLite, Scala, Suneido

Pietu1998 - PHP, sh, ALAGUF, Cardinal, Grin

4 Answers

ypnypn - NetLogo, Mouse, Salmon, Maple

resueman - Clojure, Emacs Lisp, Vimscript, VBScript

Timtech - AutoLisp, Geom++, BogusForth, owl

3 Answers

BrunoJ - CoffeeScript, F#, Betterave

2 Answers

Mig - Extended BF Type III, TCL

Calvin's Hobbies - Python, E

Sp3000 - Racket, Pyth

grc - Haskell, Turing

es1024 - Nimrod, ksh

FireFly -  FALSE, mIRC script

g-rocket - AppleScript, LiveCode

Oriol - AMPL, PARI/GP

nneonneo - Boo, Caché ObjectScript

Languages used so far:

Python

CJam

PHP

Pyth

Perl

Befunge 98

Bash

Nimrod

Ruby

GNU dc

Golfscript

Mathematica

R

Lua

Sage

Julia

Scilab

JavaScript

VHDL

HyperTalk

Haskell

LOLCODE

APL

M30W

Stata

TI-BASIC (NSpire)

ActionScript 2

J

PowerShell

K

Visual FoxPro

VBA

Extended BF Type III

Zsh

Dash

Clojure

NetLogo

Groovy

CoffeeScript

Clipper

B.A.S.I.C.

FALSE

fish (shell)

GNU Octave

TCL

E

newLisp

Lisp

SMT-LIBv2

Racket

Batsh

tcsh

AppleScript

Mouse

Pixie

F#

Falcon

Burlesque

HTML

SGML

M4

MUMPS

TeX

Forth

Salmon

Turing

bc

Betterave

Scheme

Emacs Lisp

Logo

AutoLISP

///

Rebol

Maple

FreeBASIC

Vimscript

ksh

Hack

mIRC

Batch

Make

Markdown

sh

GDB

csh

HQ9+-

Postscript

Matlab

Oz

CASIO BASIC

VBScript

QBasic

Processing

C

Rust 0.13

Dart

Kaffeine

Algoid

AMPL

Alore

Forobj

T-SQL

LiveCode

Euphoria

SpeakEasy

MediaWiki

SmallBASIC

REXX

SQLite

TPP

Geom++

SQL (postgres)

itflabtijtslwi

RegXy

Opal.rb

Squirrel

Pawn

Scala

Rebmu

Boo

PARI/GP

Red

Swift

BeanShell

Vala

Pike

Suneido

AWK

Neko

AngelScript

gosu

V

ALAGUF

BogusForth

Flaming Thunder

Caché ObjectScript

owl

Cardinal

Parser

Grin

Kitten

TwoDucks

Asymptote

CAT

IDL

Tiny

WTFZOMFG

Io

MuPAD

Java

Onyx

JBoss

S+

Hexish

yash

Improbable

wake

brat

busybox built-in shell

gammaplex

KTurtle

AGOL 68

Alice

SML/NJ

OCaml

CDuce

Underload

Simplex v.0.6

Minkolang 0.9

Fexl 7.0.3

Jolf

Vitsy

Y

Retina

Codename Dragon

Seriously

Reng v.3.3

Fuzzy Octo Guacamole

05AB1E

(Feel free to edit these lists if they are incorrect or out of date.)

This question works best when you sort by oldest.

NOTE: This is a trial question for a new challenge type I have in mind where each answer depends on the last and increases in difficulty. Come discuss it with us in the chatroom for this question or in meta.

答:
Answer 179, Fuzzy Octo Guacamole

```<code>#^.`4mrZ"#03w(*#class jux!{public static void main(String[] h){#\
#System.Console.Writeln(//@\//Hello*}}print,cat<<#*)\
#put"

#^
is~ob"Hello World!"@)
gx`#(O)X.g!)S(#X` ;}}//printputs;//-##E;]bye</>#*)`kX
</code>```

Pretty standard.

Since # is a comment, most of the lines are skipped.

After removing the comments, you get this:

```<code>is~ob"Hello World!"@)
gx`
</code>```

Everything after the @ is not executed, since @ is end.

```<code>is~ob"Hello World!"@
</code>```

The important parts is the "Hello World!"@ which pushes and prints (implicit output).

The rest:

i is invert, s is switch. This doesn't do anything important, moves 1 to the inactive stack (invert 0 and move).

~ob negates (bitwise) pushing -1, and sets the rest ToS (as a string) to b. This basically says b now pushes -1 to the stack.

Title: Evolution of "Hello World!"

Body:
Answer 179, Fuzzy Octo Guacamole

#^.`4mrZ"#03w(*#class jux!{public static void main(String[] h){#\
#System.Console.Writeln(//@\//Hello*}}print,cat<<#*)\
#put"

#^
is~ob"Hello World!"@)
gx`#(O)X.g!)S(#X` ;}}//printputs;//-##E;]bye</>#*)`kX

Pretty standard.

Since # is a comment, most of the lines are skipped.

After removing the comments, you get this:

is~ob"Hello World!"@)
gx`

Everything after the @ is not executed, since @ is end.

is~ob"Hello World!"@

The important parts is the "Hello World!"@ which pushes and prints (implicit output).

The rest:

i is invert, s is switch. This doesn't do anything important, moves 1 to the inactive stack (invert 0 and move).

~ob negates (bitwise) pushing -1, and sets the rest ToS (as a string) to b. This basically says b now pushes -1 to the stack.


问:
Swap bits with their neighbours

Task description

Given an integer, swap its (2k–1)-th and 2k-th least significant bits for all integers k > 0. This is sequence A057300 in the OEIS.

(The number is assumed to have “infinitely many” leading zeroes. In practice, this simply means prepending a single 0 bit to odd-length numbers.)

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

Test cases

```<code>0 -> 0
1 -> 2
9 -> 6
85 -> 170
220 -> 236
1827 -> 2835
47525 -> 30298
</code>```

答:
x86 asm function: 14 bytes of machine code

uint64_t version: 24 bytes

x86-64 SysV calling convention (x in edi), but this same machine code will also work in 32bit mode.  (Where the lea will decode as lea eax, [edi + eax*2], which gives identical results).

```<code>0000000000000040 <onemask_even>:
  40:   89 f8                   mov    eax,edi
  42:   25 55 55 55 55          and    eax,0x55555555
  47:   29 c7                   sub    edi,eax
  49:   d1 ef                   shr    edi,1
  4b:   8d 04 47                lea    eax,[rdi+rax*2]
  4e:   c3                      ret
4f: <end>
</code>```

0x4f - 0x40 = 14 bytes

This is compiler output from using xnor's excellent mask-once idea the opposite way.  (And opposite terminology: the low bit is bit 0, which is even, not odd.)

```<code>unsigned onemask_even(unsigned x) {
  unsigned emask = ~0U/3;
  unsigned e = (x & emask);
  return e*2 + ((x - e) >> 1);
}
</code>```

I didn't find any improvements over what the compiler does.  I might have written it as mov eax, 0x555... / and eax, edi, but that's the same length.

The same function for 64bit integers takes 24 bytes (see the godbolt link).  I don't see any way shorter than 10-byte movabs rax, 0x55... to generate the mask in a register.  (x86's div instruction is clunky, so unsigned division of all-ones by 3 doesn't help.)

I did come up with a loop to generate the mask in rax, but it's 10 bytes (exactly the same length as the mov imm64).

```<code># since 0x55 has its low bit set, shifting it out the top of RAX will set CF
0000000000000000 <swap_bitpairs64>:
   0:   31 c0                   xor    eax,eax      ; old garbage in rax could end the loop early
0000000000000002 <swap_bitpairs64.loop>:
   2:   48 c1 e0 08             shl    rax,0x8
   6:   b0 55                   mov    al,0x55      ; set the low byte
   8:   73 f8                   jnc    2 <swap_bitpairs64.loop>  ; loop until CF is set
000000000000000a <swap_bitpairs64.rest_of_function_as_normal>:
 # 10 bytes, same as   mov  rax, 0x5555555555555555
 # rax = 0x5555...
   a:   48 21 f8                and    rax,rdi
   ...
</code>```

If we knew that none of the existing bytes in rax has their low bit set, we could skip the xor, and this would be 8 bytes long.

A previous version of this answer had a 10 byte loop using the loop insn, but it had a worst-case run-time of 0xFFFFFFFFFFFFFF08 iterations, because I only set cl.

Title: Swap bits with their neighbours

Body:
x86 asm function: 14 bytes of machine code

uint64_t version: 24 bytes

x86-64 SysV calling convention (x in edi), but this same machine code will also work in 32bit mode.  (Where the lea will decode as lea eax, [edi + eax*2], which gives identical results).

0000000000000040 <onemask_even>:
  40:   89 f8                   mov    eax,edi
  42:   25 55 55 55 55          and    eax,0x55555555
  47:   29 c7                   sub    edi,eax
  49:   d1 ef                   shr    edi,1
  4b:   8d 04 47                lea    eax,[rdi+rax*2]
  4e:   c3                      ret
4f: <end>

0x4f - 0x40 = 14 bytes

This is <a href="http://gcc.godbolt.org/#compilers:!((compiler:g6,options:'-xc+-std%3Dgnu99+-O3+-Wno-all+-Wno-extra+-fno-verbose-asm',sourcez:PQKgBAIglg5lAuBDANmAKgJ0QVwLaIHIBnMAYTADcBTDIqAewDswRgAoAMwAoAPASgDeGKvGwZGvAGQA/AAwBVYAGYQAJj7BVAailzFSvmoDcAXzZtQYGPWQcqAEzKUadJmHocwPRvQzF3jFT4RADWYAAOAJ7wABZuHNiMAMbwDMysbDC8gsKi4mCqIDwAtCq8mvIyCsp8pmwx2UIiYsyFJWU8VfpqGqqmYGDAwGBEiNRgsVRg8uZsAMRQnrJsiXQwgY7ITDBgHABsACxcq7AbYFuMO/wCbAO5LWC6CgAyz8o9mmBaj516rzXGNhmNhQRjwXZrDZcUHg673cRPbrqTQ6X7VAzGMwndYOXb0ehgAC8YD0yiM8yojHsi1mlg4GHouC8Pj8JCisTciEYRAA7jQADRgABG2HB9HC4XodHgUxlGFwoJs9BgkQAXMKELIwFASFRqOl2NizkwgohQgB9XywY7c064/hgG4DI24vWU4JhYmkpTk522nGOehChAkYlcXhgAB8kbAAEY%2BGBJGA3YwPbVbmB4a0imBimAVEGQ%2BTgSt/cbAh7zZXJoxzUQYot4DbIfaE06wC7Ax6iST0SwCr6O2XcfRVD2I0nGWaQum/S3A8H4KH3GPo3HB1mCjm8wXF0Ri%2BZQLdmMTCgTvlRbsvClNvvRzMme8w82eBm/xzxE735G8DLcCWGz7Jr075hp%2BSZcH8NQADzQfGUaRrGtxXj2N5fI8jDFFQvTIWAKGniAXBAWeCZ3qhIDPgcIDnu45FAQWtwZBY4DwBgkQTDEUz0JMGBgDyiCRIKZpgIgERSnQQrIFMPAABx7CJRBMlyvI0CwhrDoGFbTuaKbNnajgOu2nbJt2XrooOxlTGBX6mqEs6Zs0%2BRUGo6Hhp%2BebYQhcbpsCCzJMg2D2FM0FEPA1JggAdDEkYrDChzmmKWkWimhzHHFBwJV4bYZtg6WZbZnrfr%2BFl5eCVk/DZaYbo5zDOWO3xubmwFefGB4WMMPBENx/hUDw4TCEQriMBFAwQPQVBEIwBDgjyvghBF7VgAA4o0m48KiXQAko0axnUQAA%3D)),filterAsm:(binary:!t,commentOnly:!t,directives:!t,intel:!t,labels:!t),version:3" rel="nofollow noreferrer">compiler output from using xnor's excellent mask-once idea the opposite way.  (And opposite terminology: the low bit is bit 0, which is even, not odd.)

unsigned onemask_even(unsigned x) {
  unsigned emask = ~0U/3;
  unsigned e = (x & emask);
  return e*2 + ((x - e) >> 1);
}

I didn't find any improvements over what the compiler does.  I might have written it as mov eax, 0x555... / and eax, edi, but that's the same length.

The same function for 64bit integers takes 24 bytes (see the godbolt link).  I don't see any way shorter than 10-byte movabs rax, 0x55... to generate the mask in a register.  (x86's div instruction is clunky, so unsigned division of all-ones by 3 doesn't help.)

I did come up with a loop to generate the mask in rax, but it's 10 bytes (exactly the same length as the mov imm64).

# since 0x55 has its low bit set, shifting it out the top of RAX will set CF
0000000000000000 <swap_bitpairs64>:
   0:   31 c0                   xor    eax,eax      ; old garbage in rax could end the loop early
0000000000000002 <swap_bitpairs64.loop>:
   2:   48 c1 e0 08             shl    rax,0x8
   6:   b0 55                   mov    al,0x55      ; set the low byte
   8:   73 f8                   jnc    2 <swap_bitpairs64.loop>  ; loop until CF is set
000000000000000a <swap_bitpairs64.rest_of_function_as_normal>:
 # 10 bytes, same as   mov  rax, 0x5555555555555555
 # rax = 0x5555...
   a:   48 21 f8                and    rax,rdi
   ...

If we knew that none of the existing bytes in rax has their low bit set, we could skip the xor, and this would be 8 bytes long.

A previous version of this answer had a 10 byte loop using the loop insn, but it had a worst-case run-time of 0xFFFFFFFFFFFFFF08 iterations, because I only set cl.


问:
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
WistfulC, 141 bytes

This C has seen better days.

```<code>if only int n were 0...
wish for "%d",&n upon a star
someday !n... wish "1" upon a star
*sigh*
wish "0" upon a star
if wishes were horses...
</code>```

Obviously not competitive, but then neither is this language.

Rough translation to regular C:

```<code>int n = 0;
scanf("%d", &n);
while (n) {
    puts("1");
}
puts("0");
exit(0);
</code>```

Title: Implement a Truth-Machine

Body:
WistfulC, 141 bytes

This C has seen better days.

if only int n were 0...
wish for "%d",&n upon a star
someday !n... wish "1" upon a star
*sigh*
wish "0" upon a star
if wishes were horses...

Obviously not competitive, but then neither is this language.

Rough translation to regular C:

int n = 0;
scanf("%d", &n);
while (n) {
    puts("1");
}
puts("0");
exit(0);


问:
Is this number a prime?
Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in many languages.

Rosetta code features lists by language of idiomatic approaches to primality testing, one using the Miller-Rabin test specifically and another using trial division. However, "most idiomatic" often does not coincide with "shortest." In an effort to make Programming Puzzles and Code Golf the go-to site for code golf, this challenge seeks to compile a catalog of the shortest approach in every language, similar to "Hello, World!" and Golf you a quine for great good!.

Furthermore, the capability of implementing a primality test is part of our definition of programming language, so this challenge will also serve as a directory of proven programming languages.

Task

Write a full program that, given a strictly positive integer n as input, determines whether n is prime and prints a truthy or falsy value accordingly.

For the purpose of this challenge, an integer is prime if it has exactly two strictly positive divisors. Note that this excludes 1, who is its only strictly positive divisor.

Your algorithm must be deterministic (i.e., produce the correct output with probability 1) and should, in theory, work for arbitrarily large integers. In practice, you may assume that the input can be stored in your data type, as long as the program works for integers from 1 to 255.

Input

If your language is able to read from STDIN, accept command-line arguments or any other alternative form of user input, you can read the integer as its decimal representation, unary representation (using a character of your choice), byte array (big or little endian) or single byte (if this is your languages largest data type).

If (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.

In this case, the hardcoded integer must be easily exchangeable. In particular, it may appear only in a single place in the entire program.

For scoring purposes, submit the program that corresponds to the input 1.

Output

Output has to be written to STDOUT or closest alternative.

If possible, output should consist solely of a truthy or falsy value (or a string representation thereof), optionally followed by a single newline.

The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation.

Additional rules

This is not about finding the language with the shortest approach for prime testing, this is about finding the shortest approach in every language. Therefore, no answer will be marked as accepted.

Submissions in most languages will be scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8.

The language Piet, for example, will be scored in codels, which is the natural choice for this language.

Some languages, like Folders, are a bit tricky to score. If in doubt, please ask on Meta.

Unlike our usual rules, feel free to use a language (or language version) even if it's newer than this challenge. If anyone wants to abuse this by creating a language where the empty program performs a primality test, then congrats for paving the way for a very boring answer.

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

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Headsecks or Unary), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

Built-in functions for testing primality are allowed. This challenge is meant to catalog the shortest possible solution in each language, so if it's shorter to use a built-in in your language, go for it.

Unless they have been overruled earlier, all standard code-golf rules apply, including the http://meta.codegolf.stackexchange.com/q/1061.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalog as complete as possible. However, do primarily upvote answers in languages where the author actually had to put effort into golfing the code.

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
WistfulC, 381 bytes

```<code>if only int n were 0...
wish for "%d", &n upon a star
if n < 2 were true...
    wish "not prime" upon a star
    if wishes were horses...
*sigh*
if only int i were 2...
someday i will be n...
    if n % i were 0...
        wish "not prime" upon a star
        if wishes were horses...
    *sigh*
    if only i were i + 1...
*sigh*
wish "prime" upon a star
if wishes were horses...
</code>```

Outputs prime if prime, not prime if not prime.

I went for entertainment value more than small size. Here's a golfed, (arguably) less funny version (286 bytes):

```<code>if only int n were 0...wish for "%d",&n upon a star
if n<2...wish "0" upon a star
if wishes were horses...*sigh*if only int i were 2...someday i==n...if !(n%i)...wish "0" upon a star
if wishes were horses...*sigh*if only i were i+1...*sigh*wish "1" upon a star
if wishes were horses...
</code>```

Title: Is this number a prime?

Body:
WistfulC, 381 bytes

if only int n were 0...
wish for "%d", &n upon a star
if n < 2 were true...
    wish "not prime" upon a star
    if wishes were horses...
*sigh*
if only int i were 2...
someday i will be n...
    if n % i were 0...
        wish "not prime" upon a star
        if wishes were horses...
    *sigh*
    if only i were i + 1...
*sigh*
wish "prime" upon a star
if wishes were horses...

Outputs prime if prime, not prime if not prime.

I went for entertainment value more than small size. Here's a golfed, (arguably) less funny version (286 bytes):

if only int n were 0...wish for "%d",&n upon a star
if n<2...wish "0" upon a star
if wishes were horses...*sigh*if only int i were 2...someday i==n...if !(n%i)...wish "0" upon a star
if wishes were horses...*sigh*if only i were i+1...*sigh*wish "1" upon a star
if wishes were horses...


问:
Has My Pie Been Bisected?
Write a program or function that takes in a nonempty list of positive integers. You may assume it is input in a reasonable convenient format such as "1 2 3 4" or [1, 2, 3, 4].

The numbers in the input list represent the slices of a full pie chart where each slice size is proportional to its corresponding number and all slices are arranged around the chart in the order given.

For example, the pie for 1 2 3 4 is:

The question your code must answer is: Is the pie chart ever bisected? That is, is there ever a perfectly straight line from one side of the circle to the other, splitting it symmetrically in two?

You need to output a truthy value if there is at least one bisector and output a falsy value if there are none.

In the 1 2 3 4 example there is a bisection between 4 1 and 2 3 so the output would be truthy.

But for input 1 2 3 4 5 there is no bisector so the output would be falsy:

Additional Examples

Arranging numbers differently may remove bisectors.

e.g. 2 1 3 4 → falsy:

If only one number is in the input list the pie is not bisected.

e.g. 10 → falsy:

There may be multiple bisectors. As long as there are more than zero the output is truthy.

e.g. 6 6 12 12 12 11 1 12 → truthy: (there are 3 bisectors here)

Bisections may exist even if they are not visually obvious.

e.g. 1000000 1000001 → falsy:

e.g. 1000000 1000001 1 → truthy:

(Thanks to nces.ed.gov for generating the pie charts.)

Test Cases

```<code>Truthy
1 2 3 4
6 6 12 12 12 11 1 12
1000000 1000001 1
1 2 3
1 1
42 42
1 17 9 13 2 7 3
3 1 2
10 20 10

Falsy
1 2 3 4 5
2 1 3 4
10
1000000 1000001
1
1 2
3 1 1
1 2 1 2 1 2
10 20 10 1
</code>```

Scoring

The shortest code in bytes wins. Tiebreaker is earlier answer.

答:
Dyalog APL, 12 bytes

+/∊2×+\∘.-+\
```

<p>Test it with TryAPL.</p>

<h3>How it works</h3>

```+/∊2×+\∘.-+\  Monadic function train. Right argument: y (vector)

     +\   +\  Yield the cumulative sum of y.
       ∘.-    Compute all differences of all partial sums.
              This computes the sums of all adjacent subvectors of y that do not
              contain the first value, their negatives, and 0's in the diagonal.
   2×         Multiply all differences by 2.
+/            Yield the sum of y.
  ∊           Test for membership.
```

Title: Has My Pie Been Bisected?

Body:
Dyalog APL, 12 bytes

+/∊2×+\∘.-+\

Test it with TryAPL.

How it works

+/∊2×+\∘.-+\  Monadic function train. Right argument: y (vector)

     +\   +\  Yield the cumulative sum of y.
       ∘.-    Compute all differences of all partial sums.
              This computes the sums of all adjacent subvectors of y that do not
              contain the first value, their negatives, and 0's in the diagonal.
   2×         Multiply all differences by 2.
+/            Yield the sum of y.
  ∊           Test for membership.


答:
Julia, 59 bytes

!n=sort(map(prod,combinations(17n|>primes,7))-n,by=abs)[]+n
```

<p>This is <em>very</em> inefficient, but it works for the first test case in practice and for the others in theory.</p>

<p>At the cost of 5 more bytes – for a total of <strong>64 bytes</strong> – efficiency can be improved dramatically.</p>

<pre class="lang-julia prettyprint-override"><code>!n=sort(map(prod,combinations(n>>14+17|>primes,7))-n,by=abs)[]+n
</code>```

Try it online!

Background

As mentioned in @LuisMendo's answer, the set of primes we have to consider for the nearest 7DP number is quite small. It suffices for the set to contains a 7DP number that is bigger than the input n, which will be true if and only if it contains a prime p ≥ 17 such that 30300p = 2·3·5·7·11·13·p ≥ n.

In On the interval containing at least one prime number proves that the interval [x, 1.5x) contains at least one prime number whenever x ≥ 8. Since 30030 / 16384 ≈ 1.83, that means there must be a prime p in (n/30030, n/16384) whenever n > 8 · 30300 = 242400.

Finally, when n < 510510, p = 17 is clearly sufficient, so we only need to consider primes up to n/16384 + 17.

At the cost of efficiency, we can consider primes up to 17n instead. This works when n = 1 and is vastly bigger than n/16384 + 17 for larger values of n.

How it works

17n|>primes and n>>14+17|>primes (the bitshift is equivalent to dividing by 214 = 16384) compute the prime ranges mentioned in the previous paragraph. Then, combinations(...,7) computes all arrays of seven different prime numbers in that range, and mapping prod over those calculates their products, i.e., the 7DP numbers from which we'll choose the answer.

Next, -n subtracts n prom each 7DP number, then sort(...,by=abs) sorts those differences by their absolute values. Finally, we select the first difference with [] and compute the corresponding 7DP number by adding n with +n.

Title: Closest 7-Distinct-Prime Product

Body:
(via chat)

The OEIS entry A123321 lists the sequence of numbers that are the product of seven distinct primes. For brevity, we'll call this a 7DP number. The first few numbers and their corresponding divisors are below:

```<code>510510 = 2 * 3 * 5 * 7 * 11 * 13 * 17
570570 = 2 * 3 * 5 * 7 * 11 * 13 * 19
690690 = 2 * 3 * 5 * 7 * 11 * 13 * 23
746130 = 2 * 3 * 5 * 7 * 11 * 17 * 19
</code>```

The challenge here will be to find the closest 7DP number, in terms of absolute distance, from a given input.

Input

A single positive integer n in any convenient format.

Output

The closest 7DP number to n, again in any convenient format. If two 7DP numbers are tied for closest, you can output either or both.

Rules

Numbers can be assumed to fit in your language's default [int] datatype (or equivalent).

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

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

Examples

```<code>5 -> 510510
860782 -> 870870
1425060 -> 1438710 (or 1411410, or both)
</code>```

Body:
Julia, 59 bytes

!n=sort(map(prod,combinations(17n|>primes,7))-n,by=abs)[]+n

This is very inefficient, but it works for the first test case in practice and for the others in theory.

At the cost of 5 more bytes – for a total of 64 bytes – efficiency can be improved dramatically.

!n=sort(map(prod,combinations(n>>14+17|>primes,7))-n,by=abs)[]+n

Try it online!

Background

As mentioned in @LuisMendo's answer, the set of primes we have to consider for the nearest 7DP number is quite small. It suffices for the set to contains a 7DP number that is bigger than the input n, which will be true if and only if it contains a prime p ≥ 17 such that 30300p = 2·3·5·7·11·13·p ≥ n.

In On the interval containing at least one prime number proves that the interval [x, 1.5x) contains at least one prime number whenever x ≥ 8. Since 30030 / 16384 ≈ 1.83, that means there must be a prime p in (n/30030, n/16384) whenever n > 8 · 30300 = 242400.

Finally, when n < 510510, p = 17 is clearly sufficient, so we only need to consider primes up to n/16384 + 17.

At the cost of efficiency, we can consider primes up to 17n instead. This works when n = 1 and is vastly bigger than n/16384 + 17 for larger values of n.

How it works

17n|>primes and n>>14+17|>primes (the bitshift is equivalent to dividing by 214 = 16384) compute the prime ranges mentioned in the previous paragraph. Then, combinations(...,7) computes all arrays of seven different prime numbers in that range, and mapping prod over those calculates their products, i.e., the 7DP numbers from which we'll choose the answer.

Next, -n subtracts n prom each 7DP number, then sort(...,by=abs) sorts those differences by their absolute values. Finally, we select the first difference with [] and compute the corresponding 7DP number by adding n with +n.


答:
Mathematica <s>136 80</s> 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

```<code>g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)⌊z=n-⌊k/2](-1)^k⌋,k++];z)
</code>```

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n.  If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product.  This more efficient version adopts the approach Dennis took.

The key advance was in using ⌊k/2](-1)^k⌋ to return the series, 0, 1, -1, 2, -2... The zero is used to check whether n is itself a 7-distinct-prime product. For this reason, Floor(that is, ⌊...⌋) is used instead of Ceiling.

```<code>g[5]
g[860782]
g[1425060]
</code>```

510510

870870

1438710

Title: Closest 7-Distinct-Prime Product

Body:
Mathematica <s>136 80</s> 75 bytes

This is a straightforward approach, working outwards from n.

n is a 7-distinct-prime product iff the number of prime factors is 7 (PrimeNu@#==7) and none of these factors appears more than once (SquareFreeQ@#&).

g@n_:=(k=1;While[!(PrimeNu@#==7&&SquareFreeQ@#&)⌊z=n-⌊k/2](-1)^k⌋,k++];z)

My earlier submission (136 bytes) found both the first 7-distinct-prime product above n and, if it exists, the first 7-distinct-prime product below n. It then simply determined which was closer to n.  If the products were equidistant, it returned both.

The current version checks n-1,n+1,n-2,n+2... until it reaches the first 7-distinct-prime product.  This more efficient version adopts the approach Dennis took.

The key advance was in using ⌊k/2](-1)^k⌋ to return the series, 0, 1, -1, 2, -2... The zero is used to check whether n is itself a 7-distinct-prime product. For this reason, Floor(that is, ⌊...⌋) is used instead of Ceiling.

g[5]
g[860782]
g[1425060]

510510

870870

1438710


问:
Recognize a vine

Background

I have a bunch of old and grainy black-and-white images.
Some of them depict vines climbing on a wall, others don't – your task is to classify them for me.

Input and output

Your input is a rectangular 2D array of bits A, given in any convenient format.
It will not be empty, but it's not guaranteed to contain both 0s and 1s.
The array depicts a vine if the following conditions hold:

The bottom row of A contains at least one 1. These are the roots of the vine.

Every 1 in A is connected to the bottom row by a path of 1s that only goes left, right and down (not up, and not diagonally). These paths are the branches of the vine.

Your output is a consistent truthy value if the input depicts a vine, and a consistent falsy value otherwise.

Examples

This array depicts a vine:

```<code>0 0 1 0 0 1
0 1 1 0 0 1
0 1 0 1 1 1
1 1 0 1 0 1
0 1 1 1 0 1
0 0 1 0 1 1
</code>```

This input does not depict a vine, since there's a 1 at the middle of the right border that's not connected to the roots by a branch:

```<code>0 0 0 1 1 0
0 1 0 1 1 1
0 1 0 1 0 1
0 1 1 1 1 0
0 0 1 1 0 1
</code>```

The all-0 array never depicts a vine, but the all-1 array always does.

Rules and scoring

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

Test cases

Truthy inputs:

```<code>1

0
1
1

01
11

0000
0111
1100
1001

1111
1111
1111
1111

001001
011001
010111
110101
011101
001011

1011011
1001001
1111111
0100000
0111111
1111001
1001111
1111101

0000000
0011100
0010100
0011100
0001000
1111111
0001000
0011100
0010100
0010100
</code>```

Falsy inputs:

```<code>0

1
0

10
01

000
000
000

011
110
000

111111
000000
101011
111001

010010
001000
000010
110001

001100
111111
110101
010011
111011

000110
010111
010101
011110
001101

11000000
10110001
10011111
11110001
01100011
00110110
01101100
01100001
01111111
</code>```

答:
Python 2, 254 bytes

No libraries

```<code>def f(A,r=0,c=-1):
 B=A[r];R=len(A)-1;C=len(B);i=1 in A[R]
 if c<0:
    for j in range(R*C+C):
        if A[j/C][j%C]:i&=f(A,j/C,j%C)
    return i&1
 _=B[c];B[c]=0;i=_&(r==R)
 if _:
    if c>0:i|=f(A,r,c-1)
    if r<R:i|=f(A,r+1,c)
    if c<C-1:i|=f(A,r,c+1)
 B[c]=_;return i
</code>```

Note that the second and third level indents are formed with tabs in the byte count.

Try it online

Title: Recognize a vine

Body:
Python 2, 254 bytes

No libraries

def f(A,r=0,c=-1):
 B=A[r];R=len(A)-1;C=len(B);i=1 in A[R]
 if c<0:
    for j in range(R*C+C):
        if A[j/C][j%C]:i&=f(A,j/C,j%C)
    return i&1
 _=B[c];B[c]=0;i=_&(r==R)
 if _:
    if c>0:i|=f(A,r,c-1)
    if r<R:i|=f(A,r+1,c)
    if c<C-1:i|=f(A,r,c+1)
 B[c]=_;return i

Note that the second and third level indents are formed with tabs in the byte count.

Try it online


问:
How's your string theory?
Back to the basics! You're in you comp sci class again, except wiser and golfier. You have the tools, you have the power… but do you have the skill? Probably.

Crash Course for the non-Computer Scientist (skip if you don't need it)

A string is symbolically represented by an arbitrary letter (usually, for our purposes, will be  etc. Of course, we know a string as something like "Hello, World!" or 'Hello, World!', or, if you're the snarky Python user, """Hello, World!""".

An alphabet can be thought of as a set (i.e. no repeating characters) of symbols, of which strings can be made. For example, ; this is the binary alphabet, of which contains strings like  and .  These strings can said to be strings over , or, alternatively, .

The length of any string is denoted . For example, .

There is the empty or null string , which is equivalent to "". It is a valid string in over any alphabet. In other words,  is the unique string satisfying the property .

The set  is the set of all strings  over  for which .

The set  is called the Kleene closure of , and is the set of all strings over . This can be considered the language of .

The concatenation of two strings  and  is denoted , and is the string containing the characters of  followed by the characters of .

 is said to be a prefix of  if there is some string  that satisfies the equality . (If , then  is said to be a proper prefix of .)

The alphabet of a string  is denoted , and is the minimal alphabet  so that  is a string over

The projection of a string  relative to an alphabet  is defined as

and is essentially the removal of all characters in  not in .

TL;DR

Objective Write a program, series of functions, series of programs etc. that can calculate as many of the following tasks as possible:

(1) Calculate, given a string s, its length.

(2) Arrive at, given a string s and an alphabet Σ, whether or not (output a truthy/falsy value) that string is over said alphabet.

(1) Given an alphabet, arrive at whether or not (output a truthy/falsy value) the alphabet is valid (a valid alphabet can have no repeating characters, but is otherwise valid).

(4) Given an alphabet Σ and a positive integer n, display .

(6) Given an alphabet Σ and an integer n, display the first n entries in  (Remember that ε ∈ Σ!)

(1) Given a string s and a string t, output st.

(3) Given a string s, output Al(s).

(5) Given a string s and an alphabet Σ, output πΣ(s).

Input is given by a string or your language's closest equivalent for a string input, an array, tuple, or n-ordinate of characters for an alphabet  (your language's closest equivalent), and a number for a number (or your language's closest equivalent, heaven forbid your language does not support numbers!).

Each task has a score (the number in parenthesis). Your submission's score is calculated as follows:

```<code>        sum points scored
score = —————————————————
         length of bytes
</code>```

Highest score wins.

Bonuses

×4 final score iff you output (with the correct symbols!) the input query. E.g., outputting \pi_{\{0,1\}}(012345678910111213)=01101111 for an input of Σ = [0,1]; s = 012345678910111213. (You may choose to do this in either HTML or (La)TeX. Either counts.)

(I'm open to suggestions.)

答:
dc: 1k 1 1+2 3+/p: 0.4 points

Strings s and t, as applicable, must be present on the top of the stack at execution time, with s topmost.

Calculate length of string s: 1pt, 2B

```<code>Zp
</code>```

Concatenate s and t: 1pt, 3B

```<code>rnn
</code>```

Title: How's your string theory?

Body:
dc: 1k 1 1+2 3+/p: 0.4 points

Strings s and t, as applicable, must be present on the top of the stack at execution time, with s topmost.

Calculate length of string s: 1pt, 2B

Zp

Concatenate s and t: 1pt, 3B

rnn


问:
Find the Factorial!
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

$$n!:=\begin{cases}1 & n=0\\n\cdot(n-1)!&n>0\end{cases}$$

In plain English the factorial of 0 is 1 and the factorial of n, where n is larger than 0 is n times the factorial of one less than n.

Your code should perform input and output using a standard methods.

Requirements:

Does not use any built-in libraries that can calculate the factorial (this includes any form of eval)

Can calculate factorials for numbers up to 125

Can calculate the factorial for the number 0 (equal to 1)

Completes in under a minute for numbers up to 125

The shortest submission wins, in the case of a tie the answer with the most votes at the time wins.

答:
Yup, <s>33</s> 31 29 bytes

```<code>*{{:0e-}]~{~|~|0~--e~}~#\}0e#
</code>```

Here's the github. Invoke like this:

```<code>node yup.js <location>.yup -n <input>
</code>```

Or

```<code>node yup.js -l "*{{:0e-}]~{~|~|0~--e~}~#\}0e#" -n <input>
</code>```

or Try it online!

Examples:

```<code>λ node yup.js -l "*{{:0e-}]~{~|~|0~--e~}~#\}0e#" -n 5
120
λ node yup.js examples\factorial.yup -n 0
1
</code>```

Explanation

```<code>*{{:0e-}]~{~|~|0~--e~}~#\}0e#
*                              ` take input
 {                       }     ` while TOS -- if zero, we advance to the }
                          0e#  ` print number 1 (exp(0))
                               ` otherwise (nonzero)
  {    }                       ` while TOS is not zero
   :                           ` duplicate TOS
    0                          ` push 0
     e                         ` pop 0, push exp(0) = 1
      -                        ` subtract 1
                               ` we eventually are at zero.
        ]                      ` we move that zero to the bottom of the stack
         ~                     ` switch top two for looping offset
          {~        ~}         ` while STOS
            |~|0~--e           ` multiply two elements (see further down)
                      ~        ` switch the top zero with the result
                       #       ` print the result
                        \      ` exit program (so we don't print the final one)
</code>```

Multiplication

In this program, I have multiplication defined as thus:

```<code>|~|0~--e
</code>```

First, observe 0~--. This pushes a zero behind the TOS, and subtracts twice:

```<code>command | stack
        | a b
0       | a b 0
~       | a 0 b
-       | a (-b)
-       | a - (-b) = a + b
</code>```

This performs addition. Let's replace 0~-- with + for clarity:

```<code>|~|+e
</code>```

Now, | is ln. So watch the stack:

```<code>command | stack
        | a b
|       | a ln(b)
~       | ln(b) a
|       | ln(b) ln(a)
+       | (ln(b)+ln(a))
e       | exp(ln(b)+ln(a))
</code>```

And, by the theorem of logarithms, this is multiplication.

Title: Find the Factorial!

Body:
Yup, <s>33</s> 31 29 bytes

*{{:0e-}]~{~|~|0~--e~}~#\}0e#

Here's the github. Invoke like this:

node yup.js <location>.yup -n <input>

Or

node yup.js -l "*{{:0e-}]~{~|~|0~--e~}~#\}0e#" -n <input>

or Try it online!

Examples:

λ node yup.js -l "*{{:0e-}]~{~|~|0~--e~}~#\}0e#" -n 5
120
λ node yup.js examples\factorial.yup -n 0
1

Explanation

*{{:0e-}]~{~|~|0~--e~}~#\}0e#
*                              ` take input
 {                       }     ` while TOS -- if zero, we advance to the }
                          0e#  ` print number 1 (exp(0))
                               ` otherwise (nonzero)
  {    }                       ` while TOS is not zero
   :                           ` duplicate TOS
    0                          ` push 0
     e                         ` pop 0, push exp(0) = 1
      -                        ` subtract 1
                               ` we eventually are at zero.
        ]                      ` we move that zero to the bottom of the stack
         ~                     ` switch top two for looping offset
          {~        ~}         ` while STOS
            |~|0~--e           ` multiply two elements (see further down)
                      ~        ` switch the top zero with the result
                       #       ` print the result
                        \      ` exit program (so we don't print the final one)

Multiplication

In this program, I have multiplication defined as thus:

|~|0~--e

First, observe 0~--. This pushes a zero behind the TOS, and subtracts twice:

command | stack
        | a b
0       | a b 0
~       | a 0 b
-       | a (-b)
-       | a - (-b) = a + b

This performs addition. Let's replace 0~-- with + for clarity:

|~|+e

Now, | is ln. So watch the stack:

command | stack
        | a b
|       | a ln(b)
~       | ln(b) a
|       | ln(b) ln(a)
+       | (ln(b)+ln(a))
e       | exp(ln(b)+ln(a))

And, by the theorem of logarithms, this is multiplication.