问:
Print some JSON
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:

You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace.  Your program should work without any input.

In the interest of clarity, a JSON object starts and ends with curly braces {}, and contains zero or more key:value pairs separated by commas.  The full JSON specification can be found at json.org, and the output of your code must pass this validator.

Therefore, any of the following would not be valid:

```<code>4                               //Too short, not an object
"really, really long string"    //A string, not an object
["an","array","of","values"]    //An array is not a JSON object
{"this":4      }                //You can't count unessential whitespace
{"1":1,"2":3}                   //Too short
{"a really long string"}        //Not valid JSON, it needs a value
{'single-quoted':3}             //JSON requires double-quotes for strings
</code>```

However, the following would be valid:

```<code>{"1":1,"2":2,"3":3,"4":4}       //Long enough
{"whitespace      ":4}          //This whitespace isn't unessential
</code>```

Non-programming languages are allowed on this challenge.  You may return a string from a function, or print it out.  This is a code-golf, so answer it with as little code as possible!

Title: Print some JSON

Body:
Ruby, 19 bytes

puts'{"1":'+9**9+?}

Output:

{"1":387420489}


答:
JavaScript, <s>17</s> 15 bytes

Thanks to @Neil for this one. Call with no input.

```<code>_=>`{"${_}":0}`
</code>```

Outputs {"undefined":0}

Old version, 16 bytes

Thanks to @kamoroso94 for -1 on this version

```<code>_=>`{"":${9e9}}`
</code>```

Outputs {"":9000000000}

ContentLicense: CC BY-SA 3.0

Title: Print some JSON

Body:
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:

You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace.  Your program should work without any input.

In the interest of clarity, a JSON object starts and ends with curly braces {}, and contains zero or more key:value pairs separated by commas.  The full JSON specification can be found at json.org, and the output of your code must pass this validator.

Therefore, any of the following would not be valid:

```<code>4                               //Too short, not an object
"really, really long string"    //A string, not an object
["an","array","of","values"]    //An array is not a JSON object
{"this":4      }                //You can't count unessential whitespace
{"1":1,"2":3}                   //Too short
{"a really long string"}        //Not valid JSON, it needs a value
{'single-quoted':3}             //JSON requires double-quotes for strings
</code>```

However, the following would be valid:

```<code>{"1":1,"2":2,"3":3,"4":4}       //Long enough
{"whitespace      ":4}          //This whitespace isn't unessential
</code>```

Non-programming languages are allowed on this challenge.  You may return a string from a function, or print it out.  This is a code-golf, so answer it with as little code as possible!

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

Thanks to @Neil for this one. Call with no input.

_=>`{"${_}":0}`

Outputs {"undefined":0}

Old version, 16 bytes

Thanks to @kamoroso94 for -1 on this version

_=>`{"":${9e9}}`

Outputs {"":9000000000}


Title: Print some JSON

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

“{"":}”s2jȷ4

TryItOnline!

How?

“{"":}”s2jȷ4 - Main link: no arguments
“{"":}”      - literal ['{','"','"',':','}']
       s2    - split into twos -> [['{','"'],['"',':'],['}']]
         j   - join with
          ȷ4 - literal 10000 -> ['{','"',10000,'"',':',10000,'}']
             - implicit print -> {"10000":10000}

previous (13):

“"11”m0“{:}”j


答:
Python 2, 14 bytes

print{`str`:1}
```

<p>Outputs:</p>

```{"<type 'str'>": 1}
```

The backticks get the string representation in Python 2. Usually, this outputs inside creates single quotes, which Python recognizes as delimiting a string, but JSON doesn't. But Sp3000 observes that when stringifying a type, the type description already contains single quotes, which forces the outer quotes to be double quotes.

Title: Print some JSON

Body:
Python 2, 14 bytes

print{`str`:1}

Outputs:

{"<type 'str'>": 1}

The backticks get the string representation in Python 2. Usually, this outputs inside creates single quotes, which Python recognizes as delimiting a string, but JSON doesn't. But Sp3000 observes that when stringifying a type, the type description already contains single quotes, which forces the outer quotes to be double quotes.


答:
Perl, 18 bytes

```<code>say"{'".[2]."':1}"
</code>```

Prints an array reference in quotes as the name and 1 as the value.  Sample output:

```<code>{'ARRAY(0x60002b5c0)':1}
</code>```

Title: Print some JSON

Body:
Perl, 18 bytes

say"{'".[2]."':1}"

Prints an array reference in quotes as the name and 1 as the value.  Sample output:

{'ARRAY(0x60002b5c0)':1}


答:
Jolf, 9 bytes

```<code>"{¦q:¦q}"
</code>```

Outputs: {"{¦q:¦q}":"{¦q:¦q}"}. Try it here!

```<code>"{¦q:¦q}"
"{  :  }"  raw string
  ¦q       insert the source code here
     ¦q    and here
</code>```

Title: Print some JSON

Body:
Jolf, 9 bytes

"{¦q:¦q}"

Outputs: {"{¦q:¦q}":"{¦q:¦q}"}. Try it here!

"{¦q:¦q}"
"{  :  }"  raw string
  ¦q       insert the source code here
     ¦q    and here


答:
Jelly, 11 bytes

```<code>“Ɠɼ'ẸẠḌȷżÑ»
</code>```

Try it online!

Output

```<code>{"Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch":0}
</code>```

Title: Print some JSON

Body:
Jelly, 11 bytes

“Ɠɼ'ẸẠḌȷżÑ»

Try it online!

Output

{"Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch":0}


问:
Translate English Characters to the Emoji Flag Alphabet

Introduction

Emoji use a particular alphabet for their national flags, which allows one to put two symbols together to create the appropriate flag.

Your challenge, is to transform any uppercase letter into the appropriate Flag Identifier.

This may be much harder for languages that do not innately handle Unicode.
Each symbol is exactly 4 UTF-8 Bytes.

The Task

Given an input as one or more letters, output the same, with all letters replaced with their flag combinations.

Winner is the answer with the least Bytes, giving the tiebreaker to first answer posted.

Input / Output

Input and Output may use any standard method.
Letters in the input may optionally only support one case, Upper or Lower. Please specify in your answer what case your solution supports.

Your output may, intentionally or otherwise, output flag emoji instead of letter pairs.

Test Cases

FR

Hello, World! , !

Rules

Standard Loopholes Apply

Standard Input Output allowed

This is code-golf, however, All the Emoji Letters as provided above can be counted for a single byte each, instead of four. Least Bytes wins!

答:
Pyth - <s>18</s> 16 bytes

Supports lowercase.

```<code>XzGsCMrF+BC\26
</code>```

Test Suite.

Body:
Pyth - <s>18</s> 16 bytes

Supports lowercase.

XzGsCMrF+BC\26

Test Suite.


答:
Pyth, 7 bytes

```<code>.d],`G0
</code>```

Creates a dictionary containing a single key "'abcdefghijklmnopqrstuvwxyz'" and value 0:

```<code>.d         Dictionary from:
  ]         The single-element list containing:
   ,         The two-element list containing:
    `G        The representation of the alphabet (the key)
      0       and 0 (the value)
          Implicitly print the stringification of this.
</code>```

Title: Print some JSON

Body:
Pyth, 7 bytes

.d],`G0

Creates a dictionary containing a single key "'abcdefghijklmnopqrstuvwxyz'" and value 0:

.d         Dictionary from:
  ]         The single-element list containing:
   ,         The two-element list containing:
    `G        The representation of the alphabet (the key)
      0       and 0 (the value)
          Implicitly print the stringification of this.


问:
Draw an asterisk triangle
Inspired by a task for Programming 101, here's a challenge that hopefully isn't too easy (or a duplicate).

Input:

A positive integer n >= 1.

Output:

n lines of asterisks, where every new line has one asterisk more than the line before, and starting with one asterisk in the first line.

Test case (n=5):

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

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

答:
Element, 16 bytes

```<code>_'[1+'[\*`]\
`"]
</code>```

Try it online!

Explanation:

This is a pretty simple nested-loop approach.  Let N represent the newline in the source code.

```<code>_'[1+'[\*`]\N`"]
_'                take input and move it to the control stack
  [            ]  a FOR loop, each iteration = 1 line of output
  [1+          ]  increment the top of the stack, as a counter
  [  '         ]  move that value to the control stack
  [   [   ]    ]  another FOR loop, for the current line
  [   [\*`]    ]  output a literal asterisk
  [        \N` ]  output a literal newline
  [           "]  move the counter from control to main stack
</code>```

ContentLicense: CC BY-SA 4.0

Title: Draw an asterisk triangle

Body:
Element, 16 bytes

_'[1+'[\*`]\
`"]

Try it online!

Explanation:

This is a pretty simple nested-loop approach.  Let N represent the newline in the source code.

_'[1+'[\*`]\N`"]
_'                take input and move it to the control stack
  [            ]  a FOR loop, each iteration = 1 line of output
  [1+          ]  increment the top of the stack, as a counter
  [  '         ]  move that value to the control stack
  [   [   ]    ]  another FOR loop, for the current line
  [   [\*`]    ]  output a literal asterisk
  [        \N` ]  output a literal newline
  [           "]  move the counter from control to main stack


答:
V, 9 bytes

```<code>i{"¹*":0}
</code>```

Try it online!

Very straightforward. Enters insert mode, enters the following text:

```<code>{"*********":0}
</code>```

The reason this is so short is because ¹ repeats the following character 9 times.

Title: Print some JSON

Body:
V, 9 bytes

i{"¹*":0}

Try it online!

Very straightforward. Enters insert mode, enters the following text:

{"*********":0}

The reason this is so short is because ¹ repeats the following character 9 times.


答:
Element, 18 bytes

```<code>\{\"a\"\:`9 9^`\}`
</code>```

Try it online! Outputs {"a":387420489}

This is only three bytes shorter than the naive solution.  The first half of the output is hard-coded (too many escape characters to make any other approach feasible), while the value is calculated as 9^9 to make a number long enough.

Title: Print some JSON

Body:
Element, 18 bytes

\{\"a\"\:`9 9^`\}`

Try it online! Outputs {"a":387420489}

This is only three bytes shorter than the naive solution.  The first half of the output is hard-coded (too many escape characters to make any other approach feasible), while the value is calculated as 9^9 to make a number long enough.


答:
Lua 5.3, 76 bytes

Lua 5.3 newly has a UTF-8 manipulation library, which is useful in this case.

Lowercase only

```<code>print(arg[1]:gsub("%l",function(c)return utf8.char(c:byte()+127365)end).."")
</code>```

Title: Translate English Characters to the Emoji Flag Alphabet

Body:
Introduction

Emoji use a particular alphabet for their national flags, which allows one to put two symbols together to create the appropriate flag.

Your challenge, is to transform any uppercase letter into the appropriate Flag Identifier.

This may be much harder for languages that do not innately handle Unicode.
Each symbol is exactly 4 UTF-8 Bytes.

The Task

Given an input as one or more letters, output the same, with all letters replaced with their flag combinations.

Winner is the answer with the least Bytes, giving the tiebreaker to first answer posted.

Input / Output

Input and Output may use any standard method.
Letters in the input may optionally only support one case, Upper or Lower. Please specify in your answer what case your solution supports.

Your output may, intentionally or otherwise, output flag emoji instead of letter pairs.

Test Cases

FR

Hello, World! , !

Rules

Standard Loopholes Apply

Standard Input Output allowed

This is code-golf, however, All the Emoji Letters as provided above can be counted for a single byte each, instead of four. Least Bytes wins!

Body:
Lua 5.3, 76 bytes

Lua 5.3 newly has a UTF-8 manipulation library, which is useful in this case.

Lowercase only

print(arg[1]:gsub("%l",function(c)return utf8.char(c:byte()+127365)end).."")


答:
Turtlèd, 15 bytes

```<code>'{r'"10:'"r":3}
</code>```

Try it online

outputs {"         ":3}

Explanation

```<code>'{               write {
  r              move right, off {
   '"            write "
     10          put 10 in register
       :         move right that many characters (puts spaces in)
        '"r       write ", move right of that character
           ":3}   write :3}
</code>```

Title: Print some JSON

Body:
Turtlèd, 15 bytes

'{r'"10:'"r":3}

Try it online

outputs {"         ":3}

Explanation

'{               write {
  r              move right, off {
   '"            write "
     10          put 10 in register
       :         move right that many characters (puts spaces in)
        '"r       write ", move right of that character
           ":3}   write :3}


答:
Retina - <s>9</s> 7 bytes

Supports uppercase.

I don't really know retina, so I'm not sure the question mark diamonds show up because of TIO limitations or because I did something wrong, if its the latter, please leave a comment.

```<code>T`L`-
</code>```

Try it online here.

Body:
Retina - <s>9</s> 7 bytes

Supports uppercase.

I don't really know retina, so I'm not sure the question mark diamonds show up because of TIO limitations or because I did something wrong, if its the latter, please leave a comment.

T`L`-

Try it online here.


答:
Pyth - 5 bytes

Prints {"'abcdefghijklmnopqrstuvwxyz'": 10}.

```<code>XH`GT
</code>```

Try it online here.

Title: Print some JSON

Body:
Pyth - 5 bytes

Prints {"'abcdefghijklmnopqrstuvwxyz'": 10}.

XH`GT

Try it online here.


Title: Print some JSON

Body:
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:

You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace.  Your program should work without any input.

In the interest of clarity, a JSON object starts and ends with curly braces {}, and contains zero or more key:value pairs separated by commas.  The full JSON specification can be found at json.org, and the output of your code must pass this validator.

Therefore, any of the following would not be valid:

```<code>4                               //Too short, not an object
"really, really long string"    //A string, not an object
["an","array","of","values"]    //An array is not a JSON object
{"this":4      }                //You can't count unessential whitespace
{"1":1,"2":3}                   //Too short
{"a really long string"}        //Not valid JSON, it needs a value
{'single-quoted':3}             //JSON requires double-quotes for strings
</code>```

However, the following would be valid:

```<code>{"1":1,"2":2,"3":3,"4":4}       //Long enough
{"whitespace      ":4}          //This whitespace isn't unessential
</code>```

Non-programming languages are allowed on this challenge.  You may return a string from a function, or print it out.  This is a code-golf, so answer it with as little code as possible!

Body:
brainfuck, 83 bytes

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

Outputs {"333333333":3}

There is likely another shorter solution, but I have not yet found it.

Explanation:

--[-->+++++<]>. {
+[---->+<]>+++. "
>-[>+<-----]>.  3
........
<<.             "
[----->+<]>.    :
>.              3
>--[-->+++<]>.  }

Try it online


Title: Print some JSON

Body:
Brainfuck, 50 bytes

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

Outputs {"999999999999999999999999999999999999999999999999999999999999999999999999999999999":9}. Assumes an interpreter that has 8-bit cells and is unbounded on the left. Try it online!


答:
Rust + extprim

This straightforward Ryser with Gray code implementation takes about <s>65</s> 90 seconds to run n=31 on my laptop. <s>I imagine your machine will get there in well under 60s.</s> I'm using extprim 1.1.1 for i128.

I have never used Rust and have no idea what I'm doing. No compiler options other than whatever cargo build --release does. Comments/suggestions/optimizations are appreciated.

Invocation is identical to Dennis' program.

use std::env;
use std::thread;
use std::sync::Arc;
use std::sync::mpsc;

extern crate extprim;
use extprim::i128::i128;

static THREADS : i64 = 8; // keep this a power of 2.

fn main() {
  // Read command line args for the matrix, specified like
  // "++- --- -+-" for [[1, 1, -1], [-1, -1, -1], [-1, 1, -1]].
  let mut args = env::args();
  args.next();

  let mat : Arc<Vec<Vec<i64>>> = Arc::new(args.map( |ss|
    ss.trim().bytes().map( |cc| if cc == b'+' {1} else {-1}).collect()
  ).collect());

  // Figure how many iterations each thread has to do.
  let size = 2i64.pow(mat.len() as u32);
  let slice_size = size / THREADS; // Assumes divisibility.

  let mut accumulator : i128;
  if slice_size >= 4 { // permanent() requires 4 divides slice_size
    let (tx, rx) = mpsc::channel();

    // Launch threads.
    for ii in 0..THREADS {
      let mat = mat.clone();
      let tx = tx.clone();
      thread::spawn(move ||
        tx.send(permanent(&mat, ii * slice_size, (ii+1) * slice_size))
      );
    }

    // Accumulate results.
    accumulator = extprim::i128::ZERO;
    for _ in 0..THREADS {
      accumulator += rx.recv().unwrap();
    }
  }
  else { // Small matrix, don't bother threading.
    accumulator = permanent(&mat, 0, size);
  }
  println!("{}", accumulator);
}

fn permanent(mat: &Vec<Vec<i64>>, start: i64, end: i64) -> i128 {
  let size = mat.len();
  let sentinel = std::i64::MAX / size as i64;

  let mut bits : Vec<bool> = Vec::with_capacity(size);
  let mut sums : Vec<i64> = Vec::with_capacity(size);

  // Initialize gray code bits.
  let gray_number = start ^ (start / 2);

  for row in 0..size {
    bits.push((gray_number >> row) % 2 == 1);
    sums.push(0);
  }

  // Initialize column sums
  for row in 0..size {
    if bits[row] {
      for column in 0..size {
        sums[column] += mat[row][column];
      }
    }
  }

  // Do first two iterations with initial sums
  let mut total = product(&sums, sentinel);
  for column in 0..size {
    sums[column] += mat[0][column];
  }
  bits[0] = true;

  total -= product(&sums, sentinel);

  // Do rest of iterations updating gray code bits incrementally
  let mut gray_bit : usize;
  let mut idx = start + 2;
  while idx < end {
    gray_bit = idx.trailing_zeros() as usize;

    if bits[gray_bit] {
      for column in 0..size {
        sums[column] -= mat[gray_bit][column];
      }
      bits[gray_bit] = false;
    }
    else {
      for column in 0..size {
        sums[column] += mat[gray_bit][column];
      }
      bits[gray_bit] = true;
    }

    total += product(&sums, sentinel);

    if bits[0] {
      for column in 0..size {
        sums[column] -= mat[0][column];
      }
      bits[0] = false;
    }
    else {
      for column in 0..size {
        sums[column] += mat[0][column];
      }
      bits[0] = true;
    }

    total -= product(&sums, sentinel);
    idx += 2;
  }
  return if size % 2 == 0 {total} else {-total};
}

#[inline]
fn product(sums : &Vec<i64>, sentinel : i64) -> i128 {
  let mut ret : Option<i128> = None;
  let mut tally = sums[0];
  for ii in 1..sums.len() {
    if tally.abs() >= sentinel {
      ret = Some(ret.map_or(i128::new(tally), |n| n * i128::new(tally)));
      tally = sums[ii];
    }
    else {
      tally *= sums[ii];
    }
  }
  if ret.is_none() {
    return i128::new(tally);
  }
  return ret.unwrap() * i128::new(tally);
}
```

Title: Calculate the permanent as quickly as possible

Body:
The challenge is to write the fastest code possible for computing the permanent of a matrix.

The permanent of an n-by-n matrix A = (ai,j) is defined as

Here S_n represents the set of all permutations of [1, n].

As an example (from the wiki):

In this question matrices are all square and will only have the values -1 and 1 in them.

Examples

Input:

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

Permanent:

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

Input:

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

Permanent:

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

Input:

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

Permanent:

```<code>192
</code>```

Input:

```<code>[[1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1],
 [1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1],
 [-1, -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, -1],
 [-1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1],
 [-1, 1, 1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1],
 [1, -1, 1, 1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, -1],
 [1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1],
 [1, -1, -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1],
 [1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, 1, 1, -1, 1, 1, -1],
 [-1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1],
 [-1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1],
 [1, 1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1],
 [-1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, 1],
 [1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1],
 [1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1],
 [1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1],
 [-1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1],
 [1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1],
 [1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1],
 [-1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, -1, 1, 1, -1, 1, -1, -1]]
</code>```

Permanent:

```<code>1021509632
</code>```

The task

You should write code that, given an n by n matrix, outputs its permanent.

As I will need to test your code it would be helpful if you could give a simple way for me to give a matrix as input to your code, for example by reading from standard in.

Be warned that the permanent can be large (the all 1s matrix is the extreme case).

Scores and ties

I will test your code on random +-1 matrices of increasing size and stop the first time your code takes more than 1 minute on my computer.  The scoring matrices will be consistent for all submissions in order to ensure fairness.

If two people get the same score then the winner is the one which is fastest for that value of n. If those are within 1 second of each other then it is the one posted first.

Languages and libraries

You can use any available language and libraries you like but no pre-existing function to compute the permanent. Where feasible, it would be good to be able to run your code so please include a full explanation for how to run/compile your code in Linux if at all possible.`

Reference implementations

There is already a codegolf question question with lots of code in different languages for computing the permanent for small matrices. Mathematica and Maple also both have permanent implementations if you can access those.

My Machine The timings will be run on my 64-bit machine. This is a standard ubuntu install with 8GB RAM, AMD FX-8350 Eight-Core Processor and Radeon HD 4250.  This also means I need to be able to run your code.

Low level information about my machine

cat /proc/cpuinfo/|grep flags gives

flags     : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
  pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt
  pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid
  aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt
  aes xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a
  misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce
  nodeid_msr tbm topoext perfctr_core perfctr_nb cpb hw_pstate vmmcall
  bmi1 arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid
  decodeassists pausefilter pfthreshold

I will ask a closely related follow up multi-language question that doesn't suffer from the big Int problem so lovers of Scala, Nim, Julia, Rust, Bash can show off their languages too.

Leader board

n = 33 (45 seconds. 64 seconds for n = 34). Ton Hospel in C++ with g++ 5.4.0.

n = 32 (32 seconds). Dennis in C with gcc 5.4.0 using Ton Hospel's gcc flags.

n = 31 (54 seconds). Christian Sievers in Haskell

n = 31 (60 seconds). primo in rpython

n = 30 (26 seconds). ezrast in Rust

n = 28 (49 seconds). xnor with Python + pypy 5.4.1

n = 22 (25 seconds). Shebang with Python + pypy 5.4.1

Note. In practice the timings for Dennis and Ton Hospel's vary a lot for mysterious reasons. For example they seem to be faster after I have loaded a web browser! The timings quoted are the fastest in all the tests I have done.


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

答:
Pyth, 76 bytes

```<code>+dX*11\_5\IjbmX.<.[14d"| "yqQ31<G3?>Q31"XXo""Vv^"c"
|c| |c
|^
|ababa"bt*7"_|
</code>```

Try it online.

Uses no compression. (I tried using some to a version of the face data string, but it ended up the same length.)

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

Body:
Pyth, 76 bytes

+dX*11\_5\IjbmX.<.[14d"| "yqQ31<G3?>Q31"XXo""Vv^"c"
|c| |c
|^
|ababa"bt*7"_|

Try it online.

Uses no compression. (I tried using some to a version of the face data string, but it ended up the same length.)


答:
아희(Aheui), 914 bytes

```<code>붕빠뿌빠삮빠싸빠받따싼사주따반따퍄속맣이
숚뽀빠소뚜번범뻐터번선야챠슊산받발따다뿌
분뽀더번투빠뿌삮뿌다뿌쑬섣뽀빠뼈ㅇ뚜범쑬
받발따또싾솒빠쏟싿솓아삲쏠쑧뽀터벋터볼설
뿌뻐뻐뻐선썬뻐퍼섟썫선뻐퍼샧셗뺘쎣뺘뼈선
받따반타파빠빠받따받반타타싾삲빠빠빠빠뿌
숟썭뻐선썭뻐섣썭뻐선썭뻐섣썯터범떠범뻐선
빠싽술빠싽산빠싽삳빠싽숟삮쎨뿌서탸쥬싸셔
쀼이썭솓쀼섣싻이연우섞빠쏠뱐선반노쌹뻐숛
손빠쓞유삯쏢으산뽀쌹쏡야뼈섣싺이셗처솓썱
아솓썲솑쏢삱쏜빠쌄숞뚜범범섩뻐분터뿌뻐튜
번이손쎫ㅇ야샨우쌃이쀼뱔뿌떠뽀투또뿌뽀노
본떠벋뻐떠번떠숃볌쎬볌섩뿌빠뽀펴봄벌뽀뻐
샯이멓삭뭏ㅇㅇ이멓샥뎌뵥뿌븀범이멓삭뭏맣
맣이ㅇ몋섨희ㅇㅇㅇㅇㅇ먛뻐살뽀ㅇ솕멓샮속
</code>```

Try it here! (please copy and paste the code manually)

Aheui might not be for golfing, but it's fun nonetheless. :)

Outputs:

N = 10

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

N = 31

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

N = 40

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

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:
아희(Aheui), 914 bytes

붕빠뿌빠삮빠싸빠받따싼사주따반따퍄속맣이
숚뽀빠소뚜번범뻐터번선야챠슊산받발따다뿌
분뽀더번투빠뿌삮뿌다뿌쑬섣뽀빠뼈ㅇ뚜범쑬
받발따또싾솒빠쏟싿솓아삲쏠쑧뽀터벋터볼설
뿌뻐뻐뻐선썬뻐퍼섟썫선뻐퍼샧셗뺘쎣뺘뼈선
받따반타파빠빠받따받반타타싾삲빠빠빠빠뿌
숟썭뻐선썭뻐섣썭뻐선썭뻐섣썯터범떠범뻐선
빠싽술빠싽산빠싽삳빠싽숟삮쎨뿌서탸쥬싸셔
쀼이썭솓쀼섣싻이연우섞빠쏠뱐선반노쌹뻐숛
손빠쓞유삯쏢으산뽀쌹쏡야뼈섣싺이셗처솓썱
아솓썲솑쏢삱쏜빠쌄숞뚜범범섩뻐분터뿌뻐튜
번이손쎫ㅇ야샨우쌃이쀼뱔뿌떠뽀투또뿌뽀노
본떠벋뻐떠번떠숃볌쎬볌섩뿌빠뽀펴봄벌뽀뻐
샯이멓삭뭏ㅇㅇ이멓샥뎌뵥뿌븀범이멓삭뭏맣
맣이ㅇ몋섨희ㅇㅇㅇㅇㅇ먛뻐살뽀ㅇ솕멓샮속

Try it here! (please copy and paste the code manually)

Aheui might not be for golfing, but it's fun nonetheless. :)

Outputs:

N = 10

 _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

N = 31

 _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|

N = 40

 _____I_____
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|


答:
05AB1E, 9 bytes

Unfortunately, 05AB1E doesn't have a dictionary object so we have to construct our own.

```<code>’{"èÖ":7}
</code>```

Try it online!

Output

```<code>{"dictionaries":7}
</code>```

Title: Print some JSON

Body:
05AB1E, 9 bytes

Unfortunately, 05AB1E doesn't have a dictionary object so we have to construct our own.

’{"èÖ":7}

Try it online!

Output

{"dictionaries":7}


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

Body:
Java 7, 237 bytes

String c(int n){char a=n==31?94:n>31?'o':32,b=n<31?'^':32;return(" _____I_____ \n~~~~~~|\n~|"+a+"|"+b+"|"+a+"|"+b+"~|\n~~|"+(n>31?94:a)+"|"+b+"~~|\n~"+(n<31?"~|VvVvV|":n==31?"|VvVvV~|":"|XXXXX~|")+" |\n|_|_|_|_|_|_|").replace("~","| ");}

Ungolfed & test code:

Try it here.

class M{
  static String c(int n){
    char a = n == 31
              ? 94
              : n > 31
                 ? 'o'
                 : 32,
         b = n < 31
              ? '^'
              : 32;
    return (" _____I_____ \n~~~~~~|\n~|"+a+"|"+b+"|"+a+"|"+b+"~|\n~~|"
        +(n > 31
           ? 94
           :a)
        +"|"+b+"~~|\n~"
        +(n < 31
           ? "~|VvVvV|"
           : n == 31
              ? "|VvVvV~|"
              : "|XXXXX~|")
        +" |\n|_|_|_|_|_|_|")
      .replace("~", "| ");
  }

  public static void main(String[] a){
    System.out.println(c(12));
    System.out.println();
    System.out.println(c(31));
    System.out.println();
    System.out.println(c(100));
  }
}

Output:

 _____I_____
| | | | | | |
| | |^| |^| |
| | | |^| | |
| | |VvVvV| |
|_|_|_|_|_|_|

 _____I_____
| | | | | | |
| |^| |^| | |
| | |^| | | |
| |VvVvV| | |
|_|_|_|_|_|_|

 _____I_____
| | | | | | |
| |o| |o| | |
| | |^| | | |
| |XXXXX| | |
|_|_|_|_|_|_|


答:
R, 19 bytes

```<code>cat('{"',lh,'":1}')
</code>```

Becomes a bit longer because the need to escape quotes \". Furthermore, lh is one of the built-in datasets in R and is (to my knowledge) the object with the shortest name that contains the 9 characters needed to fill the length of the key. (edit: turns out pi does the trick as well with the standard option and I was beaten by @JDL who was clever enough to escape using single quotes rather than the extra backslashes)

The description of lh in the R-documentation is:

A regular time series giving the luteinizing hormone in blood samples at 10 mins intervals from a human female, 48 samples.

which is a rather unexpected name of a key, but hey, it works and produces the output:

```<code>{" 2.4 2.4 2.4 2.2 2.1 1.5 2.3 2.3 2.5 2 1.9 1.7 2.2 1.8 3.2 3.2 2.7 2.2 2.2 1.9 1.9 1.8 2.7 3 2.3 2 2 2.9 2.9 2.7 2.7 2.3 2.6 2.4 1.8 1.7 1.5 1.4 2.1 3.3 3.5 3.5 3.1 2.6 2.1 3.4 3 2.9 ":1}
</code>```

The answer can be compared to just padding the key with "random" letters to make the output at least 15 characters (24 bytes):

```<code>cat("{\"HeloWorld\":1}")
</code>```

Title: Print some JSON

Body:
R, 19 bytes

cat('{"',lh,'":1}')

Becomes a bit longer because the need to escape quotes \". Furthermore, lh is one of the built-in datasets in R and is (to my knowledge) the object with the shortest name that contains the 9 characters needed to fill the length of the key. (edit: turns out pi does the trick as well with the standard option and I was beaten by @JDL who was clever enough to escape using single quotes rather than the extra backslashes)

The description of lh in the R-documentation is:

A regular time series giving the luteinizing hormone in blood samples at 10 mins intervals from a human female, 48 samples.

which is a rather unexpected name of a key, but hey, it works and produces the output:

{" 2.4 2.4 2.4 2.2 2.1 1.5 2.3 2.3 2.5 2 1.9 1.7 2.2 1.8 3.2 3.2 2.7 2.2 2.2 1.9 1.9 1.8 2.7 3 2.3 2 2 2.9 2.9 2.7 2.7 2.3 2.6 2.4 1.8 1.7 1.5 1.4 2.1 3.3 3.5 3.5 3.1 2.6 2.1 3.4 3 2.9 ":1}

The answer can be compared to just padding the key with "random" letters to make the output at least 15 characters (24 bytes):

cat("{\"HeloWorld\":1}")


答:
R, 19 bytes

This works in British English locale; it may require +2 bytes in others. (Edit: it probably doesn't --- see comments.)

```<code>cat('{"',pi,'":1}')
</code>```

I was hoping for something clever (perhaps plucking a line of code out of a pre-existing function like q) but couldn't find anything. The result:

```<code>{" 3.141593 ":1}
</code>```

Note that you don't have to escape double quotes in R if you use single quotes to quote the string (and vice-versa). This behaviour is locale-dependent though. I would expect it to work in a US English locale as well though.

This also requires that your default digits option is at least six (which is the factory-fresh default) and that scipen is at least -digits (the factory-fresh default is zero).

Title: Print some JSON

Body:
R, 19 bytes

This works in British English locale; it may require +2 bytes in others. (Edit: it probably doesn't --- see comments.)

cat('{"',pi,'":1}')

I was hoping for something clever (perhaps plucking a line of code out of a pre-existing function like q) but couldn't find anything. The result:

{" 3.141593 ":1}

Note that you don't have to escape double quotes in R if you use single quotes to quote the string (and vice-versa). This behaviour is locale-dependent though. I would expect it to work in a US English locale as well though.

This also requires that your default digits option is at least six (which is the factory-fresh default) and that scipen is at least -digits (the factory-fresh default is zero).


答:
Java 7, 36 bytes

```<code>String c(){return"{\"a\":"+1e6+"}";}
</code>```

Java 8, 21 bytes

```<code>()->"{\"a\":"+1e6+"}"
</code>```

Ungolfed & test code:

Try it here.

```<code>class M{
  static String c(){
    return "{\"a\":" + 1e6 + "}";
  }

  public static void main(String[] a){
    System.out.println(c());
  }
}
</code>```

Output (length 15):

```<code>{"a":1000000.0}
</code>```

Title: Print some JSON

Body:
Java 7, 36 bytes

String c(){return"{\"a\":"+1e6+"}";}

Java 8, 21 bytes

()->"{\"a\":"+1e6+"}"

Ungolfed & test code:

Try it here.

class M{
  static String c(){
    return "{\"a\":" + 1e6 + "}";
  }

  public static void main(String[] a){
    System.out.println(c());
  }
}

Output (length 15):

{"a":1000000.0}


Title: Print some JSON

Body:
PHP, 19 bytes

<?='{"'.(9**9).'":1}';

Output: {"387420489":1}

https://eval.in/665889

Thanks to manatwork for the tips!


答:
jq, 6 characters

(3 characters code + 3 characters command-line option.)

```<code>env
</code>```

CW because I am sure this is not the kind of answer you intended to allow.

Sample run:

```<code>bash-4.3$ jq -n 'env'
{
  "GIT_PS1_SHOWDIRTYSTATE": "1",
  "TERM": "xterm",
  "SHELL": "/bin/bash",
  "GIT_PS1_SHOWUNTRACKEDFILES": "1",
  "XTERM_LOCALE": "en_US.UTF-8",
  "XTERM_VERSION": "XTerm(322)",
  "GIT_PS1_SHOWSTASHSTATE": "1",
  "GIT_PS1_SHOWUPSTREAM": "auto",
  "_": "/usr/bin/jq"
}
</code>```

(Output obviously shortened.)

Title: Print some JSON

Body:
jq, 6 characters

(3 characters code + 3 characters command-line option.)

env

CW because I am sure this is not the kind of answer you intended to allow.

Sample run:

bash-4.3$ jq -n 'env'
{
  "GIT_PS1_SHOWDIRTYSTATE": "1",
  "TERM": "xterm",
  "SHELL": "/bin/bash",
  "GIT_PS1_SHOWUNTRACKEDFILES": "1",
  "XTERM_LOCALE": "en_US.UTF-8",
  "XTERM_VERSION": "XTerm(322)",
  "GIT_PS1_SHOWSTASHSTATE": "1",
  "GIT_PS1_SHOWUPSTREAM": "auto",
  "_": "/usr/bin/jq"
}

(Output obviously shortened.)


答:
PHP, <s>14</s> 13 bytes

```<code>{"":<?=M_E?>}
</code>```

Prints a <s>nice</s> mathsy object <s>that one could almost pretend is useful</s>:

```<code>{"":2.718281828459}
</code>```

Uses the fact that php prints anything outside the tags verbatim to save on some quotation marks, M_E was the shortest long enough constant I could find.

edit: saved one byte thanks to Lynn. Sadly it's no longer a 'nice' mathsy object.

Title: Print some JSON

Body:
PHP, <s>14</s> 13 bytes

{"":<?=M_E?>}

Prints a <s>nice</s> mathsy object <s>that one could almost pretend is useful</s>:

{"":2.718281828459}

Uses the fact that php prints anything outside the tags verbatim to save on some quotation marks, M_E was the shortest long enough constant I could find.

edit: saved one byte thanks to Lynn. Sadly it's no longer a 'nice' mathsy object.


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

答:
MATL, 57 bytes

```<code>tZyt:Y@!"@w2)t:Y@!"@w:"3$t@:)w@:)w3$)0&|H*XHx]J)]xxtZy]H&
</code>```

Of course, you can Try it online!

Input should be in 'portrait' orientation (nRows>=nColumns). I feel that this may not be the most efficient solution... But at least I'm leaving some room for others to outgolf me. I would love to hear specific hints that could have made this particular approach shorter, but I think this massive bytecount should inspire others to make a MATL entry with a completely different approach. Displays 0 if falsy, or a massive value if truthy (will quickly become Inf if matrix too large; for 1 extra byte, one could replace H* with H&Y (logical and)). Saved a few bytes thanks to @LuisMendo.

```<code>tZy  % Duplicate, get size. Note that n=<m.
%   STACK:  [m n], [C]
t: % Range 1:m
%   STACK:  [1...m], [m n], [C]
Y@   % Get all permutations of that range.
%   STACK:  [K],[m n],[C] with K all perms in m direction.
!"   % Do a for loop over each permutation.
%   STACK:  [m n],[C], current permutation in @.
@b   % Push current permutation. Bubble size to top.
%   STACK:  [m n],[pM],[C] with p current permutation in m direction.
2)t:Y@!" % Loop over all permutations again, now in n direction
%   STACK: [n],[pM],[C] with current permutation in @.
@w:" % Push current permutation. Loop over 1:n (to get size @ x @ matrices)
%   STACK: [pN],[pM],[C] with loop index in @.
3$t  % Duplicate the entire stack.
%   STACK: [pN],[pM],[C],[pN],[pM],[C]
@:)  % Get first @ items from pN
%   STACK: [pNsub],[pM],[C],[pN],[pM],[C]
w@:) % Get first @ items from pM
%   STACK: [pMsub],[pNsub],[C],[pN],[pM],[C]
w3$)  % Get submatrix. Needs a `w` to ensure correct order.
%   STACK: [Csub],[pN],[pM],[C]
0&|  % Determinant.
%   STACK: [det],[pN],[pM],[C]
H*XHx% Multiply with clipboard H.
%   STACK: [pN],[pM],[C]
]    % Quit size loop
%   STACK: [pN],[pM],[C]. Expected: [n],[pM],[C]
J)   % Get last element from pN, which is n.
%   STACK: [n],[pM],[C]
]    % Quit first loop
xxtZy% Reset stack to
%   STACK: [m n],[C]
]    % Quit final loop.
H& % Output H only.
</code>```

Title: Totally Invertible Submatrices

Body:
MATL, 57 bytes

tZyt:Y@!"@w2)t:Y@!"@w:"3$t@:)w@:)w3$)0&|H*XHx]J)]xxtZy]H&

Of course, you can Try it online!

Input should be in 'portrait' orientation (nRows>=nColumns). I feel that this may not be the most efficient solution... But at least I'm leaving some room for others to outgolf me. I would love to hear specific hints that could have made this particular approach shorter, but I think this massive bytecount should inspire others to make a MATL entry with a completely different approach. Displays 0 if falsy, or a massive value if truthy (will quickly become Inf if matrix too large; for 1 extra byte, one could replace H* with H&Y (logical and)). Saved a few bytes thanks to @LuisMendo.

tZy  % Duplicate, get size. Note that n=<m.
%   STACK:  [m n], [C]
t: % Range 1:m
%   STACK:  [1...m], [m n], [C]
Y@   % Get all permutations of that range.
%   STACK:  [K],[m n],[C] with K all perms in m direction.
!"   % Do a for loop over each permutation.
%   STACK:  [m n],[C], current permutation in @.
@b   % Push current permutation. Bubble size to top.
%   STACK:  [m n],[pM],[C] with p current permutation in m direction.
2)t:Y@!" % Loop over all permutations again, now in n direction
%   STACK: [n],[pM],[C] with current permutation in @.
@w:" % Push current permutation. Loop over 1:n (to get size @ x @ matrices)
%   STACK: [pN],[pM],[C] with loop index in @.
3$t  % Duplicate the entire stack.
%   STACK: [pN],[pM],[C],[pN],[pM],[C]
@:)  % Get first @ items from pN
%   STACK: [pNsub],[pM],[C],[pN],[pM],[C]
w@:) % Get first @ items from pM
%   STACK: [pMsub],[pNsub],[C],[pN],[pM],[C]
w3$)  % Get submatrix. Needs a `w` to ensure correct order.
%   STACK: [Csub],[pN],[pM],[C]
0&|  % Determinant.
%   STACK: [det],[pN],[pM],[C]
H*XHx% Multiply with clipboard H.
%   STACK: [pN],[pM],[C]
]    % Quit size loop
%   STACK: [pN],[pM],[C]. Expected: [n],[pM],[C]
J)   % Get last element from pN, which is n.
%   STACK: [n],[pM],[C]
]    % Quit first loop
xxtZy% Reset stack to
%   STACK: [m n],[C]
]    % Quit final loop.
H& % Output H only.


答:
Groovy Script, <s>273</s> <s>265</s> <s>216</s> <s>202</s> 198 bytes

```<code>i=args[0]as int
a=i<32?'^| |^':'o| |o'
b=i<32?'VvVvV':'XXXXX'
j=i>30
print" _____I_____\n| | | | | | |\n| |${j?"$a| ":" |$a"}| |\n| | |${j?'^| ':' |^'}| | |\n| |${j?"$b| ":" |$b"}| |\n|_|_|_|_|_|_|"
</code>```

Ungolfed version

```<code>i = args[0] as int
a = i < 32 ? '^| |^' : 'o| |o'
b = i < 32 ? 'VvVvV' : 'XXXXX'
j = i > 30
print """ _____I_____
| | | | | | |
| |${j ? "$a| " : " |$a"}| |
| | |${j ? '^| ' : ' |^'}| | |
| |${j ? "$b| " : " |$b"}| |
|_|_|_|_|_|_|"""
</code>```

Try it here

Edit

As Titus mentioned, I can save some size with i < 32 instead of i in 1..31

Edit 2

Removed all possible spaces around operators... Forgot to do so in the beginning

Edit 3

Rewrote ternary conditions to use the saved variable, replaced ; with newlines, removed explicit variable definition

Edit 4

As Otávio mentioned, I can save another 4 bytes if I switch from | |${j ? ' |^| | ' : ' | |^| '}| | to | | |${j ? '^| ' : ' |^'}| | |

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

Body:
Groovy Script, <s>273</s> <s>265</s> <s>216</s> <s>202</s> 198 bytes

i=args[0]as int
a=i<32?'^| |^':'o| |o'
b=i<32?'VvVvV':'XXXXX'
j=i>30
print" _____I_____\n| | | | | | |\n| |${j?"$a| ":" |$a"}| |\n| | |${j?'^| ':' |^'}| | |\n| |${j?"$b| ":" |$b"}| |\n|_|_|_|_|_|_|"

Ungolfed version

i = args[0] as int
a = i < 32 ? '^| |^' : 'o| |o'
b = i < 32 ? 'VvVvV' : 'XXXXX'
j = i > 30
print """ _____I_____
| | | | | | |
| |${j ? "$a| " : " |$a"}| |
| | |${j ? '^| ' : ' |^'}| | |
| |${j ? "$b| " : " |$b"}| |
|_|_|_|_|_|_|"""

Try it here

Edit

As Titus mentioned, I can save some size with i < 32 instead of i in 1..31

Edit 2

Removed all possible spaces around operators... Forgot to do so in the beginning

Edit 3

Rewrote ternary conditions to use the saved variable, replaced ; with newlines, removed explicit variable definition

Edit 4

As Otávio mentioned, I can save another 4 bytes if I switch from | |${j ? ' |^| | ' : ' | |^| '}| | to | | |${j ? '^| ' : ' |^'}| | |


问:
Print the tetration

Tetration, represented as \${}^ba\$, is repeated exponentiation. For example, \${}^32\$ is \$2^{2^2}\$, which is \$16\$.

Given two numbers \$a\$ and \$b\$, print \${}^ba\$.

Test cases

```<code>1 2 -> 1
2 2 -> 4
5 2 -> 3125
3 3 -> 7625597484987
etc.
</code>```

Scientific notation is acceptable.

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

答:
Java 7, <s>71</s> 57 bytes

```<code>double c(int a,int b){return b>0?Math.pow(a,c(a,b-1)):1;}
</code>```

Ungolfed & test code:

Try it here.

```<code>class M{
  static double c(int a, int b){
    return b > 0
            ? Math.pow(a, c(a, b-1))
            :1;
  }

  public static void main(String[] a){
    System.out.println(c(1, 2));
    System.out.println(c(2, 2));
    System.out.println(c(5, 2));
    System.out.println(c(3, 3));
  }
}
</code>```

Output:

```<code>1.0
4.0
3125.0
7.625597484987E12
</code>```

Title: Print the tetration

Body:
Java 7, <s>71</s> 57 bytes

double c(int a,int b){return b>0?Math.pow(a,c(a,b-1)):1;}

Ungolfed & test code:

Try it here.

class M{
  static double c(int a, int b){
    return b > 0
            ? Math.pow(a, c(a, b-1))
            :1;
  }

  public static void main(String[] a){
    System.out.println(c(1, 2));
    System.out.println(c(2, 2));
    System.out.println(c(5, 2));
    System.out.println(c(3, 3));
  }
}

Output:

1.0
4.0
3125.0
7.625597484987E12


答:
///, <s>15</s> 14 characters

```<code>/a/{":1234}/aa
</code>```

(At least the output is <s>1</s> 2 characters longer than the code.)

Try it online!

Thanks to:

ETHproductions for reusing the object delimiters as part of key (-1 character)

Sample run:

```<code>bash-4.3$ slashes.pl <<< '/a/{":1234}/aa'
{":1234}{":1234}
</code>```

Just to make it more readable:

```<code>bash-4.3$ slashes.pl <<< '/a/{":1234}/aa' | jq ''
{
  ":1234}{": 1234
}
</code>```

Title: Print some JSON

Body:
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:

You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace.  Your program should work without any input.

In the interest of clarity, a JSON object starts and ends with curly braces {}, and contains zero or more key:value pairs separated by commas.  The full JSON specification can be found at json.org, and the output of your code must pass this validator.

Therefore, any of the following would not be valid:

```<code>4                               //Too short, not an object
"really, really long string"    //A string, not an object
["an","array","of","values"]    //An array is not a JSON object
{"this":4      }                //You can't count unessential whitespace
{"1":1,"2":3}                   //Too short
{"a really long string"}        //Not valid JSON, it needs a value
{'single-quoted':3}             //JSON requires double-quotes for strings
</code>```

However, the following would be valid:

```<code>{"1":1,"2":2,"3":3,"4":4}       //Long enough
{"whitespace      ":4}          //This whitespace isn't unessential
</code>```

Non-programming languages are allowed on this challenge.  You may return a string from a function, or print it out.  This is a code-golf, so answer it with as little code as possible!

Body:
///, <s>15</s> 14 characters

/a/{":1234}/aa

(At least the output is <s>1</s> 2 characters longer than the code.)

Try it online!

Thanks to:

ETHproductions for reusing the object delimiters as part of key (-1 character)

Sample run:

bash-4.3$ slashes.pl <<< '/a/{":1234}/aa'
{":1234}{":1234}

Just to make it more readable:

bash-4.3$ slashes.pl <<< '/a/{":1234}/aa' | jq ''
{
  ":1234}{": 1234
}


答:
Jelly, 13 bytes

```<code>e€ØA×“¢®Ƒ’+OỌ
</code>```

Supports only uppercase letters.

Try it online!

Explanation

```<code>e€ØA×“¢®Ƒ’+OỌ  Input: string S
e€             Test if each char in S is an element of
  ØA             the uppercase alphabet 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    ×          Multiply by
     “¢®Ƒ’       The codepoints of '¢®Ƒ' as a base 250 integer
                 This forms 127397
          +    Vectorized add with
           O     The codepoints of each char in S
            Ọ  Convert back to char from codepoints
               Return and print implicitly
</code>```

Body:
Introduction

Emoji use a particular alphabet for their national flags, which allows one to put two symbols together to create the appropriate flag.

Your challenge, is to transform any uppercase letter into the appropriate Flag Identifier.

This may be much harder for languages that do not innately handle Unicode.
Each symbol is exactly 4 UTF-8 Bytes.

The Task

Given an input as one or more letters, output the same, with all letters replaced with their flag combinations.

Winner is the answer with the least Bytes, giving the tiebreaker to first answer posted.

Input / Output

Input and Output may use any standard method.
Letters in the input may optionally only support one case, Upper or Lower. Please specify in your answer what case your solution supports.

Your output may, intentionally or otherwise, output flag emoji instead of letter pairs.

Test Cases

FR

Hello, World! , !

Rules

Standard Loopholes Apply

Standard Input Output allowed

This is code-golf, however, All the Emoji Letters as provided above can be counted for a single byte each, instead of four. Least Bytes wins!

Body:
Jelly, 13 bytes

e€ØA×“¢®Ƒ’+OỌ

Supports only uppercase letters.

Try it online!

Explanation

e€ØA×“¢®Ƒ’+OỌ  Input: string S
e€             Test if each char in S is an element of
  ØA             the uppercase alphabet 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    ×          Multiply by
     “¢®Ƒ’       The codepoints of '¢®Ƒ' as a base 250 integer
                 This forms 127397
          +    Vectorized add with
           O     The codepoints of each char in S
            Ọ  Convert back to char from codepoints
               Return and print implicitly


问:
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, <s>39</s> <s>38</s> 35 bytes

Includes +1 for -p

Give sequence on STDIN:

```<code>antsy.pl <<< "2 1 3 0"
</code>```

antsy.pl:

```<code>#!/usr/bin/perl -p
s%\d+%--$a[$&]x"@a"=~/1  /%eg;$_++
</code>```

Title: Antsy permutations

Body:
Perl, <s>39</s> <s>38</s> 35 bytes

Includes +1 for -p

Give sequence on STDIN:

antsy.pl <<< "2 1 3 0"

antsy.pl:

#!/usr/bin/perl -p
s%\d+%--$a[$&]x"@a"=~/1  /%eg;$_++


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

Title: Traveling Pumpkin Problem

Body:
PHP, 309 bytes

function j($x,$y,$c,$v){if($s=array_search([$x,$y],$v))unset($v[$s]);for($c--,$i=4;$c>0&&$i--;)$m=($n=j($x+[1,0,-1,0][$i],$y+[0,1,0,-1][$i],$c,$v))>$m?$n:$m;for($c-=.5,$i=4;$c>0&&$i--;)$m=($n=j($x+[1,-1,-1,1][$i],$y+[1,1,-1,-1][$i],$c,$v))>$m?$n:$m;return$s?++$m:$m;}echo j(0,0,$argv[1],array_chunk($argv,2));

Absolutely brute force and not even very short. Use like:

php -r "function j($x,$y,$c,$v){if($s=array_search([$x,$y],$v))unset($v[$s]);for($c--,$i=4;$c>0&&$i--;)$m=($n=j($x+[1,0,-1,0][$i],$y+[0,1,0,-1][$i],$c,$v))>$m?$n:$m;for($c-=.5,$i=4;$c>0&&$i--;)$m=($n=j($x+[1,-1,-1,1][$i],$y+[1,1,-1,-1][$i],$c,$v))>$m?$n:$m;return$s?++$m:$m;}echo j(0,0,$argv[1],array_chunk($argv,2));" 5 1 1 2 1 3 1 4 1 5 0 5 1

With more whitespace and saved in a file:

<?php
function j( $x, $y, $c, $v)
{
    if( $s = array_search( [$x,$y], $v ) )
        unset( $v[$s] );

    for( $c--, $i=4; $c>0 && $i--;)
        $m = ( $n=j($x+[1,0,-1,0][$i],$y+[0,1,0,-1][$i],$c,$v) )>$m ? $n : $m;

    for( $c-=.5, $i=4; $c>0 && $i--;)
        $m = ( $n=j($x+[1,-1,-1,1][$i],$y+[1,1,-1,-1][$i],$c,$v) )>$m ? $n : $m;

    return $s ? ++$m : $m;
}
echo j( 0, 0, $argv[1], array_chunk($argv,2) );


答:
Retina, 11 bytes

{"9$*R":1}
```

<h3>Output</h3>

```{"RRRRRRRRR":1}
```

Note: the leading newline is significant as nothing is replaced with the resultant output, I've used a non-breaking space to illustrate this!

Try it online!

Title: Print some JSON

Body:
Retina, 11 bytes

{"9$*R":1}

Output

{"RRRRRRRRR":1}

Note: the leading newline is significant as nothing is replaced with the resultant output, I've used a non-breaking space to illustrate this!

Try it online!


Title: Print some JSON

Body:
Java (JDK 10), 20 bytes

v->"{\"\":"+1/.3+"}"

Try it online!

Output

{"":3.3333333333333335}


答:
IBM/Lotus Notes @Formula, <s>24</s> 23 bytes

Computed value in a Notes field.

```<code>"{\"\":"+@Text(@Pi)+"}"
</code>```

Outputs:

```<code>{"":3.14159265358979}
</code>```

Nothing clever - just uses the shortest possible function that outputs a number then converts it to text for display.

Title: Print some JSON

Body:
IBM/Lotus Notes @Formula, <s>24</s> 23 bytes

Computed value in a Notes field.

"{\"\":"+@Text(@Pi)+"}"

Outputs:

{"":3.14159265358979}

Nothing clever - just uses the shortest possible function that outputs a number then converts it to text for display.


答:
Brainfuck, 60 bytes

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

The permutation is given as bytes with no separators and no terminating newline. Since \x00 occurs in the input, this is designed for implementations with EOF = -1. The output is \x00 for false and \x01 for true.

If a permutation of \x01 up to chr(r) is allowed, then we can replace all instances of ,+ with , for a score of 57 with an EOF = 0 implementation.

Try it online (57-byte version): Input can be given as a permutation of any contiguous range of bytes excluding \x00, and the output will be \x00 for false and the minimum of the range for true.

We keep track of the min and max seen so far, and for each character after the first, check whether it is min-1 or max+1 or neither. In the case of neither, move the pointer outside the normal working space so that the local cells become zero.

The memory layout of the normal working space at the beginning of the main loop is

c a b 0 0

where c is the current character, a is min, and b is max. (For the 60-byte version, everything is handled with an offset of 1 because of ,+.)

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:
Brainfuck, 60 bytes

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

The permutation is given as bytes with no separators and no terminating newline. Since \x00 occurs in the input, this is designed for implementations with EOF = -1. The output is \x00 for false and \x01 for true.

If a permutation of \x01 up to chr(r) is allowed, then we can replace all instances of ,+ with , for a score of 57 with an EOF = 0 implementation.

Try it online (57-byte version): Input can be given as a permutation of any contiguous range of bytes excluding \x00, and the output will be \x00 for false and the minimum of the range for true.

We keep track of the min and max seen so far, and for each character after the first, check whether it is min-1 or max+1 or neither. In the case of neither, move the pointer outside the normal working space so that the local cells become zero.

The memory layout of the normal working space at the beginning of the main loop is

c a b 0 0

where c is the current character, a is min, and b is max. (For the 60-byte version, everything is handled with an offset of 1 because of ,+.)


问:
Draw an hourglass
Again inspired by a task for Programming 101 here's another challenge.

Input:

A positive integer n >= 3. (has to be odd)

Output:

n lines of asterisks, where the first line has n asterisks and every new line has two asterisks less than the line before. Until hitting 1 asterisk. From there every new line has two asterisks more than the line before until getting back to n asterisks. Spaces or something like spaces have to used to align the asterisks so that it really will look like an hourglass.

General rules:

Trailing newlines are allowed but do not have to be used.

indentation is a must.

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

Since the course is taught in C++, I'm eager to see solutions in C++.

Test case (n=5):

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

答:
C++ Metatemplates, 186 bytes

With the explicit formula from my C answer the Metatemplates are competing!

template<int N,int X=N*N+N-1>struct H{enum{I=X/(N+1)-N/2,J=X%(N+1)-N/2-1};S s{(J==-N/2-1?'\n':((I>=J&I>=-J)|(I<=J&I<=-J)?'*':' '))+H<N,X-1>().s};};template<int N>struct H<N,-1>{S s="";};
```

<p>Ungolfed:</p>

<pre class="lang-c++ prettyprint-override"><code>using S=std::string;

template <int N, int X=N*N+N-1>
struct H{
 enum{I=X/(N+1)-N/2,J=X%(N+1)-N/2-1};
 S s{(J==-N/2-1 ? '\n' : ( (I>=J&I>=-J)|(I<=J&I<=-J) ?'*':' '))+H<N,X-1>().s};
};

template <int N> struct H<N,-1> {S s="";};
</code>```

usage:

std::cout << H<5>().s;
```

<h3>non-competing</h3>

<p>Just for the sake of fun:</p>

<pre class="lang-c++ prettyprint-override"><code>//T: Tuple of chars
template <char C, char...Tail> struct T { S r=S(1,C)+T<Tail...>().r; };

//specialization for single char
template <char C> struct T<C> { S r=S(1,C); };

//M: Repeated char
template <int N, char C> struct M { S r=S(N,C); };

//U: concatenates T and M
template <class Head, class...Tail> struct U { S r=Head().r+U<Tail...>().r; };

//specialization for Tail=M
template <int N, char C> struct U<M<N,C>> { S r{M<N,C>().r}; };

//specialization for Tail=T
template <char...C> struct U<T<C...>> { S r=T<C...>().r; };

//finally the Hourglass
template <int N, int I=0> struct H {
 S s=U<
       M<I,' '>,
       M<N,'*'>,
       T<'\n'>
      >().r;
 S r{s + H<N-2,I+1>().r + s};
};

//specialization for recursion end
template <int I> struct H<1,I> {
 S r=U<
       M<I,' '>,
       T<'*','\n'>
      >().r;
};
</code>```

Usage:

std::cout << H<5>().r;
```

Title: Draw an hourglass

Body:
C++ Metatemplates, 186 bytes

With the explicit formula from my C answer the Metatemplates are competing!

template<int N,int X=N*N+N-1>struct H{enum{I=X/(N+1)-N/2,J=X%(N+1)-N/2-1};S s{(J==-N/2-1?'\n':((I>=J&I>=-J)|(I<=J&I<=-J)?'*':' '))+H<N,X-1>().s};};template<int N>struct H<N,-1>{S s="";};

Ungolfed:

using S=std::string;

template <int N, int X=N*N+N-1>
struct H{
 enum{I=X/(N+1)-N/2,J=X%(N+1)-N/2-1};
 S s{(J==-N/2-1 ? '\n' : ( (I>=J&I>=-J)|(I<=J&I<=-J) ?'*':' '))+H<N,X-1>().s};
};

template <int N> struct H<N,-1> {S s="";};

usage:

std::cout << H<5>().s;

non-competing

Just for the sake of fun:

//T: Tuple of chars
template <char C, char...Tail> struct T { S r=S(1,C)+T<Tail...>().r; };

//specialization for single char
template <char C> struct T<C> { S r=S(1,C); };

//M: Repeated char
template <int N, char C> struct M { S r=S(N,C); };

//U: concatenates T and M
template <class Head, class...Tail> struct U { S r=Head().r+U<Tail...>().r; };

//specialization for Tail=M
template <int N, char C> struct U<M<N,C>> { S r{M<N,C>().r}; };

//specialization for Tail=T
template <char...C> struct U<T<C...>> { S r=T<C...>().r; };

//finally the Hourglass
template <int N, int I=0> struct H {
 S s=U<
       M<I,' '>,
       M<N,'*'>,
       T<'\n'>
      >().r;
 S r{s + H<N-2,I+1>().r + s};
};

//specialization for recursion end
template <int I> struct H<1,I> {
 S r=U<
       M<I,' '>,
       T<'*','\n'>
      >().r;
};

Usage:

std::cout << H<5>().r;


答:
PHP, 101 Bytes

supports both replace 64 with 96 to support only lowercase. input only ascii characters allowed

```<code>foreach(str_split($argv[1])as$c)echo($o=ord($c))>64&&$o%32<27?hex2bin("f09f87".dechex($o%32+165)):$c;
</code>```

PHP, 112 Bytes

supports both remove i as modifier in the regex to support only lowercase

```<code><?=preg_replace_callback("#[a-z]#i",function($t){return hex2bin("f09f87".dechex(ord($t[0])%32+165));},$argv[1]);
</code>```

first version 205 Bytes

```<code><?=preg_replace_callback("#[a-z]#i",function($t){return substr("",(ord($t[0])%32-1)*4,4);},$argv[1]);
</code>```

The version with mb_substr is one Byte longer

Body:
PHP, 101 Bytes

supports both replace 64 with 96 to support only lowercase. input only ascii characters allowed

foreach(str_split($argv[1])as$c)echo($o=ord($c))>64&&$o%32<27?hex2bin("f09f87".dechex($o%32+165)):$c;

PHP, 112 Bytes

supports both remove i as modifier in the regex to support only lowercase

<?=preg_replace_callback("#[a-z]#i",function($t){return hex2bin("f09f87".dechex(ord($t[0])%32+165));},$argv[1]);

first version 205 Bytes

<?=preg_replace_callback("#[a-z]#i",function($t){return substr("",(ord($t[0])%32-1)*4,4);},$argv[1]);

The version with mb_substr is one Byte longer


答:
Perl 5, 16 15 bytes

Uses the unix timestamp of the moment the program was started as the content of a one-element object. It gives valid output if you run it later than 10:46:39 on 3rd of March 1973. But since we can't go back in time that seems legit.

```<code>say"{\"$^T\":1}"
</code>```

Uses the FORMAT_TOP_HANDLE variable $^ which defaults to STDOUT_TOP.

```<code>say"{\"$^\":1}";
</code>```

Run with -E flag at no additional cost.

```<code>perl -E 'say"{\"$^\":1}";'
</code>```

Outputs is 16 bytes long.

```<code>{"STDOUT_TOP":1}
</code>```

Title: Print some JSON

Body:
Perl 5, 16 15 bytes

Uses the unix timestamp of the moment the program was started as the content of a one-element object. It gives valid output if you run it later than 10:46:39 on 3rd of March 1973. But since we can't go back in time that seems legit.

say"{\"$^T\":1}"

Uses the FORMAT_TOP_HANDLE variable $^ which defaults to STDOUT_TOP.

say"{\"$^\":1}";

Run with -E flag at no additional cost.

perl -E 'say"{\"$^\":1}";'

Outputs is 16 bytes long.

{"STDOUT_TOP":1}


答:
JavaScript (ES6), 70 bytes

f=
s=>s.replace(/[A-Z]/g,c=>String.fromCodePoint(c.codePointAt()+127397))
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input oninput=o.textContent=f(this.value)><div id=o></code>```

Accepts upper case only. Mixed case version for 73 bytes:

f=
s=>s.replace(/[A-Z]/gi,c=>String.fromCodePoint(c.codePointAt()+5|127392))
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input oninput=o.textContent=f(this.value)><div id=o></code>```

Body:
JavaScript (ES6), 70 bytes

f=
s=>s.replace(/[A-Z]/g,c=>String.fromCodePoint(c.codePointAt()+127397))
;

<input oninput=o.textContent=f(this.value)><div id=o>

Accepts upper case only. Mixed case version for 73 bytes:

f=
s=>s.replace(/[A-Z]/gi,c=>String.fromCodePoint(c.codePointAt()+5|127392))
;

<input oninput=o.textContent=f(this.value)><div id=o>


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:
PHP, <s>178</s> <s>176</s> 171 bytes

$e="| | ";$b=($n=$argv[1]-31)?" |^":"^| ";$c=$n<1?VvVvV:XXXXX;$a=$n<1?$b:" |o";echo" _____I_____\n$e$e$e|\n| |$a|$a$e\n$e|$b$e|\n| |",$n?" |$c":"$c| ","$e\n|_|_|_|_|_|_|";

could save 5 bytes with physical linebreaks. Run with -r.


答:
C++ 11, 65 bytes

Not including the include in the byte count.

#include<string>
using S=std::string;S g(int n){return n?g(n-1)+S(n,'*')+'\n':"";}
```
<p>Usage:</p>
<pre class="lang-c++ prettyprint-override"><code>std::cout << g(n) << std::endl;
</code>```

Title: Draw an asterisk triangle

Body:
Inspired by a task for Programming 101, here's a challenge that hopefully isn't too easy (or a duplicate).

Input:

A positive integer n >= 1.

Output:

n lines of asterisks, where every new line has one asterisk more than the line before, and starting with one asterisk in the first line.

Test case (n=5):

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

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

Body:
C++ 11, 65 bytes

Not including the include in the byte count.

#include<string>
using S=std::string;S g(int n){return n?g(n-1)+S(n,'*')+'\n':"";}

Usage:

std::cout << g(n) << std::endl;


问:
Find the nth decimal of pi
There are already 30 challenges dedicated to pi but not a single one asks you to find the nth decimal, so...

Challenge

For any integer in the range of 0 <= n <= 10000 display the nth decimal of pi.

Rules

Decimals are every number after 3.

Your program may be a function, or a full program

You must output the result in base 10

You may get n from any suitable input method (stdin, input(), function parameters, ...), but not hardcoded

You may use 1-based indexing if that's native to your language of choice

You don't have to deal with invalid input (n == -1, n == 'a' or n == 1.5)

Builtins are allowed, if they support up to at least 10k decimals

Runtime doesn't matter, since this is about the shortest code and not the fastest code

This is code-golf, shortest code in bytes wins

Test cases

```<code>f(0)     == 1
f(1)     == 4 // for 1-indexed languages f(1) == 1
f(2)     == 1 // for 1-indexed languages f(2) == 4
f(3)     == 5
f(10)    == 8
f(100)   == 8
f(599)   == 2
f(760)   == 4
f(1000)  == 3
f(10000) == 5
</code>```

For reference, here are the first 100k digits of pi.

答:
Java 7, <s>262</s> 260 bytes

```<code>import java.math.*;int c(int n){BigInteger p,a=p=BigInteger.TEN.pow(10010).multiply(new BigInteger("2"));for(int i=1;a.compareTo(BigInteger.ZERO)>0;p=p.add(a))a=a.multiply(new BigInteger(i+"")).divide(new BigInteger((2*i+++1)+""));return(p+"").charAt(n+1)-48;}
</code>```

Used @LeakyNun's Python 2 algorithm.

Ungolfed & test code:

Try it here.

```<code>import java.math.*;
class M{
  static int c(int n){
    BigInteger p, a = p = BigInteger.TEN.pow(10010).multiply(new BigInteger("2"));
    for(int i = 1; a.compareTo(BigInteger.ZERO) > 0; p = p.add(a)){
      a = a.multiply(new BigInteger(i+"")).divide(new BigInteger((2 * i++ + 1)+""));
    }
    return (p+"").charAt(n+1) - 48;
  }

  public static void main(String[] a){
    System.out.print(c(0)+", ");
    System.out.print(c(1)+", ");
    System.out.print(c(2)+", ");
    System.out.print(c(3)+", ");
    System.out.print(c(10)+", ");
    System.out.print(c(100)+", ");
    System.out.print(c(599)+", ");
    System.out.print(c(760)+", ");
    System.out.print(c(1000)+", ");
    System.out.print(c(10000));
  }
}
</code>```

Output:

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

Title: Find the nth decimal of pi

Body:
Java 7, <s>262</s> 260 bytes

import java.math.*;int c(int n){BigInteger p,a=p=BigInteger.TEN.pow(10010).multiply(new BigInteger("2"));for(int i=1;a.compareTo(BigInteger.ZERO)>0;p=p.add(a))a=a.multiply(new BigInteger(i+"")).divide(new BigInteger((2*i+++1)+""));return(p+"").charAt(n+1)-48;}

Used @LeakyNun's Python 2 algorithm.

Ungolfed & test code:

Try it here.

import java.math.*;
class M{
  static int c(int n){
    BigInteger p, a = p = BigInteger.TEN.pow(10010).multiply(new BigInteger("2"));
    for(int i = 1; a.compareTo(BigInteger.ZERO) > 0; p = p.add(a)){
      a = a.multiply(new BigInteger(i+"")).divide(new BigInteger((2 * i++ + 1)+""));
    }
    return (p+"").charAt(n+1) - 48;
  }

  public static void main(String[] a){
    System.out.print(c(0)+", ");
    System.out.print(c(1)+", ");
    System.out.print(c(2)+", ");
    System.out.print(c(3)+", ");
    System.out.print(c(10)+", ");
    System.out.print(c(100)+", ");
    System.out.print(c(599)+", ");
    System.out.print(c(760)+", ");
    System.out.print(c(1000)+", ");
    System.out.print(c(10000));
  }
}

Output:

1, 4, 1, 5, 8, 8, 2, 4, 3, 5


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

Body:
C# 6, 223 215 bytes

int d=int.Parse(args[0]);var x="| | |\n| |";var s=d<31?" |^| |^| |\n| | | |^"+x+" |VvVvV":(d==31?"^| |^"+x+" |^| "+x+"VvVvV| ":"o| |o"+x+" |^| "+x+"XXXXX| ");Write(" _____I_____\n| | | | "+x+s+"| |\n|_|_|_|_|_|_|");

Entire program ungolfed:

using static System.Console;
namespace Halloween
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int d = int.Parse(args[0]);
            var x = "| | |\n| |";
            var s = d < 31 ? " |^| |^| |\n| | | |^" + x + " |VvVvV"
                           : (d == 31 ? "^| |^" + x + " |^| " + x + "VvVvV| "
                                      : "o| |o" + x + " |^| " + x + "XXXXX| ");
            Write(" _____I_____\n| | | | " + x + s + "| |\n|_|_|_|_|_|_|");
        }
    }
}


答:
PowerShell <s>22</s> <s>20</s> 14 Bytes

```<code>'{"":'+1tb+'}'
</code>```

Output

```<code>{"":1099511627776}
</code>```

Using the constant defined for 1TB in bytes to reach the character limit and the value of a static integer to make for valid json. Thanks to TimmyD for reducing the characters by 5 by removing some redundancy.

Earlier Post 40 Bytes

```<code>"{$((1..9|%{'"{0}":{0}'-f$_})-join",")}"
</code>```

Output

```<code>{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9}
</code>```

Takes a integer array and creates a key-value pair for each. Join with commas and wrap with a set of curly braces.

Title: Print some JSON

Body:
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:

You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace.  Your program should work without any input.

In the interest of clarity, a JSON object starts and ends with curly braces {}, and contains zero or more key:value pairs separated by commas.  The full JSON specification can be found at json.org, and the output of your code must pass this validator.

Therefore, any of the following would not be valid:

```<code>4                               //Too short, not an object
"really, really long string"    //A string, not an object
["an","array","of","values"]    //An array is not a JSON object
{"this":4      }                //You can't count unessential whitespace
{"1":1,"2":3}                   //Too short
{"a really long string"}        //Not valid JSON, it needs a value
{'single-quoted':3}             //JSON requires double-quotes for strings
</code>```

However, the following would be valid:

```<code>{"1":1,"2":2,"3":3,"4":4}       //Long enough
{"whitespace      ":4}          //This whitespace isn't unessential
</code>```

Non-programming languages are allowed on this challenge.  You may return a string from a function, or print it out.  This is a code-golf, so answer it with as little code as possible!

Body:
PowerShell <s>22</s> <s>20</s> 14 Bytes

'{"":'+1tb+'}'

Output

{"":1099511627776}

Using the constant defined for 1TB in bytes to reach the character limit and the value of a static integer to make for valid json. Thanks to TimmyD for reducing the characters by 5 by removing some redundancy.

Earlier Post 40 Bytes

"{$((1..9|%{'"{0}":{0}'-f$_})-join",")}"

Output

{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9}

Takes a integer array and creates a key-value pair for each. Join with commas and wrap with a set of curly braces.


问:
Print the n-th digit of pi
Task

Given an input n, calculate the n-th decimal digit of pi

Rules

Answer can be a full program or a function.

Input must be taken from stdin or from function arguments.

Output must be either sent to stdout, the return value of a function, or written to a file.

all n values between 0 and 20000 must be supported (can be between 1 and 20001 for 1-indexed languages).

Built-ins to calculate pi cannot be used. This includes pi constants (e.g. math.pi in Python) and built-in functions that return either the value of pi, or the n-th digit of pi. This means that an algorithm which calculates pi, or the n-th digit of pi must be implemented in your answer.

Digits must be calculated at runtime.

First digit (0-th or 1-th, depending on the language) is 3.

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

EDIT:

This is not a duplicate of 'Find the n-th decimal of pi', since that challenge allowed built-ins. This one is focused around actually implementing an algorithm to find the digits, rather than relying on built-ins.

答:
Java 7, <s>260</s> 258 bytes

```<code>import java.math.*;int c(int n){BigInteger p,a=p=BigInteger.TEN.pow(20010).multiply(new BigInteger("2"));for(int i=1;a.compareTo(BigInteger.ZERO)>0;p=p.add(a))a=a.multiply(new BigInteger(i+"")).divide(new BigInteger((2*i+++1)+""));return(p+"").charAt(n)-48;}
</code>```

Copy from my answer here. Java's built-in Math.PI has a precision of 15 decimal points, so I was already forced to use an algorithm for the other challenge anyway..

Used @LeakyNun's Python 2 algorithm.

Ungolfed & test code:

Try it here. (The ideone can't handle the last two test cases, but it works within 2 sec in the Eclipse IDE.)

```<code>import java.math.*;
class M{
  static int c(int n){
    BigInteger p, a = p = BigInteger.TEN.pow(20010).multiply(new BigInteger("2"));
    for(int i = 1; a.compareTo(BigInteger.ZERO) > 0; p = p.add(a), i++){
      a = a.multiply(new BigInteger(i+"")).divide(new BigInteger((2 * i++ + 1)+""));
    }
    return (p+"").charAt(n) - 48;
  }

  public static void main(String[] a){
    System.out.print(c(0)+", ");
    System.out.print(c(1)+", ");
    System.out.print(c(2)+", ");
    System.out.print(c(3)+", ");
    System.out.print(c(4)+", ");
    System.out.print(c(11)+", ");
    System.out.print(c(101)+", ");
    System.out.print(c(600)+", ");
    System.out.print(c(761)+", ");
    System.out.print(c(1001)+", ");
    System.out.print(c(10001)+", ");
    System.out.print(c(20001));
  }
}
</code>```

Output:

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

Title: Print the n-th digit of pi

Body:
Java 7, <s>260</s> 258 bytes

import java.math.*;int c(int n){BigInteger p,a=p=BigInteger.TEN.pow(20010).multiply(new BigInteger("2"));for(int i=1;a.compareTo(BigInteger.ZERO)>0;p=p.add(a))a=a.multiply(new BigInteger(i+"")).divide(new BigInteger((2*i+++1)+""));return(p+"").charAt(n)-48;}

Copy from my answer here. Java's built-in Math.PI has a precision of 15 decimal points, so I was already forced to use an algorithm for the other challenge anyway..

Used @LeakyNun's Python 2 algorithm.

Ungolfed & test code:

Try it here. (The ideone can't handle the last two test cases, but it works within 2 sec in the Eclipse IDE.)

import java.math.*;
class M{
  static int c(int n){
    BigInteger p, a = p = BigInteger.TEN.pow(20010).multiply(new BigInteger("2"));
    for(int i = 1; a.compareTo(BigInteger.ZERO) > 0; p = p.add(a), i++){
      a = a.multiply(new BigInteger(i+"")).divide(new BigInteger((2 * i++ + 1)+""));
    }
    return (p+"").charAt(n) - 48;
  }

  public static void main(String[] a){
    System.out.print(c(0)+", ");
    System.out.print(c(1)+", ");
    System.out.print(c(2)+", ");
    System.out.print(c(3)+", ");
    System.out.print(c(4)+", ");
    System.out.print(c(11)+", ");
    System.out.print(c(101)+", ");
    System.out.print(c(600)+", ");
    System.out.print(c(761)+", ");
    System.out.print(c(1001)+", ");
    System.out.print(c(10001)+", ");
    System.out.print(c(20001));
  }
}

Output:

3, 1, 4, 1, 5, 8, 8, 2, 4, 3, 5, 2


答:
Batch, 16 bytes

Prints {"Windows_NT":0}.

```<code>@echo {"%OS%":0}
</code>```

Title: Print some JSON

Body:
Batch, 16 bytes

Prints {"Windows_NT":0}.

@echo {"%OS%":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.

答:
R, 30 bytes, arguable whether it is deterministic

```<code>while(any(sample(2,654,T)>1))1
</code>```

R's default random number generator has equidistribution in 653 consecutive dimensions but it is not known to in 654 dimensions. Thus there may or may not be a sequence of pseudorandom numbers that sample the lowest element from a given vector 654 times in a row (here the vector 1:2).

Since R's RNG is periodic (albeit with very long period), I claim that this is deterministic since it will eventually loop round to the start. Your opinions may differ, of course.

Title: Does the code terminate?

Body:
R, 30 bytes, arguable whether it is deterministic

while(any(sample(2,654,T)>1))1

R's default random number generator has equidistribution in 653 consecutive dimensions but it is not known to in 654 dimensions. Thus there may or may not be a sequence of pseudorandom numbers that sample the lowest element from a given vector 654 times in a row (here the vector 1:2).

Since R's RNG is periodic (albeit with very long period), I claim that this is deterministic since it will eventually loop round to the start. Your opinions may differ, of course.


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

Body:
Python 2, 167 bytes

i=input()
b='| |';e='^o'[i>31]+b;print'\n'.join(x[::[1,-1][i>30]]for x in[' _____I_____ ','| '*5+b,b+' |'+e+e,b+' | |^| '+b,b+' |'+['VvVvV','X'*5][i>31]+b,'|_'*6+'|'])


答:
Python 2, <s>182</s> 65 bytes

a=p=2*10**20004
i=3
while a:a=i/2*a/i;p+=a;i+=2
print`p`[input()]
```

<p><strong>repl.it</strong></p>

<p>Uses the Leibniz formula to calculate 20000 correct digits (plus a handful to allow the algorithm to maintain accuracy) then prints the requested digit.</p>

<hr>

<p>Previous (182):<br>
"The Spigot Algorithm For Pi" of Stanley Rabinowitz and Stan Wagon has the added bonus that it will work for any <code>n</code> when implemented as a generator</p>

<pre class="lang-python prettyprint-override"><code>p=lambda n,r=3,a=0,b=1,c=1,d=1,e=3,f=3,i=0:i>n and r or p(n,e,*[((2*b+a)*f,b*d,c*f,d+1,(b*(7*d)+2+(a*f))/(c*f),f+2,i),(10*(a-e*c),10*b,c,d,((10*(3*b+a))/c)-10*e,f,i+1)][4*b+a-c<e*c])
</code>```

repl.it Reaches Python's default recursion limit for the 117th digit.

Here is a non-recursive version for 198 bytes:

def p(n):
 a=i=0;b=c=d=1;e=f=3
 while i<=n:
     r=e
     if 4*b+a-c<e*c:g=10*(a-e*c);e=((10*(3*b+a))/c)-10*e;b*=10;i+=1
     else:g=(2*b+a)*f;h=(b*(7*d)+2+(a*f))/(c*f);b*=d;c*=f;f+=2;d+=1;e=h
     a=g
 print r
```

repl.it

(first indent space, second indent tab), the digits could, of course, be generated by yielding e at the start of the if clause instead of tracking the last digit with r.

Title: Print the n-th digit of pi

Body:
Task

Given an input n, calculate the n-th decimal digit of pi

Rules

Answer can be a full program or a function.

Input must be taken from stdin or from function arguments.

Output must be either sent to stdout, the return value of a function, or written to a file.

all n values between 0 and 20000 must be supported (can be between 1 and 20001 for 1-indexed languages).

Built-ins to calculate pi cannot be used. This includes pi constants (e.g. math.pi in Python) and built-in functions that return either the value of pi, or the n-th digit of pi. This means that an algorithm which calculates pi, or the n-th digit of pi must be implemented in your answer.

Digits must be calculated at runtime.

First digit (0-th or 1-th, depending on the language) is 3.

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

EDIT:

This is not a duplicate of 'Find the n-th decimal of pi', since that challenge allowed built-ins. This one is focused around actually implementing an algorithm to find the digits, rather than relying on built-ins.

Body:
Python 2, <s>182</s> 65 bytes

a=p=2*10**20004
i=3
while a:a=i/2*a/i;p+=a;i+=2
print`p`[input()]

repl.it

Uses the Leibniz formula to calculate 20000 correct digits (plus a handful to allow the algorithm to maintain accuracy) then prints the requested digit.

Previous (182):

"The Spigot Algorithm For Pi" of Stanley Rabinowitz and Stan Wagon has the added bonus that it will work for any n when implemented as a generator

p=lambda n,r=3,a=0,b=1,c=1,d=1,e=3,f=3,i=0:i>n and r or p(n,e,*[((2*b+a)*f,b*d,c*f,d+1,(b*(7*d)+2+(a*f))/(c*f),f+2,i),(10*(a-e*c),10*b,c,d,((10*(3*b+a))/c)-10*e,f,i+1)][4*b+a-c<e*c])

repl.it Reaches Python's default recursion limit for the 117th digit.

Here is a non-recursive version for 198 bytes:

def p(n):
 a=i=0;b=c=d=1;e=f=3
 while i<=n:
     r=e
     if 4*b+a-c<e*c:g=10*(a-e*c);e=((10*(3*b+a))/c)-10*e;b*=10;i+=1
     else:g=(2*b+a)*f;h=(b*(7*d)+2+(a*f))/(c*f);b*=d;c*=f;f+=2;d+=1;e=h
     a=g
 print r

repl.it

(first indent space, second indent tab), the digits could, of course, be generated by yielding e at the start of the if clause instead of tracking the last digit with r.


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

Title: Fill in the Minesweeper clues

Body:
C#, 341 Bytes

A naïve implementation that can definitely be shortened.

s=>s=="*"?1:0;s=>{for(int i=0,j,n,l=s.Length,c=s[i].Length;i<l;++i)for(j=0;j<c;++j)if(s[i][j]!="*"){n=0;if(i>0){n+=a(s[i-1][j]);n+=j>0?a(s[i-1][j-1]):0;n+=j+1<c?a(s[i-1][j+1]):0;}n+=a(s[i][j]);n+=j>0?a(s[i][j-1]):0;n+=j+1<c?a(s[i][j+1]):0;if(i+1<l){n+=a(s[i+1][j]);n+=j>0?a(s[i+1][j-1]):0;n+=j+1<c?a(s[i+1][j+1]):0;}s[i][j]=n+"";}return s;};


答:
q, 14 bytes

Prints memory usage information about the current process

```<code>-1@.j.j .Q.w`;
</code>```

Sample output:

```<code>q)-1@.j.j .Q.w`;
{"used":127392,"heap":67108864,"peak":67108864,"wmax":0,"mmap":0,"mphy":16735457280,"syms":585,"symw":18925}
</code>```

Title: Print some JSON

Body:
q, 14 bytes

Prints memory usage information about the current process

-1@.j.j .Q.w`;

Sample output:

q)-1@.j.j .Q.w`;
{"used":127392,"heap":67108864,"peak":67108864,"wmax":0,"mmap":0,"mphy":16735457280,"syms":585,"symw":18925}


答:
PowerShell v2+, 54 bytes

```<code>param($n)$n..1+2..$n|?{$_%2}|%{" "*(($n-$_)/2)+"*"*$_}
</code>```

Takes input $n (guaranteed to be an odd integer), constructs two ranges with $n..1 and 2..$n and concatenates them together, then uses Where-Object to select only the odd ones with |?{$_%2}. Those are fed into a loop. Each iteration, we construct the appropriate number of spaces, string-concatenated with the appropriate number of asterisks. Those strings are left on the pipeline, and output via implicit Write-Output inserts newlines between them at program completion.

Examples

```<code>PS C:\Tools\Scripts\golfing> 3,5,7|%{.\draw-an-hourglass.ps1 $_;""}
***
 *
***

*****
 ***
  *
 ***
*****

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

Title: Draw an hourglass

Body:
Again inspired by a task for Programming 101 here's another challenge.

Input:

A positive integer n >= 3. (has to be odd)

Output:

n lines of asterisks, where the first line has n asterisks and every new line has two asterisks less than the line before. Until hitting 1 asterisk. From there every new line has two asterisks more than the line before until getting back to n asterisks. Spaces or something like spaces have to used to align the asterisks so that it really will look like an hourglass.

General rules:

Trailing newlines are allowed but do not have to be used.

indentation is a must.

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

Since the course is taught in C++, I'm eager to see solutions in C++.

Test case (n=5):

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

Body:
PowerShell v2+, 54 bytes

param($n)$n..1+2..$n|?{$_%2}|%{" "*(($n-$_)/2)+"*"*$_}

Takes input $n (guaranteed to be an odd integer), constructs two ranges with $n..1 and 2..$n and concatenates them together, then uses Where-Object to select only the odd ones with |?{$_%2}. Those are fed into a loop. Each iteration, we construct the appropriate number of spaces, string-concatenated with the appropriate number of asterisks. Those strings are left on the pipeline, and output via implicit Write-Output inserts newlines between them at program completion.

Examples

PS C:\Tools\Scripts\golfing> 3,5,7|%{.\draw-an-hourglass.ps1 $_;""}
***
 *
***

*****
 ***
  *
 ***
*****

*******
 *****
  ***
   *
  ***
 *****
*******