答:
CJam (21 20 bytes)

```<code>{:A,{_)A<$2*)@-#},!}
</code>```

Online test suite

Dissection

This uses the observation by xnor in his Haskell answer that the difference between the maximum and minimum of the first n elements should be n-1.

```<code>{         e# Define a block. Stack: array
  :A,     e#   Store the array in A and get its length
  {       e#   Filter (with implicit , so over the array [0 ... len-1])
    _)A<  e#     Get the first i+1 elements of A (so we iterate over prefixes)
    $2*)  e#     Extract the last element without leaving an empty array if the
          e#     prefix is of length 1 by first duplicating the contents of the
          e#     prefix and then popping the last element
    @-#   e#     Search the prefix for max(prefix)-i, which should be min(prefix)
          e#     giving index 0
  },      e#   So the filter finds values of i for which the prefix of length i+1
          e#   doesn't have max(prefix) - min(prefix) = i
  !       e#   Negate, giving truthy iff there was no i matching the filter
}
</code>```

Alternative approach (also 20 bytes)

```<code>{_{a+_)f-:z1&,*}*^!}
</code>```

Online test suite

This checks directly that each element after the first is at distance 1 from a previous element. Since the input is a permutation and hence doesn't repeat values, this is a sufficient test. Thanks to Martin for a 1-byte saving.

Dissection

```<code>{_{a+_)f-:z1&,*}*^!}

{         e# Declare a block. Stack: array
  _       e#   Work with a copy of the array
  {       e#   Fold...
    a+    e#     Add to the accumulator.
    _)f-  e#     Dup, pop last, map subtraction to get distance of this element from
          e#     each of the previous ones
    :z1&, e#     Check whether the absolute values include 1
    *     e#     If not, replace the accumulator with an empty array
  }*
  ^!      e#   Test whether the accumulator is equal to the original array
          e#   Note that this can't just be = because if the array is of length 1
          e#   the accumulator will be 0 rather than [0]
}
</code>```

Title: Antsy permutations

Body:
CJam (21 20 bytes)

{:A,{_)A<$2*)@-#},!}

<a href="http://cjam.tryitonline.net/#code=MTpUOzA6RjtxIixydWVhbHNlLT4iLX5dMi97flwKCns6QSx7XylBPCQyKilALSN9LCF9Cgp-PW99Lw&input=WzBdIC0-IFRydWUKWzAsIDFdIC0-IFRydWUKWzEsIDBdIC0-IFRydWUKWzAsIDEsIDJdIC0-IFRydWUKWzAsIDIsIDFdIC0-IEZhbHNlClsyLCAxLCAzLCAwXSAtPiBUcnVlClszLCAxLCAwLCAyXSAtPiBGYWxzZQpbMSwgMiwgMCwgM10gLT4gVHJ1ZQpbMiwgMywgMSwgNCwgMF0gLT4gVHJ1ZQpbMiwgMywgMCwgNCwgMV0gLT4gRmFsc2UKWzAsIDUsIDEsIDMsIDIsIDRdIC0-IEZhbHNlCls2LCA1LCA0LCA3LCAzLCA4LCA5LCAyLCAxLCAwXSAtPiBUcnVlCls0LCAzLCA1LCA2LCA3LCAyLCA5LCAxLCAwLCA4XSAtPiBGYWxzZQpbNSwgMiwgNywgOSwgNiwgOCwgMCwgNCwgMSwgM10gLT4gRmFsc2UKWzIwLCAxMywgNywgMCwgMTQsIDE2LCAxMCwgMjQsIDIxLCAxLCA4LCAyMywgMTcsIDE4LCAxMSwgMiwgNiwgMjIsIDQsIDUsIDksIDEyLCAzLCAxNSwgMTldIC0-IEZhbHNlClszNCwgMzYsIDk5LCA5NCwgNzcsIDkzLCAzMSwgOTAsIDIxLCA4OCwgMzAsIDY2LCA5MiwgODMsIDQyLCA1LCA4NiwgMTEsIDE1LCA3OCwgNDAsIDQ4LCAyMiwgMjksIDk1LCA2NCwgOTcsIDQzLCAxNCwgMzMsIDY5LCA0OSwgNTAsIDM1LCA3NCwgNDYsIDI2LCA1MSwgNzUsIDg3LCAyMywgODUsIDQxLCA5OCwgODIsIDc5LCA1OSwgNTYsIDM3LCA5NiwgNDUsIDE3LCAzMiwgOTEsIDYyLCAyMCwgNCwgOSwgMiwgMTgsIDI3LCA2MCwgNjMsIDI1LCA2MSwgNzYsIDEsIDU1LCAxNiwgOCwgNiwgMzgsIDU0LCA0NywgNzMsIDY3LCA1MywgNTcsIDcsIDcyLCA4NCwgMzksIDUyLCA1OCwgMCwgODksIDEyLCA2OCwgNzAsIDI0LCA4MCwgMywgNDQsIDEzLCAyOCwgMTAsIDcxLCA2NSwgODEsIDE5XSAtPiBGYWxzZQpbNDcsIDQ4LCA0NiwgNDUsIDQ0LCA0OSwgNDMsIDQyLCA0MSwgNTAsIDQwLCAzOSwgMzgsIDUxLCAzNywgMzYsIDUyLCAzNSwgMzQsIDMzLCAzMiwgNTMsIDU0LCAzMSwgMzAsIDU1LCA1NiwgMjksIDI4LCA1NywgNTgsIDU5LCA2MCwgMjcsIDI2LCA2MSwgMjUsIDYyLCA2MywgNjQsIDY1LCA2NiwgNjcsIDI0LCAyMywgMjIsIDIxLCA2OCwgNjksIDIwLCAxOSwgMTgsIDE3LCA3MCwgNzEsIDE2LCAxNSwgNzIsIDczLCA3NCwgNzUsIDc2LCAxNCwgMTMsIDEyLCA3NywgMTEsIDEwLCA5LCA4LCA3OCwgNywgNzksIDgwLCA2LCA4MSwgNSwgNCwgMywgODIsIDIsIDgzLCA4NCwgMSwgODUsIDg2LCA4NywgMCwgODgsIDg5LCA5MCwgOTEsIDkyLCA5MywgOTQsIDk1LCA5NiwgOTcsIDk4LCA5OV0gLT4gVHJ1ZQ" rel="nofollow">Online test suite

Dissection

This uses the observation by xnor in his Haskell answer that the difference between the maximum and minimum of the first n elements should be n-1.

{         e# Define a block. Stack: array
  :A,     e#   Store the array in A and get its length
  {       e#   Filter (with implicit , so over the array [0 ... len-1])
    _)A<  e#     Get the first i+1 elements of A (so we iterate over prefixes)
    $2*)  e#     Extract the last element without leaving an empty array if the
          e#     prefix is of length 1 by first duplicating the contents of the
          e#     prefix and then popping the last element
    @-#   e#     Search the prefix for max(prefix)-i, which should be min(prefix)
          e#     giving index 0
  },      e#   So the filter finds values of i for which the prefix of length i+1
          e#   doesn't have max(prefix) - min(prefix) = i
  !       e#   Negate, giving truthy iff there was no i matching the filter
}

Alternative approach (also 20 bytes)

{_{a+_)f-:z1&,*}*^!}

<a href="http://cjam.tryitonline.net/#code=MTpUOzA6RjtxIixydWVhbHNlLT4iLX5dMi97flwKCntfe2ErXylmLTp6MSYsKn0qXiF9Cgp-PW99Lw&input=WzBdIC0-IFRydWUKWzAsIDFdIC0-IFRydWUKWzEsIDBdIC0-IFRydWUKWzAsIDEsIDJdIC0-IFRydWUKWzAsIDIsIDFdIC0-IEZhbHNlClsyLCAxLCAzLCAwXSAtPiBUcnVlClszLCAxLCAwLCAyXSAtPiBGYWxzZQpbMSwgMiwgMCwgM10gLT4gVHJ1ZQpbMiwgMywgMSwgNCwgMF0gLT4gVHJ1ZQpbMiwgMywgMCwgNCwgMV0gLT4gRmFsc2UKWzAsIDUsIDEsIDMsIDIsIDRdIC0-IEZhbHNlCls2LCA1LCA0LCA3LCAzLCA4LCA5LCAyLCAxLCAwXSAtPiBUcnVlCls0LCAzLCA1LCA2LCA3LCAyLCA5LCAxLCAwLCA4XSAtPiBGYWxzZQpbNSwgMiwgNywgOSwgNiwgOCwgMCwgNCwgMSwgM10gLT4gRmFsc2UKWzIwLCAxMywgNywgMCwgMTQsIDE2LCAxMCwgMjQsIDIxLCAxLCA4LCAyMywgMTcsIDE4LCAxMSwgMiwgNiwgMjIsIDQsIDUsIDksIDEyLCAzLCAxNSwgMTldIC0-IEZhbHNlClszNCwgMzYsIDk5LCA5NCwgNzcsIDkzLCAzMSwgOTAsIDIxLCA4OCwgMzAsIDY2LCA5MiwgODMsIDQyLCA1LCA4NiwgMTEsIDE1LCA3OCwgNDAsIDQ4LCAyMiwgMjksIDk1LCA2NCwgOTcsIDQzLCAxNCwgMzMsIDY5LCA0OSwgNTAsIDM1LCA3NCwgNDYsIDI2LCA1MSwgNzUsIDg3LCAyMywgODUsIDQxLCA5OCwgODIsIDc5LCA1OSwgNTYsIDM3LCA5NiwgNDUsIDE3LCAzMiwgOTEsIDYyLCAyMCwgNCwgOSwgMiwgMTgsIDI3LCA2MCwgNjMsIDI1LCA2MSwgNzYsIDEsIDU1LCAxNiwgOCwgNiwgMzgsIDU0LCA0NywgNzMsIDY3LCA1MywgNTcsIDcsIDcyLCA4NCwgMzksIDUyLCA1OCwgMCwgODksIDEyLCA2OCwgNzAsIDI0LCA4MCwgMywgNDQsIDEzLCAyOCwgMTAsIDcxLCA2NSwgODEsIDE5XSAtPiBGYWxzZQpbNDcsIDQ4LCA0NiwgNDUsIDQ0LCA0OSwgNDMsIDQyLCA0MSwgNTAsIDQwLCAzOSwgMzgsIDUxLCAzNywgMzYsIDUyLCAzNSwgMzQsIDMzLCAzMiwgNTMsIDU0LCAzMSwgMzAsIDU1LCA1NiwgMjksIDI4LCA1NywgNTgsIDU5LCA2MCwgMjcsIDI2LCA2MSwgMjUsIDYyLCA2MywgNjQsIDY1LCA2NiwgNjcsIDI0LCAyMywgMjIsIDIxLCA2OCwgNjksIDIwLCAxOSwgMTgsIDE3LCA3MCwgNzEsIDE2LCAxNSwgNzIsIDczLCA3NCwgNzUsIDc2LCAxNCwgMTMsIDEyLCA3NywgMTEsIDEwLCA5LCA4LCA3OCwgNywgNzksIDgwLCA2LCA4MSwgNSwgNCwgMywgODIsIDIsIDgzLCA4NCwgMSwgODUsIDg2LCA4NywgMCwgODgsIDg5LCA5MCwgOTEsIDkyLCA5MywgOTQsIDk1LCA5NiwgOTcsIDk4LCA5OV0gLT4gVHJ1ZQ" rel="nofollow">Online test suite

This checks directly that each element after the first is at distance 1 from a previous element. Since the input is a permutation and hence doesn't repeat values, this is a sufficient test. Thanks to Martin for a 1-byte saving.

Dissection

{_{a+_)f-:z1&,*}*^!}

{         e# Declare a block. Stack: array
  _       e#   Work with a copy of the array
  {       e#   Fold...
    a+    e#     Add to the accumulator.
    _)f-  e#     Dup, pop last, map subtraction to get distance of this element from
          e#     each of the previous ones
    :z1&, e#     Check whether the absolute values include 1
    *     e#     If not, replace the accumulator with an empty array
  }*
  ^!      e#   Test whether the accumulator is equal to the original array
          e#   Note that this can't just be = because if the array is of length 1
          e#   the accumulator will be 0 rather than [0]
}


问:
Does the code terminate?
This is a code golf challenge I thought of with a mathematical bent. The challenge is to write the shortest code possible such that it is an open question whether or not the code terminates. An example of what I mean could be the following piece of python code, adapted from an anwser to this cs stackexchange question.

```<code>def is_perfect(n):
    return sum(i for i in range(1, n) if n % i == 0) == n

n = 3
while not is_perfect(n):
    n = n + 2
</code>```

Mathematicians conjecture that there are no odd perfect numbers, but it has never been proven, so no one knows if this piece of code will ever terminate. Can you come up with other pieces of code (perhaps relying on other open problems like the Collatz conjecture, or the twin primes conjecture) that are shorter, but for which it is unknown whether or not they terminate?

Edit: Some people have brought up a good additional rule - The solutions to the question should be deterministic. Although it might be even more interesting if you could find shorter solutions using nondeterminism. In this case, the rule would be to find a snippet for which the probability of termination is unknown.

答:
Python, 80 bytes

Terminates if the Collatz Conjecture is proven false. See this question.

n=2
while 1:
 L=[];x=n
 while~-n:1/(n not in L);L+=[n];n=(n/2,n*3+1)[n%2]
 n=x+1
```

ContentLicense: CC BY-SA 3.0

Title: Does the code terminate?


问:
Traveling Pumpkin Problem

Background:

Jack is a pumpkin that enjoys spooking the citizens of the villages near his pumpkin patch every Halloween.  However, every year after someone lights the candle inside of him, he has a limited amount of time to spook everyone before the candle burns out, thus being unable to spook any more villagers because nobody can see him.  In past years, he has only been able to spook a small amount of villages due to his poor decision making, but now that he has you to help him, he will be able to spook as many villages as possible!

Task:

Given a list of village locations and a candle lifespan, output the maximum number of villages Jack can visit.  You do not have to print the path itself.

Input:

The lifespan of the candle and a list of village locations in a Cartesian coordinate system.  The pumpkin patch Jack originates from will always be at 0,0.  You may format the input in anyway you wish.  To simplify Jack's movements, he can only move horizontally, vertically, or diagonally, meaning his candle will either lose 1 or 1.5 (he takes a bit longer diagonally) units of life every move.  The candle burns out when the lifespan is less than or equal to 0.

Output:

An integer equal to the maximum number of villages Jack can visit before the candle burns out.

Rules:

This is code-golf, so shortest code in bytes wins.  Standard loopholes are not allowed.

Test cases:

```<code>// Format [lifespan] [list of village coordinates] -> [maximum visit-able villages]

4 -1,0 1,0 2,0 3,0 4,0 5,0 -> 3
4 1,1 2,2 3,3 -> 2
5 1,1 2,1 3,1 4,1 5,0 5,1 -> 4
</code>```

答:
Jelly, <s>30</s> <s>29</s> <s>27</s> 25 bytes

```<code>_AṢæ..
0,0ṭṚç2\+\<S
Œ!ç€Ṁ
</code>```

Try it online!

Apparently Jelly's dot product just ignores a list size mismatch and doesn't multiply the extra elements of the other array, just adds them. Shaves off 2 bytes.

Explanation

```<code>_AṢæ..              Helper link to calculate distance. Arguments: a, b
_                     subtract the vertices from each other
 A                    take absolute values of axes
  Ṣ                   sort the axes
   æ..                dot product with [0.5]

0,0ṭṚç2\+\<S        Helper link to calculate max cities. Arguments: perm, max
0,0                   create pair [0,0]
   ṭ                  append that to the permutation
    Ṛ                 reverse the permutation (gets the [0,0] to the beginning)
     ç2\              find distances of each pair using the previous link
        +\            find all partial sums
          <           see if each sum was less than the max
           S          sum to count cases where it was

Œ!ç€Ṁ               Main link. Arguments: cities, max
Œ!                    get permutations of cities
  ç€                  find max cities for each permutation using the previous link
    Ṁ                 take the maximum
</code>```

Title: Traveling Pumpkin Problem

Body:
Jelly, <s>30</s> <s>29</s> <s>27</s> 25 bytes

_AṢæ..
0,0ṭṚç2\+\<S
Œ!ç€Ṁ

Try it online!

Apparently Jelly's dot product just ignores a list size mismatch and doesn't multiply the extra elements of the other array, just adds them. Shaves off 2 bytes.

Explanation

_AṢæ..              Helper link to calculate distance. Arguments: a, b
_                     subtract the vertices from each other
 A                    take absolute values of axes
  Ṣ                   sort the axes
   æ..                dot product with [0.5]

0,0ṭṚç2\+\<S        Helper link to calculate max cities. Arguments: perm, max
0,0                   create pair [0,0]
   ṭ                  append that to the permutation
    Ṛ                 reverse the permutation (gets the [0,0] to the beginning)
     ç2\              find distances of each pair using the previous link
        +\            find all partial sums
          <           see if each sum was less than the max
           S          sum to count cases where it was

Œ!ç€Ṁ               Main link. Arguments: cities, max
Œ!                    get permutations of cities
  ç€                  find max cities for each permutation using the previous link
    Ṁ                 take the maximum


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

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

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

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

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

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

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

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

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

答:
05AB1E, <s>60</s> 59 bytes

```<code>AÂ"qwertyuiopasdfghjklzxcvbnm""pyfgcrlaoeuidhtnsqjkxbmwvz"»
</code>```

Try it online!

AÂ - pushes the bifurcated alphabet.

"qwertyuiopasdfghjklzxcvbnm""pyfgcrlaoeuidhtnsqjkxbmwvz" - Pushes qwerty and drovak.

» - Prints stack.

05AB1E, 57 bytes (If you don't care about random \n)

```<code>AÂ"qwertyuiopasdfghjklzxcvbnmpyfgcrlaoeuidhtnsqjkxbmwvz"»
</code>```

Try it online!

Title: Print the alphabet four times

Body:
05AB1E, <s>60</s> 59 bytes

AÂ"qwertyuiopasdfghjklzxcvbnm""pyfgcrlaoeuidhtnsqjkxbmwvz"»

Try it online!

AÂ - pushes the bifurcated alphabet.

"qwertyuiopasdfghjklzxcvbnm""pyfgcrlaoeuidhtnsqjkxbmwvz" - Pushes qwerty and drovak.

» - Prints stack.

05AB1E, 57 bytes (If you don't care about random \n)

AÂ"qwertyuiopasdfghjklzxcvbnmpyfgcrlaoeuidhtnsqjkxbmwvz"»

Try it online!


问:
Antsy permutations

Introduction

Suppose you have a ruler with numbers from 0 to r-1.
You place an ant between any two of the numbers, and it starts to crawl erratically on the ruler.
The ruler is so narrow that the ant cannot walk from one position to another without walking on all the numbers in between.
As the ant walks on a number for the first time, you record it, and this gives you a permutation of the r numbers.
We say that a permutation is antsy if it can be generated by an ant in this way.
Alternatively, a permutation p is antsy if every entry p[i] except the first is within distance 1 from some previous entry.

Examples

The length-6 permutation

```<code>4, 3, 5, 2, 1, 0
</code>```

is antsy, because 3 is within distance 1 of 4, 5 is within distance 1 of 4, 2 is within distance 1 from 3, 1 is within distance 1 from 2, and 0 is within distance 1 from 1.
The permutation

```<code>3, 2, 5, 4, 1, 0
</code>```

is not antsy, because 5 is not within distance 1 of either 3 or 2; the ant would have to pass through 4 to get to 5.

The task

Given a permutation of the numbers from 0 to r-1 for some 1 ≤ r ≤ 100 in any reasonable format, output a truthy value if the permutation is antsy, and a falsy value if not.

Test cases

```<code>[0] -> True
[0, 1] -> True
[1, 0] -> True
[0, 1, 2] -> True
[0, 2, 1] -> False
[2, 1, 3, 0] -> True
[3, 1, 0, 2] -> False
[1, 2, 0, 3] -> True
[2, 3, 1, 4, 0] -> True
[2, 3, 0, 4, 1] -> False
[0, 5, 1, 3, 2, 4] -> False
[6, 5, 4, 7, 3, 8, 9, 2, 1, 0] -> True
[4, 3, 5, 6, 7, 2, 9, 1, 0, 8] -> False
[5, 2, 7, 9, 6, 8, 0, 4, 1, 3] -> False
[20, 13, 7, 0, 14, 16, 10, 24, 21, 1, 8, 23, 17, 18, 11, 2, 6, 22, 4, 5, 9, 12, 3, 15, 19] -> False
[34, 36, 99, 94, 77, 93, 31, 90, 21, 88, 30, 66, 92, 83, 42, 5, 86, 11, 15, 78, 40, 48, 22, 29, 95, 64, 97, 43, 14, 33, 69, 49, 50, 35, 74, 46, 26, 51, 75, 87, 23, 85, 41, 98, 82, 79, 59, 56, 37, 96, 45, 17, 32, 91, 62, 20, 4, 9, 2, 18, 27, 60, 63, 25, 61, 76, 1, 55, 16, 8, 6, 38, 54, 47, 73, 67, 53, 57, 7, 72, 84, 39, 52, 58, 0, 89, 12, 68, 70, 24, 80, 3, 44, 13, 28, 10, 71, 65, 81, 19] -> False
[47, 48, 46, 45, 44, 49, 43, 42, 41, 50, 40, 39, 38, 51, 37, 36, 52, 35, 34, 33, 32, 53, 54, 31, 30, 55, 56, 29, 28, 57, 58, 59, 60, 27, 26, 61, 25, 62, 63, 64, 65, 66, 67, 24, 23, 22, 21, 68, 69, 20, 19, 18, 17, 70, 71, 16, 15, 72, 73, 74, 75, 76, 14, 13, 12, 77, 11, 10, 9, 8, 78, 7, 79, 80, 6, 81, 5, 4, 3, 82, 2, 83, 84, 1, 85, 86, 87, 0, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] -> True
</code>```

Fun fact: for r ≥ 1, there are exactly 2r-1 antsy permutations of length r.

答:
Perl, 63 bytes

Note that @Gabriel Banamy came up with a shorter (55 bytes) answer. But I think this solution is still interesting, so I'm posting it.

The bytes count includes 62 bytes of code and -n flag.

s/\d+/1x($&+1)/ge;/ 1(1*)\b(?{$.&=$`=~m%\b(11)?$1\b%})^/;say$.
```

<p>To run it : </p>

```perl -nE 's/\d+/1x($&+1)/ge;/ 1(1*)\b(?{$.&=$`=~m%\b(11)?$1\b%})^/;say$.' <<< "3 2 5 4 1 0"
```

Short explanations : converts each number k to the unary representation of k+1 (that +1 is needed so the 0s don't get ignored). Then for each number k+1 (expressed in unary as 1(1*)), we look if either k ($1 holds k) or k+2 (which is then 11$1) are present in the preceding string (referenced by $-backtick). If no, then we set $. to zero. At then end we print $. which will be 1 if we never set it to zero, or zero otherwise.

Title: Antsy permutations

Body:
Perl, 63 bytes

Note that @Gabriel Banamy came up with a shorter (55 bytes) answer. But I think this solution is still interesting, so I'm posting it.

The bytes count includes 62 bytes of code and -n flag.

s/\d+/1x($&+1)/ge;/ 1(1*)\b(?{$.&=$`=~m%\b(11)?$1\b%})^/;say$.

To run it :

perl -nE 's/\d+/1x($&+1)/ge;/ 1(1*)\b(?{$.&=$`=~m%\b(11)?$1\b%})^/;say$.' <<< "3 2 5 4 1 0"

Short explanations : converts each number k to the unary representation of k+1 (that +1 is needed so the 0s don't get ignored). Then for each number k+1 (expressed in unary as 1(1*)), we look if either k ($1 holds k) or k+2 (which is then 11$1) are present in the preceding string (referenced by $-backtick). If no, then we set $. to zero. At then end we print $. which will be 1 if we never set it to zero, or zero otherwise.


问:
Where's the 0xBEEF?
This challenge was inspired by this Wendy's commercial from 1984.

Illustration by T S Rogers

Your task is to find a hexadecimal 0xBEEF on a binary bun.

The 'beef' consists of the following pattern:

```<code>1 0 1 1  (0xB)
1 1 1 0  (0xE)
1 1 1 0  (0xE)
1 1 1 1  (0xF)
</code>```

And the 'bun' consists of a 12x12 binary matrix, such as:

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

Input

Your program or function will take the binary matrix as input. The matrix format is very flexible, but it must be clearly described in your answer.

For instance:

a single binary string, with or without separators between the rows:

"111001111110 110100100000..."

or:

"111001111110110100100000..."

an array of binary strings:

["111001111110", "110100100000", ...]

an array of numbers (each number describing a row once converted back to binary and left-padded with zeros):

[3710, 3360, ...]

Output

The coordinates (X, Y) of the 'beef', (0, 0) being the top left corner of the bun.

Alternatively, you may use 1-based coordinates (but not a mix of both formats, like 0-based for X and 1-based for Y).

For the above example, the expected answer is (3, 4) (0-based) or (4, 5) (1-based):

```<code>   00 01 02 03 04 05 06 07 08 09 10 11
00  1  1  1  0  0  1  1  1  1  1  1  0
01  1  1  0  1  0  0  1  0  0  0  0  0
02  0  1  0  0  0  1  1  1  1  1  0  1
03  1  0  0  1  0  0  1  0  0  1  0  0
04  1  0  0 [1  0  1  1] 0  0  1  1  1
05  1  1  1 [1  1  1  0] 0  0  0  1  0
06  1  1  0 [1  1  1  0] 0  0  0  0  1
07  1  0  0 [1  1  1  1] 0  0  0  0  1
08  1  0  0  1  1  1  0  1  1  1  1  1
09  1  1  1  1  1  0  0  1  1  1  1  1
10  1  0  0  0  0  1  0  1  0  1  1  1
11  1  1  0  0  1  1  0  0  0  0  1  1
</code>```

Again, any reasonable format would work as long as it is specified in your answer. Please also mention if you're using 0-based or 1-based coordinates.

Rules

You can safely assume that there is always exactly one 'beef' on the bun. Your code is not required to support cases with more than one beef or no beef at all.

The beef pattern will always appear as described. It will never be rotated or mirrored in any way.

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

Test cases

In the following test cases, each row of the matrix is expressed as its decimal representation.

```<code>Input : [ 3710, 3360, 1149, 2340, 2407, 4034, 3521, 2529, 2527, 3999, 2135, 3267 ]
Output: [ 3, 4 ]

Input : [ 1222, 3107, 1508, 3997, 1906, 379, 2874, 2926, 1480, 1487, 3565, 633 ]
Output: [ 3, 7 ]

Input : [ 2796, 206, 148, 763, 429, 1274, 2170, 2495, 42, 1646, 363, 1145 ]
Output: [ 6, 4 ]

Input : [ 3486, 3502, 1882, 1886, 2003, 1442, 2383, 2808, 1416, 1923, 2613, 519 ]
Output: [ 1, 1 ]

Input : [ 3661, 2382, 2208, 1583, 1865, 3969, 2864, 3074, 475, 2382, 1838, 127 ]
Output: [ 8, 8 ]

Input : [ 361, 1275, 3304, 2878, 3733, 3833, 3971, 3405, 2886, 448, 3101, 22 ]
Output: [ 0, 3 ]

Input : [ 3674, 2852, 1571, 3582, 1402, 3331, 1741, 2678, 2076, 2685, 734, 261 ]
Output: [ 7, 7 ]
</code>```

答:
Python, 137 bytes (according to Linux (thanks ElPedro))

```<code>def f(s,q=0):import re
 i=s.index(re.findall('1011.{8}1110.{8}1110.{8}1111',s)[q])+1
 x=i%12
 y=(i-x)/12
 if x>8:x,y=f(s,q+1)
 return x,y
</code>```

Not exactly a competitive bytecount, but the algorithm is a bit interesting. Takes input as a string of binary values.

ContentLicense: CC BY-SA 4.0

Title: Where's the 0xBEEF?

Body:
Python, 137 bytes (according to Linux (thanks ElPedro))

def f(s,q=0):import re
 i=s.index(re.findall('1011.{8}1110.{8}1110.{8}1111',s)[q])+1
 x=i%12
 y=(i-x)/12
 if x>8:x,y=f(s,q+1)
 return x,y

Not exactly a competitive bytecount, but the algorithm is a bit interesting. Takes input as a string of binary values.


答:
Python, <s>30</s> 28 bytes

n=2
while 2**~-n%n**3-1:n+=1
```

This program will halt if and only if there is an integer n bigger than 1 such that 2^(n-1)-1 is divisible by n^3. To my knowledge it is not known whether any number with this property exists (if a number satisfying this property is prime, it is called a Wieferich prime of order 3 to base 2, and it is open whether any such prime exists).

Title: Does the code terminate?

Body:
This is a code golf challenge I thought of with a mathematical bent. The challenge is to write the shortest code possible such that it is an open question whether or not the code terminates. An example of what I mean could be the following piece of python code, adapted from an anwser to this cs stackexchange question.

```<code>def is_perfect(n):
    return sum(i for i in range(1, n) if n % i == 0) == n

n = 3
while not is_perfect(n):
    n = n + 2
</code>```

Mathematicians conjecture that there are no odd perfect numbers, but it has never been proven, so no one knows if this piece of code will ever terminate. Can you come up with other pieces of code (perhaps relying on other open problems like the Collatz conjecture, or the twin primes conjecture) that are shorter, but for which it is unknown whether or not they terminate?

Edit: Some people have brought up a good additional rule - The solutions to the question should be deterministic. Although it might be even more interesting if you could find shorter solutions using nondeterminism. In this case, the rule would be to find a snippet for which the probability of termination is unknown.

Body:
Python, <s>30</s> 28 bytes

n=2
while 2**~-n%n**3-1:n+=1

This program will halt if and only if there is an integer n bigger than 1 such that 2^(n-1)-1 is divisible by n^3. To my knowledge it is not known whether any number with this property exists (if a number satisfying this property is prime, it is called a Wieferich prime of order 3 to base 2, and it is open whether any such prime exists).


问:
Can I take your order: a Chipotle concept conund

Challenge

Your program will take in a string from stdin, and output multiple lines to stdout.

An example of input looks like this:

My favorite Chipotle order:

B1113YNNY

Let's break it down:

The first character is either A (burrito), or B (burrito bowl).

The second character is 1 (black beans), or 2 (pinto beans).

The third character is either 1 (white rice), or 2 (brown rice).

The fourth character is either 1 (chicken), 2 (sofritas), or 3 (steak).

The fifth character is either 1 (mild salsa), 2 (medium salsa), or 3 (hot salsa).

The last four characters are Y if they want the item, or N otherwise:

character 6 is corn

character 7 is guacamole

character 8 is sour cream

character 9 is cheese

A working program for this challenge will output this to stdout:

burrito bowl with:

  black beans

  white rice

  chicken

  hot salsa

  corn

  cheese

Replace the above words with the words acquired from input.

Clarifications.

Standard loopholes are disallowed.

You may only get input from stdin, and only put output to stdout.

答:
C#, 737 Bytes

Not going to win any prizes here...

Golfed:

```<code>string O(string s){var c=new List<string>();var m=new Dictionary<int,List<string>>(){{0,new List<string>(){"burrito","burrito bowl"}},{1,new List<string>(){"","black beans","pinto beans"}},{2,new List<string>(){"","white rice","brown rice"}},{3,new List<string>(){"","chicken","sofritas","steak"}},{4,new List<string>(){"","mild salsa","medium salsa","hot salsa"}},{5,new List<string>(){"corn"}},{6,new List<string>(){"guacamole"}},{7,new List<string>(){"sour cream"}},{8,new List<string>(){"cheese"}},};for(int i=0;i<s.Length;i++){if(i==0){c.Add(s[0]=='A'?m[0][0]:m[0][1]+" with:");continue;}if(i>4){c.Add(s[i]=='Y'?m[i][0]:"");continue;}c.Add(m[i][int.Parse(s[i]+"")]);}return string.Join("\n",c.Where(o =>!string.IsNullOrEmpty(o)));}}
</code>```

Ungolfed:

```<code>public string O(string s)
{
  var c = new List<string>();

  var m = new Dictionary<int, List<string>>()
  {
    {0, new List<string>(){"burrito", "burrito bowl"}},
    {1, new List<string>(){"", "black beans", "pinto beans"}},
    {2, new List<string>(){ "", "white rice", "brown rice"}},
    {3, new List<string>(){ "", "chicken", "sofritas", "steak"}},
    {4, new List<string>(){ "", "mild salsa", "medium salsa", "hot salsa"}},
    {5, new List<string>(){"corn"}},
    {6, new List<string>(){"guacamole"}},
    {7, new List<string>(){"sour cream"}},
    {8, new List<string>(){"cheese"}},
  };

  for (int i = 0; i < s.Length; i++)
  {
    if (i == 0)
    {
      c.Add(s[0] == 'A' ? m[0][0] : m[0][1] + " with:");
      continue;
    }

    if (i > 4)
    {
      c.Add(s[i] == 'Y' ? m[i][0] : "");
      continue;
    }

    c.Add(m[i][int.Parse(s[i]+"")]);
  }

  return string.Join("\n", c.Where(o => !string.IsNullOrEmpty(o)));
}
</code>```

Testing:

```<code>  var chipotleOrder = new ChipotleOrder();
  Console.WriteLine(chipotleOrder.P(Console.ReadLine()));
  Console.ReadLine();
</code>```

Output:

```<code>burrito bowl with:
black beans
white rice
chicken
hot salsa
corn
cheese
</code>```

Body:
C#, 737 Bytes

Not going to win any prizes here...

Golfed:

string O(string s){var c=new List<string>();var m=new Dictionary<int,List<string>>(){{0,new List<string>(){"burrito","burrito bowl"}},{1,new List<string>(){"","black beans","pinto beans"}},{2,new List<string>(){"","white rice","brown rice"}},{3,new List<string>(){"","chicken","sofritas","steak"}},{4,new List<string>(){"","mild salsa","medium salsa","hot salsa"}},{5,new List<string>(){"corn"}},{6,new List<string>(){"guacamole"}},{7,new List<string>(){"sour cream"}},{8,new List<string>(){"cheese"}},};for(int i=0;i<s.Length;i++){if(i==0){c.Add(s[0]=='A'?m[0][0]:m[0][1]+" with:");continue;}if(i>4){c.Add(s[i]=='Y'?m[i][0]:"");continue;}c.Add(m[i][int.Parse(s[i]+"")]);}return string.Join("\n",c.Where(o =>!string.IsNullOrEmpty(o)));}}

Ungolfed:

public string O(string s)
{
  var c = new List<string>();

  var m = new Dictionary<int, List<string>>()
  {
    {0, new List<string>(){"burrito", "burrito bowl"}},
    {1, new List<string>(){"", "black beans", "pinto beans"}},
    {2, new List<string>(){ "", "white rice", "brown rice"}},
    {3, new List<string>(){ "", "chicken", "sofritas", "steak"}},
    {4, new List<string>(){ "", "mild salsa", "medium salsa", "hot salsa"}},
    {5, new List<string>(){"corn"}},
    {6, new List<string>(){"guacamole"}},
    {7, new List<string>(){"sour cream"}},
    {8, new List<string>(){"cheese"}},
  };

  for (int i = 0; i < s.Length; i++)
  {
    if (i == 0)
    {
      c.Add(s[0] == 'A' ? m[0][0] : m[0][1] + " with:");
      continue;
    }

    if (i > 4)
    {
      c.Add(s[i] == 'Y' ? m[i][0] : "");
      continue;
    }

    c.Add(m[i][int.Parse(s[i]+"")]);
  }

  return string.Join("\n", c.Where(o => !string.IsNullOrEmpty(o)));
}

Testing:

  var chipotleOrder = new ChipotleOrder();
  Console.WriteLine(chipotleOrder.P(Console.ReadLine()));
  Console.ReadLine();

Output:

burrito bowl with:
black beans
white rice
chicken
hot salsa
corn
cheese


答:
Scala, 196 bytes

```<code>def f(l:Int,c:(Int,Int)*)=c.permutations.map(x=>((0,0)+:x sliding 2 map{p=>val Seq(c,d)=Seq((p(0)._1-p(1)._1)abs,(p(0)._2-p(1)._2)abs).sorted
c*1.5+(d-c)}scanLeft 0d)(_+_)takeWhile(_<l)size).max-1
</code>```

Ungolfed:

```<code>def g (l: Int, c: (Int, Int)*) = {
    c.permutations
    .map { x =>
        ((0, 0) +: x).sliding(2).map({ p =>
            val Seq(c, d) = Seq((p(0)._1 - p(1)._1) abs, (p(0)._2 - p(1)._2) abs).sorted
            c * 1.5 + (d - c)
        }).scanLeft(0d)(_ + _).takeWhile(_ < l).size
    }.max - 1
}
</code>```

Explanantion:

```<code>def f(l:Int,c:(Int,Int)*)= //defien a function with an int and a vararg-int-pait parameter
  c.permutations           //get the permutations of c, that is all possible routes
  .map(x=>                 //map each of them to...
    ((0,0)+:x                //prepend (0,0)
    sliding 2                //convert to a sequence of consecutive elemtens
    map{p=>                  //and map each of them to their distance:
      val Seq(c,d)=Seq(        //create a sequence of
        (p(0)._1-p(1)._1)abs,  //of the absolute distance between the x points
        (p(0)._2-p(1)._2)abs   //and he absolute distance between the y coordinates
      ).sorted                 //sort them and assign the smaller one to c and the larger one to d
      c*1.5+(d-c)              //we do the minimum difference diagonally
    }                        //we now have a sequence of sequence of the distances for each route
    scanLeft 0d)(_+_)       //calculate the cumulative sum
    takeWhile(_<l)          //and drop all elements that are larger than the candle lifespan
    size                    //take the size
  ).max-1                   //take the maximum, taht is the size of the largest route and subtract 1 because we added (0,0) at the beginning
</code>```

Title: Traveling Pumpkin Problem

Body:
Background:

Jack is a pumpkin that enjoys spooking the citizens of the villages near his pumpkin patch every Halloween.  However, every year after someone lights the candle inside of him, he has a limited amount of time to spook everyone before the candle burns out, thus being unable to spook any more villagers because nobody can see him.  In past years, he has only been able to spook a small amount of villages due to his poor decision making, but now that he has you to help him, he will be able to spook as many villages as possible!

Task:

Given a list of village locations and a candle lifespan, output the maximum number of villages Jack can visit.  You do not have to print the path itself.

Input:

The lifespan of the candle and a list of village locations in a Cartesian coordinate system.  The pumpkin patch Jack originates from will always be at 0,0.  You may format the input in anyway you wish.  To simplify Jack's movements, he can only move horizontally, vertically, or diagonally, meaning his candle will either lose 1 or 1.5 (he takes a bit longer diagonally) units of life every move.  The candle burns out when the lifespan is less than or equal to 0.

Output:

An integer equal to the maximum number of villages Jack can visit before the candle burns out.

Rules:

This is code-golf, so shortest code in bytes wins.  Standard loopholes are not allowed.

Test cases:

```<code>// Format [lifespan] [list of village coordinates] -> [maximum visit-able villages]

4 -1,0 1,0 2,0 3,0 4,0 5,0 -> 3
4 1,1 2,2 3,3 -> 2
5 1,1 2,1 3,1 4,1 5,0 5,1 -> 4
</code>```

Body:
Scala, 196 bytes

def f(l:Int,c:(Int,Int)*)=c.permutations.map(x=>((0,0)+:x sliding 2 map{p=>val Seq(c,d)=Seq((p(0)._1-p(1)._1)abs,(p(0)._2-p(1)._2)abs).sorted
c*1.5+(d-c)}scanLeft 0d)(_+_)takeWhile(_<l)size).max-1

Ungolfed:

def g (l: Int, c: (Int, Int)*) = {
    c.permutations
    .map { x =>
        ((0, 0) +: x).sliding(2).map({ p =>
            val Seq(c, d) = Seq((p(0)._1 - p(1)._1) abs, (p(0)._2 - p(1)._2) abs).sorted
            c * 1.5 + (d - c)
        }).scanLeft(0d)(_ + _).takeWhile(_ < l).size
    }.max - 1
}

Explanantion:

def f(l:Int,c:(Int,Int)*)= //defien a function with an int and a vararg-int-pait parameter
  c.permutations           //get the permutations of c, that is all possible routes
  .map(x=>                 //map each of them to...
    ((0,0)+:x                //prepend (0,0)
    sliding 2                //convert to a sequence of consecutive elemtens
    map{p=>                  //and map each of them to their distance:
      val Seq(c,d)=Seq(        //create a sequence of
        (p(0)._1-p(1)._1)abs,  //of the absolute distance between the x points
        (p(0)._2-p(1)._2)abs   //and he absolute distance between the y coordinates
      ).sorted                 //sort them and assign the smaller one to c and the larger one to d
      c*1.5+(d-c)              //we do the minimum difference diagonally
    }                        //we now have a sequence of sequence of the distances for each route
    scanLeft 0d)(_+_)       //calculate the cumulative sum
    takeWhile(_<l)          //and drop all elements that are larger than the candle lifespan
    size                    //take the size
  ).max-1                   //take the maximum, taht is the size of the largest route and subtract 1 because we added (0,0) at the beginning


答:
Java 7, 206 201 bytes

Thanks to @KevinCruijssen for saving 5 bytes

int f(float e,int[]a,int[]b){int x=0,y=0,c=0,d=0,t;float s;for(int i:a){s=(i!=x&b[c]==y)|(i==x&b[c]!=y)?Math.sqrt((t=i-x)*t+(t=b[c]-y)*t)*1:Math.abs(i-x)*1.5;d+=e-s>=0?1:0;e-=s;x=i;y=b[c++];}return d;}
```

<h1>Ungolfed</h1>

<pre class="lang-java prettyprint-override"><code>class Travellingpumpkin {

public static void main(String[] args) {

    System.out.println(f( 5 ,new int[] { 1,2,3,4,5,5 } , new int[] { 1,1,1,1,0,1 } ));

}
static int f( double e , int[]a , int[]b ) {
    int x = 0 , y = 0 , c = 0 , d = 0 , t;
    double s ;

    for ( int i : a ) {
    s = ( i != x & b[c] == y )|( i == x & b[c] != y )
         ? Math.sqrt( ( t = i - x ) * t + ( t = b[c] - y ) * t ) * 1
         : Math.abs( i - x ) * 1.5 ;

        d += e-s >= 0 ? 1 : 0 ;
        e -= s ;
        x = i ; y = b [ c++ ] ;
    }
    return d ;

}

   }
</code>```

Title: Traveling Pumpkin Problem

Body:
Java 7, 206 201 bytes

Thanks to @KevinCruijssen for saving 5 bytes

int f(float e,int[]a,int[]b){int x=0,y=0,c=0,d=0,t;float s;for(int i:a){s=(i!=x&b[c]==y)|(i==x&b[c]!=y)?Math.sqrt((t=i-x)*t+(t=b[c]-y)*t)*1:Math.abs(i-x)*1.5;d+=e-s>=0?1:0;e-=s;x=i;y=b[c++];}return d;}

Ungolfed

class Travellingpumpkin {

public static void main(String[] args) {

    System.out.println(f( 5 ,new int[] { 1,2,3,4,5,5 } , new int[] { 1,1,1,1,0,1 } ));

}
static int f( double e , int[]a , int[]b ) {
    int x = 0 , y = 0 , c = 0 , d = 0 , t;
    double s ;

    for ( int i : a ) {
    s = ( i != x & b[c] == y )|( i == x & b[c] != y )
         ? Math.sqrt( ( t = i - x ) * t + ( t = b[c] - y ) * t ) * 1
         : Math.abs( i - x ) * 1.5 ;

        d += e-s >= 0 ? 1 : 0 ;
        e -= s ;
        x = i ; y = b [ c++ ] ;
    }
    return d ;

}

   }


问:
Maximal number of regions obtained by joining n points around a circle by straight lines
Let's define f(n) as the maximal number of regions obtained by joining n points around a circle by straight lines. For example, two points would split the circle into two pieces, three into four, like this:

Make sure when you are drawing the lines, you don't have an intersection of more than two lines.

Your task

Given a number n, print f(n).

Test cases:

```<code> n | f(n)
---+-----
 1 |   1
 2 |   2
 3 |   4
 4 |   8
 5 |  16
 6 |  31
 7 |  57
 8 |  99
 9 | 163
</code>```

You can see more here.

Using built-in sequence generators is not allowed.

Remember, this is code-golf, so the code with the smallest number of bytes wins.

If you guys want the formula, here it is:

答:
TI-89 Basic, 57 Bytes

```<code>:Def a(a)=Func
:Return nCr(n,0)+nCr(n,2)+nCr(n,4)
:End Func
</code>```

Throwback to old times.

Body:
TI-89 Basic, 57 Bytes

:Def a(a)=Func
:Return nCr(n,0)+nCr(n,2)+nCr(n,4)
:End Func

Throwback to old times.


答:
JavaScript (ES6), 267

```<code>a=>[...a].map((c,i,a,s=x=>`
`+(','+x).split`,`[c])=>i--?i--?i--?i--?i?c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):'':s`mild,medium,hot`+' salsa':s`chicken,sofritas,steak`:s`white,brown`+' rice':s`black,pinto`+' beans':'burrito'+(c>'A'?' bowl':'')+' with:').join``
</code>```

Less golfed

```<code>a=>
[...a].map((c,i,a,s=x=>'\n'+(','+x).split`,`[c])=>
       i--?i--?i--?i--?i?
       c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):''
       :s`mild,medium,hot`+' salsa'
       :s`chicken,sofritas,steak`
       :s`white,brown`+' rice'
       :s`black,pinto`+' beans'
       :'burrito'+(c>'A'?' bowl':'')+' with:'
).join``
</code>```

Test

f=
a=>[...a].map((c,i,a,s=x=>`
`+(','+x).split`,`[c])=>i--?i--?i--?i--?i?c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):'':s`mild,medium,hot`+' salsa':s`chicken,sofritas,steak`:s`white,brown`+' rice':s`black,pinto`+' beans':'burrito'+(c>'A'?' bowl':'')+' with:').join``

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

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

Title: Can I take your order: a Chipotle concept conund

Body:
Challenge

Your program will take in a string from stdin, and output multiple lines to stdout.

An example of input looks like this:

My favorite Chipotle order:

B1113YNNY

Let's break it down:

The first character is either A (burrito), or B (burrito bowl).

The second character is 1 (black beans), or 2 (pinto beans).

The third character is either 1 (white rice), or 2 (brown rice).

The fourth character is either 1 (chicken), 2 (sofritas), or 3 (steak).

The fifth character is either 1 (mild salsa), 2 (medium salsa), or 3 (hot salsa).

The last four characters are Y if they want the item, or N otherwise:

character 6 is corn

character 7 is guacamole

character 8 is sour cream

character 9 is cheese

A working program for this challenge will output this to stdout:

burrito bowl with:

  black beans

  white rice

  chicken

  hot salsa

  corn

  cheese

Replace the above words with the words acquired from input.

Clarifications.

Standard loopholes are disallowed.

You may only get input from stdin, and only put output to stdout.

Body:
JavaScript (ES6), 267

a=>[...a].map((c,i,a,s=x=>`
`+(','+x).split`,`[c])=>i--?i--?i--?i--?i?c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):'':s`mild,medium,hot`+' salsa':s`chicken,sofritas,steak`:s`white,brown`+' rice':s`black,pinto`+' beans':'burrito'+(c>'A'?' bowl':'')+' with:').join``

Less golfed

a=>
[...a].map((c,i,a,s=x=>'\n'+(','+x).split`,`[c])=>
       i--?i--?i--?i--?i?
       c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):''
       :s`mild,medium,hot`+' salsa'
       :s`chicken,sofritas,steak`
       :s`white,brown`+' rice'
       :s`black,pinto`+' beans'
       :'burrito'+(c>'A'?' bowl':'')+' with:'
).join``

Test

f=
a=>[...a].map((c,i,a,s=x=>`
`+(','+x).split`,`[c])=>i--?i--?i--?i--?i?c>'N'?(c=i,s`corn,guacamole,sour cream,cheese`):'':s`mild,medium,hot`+' salsa':s`chicken,sofritas,steak`:s`white,brown`+' rice':s`black,pinto`+' beans':'burrito'+(c>'A'?' bowl':'')+' with:').join``

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

update()

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


问:
Totally Invertible Submatrices
(inspired by this question over on Math)

The Definitions

Given an n x n square matrix A, we can call it invertible if there exists some n x n square matrix B such that AB = BA = In, with In being the identity matrix of size n x n (the matrix with the main diagonal 1s and anything else 0), and AB and BA representing usual matrix multiplication (I won't go into that here - go take a linear algebra class).

From that, we can call an m x n matrix C totally invertible if every k x k submatrix (defined below) of C is invertible for all k > 1, k <= (smaller of m,n).

A submatrix is defined as the resulting matrix after deletion of any number of rows and/or columns from the original matrix. For example, the below 3x3 matrix C can be transformed into a 2x2 submatrix C' by removing the first row 1 2 3 and the middle column 2 5 8 as follows:

```<code>C = [[1 2 3]
     [4 5 6]    -->  C' = [[4 6]
     [7 8 9]]              [7 9]]
</code>```

Note that there are many different submatrix possibilities, the above is just an example. This challenge is only concerned with those where the resulting submatrix is a k x k square matrix.

The Challenge

Given an input matrix, determine if it is totally invertible or not.

The Input

A single matrix of size m x n, in any suitable format.

Without loss of generality, you can assume m <= n or m >= n, whichever is golfier for your code, and take the input that way (i.e., you get a transpose operation for free if you want it).

The input matrix size will be no smaller than 3 x 3, and no larger than your language can handle.

The input matrix will consist of only numeric values from Z+ (the positive integers).

The Output

A truthy/falsey value for whether the input matrix is totally invertible.

The Rules

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

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

The Examples

```<code>Truthy

[[1 2 3]
 [2 3 1]
 [3 1 2]]

[[2 6 3]
 [1 12 2]
 [5 3 1]]

[[1 2 3 4]
 [2 3 4 1]
 [3 4 1 2]]

[[2  3  5  7  11]
 [13 17 19 23 29]
 [31 37 41 43 47]]

Falsey

[[1 2 3]
 [4 5 6]
 [7 8 9]]

[[1 6 2 55 3]
 [4 5 5 5  6]
 [9 3 7 10 4]
 [7 1 8 23 9]]

[[2 3 6]
 [1 2 12]
 [1 1 6]]

[[8 2 12 13 2]
 [12 7 13 12 13]
 [8 1 12 13 5]]
</code>```

答:
Jelly, <s>26 24 23 20 19 17</s> 16 bytes

-1 byte thanks to @miles (unnecessary for each, €, when taking determinants)

-2 bytes, @miles again! (unnecessary chain separation, and use of Ð€ quick)

```<code>ZœcLÆḊ
œcÐ€JÇ€€Ȧ
</code>```

TryItOnline! or all 8 tests

How?

```<code>œcÐ€JÇ€€Ȧ  - Main link: matrix as an array, M
    J      - range of length -> [1,2,...,len(a)] (n)
  Ð€       - for each of right argument
œc         -     combinations of M numbering n
     Ç€€   - call the last link (1) as a monad for €ach for €ach
        Ȧ  - all truthy (any determinant of zero results in 0, otherwise 1)
                 (this includes an implicit flattening of the list)

ZœcLÆḊ - Link 1, determinants of sub-matrices: row selection, s
Z      - transpose s
   L   - length of s
 œc    - combinations of transposed s numbering length of s
    ÆḊ - determinant
</code>```

Title: Totally Invertible Submatrices

Body:
Jelly, <s>26 24 23 20 19 17</s> 16 bytes

-1 byte thanks to @miles (unnecessary for each, €, when taking determinants)

-2 bytes, @miles again! (unnecessary chain separation, and use of Ð€ quick)

ZœcLÆḊ
œcÐ€JÇ€€Ȧ

TryItOnline! or <a href="http://jelly.tryitonline.net/#code=WsWTY0zDhuG4igrFk2PDkOKCrErDh-KCrOKCrMimCsOH4oKs&input=&args=WwpbWzEsIDIsIDNdLAogWzIsIDMsIDFdLAogWzMsIDEsIDJdXSwKW1syLCA2LCAzXSwKIFsxLCAxMiwgMl0sCiBbNSwgMywgMV1dLApbWzEsIDIsIDMsIDRdLAogWzIsIDMsIDQsIDFdLAogWzMsIDQsIDEsIDJdXSwKW1syLCAgMywgIDUsICA3LCAgMTFdLAogWzEzLCAxNywgMTksIDIzLCAyOV0sCiBbMzEsIDM3LCA0MSwgNDMsIDQ3XV0sCltbMSwgMiwgM10sCiBbNCwgNSwgNl0sCiBbNywgOCwgOV1dLApbWzEsIDYsIDIsIDU1LCAzXSwKIFs0LCA1LCA1LCA1LCAgNl0sCiBbOSwgMywgNywgMTAsIDRdLAogWzcsIDEsIDgsIDIzLCA5XV0sCltbMiwgMywgNl0sCiBbMSwgMiwgMTJdLAogWzEsIDEsIDZdXSwKW1s4LCAyLCAxMiwgMTMsIDJdLAogWzEyLCA3LCAxMywgMTIsIDEzXSwKIFs4LCAxLCAxMiwgMTMsIDVdXQpd" rel="nofollow noreferrer">all 8 tests

How?

œcÐ€JÇ€€Ȧ  - Main link: matrix as an array, M
    J      - range of length -> [1,2,...,len(a)] (n)
  Ð€       - for each of right argument
œc         -     combinations of M numbering n
     Ç€€   - call the last link (1) as a monad for €ach for €ach
        Ȧ  - all truthy (any determinant of zero results in 0, otherwise 1)
                 (this includes an implicit flattening of the list)

ZœcLÆḊ - Link 1, determinants of sub-matrices: row selection, s
Z      - transpose s
   L   - length of s
 œc    - combinations of transposed s numbering length of s
    ÆḊ - determinant


答:
MATL, 27 bytes

```<code>EH:"iY@OwYc!d|]yyXl++Ys>sX>
</code>```

EDIT (26 nov 2016): Due to changes in the Xl function, it has to be replaced in the above code by 2$X>. The links below incorporate that modification.

Try it online! Or verify all test cases.

Explanation

The pumpkin distance between two cities separated Δx and Δy in each coordinate can be obtained as ( |Δx| + |Δy| + max(|Δx|, |Δy|) ) / 2.

The code follows these steps:

Generate all permutations of x coordinates and of y coordinates, and prepend a to each 0. Each permutation represents a possible path.

Compute absolute consecutive differences for each path (these are |Δx| and |Δy| above).

Obtain the pumpkin distance for each step of each path.

Compute the cumulative sum of distances for each path.

Find, for each path, the number of steps before the accumulated distance reaches the chandle lifespan.

Take the maximum of the above.

Commented code:

```<code>E        % Input candle lifespan implicitly. Multiply by 2
H:"      % Do thie twice
  i      %   Input array of x or y coordinates
  Y@     %   All permutations. Gives a matrix, with each permutation in a row
  OwYc   %   Prepend a 0 to each row
  !      %   Transpose
  d|     %   Consecutive differences along each column. Absolute value
]        % End
yy       % Duplicate the two matrices (x and y coordinates of all paths)
Xl       % Take maximum between the two, element-wise
++       % Add twice. This gives twice the pumpkin distance
Ys       % Cumulative sum along each column
>        % True for cumulative sums that exceed twice the candle lifespan
s        % Sum of true values for each column
X>       % Maximum of the resulting row array. Inmplicitly display
</code>```

Title: Traveling Pumpkin Problem

Body:
MATL, 27 bytes

EH:"iY@OwYc!d|]yyXl++Ys>sX>

EDIT (26 nov 2016): Due to changes in the Xl function, it has to be replaced in the above code by 2$X>. The links below incorporate that modification.

Try it online! Or verify all test cases.

Explanation

The pumpkin distance between two cities separated Δx and Δy in each coordinate can be obtained as ( |Δx| + |Δy| + max(|Δx|, |Δy|) ) / 2.

The code follows these steps:

Generate all permutations of x coordinates and of y coordinates, and prepend a to each 0. Each permutation represents a possible path.

Compute absolute consecutive differences for each path (these are |Δx| and |Δy| above).

Obtain the pumpkin distance for each step of each path.

Compute the cumulative sum of distances for each path.

Find, for each path, the number of steps before the accumulated distance reaches the chandle lifespan.

Take the maximum of the above.

Commented code:

E        % Input candle lifespan implicitly. Multiply by 2
H:"      % Do thie twice
  i      %   Input array of x or y coordinates
  Y@     %   All permutations. Gives a matrix, with each permutation in a row
  OwYc   %   Prepend a 0 to each row
  !      %   Transpose
  d|     %   Consecutive differences along each column. Absolute value
]        % End
yy       % Duplicate the two matrices (x and y coordinates of all paths)
Xl       % Take maximum between the two, element-wise
++       % Add twice. This gives twice the pumpkin distance
Ys       % Cumulative sum along each column
>        % True for cumulative sums that exceed twice the candle lifespan
s        % Sum of true values for each column
X>       % Maximum of the resulting row array. Inmplicitly display


答:
Mathematica, 42 bytes

```<code>!MatchQ[#,{a__,b_,___}/;Min@Abs[{a}-b]>1]&
</code>```

Uses pattern matching to try and find a prefix a whose maximum difference from the next element b is greater than 1 (and negating the result of MatchQ).

Title: Antsy permutations

Body:
Introduction

Suppose you have a ruler with numbers from 0 to r-1.
You place an ant between any two of the numbers, and it starts to crawl erratically on the ruler.
The ruler is so narrow that the ant cannot walk from one position to another without walking on all the numbers in between.
As the ant walks on a number for the first time, you record it, and this gives you a permutation of the r numbers.
We say that a permutation is antsy if it can be generated by an ant in this way.
Alternatively, a permutation p is antsy if every entry p[i] except the first is within distance 1 from some previous entry.

Examples

The length-6 permutation

```<code>4, 3, 5, 2, 1, 0
</code>```

is antsy, because 3 is within distance 1 of 4, 5 is within distance 1 of 4, 2 is within distance 1 from 3, 1 is within distance 1 from 2, and 0 is within distance 1 from 1.
The permutation

```<code>3, 2, 5, 4, 1, 0
</code>```

is not antsy, because 5 is not within distance 1 of either 3 or 2; the ant would have to pass through 4 to get to 5.

The task

Given a permutation of the numbers from 0 to r-1 for some 1 ≤ r ≤ 100 in any reasonable format, output a truthy value if the permutation is antsy, and a falsy value if not.

Test cases

```<code>[0] -> True
[0, 1] -> True
[1, 0] -> True
[0, 1, 2] -> True
[0, 2, 1] -> False
[2, 1, 3, 0] -> True
[3, 1, 0, 2] -> False
[1, 2, 0, 3] -> True
[2, 3, 1, 4, 0] -> True
[2, 3, 0, 4, 1] -> False
[0, 5, 1, 3, 2, 4] -> False
[6, 5, 4, 7, 3, 8, 9, 2, 1, 0] -> True
[4, 3, 5, 6, 7, 2, 9, 1, 0, 8] -> False
[5, 2, 7, 9, 6, 8, 0, 4, 1, 3] -> False
[20, 13, 7, 0, 14, 16, 10, 24, 21, 1, 8, 23, 17, 18, 11, 2, 6, 22, 4, 5, 9, 12, 3, 15, 19] -> False
[34, 36, 99, 94, 77, 93, 31, 90, 21, 88, 30, 66, 92, 83, 42, 5, 86, 11, 15, 78, 40, 48, 22, 29, 95, 64, 97, 43, 14, 33, 69, 49, 50, 35, 74, 46, 26, 51, 75, 87, 23, 85, 41, 98, 82, 79, 59, 56, 37, 96, 45, 17, 32, 91, 62, 20, 4, 9, 2, 18, 27, 60, 63, 25, 61, 76, 1, 55, 16, 8, 6, 38, 54, 47, 73, 67, 53, 57, 7, 72, 84, 39, 52, 58, 0, 89, 12, 68, 70, 24, 80, 3, 44, 13, 28, 10, 71, 65, 81, 19] -> False
[47, 48, 46, 45, 44, 49, 43, 42, 41, 50, 40, 39, 38, 51, 37, 36, 52, 35, 34, 33, 32, 53, 54, 31, 30, 55, 56, 29, 28, 57, 58, 59, 60, 27, 26, 61, 25, 62, 63, 64, 65, 66, 67, 24, 23, 22, 21, 68, 69, 20, 19, 18, 17, 70, 71, 16, 15, 72, 73, 74, 75, 76, 14, 13, 12, 77, 11, 10, 9, 8, 78, 7, 79, 80, 6, 81, 5, 4, 3, 82, 2, 83, 84, 1, 85, 86, 87, 0, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] -> True
</code>```

Fun fact: for r ≥ 1, there are exactly 2r-1 antsy permutations of length r.

Body:
Mathematica, 42 bytes

!MatchQ[#,{a__,b_,___}/;Min@Abs[{a}-b]>1]&

Uses pattern matching to try and find a prefix a whose maximum difference from the next element b is greater than 1 (and negating the result of MatchQ).


问:
Fill in the Minesweeper clues
Minesweeper is a popular puzzle game where you must discover which tiles are "mines" without clicking on those tiles. Each tile is either a mine (represented by *) or a clue, i.e. a number from 0 to 8 representing how many of the 8 neighboring tiles are mines. Your task today is to take a board containing the mines and fill in all of the clues. For example, look at the following 5x4 board, with 5 mines:

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

After filling in the clues, the board will look like this:

```<code>2*211
*33*1
12*32
0112*
</code>```

Details

You must write either a full-program or a function that takes in a grid of characters containing only spaces and asterisks and outputs another grid where each space is replaced with the number of adjacent mines (asterisks). Any of these are acceptable formats for your grids:

A string with newlines in it

A 2D list of characters/single character strings

A list of strings

You can assume the grid will be at least 1x1, although it is possible for it to be all mines or all spaces.

The input grid will always be padded with the appropriate number of spaces. As usual, this is code-golf, so standard loopholes apply and the shortest answer in bytes wins!

Sample IO

So that you can see the whitespace, I will show all sample IO with brackets around it.

```<code>Input:
[    * ]
[*     ]
[      ]
[      ]
[  **  ]
[ *  * ]

Output:
[1101*1]
[*10111]
[110000]
[012210]
[12**21]
[1*33*1]

Input:
[****]
[****]

Output:
[****]
[****]

Input:
[   ]
[   ]
[   ]
[   ]

Output:
[000]
[000]
[000]
[000]

Input:
[*   ]
[**  ]
[    ]
[   *]

Ouput:
[*310]
[**10]
[2221]
[001*]

Input:
[**    ]
[*    *]
[  *   ]
[      ]
[*     ]
[****  ]

Output:
[**1011]
[*4211*]
[12*111]
[121100]
[*43210]
[****10]

Input:
[     *    ]
[        * ]
[     *    ]
[**   ***  ]
[      *** ]
[          ]
[       ** ]
[  * *     ]
[*      ** ]
[       ** ]

Output:
[00001*1111]
[00002221*1]
[22102*4321]
[**102***31]
[221013***1]
[0000013542]
[0112111**1]
[12*2*12442]
[*212112**2]
[1100002**2]
</code>```

答:
C, <s>152</s> <s>150</s> <s>147</s> 145 bytes

i,j,r,c;f(B,R,C)char**B;{for(i=R*C;i--;)for(j=9;j--;){char*b=B[i/C]+i%C;r=i/C+j/3-1;c=i%C+j%3-1;r<0|c<0|r/R|c/C|*b&8||(*b=16|*b+(B[r][c]==42));}}
```

<p>Input is in the form of a two-dimensional array of characters, followed by the numbers of rows and columns. The result will be returned in-place.</p>

<p>(Mostly) Ungolfed:</p>

<pre class="lang-c prettyprint-override"><code>i, j, r, c;
f(B, R, C) char **B; {
    for (i = R*C; i--;)
        for (j = 9; j--;) {
            char *b = B[i/C] + i%C;
            r = i/C + j/3 - 1;
            c = i%C + j%3 - 1;
            r < 0 | c < 0 | r / R | c / C | *b & 8 ||
                (*b = 16 | *b + (B[r][c] == 42));
        }
}
</code>```

The approach is straight-forward — loop over each position, loop over its neighbors, and add up all the asterisks. There are two bit-level tricks:

When we're deciding if a cell is an asterisk or not, we can just check if the eights-place bit is set, because the number in the cell must be less than 8 (the maximum cell value).

We can turn a space character into a zero character by OR-ing 16.

Edit: Golfed off two bytes by using / in place of >=.

Edit: Another five bytes by reversing the direction of the loops.

Title: Fill in the Minesweeper clues

Body:
C, <s>152</s> <s>150</s> <s>147</s> 145 bytes

i,j,r,c;f(B,R,C)char**B;{for(i=R*C;i--;)for(j=9;j--;){char*b=B[i/C]+i%C;r=i/C+j/3-1;c=i%C+j%3-1;r<0|c<0|r/R|c/C|*b&8||(*b=16|*b+(B[r][c]==42));}}

Input is in the form of a two-dimensional array of characters, followed by the numbers of rows and columns. The result will be returned in-place.

(Mostly) Ungolfed:

i, j, r, c;
f(B, R, C) char **B; {
    for (i = R*C; i--;)
        for (j = 9; j--;) {
            char *b = B[i/C] + i%C;
            r = i/C + j/3 - 1;
            c = i%C + j%3 - 1;
            r < 0 | c < 0 | r / R | c / C | *b & 8 ||
                (*b = 16 | *b + (B[r][c] == 42));
        }
}

The approach is straight-forward — loop over each position, loop over its neighbors, and add up all the asterisks. There are two bit-level tricks:

When we're deciding if a cell is an asterisk or not, we can just check if the eights-place bit is set, because the number in the cell must be less than 8 (the maximum cell value).

We can turn a space character into a zero character by OR-ing 16.

Edit: Golfed off two bytes by using / in place of >=.

Edit: Another five bytes by reversing the direction of the loops.


问:
Import this into your own language
The Zen of Python must surely be one of the most beautiful Easter eggs in any language. (It is created by writing import this)

So why not create a version for your own language?

For those who don't have access to Python 2 or 3, your code should output the following:

```<code>The Zen of [YOUR LANGUAGE]

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
</code>```

The original was The Zen of Python, by Tim Peters.

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

Standard loopholes apply, this includes no built-ins (if you are making a solution in Python, Pyth or another derivative of Python, the equivalent of import this is forbidden).

Title: Import this into your own language

Body:
JavaScript (ES6) 665 bytes

f=a=>{for(_="._eds  ieaouobvishld itxplicpecial  idonesaty ennever th    to mplbetter   an explain, e Althgh If iemti`ThZ of JS__ButifuluglyEiicSiecoexCoexcoicFlntSparsedseRdabilcntsScas ar't sghbrk  rulpracticalbepuryError passiltlyUnlelsilcIn    facof ambiguy, refusthtemptigusTherbe-- and preferabll--waydo th wamanot b first unly'rDutchNowoft *right* nowhard'a badsy maba goodNampac arhking gre -- let'do morof  ose!`";G=/[-]/.exec(_);)with(_.split(G))_=join(shift());return eval(_).split`_`.join`
`}

Because of string compression, some characters cannot be displayed in this snippet. This is above script hex-encoded:

663D613D3E7B666F72285F3D222E5F1D65641D1C73201B20691B1A6561196F75186F627669181B177368186C64201669741578706C6963151470656369616C201320696419126F6E1165731061740F79200E656E0C6E657665720B2074680920746F20086D706C0762657474657209616E2006086578706C61696E2C2015056520041D416C746818676820031D496609046907656D0C740F69111A021A0601605468045A0C206F66204A535F5F421975746966756C0175676C791D45140169076963151D5369076501636F0765781D436F07657801636F0769630F1C466C0F016E10741C53706172736501640C73651D5219646162696C150E63186E74731D5313636173102061720C27742073130C186768086272196B090472756C100370726163746963616C150E62650F1B70757215791D4572726F721B160B207061731B73696C0C746C791D556E6C101B65146C0E73696C0C631C496E0904666163046F6620616D6269677515792C2072656675730474680474656D70740F691108677510731D546865720416620411652D2D20616E642070726566657261626C0E116C0E11042D2D1777617908646F20150374680F2077610E6D610E6E6F74206204170F20666972737420756E6C101B791827720444757463681D4E6F77010B030B1A6F66740C20062A72696768742A206E6F77026861726405271B6120626164120219737905206D610E62046120676F6F64121D4E616D107061631020617204110468116B696E67206772650F12202D2D206C6574271B646F206D6F72046F66096F73652160223B473D2F5B012D1D5D2F2E65786563285F293B2977697468285F2E73706C6974284729295F3D6A6F696E2873686966742829293B72657475726E206576616C285F292E73706C6974605F602E6A6F696E600D0A607D

It can be compiled using the following function:

f=a=>eval(a.match(/../g).map(a=>String.fromCharCode(parseInt(a,16))).join``)

Demo


答:
Mathematica 10.0, 34 bytes

```<code>#~Minors~n~Table~{n,Tr@#}~FreeQ~0&
</code>```

A 6-tilde chain... new personal record!

Title: Totally Invertible Submatrices

Body:
(inspired by this question over on Math)

The Definitions

Given an n x n square matrix A, we can call it invertible if there exists some n x n square matrix B such that AB = BA = In, with In being the identity matrix of size n x n (the matrix with the main diagonal 1s and anything else 0), and AB and BA representing usual matrix multiplication (I won't go into that here - go take a linear algebra class).

From that, we can call an m x n matrix C totally invertible if every k x k submatrix (defined below) of C is invertible for all k > 1, k <= (smaller of m,n).

A submatrix is defined as the resulting matrix after deletion of any number of rows and/or columns from the original matrix. For example, the below 3x3 matrix C can be transformed into a 2x2 submatrix C' by removing the first row 1 2 3 and the middle column 2 5 8 as follows:

```<code>C = [[1 2 3]
     [4 5 6]    -->  C' = [[4 6]
     [7 8 9]]              [7 9]]
</code>```

Note that there are many different submatrix possibilities, the above is just an example. This challenge is only concerned with those where the resulting submatrix is a k x k square matrix.

The Challenge

Given an input matrix, determine if it is totally invertible or not.

The Input

A single matrix of size m x n, in any suitable format.

Without loss of generality, you can assume m <= n or m >= n, whichever is golfier for your code, and take the input that way (i.e., you get a transpose operation for free if you want it).

The input matrix size will be no smaller than 3 x 3, and no larger than your language can handle.

The input matrix will consist of only numeric values from Z+ (the positive integers).

The Output

A truthy/falsey value for whether the input matrix is totally invertible.

The Rules

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

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

The Examples

```<code>Truthy

[[1 2 3]
 [2 3 1]
 [3 1 2]]

[[2 6 3]
 [1 12 2]
 [5 3 1]]

[[1 2 3 4]
 [2 3 4 1]
 [3 4 1 2]]

[[2  3  5  7  11]
 [13 17 19 23 29]
 [31 37 41 43 47]]

Falsey

[[1 2 3]
 [4 5 6]
 [7 8 9]]

[[1 6 2 55 3]
 [4 5 5 5  6]
 [9 3 7 10 4]
 [7 1 8 23 9]]

[[2 3 6]
 [1 2 12]
 [1 1 6]]

[[8 2 12 13 2]
 [12 7 13 12 13]
 [8 1 12 13 5]]
</code>```

Body:
Mathematica 10.0, 34 bytes

#~Minors~n~Table~{n,Tr@#}~FreeQ~0&

A 6-tilde chain... new personal record!


问:
Which Row is the Key On?
Given any of the following characters (or a newline):

```<code>`1234567890-=~!@#$%^&*()_+qwertyuiop[]\QWERTYUIOP{}|asdfghjkl;'ASDFGHJKL:"zxcvbnm,./ZXCVBNM<>?
</code>```

Your program must output the row that it is on the keyboard

Because my keyboard is (almost) out of battery, your code must be as short as possible

The keyboard your program should use (for the row lookup), should look like:

Row 1:~` !1@2 #3$4 %5^6 &7*8 (9)0 _-+=

Row 2:                         Q W E R T Y U I O P {[ }]    |\
Row 3:                              A S D F G H J K L :; "' ↵ return
Row 4:                                 Z X C V B N M <, >. ?/
Row 5:                                                    space

Where ↵  return is a newline. Empty keys don't mean anything.

Examples

```<code>"$"
1

"R"
2

"a"
3

"?"
4

"\n"
3

" "
5
</code>```

where \n is a newline character.

Specifications

Your program should be case insensitive

Your program only needs to handle the characters on the keyboard shown

答:
C, <s>145 143 136 132 127 106</s> 104 bytes

```<code>#define c"\x7ea6a6f8\x5777595"
f(a){return a-32?L"\x200000\0\xf3008020\xf2a00000"c c[a>>4]>>a%16*2&3:4;}
</code>```

Try it online!

<s>This uses index() from POSIX.1-2001 and is deprecated in POSIX.1-2008.</s>
This assumes ASCII and 32 bit ints.

Title: Which Row is the Key On?

Body:
C, <s>145 143 136 132 127 106</s> 104 bytes

#define c"\x7ea6a6f8\x5777595"
f(a){return a-32?L"\x200000\0\xf3008020\xf2a00000"c c[a>>4]>>a%16*2&3:4;}

Try it online!

<s>This uses index() from POSIX.1-2001 and is deprecated in POSIX.1-2008.</s>
This assumes ASCII and 32 bit ints.


答:
Turtlèd, 99 bytes

(whoops I keep forgetting the link :| )

Takes inputs with brackets around each line

Turtlèd cannot take multi-line input, so after the last line, write | to signal end of input

Note the mismatched brackets are because open brackets parse the next char as part of the bracket command

```<code>[|!.([[]r+.][[l]d)][ u]d[|[]r( #012345678#l(*+)u(*+)r(*+)r(*+)d(*+)d(*+)l(*+)l(*+)ur.)]' [[l]' d]'
</code>```

Try it online!

How it works (general description):

Until | is entered, it writes out the input on each line, with brackets to help it recognise the end of each line.
After that has happened, it goes back up to the top of input. It goes through each character in input. If it is a space, it looks around the space, adding one to the counter for each bomb it finds. after each line, it deletes the brackets. When it gets to the last line, with the | in it, it stops, and deletes the |. the grid is implicitly printed.

Title: Fill in the Minesweeper clues

Body:
Minesweeper is a popular puzzle game where you must discover which tiles are "mines" without clicking on those tiles. Each tile is either a mine (represented by *) or a clue, i.e. a number from 0 to 8 representing how many of the 8 neighboring tiles are mines. Your task today is to take a board containing the mines and fill in all of the clues. For example, look at the following 5x4 board, with 5 mines:

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

After filling in the clues, the board will look like this:

```<code>2*211
*33*1
12*32
0112*
</code>```

Details

You must write either a full-program or a function that takes in a grid of characters containing only spaces and asterisks and outputs another grid where each space is replaced with the number of adjacent mines (asterisks). Any of these are acceptable formats for your grids:

A string with newlines in it

A 2D list of characters/single character strings

A list of strings

You can assume the grid will be at least 1x1, although it is possible for it to be all mines or all spaces.

The input grid will always be padded with the appropriate number of spaces. As usual, this is code-golf, so standard loopholes apply and the shortest answer in bytes wins!

Sample IO

So that you can see the whitespace, I will show all sample IO with brackets around it.

```<code>Input:
[    * ]
[*     ]
[      ]
[      ]
[  **  ]
[ *  * ]

Output:
[1101*1]
[*10111]
[110000]
[012210]
[12**21]
[1*33*1]

Input:
[****]
[****]

Output:
[****]
[****]

Input:
[   ]
[   ]
[   ]
[   ]

Output:
[000]
[000]
[000]
[000]

Input:
[*   ]
[**  ]
[    ]
[   *]

Ouput:
[*310]
[**10]
[2221]
[001*]

Input:
[**    ]
[*    *]
[  *   ]
[      ]
[*     ]
[****  ]

Output:
[**1011]
[*4211*]
[12*111]
[121100]
[*43210]
[****10]

Input:
[     *    ]
[        * ]
[     *    ]
[**   ***  ]
[      *** ]
[          ]
[       ** ]
[  * *     ]
[*      ** ]
[       ** ]

Output:
[00001*1111]
[00002221*1]
[22102*4321]
[**102***31]
[221013***1]
[0000013542]
[0112111**1]
[12*2*12442]
[*212112**2]
[1100002**2]
</code>```

Body:
Turtlèd, 99 bytes

(whoops I keep forgetting the link :| )

Takes inputs with brackets around each line

Turtlèd cannot take multi-line input, so after the last line, write | to signal end of input

Note the mismatched brackets are because open brackets parse the next char as part of the bracket command

[|!.([[]r+.][[l]d)][ u]d[|[]r( #012345678#l(*+)u(*+)r(*+)r(*+)d(*+)d(*+)l(*+)l(*+)ur.)]' [[l]' d]'

Try it online!

How it works (general description):

Until | is entered, it writes out the input on each line, with brackets to help it recognise the end of each line.
After that has happened, it goes back up to the top of input. It goes through each character in input. If it is a space, it looks around the space, adding one to the counter for each bomb it finds. after each line, it deletes the brackets. When it gets to the last line, with the | in it, it stops, and deletes the |. the grid is implicitly printed.


答:
Dyalog APL, <s>29</s> 27 bytes

Takes a 12x12 binary array as user input and returns the coordinates in reverse order, the indexes start at 1.

Thanks to @Adám for saving many bytes.
-2 Bytes because I'm dumb and left everything in a function for no reason.

```<code>0~⍨∊{⍵×⍳⍴⍵}⎕⍷⍨~0 8 0 6⊤⍨4/2
</code>```

Title: Where's the 0xBEEF?

Body:
This challenge was inspired by this Wendy's commercial from 1984.

Illustration by T S Rogers

Your task is to find a hexadecimal 0xBEEF on a binary bun.

The 'beef' consists of the following pattern:

```<code>1 0 1 1  (0xB)
1 1 1 0  (0xE)
1 1 1 0  (0xE)
1 1 1 1  (0xF)
</code>```

And the 'bun' consists of a 12x12 binary matrix, such as:

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

Input

Your program or function will take the binary matrix as input. The matrix format is very flexible, but it must be clearly described in your answer.

For instance:

a single binary string, with or without separators between the rows:

"111001111110 110100100000..."

or:

"111001111110110100100000..."

an array of binary strings:

["111001111110", "110100100000", ...]

an array of numbers (each number describing a row once converted back to binary and left-padded with zeros):

[3710, 3360, ...]

Output

The coordinates (X, Y) of the 'beef', (0, 0) being the top left corner of the bun.

Alternatively, you may use 1-based coordinates (but not a mix of both formats, like 0-based for X and 1-based for Y).

For the above example, the expected answer is (3, 4) (0-based) or (4, 5) (1-based):

```<code>   00 01 02 03 04 05 06 07 08 09 10 11
00  1  1  1  0  0  1  1  1  1  1  1  0
01  1  1  0  1  0  0  1  0  0  0  0  0
02  0  1  0  0  0  1  1  1  1  1  0  1
03  1  0  0  1  0  0  1  0  0  1  0  0
04  1  0  0 [1  0  1  1] 0  0  1  1  1
05  1  1  1 [1  1  1  0] 0  0  0  1  0
06  1  1  0 [1  1  1  0] 0  0  0  0  1
07  1  0  0 [1  1  1  1] 0  0  0  0  1
08  1  0  0  1  1  1  0  1  1  1  1  1
09  1  1  1  1  1  0  0  1  1  1  1  1
10  1  0  0  0  0  1  0  1  0  1  1  1
11  1  1  0  0  1  1  0  0  0  0  1  1
</code>```

Again, any reasonable format would work as long as it is specified in your answer. Please also mention if you're using 0-based or 1-based coordinates.

Rules

You can safely assume that there is always exactly one 'beef' on the bun. Your code is not required to support cases with more than one beef or no beef at all.

The beef pattern will always appear as described. It will never be rotated or mirrored in any way.

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

Test cases

In the following test cases, each row of the matrix is expressed as its decimal representation.

```<code>Input : [ 3710, 3360, 1149, 2340, 2407, 4034, 3521, 2529, 2527, 3999, 2135, 3267 ]
Output: [ 3, 4 ]

Input : [ 1222, 3107, 1508, 3997, 1906, 379, 2874, 2926, 1480, 1487, 3565, 633 ]
Output: [ 3, 7 ]

Input : [ 2796, 206, 148, 763, 429, 1274, 2170, 2495, 42, 1646, 363, 1145 ]
Output: [ 6, 4 ]

Input : [ 3486, 3502, 1882, 1886, 2003, 1442, 2383, 2808, 1416, 1923, 2613, 519 ]
Output: [ 1, 1 ]

Input : [ 3661, 2382, 2208, 1583, 1865, 3969, 2864, 3074, 475, 2382, 1838, 127 ]
Output: [ 8, 8 ]

Input : [ 361, 1275, 3304, 2878, 3733, 3833, 3971, 3405, 2886, 448, 3101, 22 ]
Output: [ 0, 3 ]

Input : [ 3674, 2852, 1571, 3582, 1402, 3331, 1741, 2678, 2076, 2685, 734, 261 ]
Output: [ 7, 7 ]
</code>```

Body:
Dyalog APL, <s>29</s> 27 bytes

Takes a 12x12 binary array as user input and returns the coordinates in reverse order, the indexes start at 1.

Thanks to @Adám for saving many bytes.
-2 Bytes because I'm dumb and left everything in a function for no reason.

0~⍨∊{⍵×⍳⍴⍵}⎕⍷⍨~0 8 0 6⊤⍨4/2


问:
Draw an ASCII-O'-Lantern for Halloween
Halloween is almost here, the holiday after which most people need to wean themselves off a hollow diet of sugar.

Write a program that takes in a positive integer. If the integer is less than 31 (1 through 30), output this ASCII-art jack-o'-lantern, looking to the right as if looking forward to Halloween:

```<code> _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|
</code>```

If the input is 31 (the October date Halloween is on), output the same ASCII-o'-lantern, but looking left:

```<code> _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|
</code>```

If the input is greater than 31, output a bloated-looking ASCII-o'-lantern who probably ate too much candy. He can face either left or right since queasyness can be disorientating. So output:

```<code> _____I_____
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|
</code>```

or

```<code> _____I_____
| | | | | | |
| | |o| |o| |
| | | |^| | |
| | |XXXXX| |
|_|_|_|_|_|_|
</code>```

Whichever you prefer. It may even be different for different numbers above 31.

The shortest code in bytes wins.

答:
Ruby, 168 bytes

```<code>->i{s=(Zlib.inflate Base64.decode64 "eJxTiAcBTzDJVaOABCG8OCiGycUhyYWVASGYF48EuRTwGhmHZkgckhzMQBKNzIdibEZGgAA2IwFZA1N4").lines;puts i<31?s[0..5]:i<32?s[6..11]:s[12..17]}
</code>```

Probably far from optimal. Requires the base64 and zlib libraries.

Call as a lambda function.

Title: Draw an ASCII-O'-Lantern for Halloween

Body:
Ruby, 168 bytes

->i{s=(Zlib.inflate Base64.decode64 "eJxTiAcBTzDJVaOABCG8OCiGycUhyYWVASGYF48EuRTwGhmHZkgckhzMQBKNzIdibEZGgAA2IwFZA1N4").lines;puts i<31?s[0..5]:i<32?s[6..11]:s[12..17]}

Probably far from optimal. Requires the base64 and zlib libraries.

Call as a lambda function.


Title: Draw an ASCII-O'-Lantern for Halloween

Body:
Halloween is almost here, the holiday after which most people need to wean themselves off a hollow diet of sugar.

Write a program that takes in a positive integer. If the integer is less than 31 (1 through 30), output this ASCII-art jack-o'-lantern, looking to the right as if looking forward to Halloween:

```<code> _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|
</code>```

If the input is 31 (the October date Halloween is on), output the same ASCII-o'-lantern, but looking left:

```<code> _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|
</code>```

If the input is greater than 31, output a bloated-looking ASCII-o'-lantern who probably ate too much candy. He can face either left or right since queasyness can be disorientating. So output:

```<code> _____I_____
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|
</code>```

or

```<code> _____I_____
| | | | | | |
| | |o| |o| |
| | | |^| | |
| | |XXXXX| |
|_|_|_|_|_|_|
</code>```

Whichever you prefer. It may even be different for different numbers above 31.

The shortest code in bytes wins.

Body:
JavaScript (ES6), <s>185</s> <s>142</s> <s>140</s> 136 bytes

Now you can tweet-a-pumpkin!

n=>` _____I_____
0 4 1
02421
0 |^| 1
031
|_|_|_|_|_|_|`.replace(/\d/g,x=>x-2?x-3?x^n>30?"| |":"| | |":n>31?"XXXXX":"VvVvV":n>31?"o":"^")

Probably still room for improvement...


答:
Pyth - 84 bytes

Manual base compression.

```<code>+dj\Im*5\_2Xjb@_MBsMc5@L"^|_V ve"jC"mËÝ8|0càvll+Ç²Sïë¬Ê"7qQ31"Vve"?>Q31"XXo""Vv^
</code>```

Test Suite.

Title: Draw an ASCII-O'-Lantern for Halloween

Body:
Pyth - 84 bytes

Manual base compression.

+dj\Im*5\_2Xjb@_MBsMc5@L"^|_V ve"jC"mËÝ8|0càvll+Ç²Sïë¬Ê"7qQ31"Vve"?>Q31"XXo""Vv^

Test Suite.


答:
JavaScript (ES6), <s>163</s> 125 bytes

f=
n=>` _____I_____
3 5 4
30504
3 |^| 4
3121214
|_|_|_|_|_|_|`.replace(/\d/g,c=>(n>31?`oXX`:`^Vv`)[c]||(c-3^n>30?`| |`:`| | |`))
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input type=number oninput=o.textContent=f(this.value)><pre id=o></code>```

Now shamelessly stealing @ETHproduction's trick for positioning the face. Encoding: 0 is an eye, 1 and 2 are teeth, 3 is the left side, 4 is the right side and 5 is the bridge of the nose.

Title: Draw an ASCII-O'-Lantern for Halloween

Body:
JavaScript (ES6), <s>163</s> 125 bytes

f=
n=>` _____I_____
3 5 4
30504
3 |^| 4
3121214
|_|_|_|_|_|_|`.replace(/\d/g,c=>(n>31?`oXX`:`^Vv`)[c]||(c-3^n>30?`| |`:`| | |`))
;

<input type=number oninput=o.textContent=f(this.value)><pre id=o>

Now shamelessly stealing @ETHproduction's trick for positioning the face. Encoding: 0 is an eye, 1 and 2 are teeth, 3 is the left side, 4 is the right side and 5 is the bridge of the nose.


问:
Random dice tipping
In a standard dice (die) the numbers are arranged so that opposite faces add to seven.
Write the shortest possible program in your preferred language which outputs a random throw followed by 9 random tippings. A tipping is a quarter turn of the dice, e.g. if the dice is facing 5, all possible tippings are 1,3,4 and 6.

Example of desired output:

1532131356

答:
Bash with only one loop: 100 99 98 96

```for((i=10,f=RANDOM%6+1;i--;))do
printf $f
((n=RANDOM%4+1,m=f<4?f:7-f,f=n<m||++n<7-m?n:n+1))
done```

http://ideone.com/XrZO7

The key idea is that to pick a random number in [1,x] which isn't equal to y you can pick a random number in [1,x-1] and then increment if it's >= y. For this problem we want a random number in [1,6] which isn't equal to f or 7-f. We have to do the two tests in order min(f,7-f), max(f,7-f).

Assuming an initially empty environment could save 2 chars by not initialising i and changing the loop condition to i++<10

ContentLicense: CC BY-SA 2.5

Title: Random dice tipping

Body:
Bash with only one loop: 100 99 98 96

for((i=10,f=RANDOM%6+1;i--;))do
printf $f
((n=RANDOM%4+1,m=f<4?f:7-f,f=n<m||++n<7-m?n:n+1))
done

http://ideone.com/XrZO7

The key idea is that to pick a random number in [1,x] which isn't equal to y you can pick a random number in [1,x-1] and then increment if it's >= y. For this problem we want a random number in [1,6] which isn't equal to f or 7-f. We have to do the two tests in order min(f,7-f), max(f,7-f).

Assuming an initially empty environment could save 2 chars by not initialising i and changing the loop condition to i++<10


答:
V, 97 bytes

```<code>é|6i| Y5PÒ_r $.7|rIGÓ /_
3G3f r^jll.kll.5G3f RVvVvVLá
Àé*ñ30|l2GGkld$PñGñ31|l3GÓÞ/o
5GÓãv/XñÍª
</code>```

Try it online!

I'm dissapointed with how long this turned out. It is more convoluted than usual since V can barely handle numbers, a lot of bytes come from creating hacky conditionals. I would post a detailed explanation, but it took a long time to come up with, so I might get around to it later. Here is a hexdump:

```<code>0000000: e97c 3669 7c20 1b59 3550 d25f 7220 242e  .|6i| .Y5P._r $.
0000010: 377c 7249 47d3 202f 5f0a 3347 3366 2072  7|rIG. /_.3G3f r
0000020: 5e6a 6c6c 2e6b 6c6c 2e35 4733 6620 5256  ^jll.kll.5G3f RV
0000030: 7656 7656 1b4c e10a c0e9 2af1 3330 7c6c  vVvV.L....*.30|l
0000040: 3247 1647 6b6c 6424 50f1 47f1 3331 7c6c  2G.Gkld$P.G.31|l
0000050: 3347 d3de 2f6f 0a35 47d3 e376 2f58 f1cd  3G../o.5G..v/X..
0000060: aa                                       .
</code>```

FYI this will run very slowly. It will take about 10 seconds. I know why this happens, and I'm looking into fixes.

Title: Draw an ASCII-O'-Lantern for Halloween

Body:
V, 97 bytes

é|6i| Y5PÒ_r $.7|rIGÓ /_
3G3f r^jll.kll.5G3f RVvVvVLá
Àé*ñ30|l2GGkld$PñGñ31|l3GÓÞ/o
5GÓãv/XñÍª

Try it online!

I'm dissapointed with how long this turned out. It is more convoluted than usual since V can barely handle numbers, a lot of bytes come from creating hacky conditionals. I would post a detailed explanation, but it took a long time to come up with, so I might get around to it later. Here is a hexdump:

0000000: e97c 3669 7c20 1b59 3550 d25f 7220 242e  .|6i| .Y5P._r $.
0000010: 377c 7249 47d3 202f 5f0a 3347 3366 2072  7|rIG. /_.3G3f r
0000020: 5e6a 6c6c 2e6b 6c6c 2e35 4733 6620 5256  ^jll.kll.5G3f RV
0000030: 7656 7656 1b4c e10a c0e9 2af1 3330 7c6c  vVvV.L....*.30|l
0000040: 3247 1647 6b6c 6424 50f1 47f1 3331 7c6c  2G.Gkld$P.G.31|l
0000050: 3347 d3de 2f6f 0a35 47d3 e376 2f58 f1cd  3G../o.5G..v/X..
0000060: aa                                       .

FYI this will run very slowly. It will take about 10 seconds. I know why this happens, and I'm looking into fixes.


答:
Jelly, 73 bytes

```<code>“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’b8ị“ I|o^Xv_”
<32ị“o^XV“vX”y¢s13µ¹U31=³¤?Y
</code>```

Full program

TryItOnline!

Might be possible to golf this with the aid of bounce, ŒḄ.

How?

```<code>“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’b8ị“ I|o^Xv_” - Link 1, Jack construction
“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’              - a base 250 integer
                               b8            - convert to base 8
                                 ị           - index into
                                  “ I|o^Xv_” - literal " I|o^Xv_"
                                             - makes this, without the line feeds:
                                                _____I_____
                                               | | | | | | |
                                               | |o| |o| | |
                                               | | |^| | | |
                                               | |XvXvX| | |
                                               |_|_|_|_|_|_|

<32ị“o^XV“vX”y¢s13µ¹U31=³¤?Y - Main link: n
<32                          - 1 if n is less than 32 else 0
   ị                         - index into
    “o^XV“vX”                - list of strings, ["o^XV","vX"]
             y               - map those characters (o->^ and X->V OR v->X) in string:
              ¢              -    call last link (1) as a nilad
               s13           - split into chunks of length 13
                  µ          - monadic chain separation
                          ?  - ternary if:
                         ¤   -     nilad and links as a nilad
                     31=³    -         31 equals first argument
                   ¹         -     identity (do nothing if true)
                    U        -     upend (reverse each if false)
                           Y - join with line feeds

</code>```

Title: Draw an ASCII-O'-Lantern for Halloween

Body:
Jelly, 73 bytes

“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’b8ị“ I|o^Xv_”
<32ị“o^XV“vX”y¢s13µ¹U31=³¤?Y

Full program

TryItOnline!

Might be possible to golf this with the aid of bounce, ŒḄ.

How?

“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’b8ị“ I|o^Xv_” - Link 1, Jack construction
“ẋƥḷỊKNṇ&JƝ¡'Ɲṣ,c;|Ṙɗ.hṿ#⁴ɠ³Ṙṅ’              - a base 250 integer
                               b8            - convert to base 8
                                 ị           - index into
                                  “ I|o^Xv_” - literal " I|o^Xv_"
                                             - makes this, without the line feeds:
                                                _____I_____
                                               | | | | | | |
                                               | |o| |o| | |
                                               | | |^| | | |
                                               | |XvXvX| | |
                                               |_|_|_|_|_|_|

<32ị“o^XV“vX”y¢s13µ¹U31=³¤?Y - Main link: n
<32                          - 1 if n is less than 32 else 0
   ị                         - index into
    “o^XV“vX”                - list of strings, ["o^XV","vX"]
             y               - map those characters (o->^ and X->V OR v->X) in string:
              ¢              -    call last link (1) as a nilad
               s13           - split into chunks of length 13
                  µ          - monadic chain separation
                          ?  - ternary if:
                         ¤   -     nilad and links as a nilad
                     31=³    -         31 equals first argument
                   ¹         -     identity (do nothing if true)
                    U        -     upend (reverse each if false)
                           Y - join with line feeds


答:
Ruby, 137 bytes

Face points left on and after the 31st.

```<code>->n{puts ' _____I_____',(0..4).map{|i|s=[?|]*7*' _'[i/4]
s[5-n/31*2,5]=' | | o| |o |^| VvVvV_|_|_'[i*5,5];s.tr('ovV','^vVoX'[n/32*3,3])}}
</code>```

Ungolfed in test program

```<code>f=->n{
  puts ' _____I_____',                                #Draw top of pumpkin
  (0..4).map{|i|                                      #then 5 more lines
    s=[?|]*7*' _'[i/4]                                #of 7 | separated by space or _ .
    s[5-n/31*2,5]=' | | o| |o |^| VvVvV_|_|_'[i*5,5]  #Add a line of face with 'o' eyes and 'VvVvV' mouth.
    s.tr('ovV','^vVoX'[n/32*3,3])                     #Substitute characters as necessary.
  }
}

f[gets.to_i]
</code>```

Title: Draw an ASCII-O'-Lantern for Halloween

Body:
Ruby, 137 bytes

Face points left on and after the 31st.

->n{puts ' _____I_____',(0..4).map{|i|s=[?|]*7*' _'[i/4]
s[5-n/31*2,5]=' | | o| |o |^| VvVvV_|_|_'[i*5,5];s.tr('ovV','^vVoX'[n/32*3,3])}}

Ungolfed in test program

f=->n{
  puts ' _____I_____',                                #Draw top of pumpkin
  (0..4).map{|i|                                      #then 5 more lines
    s=[?|]*7*' _'[i/4]                                #of 7 | separated by space or _ .
    s[5-n/31*2,5]=' | | o| |o |^| VvVvV_|_|_'[i*5,5]  #Add a line of face with 'o' eyes and 'VvVvV' mouth.
    s.tr('ovV','^vVoX'[n/32*3,3])                     #Substitute characters as necessary.
  }
}

f[gets.to_i]


答:
Java, <s>100</s> <s>98</s> <s>79</s> 75 bytes

```<code>a->{int n=a[0],m=n-1;for(int i:a)n-=i==m+1?m-m++:i==n-1?1:n+1;return n==0;}
</code>```

Formerly:

```<code>a->{int m,n;m=n=a[0];--m;for(int i:a)if(i==m+1)m=i;else if(i==n-1)n=i;else return 0>1;return 1>0;}
</code>```

Saved 3 bytes by replacing true and false with 1>0 and 0>1.

Saved 23 bytes thanks to excellent suggestions from Peter Taylor!

Ungolfed:

```<code>a -> {
    int n = a[0], m = n - 1;
    for (int i : a)
        n -= i == m + 1? m - m++ : i == n - 1? 1 : n + 1;
    return n == 0;
}
</code>```

Keep track of the highest and lowest values seen so far as m and n; only accept a new value if it is m + 1 or n - 1 i.e. the next higher or lower value; initialize the high value, m, to one less than the first element so that it will "match" the first time around the loop. Note: this is a linear-time, online algorithm. It requires only three words of memory, for the current, highest-so-far, and lowest-so-far values, unlike a lot of the other solutions.

If the next value misses both the high and low ends of the range, the lowest-so-far value is set to -1 and then the low end can never proceed and reach zero. We then detect an antsy sequence by checking whether the low value, n, reached zero.

(Unfortunately this is less efficient because we always have to look at the entire sequence rather than bailing out after the first wrong number, but it's hard to argue with a 23-byte savings (!) when other solutions are using O(n^2) and exponential time approaches.)

Usage:

```<code>import java.util.function.Predicate;

public class Antsy {
    public static void main(String[] args) {
        int[] values = { 6, 5, 4, 7, 3, 8, 9, 2, 1, 0 };
        System.out.println(test(values,
            a -> {
                int n = a[0], m = n - 1;
                for (int i : a)
                    n -= i == m + 1? m - m++ : i == n - 1? 1 : n + 1;
                return n == 0;
            }
        ));
    }

    public static boolean test(int[] values, Predicate<int[]> pred) {
        return pred.test(values);
    }
}
</code>```

Note: this can also be written without taking advantage of Java 8 lambdas:

Java 7, 89 bytes

```<code>boolean c(int[]a){int n=a[0],m=n-1;for(int i:a)n-=i==m+1?m-m++:i==n-1?1:n+1;return n==0;}
</code>```

Title: Antsy permutations

Body:
Introduction

Suppose you have a ruler with numbers from 0 to r-1.
You place an ant between any two of the numbers, and it starts to crawl erratically on the ruler.
The ruler is so narrow that the ant cannot walk from one position to another without walking on all the numbers in between.
As the ant walks on a number for the first time, you record it, and this gives you a permutation of the r numbers.
We say that a permutation is antsy if it can be generated by an ant in this way.
Alternatively, a permutation p is antsy if every entry p[i] except the first is within distance 1 from some previous entry.

Examples

The length-6 permutation

```<code>4, 3, 5, 2, 1, 0
</code>```

is antsy, because 3 is within distance 1 of 4, 5 is within distance 1 of 4, 2 is within distance 1 from 3, 1 is within distance 1 from 2, and 0 is within distance 1 from 1.
The permutation

```<code>3, 2, 5, 4, 1, 0
</code>```

is not antsy, because 5 is not within distance 1 of either 3 or 2; the ant would have to pass through 4 to get to 5.

The task

Given a permutation of the numbers from 0 to r-1 for some 1 ≤ r ≤ 100 in any reasonable format, output a truthy value if the permutation is antsy, and a falsy value if not.

Test cases

```<code>[0] -> True
[0, 1] -> True
[1, 0] -> True
[0, 1, 2] -> True
[0, 2, 1] -> False
[2, 1, 3, 0] -> True
[3, 1, 0, 2] -> False
[1, 2, 0, 3] -> True
[2, 3, 1, 4, 0] -> True
[2, 3, 0, 4, 1] -> False
[0, 5, 1, 3, 2, 4] -> False
[6, 5, 4, 7, 3, 8, 9, 2, 1, 0] -> True
[4, 3, 5, 6, 7, 2, 9, 1, 0, 8] -> False
[5, 2, 7, 9, 6, 8, 0, 4, 1, 3] -> False
[20, 13, 7, 0, 14, 16, 10, 24, 21, 1, 8, 23, 17, 18, 11, 2, 6, 22, 4, 5, 9, 12, 3, 15, 19] -> False
[34, 36, 99, 94, 77, 93, 31, 90, 21, 88, 30, 66, 92, 83, 42, 5, 86, 11, 15, 78, 40, 48, 22, 29, 95, 64, 97, 43, 14, 33, 69, 49, 50, 35, 74, 46, 26, 51, 75, 87, 23, 85, 41, 98, 82, 79, 59, 56, 37, 96, 45, 17, 32, 91, 62, 20, 4, 9, 2, 18, 27, 60, 63, 25, 61, 76, 1, 55, 16, 8, 6, 38, 54, 47, 73, 67, 53, 57, 7, 72, 84, 39, 52, 58, 0, 89, 12, 68, 70, 24, 80, 3, 44, 13, 28, 10, 71, 65, 81, 19] -> False
[47, 48, 46, 45, 44, 49, 43, 42, 41, 50, 40, 39, 38, 51, 37, 36, 52, 35, 34, 33, 32, 53, 54, 31, 30, 55, 56, 29, 28, 57, 58, 59, 60, 27, 26, 61, 25, 62, 63, 64, 65, 66, 67, 24, 23, 22, 21, 68, 69, 20, 19, 18, 17, 70, 71, 16, 15, 72, 73, 74, 75, 76, 14, 13, 12, 77, 11, 10, 9, 8, 78, 7, 79, 80, 6, 81, 5, 4, 3, 82, 2, 83, 84, 1, 85, 86, 87, 0, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99] -> True
</code>```

Fun fact: for r ≥ 1, there are exactly 2r-1 antsy permutations of length r.

Body:
Java, <s>100</s> <s>98</s> <s>79</s> 75 bytes

a->{int n=a[0],m=n-1;for(int i:a)n-=i==m+1?m-m++:i==n-1?1:n+1;return n==0;}

Formerly:

a->{int m,n;m=n=a[0];--m;for(int i:a)if(i==m+1)m=i;else if(i==n-1)n=i;else return 0>1;return 1>0;}

Saved 3 bytes by replacing true and false with 1>0 and 0>1.

Saved 23 bytes thanks to excellent suggestions from Peter Taylor!

Ungolfed:

a -> {
    int n = a[0], m = n - 1;
    for (int i : a)
        n -= i == m + 1? m - m++ : i == n - 1? 1 : n + 1;
    return n == 0;
}

Keep track of the highest and lowest values seen so far as m and n; only accept a new value if it is m + 1 or n - 1 i.e. the next higher or lower value; initialize the high value, m, to one less than the first element so that it will "match" the first time around the loop. Note: this is a linear-time, online algorithm. It requires only three words of memory, for the current, highest-so-far, and lowest-so-far values, unlike a lot of the other solutions.

If the next value misses both the high and low ends of the range, the lowest-so-far value is set to -1 and then the low end can never proceed and reach zero. We then detect an antsy sequence by checking whether the low value, n, reached zero.

(Unfortunately this is less efficient because we always have to look at the entire sequence rather than bailing out after the first wrong number, but it's hard to argue with a 23-byte savings (!) when other solutions are using O(n^2) and exponential time approaches.)

Usage:

import java.util.function.Predicate;

public class Antsy {
    public static void main(String[] args) {
        int[] values = { 6, 5, 4, 7, 3, 8, 9, 2, 1, 0 };
        System.out.println(test(values,
            a -> {
                int n = a[0], m = n - 1;
                for (int i : a)
                    n -= i == m + 1? m - m++ : i == n - 1? 1 : n + 1;
                return n == 0;
            }
        ));
    }

    public static boolean test(int[] values, Predicate<int[]> pred) {
        return pred.test(values);
    }
}

Note: this can also be written without taking advantage of Java 8 lambdas:

Java 7, 89 bytes

boolean c(int[]a){int n=a[0],m=n-1;for(int i:a)n-=i==m+1?m-m++:i==n-1?1:n+1;return n==0;}


答:
Mathematica, 47 bytes

A little longer than Martin Ender's solution (surprise surprise!). But it's one of my more unreadable efforts, so that's good :D

```<code>#=={}||{Max@#,Min@#}~MemberQ~Last@#&&#0@Most@#&
</code>```

Explanation:

```<code>#=={}                         empty lists are antsy (function halts with True)
 ||                            or
{Max@#,Min@#}~MemberQ~Last@#  lists where the last number is largest or smallest
                              are possibly antsy (else function halts with False)
 &&                            and
#0@Most@#&                    recursively call this function after dropping the
                              last element of the list
</code>```

Title: Antsy permutations

Body:
Mathematica, 47 bytes

A little longer than Martin Ender's solution (surprise surprise!). But it's one of my more unreadable efforts, so that's good :D

#=={}||{Max@#,Min@#}~MemberQ~Last@#&&#0@Most@#&

Explanation:

#=={}                         empty lists are antsy (function halts with True)
 ||                            or
{Max@#,Min@#}~MemberQ~Last@#  lists where the last number is largest or smallest
                              are possibly antsy (else function halts with False)
 &&                            and
#0@Most@#&                    recursively call this function after dropping the
                              last element of the list


问:
Write a Metaquine
A metaquine is a program which is not a quine, but whose output, when run as a program in the same language, is a quine.

The goal of this challenge is to write a metaquine. This is code-golf, so shortest code wins, with earliest answer used as a tiebreaker. Note that only full programs are acceptable, due to the definition of a quine.

Rules for Quines

Only true quines are accepted. That is, you need to print the entire source code verbatim to STDOUT, without:

reading your source code, directly or indirectly.

relying on a REPL environment which just simply evaluates and prints every expression you feed it.

relying on language features which just print out the source in certain cases.

using error messages or STDERR to write all or part of the quine. (You may write things to STDERR or produce warnings/non-fatal errors as long as STDOUT is a valid quine and the error messages are not part of it.)

the source code consisting purely of literals (whether they be string literals, numeric literals, etc.) and/or NOPs.

Any non-suppressible output (such as copyright notices, startup/shutdown messages, or a trailing line feed) may be ignored in the output for the sake of the validity of the quine.

Example

Ignoring the rule which forbids literal-only programs and built-in quining, this would be a metaquine in Seriously:

```<code>"Q"
</code>```

The program consists of the single string literal "Q", which is implicitly printed at output. When the output (Q) is run, it is a quine (Q is the built-in quine function).

答:
Turtlèd, 52 bytes (noncompeting)

1 less than original quine

```<code>@##'@r,r,r-{ +.r_}r{ +.r_}"#'@r,r,r-{ +.r_}r{ +.r_}"
</code>```

Works in the same way, except that it does not have a character at the end, when run, it will have a character at the end, that does not effect output, because it writes # on to a #. Note the output is slightly different to the quine I have made for the quine challenge, but works the same: " writes #, which is its own last character, like the quine I made. Check out the explanation there.

Title: Write a Metaquine

Body:
Turtlèd, 52 bytes (noncompeting)

1 less than original quine

@##'@r,r,r-{ +.r_}r{ +.r_}"#'@r,r,r-{ +.r_}r{ +.r_}"

Works in the same way, except that it does not have a character at the end, when run, it will have a character at the end, that does not effect output, because it writes # on to a #. Note the output is slightly different to the quine I have made for the quine challenge, but works the same: " writes #, which is its own last character, like the quine I made. Check out the explanation there.