答:
R, <s>97 88</s> 82 bytes

Hopefully I've understood this correctly.  Now to see if I can get rid of some more bytes. Ditched the rbind and put in an sapply and deal with 1-based vector properly.

Implemented as an unnamed function

```<code>function(Y)all(sapply(1:length(Y),function(X)Y[X]>=Y[X*2]&Y[X]>=Y[X*2+1]),na.rm=T)
</code>```

With a few of the test cases

```<code>> f=
+ function(Y)all(sapply(1:length(Y),function(X)Y[X]>=Y[X*2]&Y[X]>=Y[X*2+1]),na.rm=T)
> f(c(90, 15, 10, 7, 12, 2))
[1] TRUE
> f(c(93, 15, 87, 7, 15, 5))
[1] TRUE
> f(c(10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
[1] TRUE
> f(c(5, 5, 5, 5, 5, 5, 5, 5))
[1] TRUE
> f(c(4, 5, 5, 5, 5, 5, 5, 5))
[1] FALSE
> f(c(90, 15, 10, 7, 12, 11))
[1] FALSE
> f(c(4, 8, 15, 16, 23, 42))
[1] FALSE
</code>```

Title: Is it a max-heap?

Body:
A heap, also known as a priority-queue, is an abstract data type. Conceptually, it's a binary tree where the children of every node are smaller than or equal to the node itself. (Assuming it's a max-heap.) When an element is pushed or popped, the heap rearranges itself so the the biggest element is the next to be popped. It can easily be implemented as a tree or as an array.

Your challenge, should you choose to accept it, is to determine if an array is a valid heap. An array is in heap form if every element's children are smaller than or equal to the element itself. Take the following array as an example:

```<code>[90, 15, 10, 7, 12, 2]
</code>```

Really, this is a binary tree arranged in the form of an array. This is because every element has children. 90 has two children, 15 and 10.

```<code>       15, 10,
[(90),         7, 12, 2]
</code>```

15 also has children, 7 and 12:

```<code>               7, 12,
[90, (15), 10,        2]
</code>```

10 has children:

```<code>                      2
[90, 15, (10), 7, 12,  ]
</code>```

and the next element would also be a child of 10, except that there isn't room. 7, 12 and 2 would all also have children if the array was long enough. Here is another example of a heap:

```<code>[16, 14, 10, 8, 7, 9, 3, 2, 4, 1]
</code>```

And here is a visualization of the tree the previous array makes:

Just in case this isn't clear enough, here is the explicit formula to get the children of the i'th element

```<code>//0-indexing:
child1 = (i * 2) + 1
child2 = (i * 2) + 2

//1-indexing:
child1 = (i * 2)
child2 = (i * 2) + 1
</code>```

You must take an non-empty array as input and output a truthy value if the array is in heap order, and a falsy value otherwise. This can be a 0-indexed heap, or a 1-indexed heap as long as you specify which format your program/function expects. You may assume that all arrays will only contain positive integers. You may not use any heap-builtins. This includes, but is not limited to

Functions that determine if an array is in heap-form

Functions that convert an array into a heap or into heap-form

Functions that take an array as input and return a heap data-structure

You can use this python script to verify if an array is in heap-form or not (0 indexed):

```<code>def is_heap(l):
    for head in range(0, len(l)):
        c1, c2 = head * 2 + 1, head * 2 + 2
        if c1 < len(l) and l[head] < l[c1]:
            return False
        if c2 < len(l) and l[head] < l[c2]:
            return False

    return True
</code>```

Test IO:

All of these inputs should return True:

```<code>[90, 15, 10, 7, 12, 2]
[93, 15, 87, 7, 15, 5]
[16, 14, 10, 8, 7, 9, 3, 2, 4, 1]
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
[100, 19, 36, 17, 3, 25, 1, 2, 7]
[5, 5, 5, 5, 5, 5, 5, 5]
</code>```

And all of these inputs should return False:

```<code>[4, 5, 5, 5, 5, 5, 5, 5]
[90, 15, 10, 7, 12, 11]
[1, 2, 3, 4, 5]
[4, 8, 15, 16, 23, 42]
[2, 1, 3]
</code>```

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

Body:
R, <s>97 88</s> 82 bytes

Hopefully I've understood this correctly.  Now to see if I can get rid of some more bytes. Ditched the rbind and put in an sapply and deal with 1-based vector properly.

Implemented as an unnamed function

function(Y)all(sapply(1:length(Y),function(X)Y[X]>=Y[X*2]&Y[X]>=Y[X*2+1]),na.rm=T)

With a few of the test cases

> f=
+ function(Y)all(sapply(1:length(Y),function(X)Y[X]>=Y[X*2]&Y[X]>=Y[X*2+1]),na.rm=T)
> f(c(90, 15, 10, 7, 12, 2))
[1] TRUE
> f(c(93, 15, 87, 7, 15, 5))
[1] TRUE
> f(c(10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
[1] TRUE
> f(c(5, 5, 5, 5, 5, 5, 5, 5))
[1] TRUE
> f(c(4, 5, 5, 5, 5, 5, 5, 5))
[1] FALSE
> f(c(90, 15, 10, 7, 12, 11))
[1] FALSE
> f(c(4, 8, 15, 16, 23, 42))
[1] FALSE


问:
Is it a max-heap?
A heap, also known as a priority-queue, is an abstract data type. Conceptually, it's a binary tree where the children of every node are smaller than or equal to the node itself. (Assuming it's a max-heap.) When an element is pushed or popped, the heap rearranges itself so the the biggest element is the next to be popped. It can easily be implemented as a tree or as an array.

Your challenge, should you choose to accept it, is to determine if an array is a valid heap. An array is in heap form if every element's children are smaller than or equal to the element itself. Take the following array as an example:

```<code>[90, 15, 10, 7, 12, 2]
</code>```

Really, this is a binary tree arranged in the form of an array. This is because every element has children. 90 has two children, 15 and 10.

```<code>       15, 10,
[(90),         7, 12, 2]
</code>```

15 also has children, 7 and 12:

```<code>               7, 12,
[90, (15), 10,        2]
</code>```

10 has children:

```<code>                      2
[90, 15, (10), 7, 12,  ]
</code>```

and the next element would also be a child of 10, except that there isn't room. 7, 12 and 2 would all also have children if the array was long enough. Here is another example of a heap:

```<code>[16, 14, 10, 8, 7, 9, 3, 2, 4, 1]
</code>```

And here is a visualization of the tree the previous array makes:

Just in case this isn't clear enough, here is the explicit formula to get the children of the i'th element

```<code>//0-indexing:
child1 = (i * 2) + 1
child2 = (i * 2) + 2

//1-indexing:
child1 = (i * 2)
child2 = (i * 2) + 1
</code>```

You must take an non-empty array as input and output a truthy value if the array is in heap order, and a falsy value otherwise. This can be a 0-indexed heap, or a 1-indexed heap as long as you specify which format your program/function expects. You may assume that all arrays will only contain positive integers. You may not use any heap-builtins. This includes, but is not limited to

Functions that determine if an array is in heap-form

Functions that convert an array into a heap or into heap-form

Functions that take an array as input and return a heap data-structure

You can use this python script to verify if an array is in heap-form or not (0 indexed):

```<code>def is_heap(l):
    for head in range(0, len(l)):
        c1, c2 = head * 2 + 1, head * 2 + 2
        if c1 < len(l) and l[head] < l[c1]:
            return False
        if c2 < len(l) and l[head] < l[c2]:
            return False

    return True
</code>```

Test IO:

All of these inputs should return True:

```<code>[90, 15, 10, 7, 12, 2]
[93, 15, 87, 7, 15, 5]
[16, 14, 10, 8, 7, 9, 3, 2, 4, 1]
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
[100, 19, 36, 17, 3, 25, 1, 2, 7]
[5, 5, 5, 5, 5, 5, 5, 5]
</code>```

And all of these inputs should return False:

```<code>[4, 5, 5, 5, 5, 5, 5, 5]
[90, 15, 10, 7, 12, 11]
[1, 2, 3, 4, 5]
[4, 8, 15, 16, 23, 42]
[2, 1, 3]
</code>```

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

答:
CJam, 19 16 13 12 bytes

```<code>q~_:_\(;./:*
</code>```

Golfed off 3 bytes thanks to Dennis.

Try it here.

ContentLicense: CC BY-SA 3.0

Title: Is it a max-heap?

Body:
CJam, 19 16 13 12 bytes

q~_:_\(;./:*

Golfed off 3 bytes thanks to Dennis.

Try it here.


答:
MATL, <s>13</s> 12 bytes

```<code>ttf2/k)>~4L)
</code>```

Try it online! Or verify all test cases.

An array is truthy if it is non-empty and all its entries are nonzero. Otherwise it's falsy. Here are some examples.

Explanation

```<code>t     % Take input implicitly. Duplicate
tf    % Duplicate and push indices of nonzero entries. This gives [1 2 ... n] where n
      % is input size
2/k   % Divide by 2 and round down
)     % Index into input. Gives array of parents, except for the first entry
>~    % True for entries of the input that don't exceed those in the array of parents
4L)   % Discard first entry
</code>```

Title: Is it a max-heap?

Body:
MATL, <s>13</s> 12 bytes

ttf2/k)>~4L)

Try it online! Or verify all test cases.

An array is truthy if it is non-empty and all its entries are nonzero. Otherwise it's falsy. Here are some examples.

Explanation

t     % Take input implicitly. Duplicate
tf    % Duplicate and push indices of nonzero entries. This gives [1 2 ... n] where n
      % is input size
2/k   % Divide by 2 and round down
)     % Index into input. Gives array of parents, except for the first entry
>~    % True for entries of the input that don't exceed those in the array of parents
4L)   % Discard first entry


问:
Calculate Swatch Internet Time
Output the current time of day as Swatch Internet Time.

Specifically, output a three-digit (zero-padded) number of ".beats" (1000ths of a day) which represent the current time of day in the Swatch Internet Time time zone of UTC+01:00 ("Biel Meantime").

For example, if the current time in UTC is 23:47, then it is 00:47 in UTC+1 ("Biel Meantime"), and the output would be 032.

Examples:

```<code>UTC Current Time  ->  SIT Output
23:47             ->  032
23:00             ->  000
11:00             ->  500
14:37             ->  651
</code>```

The program should produce this output then immediately exit.

Output is to standard output (or equivalent). Must be a complete, runnable program, not a function. The program takes no input; it outputs the current time.

答:
PHP, 12 bytes

```<code><?=@date(B);
</code>```

But it can only be so short because PHP has built-in Swatch Internet Time support. So this answer isn't much fun.

<?= exits HTML mode and evaluates an expression, then echoes it.

@ silences an error.

date() outputs the current time, formatting it with a given format string.

B is an undefined constant. In PHP, if you reference a constant that doesn't exist, you get back a string containing its name, and it also produces a “notice”-level error. Here, the @ suppresses that error. B is the date() format code for Swatch Internet Time.

; terminates the expression.

If we assume PHP is being run with the default error-reporting settings, where “notices” are silenced, we could skip the @, and it would only be 11 bytes.

Title: Calculate Swatch Internet Time

Body:
PHP, 12 bytes

<?=@date(B);

But it can only be so short because PHP has built-in Swatch Internet Time support. So this answer isn't much fun.

<?= exits HTML mode and evaluates an expression, then echoes it.

@ silences an error.

date() outputs the current time, formatting it with a given format string.

B is an undefined constant. In PHP, if you reference a constant that doesn't exist, you get back a string containing its name, and it also produces a “notice”-level error. Here, the @ suppresses that error. B is the date() format code for Swatch Internet Time.

; terminates the expression.

If we assume PHP is being run with the default error-reporting settings, where “notices” are silenced, we could skip the @, and it would only be 11 bytes.


答:
Jelly, 11 9 5 bytes

```<code>x2:ḊṂ
</code>```

4 bytes removed thanks to Dennis!

Try it here.

Explanation

```<code>x2          Duplicate each element.
:Ḋ          Each element divided by the input with the first element removed,
            as integer, so there is a 0 only if some element in the duplicated
            list is less than the corresponding element in the other.
            There are also elements left unchanged, but it doesn't matter as
            the input is all positive.
Ṃ           Minimum in the list.
</code>```

Title: Is it a max-heap?

Body:
Jelly, 11 9 5 bytes

x2:ḊṂ

4 bytes removed thanks to Dennis!

Try it here.

Explanation

x2          Duplicate each element.
:Ḋ          Each element divided by the input with the first element removed,
            as integer, so there is a 0 only if some element in the duplicated
            list is less than the corresponding element in the other.
            There are also elements left unchanged, but it doesn't matter as
            the input is all positive.
Ṃ           Minimum in the list.


答:
J, 24 bytes

```<code>*/@:<:]{~0}:@,<.@-:@i.@#
</code>```

Explanation

```<code>*/@:<:]{~0}:@,<.@-:@i.@#  Input: s
                       #  Count of s
                    i.@   Create range [0, 1, ..., len(s)-1]
                 -:@      Halve each
              <.@         Floor each
         0   ,            Prepend a zero to it
          }:@             Remove the last value to get the parent indices of each
      ]                   Identity function to get s
       {~                 Take the values from s at the parent indices
    <:                    For each, 1 if it is less than or equal to its parent else 0
*/@:                      Reduce using multiplication and return
</code>```

Title: Is it a max-heap?

Body:
J, 24 bytes

*/@:<:]{~0}:@,<.@-:@i.@#

Explanation

*/@:<:]{~0}:@,<.@-:@i.@#  Input: s
                       #  Count of s
                    i.@   Create range [0, 1, ..., len(s)-1]
                 -:@      Halve each
              <.@         Floor each
         0   ,            Prepend a zero to it
          }:@             Remove the last value to get the parent indices of each
      ]                   Identity function to get s
       {~                 Take the values from s at the parent indices
    <:                    For each, 1 if it is less than or equal to its parent else 0
*/@:                      Reduce using multiplication and return


问:
m3ph1st0s's programming puzzle 1 (C++)
This is the first of a series of C++ puzzles for you. Hope you will enjoy.

So, puzzle no.1:

Given the following program:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

Insert some code on a single new line anywhere inside the program so that the output will be 0. The new line will contain AT MOST 18 characters (including spaces), and the rest of the lines will remain unmodified.
 To be clear, here is an example of a valid new code:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   int* p = NULL;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

A new line with 15 characters was inserted so it's ok. However it does not solve the problem.

If this is too simple for you, don't worry, more is coming!!

答:
```<code>#define int float
</code>```

should work as well and is the same length.

Title: m3ph1st0s's programming puzzle 1 (C++)

Body:
#define int float

should work as well and is the same length.


问:
Illustrate music beats
You know—they look like this:

source

The goal is to draw a music beats illustration like the following:

```<code>=     =      =
=  =  =      =          =
== = ==   =  ==     = ====
== ====  == ===   = = =======
======== == ====  = ========= =
=================================
</code>```

The rules are:

The width of the illustration is 33 symbols, but if you need—any trailing spaces exceeding this width are allowed.

Each column is made of equals signs (=).

Each column has a random height (the height of the next column shouldn’t depend in any way on the height of the previous column), varying from 1 to 6. It’s also fine if it’s at least possible to get some input with no strict math probability (i.e. some inputs could appear more rarely than others).

A column can’t float above the bottom and have gaps in it.

Since every column has the minimal height of 1, the last row can’t have any gaps either—it always consists of 33 equals signs.

Since it’s possible to have no columns with the height of 6 (it’s all random after all): in this case you don’t need to have a top line made of spaces. Applies to any edge cases of this nature: if suddenly your code provided no columns with the height greater than 1, you don’t need to have additional lines made of spaces above the bottom line.

You don’t take any input.

答:
C#, <s>200</s> 117 bytes

```<code>()=>{var s="";int x,y=6;for(;y-->0;){var r=new Random();for(x=33;x-->0;)s+="= "[r.Next(6)<y?1:0];s+='\n';}return s;};
</code>```

I move to @Lynn algorithm and save 83 bytes!

C# lambda without input and where output is a string. Try it online.

Code:

```<code>()=>{
    var s="";int x,y=6;
    for(;y-->0;){
        var r=new Random();
        for(x=33;x-->0;)
            s+="= "[r.Next(6)<y?1:0];
        s+='\n';
    }return s;
};
</code>```

Title: Illustrate music beats

Body:
C#, <s>200</s> 117 bytes

()=>{var s="";int x,y=6;for(;y-->0;){var r=new Random();for(x=33;x-->0;)s+="= "[r.Next(6)<y?1:0];s+='\n';}return s;};

I move to @Lynn algorithm and save 83 bytes!

C# lambda without input and where output is a string. Try it online.

Code:

()=>{
    var s="";int x,y=6;
    for(;y-->0;){
        var r=new Random();
        for(x=33;x-->0;)
            s+="= "[r.Next(6)<y?1:0];
        s+='\n';
    }return s;
};


问:
Print the ASCII printable character set
Challenge: Print the entire printable ASCII charset (not just a range!) in order.

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

Rules: read closely

No other characters allowed in the output.

Program/function does not accept input.

Try not to hardcode/embed the output.

This is code golf, shortest answer wins.

答:
CJam, 6 bytes

```<code>',32>
</code>```

The second byte is a DEL character. Try it online!

ContentLicense: CC BY-SA 4.0

Title: Print the ASCII printable character set

Body:
CJam, 6 bytes

',32>

The second byte is a DEL character. Try it online!


答:
Pyth, 5 bytes

```<code>srd\
</code>```

Try it here.

```<code> r         range from
  d        space
   \<del>  to the delete character, 0x7F (included literally in the program)
s          sum (concatenate all)
</code>```

Title: Print the ASCII printable character set

Body:
Challenge: Print the entire printable ASCII charset (not just a range!) in order.

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

Rules: read closely

No other characters allowed in the output.

Program/function does not accept input.

Try not to hardcode/embed the output.

This is code golf, shortest answer wins.

Body:
Pyth, 5 bytes

srd\

Try it here.

 r         range from
  d        space
   \<del>  to the delete character, 0x7F (included literally in the program)
s          sum (concatenate all)


答:
Cheddar, <s>68</s> 65 bytes (non-competing)

```<code>->(1:33).map(->IO.sprintf("%6s","="*Math.rand(1,7))).turn().vfuse
</code>```

O_O Cheddar is actually doing good! Uses sprintf and turn to do a bulk of the work. vfuse is vertical-fuse meaning it joins the array but vertically. This is very golfy but also rather fast. Version is prerelease v1.0.0-beta.10, which post-dates the challenge.

Explanation

```<code>->           // Anonymous function
  (1:33)     // Range 1-33 inclusive
  .map(->    // Loop through the above range
    IO.sprintf("%6s",       // `sprintf` from C/C++
      "="*Math.rand(1,7)    // Repeat `=` a random time from [1,7)
    )
  ).turn().vfuse     // Turn it 90deg, and fuse it vertically
</code>```

Some example runs:

Title: Illustrate music beats

Body:
You know—they look like this:

source

The goal is to draw a music beats illustration like the following:

```<code>=     =      =
=  =  =      =          =
== = ==   =  ==     = ====
== ====  == ===   = = =======
======== == ====  = ========= =
=================================
</code>```

The rules are:

The width of the illustration is 33 symbols, but if you need—any trailing spaces exceeding this width are allowed.

Each column is made of equals signs (=).

Each column has a random height (the height of the next column shouldn’t depend in any way on the height of the previous column), varying from 1 to 6. It’s also fine if it’s at least possible to get some input with no strict math probability (i.e. some inputs could appear more rarely than others).

A column can’t float above the bottom and have gaps in it.

Since every column has the minimal height of 1, the last row can’t have any gaps either—it always consists of 33 equals signs.

Since it’s possible to have no columns with the height of 6 (it’s all random after all): in this case you don’t need to have a top line made of spaces. Applies to any edge cases of this nature: if suddenly your code provided no columns with the height greater than 1, you don’t need to have additional lines made of spaces above the bottom line.

You don’t take any input.

Body:
Cheddar, <s>68</s> 65 bytes (non-competing)

->(1:33).map(->IO.sprintf("%6s","="*Math.rand(1,7))).turn().vfuse

O_O Cheddar is actually doing good! Uses sprintf and turn to do a bulk of the work. vfuse is vertical-fuse meaning it joins the array but vertically. This is very golfy but also rather fast. Version is prerelease v1.0.0-beta.10, which post-dates the challenge.

Explanation

->           // Anonymous function
  (1:33)     // Range 1-33 inclusive
  .map(->    // Loop through the above range
    IO.sprintf("%6s",       // `sprintf` from C/C++
      "="*Math.rand(1,7)    // Repeat `=` a random time from [1,7)
    )
  ).turn().vfuse     // Turn it 90deg, and fuse it vertically

Some example runs:


答:
Brainfuck, <s>40</s> 39 bytes

```<code>++++[->++++[->++>++++++<<]<]>>>-[-<.+>]
</code>```

Try it online.

Explanation

```<code>++++[->++++[->++>++++++<<]<]
</code>```

The nested loops basically mean you multiply the number of plusses together, so 4 × 4 × 2 = 32 in one cell and 4 × 4 × 6 = 96. Here is the tape after running this:

```<code>00 00 32 96
 ^
</code>```

>>>- moves the pointer to the fourth cell and decrements it. Now we're done with the setup. 32 is the code for space, the first printable ASCII character. 95 is the number of characters we have to print. Here is the tape now:

```<code>00 00 32 95
          ^
</code>```

[-<.+>] runs until the current cell (the fourth one) is zero. It decrements the counter and prints the character and increments it for the next time.

Title: Print the ASCII printable character set

Body:
Brainfuck, <s>40</s> 39 bytes

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

Try it online.

Explanation

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

The nested loops basically mean you multiply the number of plusses together, so 4 × 4 × 2 = 32 in one cell and 4 × 4 × 6 = 96. Here is the tape after running this:

00 00 32 96
 ^

>>>- moves the pointer to the fourth cell and decrements it. Now we're done with the setup. 32 is the code for space, the first printable ASCII character. 95 is the number of characters we have to print. Here is the tape now:

00 00 32 95
          ^

[-<.+>] runs until the current cell (the fourth one) is zero. It decrements the counter and prints the character and increments it for the next time.


答:
Python 2.7, 36 bytes:

```<code>print''.join(map(chr,range(32,127)))
</code>```

Simple enough. A full program that prints out the entire ASCII sequence in order.

Title: Print the ASCII printable character set

Body:
Python 2.7, 36 bytes:

print''.join(map(chr,range(32,127)))

Simple enough. A full program that prints out the entire ASCII sequence in order.


答:
J, 18 bytes

```<code>|.|:'='#~"0>:?33#6
</code>```

Very simple stuff. With a bugfix from miles!

Title: Illustrate music beats

Body:
J, 18 bytes

|.|:'='#~"0>:?33#6

Very simple stuff. With a bugfix from miles!


答:
JavaScript, 54 bytes

```<code>for(i=32;i<128;i++)console.log(String.fromCharCode(i))
</code>```

Wasted quite a few bytes printing it... Also prints each char on a new line.

Title: Print the ASCII printable character set

Body:
JavaScript, 54 bytes

for(i=32;i<128;i++)console.log(String.fromCharCode(i))

Wasted quite a few bytes printing it... Also prints each char on a new line.


答:
Perl 6, 17 bytes

print |(' '..'~')
```

<pre class="lang-perl6 prettyprint-override"><code>print chrs ^95+32
</code>```

Title: Print the ASCII printable character set

Body:
Perl 6, 17 bytes

print |(' '..'~')

print chrs ^95+32


Title: Print the ASCII printable character set

Body:
C, 40 bytes

f(){for(char i=32;i<128;i++)putchar(i);}


问:
Implement BCD Arithmetic
Write the shortest function you can that takes two binary-coded decimal integers and a character indicating an arithmetic operation to perform and return the result.

Input Specification

You will be passed two 32-bit bit patterns representing unsigned BCD integers.  In C or Java, for example, you would be passed an int (unsigned, if you prefer).  The third argument to your function will be a single character denoting what operation to perform.  If your language requires fixed return sizes, return a 32-bit result and ignore overflow.  Your return value should also be encoded as a BCD.

You should support +, -, *, /, and %.  For subtraction, the first argument is the minuend and the second argument is the subtrahend.  For division and modulo, the first argument is the quotient and the second is the divisor.

Example

```<code>bcd(0x00000127, 0x00000003, '+') => 0x00000130 // NOT 0x0000012A
</code>```

答:
Windows PowerShell, 54 <s>56</s> <s>69</s>

filter f($a,$b,$o){'0x'+("{0:x}$o{1:x}"-f+$a,+$b|iex)}
```
<p>A bit cheating, I guess, but the output very well works as input again. I.e., PowerShell doesn't care whether it's a string or actual numeric literal there.</p>
<p>Test:</p>
<pre class="lang-ps prettyprint-override"><code>> f 0x127 0x3 +
0x130
</code>```

History:

2011-02-11 10:35 (69) – First attempt.

2011-02-11 10:36 (56) – Going easy on the extra zeroes.

2011-02-11 10:41 (54) – filter is shorter.

ContentLicense: CC BY-SA 2.5

Title: Implement BCD Arithmetic

Body:
Windows PowerShell, 54 <s>56</s> <s>69</s>

filter f($a,$b,$o){'0x'+("{0:x}$o{1:x}"-f+$a,+$b|iex)}

A bit cheating, I guess, but the output very well works as input again. I.e., PowerShell doesn't care whether it's a string or actual numeric literal there.

Test:

> f 0x127 0x3 +
0x130

History:

2011-02-11 10:35 (69) – First attempt.

2011-02-11 10:36 (56) – Going easy on the extra zeroes.

2011-02-11 10:41 (54) – filter is shorter.


问:
Code Golf Bingo!
You are given a Bingo board and a list of calls.  You must print BINGO! as soon as your board wins the game.

Bingo boards look like this:

They will be specified like this:

```<code>14 29 38 52 74
4 18 33 46 62
7 16 * 60 71
9 27 44 51 67
12 23 35 47 73
</code>```

Immediately following the board will be calls, like this:

```<code>B7
I29
G60
G51
O71
I23
I16
N38
</code>```

You must echo the calls out to standard output until just after the call that makes you win (get a row, column, or 5-long diagonal all filled), then print BINGO!.

For the above example, print:

```<code>B7
I29
G60
G51
O71
I23
I16
BINGO!
</code>```

Rules

Standard code-golf rules, shortest code wins.

Details

There will always be enough calls to guarantee you a Bingo.  There will be no duplicate numbers on the board, and no duplicate calls.  Boards will always have correctly matched numbers and letters (the B column contains only 1-15, the I column contains only 16-30, and so on), as will calls.  The one and only free space will always be in the middle, marked with * instead of a number.  Consuming and discarding calls from standard input after the winning call is allowed, but not required.

Make your own test cases!

答:
C# – 536

(OK, this is probably not the most suitable language for that, but anyway…)

using System;using System.Collections.Generic;using System.Linq;class C{static void Main(){var s=Enumerable.Range(1,12).Select(_=>new HashSet<string>()).ToList();var b=Enumerable.Range(1,5).Select(_=>Console.ReadLine().Split(' ')).ToList();int i;for(i=0;i<5;++i){for(int j=0;j<5;++j){s[i].Add(b[i][j]);s[i+5].Add(b[j][i]);}s[10].Add(b[i][i]);s[11].Add(b[4-i][i]);}while(i>0){var l=Console.ReadLine();Console.WriteLine(l);l=l.Substring(1);foreach(var x in s){x.Remove("*");x.Remove(l);if(x.Count==0){Console.WriteLine("BINGO!");i=0;}}}}}
```

<p>Formatted and commented:</p>

<pre class="lang-cs prettyprint-override"><code>using System;
using System.Collections.Generic;
using System.Linq;

class C
{
    static void Main()
    {
        // all possible winnable five-item sets – any one of them need to be emptied to win
        var s = Enumerable.Range(1, 12).Select(_ => new HashSet<string>()).ToList();
        // read the board from input to a list of arrays of numbers
        var b = Enumerable.Range(1, 5).Select(_ => Console.ReadLine().Split(' ')).ToList();
        int i;
        // split the board into the winnable sets
        for (i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                // sets 0–4 represent rows
                s[i].Add(b[i][j]);
                // sets 5–9 represent columns
                s[i + 5].Add(b[j][i]);
            }
            // set 10 represent one diagonal
            s[10].Add(b[i][i]);
            // set 11 represent the other diagonal
            s[11].Add(b[4 - i][i]);
        }
        while (i > 0)
        {
            // read and echo another input
            var l = Console.ReadLine();
            Console.WriteLine(l);
            // ignore the initial letter – we are guaranteed it is correct, anyway
            l = l.Substring(1);
            // remove the number from all sets
            foreach (var x in s)
            {
                x.Remove(l);
                // also remove the center * (inside the loop just to shave off a few characters)
                x.Remove("*");
                // if any set became empty, we won!
                if (x.Count == 0)
                {
                    Console.WriteLine("BINGO!");
                    // ensure the loop will stop (might not be necessary per the rules, but anyway)
                    i = 0;
                }
            }
        }
    }
}
</code>```

Title: Code Golf Bingo!

Body:
C# – 536

(OK, this is probably not the most suitable language for that, but anyway…)

using System;using System.Collections.Generic;using System.Linq;class C{static void Main(){var s=Enumerable.Range(1,12).Select(_=>new HashSet<string>()).ToList();var b=Enumerable.Range(1,5).Select(_=>Console.ReadLine().Split(' ')).ToList();int i;for(i=0;i<5;++i){for(int j=0;j<5;++j){s[i].Add(b[i][j]);s[i+5].Add(b[j][i]);}s[10].Add(b[i][i]);s[11].Add(b[4-i][i]);}while(i>0){var l=Console.ReadLine();Console.WriteLine(l);l=l.Substring(1);foreach(var x in s){x.Remove("*");x.Remove(l);if(x.Count==0){Console.WriteLine("BINGO!");i=0;}}}}}

Formatted and commented:

using System;
using System.Collections.Generic;
using System.Linq;

class C
{
    static void Main()
    {
        // all possible winnable five-item sets – any one of them need to be emptied to win
        var s = Enumerable.Range(1, 12).Select(_ => new HashSet<string>()).ToList();
        // read the board from input to a list of arrays of numbers
        var b = Enumerable.Range(1, 5).Select(_ => Console.ReadLine().Split(' ')).ToList();
        int i;
        // split the board into the winnable sets
        for (i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                // sets 0–4 represent rows
                s[i].Add(b[i][j]);
                // sets 5–9 represent columns
                s[i + 5].Add(b[j][i]);
            }
            // set 10 represent one diagonal
            s[10].Add(b[i][i]);
            // set 11 represent the other diagonal
            s[11].Add(b[4 - i][i]);
        }
        while (i > 0)
        {
            // read and echo another input
            var l = Console.ReadLine();
            Console.WriteLine(l);
            // ignore the initial letter – we are guaranteed it is correct, anyway
            l = l.Substring(1);
            // remove the number from all sets
            foreach (var x in s)
            {
                x.Remove(l);
                // also remove the center * (inside the loop just to shave off a few characters)
                x.Remove("*");
                // if any set became empty, we won!
                if (x.Count == 0)
                {
                    Console.WriteLine("BINGO!");
                    // ensure the loop will stop (might not be necessary per the rules, but anyway)
                    i = 0;
                }
            }
        }
    }
}


答:
Bash + general Linux utilities, 18

```<code>jot -s '' -c 95 32
</code>```

Title: Print the ASCII printable character set

Body:
Bash + general Linux utilities, 18

jot -s '' -c 95 32


答:
MATL, 3 bytes

```<code>6Y2
</code>```

Try it Online

And for the sake of a non-built-in (7 bytes)

```<code>32:127c
</code>```

Title: Print the ASCII printable character set

Body:
MATL, 3 bytes

6Y2

Try it Online

And for the sake of a non-built-in (7 bytes)

32:127c


答:
Octave, 13 bytes

```<code>disp(' ':'~')
</code>```

Try it on ideone.

Title: Print the ASCII printable character set

Body:
Octave, 13 bytes

disp(' ':'~')

Try it on ideone.


答:
JavaScript, 98 bytes

```<code>d=new Date();t=;console.log(Math.floor((360*d.getHours()+60*d.getMinutes()+d.getSeconds())/86.4));
</code>```

Definitely could be optimized, I had some problems with the Date object so I'm looking into shorter ways to do that.

Title: Calculate Swatch Internet Time

Body:
Output the current time of day as Swatch Internet Time.

Specifically, output a three-digit (zero-padded) number of ".beats" (1000ths of a day) which represent the current time of day in the Swatch Internet Time time zone of UTC+01:00 ("Biel Meantime").

For example, if the current time in UTC is 23:47, then it is 00:47 in UTC+1 ("Biel Meantime"), and the output would be 032.

Examples:

```<code>UTC Current Time  ->  SIT Output
23:47             ->  032
23:00             ->  000
11:00             ->  500
14:37             ->  651
</code>```

The program should produce this output then immediately exit.

Output is to standard output (or equivalent). Must be a complete, runnable program, not a function. The program takes no input; it outputs the current time.

Body:
JavaScript, 98 bytes

d=new Date();t=;console.log(Math.floor((360*d.getHours()+60*d.getMinutes()+d.getSeconds())/86.4));

Definitely could be optimized, I had some problems with the Date object so I'm looking into shorter ways to do that.


Title: Illustrate music beats

Body:
JavaScript, 179 bytes

Still working on golfing this a bit. I like this since it's straightforward.

n=>{a=Array(33).fill(0).map(n=>Math.floor(Math.random()*6)+1);r=Array(6).fill("");r.map((e,m)=>{a.map(n=>{if (n<=m+1){r[m]+="="}else r[m]+=" "})});return r.join('\n');}

Usage:

>q=n=>{a=Array(33).fill(0).map(n=>{return Math.floor(Math.random() * 6)+1});
r=Array(6).fill("");r.map((e,m)=>{a.map(n=>{if (n<=m+1){r[m]+="="}else r[m]+=" "})});return r.join('\n');}
>q();
           = =  =   =    = =
=   =    = = =  =  == =  = =  =
= = =  = === ====  ====  = = ===
= = =  = === ==========  =======
= === ===========================
=================================


答:
Cheddar, 29 bytes

```<code>->(32:126).map((i)->@"i).fuse
</code>```

Range from 32-126, loop over it and get the string at the given char code @" and the fuse together (join)

Cheddar, 7 bytes

```<code>32@"126
</code>```

Unfortunately this is broken as of the current release but I'm sure you can go back some versions where this works

Title: Print the ASCII printable character set

Body:
Challenge: Print the entire printable ASCII charset (not just a range!) in order.

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

Rules: read closely

No other characters allowed in the output.

Program/function does not accept input.

Try not to hardcode/embed the output.

This is code golf, shortest answer wins.

Body:
Cheddar, 29 bytes

->(32:126).map((i)->@"i).fuse

Range from 32-126, loop over it and get the string at the given char code @" and the fuse together (join)

Cheddar, 7 bytes

32@"126

Unfortunately this is broken as of the current release but I'm sure you can go back some versions where this works


答:
C, 56 bytes

```<code>main(){printf("%03d",(int)((time(0)+3600)%86400/86.4));}
</code>```

Explanation:

%03d - tells printf to zero-pad up to 3 digits.

time(NULL)+3600 - gets amount of seconds (UTC) elapsed since epoch and adds an hour to it (UTC+1).

%86400 - divides epoch by the amount of seconds in a 24hr day and gets the remainder (representing seconds elapsed, so far, "today").

/86.4 - divide remaining seconds by 86.4 to get the ".beat" count since midnight (UTC+1).

Compile (MSVC):

C:> cl swatch.c

Compile (GCC):

$ gcc swatch.c

Title: Calculate Swatch Internet Time

Body:
C, 56 bytes

main(){printf("%03d",(int)((time(0)+3600)%86400/86.4));}

Explanation:

%03d - tells printf to zero-pad up to 3 digits.

time(NULL)+3600 - gets amount of seconds (UTC) elapsed since epoch and adds an hour to it (UTC+1).

%86400 - divides epoch by the amount of seconds in a 24hr day and gets the remainder (representing seconds elapsed, so far, "today").

/86.4 - divide remaining seconds by 86.4 to get the ".beat" count since midnight (UTC+1).

Compile (MSVC):

C:> cl swatch.c

Compile (GCC):

$ gcc swatch.c


答:
Brainfuck, <s>30</s> 27 bytes

```<code>+[[>++<<+>-]>]<<<++[<.+>++]
</code>```

Try it online!

How it works

+ changes the initial cell to 1. After this step, we enter the following, nested loop.

```<code>[        While the current cell is non-zero:
  [        While the current cell (C) is non-zero:
    >++      Increment the cell to C's right twice.
    <<+      Increment the cell to C's left.
    >-       Decrement C.
  ]
  >        Advance to the cell to C's right.
]
</code>```

This computes consecutive powers of 2 until the the value 256 = 0 (mod 256) is reached. When the outer loop finishes, the tape is in the following state.

```<code>                                     v
001 002 004 008 016 032 064 128 000 000 000
</code>```

<<<++ retrocedes three cells and increments twice, leaving the tape as follows.

```<code>                         v
001 002 004 008 016 032 066 128 000 000 000
</code>```

Now we're ready to print the actual output. As a stop condition, we increment the cell above twice each time we print and increment the cell to its left. Since 66 + 95 × 2 = 256 = 0 (mod 256), we stop after printing all 95 printable ASCII characters. We achieve this as follows.

```<code>[      While the current cell (C) is non-zero:
  <      Retrocede to the cell to C's left.
  .+     Print its content and increment.
  >++    Increment C twice.
]
</code>```

Title: Print the ASCII printable character set

Body:
Brainfuck, <s>30</s> 27 bytes

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

Try it online!

How it works

+ changes the initial cell to 1. After this step, we enter the following, nested loop.

[        While the current cell is non-zero:
  [        While the current cell (C) is non-zero:
    >++      Increment the cell to C's right twice.
    <<+      Increment the cell to C's left.
    >-       Decrement C.
  ]
  >        Advance to the cell to C's right.
]

This computes consecutive powers of 2 until the the value 256 = 0 (mod 256) is reached. When the outer loop finishes, the tape is in the following state.

                                     v
001 002 004 008 016 032 064 128 000 000 000

<<<++ retrocedes three cells and increments twice, leaving the tape as follows.

                         v
001 002 004 008 016 032 066 128 000 000 000

Now we're ready to print the actual output. As a stop condition, we increment the cell above twice each time we print and increment the cell to its left. Since 66 + 95 × 2 = 256 = 0 (mod 256), we stop after printing all 95 printable ASCII characters. We achieve this as follows.

[      While the current cell (C) is non-zero:
  <      Retrocede to the cell to C's left.
  .+     Print its content and increment.
  >++    Increment C twice.
]


问:
Print the alphabet without using each vowel
Inspiration: in 1939, a man named Ernest Vincent Wright wrote a novel called Gadsby without using the letter 'e'.

Your task is to write a set of (up to 5) programs in any language (which has a text-based syntax*) to output all 26 letters of the alphabet in order.  However for each vowel aeiou, at least one of the programs must not include any occurrence of the vowel.

So there must be

a program that does not use 'a' or 'A' anywhere in the syntax of the program.

a program that does not use 'e' or 'E' anywhere in the syntax of the program.

a program that does not use 'i'  or 'I' anywhere in the syntax of the program.

a program that does not use 'o' or 'O' anywhere in the syntax of the program.

a program that does not use 'u' or 'U' anywhere in the syntax of the program.

All of them must output abcdefghijklmnopqrstuvwxyz.

The winner shall be the solution where the length of all programs is the shortest.

* since the constraint wouldn't be much of a challenge in Piet or Whitespace

答:
C# – 278/149

Variant 1 – Full standalone programs

A and I are unavoidable here because of class and static.

Without U: 81 chars:

```<code>class C{static void Main(){for(int x=65;x<91;++x)System.Console.Write((char)x);}}
</code>```

Without E: 96 chars:

```<code>class C{static void Main(){for(int x=65;x<91;++x)Syst\u0065m.Consol\u0065.Writ\u0065((char)x);}}
</code>```

Without O: 101 chars:

```<code>class C{static int Main(){System.C\u006fns\u006fle.Write("abcdefghijklmn\x6fpqrstuvwxyz");return 0;}}
</code>```

Total (with A, I missing): 278

Variant 2 – Pure code

Without A, E, I, O: 97 chars

```<code>Syst\u0065m.C\u006fns\u006fl\u0065.Wr\u0069t\u0065("\u0061bcd\u0065fgh\x69jklmn\x6fpqrstuvwxyz");
</code>```

Without U: 52 chars

```<code>for(int x=65;x<91;++x)System.Console.Write((char)x);
</code>```

total: 149

Body:
C# – 278/149

Variant 1 – Full standalone programs

A and I are unavoidable here because of class and static.

Without U: 81 chars:

class C{static void Main(){for(int x=65;x<91;++x)System.Console.Write((char)x);}}

Without E: 96 chars:

class C{static void Main(){for(int x=65;x<91;++x)Syst\u0065m.Consol\u0065.Writ\u0065((char)x);}}

Without O: 101 chars:

class C{static int Main(){System.C\u006fns\u006fle.Write("abcdefghijklmn\x6fpqrstuvwxyz");return 0;}}

Total (with A, I missing): 278

Variant 2 – Pure code

Without A, E, I, O: 97 chars

Syst\u0065m.C\u006fns\u006fl\u0065.Wr\u0069t\u0065("\u0061bcd\u0065fgh\x69jklmn\x6fpqrstuvwxyz");

Without U: 52 chars

for(int x=65;x<91;++x)System.Console.Write((char)x);

total: 149


答:
SQL, <s>76</s> 75 bytes

(Microsoft SQL Server 2012+)

```<code>declare @ int=32;while(@<127)begin;print char(@);set @+=1;end
</code>```

Demo

Title: Print the ASCII printable character set

Body:
SQL, <s>76</s> 75 bytes

(Microsoft SQL Server 2012+)

declare @ int=32;while(@<127)begin;print char(@);set @+=1;end

Demo


问:
"99 Bottles of Beer"
Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible.

Lyrics:

```<code>99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

....

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
</code>```

Rules:

Your program must log to STDOUT or an acceptable alternative, or be returned from a function (with or without a trailing newline).

Your program must be a full, runnable program or function.

Languages specifically written to submit a 0-byte answer to this challenge are allowed, just not particularly interesting.

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

This is different from the output by HQ9+ or 99. Any answers written in these languages will be deleted.

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

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Common Lisp (Lispworks), 431 bytes

```<code>(defun f()(do((i 99(- i 1)))((= i 2))(format t"~S bottles of beer on the wall, ~S bottles of beer.~%Take one down and pass it around, ~S bottles of beer on the wall.~%~%" i i(- i 1)))(format t"2 bottles of beer on the wall, 2 bottles of beer.~%Take one down and pass it around, 1 bottle of beer on the wall.~%~%1 bottle of beer on the wall, 1 bottle of beer.~%Go to the store and buy some more, 99 bottles of beer on the wall.~%"))
</code>```

Ungolfed:

```<code>(defun 99-Bottles-of-Beer ()
  (do ((i 99 (- i 1))) ((= i 2))
    (format t "~S bottles of beer on the wall, ~S bottles of beer.~%Take one down and pass it around, ~S bottles of beer on the wall.~%~%" i i (- i 1)))
  (format t "2 bottles of beer on the wall, 2 bottles of beer.~%Take one down and pass it around, 1 bottle of beer on the wall.~%~%1 bottle of beer on the wall, 1 bottle of beer.~%Go to the store and buy some more, 99 bottles of beer on the wall.~%"))
</code>```

Title: "99 Bottles of Beer"

Body:
Common Lisp (Lispworks), 431 bytes

(defun f()(do((i 99(- i 1)))((= i 2))(format t"~S bottles of beer on the wall, ~S bottles of beer.~%Take one down and pass it around, ~S bottles of beer on the wall.~%~%" i i(- i 1)))(format t"2 bottles of beer on the wall, 2 bottles of beer.~%Take one down and pass it around, 1 bottle of beer on the wall.~%~%1 bottle of beer on the wall, 1 bottle of beer.~%Go to the store and buy some more, 99 bottles of beer on the wall.~%"))

Ungolfed:

(defun 99-Bottles-of-Beer ()
  (do ((i 99 (- i 1))) ((= i 2))
    (format t "~S bottles of beer on the wall, ~S bottles of beer.~%Take one down and pass it around, ~S bottles of beer on the wall.~%~%" i i (- i 1)))
  (format t "2 bottles of beer on the wall, 2 bottles of beer.~%Take one down and pass it around, 1 bottle of beer on the wall.~%~%1 bottle of beer on the wall, 1 bottle of beer.~%Go to the store and buy some more, 99 bottles of beer on the wall.~%"))


问:
Duplicate & switch case
The goal is, having taken a string as input, duplicate each latin letter and "toggle" its case (i.e. uppercase becomes lowercase and vice-versa).

Example inputs & outputs:

```<code>Input      Output
bad        bBaAdD
Nice       NniIcCeE
T e S t    Tt eE Ss tT
s E t      sS Ee tT
1!1!1st!   1!1!1sStT!
n00b       nN00bB
(e.g.)     (eE.gG.)
H3l|@!     Hh3lL|@!
</code>```

The input consists of printable ASCII symbols.

You shouldn't duplicate non-latin letters, numbers, special chars.

答:
Common Lisp (Lispworks), 262 bytes

(defun f(s)(let((b""))(dotimes(i(length s))(if(lower-case-p(elt s i))(progn #1=(setf b(concatenate 'string b(string #2=(elt s i))))(setf b(concatenate 'string b(string(char-upcase #2#)))))(progn #1#(setf b(concatenate 'string b(string(char-downcase #2#)))))))b))
```

<p>ungolfed:</p>

<pre class="lang-cl prettyprint-override"><code>(defun f (s)
  (let ((b ""))
    (dotimes (i (length s))
      (if (lower-case-p (elt s i))
          (progn
           #1=(setf b (concatenate 'string b (string #2=(elt s i))))
           (setf b (concatenate 'string b (string (char-upcase #2#)))))
        (progn
          #1#
          (setf b (concatenate 'string b (string (char-downcase #2#)))))))
    b))
</code>```

Usage:

CL-USER 1 > (f "abc")
"aAbBcC"

CL-USER 2 > (f "bad")
"bBaAdD"
```

Title: Duplicate & switch case

Body:
Common Lisp (Lispworks), 262 bytes

(defun f(s)(let((b""))(dotimes(i(length s))(if(lower-case-p(elt s i))(progn #1=(setf b(concatenate 'string b(string #2=(elt s i))))(setf b(concatenate 'string b(string(char-upcase #2#)))))(progn #1#(setf b(concatenate 'string b(string(char-downcase #2#)))))))b))

ungolfed:

(defun f (s)
  (let ((b ""))
    (dotimes (i (length s))
      (if (lower-case-p (elt s i))
          (progn
           #1=(setf b (concatenate 'string b (string #2=(elt s i))))
           (setf b (concatenate 'string b (string (char-upcase #2#)))))
        (progn
          #1#
          (setf b (concatenate 'string b (string (char-downcase #2#)))))))
    b))

Usage:

CL-USER 1 > (f "abc")
"aAbBcC"

CL-USER 2 > (f "bad")
"bBaAdD"


问:
Is case sensitivity important?
Tom is going to implement a new programming language of his invention.  But before actually starting working on it, he wants to know whether his language should be case sensitive or not.

On one hand, case insensitivity seems more easy to implement to him, but he worries that it could cause a lack in the possibilities of combinations of characters that form a variable, meaning that longer variable names should then be used to avoid naming clashes (for an example, you can use Hello, HEllo, heLLo and a bunch of other possibilities if the language is case sensitive, but only HELLO if not).

But Tom is a meticulous person, so just a worry isn't enough for him. He wants to know the numbers.

The challenge

Write a function (or a full program if your language doesn't support them) that, given an integer n as the input, outputs (or returns) the difference in the number of permutations possible for a string of length n with case sensitivity and without.

In Tom's language, variable names can include all alphabet letters, underscores and, starting from the second character, digits.

Testcases

```<code>Input (length of the variable) -> Output (difference between the possibilities with case sensitivity and the possibilities with case insensitivity)
0 -> 0
1 -> 26
2 -> 2340
5 -> 784304586
8 -> 206202813193260
9 -> 13057419408922746
</code>```

Non-competing C++ reference implementation

void diff(int n) {
    long long total[2] = {0, 0}; //array holding the result for case insensivity ([0]) and case sensitivity ([1])

    for (int c = 1; c <= 2; c ++) //1 = insensitivity, 2 = sensitivity
        for (int l = 1; l <= n; l ++) //each character of the name
            if (l == 1)
                total[c - 1] = 26 * c + 1; //first character can't be a number
            else
                total[c - 1] *= 26 * c + 1 + 10; //starting from the second character, characters can include numbers

    std::cout << total[1] - total[0] << std::endl;
}
```

Scoring

Tom likes golf, so the shortest program in bytes wins.

Note

It's okay if maybe the last two testcases aren't right because of numerical precision. After all, I am not even sure my code handled number 9 correctly.

答:
Jelly, <s>16</s> 15 bytes

```<code>“~J“6j”OH*"’ÆḊḞ
</code>```

Try it online! or verify all test cases.

How it works

```<code>“~J“6j”OH*"’ÆḊḞ  Main link. Argument: n

“~J“6j”          Yield ['~J', '6j'].
       O         Ordinal; replace the characters with it code points.
                 This yields [[126, 74], [54, 106]].
        H        Halve, yielding [[63, 37], [27, 53]].
           ’     Yield n-1.
         *"      Exponentiation (zipwith); elevate 63 and 37 to the power n-1.
            ÆḊ   Take the determinant of the matrix
                 [[63 ** (n-1), 37 ** (n-1)], [27, 53]], thus yielding
                 63 ** (n-1) * 53 - 37 ** (n-1) * 27.
              Ḟ  Floor; round the result down to the nearest integer.
                 This is required for n = 0.
</code>```

Title: Is case sensitivity important?

Body:
Jelly, <s>16</s> 15 bytes

“~J“6j”OH*"’ÆḊḞ

Try it online! or verify all test cases.

How it works

“~J“6j”OH*"’ÆḊḞ  Main link. Argument: n

“~J“6j”          Yield ['~J', '6j'].
       O         Ordinal; replace the characters with it code points.
                 This yields [[126, 74], [54, 106]].
        H        Halve, yielding [[63, 37], [27, 53]].
           ’     Yield n-1.
         *"      Exponentiation (zipwith); elevate 63 and 37 to the power n-1.
            ÆḊ   Take the determinant of the matrix
                 [[63 ** (n-1), 37 ** (n-1)], [27, 53]], thus yielding
                 63 ** (n-1) * 53 - 37 ** (n-1) * 27.
              Ḟ  Floor; round the result down to the nearest integer.
                 This is required for n = 0.


问:
Generate a Stack Exchange Favicon
Do you recognize the PPCG logo?
it looks like this, when you do an ascii art of it.

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

Now, In this Code Golf, You will make a code, that makes logos for other sites, similar to the PPCG logo.

What You should do

The "Shortened" string will be the string, with all upper case letters and numbers in the input string.(Which would be PPCG when the input string is Programming Puzzles & Code Golf)

The "Box" (

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

)
should fit the Shortened string perfectly.(No bigger or smaller)

Also the v part should be exactly 1 down and 1 left to the down right +.

Then output the box which has the shortened string in it.

Example

Stack Overflow:

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

Area 51:

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

Rules

You may assume that the input contains at least one digit or upper case letter.

Standard code-golf rules apply.

Title: Generate a Stack Exchange Favicon

Body:
Common Lisp (Lispworks), 159 bytes bytes

(defun f(s)(labels((p(c l)(dotimes(i l)(format t"~A"c))))(let((l(length s)))#1=(p"+"1)#2=(p"-"l)#3=(format t"+~%")(format t"|~A|~%"s)#1##2##3#(p" "l)(p"v"1))))

ungolfed:

(defun f (s)
  (labels ((p (c l)
             (dotimes (i l)
               (format t "~A" c))))
    (let ((l (length s)))
      #1=(p "+" 1)
      #2=(p "-" l)
      #3=(format t "+~%")
      (format t "|~A|~%" s)
      #1#
      #2#
      #3#
      (p " " l)
      (p "v" 1))))

Usage:

CL-USER 2 > (f "so")
+--+
|so|
+--+
  v
NIL

CL-USER 3 > (f "pcg")
+---+
|pcg|
+---+
   v
NIL


答:
PHP, <s>40</s> <s>30</s> <s>29</s> <s>26</s> 24 bytes

Thanks to Mego, manatwork and Titus for helping me golf this down.

```<code><?=join(range(' ','~'));
</code>```

Title: Print the ASCII printable character set

Body:
PHP, <s>40</s> <s>30</s> <s>29</s> <s>26</s> 24 bytes

Thanks to Mego, manatwork and Titus for helping me golf this down.

<?=join(range(' ','~'));


问:
Golf Text into DNA

Text to DNA golf

Challenge

Convert input into a DNA output.

Algorithm

Convert text into ASCII code points (e.g. codegolf -> [99, 111, 100, 101, 103, 111, 108, 102])

String the ASCII codes together (e.g. 99111100101103111108102)

Convert to binary (e.g. 10100111111001101001011010001000011001101011011110000110010111111011000000110)

Pad 0s onto the end to make an even number of characters (e.g. 101001111110011010010110100010000110011010110111100001100101111110110000001100)

Replace 00 with A, 01 with C, 10 with G, and 11 with T (e.g. GGCTTGCGGCCGGAGACGCGGTCTGACGCCTTGTAAATA)

Output

Test Cases

```<code>codegolf > GGCTTGCGGCCGGAGACGCGGTCTGACGCCTTGTAAATA
ppcg > GGCTAATTGTCGCACTT
} > TTGG (padding)
</code>```

Specifications

This is code-golf

Your program must accept spaces in input.

Your program must work for codegolf.

答:
Common Lisp (Lispworks), 415 bytes

```<code>(defun f(s)(labels((p(e f)(concatenate'string e f)))(let((b"")(d""))(dotimes(i(length s))(setf b(p b(write-to-string(char-int(elt s i))))))(setf b(write-to-string(parse-integer b):base 2))(if(oddp #1=(length b))(setf b(p b"0")))(do((j 0(+ j 2)))((= j #1#)d)(let((c(subseq b j(+ j 2))))(cond((#2=string="00"c)(setf d(p d"A")))((#2#"01"c)(setf d(p d"C")))((#2#"10"c)(setf d(p d"G")))((#2#"11"c)(setf d(p d"T")))))))))
</code>```

ungolfed:

```<code>(defun f (s)
  (labels ((p (e f)
             (concatenate 'string e f)))
  (let ((b "") (d ""))
    (dotimes (i (length s))
      (setf b
            (p b
               (write-to-string
                (char-int (elt s i))))))
    (setf b (write-to-string (parse-integer b) :base 2))
    (if (oddp #1=(length b))
        (setf b (p b "0")))
      (do ((j 0 (+ j 2)))
          ((= j #1#) d)
        (let ((c (subseq b j (+ j 2))))
          (cond ((#2=string=  "00" c)
                 (setf d (p d "A")))
                ((#2# "01" c)
                 (setf d (p d "C")))
                ((#2# "10" c)
                 (setf d (p d "G")))
                ((#2# "11" c)
                 (setf d (p d "T")))))))))
</code>```

Usage:

```<code>CL-USER 2060 > (f "}")
"TTGG"

CL-USER 2061 > (f "golf")
"TAAAAATTATCCATAAATA"
</code>```

Title: Golf Text into DNA

Body:
Common Lisp (Lispworks), 415 bytes

(defun f(s)(labels((p(e f)(concatenate'string e f)))(let((b"")(d""))(dotimes(i(length s))(setf b(p b(write-to-string(char-int(elt s i))))))(setf b(write-to-string(parse-integer b):base 2))(if(oddp #1=(length b))(setf b(p b"0")))(do((j 0(+ j 2)))((= j #1#)d)(let((c(subseq b j(+ j 2))))(cond((#2=string="00"c)(setf d(p d"A")))((#2#"01"c)(setf d(p d"C")))((#2#"10"c)(setf d(p d"G")))((#2#"11"c)(setf d(p d"T")))))))))

ungolfed:

(defun f (s)
  (labels ((p (e f)
             (concatenate 'string e f)))
  (let ((b "") (d ""))
    (dotimes (i (length s))
      (setf b
            (p b
               (write-to-string
                (char-int (elt s i))))))
    (setf b (write-to-string (parse-integer b) :base 2))
    (if (oddp #1=(length b))
        (setf b (p b "0")))
      (do ((j 0 (+ j 2)))
          ((= j #1#) d)
        (let ((c (subseq b j (+ j 2))))
          (cond ((#2=string=  "00" c)
                 (setf d (p d "A")))
                ((#2# "01" c)
                 (setf d (p d "C")))
                ((#2# "10" c)
                 (setf d (p d "G")))
                ((#2# "11" c)
                 (setf d (p d "T")))))))))

Usage:

CL-USER 2060 > (f "}")
"TTGG"

CL-USER 2061 > (f "golf")
"TAAAAATTATCCATAAATA"


答:
Dyalog APL, 11 bytes

```<code>⎕UCS 31+⍳99
</code>```

⍳99 integers 1 through 99

31+ add 31 to them

⎕UCS pick those from the Unicode Character Set

Title: Print the ASCII printable character set

Body:
Dyalog APL, 11 bytes

⎕UCS 31+⍳99

⍳99 integers 1 through 99

31+ add 31 to them

⎕UCS pick those from the Unicode Character Set


问:
Print the alphabet four times
The program must print the alphabet four times: first in the normal alphabetical order, second in the order of a qwerty keyboard, third in the order of a dvorak keyboard, and lastly in reverse alphabetical order. The output should resemble this:

```<code>abcdefghijklmnopqrstuvwxyz
qwertyuiopasdfghjklzxcvbnm
pyfgcrlaoeuidhtnsqjkxbmwvz
zyxwvutsrqponmlkjihgfedcba
</code>```

The output is not case-sensitive, and you can add or omit newlines or spaces wherever you wish.

The catch: the program must be less than 104 characters, or, in other words, smaller than the length of the alphabet times four.

I will accept the answer with the shortest code, unless I see something really clever or interesting that I am more impressed with.

EDIT: I will accept the shortest answer on Wednesday, 4/27/2011.

EDIT2: And the winner is (as usual) Golfscript in 64 chars! Second place, which is behind by only three chars, is also in Golfscript, with 67 chars, followed by Bash in third place with 72 chars.

But there were a few others I wanted to mention, such as this one, which, depending on your definition, only used 52 "characters", and this one where he wrote it in a language he created.

There were a few people who broke an unwritten rule and did not qualify, but I will mention them just for their way of thinking without the box.

答:
Dyalog APL, 60 bytes

```<code>⎕A'QWERTYUIOPASDFGHJKLZXCVBNMPYFGCRLAOEUIDHTNSQJKXBMWVZ',⌽⎕A
</code>```

Prints:

```<code>  ABCDEFGHIJKLMNOPQRSTUVWXYZ  QWERTYUIOPASDFGHJKLZXCVBNMPYFGCRLAOEUIDHTNSQJKXBMWVZ ZYXWVUTSRQPONMLKJIHGFEDCBA
</code>```

Which is permitted as per OP:

The output is not case-sensitive, and you can add or omit newlines or spaces wherever you wish.

Title: Print the alphabet four times

Body:
Dyalog APL, 60 bytes

⎕A'QWERTYUIOPASDFGHJKLZXCVBNMPYFGCRLAOEUIDHTNSQJKXBMWVZ',⌽⎕A

Prints:

  ABCDEFGHIJKLMNOPQRSTUVWXYZ  QWERTYUIOPASDFGHJKLZXCVBNMPYFGCRLAOEUIDHTNSQJKXBMWVZ ZYXWVUTSRQPONMLKJIHGFEDCBA

Which is permitted as per OP:

The output is not case-sensitive, and you can add or omit newlines or spaces wherever you wish.


答:
Julia 0.4, 18 bytes

map(print,' ':'~')
```
<p>Try it online!</p>
<p>If returning a string from a function is acceptable, a further byte can be saved.</p>
<pre class="lang-julia prettyprint-override"><code>f()=' ':'~'|>join
</code>```

Title: Print the ASCII printable character set

Body:
Julia 0.4, 18 bytes

map(print,' ':'~')

Try it online!

If returning a string from a function is acceptable, a further byte can be saved.

f()=' ':'~'|>join


答:
Python 249

```<code>R=raw_input;F=B=[[[x,0][x=='*']for x in row]for row in[R().split()for i in'11111']];A=any
while all([all(map(A,B)),all(map(A,zip(*B))),A(F[::6]),A(F[4:24:4])]):c=R();print c;C=c[1:];B=[[[x,0][x==C]for x in row]for row in B];F=sum(B,[])
print'BINGO!'
</code>```

Usage:

```<code>$ ./bingo.py < bingo.txt
B7
I29
G60
G51
O71
I23
I16
BINGO!
</code>```

Title: Code Golf Bingo!

Body:
You are given a Bingo board and a list of calls.  You must print BINGO! as soon as your board wins the game.

Bingo boards look like this:

They will be specified like this:

```<code>14 29 38 52 74
4 18 33 46 62
7 16 * 60 71
9 27 44 51 67
12 23 35 47 73
</code>```

Immediately following the board will be calls, like this:

```<code>B7
I29
G60
G51
O71
I23
I16
N38
</code>```

You must echo the calls out to standard output until just after the call that makes you win (get a row, column, or 5-long diagonal all filled), then print BINGO!.

For the above example, print:

```<code>B7
I29
G60
G51
O71
I23
I16
BINGO!
</code>```

Rules

Standard code-golf rules, shortest code wins.

Details

There will always be enough calls to guarantee you a Bingo.  There will be no duplicate numbers on the board, and no duplicate calls.  Boards will always have correctly matched numbers and letters (the B column contains only 1-15, the I column contains only 16-30, and so on), as will calls.  The one and only free space will always be in the middle, marked with * instead of a number.  Consuming and discarding calls from standard input after the winning call is allowed, but not required.

Make your own test cases!

Body:
Python 249

R=raw_input;F=B=[[[x,0][x=='*']for x in row]for row in[R().split()for i in'11111']];A=any
while all([all(map(A,B)),all(map(A,zip(*B))),A(F[::6]),A(F[4:24:4])]):c=R();print c;C=c[1:];B=[[[x,0][x==C]for x in row]for row in B];F=sum(B,[])
print'BINGO!'

Usage:

$ ./bingo.py < bingo.txt
B7
I29
G60
G51
O71
I23
I16
BINGO!


答:
Brachylog, 3 bytes

```<code>@Pw
</code>```

@P is the string that contains the printable ASCII characters so… yeah, not very interesting.

It's not clear whether OP accepts built-ins or not, and since others have posted answers that use built-ins, I'll use the 3 bytes version until OP clarifies this point.

With no built-in, 14 bytes

```<code>32:126e          Get a number between 32 and 126
       :"~c"w    Format that number to STDOUT as a char code
             \   Backtrack
</code>```

Title: Print the ASCII printable character set

Body:
Challenge: Print the entire printable ASCII charset (not just a range!) in order.

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

Rules: read closely

No other characters allowed in the output.

Program/function does not accept input.

Try not to hardcode/embed the output.

This is code golf, shortest answer wins.

Body:
Brachylog, 3 bytes

@Pw

@P is the string that contains the printable ASCII characters so… yeah, not very interesting.

It's not clear whether OP accepts built-ins or not, and since others have posted answers that use built-ins, I'll use the 3 bytes version until OP clarifies this point.

With no built-in, 14 bytes

32:126e          Get a number between 32 and 126
       :"~c"w    Format that number to STDOUT as a char code
             \   Backtrack


答:
Haskell, 16 bytes

```<code>putStr[' '..'~']
</code>```

Title: Print the ASCII printable character set

Body:
Haskell, 16 bytes

putStr[' '..'~']


答:
Retina, 18 bytes

```<code>
~
{2`
$`
T01`p`_p</code>```

The leading linefeed is significant.

Try it online!

Explanation

Stage 1: Substitution

```<code>
~</code>```

We start by replacing the empty (non-existent) input with a single ~.

Stage 2: Substitution

```<code>{2`
$`
</code>```

The regex of this substitution is still empty, since the ` separates configuration from regex and {2 is therefore just the configuration. The { indicates that the remaining two stages should be run in a loop until they stop changing the output. The 2 indicates that this specific stage has a limit of 2, meaning that only the first two matches of the regex will be replaced. Since the regex is empty, that means we get an empty match in front of the string and an empty match after the first character.

This match is replaced with the prefix $` which refers to everything in front of the match. For the first match, there is nothing in front of it, so this doesn't insert anything, but for the second match, there is the leading character in front of it, which therefore gets duplicated.

Stage 3: Transliteration

```<code>T01`p`_p
</code>```

Here, T activates transliteration mode, and 0 and 1 are limits (where 0 just means "don't set this limit"). Together, they mean "transliterate only the first character in the string". The actual transliteration maps from p to _p. Here, p expands to the printable ASCII characters and _ means "remove" this character, so the expanded lists look like this:

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

That means spaces get removed and all other characters get decremented by one.

To see how the last two stages act together here is the string after each of the first few and last stages:

```<code>~
~~
}~
}}~
|}~
||}~
{|}~

...

"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

Since the state of the string is only checked after every other stage to determine whether to end the loop, and the two stages cancel each other once we reach the leading space (since Stage 2 adds a space and Stage 3 removes it), this terminates the loop and therefore the program.

Title: Print the ASCII printable character set

Body:
Retina, 18 bytes

~
{2`
$`
T01`p`_p

The leading linefeed is significant.

Try it online!

Explanation

Stage 1: Substitution

~

We start by replacing the empty (non-existent) input with a single ~.

Stage 2: Substitution

{2`
$`

The regex of this substitution is still empty, since the ` separates configuration from regex and {2 is therefore just the configuration. The { indicates that the remaining two stages should be run in a loop until they stop changing the output. The 2 indicates that this specific stage has a limit of 2, meaning that only the first two matches of the regex will be replaced. Since the regex is empty, that means we get an empty match in front of the string and an empty match after the first character.

This match is replaced with the prefix $` which refers to everything in front of the match. For the first match, there is nothing in front of it, so this doesn't insert anything, but for the second match, there is the leading character in front of it, which therefore gets duplicated.

Stage 3: Transliteration

T01`p`_p

Here, T activates transliteration mode, and 0 and 1 are limits (where 0 just means "don't set this limit"). Together, they mean "transliterate only the first character in the string". The actual transliteration maps from p to _p. Here, p expands to the printable ASCII characters and _ means "remove" this character, so the expanded lists look like this:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
_ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

That means spaces get removed and all other characters get decremented by one.

To see how the last two stages act together here is the string after each of the first few and last stages:

~
~~
}~
}}~
|}~
||}~
{|}~

...

"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
!!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

Since the state of the string is only checked after every other stage to determine whether to end the loop, and the two stages cancel each other once we reach the leading space (since Stage 2 adds a space and Stage 3 removes it), this terminates the loop and therefore the program.


答:
SpecaBAS - 76 bytes

```<code>1 FOR x=1 TO 33: r=1+INT(RND*6): FOR y=7-r TO 6: ?AT y,x;"=": NEXT y: NEXT x
</code>```

Prints an equal sign at the relevant screen coordinate.

with a spot of colour and a GOTO loop it becomes

Title: Illustrate music beats

Body:
You know—they look like this:

source

The goal is to draw a music beats illustration like the following:

```<code>=     =      =
=  =  =      =          =
== = ==   =  ==     = ====
== ====  == ===   = = =======
======== == ====  = ========= =
=================================
</code>```

The rules are:

The width of the illustration is 33 symbols, but if you need—any trailing spaces exceeding this width are allowed.

Each column is made of equals signs (=).

Each column has a random height (the height of the next column shouldn’t depend in any way on the height of the previous column), varying from 1 to 6. It’s also fine if it’s at least possible to get some input with no strict math probability (i.e. some inputs could appear more rarely than others).

A column can’t float above the bottom and have gaps in it.

Since every column has the minimal height of 1, the last row can’t have any gaps either—it always consists of 33 equals signs.

Since it’s possible to have no columns with the height of 6 (it’s all random after all): in this case you don’t need to have a top line made of spaces. Applies to any edge cases of this nature: if suddenly your code provided no columns with the height greater than 1, you don’t need to have additional lines made of spaces above the bottom line.

You don’t take any input.

Body:
SpecaBAS - 76 bytes

1 FOR x=1 TO 33: r=1+INT(RND*6): FOR y=7-r TO 6: ?AT y,x;"=": NEXT y: NEXT x

Prints an equal sign at the relevant screen coordinate.

with a spot of colour and a GOTO loop it becomes


答:
MATL, <s>17</s> 16 bytes

```<code>37iqY"27vt26+hpd
</code>```

Try it online!

Last test case (input 9) is not exact due to numerical precision.

Explanation

```<code>37      % Push number 37
iq      % Input number n and subtract 1
Y"      % Row array [37 ...37] of size n-1
27v     % Concatenate 27 vertically. Gives column array [37; ... 37; 27]
t26+    % Duplicate and add 26. Gives column array [63; ... 63; 53]
h       % Concatenate horizontallty. Gives 2D array [37 63; ... 37 63; 27 53]
p       % Product of each column
d       % Difference of the two values. Implicitly display
</code>```

Title: Is case sensitivity important?

Body:
Tom is going to implement a new programming language of his invention.  But before actually starting working on it, he wants to know whether his language should be case sensitive or not.

On one hand, case insensitivity seems more easy to implement to him, but he worries that it could cause a lack in the possibilities of combinations of characters that form a variable, meaning that longer variable names should then be used to avoid naming clashes (for an example, you can use Hello, HEllo, heLLo and a bunch of other possibilities if the language is case sensitive, but only HELLO if not).

But Tom is a meticulous person, so just a worry isn't enough for him. He wants to know the numbers.

The challenge

Write a function (or a full program if your language doesn't support them) that, given an integer n as the input, outputs (or returns) the difference in the number of permutations possible for a string of length n with case sensitivity and without.

In Tom's language, variable names can include all alphabet letters, underscores and, starting from the second character, digits.

Testcases

```<code>Input (length of the variable) -> Output (difference between the possibilities with case sensitivity and the possibilities with case insensitivity)
0 -> 0
1 -> 26
2 -> 2340
5 -> 784304586
8 -> 206202813193260
9 -> 13057419408922746
</code>```

Non-competing C++ reference implementation

void diff(int n) {
    long long total[2] = {0, 0}; //array holding the result for case insensivity ([0]) and case sensitivity ([1])

    for (int c = 1; c <= 2; c ++) //1 = insensitivity, 2 = sensitivity
        for (int l = 1; l <= n; l ++) //each character of the name
            if (l == 1)
                total[c - 1] = 26 * c + 1; //first character can't be a number
            else
                total[c - 1] *= 26 * c + 1 + 10; //starting from the second character, characters can include numbers

    std::cout << total[1] - total[0] << std::endl;
}
```

Scoring

Tom likes golf, so the shortest program in bytes wins.

Note

It's okay if maybe the last two testcases aren't right because of numerical precision. After all, I am not even sure my code handled number 9 correctly.

Body:
MATL, <s>17</s> 16 bytes

37iqY"27vt26+hpd

Try it online!

Last test case (input 9) is not exact due to numerical precision.

Explanation

37      % Push number 37
iq      % Input number n and subtract 1
Y"      % Row array [37 ...37] of size n-1
27v     % Concatenate 27 vertically. Gives column array [37; ... 37; 27]
t26+    % Duplicate and add 26. Gives column array [63; ... 63; 53]
h       % Concatenate horizontallty. Gives 2D array [37 63; ... 37 63; 27 53]
p       % Product of each column
d       % Difference of the two values. Implicitly display


Title: Print the ASCII printable character set

Body:
C#, <s>51</s> <s>45</s> 40 bytes

for(char x=' ';x<=128;)Debug.Write(x++);


答:
Pyke, 5 bytes

```<code>~KS4>
</code>```

Try it here!

Pyke's printable variable isn't sorted and it contains tabs and newlines etc... :(

Title: Print the ASCII printable character set

Body:
Pyke, 5 bytes

~KS4>

Try it here!

Pyke's printable variable isn't sorted and it contains tabs and newlines etc... :(


答:
JavaScript (ES6) 47

```<code>n=>n&&eval("for(a=53,b=27;--n;a*=63)b*=37;a-b")
</code>```

Note: the values are correct up to the 53 bits of precision of javascript numbers.

Test

F=n=>n&&eval("for(a=53,b=27;--n;a*=63)b*=37;a-b")

for(i=0;i<=10;i++)O.textContent+=i+' '+F(i)+'\n'```
<pre class="snippet-code-html lang-html prettyprint-override"><code><pre id=O>``````

Title: Is case sensitivity important?

Body:
JavaScript (ES6) 47

n=>n&&eval("for(a=53,b=27;--n;a*=63)b*=37;a-b")

Note: the values are correct up to the 53 bits of precision of javascript numbers.

Test

F=n=>n&&eval("for(a=53,b=27;--n;a*=63)b*=37;a-b")

for(i=0;i<=10;i++)O.textContent+=i+' '+F(i)+'\n'

<pre id=O></pre>


答:
TSQL, 53 bytes - Vertical solution

```<code>DECLARE @ int=32x:PRINT char(@)SET @+=1IF @<127GOTO x
</code>```

Fiddle

TSQL, <s>75</s> <s>71</s> 68 bytes - Horizontal solution

```<code>DECLARE @ char(95)=''WHILE 95>LEN(@)SET @=char(126-LEN(@))+@ PRINT @
</code>```

Fiddle

Title: Print the ASCII printable character set

Body:
TSQL, 53 bytes - Vertical solution

DECLARE @ int=32x:PRINT char(@)SET @+=1IF @<127GOTO x

Fiddle

TSQL, <s>75</s> <s>71</s> 68 bytes - Horizontal solution

DECLARE @ char(95)=''WHILE 95>LEN(@)SET @=char(126-LEN(@))+@ PRINT @

Fiddle


答:
```<code>#include <iostream>
main()
{
const int a=0;//\
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

17 chars.

By the way, the original program doesn't compile under MSVC, which complains that main doesn't have a return type.

Title: m3ph1st0s's programming puzzle 1 (C++)

Body:
This is the first of a series of C++ puzzles for you. Hope you will enjoy.

So, puzzle no.1:

Given the following program:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

Insert some code on a single new line anywhere inside the program so that the output will be 0. The new line will contain AT MOST 18 characters (including spaces), and the rest of the lines will remain unmodified.
 To be clear, here is an example of a valid new code:

```<code>#include <iostream>
int main()
{
   const int a=1;
   const int b=2;
   int* p = NULL;
   const float c=0.5;
   std::cout << a/b-a*c;
}
</code>```

A new line with 15 characters was inserted so it's ok. However it does not solve the problem.

If this is too simple for you, don't worry, more is coming!!

Body:
#include <iostream>
main()
{
const int a=0;//\
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}

17 chars.

By the way, the original program doesn't compile under MSVC, which complains that main doesn't have a return type.


Title: Is case sensitivity important?

Body:
Pyke, <s>17</s> 15 bytes

53[DT+Qt^*)27[-

Try it here!

  [DT+Qt^*)     - [ = lambda a: a*(a+10)^(input-1)
53[        27[- - [53)-[27)


答:
Pyth, 16 bytes

```<code>L*b^+TbtQ-y53y27
</code>```

Try it here!

Works the same as my Pyke answer

Title: Is case sensitivity important?

Body:
Pyth, 16 bytes

L*b^+TbtQ-y53y27

Try it here!

Works the same as my Pyke answer


答:
Scala, 25 bytes

```<code>()=>' 'to'~'foreach print
</code>```

Anonymous function with no args which prints given range

See it online: https://ideone.com/fX2rwf

Title: Print the ASCII printable character set

Body:
Scala, 25 bytes

()=>' 'to'~'foreach print

Anonymous function with no args which prints given range

See it online: https://ideone.com/fX2rwf


问:
"Hello, World!"
So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most interesting code golf in the common languages, finding the shortest solution in certain esolangs can be a serious challenge. For instance, to my knowledge it is not known whether the shortest possible Brainfuck solution has been found yet.

Furthermore, while all of <s>Wikipedia</s> (the Wikipedia entry has been deleted but there is a copy at archive.org
), esolangs and Rosetta Code have lists of "Hello, World!" programs, none of these are interested in having the shortest for each language (there is also this GitHub repository). If we want to be a significant site in the code golf community, I think we should try and create the ultimate catalogue of shortest "Hello, World!" programs (similar to how our basic quine challenge contains some of the shortest known quines in various languages). So let's do this!

The Rules

Each submission must be a full program.

The program must take no input, and print Hello, World! to STDOUT (this exact byte stream, including capitalization and punctuation) plus an optional trailing newline, and nothing else.

The program must not write anything to STDERR.

If anyone wants to abuse this by creating a language where the empty program prints Hello, World!, then congrats, they just paved the way for a very boring answer.

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

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

This is not about finding the language with the shortest "Hello, World!" program. This is about finding the shortest "Hello, World!" program in every language. Therefore, I will not mark any answer as "accepted".

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

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

For inspiration, check the Hello World Collection.

The Catalogue

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

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

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

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

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

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

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

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

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

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

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

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

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

    var lang = a.language;
    lang = jQuery(''+lang+'').text();

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

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

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

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

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

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

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

table thead {
  font-weight: bold;
}

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
68k machine code (EASy68k), 30 bytes

```<code>00000000: 303c 000d 43f9 0000 1010 4e4f ffff ffff  0<..C.....NO....
00000010: 4865 6c6c 6f2c 2057 6f72 6c64 2100       Hello, World!.
</code>```

I don't know what I'm doing!

Explanation

```<code>    ORG    $1000
START:                  ; first instruction of program

    MOVE #13, D0        ; put text display task number in D0
    LEA HELLO, A1       ; load address of string to display into A1
    TRAP #15            ; activates input/output task

    SIMHALT             ; halt simulator

HELLO DC.B 'Hello, World!',0

    END    START        ; last line of source
</code>```

Title: "Hello, World!"

Body:
68k machine code (EASy68k), 30 bytes

00000000: 303c 000d 43f9 0000 1010 4e4f ffff ffff  0<..C.....NO....
00000010: 4865 6c6c 6f2c 2057 6f72 6c64 2100       Hello, World!.

I don't know what I'm doing!

Explanation

    ORG    $1000
START:                  ; first instruction of program

    MOVE #13, D0        ; put text display task number in D0
    LEA HELLO, A1       ; load address of string to display into A1
    TRAP #15            ; activates input/output task

    SIMHALT             ; halt simulator

HELLO DC.B 'Hello, World!',0

    END    START        ; last line of source


答:
Lua - 41 bytes

```<code>for i=32,127 do io.write(("").char(i))end
</code>```

Title: Print the ASCII printable character set

Body:
Challenge: Print the entire printable ASCII charset (not just a range!) in order.

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

Rules: read closely

No other characters allowed in the output.

Program/function does not accept input.

Try not to hardcode/embed the output.

This is code golf, shortest answer wins.

Body:
Lua - 41 bytes

for i=32,127 do io.write(("").char(i))end


答:
Java, <s>77</s> 76 Bytes

<s>O(1) solution, no loop involved</s>

```<code>long x(long n){return 53*(long)Math.pow(63,n-1)-27*(long)Math.pow(37,n-1);}
</code>```

Title: Is case sensitivity important?

Body:
Java, <s>77</s> 76 Bytes

<s>O(1) solution, no loop involved</s>

long x(long n){return 53*(long)Math.pow(63,n-1)-27*(long)Math.pow(37,n-1);}


Title: Print the ASCII printable character set

Body:
Ruby, 17 bytes

$><<[*' '..?~]*''

or

print *[*' '..?~]


答:
JavaScript (ES7), 43 bytes

f=(n,a=53,b=27)=>n?--n?f(n,a*63,b*37):a-b:0```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input type=number value=0 min=0 max=9 style=width:4ch oninput=o.textContent=f(+this.value)><div id=o>0</div></code>```

Not reduces day today - 55 bytes.

Title: Is case sensitivity important?

Body:
JavaScript (ES7), 43 bytes

f=(n,a=53,b=27)=>n?--n?f(n,a*63,b*37):a-b:0

<input type=number value=0 min=0 max=9 style=width:4ch oninput=o.textContent=f(+this.value)><div id=o>0</div>

Not reduces day today - 55 bytes.


答:
PHP, <s>95</s> <s>92</s> 89 bytes

```<code><?php for(;++$i<34;)for($j=6,$e=' ';$j--;)$a[$j].=$e=rand(0,$j)?$e:'=';echo join("
",$a);
</code>```

Pretty happy with this one actually. For a while I had a version that in theory could generate any input but in practise would generate only solid blocks of = but this is both shorter and equally distributed!

Generates 7 undefined something notices whenever you run it but that's fine.

edit: well I just learned that join is an alias of implode, so that's nice.

Title: Illustrate music beats

Body:
You know—they look like this:

source

The goal is to draw a music beats illustration like the following:

```<code>=     =      =
=  =  =      =          =
== = ==   =  ==     = ====
== ====  == ===   = = =======
======== == ====  = ========= =
=================================
</code>```

The rules are:

The width of the illustration is 33 symbols, but if you need—any trailing spaces exceeding this width are allowed.

Each column is made of equals signs (=).

Each column has a random height (the height of the next column shouldn’t depend in any way on the height of the previous column), varying from 1 to 6. It’s also fine if it’s at least possible to get some input with no strict math probability (i.e. some inputs could appear more rarely than others).

A column can’t float above the bottom and have gaps in it.

Since every column has the minimal height of 1, the last row can’t have any gaps either—it always consists of 33 equals signs.

Since it’s possible to have no columns with the height of 6 (it’s all random after all): in this case you don’t need to have a top line made of spaces. Applies to any edge cases of this nature: if suddenly your code provided no columns with the height greater than 1, you don’t need to have additional lines made of spaces above the bottom line.

You don’t take any input.

Body:
PHP, <s>95</s> <s>92</s> 89 bytes

<?php for(;++$i<34;)for($j=6,$e=' ';$j--;)$a[$j].=$e=rand(0,$j)?$e:'=';echo join("
",$a);

Pretty happy with this one actually. For a while I had a version that in theory could generate any input but in practise would generate only solid blocks of = but this is both shorter and equally distributed!

Generates 7 undefined something notices whenever you run it but that's fine.

edit: well I just learned that join is an alias of implode, so that's nice.


答:
```<code>#include <iostream>
main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
std::cout<<0;//\
   std::cout << a/b-a*c;
}
</code>```

It's 17 characters so it just fits.

Title: m3ph1st0s's programming puzzle 1 (C++)

Body:
#include <iostream>
main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
std::cout<<0;//\
   std::cout << a/b-a*c;
}

It's 17 characters so it just fits.


答:
C - 35 bytes

```<code>f(i){for(i=31;++i<128;putchar(i));}
</code>```

Call:

```<code>int main() {
    f();
}
</code>```

Uses the horrible int-as-a-string trick I learnt from Lynn. (Will again if OP confirms that a vertical output is OK).

Title: Print the ASCII printable character set

Body:
C - 35 bytes

f(i){for(i=31;++i<128;putchar(i));}

Call:

int main() {
    f();
}

Uses the horrible int-as-a-string trick I learnt from Lynn. (Will again if OP confirms that a vertical output is OK).


问:
Cannonball Conundrum
Your task is to, with an input number p, find the smallest positive cannonball number of order p that is NOT 1.

Definition

A cannonball number (of order p) is a number which is both:

An p-gonal number (See this page).

and an p-gonal pyramid number.

The nth p-gonal pyramid number is the sum of the 1st to nth p-gonal numbers.

(e.g. 4th square pyramid number = 1 + 4 + 9 + 16 = 30)

The picture below represents the 4th square pyramid number, as a square pyramid.

For more info, visit this link.

The cannonball number of order 3, for example, is 10, because it is:

The fourth triangle number (1 + 2 + 3 + 4 = 10)

and the third triangular pyramid number. (1 + 3 + 6 = 10)

Formulas

NOTE: If you can find (or make) more useful formulae than my ones here, please post it here (or message me on the question chat thing).

If you're interested, the formula for the nth p-gonal number is:

And the nth p-gonal pyramid number is:

Specs

p is guaranteed to be larger than 2.

The program must check values for a solution for p up to (and including) 2^16. Your program may do anything if no solutions are found for p.

Only positive indices for n.

Test cases

3 outputs 10 (4th triangle number, 3rd triangle pyramid number)

4 outputs 4900 (70th square number, 24th square pyramid number)

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

Note: If you do post a solution, please include a description of how the code works.

Should I start a bounty for a solution which is better and doesn't use my formulae?

答:
JavaScript, <s>111</s> 98 bytes

```<code>f=n=>{for(b=c=g=1;b++;)for(p=b*(b*3+b*b*(n-2)-n+5)/6;g<p;c++)if(p==(g=c*(c*n-c-c-n+4)/2))return p}
</code>```

ungolfed

```<code>f=n=>{
for(b=2,c=g=1;b<1e6;b++)    // run index b from 2 (to 100k)
    for(
        p=(b*b*3+b*b*b*(n-2)-b*(n-5))/6 // p=the b-th n-pyramidal number
        ;g<p&&c<1e6;c++)   // run while n-gonal is lower than n-pyramidal (and c below 100k)
        if(p==(
            g=(c*c*(n-2)-c*(n-4))/2     // g=the c-th n-gonal number
        )) return p                     // if they are equal, return
}
</code>```

c is not reinitialized in the inner loop because the next p[b] is definitely larger than the current g[c] (so we have to move on anyway)

examples

```<code>samples=[3,4,6,8,10,11,14,17,23,26,30,32,35,41,43,50,88]
for(i in samples) document.write('n='+(n=samples[i])+': '+f(n)+'<br>');
</code>```

Title: Cannonball Conundrum

Body:
JavaScript, <s>111</s> 98 bytes

f=n=>{for(b=c=g=1;b++;)for(p=b*(b*3+b*b*(n-2)-n+5)/6;g<p;c++)if(p==(g=c*(c*n-c-c-n+4)/2))return p}

ungolfed

f=n=>{
for(b=2,c=g=1;b<1e6;b++)    // run index b from 2 (to 100k)
    for(
        p=(b*b*3+b*b*b*(n-2)-b*(n-5))/6 // p=the b-th n-pyramidal number
        ;g<p&&c<1e6;c++)   // run while n-gonal is lower than n-pyramidal (and c below 100k)
        if(p==(
            g=(c*c*(n-2)-c*(n-4))/2     // g=the c-th n-gonal number
        )) return p                     // if they are equal, return
}

c is not reinitialized in the inner loop because the next p[b] is definitely larger than the current g[c] (so we have to move on anyway)

examples

samples=[3,4,6,8,10,11,14,17,23,26,30,32,35,41,43,50,88]
for(i in samples) document.write('n='+(n=samples[i])+': '+f(n)+'<br>');