问:
Compute the Carmichael function

Task description

In number theory, the Carmichael function λ takes a positive integer n and returns the least positive integer k so that the k-th power of each integer coprime to n equals 1 modulo n.

Given a positive integer n, your solution must compute λ(n). The shortest code in bytes wins.

Your program should theoretically work for arbitrarily large inputs, but doesn’t need to be efficient.

Tips

The sequence of all λ(n) is OEIS A002322.

An ungolfed Python implementation would look like

```<code>from fractions import gcd

def carmichael(n):
    coprimes = [x for x in range(1, n) if gcd(x, n) == 1]
    k = 1
    while not all(pow(x, k, n) == 1 for x in coprimes):
        k += 1
    return k
</code>```

(In Python, pow(A, B, C) efficiently computes pow(A, B) % C.)

Test cases

```<code>Input    Output
1        1
2        1
3        2
10       4
35       12
101      100
530      52
3010     84
6511     3056
10000    500
</code>```

答:
Java8 <s>38</s> 19 + <s>287</s> <s>295</s> <s>253</s> <s>248</s> 241 = <s>325</s> <s>333</s> <s>272</s> <s>267</s> 260 bytes

```<code>BigInteger B(int i){return new BigInteger(""+i);}int c(int...k){int n=k[0];for(k[0]=1;n>1&!java.util.stream.IntStream.range(0,n).filter(i->B(n).gcd(B(i)).equals(B(1))).allMatch(x->B(x).modPow(B(k[0]),B(n)).equals(B(1)));k[0]++);return k[0];}
</code>```

Imports, 19 bytes

```<code>import java.math.*;
</code>```

Explanation

It is a straight forward implementation. The co-primes are calculated in the Set p and every one's kth power is used to check if it equals 1 modulo n.

I had to use BigInteger because of precision issues.

Usage

```<code>public static void main(String[] args) {
    Carmichael c = new Carmichael();
    System.out.println(c.c(3)); // prints 2
}
</code>```

Ungolfed

```<code>// returns the BigInteger representation of the given interger
BigInteger B(int i) {
    return new BigInteger(""+i);
}
// for a given integer it returns the result of the carmichael function again as interger
// so the return value cannot be larger
int c(int... k) {
    int n = k[0];
    // iterate k[0] until for all co-primes this is true: (x^n) mod n == 1, if n==1 skip the loop
    for (k[0]=1;n > 1 && !java.util.stream.IntStream.range(0, n)
                .filter(i -> B(n).gcd(B(i)).equals(B(1)))
                .allMatch(x -> B((int) x).modPow(B(k[0]), B(n)).equals(B(1)));k[0]++);
    return k[0];
}
</code>```

Any suggestions to golf it more are welcome :-)

Update

No elements outside the functions that keep the state

Followed Olivier Grégoire's advice and saved 1 byte from B()

Removed the k() method and p (co-primes) Set.

Removed not required casting to int.

Added varags and use for instead of while.

Title: Compute the Carmichael function

Body:
Java8 <s>38</s> 19 + <s>287</s> <s>295</s> <s>253</s> <s>248</s> 241 = <s>325</s> <s>333</s> <s>272</s> <s>267</s> 260 bytes

BigInteger B(int i){return new BigInteger(""+i);}int c(int...k){int n=k[0];for(k[0]=1;n>1&!java.util.stream.IntStream.range(0,n).filter(i->B(n).gcd(B(i)).equals(B(1))).allMatch(x->B(x).modPow(B(k[0]),B(n)).equals(B(1)));k[0]++);return k[0];}

Imports, 19 bytes

import java.math.*;

Explanation

It is a straight forward implementation. The co-primes are calculated in the Set p and every one's kth power is used to check if it equals 1 modulo n.

I had to use BigInteger because of precision issues.

Usage

public static void main(String[] args) {
    Carmichael c = new Carmichael();
    System.out.println(c.c(3)); // prints 2
}

Ungolfed

// returns the BigInteger representation of the given interger
BigInteger B(int i) {
    return new BigInteger(""+i);
}
// for a given integer it returns the result of the carmichael function again as interger
// so the return value cannot be larger
int c(int... k) {
    int n = k[0];
    // iterate k[0] until for all co-primes this is true: (x^n) mod n == 1, if n==1 skip the loop
    for (k[0]=1;n > 1 && !java.util.stream.IntStream.range(0, n)
                .filter(i -> B(n).gcd(B(i)).equals(B(1)))
                .allMatch(x -> B((int) x).modPow(B(k[0]), B(n)).equals(B(1)));k[0]++);
    return k[0];
}

Any suggestions to golf it more are welcome :-)

Update

No elements outside the functions that keep the state

Followed Olivier Grégoire's advice and saved 1 byte from B()

Removed the k() method and p (co-primes) Set.

Removed not required casting to int.

Added varags and use for instead of while.


问:
Close-Knit Words

Introduction

According to Rand Al'Thor's post in the Puzzling SE, a close-knit word is any word that contains three alphabetically consecutive letters (in any order).

Words like education, foghorn and cabaret are all considered close-knit words whereas words like learning, klaxon and perform are not close-knit words.

Challenge

The challenge is to code-golf a program capable of taking a single word as input (assumed lower case, for all intents and purposes) and to return output that (if available) lists all consecutive letter sets (also in lower case) if it is a close-knit word, and empty output if it is not a close-knit word.

Examples

```<code>Input: education
Output: cde

Input: foghorn
Output: fgh

Input: cabaret
Output: abc

Input: hijacking
Output: ghi, hij, ijk

Input: pneumonia
Output: mno, nop

Input: klaxon
Output: <<no output>>

Input: perform
Output: <<no output>>

Input: learning
Output: <<no output>>
</code>```

Rules

Whereas input is to be assumed to be a single lower-case word and output must be lower-case, the nature of the output will vary according to the choice of your coding language. Please select a form of output that will best suit the nature of the challenge, whether it be STDOUT, file output, array, etc.

Because this is code-golf, it will be a case of lowest number of bytes being the clear winner.

No silly loopholes.

I will not accept answers that have the consecutive letters in non-alphabetical order... So cab will not be deemed a suitable output for cabaret, for example.

Special note, while the "triplets" don't necessarily have to be in alphabetical order, but the characters within the triplets must be... so in the case of the word "performance", for example, the output mno,nop will be accepted, as will nop,mno. In the case of the word "hijacking", there are six ways that the triplets of ghi, hij and ijk could be arranged in a list, and all six permutations are acceptable as output.

Other than that, on your marks, get set, golf!

答:
Pyth - <s>11</s> <s>10</s> <s>8</s> 7 bytes

Super brute force method.

```<code>@^z3.:G
</code>```

Test Suite.

```<code>@            Setwise intersection, finds common strings between the two lists
 ^           Cartesian product
  z          Input
  3          Of length 3
 .:          Substrings. Without second input finds all substrings which is ok
  G          Lowercase aphabet
</code>```

ContentLicense: CC BY-SA 3.0

Title: Close-Knit Words

Body:
Pyth - <s>11</s> <s>10</s> <s>8</s> 7 bytes

Super brute force method.

@^z3.:G

Test Suite.

@            Setwise intersection, finds common strings between the two lists
 ^           Cartesian product
  z          Input
  3          Of length 3
 .:          Substrings. Without second input finds all substrings which is ok
  G          Lowercase aphabet


答:
MATL, 13 bytes

```<code>2Y23YCtjmAZ)!
</code>```

Try it online!

```<code>2Y2    % Push string of lowercase alphabet
3YC    % 2D char array with sliding blocks of size 3, each on a column
t      % Duplicate
j      % Take input
m      % Member function: true for elements of the 2D array that are in the input
A      % All: true for columns that consist of all true values
Z)     % Use as logical index into the columns of the 2D char array
!      % Transpose. Implicitly display
</code>```

Title: Close-Knit Words

Body:
Introduction

According to Rand Al'Thor's post in the Puzzling SE, a close-knit word is any word that contains three alphabetically consecutive letters (in any order).

Words like education, foghorn and cabaret are all considered close-knit words whereas words like learning, klaxon and perform are not close-knit words.

Challenge

The challenge is to code-golf a program capable of taking a single word as input (assumed lower case, for all intents and purposes) and to return output that (if available) lists all consecutive letter sets (also in lower case) if it is a close-knit word, and empty output if it is not a close-knit word.

Examples

```<code>Input: education
Output: cde

Input: foghorn
Output: fgh

Input: cabaret
Output: abc

Input: hijacking
Output: ghi, hij, ijk

Input: pneumonia
Output: mno, nop

Input: klaxon
Output: <<no output>>

Input: perform
Output: <<no output>>

Input: learning
Output: <<no output>>
</code>```

Rules

Whereas input is to be assumed to be a single lower-case word and output must be lower-case, the nature of the output will vary according to the choice of your coding language. Please select a form of output that will best suit the nature of the challenge, whether it be STDOUT, file output, array, etc.

Because this is code-golf, it will be a case of lowest number of bytes being the clear winner.

No silly loopholes.

I will not accept answers that have the consecutive letters in non-alphabetical order... So cab will not be deemed a suitable output for cabaret, for example.

Special note, while the "triplets" don't necessarily have to be in alphabetical order, but the characters within the triplets must be... so in the case of the word "performance", for example, the output mno,nop will be accepted, as will nop,mno. In the case of the word "hijacking", there are six ways that the triplets of ghi, hij and ijk could be arranged in a list, and all six permutations are acceptable as output.

Other than that, on your marks, get set, golf!

Body:
MATL, 13 bytes

2Y23YCtjmAZ)!

Try it online!

2Y2    % Push string of lowercase alphabet
3YC    % 2D char array with sliding blocks of size 3, each on a column
t      % Duplicate
j      % Take input
m      % Member function: true for elements of the 2D array that are in the input
A      % All: true for columns that consist of all true values
Z)     % Use as logical index into the columns of the 2D char array
!      % Transpose. Implicitly display


答:
Haskell, <s>63</s> <s>60</s> 52 bytes

```<code>f w=[x|x<-take 3<$>scanr(:)"_"['a'..],all(`elem`w)x]
</code>```

Usage example: f "hijacking" -> ["ghi","hij","ijk"].

scanr(:)"_"['a'..] builds a list with the tails of the list of all unicode chars starting with 'a' and lets it end with a '_', i.e. ["abcde...\1114111_", "bcde...\1114111_", "cde...\1114111_", ..., "\1114109\1114110\1114111_", "\1114110\1114111_", "\1114111_", "_"]. Then we take up to three chars of each string and bind it to x. Keep all x where every letter of it is in the input parameter w.

Edit: @xnor saved <s>3</s> 7 bytes. Thanks!

Title: Close-Knit Words

Body:
Haskell, <s>63</s> <s>60</s> 52 bytes

f w=[x|x<-take 3<$>scanr(:)"_"['a'..],all(`elem`w)x]

Usage example: f "hijacking" -> ["ghi","hij","ijk"].

scanr(:)"_"['a'..] builds a list with the tails of the list of all unicode chars starting with 'a' and lets it end with a '_', i.e. ["abcde...\1114111_", "bcde...\1114111_", "cde...\1114111_", ..., "\1114109\1114110\1114111_", "\1114110\1114111_", "\1114111_", "_"]. Then we take up to three chars of each string and bind it to x. Keep all x where every letter of it is in the input parameter w.

Edit: @xnor saved <s>3</s> 7 bytes. Thanks!


答:
JavaScript (ES6), <s>95</s> 90 bytes

f=
s=>[...s].map(c=>a[parseInt(c,36)]=c,a=[])&&a.map((c,i)=>c+a[i+1]+a[i+2]).filter(c=>!c[3])
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input oninput="o.textContent=f(this.value).join`, `"><div id=o></code>```

Missing values concatenate as undefined, so the resulting string contains greater than 3 characters. I borrowed the !c[3] trick from @ETHproductions to save 5 bytes.

Title: Close-Knit Words

Body:
JavaScript (ES6), <s>95</s> 90 bytes

f=
s=>[...s].map(c=>a[parseInt(c,36)]=c,a=[])&&a.map((c,i)=>c+a[i+1]+a[i+2]).filter(c=>!c[3])
;

<input oninput="o.textContent=f(this.value).join`, `"><div id=o>

Missing values concatenate as undefined, so the resulting string contains greater than 3 characters. I borrowed the !c[3] trick from @ETHproductions to save 5 bytes.


答:
Haskell, 48 bytes

f w=filter(all(`elem`w))[take 3[c..]|c<-['a'..]]
```

<p>Generates all triples of three consecutive characters, takes those that use only letters in the input.</p>

<hr>

<p><strong>53 bytes:</strong></p>

```f w=filter(all(`elem`w))[[pred$pred c..c]|c<-['c'..]]
```

The list ['c'..] contains all unicode characters from 'c' onward. The list comprehension [[pred$pred c..c]|c<-['c'..]] turns them into all strings of 3 consecutive characters from "abc" onward. We step backwards with [pred$pred c..c] instead of forwards with [c..succ$succ c] to avoid an error when taking the successor of the highest unicode character.

These triples are filtered for those that only use letters in the input.

Title: Close-Knit Words

Body:
Haskell, 48 bytes

f w=filter(all(`elem`w))[take 3[c..]|c<-['a'..]]

Generates all triples of three consecutive characters, takes those that use only letters in the input.

53 bytes:

f w=filter(all(`elem`w))[[pred$pred c..c]|c<-['c'..]]

The list ['c'..] contains all unicode characters from 'c' onward. The list comprehension [[pred$pred c..c]|c<-['c'..]] turns them into all strings of 3 consecutive characters from "abc" onward. We step backwards with [pred$pred c..c] instead of forwards with [c..succ$succ c] to avoid an error when taking the successor of the highest unicode character.

These triples are filtered for those that only use letters in the input.


答:
Python 3.5, <s>114</s> <s>111</s> <s>88</s> <s>80</s> 79 bytes:

```<code>lambda X,W=[*map(chr,range(65,91))]:[i*({*X}>={*i})for i in zip(W,W[1:],W[2:])]
</code>```

An anonymous lambda function. Takes input as an uppercase string and outputs an array of tuples, with the ones filled with three uppercase characters representing all sets of 3 consecutive letters that appear in the input. For example,

```<code>[(), (), (), (), (), (), ('G', 'H', 'I'), ('H', 'I', 'J'), ('I', 'J', 'K'), (), (), (), (), (), (), (), (), (), (), (), (), (), ()]
</code>```

would be the output for input HIJACKING. This output format has been confirmed to be okay by OP. So has the only uppercase input format. However, if you want to input in only lowercase, simply replace range(65,91) with range(97,123), adding one more byte.

Repl.it with all Test Cases!

Explanation:

Basically what is happening here is:

A list, W, is created using W=[*map(chr,range(65,91))], which contains all the uppercase letters in the English alphabet. Because of this, an uppercase input is always required.

For each tuple, i, in a list, which we will call U, containing all three consecutive letter tuples, i.e.:

```<code>U=[('A','B','C'),('B','C','D'),('C','D','E'),...]
</code>```

created by zip(W,W[1:],W[2:]), each i is fully added to the output list as long as all elements in the set version of i ({*i}) are in the set version of input X ({*X}), i.e. {*X}>={*i}, i.e. X is a superset of i. Otherwise, the empty version of i (()) is added to the list.

Once all the tuples have been gone through with the matches fully added, the list is returned as the final output.

Title: Close-Knit Words

Body:
Python 3.5, <s>114</s> <s>111</s> <s>88</s> <s>80</s> 79 bytes:

lambda X,W=[*map(chr,range(65,91))]:[i*({*X}>={*i})for i in zip(W,W[1:],W[2:])]

An anonymous lambda function. Takes input as an uppercase string and outputs an array of tuples, with the ones filled with three uppercase characters representing all sets of 3 consecutive letters that appear in the input. For example,

[(), (), (), (), (), (), ('G', 'H', 'I'), ('H', 'I', 'J'), ('I', 'J', 'K'), (), (), (), (), (), (), (), (), (), (), (), (), (), ()]

would be the output for input HIJACKING. This output format has been confirmed to be okay by OP. So has the only uppercase input format. However, if you want to input in only lowercase, simply replace range(65,91) with range(97,123), adding one more byte.

Repl.it with all Test Cases!

Explanation:

Basically what is happening here is:

A list, W, is created using W=[*map(chr,range(65,91))], which contains all the uppercase letters in the English alphabet. Because of this, an uppercase input is always required.

For each tuple, i, in a list, which we will call U, containing all three consecutive letter tuples, i.e.:

U=[('A','B','C'),('B','C','D'),('C','D','E'),...]

created by zip(W,W[1:],W[2:]), each i is fully added to the output list as long as all elements in the set version of i ({*i}) are in the set version of input X ({*X}), i.e. {*X}>={*i}, i.e. X is a superset of i. Otherwise, the empty version of i (()) is added to the list.

Once all the tuples have been gone through with the matches fully added, the list is returned as the final output.


问:
Connect the pixels
Given a text like this:

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

Output the same text but by connecting the pixels with the characters ─│┌┐└┘├┤┬┴┼. If a pixel doesn't have any neighbours, don't change it.

So the output of the last text is:

```<code>│ ─┬── ┌─ │
└─ │  ┌┘  │
   └──┘  ─┘
</code>```

You can take input as a boolean array.

The input will always contain at least 1 pixel.

You can count box-drawing chars as 1 byte.

You can assume the input is padded with spaces.

Test cases

```<code>## #
=>
── #
</code>```

```<code>###
 #
=>
─┬─
 │
</code>```

```<code>##### ##
 # #  #
########
=>
─┬─┬─ ┌─
 │ │  │
─┴─┴──┴─
</code>```

```<code> # #
#####
 # #
=>
 │ │
─┼─┼─
 │ │
</code>```

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

```<code>#####
#####
#####
#####
#####
=>
┌┬┬┬┐
├┼┼┼┤
├┼┼┼┤
├┼┼┼┤
└┴┴┴┘
</code>```

Since this is code-golf, the shortest code wins.

答:
Python 2.7, <s>318</s> 315 bytes (<s>270</s> 267 chars)

I'm sure this can be golfed further (particularly I'd love to get rid of that annoying first-line comment) but here's my entry:

```<code>#encoding:utf-8
f=lambda t:(lambda l,s:'\n'.join(''.join((u'┼├┤│┬┌┐│┴└┘│───#'[(s==l[i][j-1])+2*(s==l[i][j+1])+4*(i<1 or s==l[i-1][j])+8*(i>len(l)-2 or s==l[i+1][j])],s)[s==l[i][j]]for j in range(len(l[i])-1))for i in range(len(l))))([l+' 'for l in t.split('\n')],' ')
</code>```

Here's an explanation of how the whole thing works:

#encoding:utf-8 # Dammit, Python. This adds an extra 16 bytes!
f=lambda t:( # main lambda function
    lambda l,s: # inner lambda so we can pass it "local constants" (see last line)
        '\n'.join( # join each line
            ''.join( # join each char within the line
                (u'┼├┤│┬┌┐│┴└┘│───#'[ # string of all possible characters, indexed by binary 0-15 based on adjacent chars
                    (s==l[i][j-1])+ # left
                    2*(s==l[i][j+1])+ # right
                    4*(i<1 or s==l[i-1][j])+ # up ('i<1' just yields zero in case this is the first line, so that we don't get index problems)
                    8*(i>len(l)-2 or s==l[i+1][j])], # down ('i>len(l)-2' is same as above)
                s)[s==l[i][j]] # if original is space, choose space, else choose the previously chosen box-drawing char
                for j in range(len(l[i])-1)) # do this process for each char (excluding last, which is a space)
            for i in range(len(l))) # do this for each line
    )([l+' ' for l in t.split('\n')],' ') # call the inner lambda with two parameters: first, the text split into lines; second, a space char (actually makes code shorter)
```

EDIT: Removed some spaces before for ... in ...

Title: Connect the pixels

Body:
Python 2.7, <s>318</s> 315 bytes (<s>270</s> 267 chars)

I'm sure this can be golfed further (particularly I'd love to get rid of that annoying first-line comment) but here's my entry:

#encoding:utf-8
f=lambda t:(lambda l,s:'\n'.join(''.join((u'┼├┤│┬┌┐│┴└┘│───#'[(s==l[i][j-1])+2*(s==l[i][j+1])+4*(i<1 or s==l[i-1][j])+8*(i>len(l)-2 or s==l[i+1][j])],s)[s==l[i][j]]for j in range(len(l[i])-1))for i in range(len(l))))([l+' 'for l in t.split('\n')],' ')

Here's an explanation of how the whole thing works:

#encoding:utf-8 # Dammit, Python. This adds an extra 16 bytes!
f=lambda t:( # main lambda function
    lambda l,s: # inner lambda so we can pass it "local constants" (see last line)
        '\n'.join( # join each line
            ''.join( # join each char within the line
                (u'┼├┤│┬┌┐│┴└┘│───#'[ # string of all possible characters, indexed by binary 0-15 based on adjacent chars
                    (s==l[i][j-1])+ # left
                    2*(s==l[i][j+1])+ # right
                    4*(i<1 or s==l[i-1][j])+ # up ('i<1' just yields zero in case this is the first line, so that we don't get index problems)
                    8*(i>len(l)-2 or s==l[i+1][j])], # down ('i>len(l)-2' is same as above)
                s)[s==l[i][j]] # if original is space, choose space, else choose the previously chosen box-drawing char
                for j in range(len(l[i])-1)) # do this process for each char (excluding last, which is a space)
            for i in range(len(l))) # do this for each line
    )([l+' ' for l in t.split('\n')],' ') # call the inner lambda with two parameters: first, the text split into lines; second, a space char (actually makes code shorter)

EDIT: Removed some spaces before for ... in ...


答:
Jelly, 7 bytes

```<code>ØaẆfṗ3$
</code>```

This is a monadic link. Try it online!

How it works

```<code>ØaẆfṗ3$  Monadic link. Argument: s (string)

Øa       Yield the lowercase alphabet, i.e., a := "abcdefghijklmnopqrstuvwxyz".
  Ẇ      Window; yields all substrings of a.
      $  Combine the two links to the left into a monadic chain.
    ṗ3   Take the third Cartesian power of s, yielding all combinations of three
         characters that can be formed from the letters in s.
   f     Filter; keep only those substrings of a that appear in the Cart. power.
</code>```

Title: Close-Knit Words

Body:
Jelly, 7 bytes

ØaẆfṗ3$

This is a monadic link. Try it online!

How it works

ØaẆfṗ3$  Monadic link. Argument: s (string)

Øa       Yield the lowercase alphabet, i.e., a := "abcdefghijklmnopqrstuvwxyz".
  Ẇ      Window; yields all substrings of a.
      $  Combine the two links to the left into a monadic chain.
    ṗ3   Take the third Cartesian power of s, yielding all combinations of three
         characters that can be formed from the letters in s.
   f     Filter; keep only those substrings of a that appear in the Cart. power.


问:
Draw an ASCII Rectangle
Given two integers as input in an array, draw a rectangle, using the first integer as width and second as height.

Or, if your language supports it, the two integers can be given as separate inputs.

Assume the width and height will never be less than 3, and they will always be given.

Example Outputs:

[3, 3]

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

[5, 8]

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

[10, 3]

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

This is code-golf, so the answer with the lowest amount of bytes wins.

答:
Jolf, 6 bytes

```<code>,ajJ'|
</code>```

Try it here! My box builtin finally came in handy! :D

```<code>,ajJ'|
,a       draw a box
  j      with width (input 1)
   J     and height (input 2)
    '    with options
     |    - corner
          - the rest are defaults
</code>```

Title: Draw an ASCII Rectangle

Body:
Jolf, 6 bytes

,ajJ'|

Try it here! My box builtin finally came in handy! :D

,ajJ'|
,a       draw a box
  j      with width (input 1)
   J     and height (input 2)
    '    with options
     |    - corner
          - the rest are defaults


答:
PHP, 100 bytes

```<code>for($a="abc",$i=98;$i<123;$a=substr($a,1).chr(++$i))if(strstr(count_chars($argv[1],3),$a))echo"$a,";
</code>```

takes input as command line argument; prints a trailing comma. run with -r.

Title: Close-Knit Words

Body:
PHP, 100 bytes

for($a="abc",$i=98;$i<123;$a=substr($a,1).chr(++$i))if(strstr(count_chars($argv[1],3),$a))echo"$a,";

takes input as command line argument; prints a trailing comma. run with -r.


答:
Python 3.5, 78 bytes

s={*input()}
for c in s:o=ord(c);a=chr(o-2);b=chr(o-1);s>{a,b}and print(a+b+c)
```

Title: Close-Knit Words


答:
F#, 131 bytes

```<code>let d x y=
 let q = String.replicate (x-2)
 [for r in [1..y] do printfn "%s%s%s" "|" (if r=y||r=1 then(q "-")else(q " ")) "|"]
</code>```

Title: Draw an ASCII Rectangle

Body:
Given two integers as input in an array, draw a rectangle, using the first integer as width and second as height.

Or, if your language supports it, the two integers can be given as separate inputs.

Assume the width and height will never be less than 3, and they will always be given.

Example Outputs:

[3, 3]

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

[5, 8]

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

[10, 3]

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

This is code-golf, so the answer with the lowest amount of bytes wins.

Body:
F#, 131 bytes

let d x y=
 let q = String.replicate (x-2)
 [for r in [1..y] do printfn "%s%s%s" "|" (if r=y||r=1 then(q "-")else(q " ")) "|"]


问:
Mutilating the Query
I know you've always thought about the trials and tribulations of experiencing the joys of life as a web proxy. Honestly, who hasn't? Today you're tasked with realizing this goal (at least a part of it). Website X gets a lot of traffic on the daily and is looking for a PaaS (clearly this refers to Proxy as a Service) because of the large number of users who insist on passing sensitive information via query parameters (users are silly). Your task is to remove any and all sensitive query parameters from the request before forwarding the request through to its original destination.

Input

A well-formed absolute HTTP URL that follows the URI grammar in RFC3986 Section 3.

You can assume there is no fragment

Brief format example where anything in square brackets denotes optional: http[s]://[user:pass@]host.name.com[:port]/[?param1=value1&param2=value2...]

A list of query parameters to be removed.

Output

The modified HTTP URL without the parameters defined in the input list.

Examples

```<code>http://example.com/ [foo]
> http://example.com/

http://example.com/?foo=bar []
> http://example.com/?foo=bar

http://example.com/ []
> http://example.com/

http://example.com/?foo=1&bar=2&baz=3 [foo,baz]
> http://example.com/?bar=2

http://example.com/?foo=1&bar=2&baz=3 [foo,bar,baz]
> http://example.com/

http://example.com/?foo&bar=2&baz= [foo,baz]
> http://example.com/?bar=2

http://example.com/?abc=1&def=2&baz=foo [foo,bar]
> http://example.com/?abc=1&def=2&baz=foo

http://example.com/?foobar=baz [foo]
> http://example.com/?foobar=baz

http://foo:foo@foo.com:8080/?foo=1&bar=foo [foo]
> http://foo:foo@foo.com:8080/?bar=foo
</code>```

Scoring

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

答:
Java 7, 203 bytes

String f(String u,List p)throws Exception{String[]g=u.split("\\?",2);String s="";if(g.length>1)for(String q:g[1].split("&")){if(p.indexOf(q.split("=")[0])<0){s+=s.isEmpty()?"?":"&";s+=q;}}return g[0]+s;}
```

<p>Ungolfed:</p>

<pre class="lang-java prettyprint-override"><code>  String f(String u, List p) throws Exception {
    String[] g = u.split("\\?", 2);
    String s = "";
    if (g.length > 1) for (String q : g[1].split("&")) {
      if (p.indexOf(q.split("=")[0]) < 0) {
        s += s.isEmpty() ? "?" : "&";
        s += q;
      }
    }
    return g[0] + s;
  }
</code>```

This function passes all of the tests.

Title: Mutilating the Query

Body:
Java 7, 203 bytes

String f(String u,List p)throws Exception{String[]g=u.split("\\?",2);String s="";if(g.length>1)for(String q:g[1].split("&")){if(p.indexOf(q.split("=")[0])<0){s+=s.isEmpty()?"?":"&";s+=q;}}return g[0]+s;}

Ungolfed:

  String f(String u, List p) throws Exception {
    String[] g = u.split("\\?", 2);
    String s = "";
    if (g.length > 1) for (String q : g[1].split("&")) {
      if (p.indexOf(q.split("=")[0]) < 0) {
        s += s.isEmpty() ? "?" : "&";
        s += q;
      }
    }
    return g[0] + s;
  }

This function passes all of the tests.


答:
Python 3.5, 68 bytes

w=input()
a=0
while 1:s='%c'*3%(a,a+1,a+2);a+=1;{*s}-{*w}or print(s)
```

Prints output strings, and terminates with error when the character value gets too large.

Generates all strings of three consecutive and prints those that are a subset of the input word.

Title: Close-Knit Words

Body:
Python 3.5, 68 bytes

w=input()
a=0
while 1:s='%c'*3%(a,a+1,a+2);a+=1;{*s}-{*w}or print(s)

Prints output strings, and terminates with error when the character value gets too large.

Generates all strings of three consecutive and prints those that are a subset of the input word.


答:
Ruby, <s>146 140 127 119 116</s> 113 bytes

edit 2: saved 6 bytes by using $1, $2, and $*,  and 7 by changing x.split("=")[0] to x[/\w+/]

edit 3: saved 6 bytes by using * instead of .join, saved 2 bytes from unnecessary spaces

edit 4: saved 3 bytes by reformulating inline (changed regex to equivalent $*[1][/([^?]*)\??(.*)/,1] and put as assigned to a)

edit 5: saved 3 bytes by using ($*[2].scan(r=/\w+/)&[x[r]])[0] instead of $*[2].scan(r=/\w+/).include?(x[r])

Assuming input to the program when running it:

```<code>a,b=$*[1][/([^?]*)\??(.*)/,1],$2.split("&").reject{|x|($*[2].scan(r=/\w+/)&[x[r]])[0]}*"&"
puts(b[0] ?a+"?"+b: a)
</code>```

Explanation

```<code>a,b=$*[1][/([^?]*)\??(.*)/,1],$2.split("&")
</code>```

This parses the URL given on the command line, and stores the matches into $1 and $2.  $*[1][/([^?]*)\??(.*)/,1] also returns the first match to store inside a, while the second match is referred to as $2
let a point to $1, and parse b into an array of arrays...

```<code>.reject { |x|
</code>```

...rejecting all that...

```<code>    ($*[2].scan(r=/\w+/)&[x[r]])[0]
</code>```

...have a string before the '=' that is included in the list of names given by the second parameter...
This works because we scan for words (to get the list) then get the word before the =, and see if that word is in the list with &.  Since & returns an empty array on "not found" (the null set), we use the trick explained below to get nil if there are no elements in the array.  otherwise we return a string, which counts as truthy, which rejects that string.

```<code>}*"&"
</code>```

...and join the remaining strings together with '&'

At this point, b is the GET query string for the URL.  Thus, we just need to print it.

```<code>puts(b[0] ?a+"?"+b: a)
</code>```

This uses a trick in ruby.  b[0] will be nil if b is an empty array or string.   So if its truthy, (not nil or false), then there's at least one element in the array, so we need to puts a+"?"+b for the correct URL.  otherwise, we just puts a, because there are no parameters to show

Note: this answer assumes that ? cannot appear anywhere except to delimit the URL from the query. (according to what I read from the linked RFC)

Also, this is my first golf answer :D

Title: Mutilating the Query

Body:
I know you've always thought about the trials and tribulations of experiencing the joys of life as a web proxy. Honestly, who hasn't? Today you're tasked with realizing this goal (at least a part of it). Website X gets a lot of traffic on the daily and is looking for a PaaS (clearly this refers to Proxy as a Service) because of the large number of users who insist on passing sensitive information via query parameters (users are silly). Your task is to remove any and all sensitive query parameters from the request before forwarding the request through to its original destination.

Input

A well-formed absolute HTTP URL that follows the URI grammar in RFC3986 Section 3.

You can assume there is no fragment

Brief format example where anything in square brackets denotes optional: http[s]://[user:pass@]host.name.com[:port]/[?param1=value1&param2=value2...]

A list of query parameters to be removed.

Output

The modified HTTP URL without the parameters defined in the input list.

Examples

```<code>http://example.com/ [foo]
> http://example.com/

http://example.com/?foo=bar []
> http://example.com/?foo=bar

http://example.com/ []
> http://example.com/

http://example.com/?foo=1&bar=2&baz=3 [foo,baz]
> http://example.com/?bar=2

http://example.com/?foo=1&bar=2&baz=3 [foo,bar,baz]
> http://example.com/

http://example.com/?foo&bar=2&baz= [foo,baz]
> http://example.com/?bar=2

http://example.com/?abc=1&def=2&baz=foo [foo,bar]
> http://example.com/?abc=1&def=2&baz=foo

http://example.com/?foobar=baz [foo]
> http://example.com/?foobar=baz

http://foo:foo@foo.com:8080/?foo=1&bar=foo [foo]
> http://foo:foo@foo.com:8080/?bar=foo
</code>```

Scoring

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

Body:
Ruby, <s>146 140 127 119 116</s> 113 bytes

edit 2: saved 6 bytes by using $1, $2, and $*,  and 7 by changing x.split("=")[0] to x[/\w+/]

edit 3: saved 6 bytes by using * instead of .join, saved 2 bytes from unnecessary spaces

edit 4: saved 3 bytes by reformulating inline (changed regex to equivalent $*[1][/([^?]*)\??(.*)/,1] and put as assigned to a)

edit 5: saved 3 bytes by using ($*[2].scan(r=/\w+/)&[x[r]])[0] instead of $*[2].scan(r=/\w+/).include?(x[r])

Assuming input to the program when running it:

a,b=$*[1][/([^?]*)\??(.*)/,1],$2.split("&").reject{|x|($*[2].scan(r=/\w+/)&[x[r]])[0]}*"&"
puts(b[0] ?a+"?"+b: a)

Explanation

a,b=$*[1][/([^?]*)\??(.*)/,1],$2.split("&")

This parses the URL given on the command line, and stores the matches into $1 and $2.  $*[1][/([^?]*)\??(.*)/,1] also returns the first match to store inside a, while the second match is referred to as $2
let a point to $1, and parse b into an array of arrays...

.reject { |x|

...rejecting all that...

    ($*[2].scan(r=/\w+/)&[x[r]])[0]

...have a string before the '=' that is included in the list of names given by the second parameter...
This works because we scan for words (to get the list) then get the word before the =, and see if that word is in the list with &.  Since & returns an empty array on "not found" (the null set), we use the trick explained below to get nil if there are no elements in the array.  otherwise we return a string, which counts as truthy, which rejects that string.

}*"&"

...and join the remaining strings together with '&'

At this point, b is the GET query string for the URL.  Thus, we just need to print it.

puts(b[0] ?a+"?"+b: a)

This uses a trick in ruby.  b[0] will be nil if b is an empty array or string.   So if its truthy, (not nil or false), then there's at least one element in the array, so we need to puts a+"?"+b for the correct URL.  otherwise, we just puts a, because there are no parameters to show

Note: this answer assumes that ? cannot appear anywhere except to delimit the URL from the query. (according to what I read from the linked RFC)

Also, this is my first golf answer :D


答:
Retina, <s>44</s> 48 bytes

Crossed-out 44 is still 44. Thanks to Martin for the fix.

```<code>[?&](?>([^ =&]+))[^ &]*(?=.* \1( |$))| .*

/&
/?
</code>```

Takes input like uri param1 param2. Try it online!

Explanation

The first replacement deletes the appropriate parameters from the query string. [?&](?>([^ =&+))[^ &]* matches a ? or &, a full parameter name, and (optionally) = and a value, storing the parameter name in capture group 1. Then (?=.* \1( |$)) is a lookahead that checks whether that parameter name appears in the list of parameters to delete. If a parameter matches these conditions, it is removed (substituted with an empty replacement).

Substitutions are non-overlapping (thanks to the lookahead) and proceed from left to right. On reaching the end of the URL, the  .* branch matches the list of parameters to delete and removes it as well.

The second replacement just makes sure the new query string starts with ? if the first parameter was deleted.

Title: Mutilating the Query

Body:
Retina, <s>44</s> 48 bytes

Crossed-out 44 is still 44. Thanks to Martin for the fix.

[?&](?>([^ =&]+))[^ &]*(?=.* \1( |$))| .*

/&
/?

Takes input like uri param1 param2. Try it online!

Explanation

The first replacement deletes the appropriate parameters from the query string. [?&](?>([^ =&+))[^ &]* matches a ? or &, a full parameter name, and (optionally) = and a value, storing the parameter name in capture group 1. Then (?=.* \1( |$)) is a lookahead that checks whether that parameter name appears in the list of parameters to delete. If a parameter matches these conditions, it is removed (substituted with an empty replacement).

Substitutions are non-overlapping (thanks to the lookahead) and proceed from left to right. On reaching the end of the URL, the  .* branch matches the list of parameters to delete and removes it as well.

The second replacement just makes sure the new query string starts with ? if the first parameter was deleted.


问:
Compact a Befunge program
Befunge is a 2-dimensional esoteric programming language. The basic idea is that (one-character) commands are placed on a 2-dimensional grid. Control flow walks across the grid, executing commands it passes over, and changing direction when it hits an arrow (>^<v). Commands are stack-based; see this list. See also http://esolangs.org/wiki/Befunge.

The specification for Befunge-98 is available.

Problem

Write a program that transforms a Befunge program into a more compact representation. For example, the following program prints 0:

```<code>>   0   v

>   @   .

^       <
</code>```

In this case, it could be compacted without changing the program's behavior by removing rows of spaces, to give

```<code>>0v
>@.
^ <
</code>```

More sophisticated transformations could rotate or mirror sequences of commands and eliminate unnecessary control-flow commands in order to compact the program. For example, with this program:

```<code>>12345v
      6
v....7<
.
.
.
@
</code>```

you might tuck the end of the program into the hole:

```<code>>12345v
>...@ 6
^....7<
</code>```

For the first example, the most compact program possible is

```<code>>0.@
</code>```

You may use any transformations as long as the output program gives the same result.

Input programs

Input programs are valid Befunge-98 programs.

You may assume that the input program is deterministic. That is, it does not use commands that read external state: the user input commands & and ~, the randomizer ?, and the self-modifying code commands p and g.

You may assume the input program terminates.

Scoring

This is not a code golf, but a problem to write a program that performs code golfing.

The input is a set of test cases (Befunge programs that satisfy the input restrictions above). The total score is the sum of the scores for the test cases.

Score for each test case

The score is the area of the convex hull of the non-empty cells in the output program, where each cell is treated as a square whose four corners are lattice points in the Cartesian plane. For example, a program of

```<code>>   v
 @  <
</code>```

gets a score of 9.5.

If your program does not terminate in a reasonable amount of time and memory on a particular input, the score is that of the input program. (This is because you could trivially add a time-limiting wrapper that outputs the input program unchanged if your program doesn't terminate in time.)

If the test-case program has a different result (or fails to terminate) after processing with your program, the score is the score of the input program plus a penalty of 100 points.

答:
Sed, 5 chars

So, even if this is not codegolf, here's a solution that will have a rather good codelength to score ratio, but not necessarily a good score.

```<code>/^$/d
</code>```

It simply removes blank lines.

Title: Compact a Befunge program

Body:
Sed, 5 chars

So, even if this is not codegolf, here's a solution that will have a rather good codelength to score ratio, but not necessarily a good score.

/^$/d

It simply removes blank lines.


答:
Ruby, <s>101</s> <s>86</s> <s>91</s> 90 bytes

A Ruby port of my Actually answer. Golfing suggestions welcome.

Edit: -4 bytes from removing a but +9 bytes from fixing a bug where 1 returned nil. -1 byte thanks to Cyoce.

require'prime'
->n{((n%8<1?n/2:n).prime_division<<[2,1]).map{|x,y|x**~-y*~-x}.reduce :lcm}
```

<p><strong>Ungolfing</strong></p>

<pre class="lang-ruby prettyprint-override"><code>require 'prime'
def carmichael(n)
  if n%8 < 1
    n /= 2
  end
  a = []
  n.prime_division.do each |x,y|
    a << x**(y-1)*(x-1)
  end
  return a.reduce :lcm
end
</code>```

Title: Compute the Carmichael function

Body:
Task description

In number theory, the Carmichael function λ takes a positive integer n and returns the least positive integer k so that the k-th power of each integer coprime to n equals 1 modulo n.

Given a positive integer n, your solution must compute λ(n). The shortest code in bytes wins.

Your program should theoretically work for arbitrarily large inputs, but doesn’t need to be efficient.

Tips

The sequence of all λ(n) is OEIS A002322.

An ungolfed Python implementation would look like

```<code>from fractions import gcd

def carmichael(n):
    coprimes = [x for x in range(1, n) if gcd(x, n) == 1]
    k = 1
    while not all(pow(x, k, n) == 1 for x in coprimes):
        k += 1
    return k
</code>```

(In Python, pow(A, B, C) efficiently computes pow(A, B) % C.)

Test cases

```<code>Input    Output
1        1
2        1
3        2
10       4
35       12
101      100
530      52
3010     84
6511     3056
10000    500
</code>```

Body:
Ruby, <s>101</s> <s>86</s> <s>91</s> 90 bytes

A Ruby port of my Actually answer. Golfing suggestions welcome.

Edit: -4 bytes from removing a but +9 bytes from fixing a bug where 1 returned nil. -1 byte thanks to Cyoce.

require'prime'
->n{((n%8<1?n/2:n).prime_division<<[2,1]).map{|x,y|x**~-y*~-x}.reduce :lcm}

Ungolfing

require 'prime'
def carmichael(n)
  if n%8 < 1
    n /= 2
  end
  a = []
  n.prime_division.do each |x,y|
    a << x**(y-1)*(x-1)
  end
  return a.reduce :lcm
end


答:
Python, <s>75</s> <s>81</s> 112 bytes:

```<code>def Z(A,S):import re;F=A.rindex('/');print A[:F]+re.sub('|'.join(i+'(=\d?|&)&?'for i in S),'',A[F:]).strip('&?')
</code>```

A named function. Takes input in the format

```<code>D(<String>,<Array>)
</code>```

and outputs a string.

Repl.it With All Test Cases!

Title: Mutilating the Query

Body:
Python, <s>75</s> <s>81</s> 112 bytes:

def Z(A,S):import re;F=A.rindex('/');print A[:F]+re.sub('|'.join(i+'(=\d?|&)&?'for i in S),'',A[F:]).strip('&?')

A named function. Takes input in the format

D(<String>,<Array>)

and outputs a string.

Repl.it With All Test Cases!


问:
The shortest code to invert bit-wise a binary string
Me thinks there aren't enough easy questions on here that beginners can attempt!

The challenge: Given a random input string of 1's and 0's such as:

```<code>10101110101010010100010001010110101001010
</code>```

Write the shortest code that outputs the bit-wise inverse like so:

```<code>01010001010101101011101110101001010110101
</code>```

答:
Turtlèd, 24 bytes (non-competing)

```<code>' !-[*+.(1'0r)(0'1r)_]'
</code>```

[note trailing space]

beating the non golf langs, in a task this language is not really designed for :)

Explanation

```<code>'[space]                      write space over initial square
  !                           take input into string variable
   -                          decrement the string pointer (used when writing char from string)
    [*               ]        while current cell is not *
      +.                      increment string pointer, write pointed char from string
        (1'0r)                if cell is 1, write 0, move right
              (0'1r)          if cell is 0, write 1, move right
                    _         EOF checker: if end of string var, write *, else [space]
                      '[space]write space on cell (asterisk must be here)
          [implicit]     remove trailing and leading spaces and newlines, print grid.
</code>```

ContentLicense: CC BY-SA 4.0

Body:
Turtlèd, 24 bytes (non-competing)

' !-[*+.(1'0r)(0'1r)_]'

[note trailing space]

beating the non golf langs, in a task this language is not really designed for :)

Explanation

'[space]                      write space over initial square
  !                           take input into string variable
   -                          decrement the string pointer (used when writing char from string)
    [*               ]        while current cell is not *
      +.                      increment string pointer, write pointed char from string
        (1'0r)                if cell is 1, write 0, move right
              (0'1r)          if cell is 0, write 1, move right
                    _         EOF checker: if end of string var, write *, else [space]
                      '[space]write space on cell (asterisk must be here)
          [implicit]     remove trailing and leading spaces and newlines, print grid.


Title: Connect the pixels

Body:
Given a text like this:

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

Output the same text but by connecting the pixels with the characters ─│┌┐└┘├┤┬┴┼. If a pixel doesn't have any neighbours, don't change it.

So the output of the last text is:

```<code>│ ─┬── ┌─ │
└─ │  ┌┘  │
   └──┘  ─┘
</code>```

You can take input as a boolean array.

The input will always contain at least 1 pixel.

You can count box-drawing chars as 1 byte.

You can assume the input is padded with spaces.

Test cases

```<code>## #
=>
── #
</code>```

```<code>###
 #
=>
─┬─
 │
</code>```

```<code>##### ##
 # #  #
########
=>
─┬─┬─ ┌─
 │ │  │
─┴─┴──┴─
</code>```

```<code> # #
#####
 # #
=>
 │ │
─┼─┼─
 │ │
</code>```

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

```<code>#####
#####
#####
#####
#####
=>
┌┬┬┬┐
├┼┼┼┤
├┼┼┼┤
├┼┼┼┤
└┴┴┴┘
</code>```

Since this is code-golf, the shortest code wins.

Body:
J, <s>82</s> <s>72</s> 66 bytes

(ucp' #───│┌┐┬│└┘┴│├┤┼'){~]+]*3 3((2#.1 7 3 5{,);._3)0,.~0,.0,~0,]

The input is a boolean table of 1's and 0's. The rules state that the box characters each count as one byte, not three, and that has been applied here.

Usage

   f =: (ucp' #───│┌┐┬│└┘┴│├┤┼'){~]+]*3 3((2#.1 7 3 5{,);._3)0,.~0,.0,~0,]
   m =: 1 0 1 1 1 1 0 1 1 0 1 , 1 1 0 1 0 0 1 1 0 0 1 ,: 0 0 0 1 1 1 1 0 0 1 1
   m { ' #'
# #### ## #
## #  ##  #
   ####  ##
   f m
│ ─┬── ┌─ │
└─ │  ┌┘  │
   └──┘  ─┘
   ' #' {~ m =: 5 5 $ 1
   f m
┌┬┬┬┐
├┼┼┼┤
├┼┼┼┤
├┼┼┼┤
└┴┴┴┘
   ' #' {~ m =: 5 9 $ 1 0
# # # # #
 # # # #
# # # # #
 # # # #
# # # # #
   f m
# # # # #
 # # # #
# # # # #
 # # # #
# # # # #

Explanation

First the input is padded with 0's on all sides.

   ] m =: 1 0 1 1 1 1 0 1 1 0 1 , 1 1 0 1 0 0 1 1 0 0 1 ,: 0 0 0 1 1 1 1 0 0 1 1
1 0 1 1 1 1 0 1 1 0 1
1 1 0 1 0 0 1 1 0 0 1
0 0 0 1 1 1 1 0 0 1 1
   (0,.~0,.0,~0,]) m
0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 1 1 1 1 0 1 1 0 1 0
0 1 1 0 1 0 0 1 1 0 0 1 0
0 0 0 0 1 1 1 1 0 0 1 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0

Then each subarray of size 3 is selected

   3 3 <;._3 (0,.~0,.0,~0,]) m
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│
│0 1 0│1 0 1│0 1 1│1 1 1│1 1 1│1 1 0│1 0 1│0 1 1│1 1 0│1 0 1│0 1 0│
│0 1 1│1 1 0│1 0 1│0 1 0│1 0 0│0 0 1│0 1 1│1 1 0│1 0 0│0 0 1│0 1 0│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│0 1 0│1 0 1│0 1 1│1 1 1│1 1 1│1 1 0│1 0 1│0 1 1│1 1 0│1 0 1│0 1 0│
│0 1 1│1 1 0│1 0 1│0 1 0│1 0 0│0 0 1│0 1 1│1 1 0│1 0 0│0 0 1│0 1 0│
│0 0 0│0 0 0│0 0 1│0 1 1│1 1 1│1 1 1│1 1 0│1 0 0│0 0 1│0 1 1│1 1 0│
├─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┤
│0 1 1│1 1 0│1 0 1│0 1 0│1 0 0│0 0 1│0 1 1│1 1 0│1 0 0│0 0 1│0 1 0│
│0 0 0│0 0 0│0 0 1│0 1 1│1 1 1│1 1 1│1 1 0│1 0 0│0 0 1│0 1 1│1 1 0│
│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│0 0 0│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

Then only 5 of the values in each subarray is considered

┌───┐
│xAx│
│CED│
│xBx│
└───┘

The values ABCD are selected by flattening each subarray and selecting at indices 1 7 3 5. Those values are multiplied by E which is at index 4. It is then converted from a list of binary digits to a decimal, and incremented by E. The x values are not needed.

   3 3 (4&{([+2#.*)1 7 3 5&{)@,;._3 (0,.~0,.0,~0,]) m
 5 0 2  8 4 3  0  6 3 0  5
10 3 0 13 0 0  6 11 0 0 13
 0 0 0 10 4 4 11  0 0 2 11

This is used as an index to select which character to draw according to the table below (reordered a bit for golfing). The last column matches the output value of each subarray to a box character.

 0  (space)  0
 1  #        1
 2  ┌        6
 3  ┬        8
 4  ┐        7
 5  ├        14
 6  ┼        16
 7  ┤        15
 8  └        10
 9  ┴        12
10  ┘        11
11  │        5, 9, 13
12  ─        2, 3, 4

Also, in J, the string ' #───│┌┐┬│└┘┴│├┤┼' uses 8-bit characters making it have a length of 47 (for each byte) for the 17 characters needed. The command ucp converts it to 16-bit characters which allows it to be length 17.


问:
Bake a slice of Pi
Write a program or function that prints or outputs this exact text (consisting of 142 characters):

```<code>()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|
</code>```

Your program must take no input (except in languages where this is impossible, such as sed), and produce the above text (and only the above text) as output. A trailing newline is acceptable.

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

Title: Bake a slice of Pi

Body:
Lua, 152 Bytes

print[[()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|]]

Try as I might I could not compress this pi.

Lua is just too verbose to do it, maybe a pi of greater size, but not this one.

Another solution, 186 Bytes.

s="()()()()()()\n|\\3.1415926|\n|:\\53589793|\n"i=0 for z in('2384626|433832|79502|8841|971|69|3|'):gmatch'.-|'do s=s..(' '):rep(i)..'\\::\\'..z.."\n"i=i+1 end print(s..'       \\__\\|')

Annoyingly Lua's pi isn't accurate enough to even fill the pi. :(


问:
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Turtlèd, 7 bytes

Turtlèd cannot output without halting, so the truth machine writes down infinite ones, like a turing machine's implementation might, onto the grid if input is 1.

```<code>!.{1r.}
</code>```

Explanation:

```<code>!                  input into string variable

 .                 write current char of string var (by default the first char)
                   for a single char input, this will be the entire input

  {1  }            while the current char is 1
                   this loop is never run if input is zero, but if it is one, it will run
                   forever, as the last action of the loop writes 1 to the current cell

    r              move right, so that we constantly move right to write ones to infinite
                   cells

     .             write current char of string var (still by default the first char)
                   this is 1 if the loop was run at all. because the loop runs while the
                   current cell is one, this will cause the loop to rerun every time.

       [implicit]  output grid at end of program, program will only end if input isn't 1
</code>```

Title: Implement a Truth-Machine

Body:
Turtlèd, 7 bytes

Turtlèd cannot output without halting, so the truth machine writes down infinite ones, like a turing machine's implementation might, onto the grid if input is 1.

!.{1r.}

Explanation:

!                  input into string variable

 .                 write current char of string var (by default the first char)
                   for a single char input, this will be the entire input

  {1  }            while the current char is 1
                   this loop is never run if input is zero, but if it is one, it will run
                   forever, as the last action of the loop writes 1 to the current cell

    r              move right, so that we constantly move right to write ones to infinite
                   cells

     .             write current char of string var (still by default the first char)
                   this is 1 if the loop was run at all. because the loop runs while the
                   current cell is one, this will cause the loop to rerun every time.

       [implicit]  output grid at end of program, program will only end if input isn't 1


答:
Python 3 - <s>59</s> 41 bytes

( -18 bytes thanks to @Mego)

```<code>lambda s:''.join(str(1-int(c))for c in s)
</code>```

Title: The shortest code to invert bit-wise a binary string

Body:
Me thinks there aren't enough easy questions on here that beginners can attempt!

The challenge: Given a random input string of 1's and 0's such as:

```<code>10101110101010010100010001010110101001010
</code>```

Write the shortest code that outputs the bit-wise inverse like so:

```<code>01010001010101101011101110101001010110101
</code>```

Body:
Python 3 - <s>59</s> 41 bytes

( -18 bytes thanks to @Mego)

lambda s:''.join(str(1-int(c))for c in s)


答:
Pyth, 89 bytes

```<code>J_2K+.n0."09\07´\C2\84J\01£\07Nl:?í"*"()"6Vr9Zp*dJp?!Z\|?qZ9"|:""\::"p\\p:KZ+ZN\|=+ZN=hJ)p*dJ"\__\|"
</code>```

Try it online!

Replace \xx (hexadecimal) with the corresponding ASCII character if you copy/paste the code from this answer; it contains unprintable characters in the packed string which SE filters out.

Explanation

```<code>J_2        Sets J to -2
  .n0      Pi; returns 3.141592653589793
  ."(...)" Packed string; returns "2384626433832795028841971693"
 +         Concatenation; returns "3.1415926535897932384626433832795028841971693"
K          Sets K to that string
*"()"6     Repetition; returns "()()()()()()", which is implicitly printed with a newline
 r9Z       Range; returns [9, 8, 7, 6, 5, 4, 3, 2, 1] (Z is initialized to 0)
V          Loop through r9Z, using N as the loop variable
  *dJ      Repetition; d is initialized to " " (returns an empty string if J <= 0)
 p         Print without a newline
  ?!Z      Ternary; if not Z
   \|      then return "|"
   ?qZ9    else, ternary; if Z == 9
    "|:"   then return "|:"
    "\::"  else, return "\::"
 p         Print without a newline
  \\       One-character string; returns "\"
 p         Print without a newline
  :KZ+ZN   Slice; returns K[Z:Z+N], not including K[Z+N]
 p         Print without a newline
 \|        One-character string; returns "|", which is implicitly printed with a newline.
 =+ZN      Adds N to Z
 =hJ       Increments J by 1
)          Ends loop
 *dJ       Repetition; d is initialized to " "
p          Print without a newline
"\__\|"    Returns "\__\|", which is implicitly printed with a newline
</code>```

Title: Bake a slice of Pi

Body:
Write a program or function that prints or outputs this exact text (consisting of 142 characters):

```<code>()()()()()()
|\3.1415926|
|:\53589793|
\::\2384626|
 \::\433832|
  \::\79502|
   \::\8841|
    \::\971|
     \::\69|
      \::\3|
       \__\|
</code>```

Your program must take no input (except in languages where this is impossible, such as sed), and produce the above text (and only the above text) as output. A trailing newline is acceptable.

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

Body:
Pyth, 89 bytes

J_2K+.n0."09\07´\C2\84J\01£\07Nl:?í"*"()"6Vr9Zp*dJp?!Z\|?qZ9"|:""\::"p\\p:KZ+ZN\|=+ZN=hJ)p*dJ"\__\|"

Try it online!

Replace \xx (hexadecimal) with the corresponding ASCII character if you copy/paste the code from this answer; it contains unprintable characters in the packed string which SE filters out.

Explanation

J_2        Sets J to -2
  .n0      Pi; returns 3.141592653589793
  ."(...)" Packed string; returns "2384626433832795028841971693"
 +         Concatenation; returns "3.1415926535897932384626433832795028841971693"
K          Sets K to that string
*"()"6     Repetition; returns "()()()()()()", which is implicitly printed with a newline
 r9Z       Range; returns [9, 8, 7, 6, 5, 4, 3, 2, 1] (Z is initialized to 0)
V          Loop through r9Z, using N as the loop variable
  *dJ      Repetition; d is initialized to " " (returns an empty string if J <= 0)
 p         Print without a newline
  ?!Z      Ternary; if not Z
   \|      then return "|"
   ?qZ9    else, ternary; if Z == 9
    "|:"   then return "|:"
    "\::"  else, return "\::"
 p         Print without a newline
  \\       One-character string; returns "\"
 p         Print without a newline
  :KZ+ZN   Slice; returns K[Z:Z+N], not including K[Z+N]
 p         Print without a newline
 \|        One-character string; returns "|", which is implicitly printed with a newline.
 =+ZN      Adds N to Z
 =hJ       Increments J by 1
)          Ends loop
 *dJ       Repetition; d is initialized to " "
p          Print without a newline
"\__\|"    Returns "\__\|", which is implicitly printed with a newline


问:
Pointers, pointers, pointers!

Introduction

In the error outputs of some languages such as Java, a pointer is shown to give the programmer an idea of exactly where the error went wrong.

Take this example on Ideone:

```<code>Main.java:12: error: ';' expected
    Invalid Java!
                ^
</code>```

Notice the caret shows where the invalid code is?

Challenge

Your challenge is: given number N and string S, place a pointer on the Nth character in S.

Examples

Input: 2, "Lorem ipsum, dollar sit amet."

Output:

```<code>Lorem ipsum, dollar sit amet.
 ^
</code>```

Rules

Input is received via STDIN or function parameters

Output is printed out to the console or returned

Trailing new lines, spaces etc are allowed in the output

The pointer character must be a ^ caret and must be on a new line.

This is code golf, so the shortest answer wins. Good luck!

答:
Turtlèd, 17 bytes

```<code>r!-[*.-l_]' d?:'^
</code>```

explanation

```<code>r!-               move right, take input into string variable, decrement string pointer
   [*    ]        while current char is not *
     .-           write pointed char from string, decrement pointer
       l_         move left, write * if the pointer is on the last char of string
          ' d     write space, move down
             ?:'^ Take input into register, move forward by the amount in register, write ^
</code>```

Title: Pointers, pointers, pointers!

Body:
Turtlèd, 17 bytes

r!-[*.-l_]' d?:'^

explanation

r!-               move right, take input into string variable, decrement string pointer
   [*    ]        while current char is not *
     .-           write pointed char from string, decrement pointer
       l_         move left, write * if the pointer is on the last char of string
          ' d     write space, move down
             ?:'^ Take input into register, move forward by the amount in register, write ^


问:
Test if given number is a Keith number
Since Fibonacci numbers and sequences seems like a popular subject for code golf I thought that it might be a fun challenge to code golf with Keith numbers.

So I propose a challenge that is to create a function that takes an integer and gives back a true or false depending on the number is a Keith number or not.

More about Keith numbers

In recreational mathematics, a Keith number or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence:
  14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208, 2580, …

Numberphile has a video explaining how to calculate a Keith number. But basically you take the digits of a number. Add them together and then take the last digits of the original number and add them to the sum of the calculation, rinse and repeat. And example to make it clear.

14
1 + 4 = 5

  4 + 5 = 9

  5 + 9 = 14

Input

An integer.

Output

True if the number is a Keith number. False if it's not..

答:
R, 116

Python rip-off:

```<code>a=scan();n=as.numeric(strsplit(as.character(a),"")[[1]]);while(a>n[1])n=c(n[-1],sum(n));if((n[1]==a)&&(a>9))T else F
</code>```

Title: Test if given number is a Keith number

Body:
R, 116

Python rip-off:

a=scan();n=as.numeric(strsplit(as.character(a),"")[[1]]);while(a>n[1])n=c(n[-1],sum(n));if((n[1]==a)&&(a>9))T else F


问:
Z̡̬a̧̯̔l̆̓g̛̘̟o̡ generator
Write a program or function that transforms an input string into Zalgo text.

For example, for an input string Zalgo, a possible output might look like:

Z̗̄̀ȧ̛̛̭̣̖̇̀̚l̡̯̮̠̗̩̩̥̭̋̒̄̉̏̂̍̄̌ģ̨̭̭̪̯̫̒̇̌̂o̢̟̬̪̬̙̝̫̍̈̓̅̉̇

Zalgoification specs

Each letter (upper or lower case) must be zalgoified, and nothing else (spaces, punctuation).

The combining characters that can be placed on letters here are all those between U+0300  ̀  and U+032F  ̯

Each letter must have a total number of combining characters on it (above and under combined) which is randomly chosen according to a normal distribution of mean 10 and standard deviation 5 (If a negative number is chosen, 0 combining characters must be added).

Each combining character placed on a letter is chosen uniformly at random between the 48 possible combining characters (see 2nd item).

Inputs, Outputs

Input is a single line string that contains only characters between ASCII 32 (space) and ASCII 126 (tilde). No line breaks. You may assume there is at least one letter in the string. The input can be taken as command line argument, function parameter, or STDIN.

Output is the Zalgoified string. It can be written to a file, or printed to STDOUT, or returned from a function. A trailing line feed is fine. The output doesn't have to display properly in your interpreter/whatever, as long as when you copy it to a Stack Exchange answer it displays properly like here.

Test cases

The Zalgo example above.

Input: Programming Puzzles & Code Golf

Possible output:

P̢̭̟̟̮̍̅̏̍̀̊̕̚̚r̢̫̝̟̩̎̔̅̈̑o̡̠̣̪̠̍̈̐̏̌̆g̡̬̯̟̠̩̎̐́̅̚ȑ̢̨̩̠̙̭̤̩̟̔̕ą̟̟̯̠̪̜́̉̒̎̂̍̃́̚̚̚m̪̈̅̈m̨̛̛̪̤̟̔̍̓i̢̛̬̠̠̇̈̂̓̒̀̋̔̚̚n̛̝̩̜̓̐̑̅̅g̨̩̪̊ P̨̧̢̟̙̮̋̆ų̨̙̞̙̫̤̫̭̊̓̒̃̒̚z̜̤̮̪̫̄̌̃̈̉̑̋́̕z̡̥̯̠̬̜̥̑̌̓̌̋́̅ľ̫̙̟̪̖̉ė̢̨̘̦̘̖s̛̜̙̘̚ & C̨̠̟̯̟̙̠̉̄̄́̄̑̈̔̆̀ö̭̟̗̯̥̏̐̄̏̌d̞̬̀̆́̀é̟̙̩̗̙̣̋̎̌̌̋ Ğ̨̡̧̡̣̪̝̝̘̩̮̉̋̀̉̉̕̕ọ̠̠̘̟̑̇́̀̃̎̓̋̚ḽ̡̢̟̪̥̍̍̅̀́̎̆̕f̧̢̪̠̠̀̉̒̍̍̊́

Input: Golf is a club and ball sport in which players use various clubs to hit balls into a series of holes on a course in as few strokes as possible.

Possible output:

Ǧ̡̧̄̐̊ò̡̞̟̖̌́̄́̆̈̒l̡̬̣̜̫̞̘̪̇̈̏̊̆̃̑̉̓̒f̙̐̍̇́̐̍̉ į̦̘̝̣̊̒̎̚s à̡̛̠̜̙̣̙̞̣̗̯̝̘̩̅̊̓̄̒̃ ć̬̗̫̯̫̎́̚l̒̎̋ű̯̜̑̎b̯̣̮̭̤̃̊́ a̡̨̟̘̭̣̍̈̀̃̎́̐̋̆̂ń̨̖̭̝̬̘̦̣̓̇̚̕d̨̤̣̙̜̪̖̪̍̓̔̍̔̃̒̍̆̏̚̚̕̚ ḃ̬̪̇̕a̡̟̖̬̬̖̬̋́̎̎̔̄̏̒̑̚l̨̖̜̬̠̭̭̇l̡̡̛̛̬̤̆̔̑̍ s̠̙̣̠̖̜̜̅p̤̖̃́̅̕̕ǫ̢̥̬̠̞̭̭̘̟̞̋̊̌r̡̛̞̬̈̇̑̎̄̚t̟̩̏̀ ï̡̧̢̨̜̜̝̝̜̜̫̔̇̂̔̐n̞̖̫̪̟̤̦̫̂̓̍̑̆̒̚ w̨̧̟̠̯̜̙̘̏̎̈̆̂̅̔hi̧̝̖̗̖̒̆̆̈̚ć̪̜̫̖̠̣̞̋̈́̀̌̋h̢̢̨̥̮ p̜̣̋̔̆l̨̧̛̘̫̝̙̠̯̂̑̌̈̒̐ā̩̗̟̐ẏ̢̛̫̠̦̤̫̞̦̯̥̜̀̀̈̅̉̈̄ẹ̡̑̔̄̉̀̎̒̑r̛̫̭̤̋̄̓̀̅̓ș̜̯̆̋̒̍̔ ų̛̘̭̜̝̈̃̂̅̌̍̆̚s̡̡̡̨̫̥̪̋̈̀̀̆ê̢̡̡̥̖̮̞̫̪̥̘̥̯̎́ v̡̢̢̟̠̞̬̥̩̣̫̫̦̞̂̐̓̇ặ̢̧̙̝̥̪̗̆̎̓ŗ̦̙̩̑̒̕í̫̣̊̚ō̡̧̤̘̟̩̠̫̗̃̍̉̊̕ụ̡̪̠̈̈́̊̅s̢̢̘̤̝̪̀̎̅ c̡̢̛̖̫̗̑̒̆́̎̚l̥̥̖̘̉̎̓̔̀̔ų̘̘̣̟̃̆̓̉̏̅̓̂́̇b̡̝̗̙̗̮̖̩̗̦̏̌̏š̛̮̣̮̜̒̓̌ ṭ̣̫̗̮̙̈̔̅̂̎̃̌̈ò̮̘̍̅̃̃̅̚̕ ḩ̜̞̮̠̇i̮t̝̗̦̖̮̞̗̩̞̤̎̍̒̐ bȁ̢̮̩̝̣̉ļ̛̮̘̏ĺ̨̖̮̑s̢̬̪̗̬̖̟̅̀ i̢̗̖̊̃ń̨̧̛̫̮̞̎t̡̗̞̩̙̑̐̏̔̏ơ̧̯̮̦̖̇̆̔ ạ̧̉̍̚ s̤̬̫̠̉e̎̃r̟̪̥̗̜̥̍̆̍̇̕̕i̧̧̭̝̫̪̯̖̞̪̅̇̎̈̐̅̍ȇ̟̬́̄̃̐̊̕s̢̢̛̝̤̙̭̘̩̩̍̑̂̈̀̀̍̄̔̒̒ o̡̢̘̩̣̅̐̆̌̂̉̇̆̋̕f̡̯̜̝̘̮̠̖̐̂̒̃̚̕ h̪̘̫̪́ǫ̭̦̔̋̆̚̕l̢̡̧̨̙̯̤̔̅̓̆̑̍́ȅ̪̬̝̙̅̋̍s̪̖̭̫̪̟̖̐̀̕ ǫ̦̠̫̍̊̉̄̚n̐̎̂̀ ą̡̛̛̤̦̪̣̭̈̐̂̎ c̪̩̠̗̟̜̘̐̂̈̐̑̏̈ọ̡̡̙̫̞̜̐̇̄̓̏u̥̖̙̝̔̂̎̅̚̚r̙̜̬̭̠̮̙̙̪̫̝̙̬̥̥̯̐́̈́̊̈̍̍ș̀́e̞̜̒̌̚ ĩ̧̦̝̪̆n̛̞̞̆̆̀ a̟̅̐̈̍̉̚̚̕ş̫̭̍̐̚ f̘̝̠̪̦̜́̌̍̇̀̕e̩̫̣̊̎̇̚w̪ ŝ̨̨̠̠̝̦̣̜̦̗̮̞̞̥̥̅̄̄̕t̢̡̢̙̞̟̩̭̤̅̎̌̒̃̇̕r̞̤̙̄̊̃̇̅̈̏̈̌ǫ̝̬̀̋̏̐̌̈k̡̢̧̪̭̝̙̆̈̒̀ȩ̛̙̣̠̗̞̮̅̅s̙̣̒̉̎́̂̅ à̧̛̖̘̞̫̘̎̃̀̑̎̕̕s̢̟̟̭̩̈̏̇ p̣̟̭̗̪̜̫̦̝̣̎̋̎̀̐̏o̧̢̪̮̤̦̎́̐̒̀̚̕s̛̯̦̗̬̬̊̊̄̓̐̉̏́̚s̢̠̣̬̥̬̔̅̕̕i̡̠̣̣̫̞̣̮̥̟̅̎̇̄̋̌̌̇b̡̧̡̖̖̃̄̋̈̋l̢̢̙̪̣̉̉̐̑̆ẹ̢̒̎.

Scoring

This is code-golf, so the shortest answer in bytes ẁ̨̛̭̙̥̖̏̏̐̐̉̃̅̚i̜̟̭̤̞̘̗̐̐̔̈̍̋̏̚n̘̯̥̩̗̯̠̘̮̋̈̃̀̊̉̎̈̕s̛̬̦̙̮̩̜̄̑̐́̎̆̚.

答:
Perl, 73 bytes

s!\w\K!$x=-140;$x+=rand for 1..300;(x x $x) =~ s/x/chr 768+rand 48/ger!ge
```

Input is taken as newline-separated strings.

If you want to ignore the warnings printed to STDERR, use the -C7 command-line flag.

This uses the same approximation for a normal distribution as the Moonscript solution.

Title: Z̡̬a̧̯̔l̆̓g̛̘̟o̡ generator

Body:
Perl, 73 bytes

s!\w\K!$x=-140;$x+=rand for 1..300;(x x $x) =~ s/x/chr 768+rand 48/ger!ge

Input is taken as newline-separated strings.

If you want to ignore the warnings printed to STDERR, use the -C7 command-line flag.

This uses the same approximation for a normal distribution as the Moonscript solution.


答:
Pyth, 8 bytes

```<code>z+*dtQ\^
</code>```

Takes inputs separated by a newline (i.e. 2\nLorem ipsum).

Try it online!

Explanation:

```<code>z           The second input, implicitly printed with trailing newline
  *d__      The space character, __ times
    tQ        where __ is the first input -1
 +    \^    Append a literal carat character and printed
</code>```

Title: Pointers, pointers, pointers!

Body:
Introduction

In the error outputs of some languages such as Java, a pointer is shown to give the programmer an idea of exactly where the error went wrong.

Take this example on Ideone:

```<code>Main.java:12: error: ';' expected
    Invalid Java!
                ^
</code>```

Notice the caret shows where the invalid code is?

Challenge

Your challenge is: given number N and string S, place a pointer on the Nth character in S.

Examples

Input: 2, "Lorem ipsum, dollar sit amet."

Output:

```<code>Lorem ipsum, dollar sit amet.
 ^
</code>```

Rules

Input is received via STDIN or function parameters

Output is printed out to the console or returned

Trailing new lines, spaces etc are allowed in the output

The pointer character must be a ^ caret and must be on a new line.

This is code golf, so the shortest answer wins. Good luck!

Body:
Pyth, 8 bytes

z+*dtQ\^

Takes inputs separated by a newline (i.e. 2\nLorem ipsum).

Try it online!

Explanation:

z           The second input, implicitly printed with trailing newline
  *d__      The space character, __ times
    tQ        where __ is the first input -1
 +    \^    Append a literal carat character and printed


答:
05AB1E, <s>7</s> <s>6</s> 5 bytes

Code:

```<code>3ãAŒÃ
</code>```

Explanation:

```<code>3ã      # Cartesian product × 3 with input
  AŒ    # All substrings of the alphabet
    Ã   # Setwise intersection
</code>```

Uses the CP-1252 encoding. Try it online!

Title: Close-Knit Words

Body:
Introduction

According to Rand Al'Thor's post in the Puzzling SE, a close-knit word is any word that contains three alphabetically consecutive letters (in any order).

Words like education, foghorn and cabaret are all considered close-knit words whereas words like learning, klaxon and perform are not close-knit words.

Challenge

The challenge is to code-golf a program capable of taking a single word as input (assumed lower case, for all intents and purposes) and to return output that (if available) lists all consecutive letter sets (also in lower case) if it is a close-knit word, and empty output if it is not a close-knit word.

Examples

```<code>Input: education
Output: cde

Input: foghorn
Output: fgh

Input: cabaret
Output: abc

Input: hijacking
Output: ghi, hij, ijk

Input: pneumonia
Output: mno, nop

Input: klaxon
Output: <<no output>>

Input: perform
Output: <<no output>>

Input: learning
Output: <<no output>>
</code>```

Rules

Whereas input is to be assumed to be a single lower-case word and output must be lower-case, the nature of the output will vary according to the choice of your coding language. Please select a form of output that will best suit the nature of the challenge, whether it be STDOUT, file output, array, etc.

Because this is code-golf, it will be a case of lowest number of bytes being the clear winner.

No silly loopholes.

I will not accept answers that have the consecutive letters in non-alphabetical order... So cab will not be deemed a suitable output for cabaret, for example.

Special note, while the "triplets" don't necessarily have to be in alphabetical order, but the characters within the triplets must be... so in the case of the word "performance", for example, the output mno,nop will be accepted, as will nop,mno. In the case of the word "hijacking", there are six ways that the triplets of ghi, hij and ijk could be arranged in a list, and all six permutations are acceptable as output.

Other than that, on your marks, get set, golf!

Body:
05AB1E, <s>7</s> <s>6</s> 5 bytes

Code:

3ãAŒÃ

Explanation:

3ã      # Cartesian product × 3 with input
  AŒ    # All substrings of the alphabet
    Ã   # Setwise intersection

Uses the CP-1252 encoding. Try it online!


问:
The Alphabet Chromosome

Introduction

Alphabet challenges are in our DNA, so let's show it.

Challenge

Print the following the text exactly:

```<code>AaBbCc        cCbBaA
BbCcDd        dDcCbB
EeFfGg        gGfFeE
HhIiJj        jJiIhH
KkLlMm        mMlLkK
NnOoPp        pPoOnN
QqRrSs        sSrRqQ
TtUuVv        vVuUtT
   WwXx      xXwW
       Yy  yY
         ZZ
         zz
         ZZ
       Yy  yY
   WwXx      xXwW
TtUuVv        vVuUtT
QqRrSs        sSrRqQ
NnOoPp        pPoOnN
KkLlMm        mMlLkK
HhIiJj        jJiIhH
EeFfGg        gGfFeE
BbCcDd        dDcCbB
AaBbCc        cCbBaA
</code>```

Rules

You must match the case of each letter

Trailing and/or leading newlines and/or spaces are allowed

Winning

Shortest code in bytes wins.

答:
Lua, 212 Bytes

```<code>s=([[         Z
       Yy
   WwXx
TtUuVv_QqRrSs_NnOoPp_KkLlMm_HhIiJj_EeFfGg_BbCcDd_AaBbCc    ]]):gsub("_","    \n")S="         zz"for z in s:gmatch"[%w ]+"do k=z..z:reverse()S=k..'\n'..S..'\n'..k end print(S)
</code>```

Simple enough, based off of TimmyD's answer, kind of.
Builds the top left arm using a really poorly compressed chunk,
then does both mirrors at once around a 'zz', and prints.

Try it on Repl.It

Title: The Alphabet Chromosome

Body:
Lua, 212 Bytes

s=([[         Z
       Yy
   WwXx
TtUuVv_QqRrSs_NnOoPp_KkLlMm_HhIiJj_EeFfGg_BbCcDd_AaBbCc    ]]):gsub("_","    \n")S="         zz"for z in s:gmatch"[%w ]+"do k=z..z:reverse()S=k..'\n'..S..'\n'..k end print(S)

Simple enough, based off of TimmyD's answer, kind of.
Builds the top left arm using a really poorly compressed chunk,
then does both mirrors at once around a 'zz', and prints.

Try it on Repl.It


答:
Lua, 34 Bytes

```<code>repeat print(arg[2])until arg[2]<1
</code>```

arg[2] contains the first command line argument, (arg[1] contains the filename)

Give an input through the command line, and it shall spam it if it's 1, or once if it's not.

Simple enough.

Title: Implement a Truth-Machine

Body:
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Body:
Lua, 34 Bytes

repeat print(arg[2])until arg[2]<1

arg[2] contains the first command line argument, (arg[1] contains the filename)

Give an input through the command line, and it shall spam it if it's 1, or once if it's not.

Simple enough.


答:
Brainfuck, 5 Bytes

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

I/O is as 0x00 / 0x01 bytes.

I just think it's a neat thing.

Title: Implement a Truth-Machine

Body:
Brainfuck, 5 Bytes

,.[.]

I/O is as 0x00 / 0x01 bytes.

I just think it's a neat thing.


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

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

The Rules

Each submission must be a full program.

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

The program must not write anything to STDERR.

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

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

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

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

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

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

For inspiration, check the Hello World Collection.

The Catalogue

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

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

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

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

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

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

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

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

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

/* Configuration */

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

/* App */

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

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

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

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

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

getAnswers();

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

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

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

function process() {
  var valid = [];

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

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

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

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

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

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

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

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

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

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

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

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

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

table thead {
  font-weight: bold;
}

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Logicode, 121 bytes

```<code>var a=11011
var l=@(a+00)
var o=a+11
out @1001000+@(a+01)+l+l+@o+@101100+@10000+@1010111+@o+@1110010+l+@1100100+@10001
</code>```

As Logicode works on binary strings, it's pretty hard to convert stuff to ASCII. In comes the @ operator!

It basically converts a binary string to its ASCII counterpart, so something like @1001000 turns into H (1001000 is 72 in binary, and H's ASCII code is 72).

Title: "Hello, World!"

Body:
Logicode, 121 bytes

var a=11011
var l=@(a+00)
var o=a+11
out @1001000+@(a+01)+l+l+@o+@101100+@10000+@1010111+@o+@1110010+l+@1100100+@10001

As Logicode works on binary strings, it's pretty hard to convert stuff to ASCII. In comes the @ operator!

It basically converts a binary string to its ASCII counterpart, so something like @1001000 turns into H (1001000 is 72 in binary, and H's ASCII code is 72).


问:
Output the largest number with the fewest digits
Given a nonempty list of positive decimal integers, output the largest number from the set of numbers with the fewest digits.

The input list will not be in any particular order and may contain repeated values.

Examples:

```<code>[1] -> 1
[9] -> 9
[1729] -> 1729
[1, 1] -> 1
[34, 3] -> 3
[38, 39] -> 39
[409, 12, 13] -> 13
[11, 11, 11, 1] -> 1
[11, 11, 11, 11] -> 11
[78, 99, 620, 1] -> 1
[78, 99, 620, 10] -> 99
[78, 99, 620, 100] -> 99
[1, 5, 9, 12, 63, 102] -> 9
[3451, 29820, 2983, 1223, 1337] -> 3451
[738, 2383, 281, 938, 212, 1010] -> 938
</code>```

The shortest code in bytes wins.

答:
Pascal (FPC), <s>169</s> 167 bytes

A function which takes variable array as input:

function m(a:array of integer):integer;var i:integer;begin m:=a[0];for i in a do if(int(log10(i))<int(log10(m)))or((int(log10(i))=int(log10(m)))and(i>m))then m:=i;end;
```

Try it online!

(Yes I know, pascal sucks at this, in addition there is no sort function in it's library..)

Body:
Pascal (FPC), <s>169</s> 167 bytes

A function which takes variable array as input:

function m(a:array of integer):integer;var i:integer;begin m:=a[0];for i in a do if(int(log10(i))<int(log10(m)))or((int(log10(i))=int(log10(m)))and(i>m))then m:=i;end;

<a href="https://tio.run/##lVPLboMwELznK/ZoS2kFJg@wS6Wqp957i3IwwYAlwBFxGuXr6Zo8KtIoVg6GXWZmd9bGW7nbyPql2G76/U7tJgCNtJXoi327sdq00BDJZdfJI5gCdGtVqTrKz4H4kR3oa5apUqOCp3IVrEVhEEMJSMgN6IIgjdSmDAOiKX37yxpKqenIGE/HuGxzot8xspUaWmih2lz09rhVaPr762ThY3CawtXx@bu45fwjjlAxmeBkqNHczRw7ecbvVEDiMLTDgad3GK@fnZJWEWTcWLggEAKdPoCTx3C4ZD7G1Ncimk0h8lBipHgazYIEWzFcnmKhs3RZT1A93CV6TNDCggXeumNu8BQ58O73HPmnrVhETsF8@z9HEUtiVx9fTsOYe0bR0mPNHQyLnITFWCQZ8uEQAjcWSin@pQDDdeRpbQ4ko2ANVLqsXJibofyh01bVLWlIttJriiK8YK/9Lw" rel="nofollow noreferrer" title="Pascal (FPC) – Try It Online">Try it online!

(Yes I know, pascal sucks at this, in addition there is no sort function in it's library..)


问:
Prime factors buddies
Given an integer N > 1, output all other numbers which prime decompositions have the same digits as the prime decomposition of N.

For example, if N = 117, then the output must be [279, 939, 993, 3313, 3331], because

```<code>117 = 3 × 3 × 13
</code>```

therefore, the available digits are 1, 3, 3 and 3 and we have

```<code>279  = 3 × 3 × 31
939  = 3 × 313
993  = 3 × 331
3313 = 3313
3331 = 3331
</code>```

Those are the only other possible numbers, because other combination of these digits yield non-prime integers, which can't be the result of prime factorization.

If N is any of 117, 279, 939, 993, 3313 or 3331, then the output will contain the five other numbers: they are prime factors buddies.

You cannot use leading zeroes to get primes, e.g. for N = 107, its only buddy is 701 (017 is not considered).

Input and Outputs

The input and output buddies must be taken and returned in the decimal base.

N will always be strictly greater than 1.

The output can be formatted rather freely, as long as it only contains the buddies and separators/list syntactic elements.

The ordering of the output is unimportant.

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

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

Test cases

Your program should solve any of the test cases below in less than a minute.

```<code>N        Buddies
2        []
4        []
8        []
15       [53]
16       []
23       [6]
42       [74, 146, 161]
126      [222, 438, 483, 674, 746, 851, 1466, 1631, 1679]
204      [364,548,692,762,782,852,868,1268,1626,2474,2654,2921,2951,3266,3446,3791,4274,4742,5426,5462,6233,6434,6542,7037,8561,14426,14642,15491,15833,22547]
</code>```

Scoring

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

答:
CJam, <s>26</s> 23 bytes

```<code>{_mfs$:XW%i){mfs$X=},^}
</code>```

Try it online

Explanation

Concatenating two numbers always gives a bigger result than multiplying them. So the largest number we possibly need to consider is the largest number we can form from the digits of the input's prime factorisation, which is just all digits sorted in descending order. For the given numbers this upper bound is easily small enough that we can exhaustively check every number in range for whether it's a prime factor buddy:

```<code>_mf    e# Duplicate input N and get a list of its prime factors.
s$     e# Convert the list to a (flattened) string and sort it.
:X     e# Store this in X for later.
W%     e# Reverse it. This is now a string repesentation of the largest
       e# possible output M.
i)     e# Convert to integer and increment.
{      e# Get a list of all integers i in [0 1 ... M] for which the following
       e# block gives a truthy result.
  mf   e#   Get list of prime factors of i.
  s$   e#   Get a sorted list of the digits appearing in the factorisation.
  X=   e#   Check for equality with X.
},
^      e# Symmetric set difference: removes N from the output list.
</code>```

Title: Prime factors buddies

Body:
CJam, <s>26</s> 23 bytes

{_mfs$:XW%i){mfs$X=},^}

Try it online

Explanation

Concatenating two numbers always gives a bigger result than multiplying them. So the largest number we possibly need to consider is the largest number we can form from the digits of the input's prime factorisation, which is just all digits sorted in descending order. For the given numbers this upper bound is easily small enough that we can exhaustively check every number in range for whether it's a prime factor buddy:

_mf    e# Duplicate input N and get a list of its prime factors.
s$     e# Convert the list to a (flattened) string and sort it.
:X     e# Store this in X for later.
W%     e# Reverse it. This is now a string repesentation of the largest
       e# possible output M.
i)     e# Convert to integer and increment.
{      e# Get a list of all integers i in [0 1 ... M] for which the following
       e# block gives a truthy result.
  mf   e#   Get list of prime factors of i.
  s$   e#   Get a sorted list of the digits appearing in the factorisation.
  X=   e#   Check for equality with X.
},
^      e# Symmetric set difference: removes N from the output list.


问:
Emulate a 7-segment display

Task

The task is to display any of the 128 possible states of a
7-segment display.

Your program should accept a string of 7 characters ("bits") that are either 0 or 1.
First bit of input corresponds to segment A of the following illustration, the
second to B, etc (ignore dp):

How you represent the display is up to you -- a single Unicode or ASCII symbol,
ASCII art, grafically, or whatever you can come up with. However, each
input must have it's own distinct output. If you come up with something fancy I'm sure you can harvest upvotes by showing off some examples.

All 128 possible states of the display are:

Rules

Codegolf

As I said, any kind of output is allowed, but it would be nice if you specified it.

Input can be stdin or command line argument.

Examples

Input

```<code>1101101
</code>```

Output

As ASCII/Unicode:

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

Different kinds of ASCII art (I'm not too good at this)

```<code> _   ╺┓  ╒╗   ---
 _|  ┏┛  ╔╝     |
|_   ┗╸  ╚╛   ---
              |
              ---
</code>```

答:
Python 2.7 (93 chars):

```<code>print (' {0}\n{5} {1}\n {6}\n{4} {2}\n {3}').format(*map(lambda x:int(x)and'*'or' ',raw_input()))
</code>```

Explanation:

With the stdin input, use a makeshift ternary operator to give * for true and a space for false.  Take those values and plug them into a format statement that's in the format of the 7 digit display.  It'd be at most 83 characters if the display worked like this:

```<code> a
b c
 d
e f
 g
</code>```

but the ordering makes it longer.  Anyone have a way around this?

Example:

```<code>$ ./7seg.py
111000

 *
  *

  *

$ ./7seg.py

1111111

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

Title: Emulate a 7-segment display

Body:
Python 2.7 (93 chars):

print (' {0}\n{5} {1}\n {6}\n{4} {2}\n {3}').format(*map(lambda x:int(x)and'*'or' ',raw_input()))

Explanation:

With the stdin input, use a makeshift ternary operator to give * for true and a space for false.  Take those values and plug them into a format statement that's in the format of the 7 digit display.  It'd be at most 83 characters if the display worked like this:

 a
b c
 d
e f
 g

but the ordering makes it longer.  Anyone have a way around this?

Example:

$ ./7seg.py
111000

 *
  *

  *

$ ./7seg.py

1111111

 *
* *
 *
* *
 *


答:
05AB1E, 17 bytes

Code:

```<code>ÒJ{©RƒNÒJ{®QN¹Ê*–
</code>```

Explanation:

```<code>Ò                  # Get the factorization with duplicates, e.g. [3, 3, 13]
 J                 # Join the array, e.g. 3313
  {©               # Sort and store in ©, e.g. 1333
    R              # Reverse the number, e.g. 3331. This is the upperbound for the range
     ƒ             # For N in range(0, a + 1), do...
      NÒ           # Push the factorization with duplicates for N
        J          # Join the array
         {         # Sort the string
          ®Q       # Check if equal to the string saved in ©
            N¹Ê    # Check if not equal to the input
               *   # Multiply, acts as a logical AND
                –  # If 1, print N
</code>```

Uses the CP-1252 encoding. Try it online!

Title: Prime factors buddies

Body:
Given an integer N > 1, output all other numbers which prime decompositions have the same digits as the prime decomposition of N.

For example, if N = 117, then the output must be [279, 939, 993, 3313, 3331], because

```<code>117 = 3 × 3 × 13
</code>```

therefore, the available digits are 1, 3, 3 and 3 and we have

```<code>279  = 3 × 3 × 31
939  = 3 × 313
993  = 3 × 331
3313 = 3313
3331 = 3331
</code>```

Those are the only other possible numbers, because other combination of these digits yield non-prime integers, which can't be the result of prime factorization.

If N is any of 117, 279, 939, 993, 3313 or 3331, then the output will contain the five other numbers: they are prime factors buddies.

You cannot use leading zeroes to get primes, e.g. for N = 107, its only buddy is 701 (017 is not considered).

Input and Outputs

The input and output buddies must be taken and returned in the decimal base.

N will always be strictly greater than 1.

The output can be formatted rather freely, as long as it only contains the buddies and separators/list syntactic elements.

The ordering of the output is unimportant.

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

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

Test cases

Your program should solve any of the test cases below in less than a minute.

```<code>N        Buddies
2        []
4        []
8        []
15       [53]
16       []
23       [6]
42       [74, 146, 161]
126      [222, 438, 483, 674, 746, 851, 1466, 1631, 1679]
204      [364,548,692,762,782,852,868,1268,1626,2474,2654,2921,2951,3266,3446,3791,4274,4742,5426,5462,6233,6434,6542,7037,8561,14426,14642,15491,15833,22547]
</code>```

Scoring

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

Body:
05AB1E, 17 bytes

Code:

ÒJ{©RƒNÒJ{®QN¹Ê*–

Explanation:

Ò                  # Get the factorization with duplicates, e.g. [3, 3, 13]
 J                 # Join the array, e.g. 3313
  {©               # Sort and store in ©, e.g. 1333
    R              # Reverse the number, e.g. 3331. This is the upperbound for the range
     ƒ             # For N in range(0, a + 1), do...
      NÒ           # Push the factorization with duplicates for N
        J          # Join the array
         {         # Sort the string
          ®Q       # Check if equal to the string saved in ©
            N¹Ê    # Check if not equal to the input
               *   # Multiply, acts as a logical AND
                –  # If 1, print N

Uses the CP-1252 encoding. Try it online!