问:
Index of a multidimensional array
Lower level languages, such as C and C++ actually have no concept of multidimensional arrays. (Other than vectors and dynamic arrays) When you create a multidimensional array with

```<code>int foo[5][10];
</code>```

This is actually just syntactic sugar. What C really does is create a single contiguous array of 5 * 10 elements. This

```<code>foo[4][2]
</code>```

is also syntactic sugar. This really refers to the element at

```<code>4 * 10 + 2
</code>```

or, the 42nd element. In general, the index of element [a][b] in array foo[x][y] is at

```<code>a * y + b
</code>```

The same concept applies to 3d arrays. If we have foo[x][y][z] and we access element [a][b][c] we are really accessing element:

```<code>a * y * z + b * z + c
</code>```

This concept applies to n-dimensional arrays. If we have an array with dimensions D1, D2, D3 ... Dn and we access element S1, S2, S3 ... Sn the formula is

```<code>(S1 * D2 * D3 ... * Dn) + (S2 * D3 * D4 ... * Dn) + (S3 * D4 ... * Dn) ... + (Sn-1 * Dn) + Sn
</code>```

The challenge

You must write a program or function that calculates the index of a multidimensional array according to the formula above. Input will be two arrays. The first array is the dimensions, and the second array is the indices. The length of these two arrays will always be equal and at least 1.

You can safely assume that every number in the arrays will be an non-negative integer. You can also assume that you will not get a 0 in the dimension array, although a 0 might be in the indices. You can also assume that indices will not be larger than the dimensions.

Test IO

```<code>Dimensions: [5, 10]
Indices: [4, 2]
Output: 42

Dimensions: [10, 10, 4, 62, 7]
Indices: [1, 2, 3, 4, 5]
Output: 22167

Dimensions: [5, 1, 10]
Indices: [3, 0, 7]
Output: 37

Dimensions: [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
Indices: [3, 1, 5, 5, 3, 0, 5, 2, 5, 4]
Output: 33570178
</code>```

答:
C#, 73 bytes

```<code>d=>i=>{int n=d.Length,x=0,y=1;for(;n>0;){x+=y*i[--n];y*=d[n];}return x;};
</code>```

Full program with test cases:

```<code>using System;

namespace IndexOfAMultidimensionalArray
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<int[],Func<int[],int>>f= d=>i=>{int n=d.Length,x=0,y=1;for(;n>0;){x+=y*i[--n];y*=d[n];}return x;};

            int[] dimensions, indices;
            dimensions =new int[]{5, 10};
            indices=new int[]{4,2};
            Console.WriteLine(f(dimensions)(indices));      //42

            dimensions=new int[]{10, 10, 4, 62, 7};
            indices=new int[]{1, 2, 3, 4, 5};
            Console.WriteLine(f(dimensions)(indices));      //22167

            dimensions=new int[]{5, 1, 10};
            indices=new int[]{3, 0, 7};
            Console.WriteLine(f(dimensions)(indices));      //37

            dimensions=new int[]{6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
            indices=new int[]{3, 1, 5, 5, 3, 0, 5, 2, 5, 4};
            Console.WriteLine(f(dimensions)(indices));      //33570178
        }
    }
}
</code>```

Title: Index of a multidimensional array

Body:
C#, 73 bytes

d=>i=>{int n=d.Length,x=0,y=1;for(;n>0;){x+=y*i[--n];y*=d[n];}return x;};

Full program with test cases:

using System;

namespace IndexOfAMultidimensionalArray
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<int[],Func<int[],int>>f= d=>i=>{int n=d.Length,x=0,y=1;for(;n>0;){x+=y*i[--n];y*=d[n];}return x;};

            int[] dimensions, indices;
            dimensions =new int[]{5, 10};
            indices=new int[]{4,2};
            Console.WriteLine(f(dimensions)(indices));      //42

            dimensions=new int[]{10, 10, 4, 62, 7};
            indices=new int[]{1, 2, 3, 4, 5};
            Console.WriteLine(f(dimensions)(indices));      //22167

            dimensions=new int[]{5, 1, 10};
            indices=new int[]{3, 0, 7};
            Console.WriteLine(f(dimensions)(indices));      //37

            dimensions=new int[]{6, 6, 6, 6, 6, 6, 6, 6, 6, 6};
            indices=new int[]{3, 1, 5, 5, 3, 0, 5, 2, 5, 4};
            Console.WriteLine(f(dimensions)(indices));      //33570178
        }
    }
}


问:
How many times will a bell tower ring?

Introduction

A bell tower will ring its bells every hour, n times, with n being the the current hour on a 12 hour clock.

For example, a bell will ring 5 times at 5pm, and 10 times at 10am.

Task

Given two times in a suitable format, output the number of times the bell will ring, inclusive of the start and end times

Examples

```<code>"10am-12pm"
10+11+12= 33

[01:00, 05:00]
1+2+3+4+5 = 15

[11, 15]
11+12+1+2+3 = 29

[10:00pm, 10:00am]
10+11+12+1+2+3+4+5+6+7+8+9+10 = 88
</code>```

If the start is the same as the end then the you simply just ouput the number of chimes for that hour:

```<code>[5pm, 5pm]
5 = 5
</code>```

As you can see, you may choose an input method but the output must be an integer on its own (or an acceptable alternative) trailing/ leading newlines and spaces are allowed.

Note:

inputs may span from the afternoon of one day to the morning of the next.

the difference between the two times will never be more than 24 hours.

input is flexible so long as you clearly state what format your input is.

your input must have a clear distinction between AM and PM.

答:
Qbasic, 112 bytes

```<code>input "",a
input "",b
do
if a=25 then a=1
if a<=12 then
c=c+a
else
c=c+a-12
endif
a=a+1
loop until a=b+1
print c
</code>```

ContentLicense: CC BY-SA 3.0

Title: How many times will a bell tower ring?

Body:
Qbasic, 112 bytes

input "",a
input "",b
do
if a=25 then a=1
if a<=12 then
c=c+a
else
c=c+a-12
endif
a=a+1
loop until a=b+1
print c


答:
Python, 73 bytes

It would be so much shorter if we didn't have to support pm to am. I use recursion to support it.

f=lambda a,b:sum([~-i%12+1for i in range(a,b+1)]*(a<b)or[f(a,24),f(1,b)])
```
<p><strong>Try it online</strong></p>
<p>Without supporting <code>pm</code> to <code>am</code> (45 bytes):</p>
<pre class="lang-python prettyprint-override"><code>lambda a,b:sum(~-i%12+1for i in range(a,b+1))
</code>```

Title: How many times will a bell tower ring?

Body:
Introduction

A bell tower will ring its bells every hour, n times, with n being the the current hour on a 12 hour clock.

For example, a bell will ring 5 times at 5pm, and 10 times at 10am.

Task

Given two times in a suitable format, output the number of times the bell will ring, inclusive of the start and end times

Examples

```<code>"10am-12pm"
10+11+12= 33

[01:00, 05:00]
1+2+3+4+5 = 15

[11, 15]
11+12+1+2+3 = 29

[10:00pm, 10:00am]
10+11+12+1+2+3+4+5+6+7+8+9+10 = 88
</code>```

If the start is the same as the end then the you simply just ouput the number of chimes for that hour:

```<code>[5pm, 5pm]
5 = 5
</code>```

As you can see, you may choose an input method but the output must be an integer on its own (or an acceptable alternative) trailing/ leading newlines and spaces are allowed.

Note:

inputs may span from the afternoon of one day to the morning of the next.

the difference between the two times will never be more than 24 hours.

input is flexible so long as you clearly state what format your input is.

your input must have a clear distinction between AM and PM.

Body:
Python, 73 bytes

It would be so much shorter if we didn't have to support pm to am. I use recursion to support it.

f=lambda a,b:sum([~-i%12+1for i in range(a,b+1)]*(a<b)or[f(a,24),f(1,b)])

Try it online

Without supporting pm to am (45 bytes):

lambda a,b:sum(~-i%12+1for i in range(a,b+1))


答:
Python 2, <s>59</s> 54 bytes

```<code>a=lambda x,y:sum(1+i%12for i in range(x-1,y+24*(x>y)))
</code>```
Equivalent to
```<code>summ=0
if start > end:
    end+=24
for hour in range(start-1,end):
    summ +=1+hour%12
print summ
</code>```

Title: How many times will a bell tower ring?

Body:
Python 2, <s>59</s> 54 bytes

a=lambda x,y:sum(1+i%12for i in range(x-1,y+24*(x>y)))

Equivalent to

summ=0
if start > end:
    end+=24
for hour in range(start-1,end):
    summ +=1+hour%12
print summ


答:
JavaScript (ES6), <s>38</s> 35 bytes

```<code>f=(x,y)=>~-x%12-~(x-y&&f(x%24+1,y))
</code>```

Recursively adds the current number of bell rings to the total. Called like f(11,15); midnight is represented as 24. I got part of the ~- trick from @xnor's Python answer.

Test snippet

f=(x,y)=>~-x%12-~(x-y&&f(x%24+1,y))
g=(x,y)=>console.log("x:",x,"y:",y,"result:",f(x,y))

g(10,12)
g(1,5)
g(11,15)
g(22,10)```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=A type="number" min=1 max=24 value=9>
<input id=B type="number" min=1 max=24 value=17>
<button onclick="g(A.value,B.value)">Run</button></code>```

Non-recursive version (Firefox 30+), 56 bytes

```<code>(x,y,t=0)=>[for(_ of Array((y-x+25)%24))t+=x++%12||12]|t
</code>```

Equivalent to the following ES6 function:

```<code>(x,y,t=0)=>[...Array((y-x+25)%24))].map(_=>t+=x++%12||12)|t
</code>```

Title: How many times will a bell tower ring?

Body:
JavaScript (ES6), <s>38</s> 35 bytes

f=(x,y)=>~-x%12-~(x-y&&f(x%24+1,y))

Recursively adds the current number of bell rings to the total. Called like f(11,15); midnight is represented as 24. I got part of the ~- trick from @xnor's Python answer.

Test snippet

f=(x,y)=>~-x%12-~(x-y&&f(x%24+1,y))
g=(x,y)=>console.log("x:",x,"y:",y,"result:",f(x,y))

g(10,12)
g(1,5)
g(11,15)
g(22,10)

<input id=A type="number" min=1 max=24 value=9>
<input id=B type="number" min=1 max=24 value=17>
<button onclick="g(A.value,B.value)">Run</button>

Non-recursive version (Firefox 30+), 56 bytes

(x,y,t=0)=>[for(_ of Array((y-x+25)%24))t+=x++%12||12]|t

Equivalent to the following ES6 function:

(x,y,t=0)=>[...Array((y-x+25)%24))].map(_=>t+=x++%12||12)|t


问:
Natural Pi #0 - Rock

Goal

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

TL;DR

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

Simulation

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

How are we simulating this?

Take input N

Do the following N times:

Uniformly generate random positive integers, i and j

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

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

Else: result = 0

Take the sum of the N results, S

Return sqrt(6 * N / S)

Specification

Input

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

Output

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

White space, trailing and leading white space is acceptable

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

Scoring

Shortest code wins!

Test Cases

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

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

答:
R, <s>103</s> <s>99</s> <s>95</s> <s>99</s> <s>98</s> 94 bytes

Can likely be golfed down a bit. Cut down 4 bytes due to @antoine-sac, and another 4 bytes by defining an alias for sample, using ^.5 instead of sqrt, and 1e6 instead of 10^6. Added 4 bytes to ensure that the sampling of i and j is truly uniform. Removed one byte after I realized that 6*N/sum(x) is the same as 6/mean(x). Used pryr::f instead of function(x,y) to save 4 bytes.

```<code>N=scan()
s=sample
g=pryr::f(ifelse(o<-x%%y,g(y,o),y))
(6/mean(g(s(1e6,N,1),s(1e6,N,1))==1))^.5
</code>```

Sample output:

```<code>N=100     -> 3.333333
N=10000   -> 3.137794
N=1000000 -> 3.141709
</code>```

Title: Natural Pi #0 - Rock

Body:
R, <s>103</s> <s>99</s> <s>95</s> <s>99</s> <s>98</s> 94 bytes

Can likely be golfed down a bit. Cut down 4 bytes due to @antoine-sac, and another 4 bytes by defining an alias for sample, using ^.5 instead of sqrt, and 1e6 instead of 10^6. Added 4 bytes to ensure that the sampling of i and j is truly uniform. Removed one byte after I realized that 6*N/sum(x) is the same as 6/mean(x). Used pryr::f instead of function(x,y) to save 4 bytes.

N=scan()
s=sample
g=pryr::f(ifelse(o<-x%%y,g(y,o),y))
(6/mean(g(s(1e6,N,1),s(1e6,N,1))==1))^.5

Sample output:

N=100     -> 3.333333
N=10000   -> 3.137794
N=1000000 -> 3.141709


答:
05AB1E, 13 bytes

With a lot of help from Emigna.

```<code>-24%Ý¹+<12%>O
</code>```

Uses the CP-1252 encoding. Try it online!

Title: How many times will a bell tower ring?

Body:
05AB1E, 13 bytes

With a lot of help from Emigna.

-24%Ý¹+<12%>O

Uses the CP-1252 encoding. Try it online!


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

```<code>>×24+⁹⁸r’%12‘S
</code>```

TryItOnline

How?

```<code>>×24+⁹⁸r’%12‘S - Main link: a, b (24 hr integers, midnight may be 0 or 24)
>              - a>b? (1 if true, 0 if false)
 ×24           - times 24 (24 if a>b, else 0)
    +⁹         - add to b (b+24 if a>b, else b)
      ⁸        - a
       r       - range(a, b+24 or b) ([a,a+1,...,b+24 or b])
        ’      - decrement (vectorises) ([a-1,a,...,b+23 or b-1])
         %12   - mod 12 (vectorises) (number of tolls at each occurrence - 1)
            ‘  - increment (vectorises) (number of tolls at each occurrence)
             S - sum
</code>```

Title: How many times will a bell tower ring?

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

>×24+⁹⁸r’%12‘S

TryItOnline

How?

>×24+⁹⁸r’%12‘S - Main link: a, b (24 hr integers, midnight may be 0 or 24)
>              - a>b? (1 if true, 0 if false)
 ×24           - times 24 (24 if a>b, else 0)
    +⁹         - add to b (b+24 if a>b, else b)
      ⁸        - a
       r       - range(a, b+24 or b) ([a,a+1,...,b+24 or b])
        ’      - decrement (vectorises) ([a-1,a,...,b+23 or b-1])
         %12   - mod 12 (vectorises) (number of tolls at each occurrence - 1)
            ‘  - increment (vectorises) (number of tolls at each occurrence)
             S - sum


答:
Python 2, 46 bytes

```<code>f=lambda x,y:(x%12or 12)+(x-y and f(-~x%24,y))
</code>```

Based on my JS answer. The recursive formula f for the solution is defined as so:

Start with two integers x and y.

Take x mod 12; if this is 0, take 12 instead.

If x != y, add the result of f(x+1 mod 24, y).

Title: How many times will a bell tower ring?

Body:
Python 2, 46 bytes

f=lambda x,y:(x%12or 12)+(x-y and f(-~x%24,y))

Based on my JS answer. The recursive formula f for the solution is defined as so:

Start with two integers x and y.

Take x mod 12; if this is 0, take 12 instead.

If x != y, add the result of f(x+1 mod 24, y).


答:
05AB1E, 12 bytes

Uses CP-1252 encoding.

```<code>CÐ<^¹SOÉ*>^b
</code>```

Try it online!

Explanation

Example for input 1011.

```<code>C              # convert to int (bigint if necessary)
               # STACK: 11
 Ð             # triplicate
               # STACK: 11, 11, 11
  <            # decrease by 1
               # STACK: 11, 11, 10
   ^           # XOR
               # STACK: 11, 1
    ¹          # push first input
               # STACK: 11, 1, 1011
     S         # split to list
               # STACK: 11, 1, [1,0,1,1]
      O        # sum
               # STACK: 11, 1, 3
       É       # mod 2
               # STACK: 11, 1, 1
        *      # multiply
               # STACK: 11, 1
         >     # increase by 1
               # STACK: 11, 2
          ^    # XOR
               # STACK: 9
           b   # convert to binary
               # STACK: 1001
               # implicitly print top of stack
</code>```

Title: Incrementing Gray Codes

Body:
Introduction

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

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

Cyclic Bit Pattern of a Gray Code

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

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

...and so on.

Objective

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

Caveats

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

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

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

I/O formats

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

most significant "bit" first

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

non-padded integer array of 1s and 0s

non-padded boolean array

What's not allowed:

least significant "bit" first

decimal, binary or unary integer

fixed-length data-structure

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

Tests

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

More tests can be added by request.

Criteria

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

Body:
05AB1E, 12 bytes

Uses CP-1252 encoding.

CÐ<^¹SOÉ*>^b

Try it online!

Explanation

Example for input 1011.

C              # convert to int (bigint if necessary)
               # STACK: 11
 Ð             # triplicate
               # STACK: 11, 11, 11
  <            # decrease by 1
               # STACK: 11, 11, 10
   ^           # XOR
               # STACK: 11, 1
    ¹          # push first input
               # STACK: 11, 1, 1011
     S         # split to list
               # STACK: 11, 1, [1,0,1,1]
      O        # sum
               # STACK: 11, 1, 3
       É       # mod 2
               # STACK: 11, 1, 1
        *      # multiply
               # STACK: 11, 1
         >     # increase by 1
               # STACK: 11, 2
          ^    # XOR
               # STACK: 9
           b   # convert to binary
               # STACK: 1001
               # implicitly print top of stack


答:
Python, 42 bytes

f=lambda a,b:~-a%12-~(b-a and f(-~a%24,b))
```

<p>A recursive function that takes two numbers from 0 to 23. Expanding the <code>~x</code>'s to <code>-x-1</code> gives</p>

<pre class="lang-python prettyprint-override"><code>f=lambda a,b:(a-1)%12+1+(b-a and f((a+1)%24,b))
</code>```

The expression (a+1)%12+1 converts a time to the number of rings 1 to 12. Then, the lower bound is incremented modulo 24 and the function for the recursive result is added. That is, unless the current hour is the end hour, in which case we stop.

I've been trying to write a purely arithmetical solution instead, but so far I've only found long and messy expressions.

Title: How many times will a bell tower ring?

Body:
Python, 42 bytes

f=lambda a,b:~-a%12-~(b-a and f(-~a%24,b))

A recursive function that takes two numbers from 0 to 23. Expanding the ~x's to -x-1 gives

f=lambda a,b:(a-1)%12+1+(b-a and f((a+1)%24,b))

The expression (a+1)%12+1 converts a time to the number of rings 1 to 12. Then, the lower bound is incremented modulo 24 and the function for the recursive result is added. That is, unless the current hour is the end hour, in which case we stop.

I've been trying to write a purely arithmetical solution instead, but so far I've only found long and messy expressions.


Title: Index of a multidimensional array

Body:
Lower level languages, such as C and C++ actually have no concept of multidimensional arrays. (Other than vectors and dynamic arrays) When you create a multidimensional array with

```<code>int foo[5][10];
</code>```

This is actually just syntactic sugar. What C really does is create a single contiguous array of 5 * 10 elements. This

```<code>foo[4][2]
</code>```

is also syntactic sugar. This really refers to the element at

```<code>4 * 10 + 2
</code>```

or, the 42nd element. In general, the index of element [a][b] in array foo[x][y] is at

```<code>a * y + b
</code>```

The same concept applies to 3d arrays. If we have foo[x][y][z] and we access element [a][b][c] we are really accessing element:

```<code>a * y * z + b * z + c
</code>```

This concept applies to n-dimensional arrays. If we have an array with dimensions D1, D2, D3 ... Dn and we access element S1, S2, S3 ... Sn the formula is

```<code>(S1 * D2 * D3 ... * Dn) + (S2 * D3 * D4 ... * Dn) + (S3 * D4 ... * Dn) ... + (Sn-1 * Dn) + Sn
</code>```

The challenge

You must write a program or function that calculates the index of a multidimensional array according to the formula above. Input will be two arrays. The first array is the dimensions, and the second array is the indices. The length of these two arrays will always be equal and at least 1.

You can safely assume that every number in the arrays will be an non-negative integer. You can also assume that you will not get a 0 in the dimension array, although a 0 might be in the indices. You can also assume that indices will not be larger than the dimensions.

Test IO

```<code>Dimensions: [5, 10]
Indices: [4, 2]
Output: 42

Dimensions: [10, 10, 4, 62, 7]
Indices: [1, 2, 3, 4, 5]
Output: 22167

Dimensions: [5, 1, 10]
Indices: [3, 0, 7]
Output: 37

Dimensions: [6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
Indices: [3, 1, 5, 5, 3, 0, 5, 2, 5, 4]
Output: 33570178
</code>```

Body:
Racket 76 bytes

(λ(l i(s 0))(if(null? i)s(f(cdr l)(cdr i)(+ s(*(car i)(apply *(cdr l)))))))

Ungolfed:

(define f
  (λ (ll il (sum 0))
    (if (null? il)
        sum
        (f (rest ll)
           (rest il)
           (+ sum
              (* (first il)
                 (apply * (rest ll))))))))

Testing:

(f '(5 10) '(4 2))
(f '(10 10 4 62 7) '(1 2 3 4 5))
(f '(5 1 10) '(3 0 7))

Output:

42
22167
37


答:
PHP, 90 Bytes

Input format '[1,24]' between 1 and 24

In this challenge that I am hate why PHP loose against other languages. I prefer to show all my ideas. Maybe an other PHP Crack finds a shorter solution.

```<code><?list($f,$g)=$_GET[b];for($i=$f;$i-1!=$g|$f>$g&!$c;$s+=$i++%12?:12)$i<25?:$c=$i=1;echo$s;
</code>```

99 Bytes

```<code><?for($i=($b=$_GET[b])[0],$c=($d=$b[1]-$b[0])<0?25+$d:$d+1;$c--;$s+=$i++%12?:12)$i<25?:$i=1;echo$s;
</code>```

113 Bytes a way with min and max

```<code><?for($i=min($b=$_GET[b]);$i<=$m=max($b);)$s+=$i++%12?:12;echo($b[0]>$b[1])?156-$s+($m%12?:12)+($b[1]%12?:12):$s;
</code>```

okay this crazy idea works with an array 149 Bytes
fills the array $y[0] and $y[1] if $_GET["b"][0]<=$_GET["b"][1]
if $y[1] is null we can sum this array array_diff_key($y[0],array_slice($y[0],$b[1],$b[0]-$b[1]-1,1))

```<code><?for(;++$i<25;)$y[$i>=($b=$_GET[b])[0]&$i<=$b[1]][$i]=$i%12?:12;echo array_sum($y[1]??array_diff_key($y[0],array_slice($y[0],$b[1],$b[0]-$b[1]-1,1)));
</code>```

This could be golfed down 124 Bytes

```<code><?for(;++$i<25;)$x[($v=($b=$_GET[b])[0]>$b[1])?$i<$b[0]&$i>$b[1]:$i>=$b[0]&$i<=$b[1]][$i]=$i%12?:12;echo array_sum($x[!$v]);
</code>```

Now at this point we can reduce the array with only two ints 101 Bytes
Make 2 sums $x[0] and $x[1]

list($f,$g)=$_GET[b];

if $v=($f>$g
then add value to $x[$i<$f&$i>$g]
else add value to $x[$i>=$f&$i<=$g]
the output will be find by case echo$x[!$v];

```<code><?list($f,$g)=$_GET[b];for(;++$i<25;)$x[($v=$f>$g)?$i<$f&$i>$g:$i>=$f&$i<=$g]+=$i%12?:12;echo$x[!$v];
</code>```

After that i found a way to calculate the result directly 112 Bytes

```<code><?list($x,$y)=$_GET[t];echo(($b=$x>$y)+(($x-($s=$x%12?:12)^$y-($t=$y%12?:12))xor$b))*78-($s*($s-1)-$t*($t+1))/2;
</code>```

recursive 103 Bytes

```<code><?list($x,$y)=$_GET[t];function f($x,$y){return($x%12?:12)+($x-$y?f(++$x<25?$x:1,$y):0);}echo f($x,$y);
</code>```

Title: How many times will a bell tower ring?

Body:
PHP, 90 Bytes

Input format '[1,24]' between 1 and 24

In this challenge that I am hate why PHP loose against other languages. I prefer to show all my ideas. Maybe an other PHP Crack finds a shorter solution.

<?list($f,$g)=$_GET[b];for($i=$f;$i-1!=$g|$f>$g&!$c;$s+=$i++%12?:12)$i<25?:$c=$i=1;echo$s;

99 Bytes

<?for($i=($b=$_GET[b])[0],$c=($d=$b[1]-$b[0])<0?25+$d:$d+1;$c--;$s+=$i++%12?:12)$i<25?:$i=1;echo$s;

113 Bytes a way with min and max

<?for($i=min($b=$_GET[b]);$i<=$m=max($b);)$s+=$i++%12?:12;echo($b[0]>$b[1])?156-$s+($m%12?:12)+($b[1]%12?:12):$s;

okay this crazy idea works with an array 149 Bytes
fills the array $y[0] and $y[1] if $_GET["b"][0]<=$_GET["b"][1]
if $y[1] is null we can sum this array array_diff_key($y[0],array_slice($y[0],$b[1],$b[0]-$b[1]-1,1))

<?for(;++$i<25;)$y[$i>=($b=$_GET[b])[0]&$i<=$b[1]][$i]=$i%12?:12;echo array_sum($y[1]??array_diff_key($y[0],array_slice($y[0],$b[1],$b[0]-$b[1]-1,1)));

This could be golfed down 124 Bytes

<?for(;++$i<25;)$x[($v=($b=$_GET[b])[0]>$b[1])?$i<$b[0]&$i>$b[1]:$i>=$b[0]&$i<=$b[1]][$i]=$i%12?:12;echo array_sum($x[!$v]);

Now at this point we can reduce the array with only two ints 101 Bytes
Make 2 sums $x[0] and $x[1]

list($f,$g)=$_GET[b];

if $v=($f>$g
then add value to $x[$i<$f&$i>$g]
else add value to $x[$i>=$f&$i<=$g]
the output will be find by case echo$x[!$v];

<?list($f,$g)=$_GET[b];for(;++$i<25;)$x[($v=$f>$g)?$i<$f&$i>$g:$i>=$f&$i<=$g]+=$i%12?:12;echo$x[!$v];

After that i found a way to calculate the result directly 112 Bytes

<?list($x,$y)=$_GET[t];echo(($b=$x>$y)+(($x-($s=$x%12?:12)^$y-($t=$y%12?:12))xor$b))*78-($s*($s-1)-$t*($t+1))/2;

recursive 103 Bytes

<?list($x,$y)=$_GET[t];function f($x,$y){return($x%12?:12)+($x-$y?f(++$x<25?$x:1,$y):0);}echo f($x,$y);


问:
Display Peter's keyboard pattern
Assume an simple keyboard with this layout:

```<code>1 2 3 4 5 6 7 8 9 0
A B C D E F G H I J
K L M N O P Q R S T
U V W X Y Z . , ? !
</code>```

Peter's keyboard pattern can be generated by starting at the top left of the keyboard, and displays the first three characters and a newline. It shifts over one character and displays the second, third, and fourth key. Once it reaches the end of a row it continues at the end of the next row and goes backwards, until it reaches the start of that row and then goes forward on the next row, and so on until it reaches the beginning of the last row.

This is Peter's keyboard pattern:

```<code>123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU
</code>```

Write a program which accepts no input and displays Peter's keyboard pattern. The program must be smaller than 152 bytes, i.e. the size of the string it outputs.

This is code golf, so the shortest solution wins.

答:
///, 151 bytes

```<code>123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU
</code>```

Try it online!

Can't golf it more? This is, in a sense, <152 bytes.

Title: Display Peter's keyboard pattern

Body:
///, 151 bytes

123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU

Try it online!

Can't golf it more? This is, in a sense, <152 bytes.


答:
Jelly, <s>41</s> 40 bytes

```<code>ØAḣ⁵Ṛ
ØDṫ2;0;¢;“KLMNOPQRST!?,.ZYXWVU”ṡ3Y
</code>```

Try it online!

Might (still) be golfable...

Title: Display Peter's keyboard pattern

Body:
Assume an simple keyboard with this layout:

```<code>1 2 3 4 5 6 7 8 9 0
A B C D E F G H I J
K L M N O P Q R S T
U V W X Y Z . , ? !
</code>```

Peter's keyboard pattern can be generated by starting at the top left of the keyboard, and displays the first three characters and a newline. It shifts over one character and displays the second, third, and fourth key. Once it reaches the end of a row it continues at the end of the next row and goes backwards, until it reaches the start of that row and then goes forward on the next row, and so on until it reaches the beginning of the last row.

This is Peter's keyboard pattern:

```<code>123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU
</code>```

Write a program which accepts no input and displays Peter's keyboard pattern. The program must be smaller than 152 bytes, i.e. the size of the string it outputs.

This is code golf, so the shortest solution wins.

Body:
Jelly, <s>41</s> 40 bytes

ØAḣ⁵Ṛ
ØDṫ2;0;¢;“KLMNOPQRST!?,.ZYXWVU”ṡ3Y

Try it online!

Might (still) be golfable...


答:
Haskell, 80

```<code>mapM_(putStrLn.take 3.(`drop`"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"))[0..37]
</code>```

Title: Display Peter's keyboard pattern

Body:
Haskell, 80

mapM_(putStrLn.take 3.(`drop`"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"))[0..37]


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

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

Input:

Your program/function accepts a positive integer or decimal.

Output:

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

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

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

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

Challenge rules:

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

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

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

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

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

General rules:

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

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

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

Default Loopholes are forbidden.

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

Also, please add an explanation if necessary.

Test cases:

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

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

答:
Logy, 74 bytes

```<code>m[X,Y]->X>Y&X|Y;f[X]->include["@stdlib.logy"]~X==ceil[X]&m[X,18]|m[X,1.4];
</code>```

Wow... Outgolfed by Java

```<code>max[X, Y] -> X > Y & X | Y;
f[X] -> include["@stdlib.logy"]
      ~ X == ceil[X] & max[X, 18] | max[X, 1.4];
</code>```

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

Body:
Logy, 74 bytes

m[X,Y]->X>Y&X|Y;f[X]->include["@stdlib.logy"]~X==ceil[X]&m[X,18]|m[X,1.4];

Wow... Outgolfed by Java

max[X, Y] -> X > Y & X | Y;
f[X] -> include["@stdlib.logy"]
      ~ X == ceil[X] & max[X, 18] | max[X, 1.4];

ContentLicense: CC BY-SA 4.0


答:
QBIC, <s>90</s> 47 bytes

So, here's the answer printing only the total number of bell-rings:

```<code>::{c=a~c>12|c=c-12]d=d+c~a=b|_Xd]a=a+1~a>24|a=1
</code>```

Input is in range 1-24; a and b are the inputs (:: in the code), c keeps track of am/pm, d is the total number of rings. When we've counted down all the hours, _Xd terminates the program, printing d in the process.

OK, I misunderstood the question and thought the 1+2+3...= text was part of the output, so I wrote that:

```<code>::{c=a~c>12|c=c-12]X=!c$Z=Z+X+@+| d=d+c~a=b|?left$$|(Z,len(Z)-1)+@ =|+!d$_X]a=a+1~a>24|a=1
</code>```

Now, I'll go code the proper answer...

Title: How many times will a bell tower ring?

Body:
Introduction

A bell tower will ring its bells every hour, n times, with n being the the current hour on a 12 hour clock.

For example, a bell will ring 5 times at 5pm, and 10 times at 10am.

Task

Given two times in a suitable format, output the number of times the bell will ring, inclusive of the start and end times

Examples

```<code>"10am-12pm"
10+11+12= 33

[01:00, 05:00]
1+2+3+4+5 = 15

[11, 15]
11+12+1+2+3 = 29

[10:00pm, 10:00am]
10+11+12+1+2+3+4+5+6+7+8+9+10 = 88
</code>```

If the start is the same as the end then the you simply just ouput the number of chimes for that hour:

```<code>[5pm, 5pm]
5 = 5
</code>```

As you can see, you may choose an input method but the output must be an integer on its own (or an acceptable alternative) trailing/ leading newlines and spaces are allowed.

Note:

inputs may span from the afternoon of one day to the morning of the next.

the difference between the two times will never be more than 24 hours.

input is flexible so long as you clearly state what format your input is.

your input must have a clear distinction between AM and PM.

Body:
QBIC, <s>90</s> 47 bytes

So, here's the answer printing only the total number of bell-rings:

::{c=a~c>12|c=c-12]d=d+c~a=b|_Xd]a=a+1~a>24|a=1

Input is in range 1-24; a and b are the inputs (:: in the code), c keeps track of am/pm, d is the total number of rings. When we've counted down all the hours, _Xd terminates the program, printing d in the process.

OK, I misunderstood the question and thought the 1+2+3...= text was part of the output, so I wrote that:

::{c=a~c>12|c=c-12]X=!c$Z=Z+X+@+| d=d+c~a=b|?left$$|(Z,len(Z)-1)+@ =|+!d$_X]a=a+1~a>24|a=1

Now, I'll go code the proper answer...


问:
Let's draw some Atari ST bombs!

Introduction

The Atari ST was a rather popular personal computer from the mid 80's to early 90's era, powered by a Motorola 68000 microprocessor. On this machine, the default behavior of the operating system for uncaught CPU exceptions was to display a row of bombs on the screen, as shown in the following picture:

Source: https://commons.wikimedia.org/wiki/File:Row_of_bombs.png

NB: Depending on the OS version, the bomb graphics may vary slightly. But let's take this one as reference.

The number of bombs depends on the exception vector, the most common ones being:

($008) Bus Error : 2 bombs

($00c) Address Error : 3 bombs

($010) Illegal Instruction : 4 bombs

Goal

Your goal is to write a program or function that prints or outputs an ASCII art of such Atari ST bombs.

Input

An integer representing the number of bombs to display. Your code must support the most common values: 2, 3 and 4. Supporting less and/or more bombs is fine, but it is neither required nor subject to a bonus.

Output

The original bomb consists of a 16x16 pixel tile, represented here in both ASCII and binary:

```<code>....##..........    0000110000000000
.#.#..#.........    0101001000000000
.......#........    0000000100000000
#..#....#.......    1001000010000000
..#...#####.....    0010001111100000
......#####.....    0000001111100000
....#########...    0000111111111000
...###########..    0001111111111100
...###########..    0001111111111100
..#############.    0011111111111110
..########.####.    0011111111011110
...#######.###..    0001111111011100
...######.####..    0001111110111100
....#########...    0000111111111000
.....#######....    0000011111110000
.......###......    0000000111000000
</code>```

In this challenge, each ASCII bomb must be stretched to twice its original width for a better rendering. Therefore, it will consist of 16 rows of 32 characters, using ## for 'ON' pixels and two spaces for 'OFF' pixels. All bomb tiles must be put side by side. Leading spaces are forbidden. Trailing spaces are also forbidden, except the ones that are actually part of the bomb tile (i.e. the 31st and 32nd columns) which must be present. You may include no more than one leading line-break and no more than one trailing line-break.

Example

Below is the reference output for two bombs, where mandatory line-breaks are marked as \n and tolerated extra line-breaks are marked as (\n):

```<code>(\n)
        ####                            ####                    \n
  ##  ##    ##                    ##  ##    ##                  \n
              ##                              ##                \n
##    ##        ##              ##    ##        ##              \n
    ##      ##########              ##      ##########          \n
            ##########                      ##########          \n
        ##################              ##################      \n
      ######################          ######################    \n
      ######################          ######################    \n
    ##########################      ##########################  \n
    ################  ########      ################  ########  \n
      ##############  ######          ##############  ######    \n
      ############  ########          ############  ########    \n
        ##################              ##################      \n
          ##############                  ##############        \n
              ######                          ######            (\n)
</code>```

(Of course, other line-break formats such as \r or \r\n may be used just as well.)

Rules

This is code-golf, so the shortest answer in bytes wins. Standard loopholes are forbidden.

Title: Let's draw some Atari ST bombs!

Body:
Pyth, <s>57</s> <s>56</s> <s>54</s> <s>53</s> <s>51</s> 50 bytes

The code contains unprintable characters, so here's a reversible xxd hexdump.

00000000: 6a2a 4c51 6331 3673 2e65 2a79 6240 2220  j*LQc16s.e*yb@"
00000010: 2322 6b6a 4322 4c49 c142 3c60 0cca 9437  #"kjC"LI.B<`...7
00000020: b383 76bb c246 c86d 4c04 99bd 3614 7022  ..v..F.mL...6.p"
00000030: 3137                                     17

Try it online.


答:
JavaScript (ES6), <s>159</s> <s>154</s> <s>140</s> 136 bytes

Saved lots of bytes thanks to @Hedi and @Arnauld

```<code>n=>[..."ￏﾵｿﻶ쀇쀇考萃쐇숇ﱿ"].map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(x.charCodeAt()).repeat(n)).join`
`
</code>```

That's 104 chars, but (sadly) 136 UTF-8 bytes. The string was generated with this snippet:

console.log([
0b1111111111001111,
0b1111111110110101,
0b1111111101111111,
0b1111111011110110,
0b1111100000111011,
0b1111100000111111,
0b1110000000001111,
0b1100000000000111,
0b1100000000000111,
0b1000000000000011,
0b1000010000000011,
0b1100010000000111,
0b1100001000000111,
0b1110000000001111,
0b1111000000011111,
0b1111110001111111
].map(x=>(65535-x).toString(16)).join(","))```
</div>
</div>
</p>

<p>Using <code>.replace</code> instead of <code>[...string].map</code> is equally long:</p>

```n=>"ￏﾵｿﻶ쀇쀇考萃쐇숇ﱿ".replace(/./g,x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(x.charCodeAt()).repeat(n)+`
`)
```

<h3>How it works</h3>

<p>Since each row of the raw data can be represented as a 16-bit number, we can store the entire file in a 16-char string. The compression algorithm takes each binary row, flips it and reverses it (since every row in the original ends in a <strong>0</strong>, every row in the modified version now <em>starts</em> with a <strong>1</strong>), then turns it into a char, and concatenates the resulting characters.</p>

<p>To decompress it, we need to extract the charcode and turn its binary representation into a string of hashes and spaces. This can be done with a recursive function, like so:</p>

```(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(x.charCodeAt())
```

<p><code>f</code> repeatedly takes the last bit of <code>q</code>, selecting two spaces if it's 1 or two hashes if it's 0, then concatenates that with the result of running <code>f</code> in the rest of <code>q</code>. This is run on <code>x.charCodeAt()</code>, turning the char-code into the correct string of spaces and hashes.</p>

<p>(There was a lot more drama here before, but the 4-byte-saving technique erased all of that.)</p>

<p>After that, we can just repeat the string <code>n</code> times and add a newline. This is the shortest decompression method I have found, but feel free to suggest any possibly shorter methods.</p>

<p>Other attempts at compressing the string:</p>

```n=>[48,74,128,265,1988,1984,8176,16376,16376,32764,31740,15352,15864,8176,4064,896].map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(65535-x).repeat(n)).join`
`
n=>"1c,22,3k,7d,1j8,1j4,6b4,cmw,cmw,pa4,oho,bug,c8o,6b4,34w,ow".split`,`.map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(65535-parseInt(x,36)).repeat(n)).join`
`
n=>"30,4a,80,109,7c4,7c0,1ff0,3ff8,3ff8,7ffc,7bfc,3bf8,3df8,1ff0,fe0,380".split`,`.map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")('0x'+x^65535)).repeat(n)).join`
`
```

The first of these is 153 bytes, so none of them come anywhere near 136...

Title: Let's draw some Atari ST bombs!

Body:
Introduction

The Atari ST was a rather popular personal computer from the mid 80's to early 90's era, powered by a Motorola 68000 microprocessor. On this machine, the default behavior of the operating system for uncaught CPU exceptions was to display a row of bombs on the screen, as shown in the following picture:

Source: https://commons.wikimedia.org/wiki/File:Row_of_bombs.png

NB: Depending on the OS version, the bomb graphics may vary slightly. But let's take this one as reference.

The number of bombs depends on the exception vector, the most common ones being:

($008) Bus Error : 2 bombs

($00c) Address Error : 3 bombs

($010) Illegal Instruction : 4 bombs

Goal

Your goal is to write a program or function that prints or outputs an ASCII art of such Atari ST bombs.

Input

An integer representing the number of bombs to display. Your code must support the most common values: 2, 3 and 4. Supporting less and/or more bombs is fine, but it is neither required nor subject to a bonus.

Output

The original bomb consists of a 16x16 pixel tile, represented here in both ASCII and binary:

```<code>....##..........    0000110000000000
.#.#..#.........    0101001000000000
.......#........    0000000100000000
#..#....#.......    1001000010000000
..#...#####.....    0010001111100000
......#####.....    0000001111100000
....#########...    0000111111111000
...###########..    0001111111111100
...###########..    0001111111111100
..#############.    0011111111111110
..########.####.    0011111111011110
...#######.###..    0001111111011100
...######.####..    0001111110111100
....#########...    0000111111111000
.....#######....    0000011111110000
.......###......    0000000111000000
</code>```

In this challenge, each ASCII bomb must be stretched to twice its original width for a better rendering. Therefore, it will consist of 16 rows of 32 characters, using ## for 'ON' pixels and two spaces for 'OFF' pixels. All bomb tiles must be put side by side. Leading spaces are forbidden. Trailing spaces are also forbidden, except the ones that are actually part of the bomb tile (i.e. the 31st and 32nd columns) which must be present. You may include no more than one leading line-break and no more than one trailing line-break.

Example

Below is the reference output for two bombs, where mandatory line-breaks are marked as \n and tolerated extra line-breaks are marked as (\n):

```<code>(\n)
        ####                            ####                    \n
  ##  ##    ##                    ##  ##    ##                  \n
              ##                              ##                \n
##    ##        ##              ##    ##        ##              \n
    ##      ##########              ##      ##########          \n
            ##########                      ##########          \n
        ##################              ##################      \n
      ######################          ######################    \n
      ######################          ######################    \n
    ##########################      ##########################  \n
    ################  ########      ################  ########  \n
      ##############  ######          ##############  ######    \n
      ############  ########          ############  ########    \n
        ##################              ##################      \n
          ##############                  ##############        \n
              ######                          ######            (\n)
</code>```

(Of course, other line-break formats such as \r or \r\n may be used just as well.)

Rules

This is code-golf, so the shortest answer in bytes wins. Standard loopholes are forbidden.

Body:
JavaScript (ES6), <s>159</s> <s>154</s> <s>140</s> 136 bytes

Saved lots of bytes thanks to @Hedi and @Arnauld

n=>[..."ￏﾵｿﻶ쀇쀇考萃쐇숇ﱿ"].map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(x.charCodeAt()).repeat(n)).join`
`

That's 104 chars, but (sadly) 136 UTF-8 bytes. The string was generated with this snippet:

console.log([
0b1111111111001111,
0b1111111110110101,
0b1111111101111111,
0b1111111011110110,
0b1111100000111011,
0b1111100000111111,
0b1110000000001111,
0b1100000000000111,
0b1100000000000111,
0b1000000000000011,
0b1000010000000011,
0b1100010000000111,
0b1100001000000111,
0b1110000000001111,
0b1111000000011111,
0b1111110001111111
].map(x=>(65535-x).toString(16)).join(","))

Using .replace instead of [...string].map is equally long:

n=>"ￏﾵｿﻶ쀇쀇考萃쐇숇ﱿ".replace(/./g,x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(x.charCodeAt()).repeat(n)+`
`)

How it works

Since each row of the raw data can be represented as a 16-bit number, we can store the entire file in a 16-char string. The compression algorithm takes each binary row, flips it and reverses it (since every row in the original ends in a 0, every row in the modified version now starts with a 1), then turns it into a char, and concatenates the resulting characters.

To decompress it, we need to extract the charcode and turn its binary representation into a string of hashes and spaces. This can be done with a recursive function, like so:

(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(x.charCodeAt())

f repeatedly takes the last bit of q, selecting two spaces if it's 1 or two hashes if it's 0, then concatenates that with the result of running f in the rest of q. This is run on x.charCodeAt(), turning the char-code into the correct string of spaces and hashes.

(There was a lot more drama here before, but the 4-byte-saving technique erased all of that.)

After that, we can just repeat the string n times and add a newline. This is the shortest decompression method I have found, but feel free to suggest any possibly shorter methods.

Other attempts at compressing the string:

n=>[48,74,128,265,1988,1984,8176,16376,16376,32764,31740,15352,15864,8176,4064,896].map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(65535-x).repeat(n)).join`
`
n=>"1c,22,3k,7d,1j8,1j4,6b4,cmw,cmw,pa4,oho,bug,c8o,6b4,34w,ow".split`,`.map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")(65535-parseInt(x,36)).repeat(n)).join`
`
n=>"30,4a,80,109,7c4,7c0,1ff0,3ff8,3ff8,7ffc,7bfc,3bf8,3df8,1ff0,fe0,380".split`,`.map(x=>(f=q=>q?(q&1?"  ":"##")+f(q>>1):"")('0x'+x^65535)).repeat(n)).join`
`

The first of these is 153 bytes, so none of them come anywhere near 136...


答:
Pyth - 11 bytes

```<code>s|R12%R12}F
</code>```

Test Suite.

Title: How many times will a bell tower ring?

Body:
Pyth - 11 bytes

s|R12%R12}F

Test Suite.


答:
Batch, <s>199</s> 197 bytes

```<code>@echo off
set/ps=
set r=
set t=%s:0=%
if 1%t:11=%==1 goto g
:l
set b=%s:~-1%
set s=%s:~,-1%
set r=%b%%r%
if %b%==0 goto l
if 0%s%==0 set s=0
:g
set/ab=1-%s:~-1%
echo %s:~,-1%%b%%r%
</code>```

Reads input from STDIN into variable s. Removes the 0s and does a parity check on the 1s and if there are an odd number it strips the rightmost 0s in a loop, stopping when it strips a 1. s therefore contains the even parity prefix and r the rest of the string. s is set to zero if it was blank so that its last digit can be toggled, and then everything is concatenated.

Title: Incrementing Gray Codes

Body:
Introduction

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

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

Cyclic Bit Pattern of a Gray Code

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

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

...and so on.

Objective

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

Caveats

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

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

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

I/O formats

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

most significant "bit" first

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

non-padded integer array of 1s and 0s

non-padded boolean array

What's not allowed:

least significant "bit" first

decimal, binary or unary integer

fixed-length data-structure

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

Tests

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

More tests can be added by request.

Criteria

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

Body:
Batch, <s>199</s> 197 bytes

@echo off
set/ps=
set r=
set t=%s:0=%
if 1%t:11=%==1 goto g
:l
set b=%s:~-1%
set s=%s:~,-1%
set r=%b%%r%
if %b%==0 goto l
if 0%s%==0 set s=0
:g
set/ab=1-%s:~-1%
echo %s:~,-1%%b%%r%

Reads input from STDIN into variable s. Removes the 0s and does a parity check on the 1s and if there are an odd number it strips the rightmost 0s in a loop, stopping when it strips a 1. s therefore contains the even parity prefix and r the rest of the string. s is set to zero if it was blank so that its last digit can be toggled, and then everything is concatenated.


问:
Divisibility test

Task

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

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

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

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

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

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

Test cases

```<code> n,  d    output

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

Leaderboard

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
MIXAL, 105 bytes

Not counting bytes for 17 and 8 in the first two lines, which are used for input. Replace with any desired n and d.

Outputs 0 for true and 1 for false.

```<code>N       EQU     17
D       EQU     8
S       LDX     =N=
        DIV     =D=
        ENTA    30
        JXZ     T
        INCA    1
T       STA     9
        OUT     9(19)
        HLT
        END     S
</code>```

Commented version:

```<code>N       EQU     17      Constants used for input
D       EQU     8
START   LDX     =N=     Put value 'n' into rX
        DIV     =D=     Divide rAX by value 'd'; rA <= quotient; rX <= remainder
        ENTA    30      Replace rA value with character code for '0'
        JXZ     T       If rX == 0, then d is a divisor of n, go to 'T'
        INCA    1       Else (there is a remainder), add 1 to rA charcode for '1'
T       STA     9       Store rA charcode at address 9 (after end of program)
        OUT     9(19)   Send contents starting at address 9 to TTY output device
        HLT
        END     START
</code>```

Title: Divisibility test

Body:
MIXAL, 105 bytes

Not counting bytes for 17 and 8 in the first two lines, which are used for input. Replace with any desired n and d.

Outputs 0 for true and 1 for false.

N       EQU     17
D       EQU     8
S       LDX     =N=
        DIV     =D=
        ENTA    30
        JXZ     T
        INCA    1
T       STA     9
        OUT     9(19)
        HLT
        END     S

Commented version:

N       EQU     17      Constants used for input
D       EQU     8
START   LDX     =N=     Put value 'n' into rX
        DIV     =D=     Divide rAX by value 'd'; rA <= quotient; rX <= remainder
        ENTA    30      Replace rA value with character code for '0'
        JXZ     T       If rX == 0, then d is a divisor of n, go to 'T'
        INCA    1       Else (there is a remainder), add 1 to rA charcode for '1'
T       STA     9       Store rA charcode at address 9 (after end of program)
        OUT     9(19)   Send contents starting at address 9 to TTY output device
        HLT
        END     START


答:
05AB1E, <s>57</s> <s>55</s> <s>53</s> 50 bytes

Uses CP-1252 encoding.

```<code>•ø6ŒY2l½î€ÈS`L<eÆô‚˜3ª½¨ºE»D2Âô3•b15ôvy1J€D„# è¹×,
</code>```

Try it online!

Explanation

As the output image only consists of 2 characters we can represent it as a binary number.

We can ignore newlines as every line has the same length.

We can ignore the last char of each row as it the same for all rows.

We use the thinner image as it takes up less space and we can easily duplicate each character later.

Using 1 to represent space and 0 to represent # we get the binary number:

111100111111111101011011111111111111101111111011011110111111110111000001111111111000001111111100000000011111000000000001111000000000001110000000000000110000000010000111000000010001111000000100001111100000000011111110000000111111111100011111

We then convert this to base-10 and then compress it to base 214, the maximum base in 05AB1E. The result of this is:

```<code>•ø6ŒY2l½î€ÈS`L<eÆô‚˜3ª½¨ºE»D2Âô3•
</code>```

The meat of the program then consist of the following:

```<code><base encoded string>
  b                     # convert to binary
   15ô                  # slice into pieces of 15
      v                 # for each slice
       1J               # append a 1
         €D             # duplicate each character
           „#           # push the string "# "
             è          # use the list of binary digits to index into the string
              ¹×        # repeat string input number of times
                ,       # and print with newline
</code>```

Title: Let's draw some Atari ST bombs!

Body:
05AB1E, <s>57</s> <s>55</s> <s>53</s> 50 bytes

Uses CP-1252 encoding.

•ø6ŒY2l½î€ÈS`L<eÆô‚˜3ª½¨ºE»D2Âô3•b15ôvy1J€D„# è¹×,

Try it online!

Explanation

As the output image only consists of 2 characters we can represent it as a binary number.

We can ignore newlines as every line has the same length.

We can ignore the last char of each row as it the same for all rows.

We use the thinner image as it takes up less space and we can easily duplicate each character later.

Using 1 to represent space and 0 to represent # we get the binary number:

111100111111111101011011111111111111101111111011011110111111110111000001111111111000001111111100000000011111000000000001111000000000001110000000000000110000000010000111000000010001111000000100001111100000000011111110000000111111111100011111

We then convert this to base-10 and then compress it to base 214, the maximum base in 05AB1E. The result of this is:

•ø6ŒY2l½î€ÈS`L<eÆô‚˜3ª½¨ºE»D2Âô3•

The meat of the program then consist of the following:

<base encoded string>
  b                     # convert to binary
   15ô                  # slice into pieces of 15
      v                 # for each slice
       1J               # append a 1
         €D             # duplicate each character
           „#           # push the string "# "
             è          # use the list of binary digits to index into the string
              ¹×        # repeat string input number of times
                ,       # and print with newline


答:
Java, <s>72</s> <s>71</s> <s>78</s> 76 bytes

```<code>Usage:
    pm:    true if first time is past 11am
    time:  first time%12
    pm2:   true if second time is past 11am
    time2: second time%12
</code>```

Edit:

-1 byte off. Thanks to @1Darco1

Fixed function head. +7 bytes on.

-2 bytes off. Thanks to @Kevin Cruijssen

+2 bytes on. Now e/clock is initialized.

```<code>(a,b,c,d)->{int e=0;b+=a?12:0;d+=c?12:0;for(;b!=d;e+=b%12,b=++b%24);return e;}
</code>```

Ungolfed:

```<code>public static int clock(boolean pm, int time, boolean pm2, int time2){
  int clock=0;
  time+=pm?12:0;
  time2+=pm2?12:0;
  while(time!=time2){
    clock+=time%12;
    time=++time%24;
  }
  return clock;
}
</code>```

Title: How many times will a bell tower ring?

Body:
Java, <s>72</s> <s>71</s> <s>78</s> 76 bytes

Usage:
    pm:    true if first time is past 11am
    time:  first time%12
    pm2:   true if second time is past 11am
    time2: second time%12

Edit:

-1 byte off. Thanks to @1Darco1

Fixed function head. +7 bytes on.

-2 bytes off. Thanks to @Kevin Cruijssen

+2 bytes on. Now e/clock is initialized.

(a,b,c,d)->{int e=0;b+=a?12:0;d+=c?12:0;for(;b!=d;e+=b%12,b=++b%24);return e;}

Ungolfed:

public static int clock(boolean pm, int time, boolean pm2, int time2){
  int clock=0;
  time+=pm?12:0;
  time2+=pm2?12:0;
  while(time!=time2){
    clock+=time%12;
    time=++time%24;
  }
  return clock;
}


答:
Batch, 415 bytes

```<code>@echo off
set h=#####
set s=
for %%a in ("    ##%s%%s%" " # #  #%s%    " "%s%  #%s%   " "#  #    #%s%  " "  #%h%%s%" "%s% %h%%s%" "    %h%####   " "   %h%%h%#  " "   %h%%h%#  " "  %h%%h%### " "  %h%### #### " "   %h%## ###  " "   %h%# ####  " "    %h%####   " "%s%%h%##    " "%s%  ###%s% ")do call:l %1 %%a
exit/b
:l
set r=
for /l %%i in (1,1,%1) do call set r=%%r%%%~2
set r=%r: =  %
echo %r:#=##%
</code>```

Note: the line set s= ends in 5 spaces. Accepts the count as a command-line parameter. Simply loops through each line of the bomb (compressed very slightly by removing runs of 5 identical characters) then repeats the bomb as many times as desired before finally duplicating each character.

Title: Let's draw some Atari ST bombs!

Body:
Batch, 415 bytes

@echo off
set h=#####
set s=
for %%a in ("    ##%s%%s%" " # #  #%s%    " "%s%  #%s%   " "#  #    #%s%  " "  #%h%%s%" "%s% %h%%s%" "    %h%####   " "   %h%%h%#  " "   %h%%h%#  " "  %h%%h%### " "  %h%### #### " "   %h%## ###  " "   %h%# ####  " "    %h%####   " "%s%%h%##    " "%s%  ###%s% ")do call:l %1 %%a
exit/b
:l
set r=
for /l %%i in (1,1,%1) do call set r=%%r%%%~2
set r=%r: =  %
echo %r:#=##%

Note: the line set s= ends in 5 spaces. Accepts the count as a command-line parameter. Simply loops through each line of the bomb (compressed very slightly by removing runs of 5 identical characters) then repeats the bomb as many times as desired before finally duplicating each character.


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

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

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

12

and

012

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

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

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

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

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

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

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

which clearly all sum to seven.

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

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

which clearly do not sum to the same number.

The challenge

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

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

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

答:
Ruby 2.3, 56 bytes

```<code>p !gets.chars.chunk_while(&:<).map{|a|eval a*?+}.uniq[1]
</code>```

Almost certainly not the golfiest way to do this, but it shows off some nice language features.

(Not newline-tolerant, so run like ruby dennis2.rb <<< '12012')

Title: Dennis numbers 2.0

Body:
Ruby 2.3, 56 bytes

p !gets.chars.chunk_while(&:<).map{|a|eval a*?+}.uniq[1]

Almost certainly not the golfiest way to do this, but it shows off some nice language features.

(Not newline-tolerant, so run like ruby dennis2.rb <<< '12012')


答:
C (gcc), <s>216 204 183 165</s> 134 bytes

b(n,i){for(n*=16,i=--n*16;i--;i%n||puts(""))printf(L"àϸ\x7fc\xfde\xfee`\x1fff\xffe\xffe\x7fcǰᇰ䡀\x80⤀\x600"[i/n]&1<<i%n%16?"##":"  ");}
```

<p>Try it online!</p>

<p>Written as a standalone program (<s>201 183</s> 151 bytes)</p>

<pre class="lang-c prettyprint-override"><code>i=16;main(j,l)char**l;{for(;i--;puts(""))for(j=*l[1]*16-769;j--;printf(L"àϸ\x7fc\xfde\xfee`\x1fff\xffe\xffe\x7fcǰᇰ䡀\x80⤀\x600"[i]&1<<j%16?"##":"  "));}
</code>```

Try it online!

This segfaults if a command line parameter is not supplied.

Title: Let's draw some Atari ST bombs!

Body:
C (gcc), <s>216 204 183 165</s> 134 bytes

b(n,i){for(n*=16,i=--n*16;i--;i%n||puts(""))printf(L"àϸ\x7fc\xfde\xfee`\x1fff\xffe\xffe\x7fcǰᇰ䡀\x80⤀\x600"[i/n]&1<<i%n%16?"##":"  ");}

Try it online!

Written as a standalone program (<s>201 183</s> 151 bytes)

i=16;main(j,l)char**l;{for(;i--;puts(""))for(j=*l[1]*16-769;j--;printf(L"àϸ\x7fc\xfde\xfee`\x1fff\xffe\xffe\x7fcǰᇰ䡀\x80⤀\x600"[i]&1<<j%16?"##":"  "));}

Try it online!

This segfaults if a command line parameter is not supplied.


答:
Haskell, 48 43 bytes

```<code>s%e=sum[mod x 12+1|x<-[s-1..e+23],x<e||s>e]
</code>```

Usage is startHour % endHour, with both inputs given in 24-hr format.

edit: added @xnor's improvement, saving 5 bytes

Title: How many times will a bell tower ring?

Body:
Haskell, 48 43 bytes

s%e=sum[mod x 12+1|x<-[s-1..e+23],x<e||s>e]

Usage is startHour % endHour, with both inputs given in 24-hr format.

edit: added @xnor's improvement, saving 5 bytes


Title: Let's draw some Atari ST bombs!

Body:
C, <s>250</s> <s>240</s> <s>208</s> 188 bytes

d[]={3072,20992,256,36992,9184,992,4088,8188,8188,16382,16350,8156,8124,4088,2032,448,0},m,c,*i=d;f(k){for(;*i;i++,puts(""))for(c=k;c--;)for(m=32768;m;write(1,&"##  "[m&*i?0:2],2),m>>=1);}

Switch to using a function.

m,d[]={3072,20992,256,36992,9184,992,4088,8188,8188,16382,16350,8156,8124,4088,2032,448,0},*i=d;main(c,v)char**v;{for(;*i;puts(""),i++)for(c=atoi(v[1]);c--;)for(m=32768;m;write(1,&"##  "[m&*i?0:2],2),m>>=1);}

Test like this.

main(c,v)char**v;
{
    f(atoi(v[1]));
}

a.exe 2
        ####                            ####
  ##  ##    ##                    ##  ##    ##
              ##                              ##
##    ##        ##              ##    ##        ##
    ##      ##########              ##      ##########
            ##########                      ##########
        ##################              ##################
      ######################          ######################
      ######################          ######################
    ##########################      ##########################
    ################  ########      ################  ########
      ##############  ######          ##############  ######
      ############  ########          ############  ########
        ##################              ##################
          ##############                  ##############
              ######                          ######


答:
MATL, <s>64</s> <s>63</s> <s>60</s> <s>59</s> 58 bytes

```<code>49:',cxJr(v9hW&waHB`U=NL%)C9[$aoAN'F16ZaQEY"32e!' #'w)liX"
</code>```

Try it online!

Explanation

The code uses a pre-compressed version of the 16×16 binary matrix. The pre-compressing (not part of the program) used two steps:

Run-length encoding of the matrix read in row-major order (first across, then down).

The resulting run-lengths range from 1 to 16, so the vector of run-lengths minus 1 was converted from base 16 to base 94 (to use all printable ASCII codes except single quote, which is not used because it would need escaping).

The compressed string,

```<code>   ',cxJr(v9hW&waHB`U=NL%)C9[$aoAN'
</code>```

is decompressed from base 94 to base 16:

```<code>                                   F16Za
</code>```

The obtained vector of run-lenghts plus 1 is multipled by 2:

```<code>                                        QE
</code>```

to perform the horizontal stretching.

The vector of run-lenghts contains 49 values. The original numbers to be repeated with those lengths should be [0 1 0 1 ... 0] (49 entries). But instead of that, it's shorter to use the vector [1 2 ... 49], which will be equally valid thanks to modular indexing. So the run-length decoding is

```<code>49:                                       Y"
</code>```

The generated vector containis the runs of 1, 2, ...49, for a total of 512 entries. This is reshaped into a 16×32 matrix:

```<code>                                            32e!
</code>```

and used as modular indices into the string ' #' to produce a single bomb:

```<code>                                                ' #'w)
</code>```

Finally, horizontal repetition by a factor given by the input produces the desired result:

```<code>                                                      liX"
</code>```

Title: Let's draw some Atari ST bombs!

Body:
MATL, <s>64</s> <s>63</s> <s>60</s> <s>59</s> 58 bytes

49:',cxJr(v9hW&waHB`U=NL%)C9[$aoAN'F16ZaQEY"32e!' #'w)liX"

Try it online!

Explanation

The code uses a pre-compressed version of the 16×16 binary matrix. The pre-compressing (not part of the program) used two steps:

Run-length encoding of the matrix read in row-major order (first across, then down).

The resulting run-lengths range from 1 to 16, so the vector of run-lengths minus 1 was converted from base 16 to base 94 (to use all printable ASCII codes except single quote, which is not used because it would need escaping).

The compressed string,

   ',cxJr(v9hW&waHB`U=NL%)C9[$aoAN'

is decompressed from base 94 to base 16:

                                   F16Za

The obtained vector of run-lenghts plus 1 is multipled by 2:

                                        QE

to perform the horizontal stretching.

The vector of run-lenghts contains 49 values. The original numbers to be repeated with those lengths should be [0 1 0 1 ... 0] (49 entries). But instead of that, it's shorter to use the vector [1 2 ... 49], which will be equally valid thanks to modular indexing. So the run-length decoding is

49:                                       Y"

The generated vector containis the runs of 1, 2, ...49, for a total of 512 entries. This is reshaped into a 16×32 matrix:

                                            32e!

and used as modular indices into the string ' #' to produce a single bomb:

                                                ' #'w)

Finally, horizontal repetition by a factor given by the input produces the desired result:

                                                      liX"


Title: Let's draw some Atari ST bombs!

Body:
Haskell, <s>191</s> 181 bytes

f n=h n:f(div n 2)
h n|odd n=' '
h _='#'
g b=mapM_ putStrLn[[f 0xfc7ff01fe00fc207c40784038003c007c007e00ff83ff83bfef6ff7fffb5ffcf!!(x`mod`32`div`2+y*16)|x<-[0..32*b-1]]|y<-[0..15]]


答:
RProgN, 3 Bytes

```<code>% !
</code>```

Explination

```<code>%   # Take the Modulus of the value under the top of the stack compared to the top of the stack. (The Inputs in order, conveniently enough)
!   # Push the Boolean not of it. In this case, 0 is falsey, and all numbers !=0 are truthy, so false correctly inverts it.
</code>```

Yay, RProgN is a competitive language!

Title: Divisibility test

Body:
Task

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

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

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

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

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

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

Test cases

```<code> n,  d    output

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

Leaderboard

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Body:
RProgN, 3 Bytes

% !

Explination

%   # Take the Modulus of the value under the top of the stack compared to the top of the stack. (The Inputs in order, conveniently enough)
!   # Push the Boolean not of it. In this case, 0 is falsey, and all numbers !=0 are truthy, so false correctly inverts it.

Yay, RProgN is a competitive language!


答:
Python, <s>223</s> 179 bytes

Second approach:

```<code>f=lambda n:'\n'.join(''.join(2*' #'[int(d)]for d in bin(int('0c0052000100908023e003e00ff81ffc1ffc3ffe3fde1fdc1fbc0ff807f001c0'[i:i+4],16))[2:].zfill(16))*n for i in range(0,64,4))
</code>```

Try it on repl.it!

Rather than creating a list of strings on-the-fly, there is a hard-coded hexadecimal string which is indexed and converted to binary; then each binary digit is turned into either ' ' or '#', which is duplicated and joined together ... etc.

First approach:

```<code>s='  ';b='##';f=lambda n:'\n'.join(n*l.ljust(32)for l in[s*4+b*2,(s+b)*2+s*2+b,s*7+b,b+s*2+b+s*4+b,s*2+b+s*3+b*5,s*6+b*5,s*4+b*9,s*3+b*11,s*3+b*11,s*2+b*13,s*2+b*8+s+b*4,s*3+b*7+s+b*3,s*3+b*6+s+b*4,s*4+b*9,s*5+b*7,s*7+b*3])
</code>```

Try it on repl.it!

This contains a hard-coded list of the strings of each line (not including trailing spaces) created by duplicating either '  ' or '##' a number of times. For each of these strings, they are padded with spaces until 32 characters in length, duplicated n times, then joined with newlines.

Title: Let's draw some Atari ST bombs!

Body:
Introduction

The Atari ST was a rather popular personal computer from the mid 80's to early 90's era, powered by a Motorola 68000 microprocessor. On this machine, the default behavior of the operating system for uncaught CPU exceptions was to display a row of bombs on the screen, as shown in the following picture:

Source: https://commons.wikimedia.org/wiki/File:Row_of_bombs.png

NB: Depending on the OS version, the bomb graphics may vary slightly. But let's take this one as reference.

The number of bombs depends on the exception vector, the most common ones being:

($008) Bus Error : 2 bombs

($00c) Address Error : 3 bombs

($010) Illegal Instruction : 4 bombs

Goal

Your goal is to write a program or function that prints or outputs an ASCII art of such Atari ST bombs.

Input

An integer representing the number of bombs to display. Your code must support the most common values: 2, 3 and 4. Supporting less and/or more bombs is fine, but it is neither required nor subject to a bonus.

Output

The original bomb consists of a 16x16 pixel tile, represented here in both ASCII and binary:

```<code>....##..........    0000110000000000
.#.#..#.........    0101001000000000
.......#........    0000000100000000
#..#....#.......    1001000010000000
..#...#####.....    0010001111100000
......#####.....    0000001111100000
....#########...    0000111111111000
...###########..    0001111111111100
...###########..    0001111111111100
..#############.    0011111111111110
..########.####.    0011111111011110
...#######.###..    0001111111011100
...######.####..    0001111110111100
....#########...    0000111111111000
.....#######....    0000011111110000
.......###......    0000000111000000
</code>```

In this challenge, each ASCII bomb must be stretched to twice its original width for a better rendering. Therefore, it will consist of 16 rows of 32 characters, using ## for 'ON' pixels and two spaces for 'OFF' pixels. All bomb tiles must be put side by side. Leading spaces are forbidden. Trailing spaces are also forbidden, except the ones that are actually part of the bomb tile (i.e. the 31st and 32nd columns) which must be present. You may include no more than one leading line-break and no more than one trailing line-break.

Example

Below is the reference output for two bombs, where mandatory line-breaks are marked as \n and tolerated extra line-breaks are marked as (\n):

```<code>(\n)
        ####                            ####                    \n
  ##  ##    ##                    ##  ##    ##                  \n
              ##                              ##                \n
##    ##        ##              ##    ##        ##              \n
    ##      ##########              ##      ##########          \n
            ##########                      ##########          \n
        ##################              ##################      \n
      ######################          ######################    \n
      ######################          ######################    \n
    ##########################      ##########################  \n
    ################  ########      ################  ########  \n
      ##############  ######          ##############  ######    \n
      ############  ########          ############  ########    \n
        ##################              ##################      \n
          ##############                  ##############        \n
              ######                          ######            (\n)
</code>```

(Of course, other line-break formats such as \r or \r\n may be used just as well.)

Rules

This is code-golf, so the shortest answer in bytes wins. Standard loopholes are forbidden.

Body:
Python, <s>223</s> 179 bytes

Second approach:

f=lambda n:'\n'.join(''.join(2*' #'[int(d)]for d in bin(int('0c0052000100908023e003e00ff81ffc1ffc3ffe3fde1fdc1fbc0ff807f001c0'[i:i+4],16))[2:].zfill(16))*n for i in range(0,64,4))

Try it on repl.it!

Rather than creating a list of strings on-the-fly, there is a hard-coded hexadecimal string which is indexed and converted to binary; then each binary digit is turned into either ' ' or '#', which is duplicated and joined together ... etc.

First approach:

s='  ';b='##';f=lambda n:'\n'.join(n*l.ljust(32)for l in[s*4+b*2,(s+b)*2+s*2+b,s*7+b,b+s*2+b+s*4+b,s*2+b+s*3+b*5,s*6+b*5,s*4+b*9,s*3+b*11,s*3+b*11,s*2+b*13,s*2+b*8+s+b*4,s*3+b*7+s+b*3,s*3+b*6+s+b*4,s*4+b*9,s*5+b*7,s*7+b*3])

Try it on repl.it!

This contains a hard-coded list of the strings of each line (not including trailing spaces) created by duplicating either '  ' or '##' a number of times. For each of these strings, they are padded with spaces until 32 characters in length, duplicated n times, then joined with newlines.


答:
MATL, 14 bytes

```<code>yy>24*+&:12X\s
</code>```

Input format is as in the third example in the challenge, that is, two numbers in 24-hour format.

Try it online!

Explanation

Take inputs 22, 10 as an example.

```<code>yy      % Take two inputs implicitly. Duplicate both
        %   STACK: 22, 10, 22, 10
>       % Is the first greater than the second?
        %   STACK: 22, 10, 1
24*     % Multiply by 24
        %   STACK: 22, 10, 24
+       % Add
        %   STACK: 22, 34
&:      % Binary range
        %   STACK: [22 23 24 25 26 27 28 29 30 31 32 33 34]
12X\    % Modulo 12, 1-based
        %   STACK: [10 11 12 1 2 3 4 5 6 7 8 9 10]
s       % Sum of array
        %   STACK: 88
        % Implicitly display
</code>```

Title: How many times will a bell tower ring?

Body:
Introduction

A bell tower will ring its bells every hour, n times, with n being the the current hour on a 12 hour clock.

For example, a bell will ring 5 times at 5pm, and 10 times at 10am.

Task

Given two times in a suitable format, output the number of times the bell will ring, inclusive of the start and end times

Examples

```<code>"10am-12pm"
10+11+12= 33

[01:00, 05:00]
1+2+3+4+5 = 15

[11, 15]
11+12+1+2+3 = 29

[10:00pm, 10:00am]
10+11+12+1+2+3+4+5+6+7+8+9+10 = 88
</code>```

If the start is the same as the end then the you simply just ouput the number of chimes for that hour:

```<code>[5pm, 5pm]
5 = 5
</code>```

As you can see, you may choose an input method but the output must be an integer on its own (or an acceptable alternative) trailing/ leading newlines and spaces are allowed.

Note:

inputs may span from the afternoon of one day to the morning of the next.

the difference between the two times will never be more than 24 hours.

input is flexible so long as you clearly state what format your input is.

your input must have a clear distinction between AM and PM.

Body:
MATL, 14 bytes

yy>24*+&:12X\s

Input format is as in the third example in the challenge, that is, two numbers in 24-hour format.

Try it online!

Explanation

Take inputs 22, 10 as an example.

yy      % Take two inputs implicitly. Duplicate both
        %   STACK: 22, 10, 22, 10
>       % Is the first greater than the second?
        %   STACK: 22, 10, 1
24*     % Multiply by 24
        %   STACK: 22, 10, 24
+       % Add
        %   STACK: 22, 34
&:      % Binary range
        %   STACK: [22 23 24 25 26 27 28 29 30 31 32 33 34]
12X\    % Modulo 12, 1-based
        %   STACK: [10 11 12 1 2 3 4 5 6 7 8 9 10]
s       % Sum of array
        %   STACK: 88
        % Implicitly display


答:
C#, 76 bytes

```<code>(a,b)=>Enumerable.Range(a,Math.Abs(b-a)+1).Select(n=>n%12==0?12:n%12).Sum();
</code>```

Title: How many times will a bell tower ring?

Body:
C#, 76 bytes

(a,b)=>Enumerable.Range(a,Math.Abs(b-a)+1).Select(n=>n%12==0?12:n%12).Sum();


答:
PHP, <s>138</s> 104+32=136 bytes

I had never thought that file was binary safe. I only wish I would have found a more interesting way to store the data; but nothing I tried beat raw binary.

```<code>foreach(unpack("v*",file(b)[0])as$v)echo"
",str_repeat(strtr(sprintf("%016b",$v),["  ","##"]),$argv[1]);
</code>```

read binary data from file, unpack from little endian 16bit to array of int

loop through array: print 16 digit binary to string,
replace 0 with 2 spaces, 1 with ##,

repeat $argv[1] times, print result + newline

run with -r

binary data in file b:

```<code>0000000 0c00 5200 0100 9080 23e0 03e0 0ff8 1ffc
0000010 1ffc 3ffe 3fde 1fdc 1fbc 0ff8 07f0 01c0
</code>```

code to generate the file:

```<code>$f=fopen(b,wb);foreach(array_map(bindec,explode("
",
"0000110000000000
0101001000000000
0000000100000000
1001000010000000
0010001111100000
0000001111100000
0000111111111000
0001111111111100
0001111111111100
0011111111111110
0011111111011110
0001111111011100
0001111110111100
0000111111111000
0000011111110000
0000000111000000"))as$c)fputs($f,pack("v*",$c));fclose($f);
</code>```

Title: Let's draw some Atari ST bombs!

Body:
PHP, <s>138</s> 104+32=136 bytes

I had never thought that file was binary safe. I only wish I would have found a more interesting way to store the data; but nothing I tried beat raw binary.

foreach(unpack("v*",file(b)[0])as$v)echo"
",str_repeat(strtr(sprintf("%016b",$v),["  ","##"]),$argv[1]);

read binary data from file, unpack from little endian 16bit to array of int

loop through array: print 16 digit binary to string,
replace 0 with 2 spaces, 1 with ##,

repeat $argv[1] times, print result + newline

run with -r

binary data in file b:

0000000 0c00 5200 0100 9080 23e0 03e0 0ff8 1ffc
0000010 1ffc 3ffe 3fde 1fdc 1fbc 0ff8 07f0 01c0

code to generate the file:

$f=fopen(b,wb);foreach(array_map(bindec,explode("
",
"0000110000000000
0101001000000000
0000000100000000
1001000010000000
0010001111100000
0000001111100000
0000111111111000
0001111111111100
0001111111111100
0011111111111110
0011111111011110
0001111111011100
0001111110111100
0000111111111000
0000011111110000
0000000111000000"))as$c)fputs($f,pack("v*",$c));fclose($f);


答:
RProgN, <s>210</s> 193 Bytes

Saved some bytes by switching 0='  ' 1='##' to 1='  ' 0='  ', this means i don't need to add the extra zeros back. Also, this means that now the B64 string that used to say "MAFIA" does not, This is sad.

```<code>'n' = => 64 -B 2 B ] 1 16 sub n rep \ 17 32 sub n rep '
' \ . . '1' '  ' replace '0' '##' replace } a'' = D4D/4/'' a DgQ/AH'' a DAIeAj'' a DgA8AB'' a DwB+AD'' a DcH/wf'' a D+/29/'' a Dz/63/'' a
</code>```

Explanation

```<code>'n' =                   # Associate the input with "n"
=>                      # Push a new function to the stack.
    64 -B               # Take the value from the top of the stack, convert it to an integer from Base64
    2 B                 # Take the value from the top of the stack, convert it from an integer to binary
    ]                   # Duplicate the top of the stack.
    1 16 sub            # Push the substring from the top of the stack between 1 and 16, 1 indexed.
    n                   # Push the input.
    rep                 # Repeat, this gives us 'n' bombs, essentially.
    \                   # Flip the values such that REPEATEDBOMB_ROW TEXT
    17 32 sub           # Push the substring between 17 and 32.
    n                   # Push the input
    rep                 # Repeat
    '                   # Push a new line
'                       # RProgN doesn't actually have escapes, so the raw newline is represented as a newline between qoutes.
    \ . .               # Flip the values so we have LINE1 NEWLINE LINE2, then concatenate them all into one string.
    '1' '  ' replace    # Replace all the 1's in the binary string with two spaces.
    '0' '##' replace    # Replace all the 1's with two '#'s
} a'' =                 # Associate the function with 'a'
D4D/4/'' a              # Bottom two lines,
DgQ/AH'' a              # Next two up,
DAIeAj'' a              # Etc...
DgA8AB'' a              # Once This is done, the memory stack is implicitly printed from top to bottom.
DwB+AD'' a              # As such, the bomb is upside down.
DcH/wf'' a              # Each of these numbers represents two lines, which is why we do the substringing to split it.
D+/29/'' a              # This works out saving a few bytes.
Dz/63/'' a              # Implicitly printed output. Yay.
</code>```

Pretty long, The expanding, printing and such of the compressed string is 105 of the bytes.
Might be a bit more golfable, but atleast it works.

Input is implicitly on the stack, stack is implicitly printed.

Output

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

Try it!

Sorry, You need to support IFrame. Why don't you..?```

Title: Let's draw some Atari ST bombs!

Body:
RProgN, <s>210</s> 193 Bytes

Saved some bytes by switching 0='  ' 1='##' to 1='  ' 0='  ', this means i don't need to add the extra zeros back. Also, this means that now the B64 string that used to say "MAFIA" does not, This is sad.

'n' = => 64 -B 2 B ] 1 16 sub n rep \ 17 32 sub n rep '
' \ . . '1' '  ' replace '0' '##' replace } a'' = D4D/4/'' a DgQ/AH'' a DAIeAj'' a DgA8AB'' a DwB+AD'' a DcH/wf'' a D+/29/'' a Dz/63/'' a

Explanation

'n' =                   # Associate the input with "n"
=>                      # Push a new function to the stack.
    64 -B               # Take the value from the top of the stack, convert it to an integer from Base64
    2 B                 # Take the value from the top of the stack, convert it from an integer to binary
    ]                   # Duplicate the top of the stack.
    1 16 sub            # Push the substring from the top of the stack between 1 and 16, 1 indexed.
    n                   # Push the input.
    rep                 # Repeat, this gives us 'n' bombs, essentially.
    \                   # Flip the values such that REPEATEDBOMB_ROW TEXT
    17 32 sub           # Push the substring between 17 and 32.
    n                   # Push the input
    rep                 # Repeat
    '                   # Push a new line
'                       # RProgN doesn't actually have escapes, so the raw newline is represented as a newline between qoutes.
    \ . .               # Flip the values so we have LINE1 NEWLINE LINE2, then concatenate them all into one string.
    '1' '  ' replace    # Replace all the 1's in the binary string with two spaces.
    '0' '##' replace    # Replace all the 1's with two '#'s
} a'' =                 # Associate the function with 'a'
D4D/4/'' a              # Bottom two lines,
DgQ/AH'' a              # Next two up,
DAIeAj'' a              # Etc...
DgA8AB'' a              # Once This is done, the memory stack is implicitly printed from top to bottom.
DwB+AD'' a              # As such, the bomb is upside down.
DcH/wf'' a              # Each of these numbers represents two lines, which is why we do the substringing to split it.
D+/29/'' a              # This works out saving a few bytes.
Dz/63/'' a              # Implicitly printed output. Yay.

Pretty long, The expanding, printing and such of the compressed string is 105 of the bytes.
Might be a bit more golfable, but atleast it works.

Input is implicitly on the stack, stack is implicitly printed.

Output

        ####                            ####                            ####
  ##  ##    ##                    ##  ##    ##                    ##  ##    ##
              ##                              ##                              ##
##    ##        ##              ##    ##        ##              ##    ##        ##
    ##      ##########              ##      ##########              ##      ##########
            ##########                      ##########                      ##########
        ##################              ##################              ##################
      ######################          ######################          ######################
      ######################          ######################          ######################
    ##########################      ##########################      ##########################
    ################  ########      ################  ########      ################  ########
      ##############  ######          ##############  ######          ##############  ######
      ############  ########          ############  ########          ############  ########
        ##################              ##################              ##################
          ##############                  ##############                  ##############
              ######                          ######                          ######

Try it!

<style>
  #frame{
    width:60em;
    height:60em;
    border:none;
  }
</style>
<iframe id='frame' src="https://tehflamintaco.github.io/Reverse-Programmer-Notation/RProgN.html?rpn=%27n%27%20%3D%20%3D%3E%2064%20-B%202%20B%20%5D%201%2016%20sub%20n%20rep%20%5C%2017%2032%20sub%20n%20rep%20%27%0A%27%20%5C%20.%20.%20%271%27%20%27%20%20%27%20replace%20%270%27%20%27%23%23%27%20replace%20%7D%20a%27%27%20%3D%20D4D%2F4%2F%27%27%20a%20DgQ%2FAH%27%27%20a%20DAIeAj%27%27%20a%20DgA8AB%27%27%20a%20DwB%2BAD%27%27%20a%20DcH%2Fwf%27%27%20a%20D%2B%2F29%2F%27%27%20a%20Dz%2F63%2F%27%27%20a&input=1">Sorry, You need to support IFrame. Why don't you..?</iframe>


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

Challenge

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

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

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

Code golf, fewest bytes wins.

Test cases

x, n, result

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

答:
J, 9 bytes

```<code>[:<./>./\
</code>```

Similar to the APL answer. >./\ applies >./ (maximum) to the (left arg)-subsets of the right arg. Then, <./ finds the minimum of that, since it's capped with [:.

Test cases

```<code>   f =: [:<./>./\
   2 f 1 5 3 4
4
   3 f 1 2 3 4 5
3
   3 f 1 1 1 1 5
1
   3 f 5 42 3 23
42
</code>```

Title: Compute minimax of an array

Body:
J, 9 bytes

[:<./>./\

Similar to the APL answer. >./\ applies >./ (maximum) to the (left arg)-subsets of the right arg. Then, <./ finds the minimum of that, since it's capped with [:.

Test cases

   f =: [:<./>./\
   2 f 1 5 3 4
4
   3 f 1 2 3 4 5
3
   3 f 1 1 1 1 5
1
   3 f 5 42 3 23
42