答:
Brain-Flak, <s>76</s> <s>68</s> <s>58</s> <s>52</s> 46 bytes

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

Try it online!

Uses this relationship instead:

$$a(n) = 1+\sum^{a(n-1)-1}_{i=0} 2i$$

which is derived from this relationship modified from that provided in the sequence:

$$a(n+1) = a(n)(a(n) - 1) + 1.$$

Explanation

For a documentation of what each command does, please visit the GitHub page.

There are two stacks in Brain-Flak, which I shall name as Stack 1 and Stack 2 respectively.

The input is stored in Stack 1.

```<code><>(()())<>             Store 2 in Stack 2.

{                      while(Stack_1 != 0){
  ({}[()])                 Stack_1 <- Stack_1 - 1;
  <>                       Switch stack.
  ({({}[()])({})}{}())     Generate the next number in Stack 2.
  <>                       Switch back to Stack 1.
}

<>                     Switch to Stack 2, implicitly print.
</code>```

For the generation algorithm:

```<code>({({}[()])({})}{}())      Top <- (Top + Top + (Top-1) + (Top-1) + ... + 0) + 1

(                  )      Push the sum of the numbers evaluated in the process:

 {            }               while(Top != 0){
  ({}[()])                        Pop Top, push Top-1    (added to sum)
          ({})                    Pop again, push again  (added to sum)
                              }

               {}             Top of stack is now zero, pop it.
                 ()           Evaluates to 1 (added to sum).
</code>```

Alternative 46-byte version

This uses only one stack.

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

Try it online!

Title: Sylvester's sequence

Body:
Brain-Flak, <s>76</s> <s>68</s> <s>58</s> <s>52</s> 46 bytes

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

Try it online!

Uses this relationship instead:

$$a(n) = 1+\sum^{a(n-1)-1}_{i=0} 2i$$

which is derived from this relationship modified from that provided in the sequence:

$$a(n+1) = a(n)(a(n) - 1) + 1.$$

Explanation

For a documentation of what each command does, please visit the GitHub page.

There are two stacks in Brain-Flak, which I shall name as Stack 1 and Stack 2 respectively.

The input is stored in Stack 1.

<>(()())<>             Store 2 in Stack 2.

{                      while(Stack_1 != 0){
  ({}[()])                 Stack_1 <- Stack_1 - 1;
  <>                       Switch stack.
  ({({}[()])({})}{}())     Generate the next number in Stack 2.
  <>                       Switch back to Stack 1.
}

<>                     Switch to Stack 2, implicitly print.

For the generation algorithm:

({({}[()])({})}{}())      Top <- (Top + Top + (Top-1) + (Top-1) + ... + 0) + 1

(                  )      Push the sum of the numbers evaluated in the process:

 {            }               while(Top != 0){
  ({}[()])                        Pop Top, push Top-1    (added to sum)
          ({})                    Pop again, push again  (added to sum)
                              }

               {}             Top of stack is now zero, pop it.
                 ()           Evaluates to 1 (added to sum).

Alternative 46-byte version

This uses only one stack.

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

Try it online!


问:
Sylvester's sequence
Sylvester's sequence, OEIS A000058, is an integer sequence defined as follows:

Each member is the product of all previous members plus one.  The first member of the sequence is 2.

Task

Create a program to calculate the nth term of Sylvester's Sequence.  Standard input, output and loopholes apply.

Standard sequence rules apply.

This is code-golf, so the goal is to minimize the size of your source code as measured in bytes.

Test Cases

You may use either zero or one indexing. (Here I use zero indexing)

```<code>>>0
2
>>1
3
>>2
7
>>3
43
>>4
1807
</code>```

答:
CJam, 10 bytes

```<code>2{_(*)}ri*
</code>```

Uses 0-based indexing. Try it online!

ContentLicense: CC BY-SA 4.0

Title: Sylvester's sequence

Body:
CJam, 10 bytes

2{_(*)}ri*

Uses 0-based indexing. Try it online!

ContentLicense: CC BY-SA 3.0


问:
Creating a Crossed Square

Creating a Crossed Square

You are to take input of an integer of one or more and output a square made of any printable character of your choice with a diagonal cross through the centre.

The general idea is for the output to be a hollow square that has a diagonal cross through it.:

```<code>Input: 7
Output:
*******
*#   #*
* # # *
*  #  *
* # # *
*#   #*
*******
</code>```

In the above example the '*'s represent the outer box and the '#'s represent the diagonal cross.

Note that the above example uses two different characters so that it is easier to see what the output looks like, your program should use one character only.

Input

An integer of 1 or more, it is guaranteed to be odd.

Output

A square that is made up of a character of your choice with a cross through the middle.

The cross must be diagonal

The square may be output via the function or written to output

Trailing newlines are okay

Can output as a graphic, diagram or image if you wish too

Examples

```<code>Input: 1
Output:
*

Input: 3
Output:
***
***
***

Input: 5
Output:
*****
** **
* * *
** **
*****

Input: 7
Output:
*******
**   **
* * * *
*  *  *
* * * *
**   **
*******
</code>```

Specs

Functions or full programs are allowed

You can get input by your preferred means

Standard loopholes are disallowed

Programs must work without any additional statements i.e. usings in C#, they must be included in the entry

You can output from a function or print the result

This is code golf so the shortest solution wins.

答:
VBA Excel, 168 bytes

Instruction:

I find Excel with the help of VBA is an effective and a sufficient tool for this challenge. Set the worksheet of Excel like following

Yes, we use the small, classic square-shaped pixels like the old times by using the cells in a worksheet as the pixels. Ha-ha...

Here I use cell A1 as the input and I change its font color to red. Why red? Because red is three-letter-color so it fits for golfing. Write and run the following code in the Immediate Window:

```<code>N=[A1]:Range("A1",Cells(N,N)).Interior.Color=vbRed:Range("B2",Cells(N-1,N-1)).Clear:For i=1To N:Cells(i,i).Interior.Color=vbRed:Cells(i,N+1-i).Interior.Color=vbRed:Next
</code>```

Ungolfed the code:

```<code>Sub A()
    N = [A1]
    Range("A1", Cells(N, N)).Interior.Color = vbRed
    Range("B2", Cells(N - 1, N - 1)).Clear

    For i = 1 To N
        Cells(i, i).Interior.Color = vbRed
        Cells(i, N + 1 - i).Interior.Color = vbRed
    Next
End Sub
</code>```

Step-by-step Explanation:

```<code>N = [A1]: Range("A1", Cells(N, N)).Interior.Color = vbRed
</code>```

```<code>Range("B2", Cells(N - 1, N - 1)).Clear
</code>```

Looping through the diagonal of range cells: Cells(i, i).Interior.Color = vbRed

Final step and output: Cells(i, N + 1 - i).Interior.Color = vbRed

Title: Creating a Crossed Square

Body:
VBA Excel, 168 bytes

Instruction:

I find Excel with the help of VBA is an effective and a sufficient tool for this challenge. Set the worksheet of Excel like following

Yes, we use the small, classic square-shaped pixels like the old times by using the cells in a worksheet as the pixels. Ha-ha...

Here I use cell A1 as the input and I change its font color to red. Why red? Because red is three-letter-color so it fits for golfing. Write and run the following code in the Immediate Window:

N=[A1]:Range("A1",Cells(N,N)).Interior.Color=vbRed:Range("B2",Cells(N-1,N-1)).Clear:For i=1To N:Cells(i,i).Interior.Color=vbRed:Cells(i,N+1-i).Interior.Color=vbRed:Next

Ungolfed the code:

Sub A()
    N = [A1]
    Range("A1", Cells(N, N)).Interior.Color = vbRed
    Range("B2", Cells(N - 1, N - 1)).Clear

    For i = 1 To N
        Cells(i, i).Interior.Color = vbRed
        Cells(i, N + 1 - i).Interior.Color = vbRed
    Next
End Sub

Step-by-step Explanation:

N = [A1]: Range("A1", Cells(N, N)).Interior.Color = vbRed

Range("B2", Cells(N - 1, N - 1)).Clear

Looping through the diagonal of range cells: Cells(i, i).Interior.Color = vbRed

Final step and output: Cells(i, N + 1 - i).Interior.Color = vbRed


答:
C, 32 bytes

f(n){return--n?f(n)*~-f(n)+1:2;}
```

Uses 1-based indexing. Test it on Ideone.

Title: Sylvester's sequence

Body:
Sylvester's sequence, OEIS A000058, is an integer sequence defined as follows:

Each member is the product of all previous members plus one.  The first member of the sequence is 2.

Task

Create a program to calculate the nth term of Sylvester's Sequence.  Standard input, output and loopholes apply.

Standard sequence rules apply.

This is code-golf, so the goal is to minimize the size of your source code as measured in bytes.

Test Cases

You may use either zero or one indexing. (Here I use zero indexing)

```<code>>>0
2
>>1
3
>>2
7
>>3
43
>>4
1807
</code>```

Body:
C, 32 bytes

f(n){return--n?f(n)*~-f(n)+1:2;}

Uses 1-based indexing. Test it on Ideone.


问:
Russian Roulette
Write a program which plays Russian Roulette!

If the program is started,

there should be a 5 in 6 chance of it ending normally after printing "I survived!"

there should be a 1 in 6 chance of the program crashing. (segmentation fault, etc.)

No input, and no other outputs are allowed.

The randomness must be fair: it must have a uniform probability distribution. This means an uninitialized variable (or a RNG without seed) MOD 6 will not be sufficient.

If the solution works with only one dedicated operating system / platform, you will receive a 6 byte penalty to the score.

Shortest code wins, not sooner than 10 days after first valid answer.

答:
Befunge - 48 chars

```<code> v >91+"!devi"v
/?>?<v"I surv"<
 / / :
   :,_@#
</code>```

Befunge's only randomness is the ? operator, which sends you heading in one of four posible directions (1/4 chance). By blocking one or two directions, you have 1/3 or 1/2 chance, and by combining these, you get 1/6 chance to get out of the program "alive".

The program crashes by doing a divive-by-zero. I guess it's implementation-specific what will happen (on Wikipedia it says the program should ask for the desired answer), but befungee.py sort of crashes, or exits angrily:

```<code>$ for i in {1..6} ; do ./befungee.py roulette.befunge ; done
Error (1,2): integer division or modulo by zero
Error (3,2): integer division or modulo by zero
Error (1,2): integer division or modulo by zero
I survived!
Error (0,1): integer division or modulo by zero
I survived!
</code>```

Title: Russian Roulette

Body:
Befunge - 48 chars

 v >91+"!devi"v
/?>?<v"I surv"<
 / / :
   :,_@#

Befunge's only randomness is the ? operator, which sends you heading in one of four posible directions (1/4 chance). By blocking one or two directions, you have 1/3 or 1/2 chance, and by combining these, you get 1/6 chance to get out of the program "alive".

The program crashes by doing a divive-by-zero. I guess it's implementation-specific what will happen (on Wikipedia it says the program should ask for the desired answer), but befungee.py sort of crashes, or exits angrily:

$ for i in {1..6} ; do ./befungee.py roulette.befunge ; done
Error (1,2): integer division or modulo by zero
Error (3,2): integer division or modulo by zero
Error (1,2): integer division or modulo by zero
I survived!
Error (0,1): integer division or modulo by zero
I survived!


Title: Sylvester's sequence

Body:
J, <s>18</s> <s>14</s> 12 bytes

This version thanks to randomra. I'll try to write a detailed explanation later.

0&(]*:-<:)2:

J, 14 bytes

This version thanks to miles. Used the power adverb ^: instead of an agenda as below. More explanation to come.

2(]*:-<:)^:[~]

J, 18 bytes

2:`(1+*/@$:@i.)@.*

0-indexed.

Examples

   e =: 2:`(1+*/@$:@i.)@.*
   e 1
3
   e 2
7
   e 3
43
   e 4
1807
   x: e i. 10
2 3 7 43 1807 3263443 10650056950807 113423713055421862298779648 12864938683278674737956996400574416174101565840293888 1655066473245199944217466828172807675196959605278049661438916426914992848    91480678309535880456026315554816
   |: ,: x: e i. 10
                                                                                2
                                                                                3
                                                                                7
                                                                                43
                                                                                1807
                                                                                3263443
                                                                                10650056950807
                                                                              113423713055421862298779648
                                                    12864938683278674737956996400574416174101565840293888
165506647324519994421746682817280767519695960527804966143891642691499284891480678309535880456026315554816

Explanation

This is an agenda that looks like this:

           ┌─ 2:
           │    ┌─ 1
       ┌───┤    ├─ +
       │   └────┤           ┌─ / ─── *
── @. ─┤        │     ┌─ @ ─┴─ $:
       │        └─ @ ─┴─ i.
       └─ *

(Generated using (9!:7)'┌┬┐├┼┤└┴┘│─' then 5!:4<'e')

Decomposing:

       ┌─ ...
       │
── @. ─┤
       │
       └─ *

Using the top branch as a the gerund G, and the bottom as the selector F, this is:

e n     <=>     ((F n) { G) n

This uses the constant function 2: when 0 = * n, that is, when the sign is zero (thus n is zero). Otherwise, we use this fork:

  ┌─ 1
  ├─ +
──┤           ┌─ / ─── *
  │     ┌─ @ ─┴─ $:
  └─ @ ─┴─ i.

Which is one plus the following atop series:

            ┌─ / ─── *
      ┌─ @ ─┴─ $:
── @ ─┴─ i.

Decomposing further, this is product (*/) over self-reference ($:) over range (i.).


问:
The IHIH Pyramid
I find it fascinating how the letters "H" and "I" are very similar. "H" is a horizontal stroke surrounded by two vertical strokes; "I" is a vertical stroke surrounded by two horizontal strokes (depending on your font). I bet this could be nested... You know what that reminds me of? Fractals!!!

Let's define the "IHIH" pyramid as follows: The first iteration is this ASCII representation of the letter "I":

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

The next iteration has a vertical stroke on either side.

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

If you view the "I" in the middle as a single horizontal stroke, then this second iteration is basically an "H". The third iteration adds a horizontal stroke on the top and bottom

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

Again, if you view the "H" in the middle as a single vertical stroke, then this iteration is basically an "I". This pattern continues, alternating between "H"s and "I"s on every iteration. For reference, here are the first 6 iterations:

```<code>1:
---
 |
---

2:
|   |
|---|
| | |
|---|
|   |

3:
-------
 |   |
 |---|
 | | |
 |---|
 |   |
-------

4:
|       |
|-------|
| |   | |
| |---| |
| | | | |
| |---| |
| |   | |
|-------|
|       |

5:
-----------
 |       |
 |-------|
 | |   | |
 | |---| |
 | | | | |
 | |---| |
 | |   | |
 |-------|
 |       |
-----------

6:
|           |
|-----------|
| |       | |
| |-------| |
| | |   | | |
| | |---| | |
| | | | | | |
| | |---| | |
| | |   | | |
| |-------| |
| |       | |
|-----------|
|           |
</code>```

The Challenge:

Write a program or function that outputs the N'th iteration of the IHIH pyramid, and an optional trailing newline. Your input will be a single positive integer in whatever reasonable format you want. You do not have to handle invalid inputs, e.g. non-integers, numbers smaller than 1, etc. Your program must at the very least produce the right output for inputs up to 20. Since this is code-golf, standard loopholes are not allowed and the shortest answer in bytes wins!

答:
PHP, 166 bytes

golfed more than 100 bytes off my first approach
and it´s still the longest answer here.

```<code>function i($n){for($m=['|'];$k++<$n;){array_unshift($m,$m[]=str_repeat(' -'[$f=$k&1],2*$k-1));foreach($m as$i=>&$r)$r=($c='||- '[2*$f+($i&&$i<2*$k)]).$r.$c;}return$m;}
</code>```

breakdown

```<code>function h($n)
{
    for($m=['|'];$k++<$n;)
    {
        array_unshift($m,$m[]=str_repeat(' -'[$f=$k&1],2*$k-1));
        foreach($m as$i=>&$r)
            $r=($c='||- '[2*$f+($i&&$i<2*$k)]).$r.$c;
    }
    return$m;
}
</code>```

ungolfed

```<code>function ihih($n)
{
    $m=['|'];                   // iteration 0
    for($k=1;$k<=$n;$k++)       // loop $k from 1 to $n
    {
        $f=$k&1;                        // flag for odd iterations
        // add lines:
        $r=str_repeat(' -'[$f],2*$k-1); // new line: ' ' for even, '-' for odd iterations
        $m[]=$r;                                // append
        array_unshift($m,$r);                   // prepend
        // add columns:
        foreach($m as$i=>&$r)           // for each line
        {
            $c='| '[$f];                        // '|' for even, ' ' for odd iterations
            if($f && (!$i || $i==2*$k)) $c='-'; // '-' in corners for odd iterations
            $r=$c.$r.$c;                        // prepend and append character
        }
    }
    return $m;
}
</code>```

Title: The IHIH Pyramid

Body:
PHP, 166 bytes

golfed more than 100 bytes off my first approach
and it´s still the longest answer here.

function i($n){for($m=['|'];$k++<$n;){array_unshift($m,$m[]=str_repeat(' -'[$f=$k&1],2*$k-1));foreach($m as$i=>&$r)$r=($c='||- '[2*$f+($i&&$i<2*$k)]).$r.$c;}return$m;}

breakdown

function h($n)
{
    for($m=['|'];$k++<$n;)
    {
        array_unshift($m,$m[]=str_repeat(' -'[$f=$k&1],2*$k-1));
        foreach($m as$i=>&$r)
            $r=($c='||- '[2*$f+($i&&$i<2*$k)]).$r.$c;
    }
    return$m;
}

ungolfed

function ihih($n)
{
    $m=['|'];                   // iteration 0
    for($k=1;$k<=$n;$k++)       // loop $k from 1 to $n
    {
        $f=$k&1;                        // flag for odd iterations
        // add lines:
        $r=str_repeat(' -'[$f],2*$k-1); // new line: ' ' for even, '-' for odd iterations
        $m[]=$r;                                // append
        array_unshift($m,$r);                   // prepend
        // add columns:
        foreach($m as$i=>&$r)           // for each line
        {
            $c='| '[$f];                        // '|' for even, ' ' for odd iterations
            if($f && (!$i || $i==2*$k)) $c='-'; // '-' in corners for odd iterations
            $r=$c.$r.$c;                        // prepend and append character
        }
    }
    return $m;
}


答:
Jelly, 5 bytes

```<code>Ḷß€P‘
</code>```

This uses 0-based indexing and the definition from the challenge spec.

Try it online! or verify all test cases.

How it works

```<code>Ḷß€P‘  Main link. Argument: n

Ḷ      Unlength; yield [0, ..., n - 1].
 ß€    Recursively apply the main link to each integer in that range.
   P   Take the product. This yields 1 for an empty range.
    ‘  Increment.
</code>```

Title: Sylvester's sequence

Body:
Jelly, 5 bytes

Ḷß€P‘

This uses 0-based indexing and the definition from the challenge spec.

Try it online! or verify all test cases.

How it works

Ḷß€P‘  Main link. Argument: n

Ḷ      Unlength; yield [0, ..., n - 1].
 ß€    Recursively apply the main link to each integer in that range.
   P   Take the product. This yields 1 for an empty range.
    ‘  Increment.


答:
Actually, <s>14</s> 12 bytes

This used 0-indexing. Golfing suggestions welcome. Try it online!

```<code>2#,`;πu@o`nF
</code>```

Ungolfing:

```<code>2#              Start with [2]
  ,`     `n     Take 0-indexed input and run function (input) times
    ;           Duplicate list
     πu         Take product of list and increment
       @o       Swap and append result to the beginning of the list
           F    Return the first item of the resulting list
</code>```

Title: Sylvester's sequence

Body:
Actually, <s>14</s> 12 bytes

This used 0-indexing. Golfing suggestions welcome. Try it online!

2#,`;πu@o`nF

Ungolfing:

2#              Start with [2]
  ,`     `n     Take 0-indexed input and run function (input) times
    ;           Duplicate list
     πu         Take product of list and increment
       @o       Swap and append result to the beginning of the list
           F    Return the first item of the resulting list


答:
Actually, 9 bytes

```<code>2@`rΣτu`n
</code>```

Try it online!

Uses this relationship instead:

which is derived from this relationship modified from that provided in the sequence:

a(n+1) = a(n) * (a(n) - 1) + 1.

Title: Sylvester's sequence

Body:
Actually, 9 bytes

2@`rΣτu`n

Try it online!

Uses this relationship instead:

which is derived from this relationship modified from that provided in the sequence:

a(n+1) = a(n) * (a(n) - 1) + 1.


答:
GolfScript, <s>12</s> 10 bytes

2 bytes thanks to Dennis.

```<code>~2\{.(*)}*
</code>```

Try it online!

Uses a(n) = a(n-1) * (a(n-1)-1) + 1.

Title: Sylvester's sequence

Body:
GolfScript, <s>12</s> 10 bytes

2 bytes thanks to Dennis.

~2\{.(*)}*

Try it online!

Uses a(n) = a(n-1) * (a(n-1)-1) + 1.


问:
Tips for golfing in J
GolfScript gets its own way far too often and I feel that a repository of handy hints for golfing in J might help in the fight against the evil empire. What tips do you have for making this already terse language shorter?

For those wanting to learn J, the obvious place to begin is the jsoftware site and particularly the vocabulary, the Learning J guide and the J for C programmers guide.

答:
Using iteration to compute sequences

Typically, solving an OEIS sequence challenge will require using one of the formulas given on its page. Some of these adapt well for J, and others not so much. Recursive formulas are straight-forward, however, iteration might not be simple. A pattern I've begun to use is

```<code>(s(]f)^:[~]) n
          ]  Gets n
 s           The first value in the sequence
         ~   Commute the argument order, n is LHS and s is RHS
        [    Gets n
      ^:     Nest n times with an initial argument s
  (]f)         Compute f s
             Returns (f^n) s
</code>```

where s is the first value in the sequence, f is a verb that will compute the next term given the previous term, and n is the zero-based index of the term you want to compute. This method relies on the fact that when computing the power of a dyad, the LHS is bound to the dyad to form a new monad, and that monad is nested on the initial value. The dyad given to the power adverb is a hook where (]f) is given the index n on the LHS and the value of a term in the sequence s. The hook will apply f on s as a monad, and then ignore n to return the result of f s.

Standard library

Sometimes, you might find that J will have support for a verb in its standard library. For example, most of the bitwise integer operations are bound to names which are shorter than using the primitive call.

```<code>AND =: (17 b.) NB. it is actually '$:/ :(17 b.)'
</code>```

Date and time builtins are also available.

Ranges

If you have a set of values [a, b, c] and you want to form a range based on their product like [0, 1, 2, ..., a*b*c-1], the typical approach would be to find their product and then form a range which might be [:i.*/ which costs 6 bytes. A shorter way is ,@i. for 4 bytes since i. can form multidimensional arrays while still counting up, and flattening it will produce an equivalent range.

Printing continuously

A tacit way to print a value and continue to use it without an explicit loop is ([echo) for a monadic case. echo is a verb in the standard library that prints its contents to stdout in the same format used in the interpreter. The hook then passes the same input value out using the left [ verb.

Base 10 digits of an integer

The standard way of acquiring the base 10 digits of an integer is 10#.inv] which costs 8 bytes, too much! An alternative is to convert it to a string and parse it at rank 0 "."0@": which saves a byte, but an even better way is ,.&.": which saves another byte making the final cost 6 bytes instead of 8.

Title: Tips for golfing in J

Body:
Using iteration to compute sequences

Typically, solving an OEIS sequence challenge will require using one of the formulas given on its page. Some of these adapt well for J, and others not so much. Recursive formulas are straight-forward, however, iteration might not be simple. A pattern I've begun to use is

(s(]f)^:[~]) n
          ]  Gets n
 s           The first value in the sequence
         ~   Commute the argument order, n is LHS and s is RHS
        [    Gets n
      ^:     Nest n times with an initial argument s
  (]f)         Compute f s
             Returns (f^n) s

where s is the first value in the sequence, f is a verb that will compute the next term given the previous term, and n is the zero-based index of the term you want to compute. This method relies on the fact that when computing the power of a dyad, the LHS is bound to the dyad to form a new monad, and that monad is nested on the initial value. The dyad given to the power adverb is a hook where (]f) is given the index n on the LHS and the value of a term in the sequence s. The hook will apply f on s as a monad, and then ignore n to return the result of f s.

Standard library

Sometimes, you might find that J will have support for a verb in its standard library. For example, most of the bitwise integer operations are bound to names which are shorter than using the primitive call.

AND =: (17 b.) NB. it is actually '$:/ :(17 b.)'

Date and time builtins are also available.

Ranges

If you have a set of values [a, b, c] and you want to form a range based on their product like [0, 1, 2, ..., a*b*c-1], the typical approach would be to find their product and then form a range which might be [:i.*/ which costs 6 bytes. A shorter way is ,@i. for 4 bytes since i. can form multidimensional arrays while still counting up, and flattening it will produce an equivalent range.

Printing continuously

A tacit way to print a value and continue to use it without an explicit loop is ([echo) for a monadic case. echo is a verb in the standard library that prints its contents to stdout in the same format used in the interpreter. The hook then passes the same input value out using the left [ verb.

Base 10 digits of an integer

The standard way of acquiring the base 10 digits of an integer is 10#.inv] which costs 8 bytes, too much! An alternative is to convert it to a string and parse it at rank 0 "."0@": which saves a byte, but an even better way is ,.&.": which saves another byte making the final cost 6 bytes instead of 8.


答:
Actually, 12 bytes

Input is u then k. Golfing suggestions welcome. Try it online!

```<code>╖R`;p@╜+p*`░
</code>```

Ungolfing:

```<code>╖              Store k in register 0.
 R             Range [1..u]
  `       `░   Start a function f and push values i of the range where f(i) is truthy.
   ;p@         Duplicate i, check if i is prime, and swap with the other i.
      ╜+p      Push k, add to i, check if i+k is prime.
         *     Multiply the two if results together.
                 Similar to logical AND. 1 if both are true, else 0.
</code>```

Title: Variable Prime "Twins"

Body:
I am 2/3 twins with my brother, i.e. born on the same day of the same month but twelve years later. When I was 5, he was 17, both primes; the last pair of ages we can reasonably count on is [71, 83] with both of us being alive and able to celebrate this coincidental jubilee.

Task

Create a code that

takes two integers as input: the difference between the counter and the "twin" as a positive integer k (well yes, I'm the younger) and the upper bound as a positive integer u (runtime consideration)

and gives output as an array or list of all i numbers lower than or equal u for which both i and i+k are primes. The output does not need to be sorted.

Test Cases

```<code>12, 1000 -> [5, 7, 11, 17, 19, 29, 31, 41, 47, 59, 61, 67, 71, 89, 97, 101, 127, 137, 139, 151, 167, 179, 181, 199, 211, 227, 229, 239, 251, 257, 269, 271, 281, 337, 347, 367, 389, 397, 409, 419, 421, 431, 449, 467, 479, 487, 491, 509, 557, 587, 601, 607, 619, 631, 641, 647, 661, 727, 739, 757, 761, 797, 809, 811, 827, 907, 929, 941, 971, 997]
2, 999 -> [3, 5, 11, 17, 29, 41, 59, 71, 101, 107, 137, 149, 179, 191, 197, 227, 239, 269, 281, 311, 347, 419, 431, 461, 521, 569, 599, 617, 641, 659, 809, 821, 827, 857, 881]
3, 1500 -> [2]
30, 1500 -> [7, 11, 13, 17, 23, 29, 31, 37, 41, 43, 53, 59, 67, 71, 73, 79, 83, 97, 101, 107, 109, 127, 137, 149, 151, 163, 167, 181, 193, 197, 199, 211, 227, 233, 239, 241, 251, 263, 277, 281, 283, 307, 317, 337, 349, 353, 359, 367, 379, 389, 401, 409, 419, 431, 433, 449, 457, 461, 479, 491, 541, 547, 557, 563, 569, 571, 577, 587, 601, 613, 617, 631, 643, 647, 653, 661, 709, 727, 739, 743, 757, 797, 809, 823, 827, 829, 853, 857, 877, 881, 907, 911, 937, 941, 947, 953, 967, 983, 991, 1009, 1019, 1021, 1031, 1033, 1039, 1061, 1063, 1087, 1093, 1123, 1151, 1163, 1171, 1187, 1193, 1201, 1229, 1249, 1259, 1277, 1289, 1291, 1297, 1399, 1409, 1423, 1429, 1451, 1453, 1459, 1481, 1493]
</code>```

Edit

Since I failed to specify the upper bound, both inclusive and exclusive solutions are welcome.

Edit No. 2

The challenge ends on 1st September, one week from the start.

Looks like we have a winner but in case of a tie popularity is the tie-breaker; in this case the "second" will be compensated via bounty.

Body:
Actually, 12 bytes

Input is u then k. Golfing suggestions welcome. Try it online!

╖R`;p@╜+p*`░

Ungolfing:

╖              Store k in register 0.
 R             Range [1..u]
  `       `░   Start a function f and push values i of the range where f(i) is truthy.
   ;p@         Duplicate i, check if i is prime, and swap with the other i.
      ╜+p      Push k, add to i, check if i+k is prime.
         *     Multiply the two if results together.
                 Similar to logical AND. 1 if both are true, else 0.


问:
Non-palindromic numbers
A strictly non-palindromic number N is a number that isn't a palindrome in any base (in bases 2 to N-2).  These numbers are listed on OEIS

For example, the number 19 in base 2,3,4,5,6,...17 is: 10011,201,103,34,31,...12.  None of these representations is palindromic, so the number is strictly non-palindromic.

For this challenge, you need to return a truthy value if the number is non-palindromic, otherwise a falsy value.

You may assume the number passed to you is greater than or equal to 0.

Your program should work for values up to your languages' integer size.

Test cases:

Truthy:

```<code>0
1
2
3
4
6
11
19
47
53
79
103
389
997
1459
</code>```

Falsy:

```<code>5
7
8
9
10
13
16
43
48
61
62
101
113
211
1361
</code>```

This is a code-golf, so make your answers as short as possible!

答:
Python 2, 71 bytes

n=input();b=1
while b<n-2:
 m=n;r=0;b+=1
 while m/(r!=n):r=r*b+m%b;m/=b
```

Output is via exit code, where 0 is truthy and 1 is falsy. Test it on Ideone.

Title: Non-palindromic numbers

Body:
Python 2, 71 bytes

n=input();b=1
while b<n-2:
 m=n;r=0;b+=1
 while m/(r!=n):r=r*b+m%b;m/=b

Output is via exit code, where 0 is truthy and 1 is falsy. Test it on Ideone.


答:
Haskell, 26 bytes

```<code>f n|n<1=2|m<-f$n-1=1+m*m-m
</code>```

Usage example: f 4 -> 1807.

Title: Sylvester's sequence

Body:
Haskell, 26 bytes

f n|n<1=2|m<-f$n-1=1+m*m-m

Usage example: f 4 -> 1807.


问:
Shortest way to reverse a number
Write a function (or equivalent subprogram) to accept a single integer valued argument and return a (similarly typed) value found by reversing the order of the base-10 digits of the argument.

For example given 76543 return 34567

答:
Befunge (3 characters)

Complete runnable program:

```<code>N.@
</code>```

Where N is your number. Rules say "accept a single integer valued argument"; In Befunge you can only enter integers from 0 to 9.

OwnerDisplayName: eltond

Title: Shortest way to reverse a number

Body:
Befunge (3 characters)

Complete runnable program:

N.@

Where N is your number. Rules say "accept a single integer valued argument"; In Befunge you can only enter integers from 0 to 9.


问:
Smallest palindrome divisible by the input
Given a positive integer N, output the smallest positive integer such that this number is a palindrome (i.e. is its own reverse) and is divisible by N.

The palindrome (i.e. the output) must not need a leading zero to be a palindrome, e.g. 080 is not the valid answer for 16.

The input will never be a multiple of 10, because of the previous reason.

Your program may take as much time as necessary, even if in practice it would be way too long to output the answer.

Inputs and outputs

You may take the input through STDIN, as a function argument, or anything similar.

You may print the output to STDOUT, return it from a function, or anything similar.

Inputs and outputs must be in the decimal base.

Test cases

```<code>N        Output
1        1
2        2
16       272
17       272
42       252
111      111
302      87278
1234     28382
</code>```

Scoring

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

答:
Mathematica, <s>34</s> 28 bytes

```<code>#//.x_/;!PalindromeQ@x:>x+#&
</code>```

Unnamed function taking a positive integer input and returning a positive integer. To be read as: "Starting with the function argument #, repeatedly replace any x we see that is not a palindrome with x+#." Yes, Virginia, there is a PalindromeQ! It only works in base 10 though.

Original submission:

```<code>(i=1;While@!PalindromeQ[++i#];i#)&
</code>```

Body:
Mathematica, <s>34</s> 28 bytes

#//.x_/;!PalindromeQ@x:>x+#&

Unnamed function taking a positive integer input and returning a positive integer. To be read as: "Starting with the function argument #, repeatedly replace any x we see that is not a palindrome with x+#." Yes, Virginia, there is a PalindromeQ! It only works in base 10 though.

Original submission:

(i=1;While@!PalindromeQ[++i#];i#)&


问:
This isn't rocket science
Write a program or function that takes in a single-line string. You can assume it only contains printable ASCII. Print or return a string of an ASCII art rocket such as

```<code>  |
 /_\
 |E|
 |a|
 |r|
 |t|
 |h|
 |_|
/___\
 VvV
</code>```

with the input string written from top to bottom on the fuselage. In this case the input was Earth. The height of the rocket (including flames) is always the length of the string plus five.

Each line in the output may have up to two trailing spaces and there may be a single optional trailing newline. The shortest code in bytes wins.

More Examples:

```<code>[empty string]

  |
 /_\
 |_|
/___\
 VvV

a

  |
 /_\
 |a|
 |_|
/___\
 VvV

|0

  |
 /_\
 |||
 |0|
 |_|
/___\
 VvV

\/\

  |
 /_\
 |\|
 |/|
 |\|
 |_|
/___\
 VvV

 _ _ [note trailing space]

  |
 /_\
 | |
 |_|
 | |
 |_|
 | |
 |_|
/___\
 VvV

    [4 spaces]

  |
 /_\
 | |
 | |
 | |
 | |
 |_|
/___\
 VvV

SPACEY

  |
 /_\
 |S|
 |P|
 |A|
 |C|
 |E|
 |Y|
 |_|
/___\
 VvV
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Actually, 40 bytes

```<code>"/___\
 VvV",'_o"|
 |"j'|o" |"+"  |
 /_\
</code>```

Yes, those newlines are supposed to be there.

Try it online!

Explanation:

Newlines are represented by \n for easier formatting

```<code>"/___\\n VvV",'_o"|\n |"j'|o" |"+"  |\n /_\
"/___\\n VvV"                                create the bottom of the rocket
             ,'_o                            get input, append a "_" (for the last section before the jets)
                 "|\n |"j                    insert "|\n |" between every pair of characters
                         '|o                 append "|"
                            " |"+            prepend " |"
                                 "  |\n /_\  create the nose cone
</code>```

Title: This isn't rocket science

Body:
Actually, 40 bytes

"/___\
 VvV",'_o"|
 |"j'|o" |"+"  |
 /_\

Yes, those newlines are supposed to be there.

Try it online!

Explanation:

Newlines are represented by \n for easier formatting

"/___\\n VvV",'_o"|\n |"j'|o" |"+"  |\n /_\
"/___\\n VvV"                                create the bottom of the rocket
             ,'_o                            get input, append a "_" (for the last section before the jets)
                 "|\n |"j                    insert "|\n |" between every pair of characters
                         '|o                 append "|"
                            " |"+            prepend " |"
                                 "  |\n /_\  create the nose cone


答:
Python 2, <s>93</s> <s>66</s> <s>62</s> 61 bytes

A FGITW. Can probably be heavily golfed. Suggestions welcome.

Edit: 27 bytes thanks to Mego. 4 bytes thanks to TheBikingViking. 1 byte thanks to user3030010.

Try It Online!

lambda x:r"""  |
 /_\
 |%s|
/___\
 VvV"""%"|\n |".join(x+"_")
```

Title: This isn't rocket science

Body:
Write a program or function that takes in a single-line string. You can assume it only contains printable ASCII. Print or return a string of an ASCII art rocket such as

```<code>  |
 /_\
 |E|
 |a|
 |r|
 |t|
 |h|
 |_|
/___\
 VvV
</code>```

with the input string written from top to bottom on the fuselage. In this case the input was Earth. The height of the rocket (including flames) is always the length of the string plus five.

Each line in the output may have up to two trailing spaces and there may be a single optional trailing newline. The shortest code in bytes wins.

More Examples:

```<code>[empty string]

  |
 /_\
 |_|
/___\
 VvV

a

  |
 /_\
 |a|
 |_|
/___\
 VvV

|0

  |
 /_\
 |||
 |0|
 |_|
/___\
 VvV

\/\

  |
 /_\
 |\|
 |/|
 |\|
 |_|
/___\
 VvV

 _ _ [note trailing space]

  |
 /_\
 | |
 |_|
 | |
 |_|
 | |
 |_|
/___\
 VvV

    [4 spaces]

  |
 /_\
 | |
 | |
 | |
 | |
 |_|
/___\
 VvV

SPACEY

  |
 /_\
 |S|
 |P|
 |A|
 |C|
 |E|
 |Y|
 |_|
/___\
 VvV
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```


Title: This isn't rocket science

Body:
Perl 6, 75 bytes

"  |\n /_\\".say;" |$_|".say for slurp.chomp.comb;" |_|\n/___\\\n VvV".say;


答:
V, <s>41,</s> 39 bytes

```<code>ys$_òlé
òÎá|I |
Hr/$r\YO  |GpX2á_o VvV
</code>```

Try it online!

Note that for some reason, the online interpreter was producing unexpected results, so I pushed a debug version to the online interpreter that runs a lot slower. It should produce the correct results now.

Since this program contains unprintable characters, here is a hexdump:

```<code>0000000: 7973 245f f26c e90a f2ce e17c 4920 7c0a  ys$_.l.....|I |.
0000010: 4872 2f24 725c 594f 2020 7c1b 4770 5832  Hr/$r\YO  |.GpX2
0000020: e15f 6f20 5676 56                        ._o VvV
</code>```

Title: This isn't rocket science

Body:
V, <s>41,</s> 39 bytes

ys$_òlé
òÎá|I |
Hr/$r\YO  |GpX2á_o VvV

Try it online!

Note that for some reason, the online interpreter was producing unexpected results, so I pushed a debug version to the online interpreter that runs a lot slower. It should produce the correct results now.

Since this program contains unprintable characters, here is a hexdump:

0000000: 7973 245f f26c e90a f2ce e17c 4920 7c0a  ys$_.l.....|I |.
0000010: 4872 2f24 725c 594f 2020 7c1b 4770 5832  Hr/$r\YO  |.GpX2
0000020: e15f 6f20 5676 56                        ._o VvV


答:
05AB1E, 7 bytes

```<code>2sFD<*>
</code>```

Explained

Uses zero-based indexing.

```<code>2         # push 2 (initialization for n=0)
 sF       # input nr of times do
   D<*    # x(x-1)
      >   # add 1
</code>```

Try it online!

Title: Sylvester's sequence

Body:
Sylvester's sequence, OEIS A000058, is an integer sequence defined as follows:

Each member is the product of all previous members plus one.  The first member of the sequence is 2.

Task

Create a program to calculate the nth term of Sylvester's Sequence.  Standard input, output and loopholes apply.

Standard sequence rules apply.

This is code-golf, so the goal is to minimize the size of your source code as measured in bytes.

Test Cases

You may use either zero or one indexing. (Here I use zero indexing)

```<code>>>0
2
>>1
3
>>2
7
>>3
43
>>4
1807
</code>```

Body:
05AB1E, 7 bytes

2sFD<*>

Explained

Uses zero-based indexing.

2         # push 2 (initialization for n=0)
 sF       # input nr of times do
   D<*    # x(x-1)
      >   # add 1

Try it online!


Title: Sylvester's sequence

Body:
Mathematica, 19 bytes

Nest[#^2-#+1&,2,#]&

Or 21 bytes:

Array[#0,#,0,1+1##&]&


答:
Java 10, <s>102</s> <s>99</s> 81 bytes

a->{var r="  |\n /_\\\n |";for(var c:a)r+=c+"|\n |";return r+"_|\n/___\\\n VvV";}
```
<p>3 bytes saved thanks to <em>@Jules</em>.</p>
<p>Try it online.</p>
<p><strong>Explanation:</strong></p>
<pre class="lang-java prettyprint-override"><code>a->{                      // Method with character-array parameter and String return-type
  var r="  |\n /_\\\n |"; //  Result-String, starting with the top part:
                          //   |
                          //  /_\
                          //  |
  for(var c:a)            //  Loop over each character in the input-array:
    r+=c                  //   Append the character to the result-String,
        +"|\n |";         //   with trailing:
                          //    |
                          //  |
  return r                //  Return the result-String,
   +"_|\n/___\\\n VvV";}  //  appended with bottom part:
                          //   _|
                          // /___\
                          //  VvV
</code>```

Title: This isn't rocket science

Body:
Java 10, <s>102</s> <s>99</s> 81 bytes

a->{var r="  |\n /_\\\n |";for(var c:a)r+=c+"|\n |";return r+"_|\n/___\\\n VvV";}

3 bytes saved thanks to @Jules.

Try it online.

Explanation:

a->{                      // Method with character-array parameter and String return-type
  var r="  |\n /_\\\n |"; //  Result-String, starting with the top part:
                          //   |
                          //  /_\
                          //  |
  for(var c:a)            //  Loop over each character in the input-array:
    r+=c                  //   Append the character to the result-String,
        +"|\n |";         //   with trailing:
                          //    |
                          //  |
  return r                //  Return the result-String,
   +"_|\n/___\\\n VvV";}  //  appended with bottom part:
                          //   _|
                          // /___\
                          //  VvV


答:
In shell scripting :

```<code>  echo "your number"|rev
</code>```

Hope this was useful :)

Title: Shortest way to reverse a number

Body:
Write a function (or equivalent subprogram) to accept a single integer valued argument and return a (similarly typed) value found by reversing the order of the base-10 digits of the argument.

For example given 76543 return 34567

Body:
In shell scripting :

  echo "your number"|rev

Hope this was useful :)


答:
Actually, <s>46</s> 45 bytes

I've been meaning to do a Seriously/Actually answer for months and now I can. Golfing suggestions welcome. Try it online!

Edit: In February of 2017, there was an update to Actually that changed which function literals are which. Enjoy.

This uses the explicit definition of the Bernoulli numbers on Wikipedia.

```<code>;╖ur⌠;╝ur⌠;;0~ⁿ(╛█*╜(uⁿ*⌡MΣ╛uk⌡M┬i@;π;)♀\*@k▼
</code>```

Ungolfing

```<code>;╖     Duplicate and save m in register 0.
ur     Range [0..m]
  ⌠      Start first for loop
  ;╝     Duplicate and save k in register 1.
  ur     Range [0..k]
    ⌠      Start second for loop (as string).
    ;;     Duplicate v twice.
    0~ⁿ    Push -1, and pow() to get (-1)**v.
    (╛█    Rotate a duplicate v to TOS, push k, and binom(k, v).
    *      Multiply (-1)**v by binom(k, v).
    ╜(uⁿ   Push m, rotate last duplicate v to TOS, increment, and pow() to get (v+1)**m.
    *      (-1)**v * binom(k, v) * (v+1)**m
    ⌡      End second for loop (string turned to function).
  MΣ     Map over range [0..v] and sum
  ╛u     Push k and increment (the denominator)
           (Note: second for loop does numerators only as denominator only depends on k)
  k      Push fraction in list form [numerator, denominator]
  ⌡      End first for loop
M      Map over range [0..k]
┬i@    Transpose all of the fractions, flatten and swap.
         Stack: [denominators] [numerators]
;π     Duplicate and take product of denominators.
;)     Duplicate product and move to bottom of stack.
         Stack: product [denominators] [numerators] product
♀\     For all items in denominators, integer divide product by item.
         Return a list of these scaled-up denominators.
*      Dot product of numerators and the scaled-up denominators as new numerator.
         (In effect, getting the fractions to the same denominator and summing them)
@k     Swap new numerator and product (new denominator) and turn into a list (fraction).
▼      Divide fraction by gcd(numerator, denominator) (Simplify fraction).
</code>```

Title: Bernoulli Numbers

Body:
The Bernoulli numbers (specifically, the second Bernoulli numbers) are defined by the following recursive definition:

Where  denotes a combination.

Given a nonnegative integer m as input, output the decimal representation OR a reduced fraction for the mth second Bernoulli number. If you output a decimal representation, you must have at least 6 decimal places (digits after the decimal point) of precision, and it must be accurate when rounded to 6 decimal places. For example, for m = 2, 0.166666523 is acceptable because it rounds to 0.166667. 0.166666389 is not acceptable, because it rounds to 0.166666. Trailing zeroes may be omitted. Scientific notation may be used for decimal representations.

Here is the input and expected output for m up to and including 60, in scientific notation rounded to 6 decimal places, and as reduced fractions:

```<code>0 -> 1.000000e+00 (1/1)
1 -> 5.000000e-01 (1/2)
2 -> 1.666667e-01 (1/6)
3 -> 0.000000e+00 (0/1)
4 -> -3.333333e-02 (-1/30)
5 -> 0.000000e+00 (0/1)
6 -> 2.380952e-02 (1/42)
7 -> 0.000000e+00 (0/1)
8 -> -3.333333e-02 (-1/30)
9 -> 0.000000e+00 (0/1)
10 -> 7.575758e-02 (5/66)
11 -> 0.000000e+00 (0/1)
12 -> -2.531136e-01 (-691/2730)
13 -> 0.000000e+00 (0/1)
14 -> 1.166667e+00 (7/6)
15 -> 0.000000e+00 (0/1)
16 -> -7.092157e+00 (-3617/510)
17 -> 0.000000e+00 (0/1)
18 -> 5.497118e+01 (43867/798)
19 -> 0.000000e+00 (0/1)
20 -> -5.291242e+02 (-174611/330)
21 -> 0.000000e+00 (0/1)
22 -> 6.192123e+03 (854513/138)
23 -> 0.000000e+00 (0/1)
24 -> -8.658025e+04 (-236364091/2730)
25 -> 0.000000e+00 (0/1)
26 -> 1.425517e+06 (8553103/6)
27 -> 0.000000e+00 (0/1)
28 -> -2.729823e+07 (-23749461029/870)
29 -> 0.000000e+00 (0/1)
30 -> 6.015809e+08 (8615841276005/14322)
31 -> 0.000000e+00 (0/1)
32 -> -1.511632e+10 (-7709321041217/510)
33 -> 0.000000e+00 (0/1)
34 -> 4.296146e+11 (2577687858367/6)
35 -> 0.000000e+00 (0/1)
36 -> -1.371166e+13 (-26315271553053477373/1919190)
37 -> 0.000000e+00 (0/1)
38 -> 4.883323e+14 (2929993913841559/6)
39 -> 0.000000e+00 (0/1)
40 -> -1.929658e+16 (-261082718496449122051/13530)
41 -> 0.000000e+00 (0/1)
42 -> 8.416930e+17 (1520097643918070802691/1806)
43 -> 0.000000e+00 (0/1)
44 -> -4.033807e+19 (-27833269579301024235023/690)
45 -> 0.000000e+00 (0/1)
46 -> 2.115075e+21 (596451111593912163277961/282)
47 -> 0.000000e+00 (0/1)
48 -> -1.208663e+23 (-5609403368997817686249127547/46410)
49 -> 0.000000e+00 (0/1)
50 -> 7.500867e+24 (495057205241079648212477525/66)
51 -> 0.000000e+00 (0/1)
52 -> -5.038778e+26 (-801165718135489957347924991853/1590)
53 -> 0.000000e+00 (0/1)
54 -> 3.652878e+28 (29149963634884862421418123812691/798)
55 -> 0.000000e+00 (0/1)
56 -> -2.849877e+30 (-2479392929313226753685415739663229/870)
57 -> 0.000000e+00 (0/1)
58 -> 2.386543e+32 (84483613348880041862046775994036021/354)
59 -> 0.000000e+00 (0/1)
60 -> -2.139995e+34 (-1215233140483755572040304994079820246041491/56786730)
</code>```

Reference implementation (in Python 3):

def factorial(n):
    if n < 1:
        return 1
    else:
        return n * factorial(n - 1)

def combination(m,k):
    if k <= m:
        return factorial(m)/(factorial(k) * factorial(m - k))
    else:
        return 0

def Bernoulli(m):
    if m == 0:
        return 1
    else:
        t = 0
        for k in range(0, m):
            t += combination(m, k) * Bernoulli(k) / (m - k + 1)
        return 1 - t
```

<h3>Rules</h3>

<ul>
<li>This is code-golf, so shortest code in bytes wins</li>
<li>You may not use any functions, either built-in or included in an external library, that compute either type of Bernoulli numbers or Bernoulli polynomials.</li>
<li>Your answer must give correct output for all inputs up to and including 60.</li>
</ul>

<h1>Leaderboard</h1>

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

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

```## Language Name, N bytes
```

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

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

<p>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 <em>last</em> number in the header:</p>

```## Perl, 43 + 2 (-p flag) = 45 bytes
```

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

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

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-html lang-html prettyprint-override"><code><style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr> </tbody> </table><script>var QUESTION_ID = 65382; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 45941; 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 = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); 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('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script></code>```

Body:
Actually, <s>46</s> 45 bytes

I've been meaning to do a Seriously/Actually answer for months and now I can. Golfing suggestions welcome. Try it online!

Edit: In February of 2017, there was an update to Actually that changed which function literals are which. Enjoy.

This uses the explicit definition of the Bernoulli numbers on Wikipedia.

;╖ur⌠;╝ur⌠;;0~ⁿ(╛█*╜(uⁿ*⌡MΣ╛uk⌡M┬i@;π;)♀\*@k▼

Ungolfing

;╖     Duplicate and save m in register 0.
ur     Range [0..m]
  ⌠      Start first for loop
  ;╝     Duplicate and save k in register 1.
  ur     Range [0..k]
    ⌠      Start second for loop (as string).
    ;;     Duplicate v twice.
    0~ⁿ    Push -1, and pow() to get (-1)**v.
    (╛█    Rotate a duplicate v to TOS, push k, and binom(k, v).
    *      Multiply (-1)**v by binom(k, v).
    ╜(uⁿ   Push m, rotate last duplicate v to TOS, increment, and pow() to get (v+1)**m.
    *      (-1)**v * binom(k, v) * (v+1)**m
    ⌡      End second for loop (string turned to function).
  MΣ     Map over range [0..v] and sum
  ╛u     Push k and increment (the denominator)
           (Note: second for loop does numerators only as denominator only depends on k)
  k      Push fraction in list form [numerator, denominator]
  ⌡      End first for loop
M      Map over range [0..k]
┬i@    Transpose all of the fractions, flatten and swap.
         Stack: [denominators] [numerators]
;π     Duplicate and take product of denominators.
;)     Duplicate product and move to bottom of stack.
         Stack: product [denominators] [numerators] product
♀\     For all items in denominators, integer divide product by item.
         Return a list of these scaled-up denominators.
*      Dot product of numerators and the scaled-up denominators as new numerator.
         (In effect, getting the fractions to the same denominator and summing them)
@k     Swap new numerator and product (new denominator) and turn into a list (fraction).
▼      Divide fraction by gcd(numerator, denominator) (Simplify fraction).


问:
The Arithmetic Derivative
The derivative of a function is a cornerstone of mathematics, engineering, physics, biology, chemistry, and a large number of other sciences as well. Today we're going to be calculating something only tangentially related: the arithmetic derivative.

Definition

The arithmetic derivative a(n) or n' is defined here (A003415) by a number of properties that are similar to the derivative of a function.

a(0) = a(1) = 0,

a(p) = 1, where p is any prime, and

a(mn) = m*a(n) + n*a(m).

The third rule is based on the product rule for differentiation of functions: for functions f(x) and g(x), (fg)' = f'g + fg'. So with numbers, (ab)' = a'b + ab'.

Also of note, since the arithmetic derivative can be extended to the negative numbers via this simple relation, a(-n) = -a(n), the input may be negative.

Rules

Write a program or function that, given any integer n, returns the arithmetic derivative of n.

Inputs will be -230 < n < 230, to avoid problems with integer sizes and numbers too large to factor in a reasonable amount of time. Your algorithm should still be able to theoretically calculate the arithmetic derivative of numbers outside this range.

Built-ins for symbolic math, prime factorization and differentiation are allowed.

Examples

```<code>> a(1)
0
> a(7)
1
> a(14)   # a(7)*2 + a(2)*7 = 1*2 + 1*7 = 9
9
> a(-5)   # a(-5) = -a(5) = -1
-1
> a(8)    # a(8) = a(2**3) = 3*2**2 = 12
12
> a(225)  # a(225) = a(9)*25 + a(25)*9 = 6*25 + 10*9 = 150 + 90 = 240
240
> a(299792458)  # a(299792458) = a(2)*149896229 + a(7)*42827494 + a(73)*4106746 + a(293339)*1022 = 1*149896229 + 1*42827494 + 1*4106746 + 1*1022 = 149896229 + 42827494 + 4106746 + 1022 = 196831491
196831491
</code>```

As always, if the problem is unclear, please let me know. Good luck and good golfing!

答:
Perl 6, 90

```<code>sub A(\n) {0>n??-A(-n)!!(n>1)*{$_??n/$_*A($_)+$_*A n/$_!!1}(first n%%*,2..^n)};say A slurp
</code>```

This might be a bit slow for large numbers. Replace 2..^n with 2..n.sqrt for longer code but faster computation.

Title: The Arithmetic Derivative

Body:
Perl 6, 90

sub A(\n) {0>n??-A(-n)!!(n>1)*{$_??n/$_*A($_)+$_*A n/$_!!1}(first n%%*,2..^n)};say A slurp

This might be a bit slow for large numbers. Replace 2..^n with 2..n.sqrt for longer code but faster computation.


答:
Pyth, 38 bytes

```<code>j++"  |
 /_\\"jR_B" |"+Q\_"/___\\
 VvV
</code>```

Try it online. Test suite.

Title: This isn't rocket science

Body:
Pyth, 38 bytes

j++"  |
 /_\\"jR_B" |"+Q\_"/___\\
 VvV

Try it online. Test suite.


答:
05AB1E, <s>50</s> <s>47</s> <s>43</s> 37 bytes

```<code>I'_J"  |
 /_\"svy" |ÿ|"}"/___\
 VvV"»
</code>```

Try it online!

Saved 9 bytes thanks to Adnan.

Title: This isn't rocket science

Body:
05AB1E, <s>50</s> <s>47</s> <s>43</s> 37 bytes

I'_J"  |
 /_\"svy" |ÿ|"}"/___\
 VvV"»

Try it online!

Saved 9 bytes thanks to Adnan.


答:
Excel VBA, <s>142</s>  <s>179</s>  <s>175</s> <s>160</s> 155 bytes

Instruction:

Set the worksheet of Excel where cell A1 is input and column C as the output. <s>Set the text alignment in column C to center</s>. Write and run the following code in the Immediate Window:

[C1]="|":[C2]="/_\":T=[A1]&"_":For i=1To Len(T):Cells(i+2,3)="|"&Mid(T,i,1)&"|":Next:Cells(i+2,3)="/__\":Cells(i+3,3)="VvV":[C:C].HorizontalAlignment=-4108
```
<p><strong>Ungolfed the code:</strong></p>
<pre class="lang-vb prettyprint-override"><code>Sub R()
    [C1] = "|"
    [C2] = "/_\"
    T = [A1]&"_"

    For i = 1 To Len(T)
        Cells(i + 2, 3) = "|" & Mid(T, i, 1) & "|"
    Next

    Cells(i + 2, 3) = "/__\"
    Cells(i + 3, 3) = "VvV"
    [C:C].HorizontalAlignment = -4108   'Set the text alignment in column C to center
End Sub
</code>```

Output:

Note: The font and the color are just a personal choice.

15 bytes saved due to edc65's suggestion. Thanks.

5 bytes saved due to Taylor Raine's suggestion. Thanks.

Title: This isn't rocket science

Body:
Excel VBA, <s>142</s>  <s>179</s>  <s>175</s> <s>160</s> 155 bytes

Instruction:

Set the worksheet of Excel where cell A1 is input and column C as the output. <s>Set the text alignment in column C to center</s>. Write and run the following code in the Immediate Window:

[C1]="|":[C2]="/_\":T=[A1]&"_":For i=1To Len(T):Cells(i+2,3)="|"&Mid(T,i,1)&"|":Next:Cells(i+2,3)="/__\":Cells(i+3,3)="VvV":[C:C].HorizontalAlignment=-4108

Ungolfed the code:

Sub R()
    [C1] = "|"
    [C2] = "/_\"
    T = [A1]&"_"

    For i = 1 To Len(T)
        Cells(i + 2, 3) = "|" & Mid(T, i, 1) & "|"
    Next

    Cells(i + 2, 3) = "/__\"
    Cells(i + 3, 3) = "VvV"
    [C:C].HorizontalAlignment = -4108   'Set the text alignment in column C to center
End Sub

Output:

Note: The font and the color are just a personal choice.

15 bytes saved due to edc65's suggestion. Thanks.

5 bytes saved due to Taylor Raine's suggestion. Thanks.


答:
PHP, <s>108</s> <s>100</s> 88 bytes

-8 bytes thanks to business cat

-12 bytes thanks to YetiCGN

```<code>echo'  |
 /_\\
';foreach(str_split($argv[1])as$c){echo" |$c|
";}echo' |_|
/___\\
 VvV';
</code>```

pretty straightforward

Ideone

Title: This isn't rocket science

Body:
PHP, <s>108</s> <s>100</s> 88 bytes

-8 bytes thanks to business cat

-12 bytes thanks to YetiCGN

echo'  |
 /_\\
';foreach(str_split($argv[1])as$c){echo" |$c|
";}echo' |_|
/___\\
 VvV';

pretty straightforward

Ideone


答:
Pyke, <s>40</s> <s>37</s> 35 bytes

(Updated to work with latest version)

```<code>\_+2" ||
"m:"/___\
 VvV"+R"  |
 /_\
</code>```

Try it here!

Title: This isn't rocket science

Body:
Pyke, <s>40</s> <s>37</s> 35 bytes

(Updated to work with latest version)

\_+2" ||
"m:"/___\
 VvV"+R"  |
 /_\

Try it here!


Title: Bernoulli Numbers

Body:
Perl 6, 83 bytes

my &B={$^m??1-[+] (^$m).map: {combinations($m,$_)*B($_)/($m+1-$_)}!!1};say B slurp;

A faster, 114-byte solution:

my @b=1;for 1..+slurp() {@b.push: 1-[+] (^$^m).map: {([*] $m+1-$_..$m)*@b[$_]/($m+1-$_)/([*] 1..$_)}};say @b[*-1];


Title: This isn't rocket science

Body:
Write a program or function that takes in a single-line string. You can assume it only contains printable ASCII. Print or return a string of an ASCII art rocket such as

```<code>  |
 /_\
 |E|
 |a|
 |r|
 |t|
 |h|
 |_|
/___\
 VvV
</code>```

with the input string written from top to bottom on the fuselage. In this case the input was Earth. The height of the rocket (including flames) is always the length of the string plus five.

Each line in the output may have up to two trailing spaces and there may be a single optional trailing newline. The shortest code in bytes wins.

More Examples:

```<code>[empty string]

  |
 /_\
 |_|
/___\
 VvV

a

  |
 /_\
 |a|
 |_|
/___\
 VvV

|0

  |
 /_\
 |||
 |0|
 |_|
/___\
 VvV

\/\

  |
 /_\
 |\|
 |/|
 |\|
 |_|
/___\
 VvV

 _ _ [note trailing space]

  |
 /_\
 | |
 |_|
 | |
 |_|
 | |
 |_|
/___\
 VvV

    [4 spaces]

  |
 /_\
 | |
 | |
 | |
 | |
 |_|
/___\
 VvV

SPACEY

  |
 /_\
 |S|
 |P|
 |A|
 |C|
 |E|
 |Y|
 |_|
/___\
 VvV
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Scala, 97 94 77 bytes

print("  |\n /_\\\n"+args(0).map{" |"+_+"|\n"}.mkString+" |_|\n/___\\\n VvV")


答:
JavaScript (ES6), 54

Straightforward

```<code>x=>`  |
 /_\\
 |${[...x+'_'].join`|
 |`}|
/___\\
 VvV`
</code>```

Test

f=x=>`  |
 /_\\
 |${[...x+'_'].join`|
 |`}|
/___\\
 VvV`

function update() {
  O.textContent=f(I.value)
}

update()```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=I value='hello' oninput='update()'><pre id=O>``````

Title: This isn't rocket science

Body:
JavaScript (ES6), 54

Straightforward

x=>`  |
 /_\\
 |${[...x+'_'].join`|
 |`}|
/___\\
 VvV`

Test

f=x=>`  |
 /_\\
 |${[...x+'_'].join`|
 |`}|
/___\\
 VvV`

function update() {
  O.textContent=f(I.value)
}

update()

<input id=I value='hello' oninput='update()'><pre id=O></pre>


问:
Physics golf: inclined shooting
An angry bird is shot at an angle \$β\$ to the horizontal at a speed \$u\$. The ground is steep, inclined at an angle \$α\$. Find the horizontal distance \$q\$ that the bird traveled before it hit the ground.

Make a function \$f(α, β, u)\$ that returns the length \$q\$: the horizontal distance that the bird traveled before it hit the ground.

Constraints and notes:

\$-90° < α < 90°\$.

\$0° < β < 180°\$.

\$α < β\$.

\$0 \le u < 10^9\$.

Assume acceleration due to gravity \$g = 10\$.

You may use radians instead of degrees for \$α\$, \$β\$.

Dimensions of \$u\$ are irrelevant as long as they are consistent with \$g\$ and \$q\$.

No air resistance or anything too fancy.

Shortest code wins.

See the Wikipedia article on projectile motion for some equations.

Samples:

```<code>f(0, 45, 10) = 10
f(0, 90, 100) = 0
f(26.565, 45, 10) = 5
f(26.565, 135, 10) = 15
</code>```

答:
Python3 - 65 chars

from math import*
f=lambda α,β,u:(tan(α)+tan(β))*u*u*.2*cos(β)**2
```

Title: Physics golf: inclined shooting


问:
Calculate e^x and ln(x)
Given a floating point x (x<100), return e^x and ln(x). The first 6 decimal places of the number have to be right, but any others after do not have to be correct.

You cannot have any "magic" constants explicitly stated (e.x. a=1.35914 since 1.35914*2 ~= e), but you can calculate them. Only use +, -, *, and / for arithmetic operators.

If x is less than or equal to 0, output ERROR instead of the intended value of ln(x).

Test Cases:

```<code>input: 2
output: 7.389056 0.693147
input: 0.25
output: 1.284025 -1.386294
input: 2.718281828
output: 15.154262 0.999999  (for this to output correctly, don't round to 6 places)
input: -0.1
output: 0.904837 ERROR
</code>```

Shortest code wins.

答:
Haskell, 166 (89 without I/O)

```<code>s=1e-7
e x|x>s=1/e(-x)|x>0=1+x|y<-e$x+s=y-y*s
l x|x<1=0-l(1/x)|1>0=sum$map(s/)[1,1+s..x]
n x|x<0="ERROR"|1>0=show$l x
main=interact$unwords.(\x->[show$e x,n x]).read
</code>```

Takes an alternative approach: we use that

∂/∂x ex = ex

and solve the differential equation numerically, with a simple euler method. Similarly, use

ln x = 1∫x 1/x dx

and calculate the integral with the rectangular method.

Example:

$ echo 2 | ./exp-and-log

  7.389056835370484 0.6931472554471929

  $ echo 0.25 | ./exp-and-log

  1.284025432730133 -1.3862944228194163

  $ echo 2.718281828 | ./exp-and-log

  15.15426430695358 1.0000000576151333

  $ echo -0.1 | ./exp-and-log

  0.9048374135134576 ERROR

It's quite amazingly inefficient, in fact it uses about 4 GB of memory even for these examples (since it's non-tail–recursive... you need to compile (in GHC) with -with-rtsopts=-K2G so it even accepts such a ridiculous stack size).

Title: Calculate e^x and ln(x)

Body:
Haskell, 166 (89 without I/O)

s=1e-7
e x|x>s=1/e(-x)|x>0=1+x|y<-e$x+s=y-y*s
l x|x<1=0-l(1/x)|1>0=sum$map(s/)[1,1+s..x]
n x|x<0="ERROR"|1>0=show$l x
main=interact$unwords.(\x->[show$e x,n x]).read

Takes an alternative approach: we use that

∂/∂x ex = ex

and solve the differential equation numerically, with a simple euler method. Similarly, use

ln x = 1∫x 1/x dx

and calculate the integral with the rectangular method.

Example:

$ echo 2 | ./exp-and-log

  7.389056835370484 0.6931472554471929

  $ echo 0.25 | ./exp-and-log

  1.284025432730133 -1.3862944228194163

  $ echo 2.718281828 | ./exp-and-log

  15.15426430695358 1.0000000576151333

  $ echo -0.1 | ./exp-and-log

  0.9048374135134576 ERROR

It's quite amazingly inefficient, in fact it uses about 4 GB of memory even for these examples (since it's non-tail–recursive... you need to compile (in GHC) with -with-rtsopts=-K2G so it even accepts such a ridiculous stack size).


Title: Non-palindromic numbers

Body:
A strictly non-palindromic number N is a number that isn't a palindrome in any base (in bases 2 to N-2).  These numbers are listed on OEIS

For example, the number 19 in base 2,3,4,5,6,...17 is: 10011,201,103,34,31,...12.  None of these representations is palindromic, so the number is strictly non-palindromic.

For this challenge, you need to return a truthy value if the number is non-palindromic, otherwise a falsy value.

You may assume the number passed to you is greater than or equal to 0.

Your program should work for values up to your languages' integer size.

Test cases:

Truthy:

```<code>0
1
2
3
4
6
11
19
47
53
79
103
389
997
1459
</code>```

Falsy:

```<code>5
7
8
9
10
13
16
43
48
61
62
101
113
211
1361
</code>```

This is a code-golf, so make your answers as short as possible!

Body:
Haskell, <s>75</s> 68 bytes

(a!c)b|a<1=c|x<-c*b+mod a b=div a b!x$b
f n=all((/=n).(n!0))[2..n-2]


答:
R,  56 49 bytes

```<code>n=scan();x=2;for(i in 1:n){x=c(x,prod(x)+1)};cat(x[n+1])
</code>```

Ungolfed:

```<code>n=scan()            # Take input n
x=2                 # Initialize sequence to 2
for(i in 1:n){
  x=c(x,prod(x)+1)  # Append the product of the previous numbers + 1
}
cat(x[n+1])         # Print the nth + 1 number in seq
</code>```

Slightly golfed thanks to @Frédéric:

```<code>n=scan();x=2;for(i in 1:n)x=c(x,prod(x)+1);x[n+1]
</code>```

Title: Sylvester's sequence

Body:
Sylvester's sequence, OEIS A000058, is an integer sequence defined as follows:

Each member is the product of all previous members plus one.  The first member of the sequence is 2.

Task

Create a program to calculate the nth term of Sylvester's Sequence.  Standard input, output and loopholes apply.

Standard sequence rules apply.

This is code-golf, so the goal is to minimize the size of your source code as measured in bytes.

Test Cases

You may use either zero or one indexing. (Here I use zero indexing)

```<code>>>0
2
>>1
3
>>2
7
>>3
43
>>4
1807
</code>```

Body:
R,  56 49 bytes

n=scan();x=2;for(i in 1:n){x=c(x,prod(x)+1)};cat(x[n+1])

Ungolfed:

n=scan()            # Take input n
x=2                 # Initialize sequence to 2
for(i in 1:n){
  x=c(x,prod(x)+1)  # Append the product of the previous numbers + 1
}
cat(x[n+1])         # Print the nth + 1 number in seq

Slightly golfed thanks to @Frédéric:

n=scan();x=2;for(i in 1:n)x=c(x,prod(x)+1);x[n+1]


答:
Haskell, 25 bytes

(iterate(\m->m*m-m+1)2!!)
```

Title: Sylvester's sequence


答:
R, <s>50 46</s> 44 bytes

```<code>    n=scan();v=2;if(n)for(i in 1:n){v=v^2-v+1};v
</code>```

Rather than tracking the whole sequence, we just keep track of the product, which follows the given quadratic update rule as long as <s>n>1</s> n>0. (This sequence uses the "start at <s>one</s> zero" convention)

Using the start at zero convention saves a couple of bytes since we can use if(n) rather than if(n>1)

Title: Sylvester's sequence

Body:
R, <s>50 46</s> 44 bytes

    n=scan();v=2;if(n)for(i in 1:n){v=v^2-v+1};v

Rather than tracking the whole sequence, we just keep track of the product, which follows the given quadratic update rule as long as <s>n>1</s> n>0. (This sequence uses the "start at <s>one</s> zero" convention)

Using the start at zero convention saves a couple of bytes since we can use if(n) rather than if(n>1)


答:
Haskell, <s>67 63</s> 59 bytes

(++"_|\n/___\\\n VvV").("  |\n /_\\\n |"++).(>>=(:"|\n |"))
```

Thanks to Damien it's now essentially the same as xnor's answer, just in point-free notation. Ideone it!

Title: This isn't rocket science

Body:
Haskell, <s>67 63</s> 59 bytes

(++"_|\n/___\\\n VvV").("  |\n /_\\\n |"++).(>>=(:"|\n |"))

Thanks to Damien it's now essentially the same as xnor's answer, just in point-free notation. Ideone it!


答:
Jelly, <s>38</s> 37 bytes

```<code>;”_“|“|¶”jÐ€“  |¶“/_\¶”;K;“/___\¶ VvV
</code>```

Try it online!

Same idea as with my Pyth answer, but this can probably be golfed.

Title: This isn't rocket science

Body:
Jelly, <s>38</s> 37 bytes

;”_“|“|¶”jÐ€“  |¶“/_\¶”;K;“/___\¶ VvV

Try it online!

Same idea as with my Pyth answer, but this can probably be golfed.


答:
C#, <s>130</s> <s>111</s> 95 bytes

```<code>s=>{var a="  |\n /_\\\n";foreach(var c in s)a+=" |"+c+"|\n";a+=" |_|\n/___\\\n VvV";return a;};
</code>```

Saved 16 bytes thanks to Kevin Cruijssen

Title: This isn't rocket science

Body:
C#, <s>130</s> <s>111</s> 95 bytes

s=>{var a="  |\n /_\\\n";foreach(var c in s)a+=" |"+c+"|\n";a+=" |_|\n/___\\\n VvV";return a;};

Saved 16 bytes thanks to Kevin Cruijssen


问:
No strings (or numbers) attached
If you like this, consider participating in:

The Official Dyalog APL 2016 Year Game

The monthly Dyalog APL 2017 Code Golf Challenge

Make 12 snippets/expressions, in the same language, that result in the numbers 0 through 10, and 42 respectively, but without writing any literal numeric, string, or character data.

Build-in data, like PI() and ALPHABET(), are fine, and so are e.g. CJam's U, X, Y, Z, and A constants, and Processing's BLEND, CHORD, CENTER, BREAK, and  LINES.

Every snippet must be able to stand on its own, i.e. they may not be interdependent. However, inside a single snippet, you may assign a variable and use it freely, as long as you refer to it directly by name, and not through a string containing its name.

All the snippets must be valid on the submitter’s computer at the time of submission (as reported by SE), but may not rely on unusual local conditions like number of files in a directory, the exact date or time, or specific input from the user.

Examples of valid snippets

3: INT(LOG10(YEAR(TODAY())))   because it remains true in the foreseeable future

4: CUBICROOT(LEN(CHARACTERSET()))   because a 256 letter character set is very common

8: SQRT(SYSTEMTYPE())   because 64-bit systems are very common

Examples of invalid snippets

5: LEN(USERNAME())   because most people do not use “Admin” as login :-)

9: LOG10(SYSTEMMEMORY())   because it only works on systems with exactly 1 GB of memory

42: CODE("*")   because it contains a string/character literal

The result of each snippet must result in an actual number (value, int, float, etc.) that can be used for further calculations using the same language as the snippet, i.e not a text string representing that number.

Only character based languages allowed.

Score is total byte count of all the 12 snippets combined. Newlines separating the snippets are not counted in.

Note that the above rules may prevent some languages from participating, even if they are Turing complete.

FAQ

Q Can the programs accept any input?

A Yes, but you may not just ask for input and enter the relevant number.

Q Are physical digits (non-data) digits allowed?

A Yes, e.g. LOG10().

Q Do Symbols in Ruby count as literals?

A Yes.

Q Does score include newlines between each snippet?

A No.

Q Is TI-BASIC "character based" enough to be valid?

A Yes.

Q Do false and true count as number literals?

A No, they are acceptable.

Q Can we use a number literal to call a function if that's the only way and the number doesn't influence the output of the function?

A Yes, if that is the normal way to write code in your language.

Q My language assumes there is a [something] at the start of each program/expression. Must I include it, or should my snippets just work if placed in the middle of a program/expression?

A They should just work in the middle of a program/expression.

Q What about regex literals?

A Forbidden, except for languages that only do regexes.

Q Is one piece of code that could print all the specified numbers acceptable?

A No, they have to be separate and mutually independent.

Q May I assume a boilerplate like int main() {}... or equivalent?

A Yes.

Q What output datatypes are allowed?

A Any numeric datatype, like int, float, etc.

Q Do I need to print the result of each snippet?

A No, making the result available for subsequent use is enough.

Q Are pre-set variables allowed?

A Yes, and they become reset (if changed) for every snippet.

Q Are π and e considered number literals?

A No, you may use them.

Q May I return 4 and 2 in different cells for 42?

A No, they must be connected as one number.

Q Bytes or characters?

A Bytes, but you may choose any desired codepage.

Q May constant functions and preset variables like J's 9:, Actually's 9, and Pretzel's 9 be used?

A Yes, if the vocabulary is finite (19 for J, 10 for Actually and Pretzel).

Title: No strings (or numbers) attached

Body:
BASH, 318 bytes

0 to 3 are exit code, other ones are stored in A

bytes count is split as follow :2-5-5-26-23-32-26-38-26-33-32-70

#0
ls
#1
cd \\
#2
ls \\
#3
cd \\
A=$?
A=$(($A+$A+$A))
#4
ls \\
A=$?
A=$(($A*$A))
#5
cd \\
A=$?
A=$(($A+$A+$A+$A+$A))
#6
ls \\
A=$?
A=$(($A+$A+$A))
#7
cd \\
A=$?
A=$(($A+$A+$A+$A+$A+$A+$A))
#8
ls \\
A=$?
A=$(($A*$A*$A))
#9
A=$?
A=$(($A+$A+$A))
#10
ls \\
A=$?
A=$(($A+$A+$A+$A+$A))
#42
@
A=$?
cd \\
B=$?
cd \\
C=$?
C=$(($C+$C+$C))
B=$(($A-$B))
A=$(($B/$C))

7 is more than probably golfable a bit more, as is 42


答:
Python 3, <s>78</s> 75 Bytes

```<code>w="  |\n /_\\"
for i in input(): w+="\n |"+i+"|"
w+="\n |_| \n/___\\ \n VvV"
print(w)
</code>```

Thanks @ValueInk for spotting that I could lose 3 bytes by clearing the input function of arguments.

Title: This isn't rocket science

Body:
Python 3, <s>78</s> 75 Bytes

w="  |\n /_\\"
for i in input(): w+="\n |"+i+"|"
w+="\n |_| \n/___\\ \n VvV"
print(w)

Thanks @ValueInk for spotting that I could lose 3 bytes by clearing the input function of arguments.


答:
R,  44 42 41 bytes

2 bytes save thanks to JDL

1 byte save thanks to user5957401

```<code>f=function(n)ifelse(n,(a=f(n-1))^2-a+1,2)
</code>```

Title: Sylvester's sequence

Body:
R,  44 42 41 bytes

2 bytes save thanks to JDL

1 byte save thanks to user5957401

f=function(n)ifelse(n,(a=f(n-1))^2-a+1,2)


问:
My triangle needs more nodes
Consider the standard equilateral triangle, with nodes labeled using barycentric coordinates:

We can turn this 3 node triangle into a 6 node triangle by adding a new line of 3 vertices (one more than was present on a side of the original 3 node triangle), remove any internal edges (but not internal nodes) and re-normalize the coordinates:

Repeating the process to go from a 6 node triangle to a 10 node triangle, add a line of 4 vertices (again, one more than was present on a side of the original 6 node triangle), remove any internal edges (but not internal nodes) and re-normalize the coordinates:

This process can be repeated indefinitely. The goal of this challenge is given an integer N representing how many times this process has been performed, output all the nodes for the associated triangle in barycentric coordinates.

Input

Your program/function should take as input a single non-negative integer N representing how many times this process has been applied. Note that for N=0, you should output the original triangle with 3 nodes.

The input may come from any source (function parameter, stdio, etc.).

Output

Your program/function should output all the nodes in normalized barycentric coordinates. The order of the nodes does not matter.
A number can be specified as a fraction (fraction reduction not required) or a floating point number. You may also output "scaled" vectors to specify a node. For example, all 3 of the following outputs are equivalent and allowed:

```<code>0.5,0.5,0

1/2,2/4,0

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

If using floating point output, your output should be accurate to within 1%. The output may be to any sink desired (stdio, return value, return parameter, etc.). Note that even though the barycentric coordinates are uniquely determined by only 2 numbers per node, you should output all 3 numbers per node.

Examples

Example cases are formatted as:

```<code>N
x0,y0,z0
x1,y1,z1
x2,y2,z2
...
</code>```

where the first line is the input N, and all following lines form a node x,y,z which should be in the output exactly once. All numbers are given as approximate floating point numbers.

```<code>0
1,0,0
0,1,0
0,0,1

1
1,0,0
0,1,0
0,0,1
0.5,0,0.5
0.5,0.5,0
0,0.5,0.5

2
1,0,0
0,1,0
0,0,1
0.667,0,0.333
0.667,0.333,0
0.333,0,0.667
0.333,0.333,0.333
0.333,0.667,0
0,0.333,0.667
0,0.667,0.333

3
1,0,0
0.75,0,0.25
0.75,0.25,0
0.5,0,0.5
0.5,0.25,0.25
0.5,0.5,0
0.25,0,0.75
0.25,0.25,0.5
0.25,0.5,0.25
0.25,0.75,0
0,0,1
0,0.25,0.75
0,0.5,0.5
0,0.75,0.25
0,1,0
</code>```

Scoring

This is code golf; shortest code in bytes wins. Standard loopholes apply. You may use any built-ins desired.

答:
Actually, 15 bytes

This uses an algorithm similar to the one in TheBikingViking's Python answer. Golfing suggestions welcome. Try it online!

```<code>u;ur♀/3@∙`Σ1=`░
</code>```

Ungolfed:

```<code>u;                Increment implicit input and duplicate.
  ur              Range [0..n+1]
    ♀/            Divide everything in range by (input+1).
      3@∙         Take the Cartesian product of 3 copies of [range divided by input+1]
         `Σ1=`    Create function that takes a list checks if sum(list) == 1.
              ░   Push values of the Cartesian product where f returns a truthy value.
</code>```

Title: My triangle needs more nodes

Body:
Actually, 15 bytes

This uses an algorithm similar to the one in TheBikingViking's Python answer. Golfing suggestions welcome. Try it online!

u;ur♀/3@∙`Σ1=`░

Ungolfed:

u;                Increment implicit input and duplicate.
  ur              Range [0..n+1]
    ♀/            Divide everything in range by (input+1).
      3@∙         Take the Cartesian product of 3 copies of [range divided by input+1]
         `Σ1=`    Create function that takes a list checks if sum(list) == 1.
              ░   Push values of the Cartesian product where f returns a truthy value.


Title: This isn't rocket science

Body:
Lua, 83, 92 bytes

function f(x)return'  |\n /_\\\n'..x:gsub('(.)',' |%1|\n')..' |_|\n/___\\\n VvV'end

print('  |\n /_\\\n'..(arg[1] and arg[1]:gsub('(.)',' |%1|\n') or '')..' |_|\n/___\\\n VvV')


答:
Jellyfish, 13 bytes

```<code>p
\Ai
&(*
><2
</code>```

Try it online!

Explanation

Let's start from the bottom up:

```<code>(*
<
</code>```

This is a hook, which defines a function f(x) = (x-1)*x.

```<code>&(*
><
</code>```

This composes the previous hook with the increment function so it gives us a function g(x) = (x-1)*x+1.

```<code>\Ai
&(*
><
</code>```

Finally, this generates a function h which is an iteration of the previous function g, as many times as given by the integer input.

```<code>\Ai
&(*
><2
</code>```

And finally, we apply this iteration to the initial value 2. The p at the top just prints the result.

Alternative (also 13 bytes)

```<code>p
>
\Ai
(*
>1
</code>```

This defers the increment until the very end.

Title: Sylvester's sequence

Body:
Jellyfish, 13 bytes

p
\Ai
&(*
><2

Try it online!

Explanation

Let's start from the bottom up:

(*
<

This is a hook, which defines a function f(x) = (x-1)*x.

&(*
><

This composes the previous hook with the increment function so it gives us a function g(x) = (x-1)*x+1.

\Ai
&(*
><

Finally, this generates a function h which is an iteration of the previous function g, as many times as given by the integer input.

\Ai
&(*
><2

And finally, we apply this iteration to the initial value 2. The p at the top just prints the result.

Alternative (also 13 bytes)

p
>
\Ai
(*
>1

This defers the increment until the very end.


Title: This isn't rocket science

Body:
Write a program or function that takes in a single-line string. You can assume it only contains printable ASCII. Print or return a string of an ASCII art rocket such as

```<code>  |
 /_\
 |E|
 |a|
 |r|
 |t|
 |h|
 |_|
/___\
 VvV
</code>```

with the input string written from top to bottom on the fuselage. In this case the input was Earth. The height of the rocket (including flames) is always the length of the string plus five.

Each line in the output may have up to two trailing spaces and there may be a single optional trailing newline. The shortest code in bytes wins.

More Examples:

```<code>[empty string]

  |
 /_\
 |_|
/___\
 VvV

a

  |
 /_\
 |a|
 |_|
/___\
 VvV

|0

  |
 /_\
 |||
 |0|
 |_|
/___\
 VvV

\/\

  |
 /_\
 |\|
 |/|
 |\|
 |_|
/___\
 VvV

 _ _ [note trailing space]

  |
 /_\
 | |
 |_|
 | |
 |_|
 | |
 |_|
/___\
 VvV

    [4 spaces]

  |
 /_\
 | |
 | |
 | |
 | |
 |_|
/___\
 VvV

SPACEY

  |
 /_\
 |S|
 |P|
 |A|
 |C|
 |E|
 |Y|
 |_|
/___\
 VvV
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Haskell, 58 bytes

f s="  |\n /_\\\n |"++((:"|\n |")=<<s)++"_|\n/___\\\n VvV"


答:
Batch, 128 bytes

```<code>@echo off
set s=%1_
echo   ^|
echo  /_\
:l
echo  ^|%s:~0,1%^|
set s=%s:~1%
if not "%s%"=="" goto l
echo /___\
echo  VvV
</code>```

Title: This isn't rocket science

Body:
Batch, 128 bytes

@echo off
set s=%1_
echo   ^|
echo  /_\
:l
echo  ^|%s:~0,1%^|
set s=%s:~1%
if not "%s%"=="" goto l
echo /___\
echo  VvV


答:
C#, <s>106</s> <s>97</s> <s>80</s> 74 bytes

```<code>s=>$@"  |
 /_\
 |{string.Join("|\n |",s.ToCharArray())}|
 |_|
/___\
 VvV";
</code>```

I don't have C# 6 to try the above but I believe it will work

Saved 7 bytes thanks to Kevin Cruijssen

Thanks to manatwork for pointing me in the right direction to save 17 bytes

Saved 6 bytes thanks to milk

Title: This isn't rocket science

Body:
C#, <s>106</s> <s>97</s> <s>80</s> 74 bytes

s=>$@"  |
 /_\
 |{string.Join("|\n |",s.ToCharArray())}|
 |_|
/___\
 VvV";

I don't have C# 6 to try the above but I believe it will work

Saved 7 bytes thanks to Kevin Cruijssen

Thanks to manatwork for pointing me in the right direction to save 17 bytes

Saved 6 bytes thanks to milk


答:
Ruby, <s>57</s> 55 bytes

-2 bytes by @ValueInk

-5 bytes by assuming that there is no newline in the input, as suggested by @manatwork. Newline-less input can be provided for example with echo -n, like echo -n hey | ruby rocket.rb.

puts'  |
 /_\
 |'+gets.chars*'|
 |'+'|
 |_|
/___\
 VvV'
```

Old version, assumes newline in input:

<h1>Ruby, <s>62</s> 60 bytes</h1>

<pre class="lang-rb prettyprint-override"><code>puts'  |
 /_\
 |'+gets.chop.chars*'|
 |'+'|
 |_|
/___\
 VvV'
</code>```

Title: This isn't rocket science

Body:
Ruby, <s>57</s> 55 bytes

-2 bytes by @ValueInk

-5 bytes by assuming that there is no newline in the input, as suggested by @manatwork. Newline-less input can be provided for example with echo -n, like echo -n hey | ruby rocket.rb.

puts'  |
 /_\
 |'+gets.chars*'|
 |'+'|
 |_|
/___\
 VvV'

Old version, assumes newline in input:

Ruby, <s>62</s> 60 bytes

puts'  |
 /_\
 |'+gets.chop.chars*'|
 |'+'|
 |_|
/___\
 VvV'


答:
Scala, 85 bytes (51?)

```<code>val s:Stream[BigInt]=2#::3#::s.tail.map{c=>c*c-c+1}
print(s.take(args(0).toInt).last)
</code>```

3 less if I stick with an Int. The stream bit which actually does all the work is 51 bytes. The rest is just printing

Usage:

```<code>$ scala sylvester.scala 20
</code>```

Title: Sylvester's sequence

Body:
Sylvester's sequence, OEIS A000058, is an integer sequence defined as follows:

Each member is the product of all previous members plus one.  The first member of the sequence is 2.

Task

Create a program to calculate the nth term of Sylvester's Sequence.  Standard input, output and loopholes apply.

Standard sequence rules apply.

This is code-golf, so the goal is to minimize the size of your source code as measured in bytes.

Test Cases

You may use either zero or one indexing. (Here I use zero indexing)

```<code>>>0
2
>>1
3
>>2
7
>>3
43
>>4
1807
</code>```

Body:
Scala, 85 bytes (51?)

val s:Stream[BigInt]=2#::3#::s.tail.map{c=>c*c-c+1}
print(s.take(args(0).toInt).last)

3 less if I stick with an Int. The stream bit which actually does all the work is 51 bytes. The rest is just printing

Usage:

$ scala sylvester.scala 20