Title: When was this language released?

Body:
Your challenge is simple. You need to write a program that prints to either STDOUT or a file the year the language it is written in was released. Because this is such a simple task, the twist is that it must be written in as many different languages as possible.

Your score is the total number of different years that are correctly printed.

For each language you use, you must

Specify which version of the language you are using. (If there are multiple versions)

Specify what year that version was first released, and

Provide a link to a page proving the date of your version/language.

Any one of these counts as release date proof, as long as it specifies the version number (if applicable) and a release date.

A wikipedia page.

An esolangs page.

The language's official website. A github page or similar counts, as long as it has a release date. (Latest commit does not count, unless there is a version number somewhere in the code)

If there are not multiple versions or releases of a language, just use the initial release date of the language.

Minor versions of the same language do count as different languages, as long as they come from different years and still produce the correct output. You may not use any builtins that give you information (including release date) about the current version of the language you are using. For example, this is an invalid python submission:

```<code>import platform
i = platform.python_version()
if i == '3.5':
    print(2015)
if i == '3.4':
    print(2014)
if i == '3.3':
    print(2012)
...
</code>```

Whichever submission correctly prints the most distinct years wins!

Rules

Each program must print out the language year and nothing more. A trailing newline (windows style or *nix style) is allowed.

No programs may take any input.

In case of a tie, the shortest code scored in bytes wins. You may use whatever encoding you like for this, but all programs must use the same encoding.

Any of the programs may print to STDERR, or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file.

Different languages may use different IO methods, but they most all be full programs, (functions not allowed for this challenge) and follow one of our default IO methods allowed.

Happy <s>golfing</s> polyglotting!

Body:
10 years, 12 languages, 2430 bytes

This answer is a collaboration between myself and user 1000000000.

A brief language list:

Brainfuck    1993
Befunge      1993
Piet         2001
Whitespace   2003
Braincopter  2005
Grass        2007
Starry       2008
Paintfuck    2008
Brainbool    2010 (11111011010)
Python 2.7.2 2011
Fission      2014
Brainflak    2016

Here is the code:

P3v="";print(sum([ord(x)for x in"~~~~~~~~~~~~~~~y"]));"""{}{}     + + +---[.     + +..  '.. +. +.. +. +. +.] + + + + + + +(((((()()()()){}){}){}){})({({} +-[<() + + + + + + +>-()])}{}<[. + + + + + + + +..-------  `             +.[-]]>)[< '
 17 12
# > 7*::,8 +:,,2 +,@<>R"2014";]*ne*e*es*s*swWWW*swWWWW*sw*e*e*e*eeev*wn*n*n*n*ne*e*se*s*s*s*sWWwWWWw**e*eeee*vwn*n*n*n*ne*e*se*s*s*s*sWWWw*eeee*e*ne*n*nWWWWWw*ne*nWWWWWWw*w*sw*se*sWWWWWWWw*s*WWWWWWwwwWWWWWWWWWWwWWWWWWWWWWwvwWWWwWWWWwvwWWwWWWwvwWWwWWWwvwWWwWWWwvwWWwwwwwwwwwwwWWWwWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWWWWwWWWWWWWWWWWWwv `
255 0 255 255   0   192 192 0   192 192 0 192 192   192 255
255 192
255 255 192
255
255
0 255 255 0 255 255 0 255 255 0 255 255 0 192 192 192 255 255 255 255 255 0 192 192 0 0 255 255 255
255 0 0 255 0 192 192 0 192 192 0 192 192 192 255 255 192 255 255 192 255 255 192 255 255 0 255 255 0 255 255 0 255 255 0 192 192 255 255 255 255 255 255 255 255 255 255 255 255 0 192
192 0 0 255 0 192 192 0 192 192 0 192 192 0 192 192 192 255 255 192 255 255 192 255 255 0 255 255 0 255 255 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0 0
255 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 255 255
255 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 0 192
192 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 0 0
255 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 0 255 255 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 255 255
255 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 0 192
192 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 0 0
192 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 0 0 0 0 0 0 255 255
255 0 192 192 0 0 255 0 0 255 255 255 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 255 255 255 255 255 255 0 0 255 0 0 255 0 255 255 0 0 0 0 192 192 0 0
255 0 192 192 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 255 255 0 0 0 0 192 192 0 192 192
#   """

In order to fit this within a response I will forgo entire TIO links and will rather just post a link to a valid interpreter where the code may be input by the user.  Here is a Pastebin link for that purpose.

Piet

The PPM file format, one of the image formats that the Piet interpreter we used can read from, has a plaintext ASCII version. Using this we were able to embed the code of other languages as junk in the image file read by Piet and Braincopter.

The image looks like this:

Not all of the image is important for Piet.  Here is a version with a line highlighting the path that Piet follows through the code:

Despite somewhat convoluted methods to create the program the program itself is quite simple.  Along the top of the image it pushes 1 10 10 10 2 to the stack; along the side it multiplies thrice and adds once.  In the bottom corner it outputs the result (2001) and then halts.

Braincopter

Braincopter is the other visual language.  It also relies on the same ppm image file to run.  Because of very harsh restrictions in npiet our Braincopter code can only use a subset of the original Braincopter operations.  We are restricted to using colors that are valid ops in Piet.  This removes the - operator from Braincopter.

Here is the path traced out by the Braincopter code:

The Braincopter program is a bit strange because of the lack of a - operator.  The walls of cyan and dark cyan serve to redirect the pointer but other than that it is identical to the following brainfuck:

++++++++++++++++++++++++++++++++++++++++++++++++++.>++++++++++++++++++++++++++++++++++++++++++++++++..+++++.

This prints 2005.

Paintfuck

Paintfuck is the third visual programming language on our list however instead of taking in a image and outputting text, Paintfuck takes in text and outputs an image.

Since Paintfuck ignores irrelevant characters as no-ops most of the code is unimportant.  The relevant section of the code is:

nsn**ne*e*es*s*sw*sw*sw*e*e*e*eee*wn*n*n*n*ne*e*se*s*s*s*sww**e*eeee*wn*n*n*n*ne*e*se*s*s*s*sw*eeee*e*ne*n*nw*ne*nw*w*sw*se*sw*s*wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwnsn**ne*e*es*s*sw*sw*sw*e*e*e*eee*wn*n*n*n*ne*e*se*s*s*s*sww**e*eeee*wn*n*n*n*ne*e*se*s*s*s*sw*eeee*e*ne*n*nw*ne*nw*w*sw*se*sw*s*wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww

While they are not no-ops the ws at the end of the code do nothing.  They are there for the grass portion of the solution.  n,e,s, and w are used to move around the image and * is used to plot a point at certain location.  The program outputs:

A bigger version:

Brainfuck

Like Paintfuck Brainfuck ignores most characters.  Once again here are the important ones:

 []+++---[.++....+.+..+.+.+.]++++++++-[<+++++++>-]<[.++++++++..-------+.[-]]>[<>,+,,+,<>]

Most of this is further irrelevant by circumstance and just happen to be characters that some other language needed.  The slimmer version of this code is:

+++++++[<+++++++>-]<[.++++++++..------.[-]]

This pretty simply prints 1993.

Brainbool

Brainbool is very similar to Brainfuck in its character selection.  The big difference that allows the two to be woven together is the lack of a - in Brainbool.  The important characters for Brainbool are:

[]+++[.++....+.+..+.+.+.]++++++++[<+++++++>]<[.++++++++..+.[]]>[<>,+,,+,<>]

Brainbool and brainfuck's outputs are mutually exclusive. Brainbool hides its output in the second set of [].  Brainfuck encounters +++--- before it reaches the [ setting it to zero and causing it to skip the output, while Brainbool only sees +++ setting it to 1 causing it to pass through the loop.  Similarly Brainbool is set to zero at the 4th loop causing it to skip while Brainfuck enters the loop with a value of 49.

Since Brainbool does not have decimal output it outputs the 2010 in binary:

11111011010

Fission

The only part of the code that is important for fission is:

R"2014";

The R summons in a atom moving to the right,  the "2014" prints 2014 and the ; halts execution.

Befunge

Befunge only passes through the following characters:

P3v
  7
  > 7*::,8 +:,,2 +,@

The P3 are necessary to make a valid .ppm image for piet, and cumulatively push a 3 to the stack.  the v is placed to redirect the the pointer downwards.  It then passes through the 7 in the 17 used to indicate the width of the .ppm image.  The > redirects the pointer to the right.  7* multiplies the top of the stack by 7 leaving 49 (ASCII value of 1) on the top of the stack. :: duplicates the top of the stack twice. The 1 is output by ,.  8 + adds 8 to the top incrementing to ASCII 9.  :,, outputs 9 twice.  2 + increments the ASCII 1 to an ASCII 3 and , prints.  Finally @ terminates the program.

All in all it prints 1993.

Whitespace

Whitespace, as the name might suggest, only uses whitespace in its programs. This is what the Whitespace interpreter sees:

[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][LF]
[Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Tab][Tab][Tab][Tab][Tab][Space][Tab][Space][Space][Tab][Tab][LF]
[Tab][LF]
[Space][Tab][LF]
[LF]
[LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][Space][LF]
[Space][Space][Space][LF]

Most of what this code does is inconsequential to the execution of the program (all the lines containing only spaces simply push zero to the stack). The important part:

[Space][Space][Space][Tab][Tab][Tab][Tab][Tab][Space][Tab][Space][Space][Tab][Tab][LF]
[Tab][LF]
[Space][Tab][LF]
[LF]
[LF]

The first line pushes 2003 to the stack. After that [Tab][LF][Space][Tab] prints out the top of the stack (2003) as a number. Finally the last three linefeeds end the program execution.

Grass

Grass ignores all character until the first w in the file and after that all characters that are not w, W, or v. The Grass interpreter reads:

wWWWwWWWWwv
wWWwWWWwv
wWWWwWWWWWwWWWWWWwwwWWWWWWWwWWWWWWwwwWWWWWWWWWWwWWWWWWWWWWwv
wWWWwWWWWwv
wWWwWWWwv
wWWwWWWwv
wWWwWWWwv
wWWwwwwwwwwwwwWWWwWWWWWwWWWWWWWwWWWWWWWWWwWWWWWWWWWWWWWWWwWWWWWWWWWWWWwv

The first line defines a function that adds two to whatever it is passed. The second line defines a function that adds four to whatever it is passed. The third defines a function that prints two plus the argument, the prints the argument twice, then finally prints seven plus the argument (Grass prints out characters based on ASCII value). The fourth, fifth and sixth lines define functions that add eight, add 16, add 32, and add 64 to their argument, respectively. The final line defines the main function which takes the character w (the only predefined number in Grass, ASCII value 119) and adds 185 to it using the add functions defined in the program as well as the built in add one function. Grass wraps numbers at 256 and so the result is 48 (corresponding to the character 0). The function then passes this to the function of the third line which prints out 2007.

Starry

Starry ignores everything except for space, +, *, ., ,, `, and '. Thus the starry interpreter sees only:

       + + +.     + +..  '.. +. +.. +. +. +. + + + + + + + + + + + + + + +. + + + + + + + +..  `             +. '
     *, +,, +,************************************************* `

However, the label and jump instructions are used to skip sections of the code which could cause problems if run, so the code is effectively this:

       + + +.     + +..  '  `             +. ' `

This code pushes two to the stack, duplicates it twice and then pops and prints one of them as a number. Then pushes zero, duplicates it and prints both zeros as numbers. Next it pops one of the twos and jumps and then pushes seven to the stack and pops and prints is as a number. Finally it pops the last two on the stack and jumps to the end of the program.

Python 2.7.2

The Python code follows the format:

P3v="";print(sum([ord(x)for x in"~~~~~~~~~~~~~~~y"]));"""..."""

where ... stands in for all of the other junk.

The first line, P3v="" is there because to be a valid .ppm file our code must start with P3 this will normally error but if we tell python it is a variable declaration it will ignore it.

Next we have to print 2011.  However because of the way that a .ppm is formatted we cannot include any numbers in this line.  In order to get around this we sum up all of the ASCII values of the string "~~~~~~~~~~~~~~~y" and print the result.  Finally we use the triple quotes of a multiline comment so that python ignores everything else.

Brainflak

We saved the best for last.

Brainflak, like others, ignores most characters.  The relevant characters are:

(([()])){}{}[](((((()()()()){}){}){}){})({({}[<()>()])}{}<[[]]>)[<><>]

The python code, (([()])), pushes -1 to the stack twice so it needs to be removed before the program begins processing.

After that Brainbool uses a [] nilad which does nothing and the program begins.

(((((()()()()){}){}){}){})({({}[<()>()])}{}<[[]]>) pushes 2016. The last [<><>] is remnants of Befunge and Brainfuck but luckily does nothing.

When the program terminates it prints the contents of the stack, that is it prints 2016.


问:
Least Common Multiple
The least common multiple of a set of positive integers A is the smallest postive integer B such that, for each k in A, there exists a positive integer n such that k*n = B.

Given at least two positive integers as input, output their least common multiple.

Rules

Builtins are allowed, but if your solution uses one, you are encouraged to include an alternate solution that does not use GCD/LCM builtins. However, the alternate solution will not count towards your score at all, so it is entirely optional.

All inputs and outputs will be within the natively-representable range for your language. If your language is natively capable of arbitrarily-large integers, then your solution must work with arbitrarily large inputs and outputs.

Test cases

```<code>[7, 2] -> 14
[8, 1] -> 8
[6, 4, 8] -> 24
[8, 2, 1, 10] -> 40
[9, 6, 2, 1, 5] -> 90
[5, 5, 7, 1, 1] -> 35
[4, 13, 8, 8, 11, 1] -> 1144
[7, 2, 2, 11, 11, 8, 5] -> 3080
[1, 6, 10, 3, 4, 10, 7] -> 420
[5, 2, 9, 10, 3, 4, 4, 4, 7] -> 1260
[9, 7, 10, 9, 7, 8, 5, 10, 1] -> 2520
</code>```

答:
Java 7, 75 bytes

```<code>int f(int[]a){int i=1,s=1;for(;s>0;i++){s=0;for(int b:a)s+=i%b;}return--i;}
</code>```

A simple two-loop method. Start at one and check to see when all the remainders add to zero.

I had to jump through some dumb hoops with s. There's probably a better way to do that, but it's 1:00 AM and it'll have to wait :/

ContentLicense: CC BY-SA 3.0

Title: Least Common Multiple

Body:
Java 7, 75 bytes

int f(int[]a){int i=1,s=1;for(;s>0;i++){s=0;for(int b:a)s+=i%b;}return--i;}

A simple two-loop method. Start at one and check to see when all the remainders add to zero.

I had to jump through some dumb hoops with s. There's probably a better way to do that, but it's 1:00 AM and it'll have to wait :/


答:
JavaScript (ES6), 53 bytes (non-competing)

A recursive function which builds all gray codes until the input is found, then stops at the next iteration.

The highest possible input depends on the browser recursion limit (about 13 bits in Firefox and 15 bits in Chrome).

f=(s,n=1)=>(b=(n^n/2).toString(2),s)?f(b!=s&&s,n+1):b

console.log(f("1"));      // -> 11
console.log(f("11"));     // -> 10
console.log(f("111"));    // -> 101
console.log(f("1011"));   // -> 1001
console.log(f("1111"));   // -> 1110
console.log(f("10111"));  // -> 10110
console.log(f("101100")); // -> 100100
console.log(f("100000")); // -> 1100000```

Title: Incrementing Gray Codes

Body:
Introduction

A Gray Code is an alternative to binary representation in which a number is incremented by toggling only one bit, rather than a variable amount of bits. Here are some gray codes along with their decimal and binary equivalents:

```<code> decimal | binary | gray
-------------------------
       0 |      0 |    0
-------------------------
       1 |      1 |    1
-------------------------
       2 |     10 |   11
-------------------------
       3 |     11 |   10
-------------------------
       4 |    100 |  110
-------------------------
       5 |    101 |  111
-------------------------
       6 |    110 |  101
-------------------------
       7 |    111 |  100
-------------------------
       8 |   1000 | 1100
-------------------------
       9 |   1001 | 1101
-------------------------
      10 |   1010 | 1111
-------------------------
      11 |   1011 | 1110
-------------------------
      12 |   1100 | 1010
-------------------------
      13 |   1101 | 1011
-------------------------
      14 |   1110 | 1001
-------------------------
      15 |   1111 | 1000
</code>```

Cyclic Bit Pattern of a Gray Code

Sometimes called "reflected binary", the property of changing only one bit at a time is easily achieved with cyclic bit patterns for each column starting from the least significant bit:

```<code>bit 0: 0110011001100110011001100110011001100110011001100110011001100110
bit 1: 0011110000111100001111000011110000111100001111000011110000111100
bit 2: 0000111111110000000011111111000000001111111100000000111111110000
bit 3: 0000000011111111111111110000000000000000111111111111111100000000
bit 4: 0000000000000000111111111111111111111111111111110000000000000000
bit 5: 0000000000000000000000000000000011111111111111111111111111111111
</code>```

...and so on.

Objective

Given a non-padded input string of a gray code, increment the gray code by alternating a single character in the sequence or prepending a 1 (when incrementing to the next power of 2), then output the result as a non-padded gray code.

Caveats

Do not worry about taking 0 or an empty string as input.

The lowest input will be 1, and there is no upper-bound to the string length other than memory limitations imposed by the environment.

By non-padded string, I mean there will be no leading or trailing whitespace (other than an optional trailing newline), and no leading 0s in the input or output.

I/O formats

The following formats are accepted form for input and output, but strings are encouraged over other formats:

most significant "bit" first

non-padded character array or string of ASCII '1's and '0's

non-padded integer array of 1s and 0s

non-padded boolean array

What's not allowed:

least significant "bit" first

decimal, binary or unary integer

fixed-length data-structure

character array or string of non-printable ASCII indices 1 and 0

Tests

```<code>input -> output
1 -> 11
11 -> 10
111 -> 101
1011 -> 1001
1111 -> 1110
10111 -> 10110
101100 -> 100100
100000 -> 1100000
</code>```

More tests can be added by request.

Criteria

This is code-golf, so shortest program in bytes wins! All ties will be broken by favoring earlier submissions; standard loopholes apply. The best submitted answer will be accepted October 9th, 2016, and updated whenever better answers are given.


问:
Divisibility test

Task

Given two strictly positive integers n and d as input, determine whether n is evenly divisible by d, i.e., if there exists an integer q such that n = qd.

You may write a program or a function and use any of the our standard methods of receiving input and providing output.

The output should be a truthy or a falsy value; truthy if n is divisible by d, and falsy otherwise.

Your code only has to handle integers it can represent natively, as long as it works for all signed 8-bit integers. However, your algorithm has to work for arbitrarily large integers.

You may use any programming language, but note that these loopholes are forbidden by default.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

Test cases

```<code> n,  d    output

 1,  1    truthy
 2,  1    truthy
 6,  3    truthy
17, 17    truthy
22,  2    truthy
 1,  2    falsy
 2,  3    falsy
 2,  4    falsy
 3,  9    falsy
15, 16    falsy
</code>```

Leaderboard

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 + 3 (-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

```

答:
Brain-Flak, <s>72</s> <s>70</s> <s>64</s> <s>62</s> <s>58</s> 46 bytes

```<code>{({}[()]{(<()>)}{}<({}[()]<({}())>)>)}{}{{}}{}
</code>```

Takes dividend and divisor (in that order) as input and prints the divisor (truthy) or nothing. Since each stack has an implicit, infinite amount of zeroes, empty output should be considered falsy.

While not stack-clean, this solution uses only a single stack.

Try it online!

Thanks to @WheatWizard for golfing off 2 bytes!

How it works

```<code>                INPUT: a (dividend), b (divisor)
                INITIAL STACK: n = a, d = b, r = 0
                               An infinite amount of zeroes follows.

{               While n is non-zero:
  (
    {}              Pop n from the stack.
    [()]            Yield -1.
    {               While the top of the stack (initially, d) is non-zero:
      (<()>)          Push 0.
    }
    {}              Pop 0. This will remove d from the stack if d = 0, leaving r
                    on top. We can think of this as performing the assignment
                    (d, r) = (r, d) if d = 0.
    <
      (
        {}              Pop d.
        [()]            Yield -1.
        <
          (
            {}              Pop r.
            ()              Yield 1.
          )               Push r + 1.
        >               Yield 0.
      )               Push d + (-1) + 0 = d - 1.
    >               Yield 0.
  )               Push n + (-1) + 0 + 0 + 0 = n - 1.
}               Each iteration decrements n, swaps d and r if d = 0, decrements d,
                and increments r.
                FINAL VALUES: n = 0
                              d = b - r
                              r = a % b if a % b > 0 else b
{}              Pop n.
{               While the top of the stack is non-zero:
  {}              Pop it.
}               This pops d and r if d > 0 (and, thus, a % b > 0) or noting at all.
{}              Pop d or a 0, leaving r if r = b and, thus, a % b = 0.
</code>```

Modulus calculation, 42 bytes

The above full program can be modified in a trivial manner to calculate the modulus instead.

```<code>{({}[()]<({}[()]<({}())>)>{(<()>)}{})}{}{}
</code>```

As before, this method is not stack-clean, but it uses only a single stack. A modulus of 0 will leave the stack empty, which is roughly equivalent to leaving 0; each stack contains infinite zeroes.

Try it online!

How it works

Compare the two loops of the divisibility tester and the modulus calculator.

```<code>{({}[()]{(<()>)}{}<({}[()]<({}())>)>)}
{({}[()]<({}[()]<({}())>)>{(<()>)}{})}
</code>```

The only difference is the location of {(<()>)}{}, which swaps d and r if d = 0. To calculate the modulus, we perform this swap after decrementing d and incrementing r.

This change does not affect the outcome if a %b > 0, but if a % b = 0, it leaves (n, d, r) = (0, b, 0) – rather than (n, d, r) = (0, 0, b) – on the stack.

Thus, to obtain the modulus, we only have to pop n and d with {}{}.

Stack-clean modulus calculation, 64 bytes

The 42-byte modulus algorithm is not stack-clean, so it cannot be used as is in all programs. The following version pops dividend and divisor (in that order) from the active stack and pushes the modulus in return. It has no other side effects.

```<code>({}(<()>)){({}[()]<(({}()[({})])){{}(<({}({}))>)}{}>)}({}{}<{}>)
</code>```

This solution is largely based on @WheatWizard's previous 72-byte record, but it saves 6 bytes by never switching stacks.

Try it online!

How it works

```<code>             INPUT: a (dividend), b (divisor)
             INITIAL STACK: n = a, b

(
  {}         Pop and yield n = a.
  (<()>)       Push d = 0.
)              Push n + 0 = n.
             STACK: n, d = 0, b
{(           While n in non-zero:
  {}           Pop and yield n.
  [()]         Yield -1.
  <
   ((
     {}         Pop and yield d.
     ()         Yield 1.
     [({})]     Pop b, push it back on the stack, and yield -b.
   ))         Push d + 1 + -b = d + 1 - b twice.
   {          While/if d + 1 - b is non-zero, i.e., if d < b - 1
     {}         Pop d + 1 - b (second copy).
     (<(
       {}         Pop d + 1 - b (first copy).
       ({})       Pop b and push it back on the stack.
     )>)        Push d + 1 - b + b = d + 1, then 0.
   }          If the loop wasn't skipped entirely, pushing 0 breaks out.
              If d < b - 1, it essentially performs the assignment d = d + 1.
              However, if d = b - 1, we get d = d + 1 - b = b - 1 + 1 - b = 0.
              In all cases, we wind up with d = (d + 1) % b.
   {}         Pop 0.
  >         Yield 0.
)}        Push n + -1 + 0 = n - 1. Break if n - 1 = 0.
          STACK: n = 0, d = a % b, b
(
  {}        Pop and yield n = 0.
  {}        Pop and d = a % b.
  <{}>      Pop b, but yield 0.
)         Push 0 + a % b + 0 = a % b.
</code>```

Title: Divisibility test

Body:
Brain-Flak, <s>72</s> <s>70</s> <s>64</s> <s>62</s> <s>58</s> 46 bytes

{({}[()]{(<()>)}{}<({}[()]<({}())>)>)}{}{{}}{}

Takes dividend and divisor (in that order) as input and prints the divisor (truthy) or nothing. Since each stack has an implicit, infinite amount of zeroes, empty output should be considered falsy.

While not stack-clean, this solution uses only a single stack.

Try it online!

Thanks to @WheatWizard for golfing off 2 bytes!

How it works

                INPUT: a (dividend), b (divisor)
                INITIAL STACK: n = a, d = b, r = 0
                               An infinite amount of zeroes follows.

{               While n is non-zero:
  (
    {}              Pop n from the stack.
    [()]            Yield -1.
    {               While the top of the stack (initially, d) is non-zero:
      (<()>)          Push 0.
    }
    {}              Pop 0. This will remove d from the stack if d = 0, leaving r
                    on top. We can think of this as performing the assignment
                    (d, r) = (r, d) if d = 0.
    <
      (
        {}              Pop d.
        [()]            Yield -1.
        <
          (
            {}              Pop r.
            ()              Yield 1.
          )               Push r + 1.
        >               Yield 0.
      )               Push d + (-1) + 0 = d - 1.
    >               Yield 0.
  )               Push n + (-1) + 0 + 0 + 0 = n - 1.
}               Each iteration decrements n, swaps d and r if d = 0, decrements d,
                and increments r.
                FINAL VALUES: n = 0
                              d = b - r
                              r = a % b if a % b > 0 else b
{}              Pop n.
{               While the top of the stack is non-zero:
  {}              Pop it.
}               This pops d and r if d > 0 (and, thus, a % b > 0) or noting at all.
{}              Pop d or a 0, leaving r if r = b and, thus, a % b = 0.

Modulus calculation, 42 bytes

The above full program can be modified in a trivial manner to calculate the modulus instead.

{({}[()]<({}[()]<({}())>)>{(<()>)}{})}{}{}

As before, this method is not stack-clean, but it uses only a single stack. A modulus of 0 will leave the stack empty, which is roughly equivalent to leaving 0; each stack contains infinite zeroes.

Try it online!

How it works

Compare the two loops of the divisibility tester and the modulus calculator.

{({}[()]{(<()>)}{}<({}[()]<({}())>)>)}
{({}[()]<({}[()]<({}())>)>{(<()>)}{})}

The only difference is the location of {(<()>)}{}, which swaps d and r if d = 0. To calculate the modulus, we perform this swap after decrementing d and incrementing r.

This change does not affect the outcome if a %b > 0, but if a % b = 0, it leaves (n, d, r) = (0, b, 0) – rather than (n, d, r) = (0, 0, b) – on the stack.

Thus, to obtain the modulus, we only have to pop n and d with {}{}.

Stack-clean modulus calculation, 64 bytes

The 42-byte modulus algorithm is not stack-clean, so it cannot be used as is in all programs. The following version pops dividend and divisor (in that order) from the active stack and pushes the modulus in return. It has no other side effects.

({}(<()>)){({}[()]<(({}()[({})])){{}(<({}({}))>)}{}>)}({}{}<{}>)

This solution is largely based on @WheatWizard's previous 72-byte record, but it saves 6 bytes by never switching stacks.

Try it online!

How it works

             INPUT: a (dividend), b (divisor)
             INITIAL STACK: n = a, b

(
  {}         Pop and yield n = a.
  (<()>)       Push d = 0.
)              Push n + 0 = n.
             STACK: n, d = 0, b
{(           While n in non-zero:
  {}           Pop and yield n.
  [()]         Yield -1.
  <
   ((
     {}         Pop and yield d.
     ()         Yield 1.
     [({})]     Pop b, push it back on the stack, and yield -b.
   ))         Push d + 1 + -b = d + 1 - b twice.
   {          While/if d + 1 - b is non-zero, i.e., if d < b - 1
     {}         Pop d + 1 - b (second copy).
     (<(
       {}         Pop d + 1 - b (first copy).
       ({})       Pop b and push it back on the stack.
     )>)        Push d + 1 - b + b = d + 1, then 0.
   }          If the loop wasn't skipped entirely, pushing 0 breaks out.
              If d < b - 1, it essentially performs the assignment d = d + 1.
              However, if d = b - 1, we get d = d + 1 - b = b - 1 + 1 - b = 0.
              In all cases, we wind up with d = (d + 1) % b.
   {}         Pop 0.
  >         Yield 0.
)}        Push n + -1 + 0 = n - 1. Break if n - 1 = 0.
          STACK: n = 0, d = a % b, b
(
  {}        Pop and yield n = 0.
  {}        Pop and d = a % b.
  <{}>      Pop b, but yield 0.
)         Push 0 + a % b + 0 = a % b.


答:
Logicode, <s>289</s> 262 bytes

Presenting the language that's more verbose than Java!

```<code>circ d(n)->cond n<->0+n/d(n>)
circ e(n)->[
cond n->var a=~((~(d(n)))>)/var a=0
cond (~n)<->var b=a+0/var b=e(a)+1
b
]
circ f(a,b)->cond *a&*b->f(e(a),e(b))/a
circ g(a,b)->!(*(f(b,a)))
circ h(a,b)->cond b->h(e(a),e(b))/a
circ i(a,b)->cond g(a,b)->i(h(a,b),b)/c(a)
</code>```

I'll post an explanation later, but it's basically a shortened version of my prime checker.

Added a new feature: * (boolean)!

Title: Divisibility test

Body:
Task

Given two strictly positive integers n and d as input, determine whether n is evenly divisible by d, i.e., if there exists an integer q such that n = qd.

You may write a program or a function and use any of the our standard methods of receiving input and providing output.

The output should be a truthy or a falsy value; truthy if n is divisible by d, and falsy otherwise.

Your code only has to handle integers it can represent natively, as long as it works for all signed 8-bit integers. However, your algorithm has to work for arbitrarily large integers.

You may use any programming language, but note that these loopholes are forbidden by default.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

Test cases

```<code> n,  d    output

 1,  1    truthy
 2,  1    truthy
 6,  3    truthy
17, 17    truthy
22,  2    truthy
 1,  2    falsy
 2,  3    falsy
 2,  4    falsy
 3,  9    falsy
15, 16    falsy
</code>```

Leaderboard

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 + 3 (-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

```

Body:
Logicode, <s>289</s> 262 bytes

Presenting the language that's more verbose than Java!

circ d(n)->cond n<->0+n/d(n>)
circ e(n)->[
cond n->var a=~((~(d(n)))>)/var a=0
cond (~n)<->var b=a+0/var b=e(a)+1
b
]
circ f(a,b)->cond *a&*b->f(e(a),e(b))/a
circ g(a,b)->!(*(f(b,a)))
circ h(a,b)->cond b->h(e(a),e(b))/a
circ i(a,b)->cond g(a,b)->i(h(a,b),b)/c(a)

I'll post an explanation later, but it's basically a shortened version of my prime checker.

Added a new feature: * (boolean)!


答:
Perl, 27 bytes

Includes +1 for -p

Many different methods all seem to end up as either 27 or 28 bytes. e.g.

```<code>#!/usr/bin/perl -p
$\=$_="{@F}"for@F[0..$_]}{
</code>```

The best I could find is

```<code>#!/usr/bin/perl -p
s/./{$_/ for($\="{}")x$_}{
</code>```

since on older perls you can drop the space before the for and get 26 bytes

Title: Natural construction

Body:
The natural numbers including 0 are formally defined as sets, in the following way:

Number 0 is defined as the empty set, {}

For n ≥ 0, number n+1 is defined as n ∪ {n}.

As a consequence, n = {0, 1, ..., n-1}.

The first numbers, defined by this procedure, are:

0 = {}

1 = {{}}

2 = {{}, {{}}}

3 = {{}, {{}}, {{}, {{}}}}

Challenge

Given n, output its representation as a set.

Rules

The output can consistently use any bracket character such as {}, [], () or <>. Arbitrary characters (such as 01) are not allowed.

Instead of a comma as above, the separator can be any punctuation sign; or it may be inexistent.

Spaces (not newlines) may be included arbitrarily and inconsistently.

For example, number 2 with square brackets and semicolon as separator is [[]; [[]]], or equivalently [ [ ]; [ [ ] ] ], or even [  [ ] ;[  []]]

The order in which elements of a set are specified doesn't matter. So you can use any order in the representation. For example, these are some valid outputs for 3:

```<code>{{},{{}},{{},{{}}}}
{{{}},{{},{{}}},{}}
{{{}},{{{}},{}},{}}
</code>```

You can write a program or function. Output may be a string or, if using a function, you may return a nested list or array whose string representation conforms to the above.

Test cases

```<code>0  ->  {}
1  ->  {{}}
2  ->  {{},{{}}}
3  ->  {{},{{}},{{},{{}}}}
4  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}
5  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}
6  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}}
7  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}}}
</code>```

Body:
Perl, 27 bytes

Includes +1 for -p

Many different methods all seem to end up as either 27 or 28 bytes. e.g.

#!/usr/bin/perl -p
$\=$_="{@F}"for@F[0..$_]}{

The best I could find is

#!/usr/bin/perl -p
s/./{$_/ for($\="{}")x$_}{

since on older perls you can drop the space before the for and get 26 bytes


答:
Mathematica, 14 bytes

```<code>Array[#0,#,0]&
</code>```

Title: Natural construction

Body:
Mathematica, 14 bytes

Array[#0,#,0]&


问:
Dennis numbers 2.0
PPCG user and elected mod, @Dennis just became the second ever user to earn over 100k rep!

This is a totally original idea, that I did not get from anybody else, but let's make a challenge based off of his user ID, 12012 as a tribute!

Looking at it, you'll notice that there are two distinct "sections" to his ID.

12

and

012

Both of these sections add up to a 3. That's a pretty interesting property.

Let's define a "Dennis 2.0 number" as any positive integer where every maximal subsequence of strictly increasing digits sums to the same number. For example,

```<code>123
</code>```

is a Dennis 2.0 number because there is only one maximal sublist of strictly increasing digits, and it sums to 6. Additionally, 2,846,145 is also a Dennis 2.0 number because the three maximal sublists of increasing digits, namely

```<code>28
46
145
</code>```

All sum to 10. Additionally, numbers that just repeat the same digit must be Dennis 2.0 numbers because, for example, 777 can be broken down into

```<code>7
7
7
</code>```

which clearly all sum to seven.

A number such as 42 is not a Dennis 2.0 number, since it is broken down into

```<code>4
2
</code>```

which clearly do not sum to the same number.

The challenge

You must write a program or function to determine if a given number is a Dennis 2.0 number or not. You can take input and output in any reasonable input format, e.g. as a string, as a number, from a file, funtion arguments/return, from STDIN/STDOUT, etc. and then return a truthy value if this number is a Dennis 2.0 number, and a falsy value if it is not. For reference, here is every Dennis 2.0 number up to 1,000:

```<code>1
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
22
23
24
25
26
27
28
29
33
34
35
36
37
38
39
44
45
46
47
48
49
55
56
57
58
59
66
67
68
69
77
78
79
88
89
99
101
111
123
124
125
126
127
128
129
134
135
136
137
138
139
145
146
147
148
149
156
157
158
159
167
168
169
178
179
189
202
222
234
235
236
237
238
239
245
246
247
248
249
256
257
258
259
267
268
269
278
279
289
303
312
333
345
346
347
348
349
356
357
358
359
367
368
369
378
379
389
404
413
444
456
457
458
459
467
468
469
478
479
489
505
514
523
555
567
568
569
578
579
589
606
615
624
666
678
679
689
707
716
725
734
777
789
808
817
826
835
888
909
918
927
936
945
999
</code>```

Standard loopholes apply, and the shortest answer measured in bytes wins!

答:
Ruby, 117 105 85 bytes

```<code># original (117):
j,k=0,?0;"#{i}".chars.group_by{|n|n>k||j=j+1;k=n;j}.values.map{|a|a.map(&:to_i).reduce(&:+)}.reduce{|m,n|n==m ?m:nil}

# inspired by PHP regexp approach (105):
"#{i}".scan(/0?1?2?3?4?5?6?7?8?9?/).map{|a|a.chars.map(&:to_i).reduce(&:+)}.reduce{|m,n|!n||n==m ?m:nil}

# some number comparison simplification (85):
!"#{i}".scan(/0?1?2?3?4?5?6?7?8?9?/).map{|a|a.chars.map(&:to_i).reduce(&:+)}.uniq[1]
</code>```

This would return the integer of this dennis number or nil if not a dennis number. All integers will be considered true in ruby as well nil is considered false. i is the integer that is being check.

Third version actually returns true and false.

P.S. tested to return 172 integers from 1 to 1000 as in the answer.

Title: Dennis numbers 2.0

Body:
Ruby, 117 105 85 bytes

# original (117):
j,k=0,?0;"#{i}".chars.group_by{|n|n>k||j=j+1;k=n;j}.values.map{|a|a.map(&:to_i).reduce(&:+)}.reduce{|m,n|n==m ?m:nil}

# inspired by PHP regexp approach (105):
"#{i}".scan(/0?1?2?3?4?5?6?7?8?9?/).map{|a|a.chars.map(&:to_i).reduce(&:+)}.reduce{|m,n|!n||n==m ?m:nil}

# some number comparison simplification (85):
!"#{i}".scan(/0?1?2?3?4?5?6?7?8?9?/).map{|a|a.chars.map(&:to_i).reduce(&:+)}.uniq[1]

This would return the integer of this dennis number or nil if not a dennis number. All integers will be considered true in ruby as well nil is considered false. i is the integer that is being check.

Third version actually returns true and false.

P.S. tested to return 172 integers from 1 to 1000 as in the answer.


答:
Perl, <s>27</s> 25 bytes

Includes +1 for -p

Give input string on STDIN, e.g.

```<code>gray.pl <<< 1010
</code>```

gray.pl:

```<code>#!/usr/bin/perl -p
s%(10*\K1(\K0)*)*%1-$&%e
</code>```

Perl has no cheap infinite-precision integers. So directly toggle the right bit which is the one just before where the last odd-numbered 1 would be.

Title: Incrementing Gray Codes

Body:
Perl, <s>27</s> 25 bytes

Includes +1 for -p

Give input string on STDIN, e.g.

gray.pl <<< 1010

gray.pl:

#!/usr/bin/perl -p
s%(10*\K1(\K0)*)*%1-$&%e

Perl has no cheap infinite-precision integers. So directly toggle the right bit which is the one just before where the last odd-numbered 1 would be.


Title: Dennis numbers 2.0

Body:
PPCG user and elected mod, @Dennis just became the second ever user to earn over 100k rep!

This is a totally original idea, that I did not get from anybody else, but let's make a challenge based off of his user ID, 12012 as a tribute!

Looking at it, you'll notice that there are two distinct "sections" to his ID.

12

and

012

Both of these sections add up to a 3. That's a pretty interesting property.

Let's define a "Dennis 2.0 number" as any positive integer where every maximal subsequence of strictly increasing digits sums to the same number. For example,

```<code>123
</code>```

is a Dennis 2.0 number because there is only one maximal sublist of strictly increasing digits, and it sums to 6. Additionally, 2,846,145 is also a Dennis 2.0 number because the three maximal sublists of increasing digits, namely

```<code>28
46
145
</code>```

All sum to 10. Additionally, numbers that just repeat the same digit must be Dennis 2.0 numbers because, for example, 777 can be broken down into

```<code>7
7
7
</code>```

which clearly all sum to seven.

A number such as 42 is not a Dennis 2.0 number, since it is broken down into

```<code>4
2
</code>```

which clearly do not sum to the same number.

The challenge

You must write a program or function to determine if a given number is a Dennis 2.0 number or not. You can take input and output in any reasonable input format, e.g. as a string, as a number, from a file, funtion arguments/return, from STDIN/STDOUT, etc. and then return a truthy value if this number is a Dennis 2.0 number, and a falsy value if it is not. For reference, here is every Dennis 2.0 number up to 1,000:

```<code>1
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
22
23
24
25
26
27
28
29
33
34
35
36
37
38
39
44
45
46
47
48
49
55
56
57
58
59
66
67
68
69
77
78
79
88
89
99
101
111
123
124
125
126
127
128
129
134
135
136
137
138
139
145
146
147
148
149
156
157
158
159
167
168
169
178
179
189
202
222
234
235
236
237
238
239
245
246
247
248
249
256
257
258
259
267
268
269
278
279
289
303
312
333
345
346
347
348
349
356
357
358
359
367
368
369
378
379
389
404
413
444
456
457
458
459
467
468
469
478
479
489
505
514
523
555
567
568
569
578
579
589
606
615
624
666
678
679
689
707
716
725
734
777
789
808
817
826
835
888
909
918
927
936
945
999
</code>```

Standard loopholes apply, and the shortest answer measured in bytes wins!

Body:
JavaScript (ES6), 58

s=>![...s,z=x=p=0].some(c=>[c>p?0:z-=(x=x||z),z-=p=c][0])

Applying my rarely useful tip https://codegolf.stackexchange.com/a/49967/21348

It scans the string char by char identifying run of ascending chars, at the end of each rum it checks if the sum is always the same

c : current char

p : previous char

z : running sum, at the end of a run will be compared to ...

x : sum to compare against, at first run is simply made equal to z

Test

f=
s=>![...s,z=x=p=0].some(c=>[c>p?0:z-=(x=x||z),z-=p=c][0])

function run()
{
  var i=I.value
  O.textContent = i + ' -> ' + f(i)
}

run()

test=`1 2 3 4 5 6 7 8 9 11 12 13 14 15 16 17 18 19 22 23 24 25 26 27 28 29 33 34 35 36 37 38 39 44 45 46 47 48 49 55 56 57 58 59 66 67 68 69 77 78 79 88 89 99 101 111 123 124 125 126 127 128 129 134 135 136 137 138 139 145 146 147 148 149 156 157 158 159 167 168 169 178 179 189 202 222 234 235 236 237 238 239 245 246 247 248 249 256 257 258 259 267 268 269 278 279 289 303 312 333 345 346 347 348 349 356 357 358 359 367 368 369 378 379 389 404 413 444 456 457 458 459 467 468 469 478 479 489 505 514 523 555 567 568 569 578 579 589 606 615 624 666 678 679 689 707 716 725 734 777 789 808 817 826 835 888 909 918 927 936 945 999`.split` `

numerr=0
for(i=1; i<1000; i++)
{
  v = i + '';
  r = f(v);
  ok = r == (test.indexOf(v) >= 0)
  if (!ok) console.log('Error',++numerr, v)
}
if(!numerr) console.log('All test 1..999 ok')

<input id=I value=612324 type=number oninput='run()'>
<pre id=O>


答:
Retina, 25 bytes

```<code>^(10*10*)*
$1:
1:
0
.?:
1
</code>```

I feel sure there should be a better way of doing this...

Title: Incrementing Gray Codes

Body:
Retina, 25 bytes

^(10*10*)*
$1:
1:
0
.?:
1

I feel sure there should be a better way of doing this...


问:
The Letter A without A
Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of printing) is allowed.

Both the lowercase and uppercase versions of the letter "A" are acceptable (that is, unicode U+0061 or unicode U+0041. Other character encodings that aren't Unicode are allowed, but either way, the resulting output of your code must be the latin letter "A", and not any lookalikes or homoglyphs)

You must not use any of the below characters in your code, regardless of the character encoding that you pick:

"A", whether uppercase or lowercase.

"U", whether lowercase or uppercase.

X, whether uppercase or lowercase.

+

&

#

0

1

4

5

6

7

9

Cheating, loopholes, etc, are not allowed.

Since this is code-golf, the shortest solution, in bytes, that follows all the rules, is the winner.

Validity Checker

This Stack Snippet checks to make sure your code doesn't use the restricted characters. It might not work properly for some character encodings.

var t = prompt("Input your code.");

if (/[AaUuXx+&#0145679]/.test(t)) {
  alert("Contains a disallowed character!");
} else {
  alert("No disallowed characters");
}```
</div>
</div>
</p>

<p><em>This Stack Snippet that makes sure you don't have a disallowed character is also available on JSFiddle.</em></p>

<h3>Leaderboard</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var QUESTION_ID=90349,OVERRIDE_USER=58717;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="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});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;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>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;</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}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table></code>```

答:
QBasic, 17 bytes

```<code>PRINT CHR$(88-23)
</code>```

Exploits the fact that the function which converts an integer to char is named CHR.

Title: The Letter A without A

Body:
QBasic, 17 bytes

PRINT CHR$(88-23)

Exploits the fact that the function which converts an integer to char is named CHR.


问:
Now I know my ABCs, won't you come and golf with me?
Write a program or function that outputs this exact text, case-insensitive:

```<code>A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.
</code>```

(Based on the alphabet song that many American kids learn to help memorize the alphabet, though edited for more compressibility.)

The output must look exactly the same as the above (again, case-insensitive), but may contain trailing spaces on each line and/or trailing newlines. Notice the period at the end.

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

Body:
><>, 52 bytes

79334"A"\
or:?!~r&>:o1+:}&a" ,.["{=:}?$~o{?;{1-:}?$~

Try it online!


答:
PHP, <s>61</s> <s>58</s> <s>55</s> 50 bytes

Note: uses Windows 1252 encoding.

```<code>for($a=A;$a<Z;)echo"$a,",~ßõ[!trim($a++,GPSV)]?>Z.
</code>```

Run like this:

```<code>php -r 'for($a=A;$a<Z;)echo"$a,",~ßõ[!trim($a++,GPSV)]?>Z.' 2>/dev/null;echo
</code>```

If your terminal is set to UTF-8, this shows that it works:

```<code>php -r 'for($a=A;$a<Z;)echo"$a,"," \n"[!trim($a++,GPSV)]?>Z.' 2>/dev/null;echo
</code>```

Explanation

Iterates over the alphabet until Y is reached. Prints the letter with a comma, then prints a space, unless the letter is one of GPSV (found by !trim($a,"GPSV")). After the loop, print Z..

Tweaks

Saved 3 bytes by using strpos instead of char count

Saved 3 bytes by using trim instead of strpos

Saved 5 bytes by using the closing tag to print a literal Z. instead of echo

Title: Now I know my ABCs, won't you come and golf with me?

Body:
Write a program or function that outputs this exact text, case-insensitive:

```<code>A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.
</code>```

(Based on the alphabet song that many American kids learn to help memorize the alphabet, though edited for more compressibility.)

The output must look exactly the same as the above (again, case-insensitive), but may contain trailing spaces on each line and/or trailing newlines. Notice the period at the end.

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

Body:
PHP, <s>61</s> <s>58</s> <s>55</s> 50 bytes

Note: uses Windows 1252 encoding.

for($a=A;$a<Z;)echo"$a,",~ßõ[!trim($a++,GPSV)]?>Z.

Run like this:

php -r 'for($a=A;$a<Z;)echo"$a,",~ßõ[!trim($a++,GPSV)]?>Z.' 2>/dev/null;echo

If your terminal is set to UTF-8, this shows that it works:

php -r 'for($a=A;$a<Z;)echo"$a,"," \n"[!trim($a++,GPSV)]?>Z.' 2>/dev/null;echo

Explanation

Iterates over the alphabet until Y is reached. Prints the letter with a comma, then prints a space, unless the letter is one of GPSV (found by !trim($a,"GPSV")). After the loop, print Z..

Tweaks

Saved 3 bytes by using strpos instead of char count

Saved 3 bytes by using trim instead of strpos

Saved 5 bytes by using the closing tag to print a literal Z. instead of echo


答:
CJam (19 bytes)

```<code>{_2b__(^@1b1&*)^2b}
</code>```

Online demo. This is an anonymous block (function) from bit array to bit array, which the demo executes in a loop.

It works on the simple principle that if the number of set bits is even we should toggle the least significant bit, and otherwise we should toggle the bit to the left of the least significant set bit. Actually identifying that bit turns out to be much easier using bit hacks on an integer than using the list of bits.

Dissection

```<code>{         e# Declare a block:
  _2b     e#   Convert the bit array to a binary number
  __(^    e#   x ^ (x-1) gives 1s from the least significant set bit down
  @1b1&   e#   Get the parity of the number of set bits from the original array
  *       e#   Multiply: if we have an even number of set bits, we get 0;
          e#   otherwise we have 2**(lssb + 1) - 1
  )^      e#   Increment and xor by 1 or 2**(lssb + 1)
  2b      e#   Base convert back to a bit array
}
</code>```

Working solely with the bit array, I think it's necessary to reverse it: working with the left-most 1 is much easier than the right-most. The best I've found so far is (24 bytes):

```<code>{W%_1b)1&1$+1#0a*1+.^W%}
</code>```

Alternative approach (19 bytes)

```<code>{[{1$^}*]2b)_2/^2b}
</code>```

This converts from Gray code to index, increments, and converts back to Gray code.

Title: Incrementing Gray Codes

Body:
CJam (19 bytes)

{_2b__(^@1b1&*)^2b}

Online demo. This is an anonymous block (function) from bit array to bit array, which the demo executes in a loop.

It works on the simple principle that if the number of set bits is even we should toggle the least significant bit, and otherwise we should toggle the bit to the left of the least significant set bit. Actually identifying that bit turns out to be much easier using bit hacks on an integer than using the list of bits.

Dissection

{         e# Declare a block:
  _2b     e#   Convert the bit array to a binary number
  __(^    e#   x ^ (x-1) gives 1s from the least significant set bit down
  @1b1&   e#   Get the parity of the number of set bits from the original array
  *       e#   Multiply: if we have an even number of set bits, we get 0;
          e#   otherwise we have 2**(lssb + 1) - 1
  )^      e#   Increment and xor by 1 or 2**(lssb + 1)
  2b      e#   Base convert back to a bit array
}

Working solely with the bit array, I think it's necessary to reverse it: working with the left-most 1 is much easier than the right-most. The best I've found so far is (24 bytes):

{W%_1b)1&1$+1#0a*1+.^W%}

Alternative approach (19 bytes)

{[{1$^}*]2b)_2/^2b}

This converts from Gray code to index, increments, and converts back to Gray code.


问:
Greatest Common Divisor
Your task is to compute the greatest common divisor (GCD) of two given integers in as few bytes of code as possible.

You may write a program or function, taking input and returning output via any of our accepted standard methods (including STDIN/STDOUT, function parameters/return values, command-line arguments, etc.).

Input will be two non-negative integers. You should be able to handle either the full range supported by your language's default integer type, or the range [0,255], whichever is greater. You are guaranteed that at least one of the inputs will be non-zero.

You are not allowed to use built-ins that compute either the GCD or the LCM (least common multiple).

Standard code-golf rules apply.

Test Cases

```<code>0 2     => 2
6 0     => 6
30 42   => 6
15 14   => 1
7 7     => 7
69 25   => 1
21 12   => 3
169 123 => 1
20 142  => 2
101 202 => 101
</code>```

答:
Logy, <s>64</s> 23 bytes

```<code>f[X,Y]->Y<1&X|f[Y,X%Y];
</code>```

Ungolfed:

```<code>gcd[X, Y] -> Y < 1 & X | gcd[Y, X%Y];
</code>```

EDIT: Removed way too many bytes because there is no need for a full program

Title: Greatest Common Divisor

Body:
Logy, <s>64</s> 23 bytes

f[X,Y]->Y<1&X|f[Y,X%Y];

Ungolfed:

gcd[X, Y] -> Y < 1 & X | gcd[Y, X%Y];

EDIT: Removed way too many bytes because there is no need for a full program

ContentLicense: CC BY-SA 4.0


答:
Python 2, 69 bytes

Takes input as a string.

lambda I:len(set(eval(reduce(lambda x,y:x+',+'[y>x[-1]]+y,I+' '))))<2
```

Explanation:

ex 1201212012

Converts to list of sums:

1+2,0+1+2,1+2,0+1+2,

Evals and converts to set.

set([3])

If the length of the set is 1, all sums are the same.

Title: Dennis numbers 2.0

Body:
Python 2, 69 bytes

Takes input as a string.

lambda I:len(set(eval(reduce(lambda x,y:x+',+'[y>x[-1]]+y,I+' '))))<2

Explanation:

ex 1201212012

Converts to list of sums:

1+2,0+1+2,1+2,0+1+2,

Evals and converts to set.

set([3])

If the length of the set is 1, all sums are the same.


问:
Compute minimax of an array
Consider an array x such as [1 5 3 4] and a number n, for example 2. Write all length-n sliding subarrays: [1 5], [5 3], [3 4]. Let the minimax of the array be defined as the minimum of the maxima of the sliding blocks. So in this case it would be the minimum of 5, 5, 4, which is 4.

Challenge

Given an array x and a positive integer n, output the minimax as defined above.

The array x will only contain positive integers. n will always be at least 1 and at most the length of x.

Computation may be done by any procedure, not necessarily as defined above.

Code golf, fewest bytes wins.

Test cases

x, n, result

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

答:
Java 8, <s>128</s> <s>126</s> <s>124</s> 105 bytes

a->n->{int r=0,m,j,t,i=-1;for(;i++<a.length-n;r=r<1|m<r?m:r)for(m=j=0;j<n;m=t>m?t:m)t=a[i+j++];return r;}
```
<p>Try it online.</p>
<p><strong>Explanation:</strong></p>
<pre class="lang-java prettyprint-override"><code>a->n->{                    // Method with Integer-array & Integer as parameters
                           // and Integer return-type
  int r=0,                 //  Result-integer, starting at 0
      m,                   //  Max-integer, uninitialized
      j,t,                 //  Temp integers
  i=-1;for(;i++<a.length-n //  Loop `i` in the range (-1,length-n]:
           ;               //    After every iteration:
            r=             //     Change the result to:
              r<1          //      If the result is 0 (first iteration),
              |m<r?        //      or the max is smaller than the result:
                m          //       Change the result to this max
              :            //      Else:
               r)          //       Keep it unchanged
    for(m=                 //   Reset the max to 0
        j=0;j<n            //   Inner loop `j` in the range [0,n):
        ;                  //     After every iteration:
         m=t>m?t:m)        //      Set `m` to the max of `m` and `t`
      t=a[i+j++];          //    Set `t` to the `i+j`'th item of the array
  return r;}               //  After the nested loops, return the result
</code>```

Title: Compute minimax of an array

Body:
Java 8, <s>128</s> <s>126</s> <s>124</s> 105 bytes

a->n->{int r=0,m,j,t,i=-1;for(;i++<a.length-n;r=r<1|m<r?m:r)for(m=j=0;j<n;m=t>m?t:m)t=a[i+j++];return r;}

Try it online.

Explanation:

a->n->{                    // Method with Integer-array & Integer as parameters
                           // and Integer return-type
  int r=0,                 //  Result-integer, starting at 0
      m,                   //  Max-integer, uninitialized
      j,t,                 //  Temp integers
  i=-1;for(;i++<a.length-n //  Loop `i` in the range (-1,length-n]:
           ;               //    After every iteration:
            r=             //     Change the result to:
              r<1          //      If the result is 0 (first iteration),
              |m<r?        //      or the max is smaller than the result:
                m          //       Change the result to this max
              :            //      Else:
               r)          //       Keep it unchanged
    for(m=                 //   Reset the max to 0
        j=0;j<n            //   Inner loop `j` in the range [0,n):
        ;                  //     After every iteration:
         m=t>m?t:m)        //      Set `m` to the max of `m` and `t`
      t=a[i+j++];          //    Set `t` to the `i+j`'th item of the array
  return r;}               //  After the nested loops, return the result


Title: Natural construction

Body:
GAP, 22 bytes

f:=n->Set([0..n-1],f);

For example:

gap> f(3);
[ [  ], [ [  ] ], [ [  ], [ [  ] ] ] ]


问:
Yes, of course I'm an adult!
I think we've all done this as a kid: some websites require a minimum age of 18, so we just subtract a few years from the year of birth and voilà, we 'are' 18+.

In addition, for most rides at amusement parks the minimum height to enter is 1.40 meters (here in The Netherlands it as at least). Of course this can be cheated less easily than age, but you could wear shoes with thick heels, put your hair up, wear a hat, stand on your toes, etc.

Input:

Your program/function accepts a positive integer or decimal.

Output:

Is the input an integer >= 18? Simply print the input.

Is the input an integer 0-17? Print 18.

Is the input a decimal >= 1.4? Simply print the input.

Is the input a decimal 0.0-1.4? Print 1.4.

Challenge rules:

Assume the input will always be in the range of 0-122 (oldest woman ever was 122) or 0.0-2.72 (tallest man ever was 2.72).

You are allowed to take the input as a String, object, or anything else you prefer.

The decimal inputs will never have more than three decimal places after the decimal point.

2 or 2. both aren't valid outputs for 2.0. You are free to output 2.00 or 2.000 instead of 2.0 however.

Just like the input the output will never have more than three decimal places after the point.

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>0      ->  18
1      ->  18
2      ->  18
12     ->  18
18     ->  18
43     ->  43
115    ->  115
122    ->  122

0.0    ->  1.4
1.04   ->  1.4
1.225  ->  1.4
1.399  ->  1.4
1.4    ->  1.4
1.74   ->  1.74
2.0    ->  2.0
2.72   ->  2.72
</code>```

答:
Convex, 9 bytes

```<code>_1ÛI1.4?»
</code>```

Try it online!

Title: Yes, of course I'm an adult!

Body:
Convex, 9 bytes

_1ÛI1.4?»

Try it online!


问:
Showcase of Languages

Notes

This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional showcase questions.

This is no longer a popularity-contest, nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

All answers should include the name of the programming language at the top of the post, prefixed by a #.

Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

The snippets do not need to be related. In fact, snippets that are too related may be redundant.

Since this is not a contest, all programming languages are welcome, whenever they were created.

Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('
' + temp.innerText || temp.textContent + '');}}})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul></code>```

答:
Logy

Logy is a logic, imperative and functional programming language.

0 bytes

A program without the main rule do nothing.

1 byte

```<code>#
</code>```

Start a line comment

2 bytes

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

The rule definition operator

Title: Showcase of Languages

Body:
Logy

Logy is a logic, imperative and functional programming language.

0 bytes

A program without the main rule do nothing.

1 byte

#

Start a line comment

2 bytes

->

The rule definition operator


问:
Find the intersection point of a plane and ray
Given a ray with a point and a vector and a plane with a point and a normal vector to the plane. You have to find the intersection point of the plane and the ray..

So your job if you choose to accept is to write a shortest function that will do the job.

```<code>RULES:
The submission must be a complete program
And that's all

INPUT FORMAT:
x y z rx ry rz //gives the ray point and the ray vectors
x y z px py pz //gives the point on the plane and the vector normal to plane

OUTPUT FORMAT:
(x,y,z) //intersection point

Test Case:
2 3 4 0.577 0.577 0.577
7 1 3 1 0 0
(7,8,9)
</code>```

The shortest codes in bytes win.

References: https://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm  thanks orlp for the reference

答:
Perl, 107 bytes

Tested for all test cases (i.e. not tested at all)
Run with each input number on its own line on STDIN

```<code>perl -M5.010 plane.pl
0
1
0
0
0
1
3
3
1
0
0
1
^D
</code>```

plane.pl:

```<code>#!/usr/bin/perl
$$_=<>for a..l;say$a+($t=($j*($g-$a)+$k*($h-$b)+$l*($i-$c))/($j*$d+$k*$e+$l*$f))*$d,$",$b+$t*$e,$",$c+$t*$f
</code>```

This kind of problem is absolutely not a good match for perlgolf. Perl lacks vector operations and uses too many $s

Body:
Perl, 107 bytes

Tested for all test cases (i.e. not tested at all)
Run with each input number on its own line on STDIN

perl -M5.010 plane.pl
0
1
0
0
0
1
3
3
1
0
0
1
^D

plane.pl:

#!/usr/bin/perl
$$_=<>for a..l;say$a+($t=($j*($g-$a)+$k*($h-$b)+$l*($i-$c))/($j*$d+$k*$e+$l*$f))*$d,$",$b+$t*$e,$",$c+$t*$f

This kind of problem is absolutely not a good match for perlgolf. Perl lacks vector operations and uses too many $s


问:
Natural Pi #0 - Rock

Goal

Create a program/function that takes an input N, check if N random pairs of integers are relatively prime, and returns sqrt(6 * N / #coprime).

TL;DR

These challenges are simulations of algorithms that only require nature and your brain (and maybe some re-usable resources) to approximate Pi. If you really need Pi during the zombie apocalypse, these methods don't waste ammo! There are eight more challenges to come. Checkout the sandbox post to make recommendations.

Simulation

What are we simulating? Well, the probability that two random integers are relatively prime (ie coprime or gcd==1) is 6/Pi/Pi, so a natural way to calculate Pi would be to scoop up two buckets (or handfuls) of rocks; count them; see if their gcd is 1; repeat. After doing this a <s>couple</s> lot of times, sqrt(6.0 * total / num_coprimes) will tend towards Pi. If calculating the square-root in post-apocalyptic world makes you nervous, don't worry! There is Newton's Method for that.

How are we simulating this?

Take input N

Do the following N times:

Uniformly generate random positive integers, i and j

With 1 <= i , j <= 10^6

If gcd(i , j) == 1: result = 1

Else: result = 0

Take the sum of the N results, S

Return sqrt(6 * N / S)

Specification

Input

Flexible, take input in any of the standard ways (eg function parameter,STDIN) and in any standard format (eg String, Binary)

Output

Flexible, give output in any of the standard ways (eg return, print)

White space, trailing and leading white space is acceptable

Accuracy, please provide at least 4 decimal places of accuracy (ie 3.1416)

Scoring

Shortest code wins!

Test Cases

Your output may not line up with these, because of random chance. But on average, you should get about this much accuracy for the given value of N.

```<code>Input     ->  Output
-----         ------
100       ->  3.????
10000     ->  3.1???
1000000   ->  3.14??
</code>```

答:
Actually, 19 bytes

```<code>`6╤;Ju@Ju┤`nkΣß6*/√
</code>```

Try it online!

Explanation:

```<code>`6╤;Ju@Ju┤`nkΣß6*/√
`6╤;Ju@Ju┤`n         do this N times:
 6╤;                   two copies of 10**6
    Ju                 random integer in [0, 10**6), increment
      @Ju              another random integer in [0, 10**6), increment
         ┤             1 if coprime else 0
            kΣ       sum the results
              ß      first input again
               6*    multiply by 6
                 /   divide by sum
                  √  square root
</code>```

Title: Natural Pi #0 - Rock

Body:
Actually, 19 bytes

`6╤;Ju@Ju┤`nkΣß6*/√

Try it online!

Explanation:

`6╤;Ju@Ju┤`nkΣß6*/√
`6╤;Ju@Ju┤`n         do this N times:
 6╤;                   two copies of 10**6
    Ju                 random integer in [0, 10**6), increment
      @Ju              another random integer in [0, 10**6), increment
         ┤             1 if coprime else 0
            kΣ       sum the results
              ß      first input again
               6*    multiply by 6
                 /   divide by sum
                  √  square root


答:
MATL, 22 bytes

```<code>1e6Hi3$YrZ}Zd1=Ym6w/X^
</code>```

Try it online!

```<code>1e6      % Push 1e6
H        % Push 2
i        % Push input, N
3$Yr     % 2×N matrix of uniformly random integer values between 1 and 1e6
Z}       % Split into its two rows. Gives two 1×N arrays
Zd       % GCD, element-wise. Gives a 1×N array
1=       % Compare each entry with 1. Sets 1 to 0, and other values to 0
Ym       % Mean of the array
6w/      % 6 divided by that
X^       % Square root. Implicitly display
</code>```

Title: Natural Pi #0 - Rock

Body:
Goal

Create a program/function that takes an input N, check if N random pairs of integers are relatively prime, and returns sqrt(6 * N / #coprime).

TL;DR

These challenges are simulations of algorithms that only require nature and your brain (and maybe some re-usable resources) to approximate Pi. If you really need Pi during the zombie apocalypse, these methods don't waste ammo! There are eight more challenges to come. Checkout the sandbox post to make recommendations.

Simulation

What are we simulating? Well, the probability that two random integers are relatively prime (ie coprime or gcd==1) is 6/Pi/Pi, so a natural way to calculate Pi would be to scoop up two buckets (or handfuls) of rocks; count them; see if their gcd is 1; repeat. After doing this a <s>couple</s> lot of times, sqrt(6.0 * total / num_coprimes) will tend towards Pi. If calculating the square-root in post-apocalyptic world makes you nervous, don't worry! There is Newton's Method for that.

How are we simulating this?

Take input N

Do the following N times:

Uniformly generate random positive integers, i and j

With 1 <= i , j <= 10^6

If gcd(i , j) == 1: result = 1

Else: result = 0

Take the sum of the N results, S

Return sqrt(6 * N / S)

Specification

Input

Flexible, take input in any of the standard ways (eg function parameter,STDIN) and in any standard format (eg String, Binary)

Output

Flexible, give output in any of the standard ways (eg return, print)

White space, trailing and leading white space is acceptable

Accuracy, please provide at least 4 decimal places of accuracy (ie 3.1416)

Scoring

Shortest code wins!

Test Cases

Your output may not line up with these, because of random chance. But on average, you should get about this much accuracy for the given value of N.

```<code>Input     ->  Output
-----         ------
100       ->  3.????
10000     ->  3.1???
1000000   ->  3.14??
</code>```

Body:
MATL, 22 bytes

1e6Hi3$YrZ}Zd1=Ym6w/X^

Try it online!

1e6      % Push 1e6
H        % Push 2
i        % Push input, N
3$Yr     % 2×N matrix of uniformly random integer values between 1 and 1e6
Z}       % Split into its two rows. Gives two 1×N arrays
Zd       % GCD, element-wise. Gives a 1×N array
1=       % Compare each entry with 1. Sets 1 to 0, and other values to 0
Ym       % Mean of the array
6w/      % 6 divided by that
X^       % Square root. Implicitly display


答:
Mathematica, 20 bytes

Takes 4 lists as input. The dot product operator . has precedence over multiplication and division, so no more parentheses are needed.

```<code>#+#2(#3-#).#4/#2.#4&
</code>```

Readable version:

```<code>x + v (r - x).n / v.n
</code>```

where the arguments in order are x (ray point), v (ray direction), r (plane point), n (plane normal).

Title: Find the intersection point of a plane and ray

Body:
Given a ray with a point and a vector and a plane with a point and a normal vector to the plane. You have to find the intersection point of the plane and the ray..

So your job if you choose to accept is to write a shortest function that will do the job.

```<code>RULES:
The submission must be a complete program
And that's all

INPUT FORMAT:
x y z rx ry rz //gives the ray point and the ray vectors
x y z px py pz //gives the point on the plane and the vector normal to plane

OUTPUT FORMAT:
(x,y,z) //intersection point

Test Case:
2 3 4 0.577 0.577 0.577
7 1 3 1 0 0
(7,8,9)
</code>```

The shortest codes in bytes win.

References: https://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm  thanks orlp for the reference

Body:
Mathematica, 20 bytes

Takes 4 lists as input. The dot product operator . has precedence over multiplication and division, so no more parentheses are needed.

#+#2(#3-#).#4/#2.#4&

Readable version:

x + v (r - x).n / v.n

where the arguments in order are x (ray point), v (ray direction), r (plane point), n (plane normal).


答:
APL, 23 bytes

```<code>{.5*⍨6×⍵÷1+.=∨/?⍵2⍴1e6}
</code>```

Explanation:

?⍵2⍴1e6: generate a 2-by-⍵ matrix of random numbers in the range [1..106]

1+.=∨/: get the GCD of each pair and see how many are equal to 1. This calculates S.

.5*⍨6×⍵÷: (6 × ⍵ ÷ S)0.5

Title: Natural Pi #0 - Rock

Body:
APL, 23 bytes

{.5*⍨6×⍵÷1+.=∨/?⍵2⍴1e6}

Explanation:

?⍵2⍴1e6: generate a 2-by-⍵ matrix of random numbers in the range [1..106]

1+.=∨/: get the GCD of each pair and see how many are equal to 1. This calculates S.

.5*⍨6×⍵÷: (6 × ⍵ ÷ S)0.5


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

答:
Logy, 47 bytes

```<code>f[X]->include["@stdlib.logy"]~product[..[2,X]];
</code>```

Trivial. Return the product of the range [2..n]

Title: Find the Factorial!

Body:
Logy, 47 bytes

f[X]->include["@stdlib.logy"]~product[..[2,X]];

Trivial. Return the product of the range [2..n]


答:
Scala, <s>149</s> 126 bytes

```<code>val& =BigInt
def f(n: Int)={math.sqrt(6f*n/Seq.fill(n){val i,j=(math.random*99999+1).toInt
if(&(i).gcd(&(j))>1)0 else 1}.sum)}
</code>```

Explanation:

```<code>val& =BigInt                //define & as an alias to the object BigInt, because it has a gcd method
def f(n:Int)={              //define a method
  math.sqrt(                //take the sqrt of...
    6f * n /                //6 * n (6f is a floating-point literal to prevent integer division)
    Seq.fill(n){            //Build a sequence with n elements, where each element is..
      val i,j=(math.random*99999+1).toInt //take 2 random integers
      if(&(i).gcd(&(j))>1)0 else 1        //put 0 or 1 in the list by calling
                                          //the apply method of & to convert the numbers to
                                          //BigInt and calling its bcd method
    }.sum                   //calculate the sum
  )
}
</code>```

Title: Natural Pi #0 - Rock

Body:
Scala, <s>149</s> 126 bytes

val& =BigInt
def f(n: Int)={math.sqrt(6f*n/Seq.fill(n){val i,j=(math.random*99999+1).toInt
if(&(i).gcd(&(j))>1)0 else 1}.sum)}

Explanation:

val& =BigInt                //define & as an alias to the object BigInt, because it has a gcd method
def f(n:Int)={              //define a method
  math.sqrt(                //take the sqrt of...
    6f * n /                //6 * n (6f is a floating-point literal to prevent integer division)
    Seq.fill(n){            //Build a sequence with n elements, where each element is..
      val i,j=(math.random*99999+1).toInt //take 2 random integers
      if(&(i).gcd(&(j))>1)0 else 1        //put 0 or 1 in the list by calling
                                          //the apply method of & to convert the numbers to
                                          //BigInt and calling its bcd method
    }.sum                   //calculate the sum
  )
}


答:
JavaScript (ES7), <s>107</s> <s>95</s> 94 bytes

```<code>n=>(n*6/(r=_=>Math.random()*1e6+1|0,g=(a,b)=>b?g(b,a%b):a<2,q=n=>n&&g(r(),r())+q(n-1))(n))**.5
</code>```

The ES6 version is exactly 99 bytes, but the ES7 exponentiation operator ** saves 5 bytes over Math.sqrt.

Ungolfed

```<code>function pi(n) {
  function random() {
    return Math.floor(Math.random() * 1e6) + 1;
  }
  function gcd(a, b) {
    if (b == 0)
      return a;
    return gcd(b, a % b);
  }
  function q(n) {
    if (n == 0)
      return 0;
    return (gcd(random(), random()) == 1 ? 1 : 0) + q(n - 1));
  }
  return Math.sqrt(n * 6 / q(n));
}
</code>```

Title: Natural Pi #0 - Rock

Body:
JavaScript (ES7), <s>107</s> <s>95</s> 94 bytes

n=>(n*6/(r=_=>Math.random()*1e6+1|0,g=(a,b)=>b?g(b,a%b):a<2,q=n=>n&&g(r(),r())+q(n-1))(n))**.5

The ES6 version is exactly 99 bytes, but the ES7 exponentiation operator ** saves 5 bytes over Math.sqrt.

Ungolfed

function pi(n) {
  function random() {
    return Math.floor(Math.random() * 1e6) + 1;
  }
  function gcd(a, b) {
    if (b == 0)
      return a;
    return gcd(b, a % b);
  }
  function q(n) {
    if (n == 0)
      return 0;
    return (gcd(random(), random()) == 1 ? 1 : 0) + q(n - 1));
  }
  return Math.sqrt(n * 6 / q(n));
}


答:
APL, 23 bytes

```<code>{1=≢∪+/↑N⊂⍨1,2>/N←⍎¨⍕⍵}
</code>```

Explanation:

N←⍎¨⍕⍵: get the individual digits in the input, store in N

N⊂⍨1,2>/N: find the sublists of strictly increasing numbers in N

+/↑: sum each sublist

1=≢∪: see if the resulting list has only one unique element

Title: Dennis numbers 2.0

Body:
PPCG user and elected mod, @Dennis just became the second ever user to earn over 100k rep!

This is a totally original idea, that I did not get from anybody else, but let's make a challenge based off of his user ID, 12012 as a tribute!

Looking at it, you'll notice that there are two distinct "sections" to his ID.

12

and

012

Both of these sections add up to a 3. That's a pretty interesting property.

Let's define a "Dennis 2.0 number" as any positive integer where every maximal subsequence of strictly increasing digits sums to the same number. For example,

```<code>123
</code>```

is a Dennis 2.0 number because there is only one maximal sublist of strictly increasing digits, and it sums to 6. Additionally, 2,846,145 is also a Dennis 2.0 number because the three maximal sublists of increasing digits, namely

```<code>28
46
145
</code>```

All sum to 10. Additionally, numbers that just repeat the same digit must be Dennis 2.0 numbers because, for example, 777 can be broken down into

```<code>7
7
7
</code>```

which clearly all sum to seven.

A number such as 42 is not a Dennis 2.0 number, since it is broken down into

```<code>4
2
</code>```

which clearly do not sum to the same number.

The challenge

You must write a program or function to determine if a given number is a Dennis 2.0 number or not. You can take input and output in any reasonable input format, e.g. as a string, as a number, from a file, funtion arguments/return, from STDIN/STDOUT, etc. and then return a truthy value if this number is a Dennis 2.0 number, and a falsy value if it is not. For reference, here is every Dennis 2.0 number up to 1,000:

```<code>1
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
22
23
24
25
26
27
28
29
33
34
35
36
37
38
39
44
45
46
47
48
49
55
56
57
58
59
66
67
68
69
77
78
79
88
89
99
101
111
123
124
125
126
127
128
129
134
135
136
137
138
139
145
146
147
148
149
156
157
158
159
167
168
169
178
179
189
202
222
234
235
236
237
238
239
245
246
247
248
249
256
257
258
259
267
268
269
278
279
289
303
312
333
345
346
347
348
349
356
357
358
359
367
368
369
378
379
389
404
413
444
456
457
458
459
467
468
469
478
479
489
505
514
523
555
567
568
569
578
579
589
606
615
624
666
678
679
689
707
716
725
734
777
789
808
817
826
835
888
909
918
927
936
945
999
</code>```

Standard loopholes apply, and the shortest answer measured in bytes wins!

Body:
APL, 23 bytes

{1=≢∪+/↑N⊂⍨1,2>/N←⍎¨⍕⍵}

Explanation:

N←⍎¨⍕⍵: get the individual digits in the input, store in N

N⊂⍨1,2>/N: find the sublists of strictly increasing numbers in N

+/↑: sum each sublist

1=≢∪: see if the resulting list has only one unique element


答:
Python 2, <s>143</s> <s>140</s> <s>132</s> <s>124</s> <s>122</s> <s>124</s> 122 bytes

It has been quite some time since I have tried golfing, so I may have missed something here! Will be updating as I shorten this.

import random as r,fractions as f
n,s=input(),0
k=lambda:r.randrange(1e6)+1
exec's+=f.gcd(k(),k())<2;'*n
print(6.*n/s)**.5
```

Test me here!

thanks to Jonathan Allan for the two-byte save :)

Title: Natural Pi #0 - Rock

Body:
Python 2, <s>143</s> <s>140</s> <s>132</s> <s>124</s> <s>122</s> <s>124</s> 122 bytes

It has been quite some time since I have tried golfing, so I may have missed something here! Will be updating as I shorten this.

import random as r,fractions as f
n,s=input(),0
k=lambda:r.randrange(1e6)+1
exec's+=f.gcd(k(),k())<2;'*n
print(6.*n/s)**.5

Test me here!

thanks to Jonathan Allan for the two-byte save :)


答:
PHP, <s>82</s> <s>77</s> 74 bytes

```<code>for(;$i++<$argn;)$s+=2>gmp_gcd(rand(1,1e6),rand(1,1e6));echo(6*$i/$s)**.5;
</code>```

Run like this:

```<code>echo 10000 | php -R 'for(;$i++<$argn;)$s+=2>gmp_gcd(rand(1,1e6),rand(1,1e6));echo(6*$i/$s)**.5;' 2>/dev/null;echo
</code>```

Explanation

Does what it says on the tin. Requires PHP_GMP for gcd.

Tweaks

Saved 3 bytes by using $argn

Title: Natural Pi #0 - Rock

Body:
PHP, <s>82</s> <s>77</s> 74 bytes

for(;$i++<$argn;)$s+=2>gmp_gcd(rand(1,1e6),rand(1,1e6));echo(6*$i/$s)**.5;

Run like this:

echo 10000 | php -R 'for(;$i++<$argn;)$s+=2>gmp_gcd(rand(1,1e6),rand(1,1e6));echo(6*$i/$s)**.5;' 2>/dev/null;echo

Explanation

Does what it says on the tin. Requires PHP_GMP for gcd.

Tweaks

Saved 3 bytes by using $argn


答:
Pyth, 21 bytes

```<code>@*6cQ/iMcmhO^T6yQ2lN2
</code>```

Try it online.

Explanation

```<code>                Q          input number
               y           twice that
         m                 map numbers 0 to n-1:
             T                 10
            ^ 6                to the 6th power
           O                   random number from 0 to n-1
          h                    add one
        c        2         split into pairs
      iM                   gcd of each pair
     /            lN       count ones
   cQ                      divide input number by the result
 *6                        multiply by 6
@                   2      square root
</code>```

Title: Natural Pi #0 - Rock

Body:
Pyth, 21 bytes

@*6cQ/iMcmhO^T6yQ2lN2

Try it online.

Explanation

                Q          input number
               y           twice that
         m                 map numbers 0 to n-1:
             T                 10
            ^ 6                to the 6th power
           O                   random number from 0 to n-1
          h                    add one
        c        2         split into pairs
      iM                   gcd of each pair
     /            lN       count ones
   cQ                      divide input number by the result
 *6                        multiply by 6
@                   2      square root


答:
Racket 119 bytes

```<code>(λ(n)(define ll(list'()))(for((i(range 1 n)))(set! ll(cons ll(for/list((j(length ll)))(list-ref ll j)))))(reverse ll))
</code>```

Ungolfed:

```<code>(define f
  (λ (n)
    (define ll (list '()))
    (for ((i (range 1 n)))
      (set! ll
            (cons ll
                  (for/list ((j (length ll)))
                    (list-ref ll j)
                    ))))
    (reverse ll)))
</code>```

Testing (In Racket {} is same as () and default output is ()):

```<code>(f 4)

'(() (()) ((()) ()) (((()) ()) (()) ()))
</code>```

To clearly see each number (0 to 3):

```<code>(for((i (f 4)))  (println (reverse i)))

'()
'(())
'(() (()))
'(() (()) ((()) ()))
</code>```

Title: Natural construction

Body:
The natural numbers including 0 are formally defined as sets, in the following way:

Number 0 is defined as the empty set, {}

For n ≥ 0, number n+1 is defined as n ∪ {n}.

As a consequence, n = {0, 1, ..., n-1}.

The first numbers, defined by this procedure, are:

0 = {}

1 = {{}}

2 = {{}, {{}}}

3 = {{}, {{}}, {{}, {{}}}}

Challenge

Given n, output its representation as a set.

Rules

The output can consistently use any bracket character such as {}, [], () or <>. Arbitrary characters (such as 01) are not allowed.

Instead of a comma as above, the separator can be any punctuation sign; or it may be inexistent.

Spaces (not newlines) may be included arbitrarily and inconsistently.

For example, number 2 with square brackets and semicolon as separator is [[]; [[]]], or equivalently [ [ ]; [ [ ] ] ], or even [  [ ] ;[  []]]

The order in which elements of a set are specified doesn't matter. So you can use any order in the representation. For example, these are some valid outputs for 3:

```<code>{{},{{}},{{},{{}}}}
{{{}},{{},{{}}},{}}
{{{}},{{{}},{}},{}}
</code>```

You can write a program or function. Output may be a string or, if using a function, you may return a nested list or array whose string representation conforms to the above.

Test cases

```<code>0  ->  {}
1  ->  {{}}
2  ->  {{},{{}}}
3  ->  {{},{{}},{{},{{}}}}
4  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}
5  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}
6  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}}
7  ->  {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}}}
</code>```

Body:
Racket 119 bytes

(λ(n)(define ll(list'()))(for((i(range 1 n)))(set! ll(cons ll(for/list((j(length ll)))(list-ref ll j)))))(reverse ll))

Ungolfed:

(define f
  (λ (n)
    (define ll (list '()))
    (for ((i (range 1 n)))
      (set! ll
            (cons ll
                  (for/list ((j (length ll)))
                    (list-ref ll j)
                    ))))
    (reverse ll)))

Testing (In Racket {} is same as () and default output is ()):

(f 4)

'(() (()) ((()) ()) (((()) ()) (()) ()))

To clearly see each number (0 to 3):

(for((i (f 4)))  (println (reverse i)))

'()
'(())
'(() (()))
'(() (()) ((()) ()))


答:
Jelly, <s>20 18</s> 16 bytes

-2 bytes thanks to @Pietu1998 (chain & use count 1s, ċ1 in place of less than two summed <2S)

-2 bytes thanks to @Dennis (repeat 1e6 multiple times before sampling to avoid chaining)

```<code>Ḥȷ6xX€g2/ċ1÷³6÷½
</code>```

(Extremely slow due to the random function)

How?

```<code>Ḥȷ6xX€g2/ċ1÷³6÷½ - Main link: n
 ȷ6              - 1e6
   x             - repeat
Ḥ                -     double, 2n
    X€           - random integer in [1,1e6] for each
       2/        - pairwise reduce with
      g          -     gcd
         ċ1      - count 1s
           ÷     - divide
            ³    - first input, n
             6   - literal 6
              ÷  - divide
               ½ - square root
</code>```

TryItOnline

Title: Natural Pi #0 - Rock

Body:
Jelly, <s>20 18</s> 16 bytes

-2 bytes thanks to @Pietu1998 (chain & use count 1s, ċ1 in place of less than two summed <2S)

-2 bytes thanks to @Dennis (repeat 1e6 multiple times before sampling to avoid chaining)

Ḥȷ6xX€g2/ċ1÷³6÷½

(Extremely slow due to the random function)

How?

Ḥȷ6xX€g2/ċ1÷³6÷½ - Main link: n
 ȷ6              - 1e6
   x             - repeat
Ḥ                -     double, 2n
    X€           - random integer in [1,1e6] for each
       2/        - pairwise reduce with
      g          -     gcd
         ċ1      - count 1s
           ÷     - divide
            ³    - first input, n
             6   - literal 6
              ÷  - divide
               ½ - square root

TryItOnline


答:
Mathematica, <s>49</s> <s>48</s> 51 bytes

Saved one byte and fixed one bug thanks to @LegionMammal978.

```<code>(6#/Count[GCD@@{1,1*^6}~RandomInteger~{2,#},1])^.5&
</code>```

Title: Natural Pi #0 - Rock

Body:
Mathematica, <s>49</s> <s>48</s> 51 bytes

Saved one byte and fixed one bug thanks to @LegionMammal978.

(6#/Count[GCD@@{1,1*^6}~RandomInteger~{2,#},1])^.5&