答:
JavaScript (ES6), 99 bytes

```<code>f=(n,i=1)=>(n-=/^.0+$/.test(i)</^((.),\2,)*(.)(,\3)?(,(.),\6)*$/.test([...i+''].sort()))?f(n,i+1):i
</code>```

Explanation:

```<code>f=(n,i=1)=>             look for n numbers starting at 1
 (n-=                   test whether current guess is
  /^.0+$/.test(i)<      not a round number and
  /^((.),\2,)*          pairs of comma-separated digits
   (.)(,\3)?            possible single digit
   (,(.),\6)*$/         pairs of comma-separated digits
   .test(               matches the comma-joined
    [...i+''].sort()))  digits in ascending order
 ?f(n,i+1)              if not n numbers found try next number
 :i                     found it!
</code>```

Title: Permutapalindromic numbers

Body:
JavaScript (ES6), 99 bytes

f=(n,i=1)=>(n-=/^.0+$/.test(i)</^((.),\2,)*(.)(,\3)?(,(.),\6)*$/.test([...i+''].sort()))?f(n,i+1):i

Explanation:

f=(n,i=1)=>             look for n numbers starting at 1
 (n-=                   test whether current guess is
  /^.0+$/.test(i)<      not a round number and
  /^((.),\2,)*          pairs of comma-separated digits
   (.)(,\3)?            possible single digit
   (,(.),\6)*$/         pairs of comma-separated digits
   .test(               matches the comma-joined
    [...i+''].sort()))  digits in ascending order
 ?f(n,i+1)              if not n numbers found try next number
 :i                     found it!


问:
All in all it's just, uh, another trick in code golf
The purpose of this challenge is to produce an ASCII version of the cover of this great album by the rock band Pink Floyd.

The brick junctions are made of characters _ and |. Bricks have width 7 and height 2 characters, excluding junctions. So the basic unit, including the junctions, is:

```<code>_________
|       |
|       |
_________
</code>```

Each row of bricks is offset by half a brick width (4 chars) with respect to the previous row:

```<code>________________________________________
  |       |       |       |       |
  |       |       |       |       |
________________________________________
      |       |       |       |       |
      |       |       |       |       |
________________________________________
  |       |       |       |       |
  |       |       |       |       |
</code>```

The wall is parameterized as follows. All parameters are measured in chars including junctions:

Horizontal offset of first row, F. This is the distance between the left margin and the first vertical junction of the upmost row. (Remember also the half-brick relative offset between rows). Its possible values are 0, 1, ..., 7.

Total width, W. This includes junctions. Its value is a positive integer.

Total height, H. This includes junctions. Its value is a positive integer.

The top of the wall always coincides with the top of a row. The bottom may be ragged (if the total height is not a multiple of 3). For example, here's the output for 6, 44, 11:

```<code>____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
</code>```

and a visual explanation of parameters:

```<code>          F=6
         ......
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |
H=11 .     |       |       |       |       |       |
     .   ____________________________________________
     .         |       |       |       |       |
     .         |       |       |       |       |
     .   ____________________________________________
     .     |       |       |       |       |       |

         ............................................
                             W=44
</code>```

Additional rules

You may provide a program or a function.

Input format is flexible as usual. Output may be through STDOUT or an argument returned by a function. In this case it may be a string with newlines or an array of strings.

Trailing spaces or newlines are allowed.

Shortest code in bytes wins.

Test cases

Inputs are in the order given above, that is: horizontal offset of first row, total width, total height.

```<code>6, 44, 11:
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |
  |       |       |       |       |       |
____________________________________________
      |       |       |       |       |
      |       |       |       |       |
____________________________________________
  |       |       |       |       |       |

2, 20, 10:
____________________
  |       |       |
  |       |       |
____________________
      |       |
      |       |
____________________
  |       |       |
  |       |       |
____________________

1, 1, 1:
_

1, 2, 3:
__
 |
 |

3, 80, 21:
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
       |       |       |       |       |       |       |       |       |       |
       |       |       |       |       |       |       |       |       |       |
________________________________________________________________________________
   |       |       |       |       |       |       |       |       |       |
   |       |       |       |       |       |       |       |       |       |
</code>```

答:
Bash + Sed, <s>411</s> <s>395</s> <s>381</s> 370 bytes:

F=`printf '_%.s' $(eval echo {1..$2})`;V="       |";(($[($2-$1)/8]>0))&&L=`printf "$V%.s" $(eval echo {1..$[($2-$1)/8]})`||L=;Z=`printf "%$1.s|%s\n" e "$L"`;I=$[($2-(${#Z}-4))/8];(($I>0))&&W=`printf "$V%.s" $(eval echo {1..$I})`||W=;J=${Z:4}$W;for i in `eval echo {1..$[$3/3+1]}`;{ (($[$i%2]<1))&&O+="$F\n$J\n$J\n"||O+="$F\n$Z\n$Z\n";};echo "`echo -e "$O"|sed -n 1,$3p`"
```

Well, here is my very first answer in Bash, or any shell scripting language for that matter. This is also by far the longest answer here. Takes in a sequence of space-separated command line arguments in the format Offset Width Height. This can probably be a lot shorter than it currently is, so any tips and/or tricks for golfing this down more are appreciated.

ContentLicense: CC BY-SA 4.0

Body:
Bash + Sed, <s>411</s> <s>395</s> <s>381</s> 370 bytes:

F=`printf '_%.s' $(eval echo {1..$2})`;V="       |";(($[($2-$1)/8]>0))&&L=`printf "$V%.s" $(eval echo {1..$[($2-$1)/8]})`||L=;Z=`printf "%$1.s|%s\n" e "$L"`;I=$[($2-(${#Z}-4))/8];(($I>0))&&W=`printf "$V%.s" $(eval echo {1..$I})`||W=;J=${Z:4}$W;for i in `eval echo {1..$[$3/3+1]}`;{ (($[$i%2]<1))&&O+="$F\n$J\n$J\n"||O+="$F\n$Z\n$Z\n";};echo "`echo -e "$O"|sed -n 1,$3p`"

Well, here is my very first answer in Bash, or any shell scripting language for that matter. This is also by far the longest answer here. Takes in a sequence of space-separated command line arguments in the format Offset Width Height. This can probably be a lot shorter than it currently is, so any tips and/or tricks for golfing this down more are appreciated.

ContentLicense: CC BY-SA 3.0


问:
Permutapalindromic numbers
Given an integer N as input, output the Nth permutapalindromic number.

A permutapalindromic number is a strictly positive integer such that there is at least one permutation of its digits that results in a palindrome (i.e. a number that is its own reverse).

For example, 117 is a permutapalindromic number since its digits can be permuted into 171, which is a palindrome.

We consider that numbers like 10 are not permutapalindromic numbers, even though 01 = 1 is a palindrome. We impose that the palindromic permutation must not have a leading zero (as such, 0 itself is not permutapalindromic).

Numbers that are already palindromes are also permutapalindromic, since permuting nothing is valid.

Inputs and outputs

N may be either 0-indexed or 1-indexed. Please indicate which of the two your answer uses.

The input can be taken through STDIN, as a function argument, or anything similar in your language of choice. The output can be written to STDOUT, returned from a function, or anything similar in your language of choice.

The input and output must be in the decimal base.

Test cases

The following test cases are 1-indexed. Your program must be able to pass any of the test cases presented here in at most 1 minute.

```<code>N      Output

1      1
2      2
3      3
4      4
5      5
6      6
7      7
8      8
9      9
10     11
42     181
100    404
128    511
256    994
270    1166
</code>```

Scoring

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

答:
05AB1E, <s>15</s> <s>14</s> 13 bytes

Saved a byte thanks to Emigna! Code:

```<code>µNœvyJÂïÊP}_½
</code>```

Explanation:

```<code>µ               # c = 0, when c is equal to the input, print N.
 N              # Push N, the iteration variable.
  œ             # Push all permutations of N.
   vyJ    }     # For each permutation...
      Â         #   Bifurcate, which is short for duplicate and reverse.
       ï        #   Convert the seconds one to int, removing leading zeros.
        Q       #   Check if they are not equal.
         P      #   Product of the stack.
           _    # Logical not.
            ½   # Pop a value, if 1 then increase c by 1.
</code>```

Uses the CP-1252 encoding. Try it online!.

Title: Permutapalindromic numbers

Body:
05AB1E, <s>15</s> <s>14</s> 13 bytes

Saved a byte thanks to Emigna! Code:

µNœvyJÂïÊP}_½

Explanation:

µ               # c = 0, when c is equal to the input, print N.
 N              # Push N, the iteration variable.
  œ             # Push all permutations of N.
   vyJ    }     # For each permutation...
      Â         #   Bifurcate, which is short for duplicate and reverse.
       ï        #   Convert the seconds one to int, removing leading zeros.
        Q       #   Check if they are not equal.
         P      #   Product of the stack.
           _    # Logical not.
            ½   # Pop a value, if 1 then increase c by 1.

Uses the CP-1252 encoding. Try it online!.


问:
Output "Fit" numbers

"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

答:
Javascript (ES6), 40 bytes

```<code>n=>'0b'+n.toString(2).replace(/0+/g,0)-0
</code>```

Title: Output "Fit" numbers

Body:
Javascript (ES6), 40 bytes

n=>'0b'+n.toString(2).replace(/0+/g,0)-0


答:
C#, <s>112</s> 91 bytes

```<code>int x(int x)=>Convert.ToInt32(Regex.Replace(Convert.ToString(x,2),"0+","0"),2);
</code>```

-8 bytes thanks to TuukkaX

Title: Output "Fit" numbers

Body:
"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

Body:
C#, <s>112</s> 91 bytes

int x(int x)=>Convert.ToInt32(Regex.Replace(Convert.ToString(x,2),"0+","0"),2);

-8 bytes thanks to TuukkaX


答:
Python 2.7, <s>163</s> 154 bytes:

```<code>from itertools import*;I,F,Q=input(),[],2
while len(F)<I:F=[g for g in range(1,Q)if any(i==i[::-1]*(i[0]>'0')for i in permutations(`g`))];Q+=1
print F[-1]
</code>```

Simple enough. Basically uses a while loop to repeatedly create arrays containing permutapalindromic numbers the the range [1,Q) until Q is large enough such that the array contains Input number of items. It then outputs the last element in that array.

Try It Online! (Ideone)

Title: Permutapalindromic numbers

Body:
Given an integer N as input, output the Nth permutapalindromic number.

A permutapalindromic number is a strictly positive integer such that there is at least one permutation of its digits that results in a palindrome (i.e. a number that is its own reverse).

For example, 117 is a permutapalindromic number since its digits can be permuted into 171, which is a palindrome.

We consider that numbers like 10 are not permutapalindromic numbers, even though 01 = 1 is a palindrome. We impose that the palindromic permutation must not have a leading zero (as such, 0 itself is not permutapalindromic).

Numbers that are already palindromes are also permutapalindromic, since permuting nothing is valid.

Inputs and outputs

N may be either 0-indexed or 1-indexed. Please indicate which of the two your answer uses.

The input can be taken through STDIN, as a function argument, or anything similar in your language of choice. The output can be written to STDOUT, returned from a function, or anything similar in your language of choice.

The input and output must be in the decimal base.

Test cases

The following test cases are 1-indexed. Your program must be able to pass any of the test cases presented here in at most 1 minute.

```<code>N      Output

1      1
2      2
3      3
4      4
5      5
6      6
7      7
8      8
9      9
10     11
42     181
100    404
128    511
256    994
270    1166
</code>```

Scoring

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

Body:
Python 2.7, <s>163</s> 154 bytes:

from itertools import*;I,F,Q=input(),[],2
while len(F)<I:F=[g for g in range(1,Q)if any(i==i[::-1]*(i[0]>'0')for i in permutations(`g`))];Q+=1
print F[-1]

Simple enough. Basically uses a while loop to repeatedly create arrays containing permutapalindromic numbers the the range [1,Q) until Q is large enough such that the array contains Input number of items. It then outputs the last element in that array.

Try It Online! (Ideone)


答:
TSQL, 143 bytes

Not using build ins to convert from and to binary.

Golfed:

```<code>DECLARE @i INT=65000

,@ CHAR(99)=''WHILE @i>0SELECT @=REPLACE(LEFT(@i%2,1)+@,'00',0),@i/=2WHILE @>''SELECT @i+=LEFT(@,1)*POWER(2,LEN(@)-1),@=STUFF(@,1,1,'')PRINT @i
</code>```

Ungolfed:

```<code>DECLARE @i INT=65000

,@ CHAR(99)=''
WHILE @i>0
  SELECT @=REPLACE(LEFT(@i%2,1)+@,'00',0),@i/=2

WHILE @>''
  SELECT @i+=LEFT(@,1)*POWER(2,LEN(@)-1),@=STUFF(@,1,1,'')

PRINT @i
</code>```

Fiddle

Title: Output "Fit" numbers

Body:
TSQL, 143 bytes

Not using build ins to convert from and to binary.

Golfed:

DECLARE @i INT=65000

,@ CHAR(99)=''WHILE @i>0SELECT @=REPLACE(LEFT(@i%2,1)+@,'00',0),@i/=2WHILE @>''SELECT @i+=LEFT(@,1)*POWER(2,LEN(@)-1),@=STUFF(@,1,1,'')PRINT @i

Ungolfed:

DECLARE @i INT=65000

,@ CHAR(99)=''
WHILE @i>0
  SELECT @=REPLACE(LEFT(@i%2,1)+@,'00',0),@i/=2

WHILE @>''
  SELECT @i+=LEFT(@,1)*POWER(2,LEN(@)-1),@=STUFF(@,1,1,'')

PRINT @i

Fiddle


问:
Deciphering XKCD colors
Randall Munroe (author of XKCD) held a survey to give names to colors. The main outcome is a list of names for the 954 most common RGB monitor colors.

For ease of programming, here is the list in plain text: http://xkcd.com/color/rgb.txt. Beware, the first line is not data, but contains the license.

Write a program or function that takes a valid color name from above list as input and outputs the associated RGB color code. Your program does not have to handle invalid inputs in any defined manner.

Standard loopholes apply. Additionally, your answer must not use pre-defined (built-in or external) color code <-> color name maps. (This includes the linked list.) Shortest code in bytes wins. If you read from a file, the file's byte count must be included.

Examples:

```<code>dark peach -> #de7e5d
robin's egg blue -> #98eff9
pink/purple -> #ef1de7
</code>```

答:
Ruby, <s>12131</s> 12030 + -p = 12033 bytes

Byte count is after replacing <compressed text> with the raw paste data in http://pastebin.com/xQM6EF9Q. (Make sure you get the raw data because of tabs within the file)

I really could shrink the text further but I've been at it for a few hours now and I need to sleep.

Input is a piped-in line from STDIN without a trailing newline. Adding in trailing newline requires +3 bytes by changing ($_+?\t) to (chomp+?\t).

i="<compressed text>"
%w"Bblu Ddeep_ R*ight_ N*own Yyellow Tdirt Kdark Ldull_ Sdu} Qdusk Ee]ctric_ Ffaded_ G|een Iish A|ey Hlight Oor{g Ppa]_ Upurpl Cred Vvery_ -pink %ros ~sea .pea @egg ^burnt_ &baby ,poo =tea !t{ Mmedium_ $pa}el_ ;mud `aqua ?s{d >neon_ <lavend :gold +lime |gr ]le [mon }st {an *br".map{|x|i.gsub!x[0],x[1,99]}
$_=i.tr(?_,' ').lines.find{|s|($_+?\t)[/^#{s[/[^#]+/]}/]}[/#.*/]
```

Title: Deciphering XKCD colors


答:
Perl, 38 + 1 (-p) = 39 bytes

$_=oct"0b".sprintf("%b",$_)=~s/0+/0/gr
```
<p>Needs <code>-p</code> flag to run (I added <code>-l</code> flag to make it more readable, but it's not needed otherwise) :</p>
```perl -plE '$_=oct"0b".sprintf("%b",$_)=~s/0+/0/gr' <<< "1
9
15
13
16
17
65535
65000"
```

Note much to say about the code : it converts the number into binary (sprintf"%b"), then replaces blocs of zeros by just one zero, and converts the result into decimal (oct"0b".).

Title: Output "Fit" numbers

Body:
Perl, 38 + 1 (-p) = 39 bytes

$_=oct"0b".sprintf("%b",$_)=~s/0+/0/gr

Needs -p flag to run (I added -l flag to make it more readable, but it's not needed otherwise) :

perl -plE '$_=oct"0b".sprintf("%b",$_)=~s/0+/0/gr' <<< "1
9
15
13
16
17
65535
65000"

Note much to say about the code : it converts the number into binary (sprintf"%b"), then replaces blocs of zeros by just one zero, and converts the result into decimal (oct"0b".).


问:
Alphabet to Number and Number to Alphabet

Challenge

In this challenge you have to take a number as input and output the corresponding letter of the alphabet, and vice versa. (1 <=> A, 2 <=> B) etc.

```<code>1 -> A
2 -> B
...
26 -> Z

A -> 1
B -> 2
...
Z -> 26
</code>```

Rules

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

The input will only consist of either an uppercase letter from A to Z or an integer from 1 to 26 inclusive.

Trailing whitespaces (space and newline) are allowed.

答:
q, 44 bytes

Reads from stdin

```<code>{$[0N~i:"J"$x;1+.Q.A?x 0;.Q.A i-1]}[read0 0]
</code>```

Body:
q, 44 bytes

Reads from stdin

{$[0N~i:"J"$x;1+.Q.A?x 0;.Q.A i-1]}[read0 0]


答:
C, 19,566 bytes

A miserable 19,566 bytes.

```<code>#include <stdio.h>
int main(int argc,char **argv){int m=0;char *t=argv[1];int c=0;while(c!=EOF){if(m==1){if(c==10||c==13){printf("\n");m=2;}else{if(c>32)putchar(c);}}if(m==0){if(c==*t){t++;if(*t==0){m=1;printf("%s -> ",argv[1]);}}else{t=argv[1];}}c=getchar();}}
</code>```

Bog-standard C. The rgb.txt file is piped in through stdin. The colour to find is given as the first argument.

So:

./xkcd "bright sea green" < colors.txt

Gives:

bright sea green -> #05ffa6

Title: Deciphering XKCD colors

Body:
Randall Munroe (author of XKCD) held a survey to give names to colors. The main outcome is a list of names for the 954 most common RGB monitor colors.

For ease of programming, here is the list in plain text: http://xkcd.com/color/rgb.txt. Beware, the first line is not data, but contains the license.

Write a program or function that takes a valid color name from above list as input and outputs the associated RGB color code. Your program does not have to handle invalid inputs in any defined manner.

Standard loopholes apply. Additionally, your answer must not use pre-defined (built-in or external) color code <-> color name maps. (This includes the linked list.) Shortest code in bytes wins. If you read from a file, the file's byte count must be included.

Examples:

```<code>dark peach -> #de7e5d
robin's egg blue -> #98eff9
pink/purple -> #ef1de7
</code>```

Body:
C, 19,566 bytes

A miserable 19,566 bytes.

#include <stdio.h>
int main(int argc,char **argv){int m=0;char *t=argv[1];int c=0;while(c!=EOF){if(m==1){if(c==10||c==13){printf("\n");m=2;}else{if(c>32)putchar(c);}}if(m==0){if(c==*t){t++;if(*t==0){m=1;printf("%s -> ",argv[1]);}}else{t=argv[1];}}c=getchar();}}

Bog-standard C. The rgb.txt file is piped in through stdin. The colour to find is given as the first argument.

So:

./xkcd "bright sea green" < colors.txt

Gives:

bright sea green -> #05ffa6


问:
Play a sound, any sound
Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

The program should run on a reasonable, not too uncommon personal computer.

Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.

Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.

答:
k/Q (6 chars)

Bell character to stdout.

```<code>1"c"$7
</code>```

Title: Play a sound, any sound

Body:
k/Q (6 chars)

Bell character to stdout.

1"c"$7


问:
Quick Golf: The Gold Leader

Challenge

Using data from the API here, output the names of the three countries with the most Olympic gold medals at the 2016 Rio Olympic Games (i.e. the first element of the returned list).

For example, at the time of posting (18:23 UTC+1, Monday, 15th August), the USA, the UK and China have the most gold medals, so the output would be:

```<code>United States
Great Britain
China
</code>```

The country names must be separated by newlines and you may have a leading or trailing newlines.

Once the Olympics have finished, the program does not have to work as expected.

URL shorteners are disallowed but JSON parsing libraries are allowed.

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

I'm going to keep trying to get an Olympics themed challenge in here

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Javascript 167 bytes

```<code>x=new XMLHttpRequest();x.open("GET","http://www.medalbot.com/api/v1/medals",false);x.send()
i=-3;while(i++)console.log(JSON.parse(x.responseText)[i+2]["country_name"])
</code>```

Title: Quick Golf: The Gold Leader

Body:
Javascript 167 bytes

x=new XMLHttpRequest();x.open("GET","http://www.medalbot.com/api/v1/medals",false);x.send()
i=-3;while(i++)console.log(JSON.parse(x.responseText)[i+2]["country_name"])


答:
BASH + bzip2, 8058 6809 6797 bytes

```<code>bunzip2 -c c|tr -d "\t"|grep -F "$1#"|cut -d "${1: -1}" -f2
</code>```

Stored the original list to a file after compressing it, not sure if this is allowed.

Call with:

```<code>sh ./colors.sh "shit"
</code>```

Title: Deciphering XKCD colors

Body:
BASH + bzip2, 8058 6809 6797 bytes

bunzip2 -c c|tr -d "\t"|grep -F "$1#"|cut -d "${1: -1}" -f2

Stored the original list to a file after compressing it, not sure if this is allowed.

Call with:

sh ./colors.sh "shit"


问:
Calculate the difficulty of a Code Golf question

Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where \$v\$ is the number of views a question has

and \$a\$ is the number of answers a question has

and \$⌈x⌉\$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases}
min & x < min \\
x   & min \le x \le max \\
max & max < x
\end{cases}$$

This question's current difficulty: ***

Task

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

Test Data

```<code>Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********
</code>```

Example with pseudocode

```<code>v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'
</code>```

The shortest code in bytes wins! Trailing/ leading spaces are allowed.

答:
javascript: <s>82</s> 73 bytes

```<code> (v,a)=>console.log("*".repeat(Math.min(Math.max(0,Math.ceil(v/a/70),10)))
</code>```

saved some bytes after Adám pointed out I overlooked the /700*10=/70, and the removal of parens

Body:
javascript: <s>82</s> 73 bytes

 (v,a)=>console.log("*".repeat(Math.min(Math.max(0,Math.ceil(v/a/70),10)))

saved some bytes after Adám pointed out I overlooked the /700*10=/70, and the removal of parens


答:
Dyalog APL, 15 bytes

'*'⍴⍨10⌊⌈⎕÷70×⎕
```

'*'⍴⍨ the character repeated this many times:

10⌊ min(10,...

⎕÷ input divided by

70× seventy times

⎕ input

TryAPL online!

Title: Calculate the difficulty of a Code Golf question

Body:
Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where \$v\$ is the number of views a question has

and \$a\$ is the number of answers a question has

and \$⌈x⌉\$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases}
min & x < min \\
x   & min \le x \le max \\
max & max < x
\end{cases}$$

This question's current difficulty: ***

Task

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

Test Data

```<code>Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********
</code>```

Example with pseudocode

```<code>v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'
</code>```

The shortest code in bytes wins! Trailing/ leading spaces are allowed.

Body:
Dyalog APL, 15 bytes

'*'⍴⍨10⌊⌈⎕÷70×⎕

'*'⍴⍨ the character repeated this many times:

10⌊ min(10,...

⎕÷ input divided by

70× seventy times

⎕ input

TryAPL online!


答:
Java, 75

int f(Integer x){return x.valueOf(x.toString(x,2).replaceAll("0+","0"),2);}
```
<p>Test program:</p>
<pre class="lang-java prettyprint-override"><code>public class Fit {
    int f(Integer x){return x.valueOf(x.toString(x,2).replaceAll("0+","0"),2);}

    public static void main(final String... args) {
        final Fit x = new Fit();
        System.out.println(x.f(65000));
    }
}
</code>```

Title: Output "Fit" numbers

Body:
Java, 75

int f(Integer x){return x.valueOf(x.toString(x,2).replaceAll("0+","0"),2);}

Test program:

public class Fit {
    int f(Integer x){return x.valueOf(x.toString(x,2).replaceAll("0+","0"),2);}

    public static void main(final String... args) {
        final Fit x = new Fit();
        System.out.println(x.f(65000));
    }
}


答:
C#, <s>97</s> <s>89</s> <s>87</s> <s>77</s> <s>42</s> 41 bytes

```<code>v=>a=>new string('*',(v/=a*70)<9?v+1:10);
</code>```

Saved 10 bytes thanks to Adám

Saved a few bytes thanks to Arnauld

Body:
C#, <s>97</s> <s>89</s> <s>87</s> <s>77</s> <s>42</s> 41 bytes

v=>a=>new string('*',(v/=a*70)<9?v+1:10);

Saved 10 bytes thanks to Adám

Saved a few bytes thanks to Arnauld


答:
Perl, 7,375 bytes

Stores slightly compressed data (grey -> E, etc) as compressed binary data, expands it into a hash and returns the matching key after replacing spaces in the input with _. I don't think it's that great, and am certain others will have much more intelligent methods for compressing the data, I might play with this more later on.

use IO::Uncompress::Gunzip qw(gunzip);gunzip\'<binary data>'=>\$_;for$v(qw{A/pale B/blue D/dark E/grey G/green I/bright L/light N/brown O/orange P/pink R/red U/purple Y/yellow}){eval"s/$v/g"}print"#".{m![/\w']+!g}->{<>=~s/ /_/gr}
```

<p>A reversible hexdump is available here which was generated using this script.</p>

<h3>Usage</h3>

<pre class="lang-sh prettyprint-override"><code>echo -n 'baby shit brown' | perl xkcd-colours.pl
#ad900d
</code>```

Title: Deciphering XKCD colors

Body:
Perl, 7,375 bytes

Stores slightly compressed data (grey -> E, etc) as compressed binary data, expands it into a hash and returns the matching key after replacing spaces in the input with _. I don't think it's that great, and am certain others will have much more intelligent methods for compressing the data, I might play with this more later on.

use IO::Uncompress::Gunzip qw(gunzip);gunzip\'<binary data>'=>\$_;for$v(qw{A/pale B/blue D/dark E/grey G/green I/bright L/light N/brown O/orange P/pink R/red U/purple Y/yellow}){eval"s/$v/g"}print"#".{m![/\w']+!g}->{<>=~s/ /_/gr}

A reversible hexdump is available here which was generated using this script.

Usage

echo -n 'baby shit brown' | perl xkcd-colours.pl
#ad900d


答:
JavaScript (ES6), <s>40</s> 39 bytes

```<code>v=>a=>"**********".substring(10-v/a/70)
</code>```

Because substring provides the required clamping and "ceil"ing behaviour. Edit: Normally I'm too lazy to bother, but because it got 4 upvotes, I've followed @MarsUltor's advice to save 1 byte by currying.

Body:
JavaScript (ES6), <s>40</s> 39 bytes

v=>a=>"**********".substring(10-v/a/70)

Because substring provides the required clamping and "ceil"ing behaviour. Edit: Normally I'm too lazy to bother, but because it got 4 upvotes, I've followed @MarsUltor's advice to save 1 byte by currying.


答:
C#, <s>68</s> <s>49</s> 48 bytes

```<code>v=>a=>"**********".Substring((int)(10-v/a/70d));
</code>```

This is the C# version of this excellent answer by Neil.

Saved another 19 bytes thanks to Neil

Body:
C#, <s>68</s> <s>49</s> 48 bytes

v=>a=>"**********".Substring((int)(10-v/a/70d));

This is the C# version of this excellent answer by Neil.

Saved another 19 bytes thanks to Neil


答:
R 9

The bell character

```<code>cat("\a")
</code>```

Title: Play a sound, any sound

Body:
Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

The program should run on a reasonable, not too uncommon personal computer.

Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.

Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.

Body:
R 9

The bell character

cat("\a")


答:
Pyth, <s>17</s> 13 bytes

4 bytes in credit to Luis Mendo for his algorithm.

```
<s>*\*htS[0T.EccFQ70</s>
*\*s>LccFQ70T
```

Test suite.

Body:
Pyth, <s>17</s> 13 bytes

4 bytes in credit to Luis Mendo for his algorithm.

<s>*\*htS[0T.EccFQ70</s>
*\*s>LccFQ70T

Test suite.


答:
MATL, 12 bytes

```<code>/70/0:9>42*c
</code>```

Try it online!

Explanation

The rounding up and clamping are done simultaneously as follows: the number x = v/a/70 is compared against each element of the array [0 1 ... 9]. The numbers of that array that are exceeded by x will become asterisks, and the rest will be spaces.

```<code>/      % Take the two numbers implicitly. Divide. (Example: for inputs 3067, 15
       % we get 204.47)
70/    % Divide by 70 (we get 2.92)
0:9    % Push array [0 1  ... 9]
>      % See which of those are exceeded by the previous number (2.92 exceeds
       % 0, 1 and 2, so we get [1 1 1 0 ... 0]). This does the rounding up
       % and the clamping
42*    % Multiply by 42, which is the ASCII code of '*' (we get [42 42 42 0 ... 0])
       % Char 0 will be displayed as space
c      % Convert to char. Implicitly display
</code>```

Body:
MATL, 12 bytes

/70/0:9>42*c

Try it online!

Explanation

The rounding up and clamping are done simultaneously as follows: the number x = v/a/70 is compared against each element of the array [0 1 ... 9]. The numbers of that array that are exceeded by x will become asterisks, and the rest will be spaces.

/      % Take the two numbers implicitly. Divide. (Example: for inputs 3067, 15
       % we get 204.47)
70/    % Divide by 70 (we get 2.92)
0:9    % Push array [0 1  ... 9]
>      % See which of those are exceeded by the previous number (2.92 exceeds
       % 0, 1 and 2, so we get [1 1 1 0 ... 0]). This does the rounding up
       % and the clamping
42*    % Multiply by 42, which is the ASCII code of '*' (we get [42 42 42 0 ... 0])
       % Char 0 will be displayed as space
c      % Convert to char. Implicitly display


答:
Pyth, 14

```<code>e.ff&_ITshT.p`
</code>```

Try it here or run a Test Suite

Expansion:

```<code>e.ff&_ITshT.p`ZQ   # Auto-fill variables
 .f            Q   # Find the first input number of numbers that give truthy on ...
           .p`Z    # Take all the permutations of the current number
   f&              # Keep those that give a truthy value for both:
     _IT           # Invariance on reversing (is a palindrome)
        shT        # The integer value of the first digit (doesn't start with zero)
                   # A list with any values in it it truthy, so if any permutation matches
                   # these conditions, the number was a permutapalindrome
e                  # Take only the last number
</code>```

Title: Permutapalindromic numbers

Body:
Given an integer N as input, output the Nth permutapalindromic number.

A permutapalindromic number is a strictly positive integer such that there is at least one permutation of its digits that results in a palindrome (i.e. a number that is its own reverse).

For example, 117 is a permutapalindromic number since its digits can be permuted into 171, which is a palindrome.

We consider that numbers like 10 are not permutapalindromic numbers, even though 01 = 1 is a palindrome. We impose that the palindromic permutation must not have a leading zero (as such, 0 itself is not permutapalindromic).

Numbers that are already palindromes are also permutapalindromic, since permuting nothing is valid.

Inputs and outputs

N may be either 0-indexed or 1-indexed. Please indicate which of the two your answer uses.

The input can be taken through STDIN, as a function argument, or anything similar in your language of choice. The output can be written to STDOUT, returned from a function, or anything similar in your language of choice.

The input and output must be in the decimal base.

Test cases

The following test cases are 1-indexed. Your program must be able to pass any of the test cases presented here in at most 1 minute.

```<code>N      Output

1      1
2      2
3      3
4      4
5      5
6      6
7      7
8      8
9      9
10     11
42     181
100    404
128    511
256    994
270    1166
</code>```

Scoring

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

Body:
Pyth, 14

e.ff&_ITshT.p`

Try it here or run a Test Suite

Expansion:

e.ff&_ITshT.p`ZQ   # Auto-fill variables
 .f            Q   # Find the first input number of numbers that give truthy on ...
           .p`Z    # Take all the permutations of the current number
   f&              # Keep those that give a truthy value for both:
     _IT           # Invariance on reversing (is a palindrome)
        shT        # The integer value of the first digit (doesn't start with zero)
                   # A list with any values in it it truthy, so if any permutation matches
                   # these conditions, the number was a permutapalindrome
e                  # Take only the last number


答:
CJam, 16

```<code>q~2b1+0a%0a*);2b
</code>```

Try it online

It's quite long due to lack of regex.

Explanation:

```<code>q~     read and evaluate the input number
2b     convert to base 2 (array of 1s and 0s)
1+     append a 1 to deal with trailing zeros
0a%    split by [0], dropping empty pieces; only chunks of 1s are left
0a*    join by [0]
);     discard the 1 we appended before
2b     convert back from base 2
</code>```

Title: Output "Fit" numbers

Body:
"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

Body:
CJam, 16

q~2b1+0a%0a*);2b

Try it online

It's quite long due to lack of regex.

Explanation:

q~     read and evaluate the input number
2b     convert to base 2 (array of 1s and 0s)
1+     append a 1 to deal with trailing zeros
0a%    split by [0], dropping empty pieces; only chunks of 1s are left
0a*    join by [0]
);     discard the 1 we appended before
2b     convert back from base 2


答:
PowerShell v2+, 47 bytes

```<code>-join(('*'*11)[1..($args[0]/$args[1]/70+.499)])
</code>```

Somewhat a port of @Neil's JavaScript answer.

Takes input $args and divides them, then divides that by 70, and adds .499. Since PowerShell does banker's rounding, this is effectively ceil to two decimal points of precision. If additional precision is required, tack on as many additional 9s as required.

Along with the 1.., this forms a range index into a string. The string is '*'*11, i.e. '***********'. That results in a char-array, so we -join it together back into a string. That string is left on the pipeline and output is implicit. Like Neil's answer, this effectively "clamps" the output to be between 1 and 10 stars.

Test Suite

```<code>PS C:\Tools\Scripts\golfing> @(@(163,2), @(548,22), @(1452,24), @(1713,37), @(4162,32), @(3067,15), @(22421,19))|%{($_-join', ')+" -> " +(.\difficulty-of-a-question $_[0] $_[1])}
163, 2 -> **
548, 22 -> *
1452, 24 -> *
1713, 37 -> *
4162, 32 -> **
3067, 15 -> ***
22421, 19 -> **********
</code>```

Body:
PowerShell v2+, 47 bytes

-join(('*'*11)[1..($args[0]/$args[1]/70+.499)])

Somewhat a port of @Neil's JavaScript answer.

Takes input $args and divides them, then divides that by 70, and adds .499. Since PowerShell does banker's rounding, this is effectively ceil to two decimal points of precision. If additional precision is required, tack on as many additional 9s as required.

Along with the 1.., this forms a range index into a string. The string is '*'*11, i.e. '***********'. That results in a char-array, so we -join it together back into a string. That string is left on the pipeline and output is implicit. Like Neil's answer, this effectively "clamps" the output to be between 1 and 10 stars.

Test Suite

PS C:\Tools\Scripts\golfing> @(@(163,2), @(548,22), @(1452,24), @(1713,37), @(4162,32), @(3067,15), @(22421,19))|%{($_-join', ')+" -> " +(.\difficulty-of-a-question $_[0] $_[1])}
163, 2 -> **
548, 22 -> *
1452, 24 -> *
1713, 37 -> *
4162, 32 -> **
3067, 15 -> ***
22421, 19 -> **********


答:
CJam, <s>18</s> <s>15</s> 14 bytes

Saved 1 byte thanks to Peter Taylor and 3 bytes thanks to Adnan

```<code>'*A*q~d/70/m]<
</code>```

Try it online

```<code>'*A*            e# Push "**********"
    q~d/        e# Get the input and divide the two numbers
        70/     e# Divide by 70
           m]   e# Ceil, yielding x
             <  e# Slice the string, taking the first x elements
</code>```

Body:
CJam, <s>18</s> <s>15</s> 14 bytes

Saved 1 byte thanks to Peter Taylor and 3 bytes thanks to Adnan

'*A*q~d/70/m]<

<a href="http://cjam.aditsu.net/#code='*A*%20%20%20%20%20%20%20%20%20%20%20%20e%23%20Push%20%22**********%22%0A%20%20%20%20q~d%2F%20%20%20%20%20%20%20%20e%23%20Get%20the%20input%20and%20divide%20the%20two%20numbers%0A%20%20%20%20%20%20%20%2070%2F%20%20%20%20%20e%23%20Divide%20by%2070%0A%20%20%20%20%20%20%20%20%20%20%20m%5D%20%20%20e%23%20Ceil%2C%20yielding%20x%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%20%20e%23%20Slice%20the%20string%2C%20taking%20the%20first%20x%20elements&input=1452%2024">Try it online

'*A*            e# Push "**********"
    q~d/        e# Get the input and divide the two numbers
        70/     e# Divide by 70
           m]   e# Ceil, yielding x
             <  e# Slice the string, taking the first x elements


答:
CJam, 23 bytes

```<code>ri2be`{_:g:>{:g}&}%e~2b
</code>```

Try it online!

Explanation

```<code>ri          e# Read input as an integer
2b          e# Convert to binary
e`          e# Run-length encoding. Gives a nested (2D) array with run-lengths
            e# and binary digits
{           e# This block is mapped over the outer array, i.e. is applied to
            e# each inner array
   _        e#   Duplicate the inner array
  :g        e#   Signum of each element of inner array
  :>        e#   This gives true if second element (digit) is false and first
            e#   element (run-length) is not zero. If so, we need to set that
            e#   run-length to 1
  {:g}&     e#   If that's the case, apply signum to original copy of inner
            e#   array, to make run-length 1
}%          e# End block which is mapped over the outer array
e~          e# Run-length decoding
2b          e# Convert from binary. Implicitly display
</code>```

Title: Output "Fit" numbers

Body:
CJam, 23 bytes

ri2be`{_:g:>{:g}&}%e~2b

Try it online!

Explanation

ri          e# Read input as an integer
2b          e# Convert to binary
e`          e# Run-length encoding. Gives a nested (2D) array with run-lengths
            e# and binary digits
{           e# This block is mapped over the outer array, i.e. is applied to
            e# each inner array
   _        e#   Duplicate the inner array
  :g        e#   Signum of each element of inner array
  :>        e#   This gives true if second element (digit) is false and first
            e#   element (run-length) is not zero. If so, we need to set that
            e#   run-length to 1
  {:g}&     e#   If that's the case, apply signum to original copy of inner
            e#   array, to make run-length 1
}%          e# End block which is mapped over the outer array
e~          e# Run-length decoding
2b          e# Convert from binary. Implicitly display


答:
Python2, 32 bytes

saved 3 + 2 bytes and corrected off by one error thanks to Leaky Nun

```<code>lambda v,a:('*'*10)[:~-v/a/70+1]
</code>```

similar to Neils answer. Uses the fact that Python2 does integer division.

Body:
Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where \$v\$ is the number of views a question has

and \$a\$ is the number of answers a question has

and \$⌈x⌉\$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases}
min & x < min \\
x   & min \le x \le max \\
max & max < x
\end{cases}$$

This question's current difficulty: ***

Task

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

Test Data

```<code>Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********
</code>```

Example with pseudocode

```<code>v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'
</code>```

The shortest code in bytes wins! Trailing/ leading spaces are allowed.

Body:
Python2, 32 bytes

saved 3 + 2 bytes and corrected off by one error thanks to Leaky Nun

lambda v,a:('*'*10)[:~-v/a/70+1]

similar to Neils answer. Uses the fact that Python2 does integer division.


答:
05AB1E, 11 bytes

```<code>/70/î'*T×s£
</code>```

Explanation

```<code>/            # divide v by a
 70/         # divide by 70
    î        # round up, call this n
     '*T×    # push 10 asterisks
         s£  # take n up to 10 asterisk
             # implicitly print
</code>```

Try it online

Body:
05AB1E, 11 bytes

/70/î'*T×s£

Explanation

/            # divide v by a
 70/         # divide by 70
    î        # round up, call this n
     '*T×    # push 10 asterisks
         s£  # take n up to 10 asterisk
             # implicitly print

Try it online


问:
Find the minimum edit distance between two strings

Explanation

The edit distance between two strings is a function of the minimum possible number of insertions, deletions, or substitutions to convert one word into another word.

Insertions and deletions cost 1, and substitutions cost 2.

For example, the distance between AB and A is 1, because deletions cost 1 and the only edit needed is the deletion of the B character.

The distance between CAR and FAR is 2, because substitutions cost 2. Another way to look at this is one deletion and one insertion.

Rules

Given two input strings (supplied however is convenient in your language), your program must find the minimum edit distance between the two strings.

You may assume that the strings only contain the characters A-Z and have fewer than 100 characters and more than 0 characters.

This is code golf, so the shortest solution wins.

Sample Test Cases

```<code>ISLANDER, SLANDER
> 1
MART, KARMA
> 5
KITTEN, SITTING
> 5
INTENTION, EXECUTION
> 8
</code>```

答:
R 51

This reads in two lines from the user (which are the input) and then just uses the adist function to calculate the distance.  Since substitutions cost 2 for this problem we need to add a named vector for the costs parameter for adist.  Since there is also a counts parameter for adist we can only shorten costs to cos so we still have a unique match for the parameter names.

```<code>x=readLines(n=2);adist(x[1],x[2],cos=c(i=1,d=1,s=2))
</code>```

Example use

```<code>> x=readLines(n=2);adist(x[1],x[2],cos=c(i=1,d=1,s=2))
MART
KARMA
     [,1]
[1,]    5
</code>```

Body:
R 51

This reads in two lines from the user (which are the input) and then just uses the adist function to calculate the distance.  Since substitutions cost 2 for this problem we need to add a named vector for the costs parameter for adist.  Since there is also a counts parameter for adist we can only shorten costs to cos so we still have a unique match for the parameter names.

x=readLines(n=2);adist(x[1],x[2],cos=c(i=1,d=1,s=2))

Example use

> x=readLines(n=2);adist(x[1],x[2],cos=c(i=1,d=1,s=2))
MART
KARMA
     [,1]
[1,]    5


答:
Java, 64 bytes

```<code>i->{return i.parseInt(i.toString(i,2).replaceAll("0+","0"),2);};
</code>```

Test Program

```<code>public static void main(String[] args) {
    Function<Integer, Integer> function = i -> {
        return i.parseInt(i.toString(i, 2).replaceAll("0+", "0"), 2);
    };

    System.out.println(function.apply(1)); // 1
    System.out.println(function.apply(9)); // 5
    System.out.println(function.apply(15)); // 15
    System.out.println(function.apply(13)); // 13
    System.out.println(function.apply(16)); // 2
    System.out.println(function.apply(17)); // 5
    System.out.println(function.apply(65535)); // 65535
}
</code>```

Title: Output "Fit" numbers

Body:
Java, 64 bytes

i->{return i.parseInt(i.toString(i,2).replaceAll("0+","0"),2);};

Test Program

public static void main(String[] args) {
    Function<Integer, Integer> function = i -> {
        return i.parseInt(i.toString(i, 2).replaceAll("0+", "0"), 2);
    };

    System.out.println(function.apply(1)); // 1
    System.out.println(function.apply(9)); // 5
    System.out.println(function.apply(15)); // 15
    System.out.println(function.apply(13)); // 13
    System.out.println(function.apply(16)); // 2
    System.out.println(function.apply(17)); // 5
    System.out.println(function.apply(65535)); // 65535
}


答:
Javascript ES6, 48 bytes

```<code>a=>b=>"*".repeat(Math.ceil(Math.min(a/b/70,10)))
</code>```

Body:
Javascript ES6, 48 bytes

a=>b=>"*".repeat(Math.ceil(Math.min(a/b/70,10)))


答:
JavaScript, 41 bytes

x=>-x?(9+x).toString(36):parseInt(x,36)-9
```

Title: Alphabet to Number and Number to Alphabet

Body:
Challenge

In this challenge you have to take a number as input and output the corresponding letter of the alphabet, and vice versa. (1 <=> A, 2 <=> B) etc.

```<code>1 -> A
2 -> B
...
26 -> Z

A -> 1
B -> 2
...
Z -> 26
</code>```

Rules

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

The input will only consist of either an uppercase letter from A to Z or an integer from 1 to 26 inclusive.

Trailing whitespaces (space and newline) are allowed.


答:
EXCEL, 18 (+ 18269)

Just to set a baseline, I will show the simplest Excel solution that I could think of:

Code

The code in Excel is very simple:

```<code>=VLOOKUP("";A:B;2)
</code>```

The input should be placed between the double quotes.

Data

The data should be stored in a .csv file, looking rougly like this:

pinkish purple;#d648d7

When I click on the CSV it automatically opens excel, and places the data in columns A and B, you may need a different separator.

Title: Deciphering XKCD colors

Body:
Randall Munroe (author of XKCD) held a survey to give names to colors. The main outcome is a list of names for the 954 most common RGB monitor colors.

For ease of programming, here is the list in plain text: http://xkcd.com/color/rgb.txt. Beware, the first line is not data, but contains the license.

Write a program or function that takes a valid color name from above list as input and outputs the associated RGB color code. Your program does not have to handle invalid inputs in any defined manner.

Standard loopholes apply. Additionally, your answer must not use pre-defined (built-in or external) color code <-> color name maps. (This includes the linked list.) Shortest code in bytes wins. If you read from a file, the file's byte count must be included.

Examples:

```<code>dark peach -> #de7e5d
robin's egg blue -> #98eff9
pink/purple -> #ef1de7
</code>```

Body:
EXCEL, 18 (+ 18269)

Just to set a baseline, I will show the simplest Excel solution that I could think of:

Code

The code in Excel is very simple:

=VLOOKUP("";A:B;2)

The input should be placed between the double quotes.

Data

The data should be stored in a .csv file, looking rougly like this:

pinkish purple;#d648d7

When I click on the CSV it automatically opens excel, and places the data in columns A and B, you may need a different separator.


答:
R,  68, 50 52  bytes

```<code>f=function(v,a)cat(rep("*",1+min(v/a/70,10)),sep="")
</code>```

rep implicitly places a min on number of 0.

Thanks to @plannapus and @Anastasiya-Romanova秀  for spotting my error.

Body:
R,  68, 50 52  bytes

f=function(v,a)cat(rep("*",1+min(v/a/70,10)),sep="")

rep implicitly places a min on number of 0.

Thanks to @plannapus and @Anastasiya-Romanova秀  for spotting my error.


Body:
Javascript (ES6), <s>37</s> 36 bytes

v=>a=>"*".repeat((v/=a*70)<9?v+1:10)

Saved 1 byte by currying, thanks to TheLethalCoder

let F=
v=>a=>"*".repeat((v/=a*70)<9?v+1:10)

console.log("Test #1:", F(163)(2))    // **
console.log("Test #2:", F(548)(22))   // *
console.log("Test #3:", F(1452)(24))  // *
console.log("Test #4:", F(1713)(37))  // *
console.log("Test #5:", F(4162)(32))  // **
console.log("Test #6:", F(3067)(15))  // ***
console.log("Test #7:", F(22421)(19)) // **********


问:
Check if input is permutation of source

Inspired by Input ∩ Source Code.

Task

Your task is to determine whether the input is a permutation of the source code.

Input

A string. Input is flexible; it should be able to handle the character encoding used for the source code.

Output

You may only have two possible outputs, one when the input is a permutation of the source code, and one when it is not. Those outputs maybe be of any length (including 0) but must be distinct, consistent, and deterministic.

Specs

Similar to quine challenges, the program/function may not read its own source code and 0-byte solutions are not allowed.

Example

If your source code is ppcg, then an input of cpgp or ppcg would be a permutation of the source code while cpg or cggp or caqp or cpaqr would not be.

答:
Python 2.7, <s>135</s> 112 bytes

```<code>print sorted(list(input()))==sorted(list('\''*7+'\\'*3+'print sorted(list(input()))==sorted(list(*7+*3+*2))'*2))
</code>```

Title: Check if input is permutation of source

Body:
Python 2.7, <s>135</s> 112 bytes

print sorted(list(input()))==sorted(list('\''*7+'\\'*3+'print sorted(list(input()))==sorted(list(*7+*3+*2))'*2))


答:
Haskell, 35 bytes

```<code>v#a=[1..min(ceiling$v/a/70)10]>>"*"
</code>```

[1..min(ceiling$v/a/70)10] creates a range from 1 to the computed difficulty (an empty list for difficulty 0). a>>b repeats the list b length a often.

Body:
Haskell, 35 bytes

v#a=[1..min(ceiling$v/a/70)10]>>"*"

[1..min(ceiling$v/a/70)10] creates a range from 1 to the computed difficulty (an empty list for difficulty 0). a>>b repeats the list b length a often.


答:
sh 6

```<code>echo .
</code>```

(where the . is in fact a BELL character)

The HEX representation of the above code is:

```<code>65 63 68 6f 20 07
</code>```

Title: Play a sound, any sound

Body:
Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

The program should run on a reasonable, not too uncommon personal computer.

Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.

Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.

Body:
sh 6

echo .

(where the . is in fact a BELL character)

The HEX representation of the above code is:

65 63 68 6f 20 07


答:
Mathematica, <s>38</s> 35 bytes

```<code>StringRepeat["*",10,⌈#/#2/70⌉]&
</code>```

Thanks to @MartinEnder for 3 bytes

Body:
Mathematica, <s>38</s> 35 bytes

StringRepeat["*",10,⌈#/#2/70⌉]&

Thanks to @MartinEnder for 3 bytes


问:
A047841: Autobiographical numbers

Definition

Here is the process to describe a number:

For each number from 0 to 9 that is present in the number:

Write down the frequency of that digit and then the digit.

For example, for the number 10213223:

There is 1 occurrence of 0,

2 occurrences of 1,

3 occurrences of 2,

2 occurrences of 3.

Therefore, the number that describes 10213223 is 10213223 (10 from the first property, 21 from the second, etc.).

Note that the number of occurrences of a digit may be greater than 9.

Task

You are to print/output all numbers that describe themselves.

Specs

Standard loopholes apply, except that you are allowed to hardcode the output or store information related to the output in your program.

The numbers in the output can be in any order.

The numbers in the output are allowed to have duplicates.

You may use any separator, if you choose to print instead of output.

You are allowed to prefix and/or postfix output if you choose to print instead of output.

The separator and the prefix and the postfix may not contain any digits (U+0030 to U+0039).

The solution must compute in one day.

Full list (109 items)

```<code>22
10213223
10311233
10313314
10313315
10313316
10313317
10313318
10313319
21322314
21322315
21322316
21322317
21322318
21322319
31123314
31123315
31123316
31123317
31123318
31123319
31331415
31331416
31331417
31331418
31331419
31331516
31331517
31331518
31331519
31331617
31331618
31331619
31331718
31331719
31331819
1031223314
1031223315
1031223316
1031223317
1031223318
1031223319
3122331415
3122331416
3122331417
3122331418
3122331419
3122331516
3122331517
3122331518
3122331519
3122331617
3122331618
3122331619
3122331718
3122331719
3122331819
10413223241516
10413223241517
10413223241518
10413223241519
10413223241617
10413223241618
10413223241619
10413223241718
10413223241719
10413223241819
41322324151617
41322324151618
41322324151619
41322324151718
41322324151719
41322324151819
41322324161718
41322324161719
41322324161819
41322324171819
1051322314251617
1051322314251618
1051322314251619
1051322314251718
1051322314251719
1051322314251819
1051322325161718
1051322325161719
1051322325161819
1051322325171819
5132231425161718
5132231425161719
5132231425161819
5132231425171819
5132232516171819
106132231415261718
106132231415261719
106132231415261819
106132231426171819
106132231526171819
613223141526171819
1011112131415161718
1011112131415161719
1011112131415161819
1011112131415171819
1011112131416171819
1011112131516171819
1011112141516171819
1011113141516171819
1111213141516171819
10713223141516271819
101112213141516171819
</code>```

References

Autobiographical numbers: OEIS A047841

Biographical number: OEIS A047842

答:
Ruby, 776 bytes

The rules say that "you are allowed to hardcode the output", so this solution does just that.

```<code>x="m|62wkn|65075|651sy|651sz|651t0|651t1|651t2|651t3|cp0ei|cp0ej|cp0ek|cp0el|cp0em|cp0en|ij2wi|ij2wj|ij2wk|ij2wl|ij2wm|ij2wnAh3Ah4Ah5Ah6Ah7AjwAjxAjyAjzAmpAmqAmrApiApjAsb|h1yp02|h1yp03|h1yp04|h1yp05|h1yp06|h1yp07Bc7Bc8Bc9BcaBcbBf0Bf1Bf2Bf3BhtBhuBhvBkmBknBnfFh8Fh9FhaFhbFk1Fk2Fk3FmuFmvFpnC08xC08yC08zC0bqC0brC0ejC81iC81jC84bCfu3EsxkfohEsxkfoiEsxkfojEsxkfraEsxkfrbEsxkfu3Et429yuEt429yvEt42a1nEt42hrf|1ej82kg93hy|1ej82kg93hz|1ej82kg93kr|1ej82kg9baj|1ej832ht8a3|t10qi0rmwpi|t10qi0rmwpj|t10qi0rmwsb|t10qi0y4qzv|t10qi2lo3hn|4nq1gm5kd1grG4p2zeraG4p2zerbG4p2zeu3G4p2zmjvG4p3l25nG4qr4enfG9c4v417|7ojtp0qb1maz|8fxg6lw9mtyj|29e6onjxe94gb|lc7bc5zbz4je3";a="|inj,|1fmye,|enb7ow,|enb7,|acnu,|3ovro98,|7ojtc".split',';b="ABCDEFG";7.times{|i|x.gsub! b[i],a[i]};x.split('|').map{|x|p x.to_i 36}
</code>```

Ruby, 116 bytes

A much shorter program that takes way too long to run, but given long enough should be able to do it. I do not know if it fits the time constraint.

```<code>f=->n{(?0..?9).map{|x|[n.to_s.chars.count{|c|c==x},x]}.select{|a|a[0]>0}.join.to_i}
(10**9).times{|i|p i if i==f[i]}
</code>```

Title: A047841: Autobiographical numbers

Body:
Ruby, 776 bytes

The rules say that "you are allowed to hardcode the output", so this solution does just that.

x="m|62wkn|65075|651sy|651sz|651t0|651t1|651t2|651t3|cp0ei|cp0ej|cp0ek|cp0el|cp0em|cp0en|ij2wi|ij2wj|ij2wk|ij2wl|ij2wm|ij2wnAh3Ah4Ah5Ah6Ah7AjwAjxAjyAjzAmpAmqAmrApiApjAsb|h1yp02|h1yp03|h1yp04|h1yp05|h1yp06|h1yp07Bc7Bc8Bc9BcaBcbBf0Bf1Bf2Bf3BhtBhuBhvBkmBknBnfFh8Fh9FhaFhbFk1Fk2Fk3FmuFmvFpnC08xC08yC08zC0bqC0brC0ejC81iC81jC84bCfu3EsxkfohEsxkfoiEsxkfojEsxkfraEsxkfrbEsxkfu3Et429yuEt429yvEt42a1nEt42hrf|1ej82kg93hy|1ej82kg93hz|1ej82kg93kr|1ej82kg9baj|1ej832ht8a3|t10qi0rmwpi|t10qi0rmwpj|t10qi0rmwsb|t10qi0y4qzv|t10qi2lo3hn|4nq1gm5kd1grG4p2zeraG4p2zerbG4p2zeu3G4p2zmjvG4p3l25nG4qr4enfG9c4v417|7ojtp0qb1maz|8fxg6lw9mtyj|29e6onjxe94gb|lc7bc5zbz4je3";a="|inj,|1fmye,|enb7ow,|enb7,|acnu,|3ovro98,|7ojtc".split',';b="ABCDEFG";7.times{|i|x.gsub! b[i],a[i]};x.split('|').map{|x|p x.to_i 36}

Ruby, 116 bytes

A much shorter program that takes way too long to run, but given long enough should be able to do it. I do not know if it fits the time constraint.

f=->n{(?0..?9).map{|x|[n.to_s.chars.count{|c|c==x},x]}.select{|a|a[0]>0}.join.to_i}
(10**9).times{|i|p i if i==f[i]}


答:
Jellyfish, 18 bytes

```<code>P
#'*
mM/%i
10 %70
</code>```

Takes input in the format [a v]. Try it online!

Explanation

% is reciprocal, so %70 is 1/70.

i is input, as a two-element array.

/% with inputs i and %70 reduces the array i by flipped division with initial value %70. In other words, it computes v/(a/(1/70)), which is equal to v / (70*a).

M takes the ceiling of this value, and m takes the maximum of that and 10.

#'* repeats the literal * character that many times.

P prints the result without quotes.

Body:
Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where \$v\$ is the number of views a question has

and \$a\$ is the number of answers a question has

and \$⌈x⌉\$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases}
min & x < min \\
x   & min \le x \le max \\
max & max < x
\end{cases}$$

This question's current difficulty: ***

Task

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

Test Data

```<code>Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********
</code>```

Example with pseudocode

```<code>v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'
</code>```

The shortest code in bytes wins! Trailing/ leading spaces are allowed.

Body:
Jellyfish, 18 bytes

P
#'*
mM/%i
10 %70

Takes input in the format [a v]. Try it online!

Explanation

% is reciprocal, so %70 is 1/70.

i is input, as a two-element array.

/% with inputs i and %70 reduces the array i by flipped division with initial value %70. In other words, it computes v/(a/(1/70)), which is equal to v / (70*a).

M takes the ceiling of this value, and m takes the maximum of that and 10.

#'* repeats the literal * character that many times.

P prints the result without quotes.


问:
Determine whether strings are anagrams

Challenge

Given two strings, work out if they both have exactly the same characters in them.

Example

Input

word, wrdo

This returns true because they are the same but just scrambled.

Input

word, wwro

This returns false.

Input

boat, toba

This returns true

Rules

Here are the rules!

Assume input will be at least 1 char long, and no longer than 8 chars.

No special characters, only a–z

All inputs can be assumed to be lowercase

Test Cases

```<code>boat, boat = true
toab, boat = true
oabt, toab = true
a, aa = false
zzz, zzzzzzzz = false
zyyyzzzz, yyzzzzzy = true
sleepy, pyels = false
p,p = true
</code>```

答:
Retina, 10 bytes

This answer is non-competing since Retina is much newer than this challenge. Byte count assumes ISO 8859-1 encoding.

```<code>%O`.
D`
¶$
</code>```

Input is linefeed-separated.

Try it online!

Explanation

```<code>%O`.
</code>```

This sorts (O) the individual characters (.) in each line (%), i.e. it sorts each input string separately.

```<code>D`
</code>```

This deduplicates the input on the (implicit) regex .*, which means it removes the characters from the second line if both strings are equal.

```<code>¶$
</code>```

Finally, this tries to match a linefeed followed by the end of the string. Since the input strings are guaranteed to be non-empty, this can only happen if the second string was removed in the previous stage.

Title: Determine whether strings are anagrams

Body:
Retina, 10 bytes

This answer is non-competing since Retina is much newer than this challenge. Byte count assumes ISO 8859-1 encoding.

%O`.
D`
¶$

Input is linefeed-separated.

Try it online!

Explanation

%O`.

This sorts (O) the individual characters (.) in each line (%), i.e. it sorts each input string separately.

D`

This deduplicates the input on the (implicit) regex .*, which means it removes the characters from the second line if both strings are equal.

¶$

Finally, this tries to match a linefeed followed by the end of the string. Since the input strings are guaranteed to be non-empty, this can only happen if the second string was removed in the previous stage.


答:
MATLAB, 34 33 bytes

Because I like this challange so much, here is one for MATLAB (outputs trailing whitespaces):

```<code>@(v,a)[(ceil(v/a/70)>0:9)*42,'']
</code>```

Inspired by @Luis Mendo's answer. Thanks to @pajonk for saving one byte.

Body:
MATLAB, 34 33 bytes

Because I like this challange so much, here is one for MATLAB (outputs trailing whitespaces):

@(v,a)[(ceil(v/a/70)>0:9)*42,'']

Inspired by @Luis Mendo's answer. Thanks to @pajonk for saving one byte.


Title: Output "Fit" numbers

Body:
"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

Body:
PARI/GP, <s>54</s> 43 bytes

n->fold((a,b)->a+if(b,a+1,a%2,a),binary(n))


答:
Perl, <s>35</s> 32 bytes

```<code>say"*"x(10-($-=10-pop()/70/pop))
</code>```

Use -E to activate say and give the arguments in the reverse order:

```<code>perl -E 'say"*"x(10-($-=10-pop()/70/pop))' 2 163
</code>```

If arguments on STDIN are allowed the following is 29 bytes:

```<code>(echo 163; echo 2) | perl -pe '$_="*"x(10-($-=10-$_/70/<>))'
</code>```

Body:
Perl, <s>35</s> 32 bytes

say"*"x(10-($-=10-pop()/70/pop))

Use -E to activate say and give the arguments in the reverse order:

perl -E 'say"*"x(10-($-=10-pop()/70/pop))' 2 163

If arguments on STDIN are allowed the following is 29 bytes:

(echo 163; echo 2) | perl -pe '$_="*"x(10-($-=10-$_/70/<>))'


答:
Ruby, 37 35 bytes

Saved two bytes thanks to manatwork.

```<code>->a{a.to_s(2).gsub(/0+/,?0).to_i 2}
</code>```

The naive approach. (:

Title: Output "Fit" numbers

Body:
Ruby, 37 35 bytes

Saved two bytes thanks to manatwork.

->a{a.to_s(2).gsub(/0+/,?0).to_i 2}

The naive approach. (:


答:
Jelly, 5 Bytes (Non-competitive)

```<code>Ṣ⁼⁴Ṣ¤
</code>```

Special thanks to Leaky Nun for helping me fix a problem.

Outputs one if true.
Try it Online!

Title: Determine whether strings are anagrams

Body:
Challenge

Given two strings, work out if they both have exactly the same characters in them.

Example

Input

word, wrdo

This returns true because they are the same but just scrambled.

Input

word, wwro

This returns false.

Input

boat, toba

This returns true

Rules

Here are the rules!

Assume input will be at least 1 char long, and no longer than 8 chars.

No special characters, only a–z

All inputs can be assumed to be lowercase

Test Cases

```<code>boat, boat = true
toab, boat = true
oabt, toab = true
a, aa = false
zzz, zzzzzzzz = false
zyyyzzzz, yyzzzzzy = true
sleepy, pyels = false
p,p = true
</code>```

Body:
Jelly, 5 Bytes (Non-competitive)

Ṣ⁼⁴Ṣ¤

Special thanks to Leaky Nun for helping me fix a problem.

Outputs one if true.
Try it Online!


答:
R, 145 bytes

```<code>g=function(n){d=b=0
while(d<n){b=b+1
if(sum(a<-table(strsplit(n<-as.character(b),""))%%2)==nchar(n)%%2&(!names(a)[1]==0|a[1]|sum(!a)>1))d=d+1}
b}
</code>```

ungolfed

```<code>f=function(b){
    a<-table(strsplit(n<-as.character(b),""))%%2
    sum(a)==nchar(n)%%2&(!names(a)[1]==0|a[1]|sum(!a)>1)
}
g=function(n){
    d=b=0
    while(d<n){
         b=b+a
         if(f(b)) d=d+1
    }
    b
}
</code>```

Essentially -- a function checking membership in permutapalindromic set, and a while loop incrementing until it finds the nth member.

Title: Permutapalindromic numbers

Body:
Given an integer N as input, output the Nth permutapalindromic number.

A permutapalindromic number is a strictly positive integer such that there is at least one permutation of its digits that results in a palindrome (i.e. a number that is its own reverse).

For example, 117 is a permutapalindromic number since its digits can be permuted into 171, which is a palindrome.

We consider that numbers like 10 are not permutapalindromic numbers, even though 01 = 1 is a palindrome. We impose that the palindromic permutation must not have a leading zero (as such, 0 itself is not permutapalindromic).

Numbers that are already palindromes are also permutapalindromic, since permuting nothing is valid.

Inputs and outputs

N may be either 0-indexed or 1-indexed. Please indicate which of the two your answer uses.

The input can be taken through STDIN, as a function argument, or anything similar in your language of choice. The output can be written to STDOUT, returned from a function, or anything similar in your language of choice.

The input and output must be in the decimal base.

Test cases

The following test cases are 1-indexed. Your program must be able to pass any of the test cases presented here in at most 1 minute.

```<code>N      Output

1      1
2      2
3      3
4      4
5      5
6      6
7      7
8      8
9      9
10     11
42     181
100    404
128    511
256    994
270    1166
</code>```

Scoring

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

Body:
R, 145 bytes

g=function(n){d=b=0
while(d<n){b=b+1
if(sum(a<-table(strsplit(n<-as.character(b),""))%%2)==nchar(n)%%2&(!names(a)[1]==0|a[1]|sum(!a)>1))d=d+1}
b}

ungolfed

f=function(b){
    a<-table(strsplit(n<-as.character(b),""))%%2
    sum(a)==nchar(n)%%2&(!names(a)[1]==0|a[1]|sum(!a)>1)
}
g=function(n){
    d=b=0
    while(d<n){
         b=b+a
         if(f(b)) d=d+1
    }
    b
}

Essentially -- a function checking membership in permutapalindromic set, and a while loop incrementing until it finds the nth member.


答:
><> 3

As in all answers, prints the bell (0x07) to stdout.

```<code>7o;
</code>```

Title: Play a sound, any sound

Body:
><> 3

As in all answers, prints the bell (0x07) to stdout.

7o;


答:
R, 69 bytes

```<code>a=function(b,d)identical(table(strsplit(b,"")),table(strsplit(d,"")))
</code>```

I think this is the shortest R implementation which deals with a("b","bb") being FALSE.

Title: Determine whether strings are anagrams

Body:
R, 69 bytes

a=function(b,d)identical(table(strsplit(b,"")),table(strsplit(d,"")))

I think this is the shortest R implementation which deals with a("b","bb") being FALSE.


答:
Perl 6, 66 bytes

{(1..*).grep(*.comb.permutations.grep({+.join.flip eq.join}))[$_]}
```

<p>0 based</p>

<h2>Explanation:</h2>

<pre class="lang-perl6 prettyprint-override"><code># bare block lambda which takes an implicit parameter ｢$_｣
{
  # all numbers greater than 0
  (1..*)\

  # remove any which aren't permutapalindromic
  .grep(

    # ｢*｣ here starts a Whatever lambda
    *\
    # split into list of digits
    .comb\
    # get all of the permutations of the digits
    .permutations\
    # find out if there are any palindromes
    .grep(

      # another bare block lambda taking ｢$_｣ as implicit parameter
      {
        # compare the current permutation with its reverse stringwise
        # numify only one side to get rid of leading ｢0｣
        +$_.join.flip eq $_.join
      }
    )

  # get the value at the index
  )[$_]
}
</code>```

Test:

#! /usr/bin/env perl6
use v6.c;
use Test;

my &permutapalindromic = {(1..*).grep(*.comb.permutations.grep({+.join.flip eq.join}))[$_]}

my @tests = (
  1   => 1,
  2   => 2,
  3   => 3,
  4   => 4,
  5   => 5,
  6   => 6,
  7   => 7,
  8   => 8,
  9   => 9,
  10  => 11,
  42  => 181,
  100 => 404,
  128 => 511,
  256 => 994,
  270 => 1166,
);

plan +@tests + 1;

my $start-time = now;
for @tests -> $_ ( :key($input), :value($expected) ) {
  # zero based instead of one based, so subtract 1
  is-deeply permutapalindromic( $input - 1 ), $expected, .gist;
}
my $finish-time = now;

my $total-time = $finish-time - $start-time;

cmp-ok $total-time, &[<], 60, 'Less than 60 seconds for the tests';
diag "$total-time seconds";
```

Title: Permutapalindromic numbers

Body:
Perl 6, 66 bytes

{(1..*).grep(*.comb.permutations.grep({+.join.flip eq.join}))[$_]}

0 based

Explanation:

# bare block lambda which takes an implicit parameter ｢$_｣
{
  # all numbers greater than 0
  (1..*)\

  # remove any which aren't permutapalindromic
  .grep(

    # ｢*｣ here starts a Whatever lambda
    *\
    # split into list of digits
    .comb\
    # get all of the permutations of the digits
    .permutations\
    # find out if there are any palindromes
    .grep(

      # another bare block lambda taking ｢$_｣ as implicit parameter
      {
        # compare the current permutation with its reverse stringwise
        # numify only one side to get rid of leading ｢0｣
        +$_.join.flip eq $_.join
      }
    )

  # get the value at the index
  )[$_]
}

Test:

#! /usr/bin/env perl6
use v6.c;
use Test;

my &permutapalindromic = {(1..*).grep(*.comb.permutations.grep({+.join.flip eq.join}))[$_]}

my @tests = (
  1   => 1,
  2   => 2,
  3   => 3,
  4   => 4,
  5   => 5,
  6   => 6,
  7   => 7,
  8   => 8,
  9   => 9,
  10  => 11,
  42  => 181,
  100 => 404,
  128 => 511,
  256 => 994,
  270 => 1166,
);

plan +@tests + 1;

my $start-time = now;
for @tests -> $_ ( :key($input), :value($expected) ) {
  # zero based instead of one based, so subtract 1
  is-deeply permutapalindromic( $input - 1 ), $expected, .gist;
}
my $finish-time = now;

my $total-time = $finish-time - $start-time;

cmp-ok $total-time, &[<], 60, 'Less than 60 seconds for the tests';
diag "$total-time seconds";


答:
Python 3, <s>69</s> 68 bytes

I didn't want to copy the Python 2 answer, so mine is slightly longer.

```<code>from math import*
x=lambda v,a:print(max(0,min(ceil(v/a/70),10))*'*')
</code>```

Saved 1 byte thanks to Program man

Body:
Python 3, <s>69</s> 68 bytes

I didn't want to copy the Python 2 answer, so mine is slightly longer.

from math import*
x=lambda v,a:print(max(0,min(ceil(v/a/70),10))*'*')

Saved 1 byte thanks to Program man


答:
dc, <s>110 108 104</s> 98 bytes

This was a doozy since slicing isn't a thing. Also, dc doesn't manipulate strings. I just really was waiting for a string one that would be < 5 hours of coding. On the plus side, I finally started writing down common constructs, like for loops. Also had to formulate rounding/ceiling, so thanks for that.

```<code>[42P]sd[dsi[li0!=dli1-dsi0!=L]dsLx]sl[Isi[li0!=dli1-dsi0!=L]dsLx]sg[1+]saIk/70*0k1~0!=adI>ldI!>gIP
</code>```

Invoked in bash:

```<code>echo 'v a (above)'|dc
# Wholly:
>> echo '163 2 [42P]sd[dsi[li0!=dli1-dsi0!=L]dsLx]sl[Isi[li0!=dli1-dsi0!=L]dsLx]sg[1+]saIk/70*0k1~0!=adI>ldI!>gIP'|dc
# outputs:
**
>>
</code>```

Replacing (above) with the code, and v and a with their respective counterparts above. The single quotes are important (otherwise you get bash's history stuff).

Explained:

```<code>[42P]sd   # Here we store a macro in register d to print 1 * without a newline

[dsi[li0!=dli1-dsi0!=L]dsLx]sl # Store the "less than" case, a for loop which
                        # uses the top-of the stack as it's number of iterations.
[Isi[li0!=dli1-dsi0!=L]dsLx]sg # Store the "greater than" case. It's the above,
                        # but it puts 10 on the stack to use instead.

[1+]sa # Store a macro to add 1 to whatever is the top-of-stack.

Ik # Set precision at non-zero to allow decimal division

/70* # Divide the top two of the stack, v/a; multiply by 70 (`/700*10` == `/70`)
             # dc is postfix and stack-based, so operators come after operands.

0k1~0!=a     # This is a ceiling function.
|> 0k  # set precision to 0 to perform integer division
|> 1~  # push the quotient of integer division by 1, and then the remainder. (r is top)
|> 0!=a # If the top-of-stack (decimal part) is not 0, add 1 to the quotient

dI>ldI!>g # Conditional statement
|> dI>l  # (d)uplicate the top, push 10 on. If 10 > the old top, execute the `l`ess-than
          # case, which loops top-of-stack times.
|> dI!>g # Complement of the above, using the `g`reater-than to loop 10 times.

IP # print a newline
</code>```

This is probably more golf-able, but I was trying to get it finished to avoid premature optimization.

2 bytes saved by duplicating-saving instead of saving-loading

4 bytes saved dividing by 70

6 bytes from daniero's suggestions (non-strings, ASCII nums instead; 10 => I)

Body:
dc, <s>110 108 104</s> 98 bytes

This was a doozy since slicing isn't a thing. Also, dc doesn't manipulate strings. I just really was waiting for a string one that would be < 5 hours of coding. On the plus side, I finally started writing down common constructs, like for loops. Also had to formulate rounding/ceiling, so thanks for that.

[42P]sd[dsi[li0!=dli1-dsi0!=L]dsLx]sl[Isi[li0!=dli1-dsi0!=L]dsLx]sg[1+]saIk/70*0k1~0!=adI>ldI!>gIP

Invoked in bash:

echo 'v a (above)'|dc
# Wholly:
>> echo '163 2 [42P]sd[dsi[li0!=dli1-dsi0!=L]dsLx]sl[Isi[li0!=dli1-dsi0!=L]dsLx]sg[1+]saIk/70*0k1~0!=adI>ldI!>gIP'|dc
# outputs:
**
>>

Replacing (above) with the code, and v and a with their respective counterparts above. The single quotes are important (otherwise you get bash's history stuff).

Explained:

[42P]sd   # Here we store a macro in register d to print 1 * without a newline

[dsi[li0!=dli1-dsi0!=L]dsLx]sl # Store the "less than" case, a for loop which
                        # uses the top-of the stack as it's number of iterations.
[Isi[li0!=dli1-dsi0!=L]dsLx]sg # Store the "greater than" case. It's the above,
                        # but it puts 10 on the stack to use instead.

[1+]sa # Store a macro to add 1 to whatever is the top-of-stack.

Ik # Set precision at non-zero to allow decimal division

/70* # Divide the top two of the stack, v/a; multiply by 70 (`/700*10` == `/70`)
             # dc is postfix and stack-based, so operators come after operands.

0k1~0!=a     # This is a ceiling function.
|> 0k  # set precision to 0 to perform integer division
|> 1~  # push the quotient of integer division by 1, and then the remainder. (r is top)
|> 0!=a # If the top-of-stack (decimal part) is not 0, add 1 to the quotient

dI>ldI!>g # Conditional statement
|> dI>l  # (d)uplicate the top, push 10 on. If 10 > the old top, execute the `l`ess-than
          # case, which loops top-of-stack times.
|> dI!>g # Complement of the above, using the `g`reater-than to loop 10 times.

IP # print a newline

This is probably more golf-able, but I was trying to get it finished to avoid premature optimization.

2 bytes saved by duplicating-saving instead of saving-loading

4 bytes saved dividing by 70

6 bytes from daniero's suggestions (non-strings, ASCII nums instead; 10 => I)


问:
Identify a string from its substrings

Introduction

I've previously created two challenges where the idea is to reconstruct an object using as few query-type operations as possible; this will be the third.

The task

Your inputs shall be a non-empty string S over the alphabet abc and its length, and your output shall be S.
With no restrictions, this would of course be a trivial task; the catch is that you're not allowed to access S directly.
The only thing you're allowed to do to S is to call the function num_occur(T, S), where T is some other string, and num_occur counts the number of occurrences of T in S.
Overlapping occurrences are counted as distinct, so num_occur(T, S) really returns the number of indices i such that

```<code>S[i, i+1, …, i+length(T)-1] == T</code>```

For example, num_occur("aba", "cababaababb") will return 3.
Note also that num_occur(S, S) will return 1.
The result of num_occur("", S) is undefined, and you should not call the function on an empty string.

In short, you should write a function or program that takes S and length(S) as inputs, calls num_occur on some shorter strings and S some number of times, reconstructs S from that information and returns it.

Rules and scoring

Your goal is to write a program that makes as few calls to num_occur as possible.
In this repository, you will find a file called abc_strings.txt.
The file contains 100 strings, each on its own line, between lengths 50 and 99.
Your score is the total number of calls to num_occur on these inputs, lower score being better.
Your solution will preferably keep track of this number as it runs, and print it upon finishing.
The strings are generated by choosing uniformly random letters from abc; you are allowed to optimize for this method of generating the strings, but not the strings themselves.

There is no time limit, except that you should run your solution on the test cases before submitting it.
You solution should work for any valid input S, not just the test cases.

You are encouraged to share your implementation of num_occur too, if you're not using someone else's.
To get the ball rolling, here's an implementation in Python:

```<code>def num_occur(needle, haystack):
    num = 0
    for i in range(len(haystack) - len(needle) + 1):
        if haystack[i : i + len(needle)] == needle:
            num += 1
    return num
</code>```

答:
Python <s>12705</s>  12632 calls

make a list of 2 characters strings occurrences

sort the list

build the string trying the most probable character first, don't test if there is only one possibility

update the list

if the list is empty it is finished else step 2

I used Loovjo function skeleton. I never code in Python I needed a bootsrap

EDIT:

Added code for one character length strings

Added code to reject already matched patterns

```<code>def finds(S):

    if len(S) == 0:
            return ""
    if len(S) == 1
            if num_occur("a",S) == 1 :
                         return "a"
            if num_occur("b",S) == 1 :
                         return "b"
            return "c"
    tuples=[]
    alphabet=[ "aa", "ab", "ac", "ba", "bb", "bc", "ca", "cb"]
    for s in alphabet : tuples.append( (num_occur(s,S), s) )

    sum=0
    for (i,s) in tuples :   sum+=i
    tuples.append( (len(S)-sum-1, "cc") )
    tuples.sort(key=lambda x:(-x[0],x[1]))

    (i, current) = tuples[0]
    tuples[0] = (i-1, current)

    add_at_start = True
    nomatch=[]
    while len(tuples) > 0:
            worked = False
            tuples.sort(key=lambda x:(-x[0],x[1]))
            count=0
            if not add_at_start :
                    for (n, s) in tuples :
                            if s[0]==current[-1:] :         count+=1
            for i in range(len(tuples)):
                    (n, s)=tuples[i]
                    if add_at_start:
                            if current[0] == s[1] :
                                    current_new = s[0] + current
                                    possible=True
                                    for nm in nomatch :
                                            lng=len(nm)
                                            if current_new[0:lng] == nm :
                                                    possible=False
                                                    break
                                    if possible and num_occur(current_new, S) > 0:
                                            current = current_new
                                            worked = True
                                    else :
                                            nomatch.append(current_new)
                    else:
                            if current[-1:] == s[0] :
                                    current_new =  current + s[1]
                                    possible=True
                                    for nm in nomatch :
                                            lng=len(nm)
                                            if current_new[-lng:] == nm :
                                                    possible=False
                                                    break
                                    if count == 1 or (possible and num_occur(current_new, S) > 0) :
                                            current = current_new
                                            worked = True
                                    else :
                                            nomatch.append(current_new)
                    if worked :
                            if n == 1:
                                    del tuples[i]
                            else    :
                                    tuples[i] = (n-1, s)
                            break
            if not worked:
                    add_at_start = False
    return current
</code>```

Title: Identify a string from its substrings

Body:
Python <s>12705</s>  12632 calls

make a list of 2 characters strings occurrences

sort the list

build the string trying the most probable character first, don't test if there is only one possibility

update the list

if the list is empty it is finished else step 2

I used Loovjo function skeleton. I never code in Python I needed a bootsrap

EDIT:

Added code for one character length strings

Added code to reject already matched patterns

def finds(S):

    if len(S) == 0:
            return ""
    if len(S) == 1
            if num_occur("a",S) == 1 :
                         return "a"
            if num_occur("b",S) == 1 :
                         return "b"
            return "c"
    tuples=[]
    alphabet=[ "aa", "ab", "ac", "ba", "bb", "bc", "ca", "cb"]
    for s in alphabet : tuples.append( (num_occur(s,S), s) )

    sum=0
    for (i,s) in tuples :   sum+=i
    tuples.append( (len(S)-sum-1, "cc") )
    tuples.sort(key=lambda x:(-x[0],x[1]))

    (i, current) = tuples[0]
    tuples[0] = (i-1, current)

    add_at_start = True
    nomatch=[]
    while len(tuples) > 0:
            worked = False
            tuples.sort(key=lambda x:(-x[0],x[1]))
            count=0
            if not add_at_start :
                    for (n, s) in tuples :
                            if s[0]==current[-1:] :         count+=1
            for i in range(len(tuples)):
                    (n, s)=tuples[i]
                    if add_at_start:
                            if current[0] == s[1] :
                                    current_new = s[0] + current
                                    possible=True
                                    for nm in nomatch :
                                            lng=len(nm)
                                            if current_new[0:lng] == nm :
                                                    possible=False
                                                    break
                                    if possible and num_occur(current_new, S) > 0:
                                            current = current_new
                                            worked = True
                                    else :
                                            nomatch.append(current_new)
                    else:
                            if current[-1:] == s[0] :
                                    current_new =  current + s[1]
                                    possible=True
                                    for nm in nomatch :
                                            lng=len(nm)
                                            if current_new[-lng:] == nm :
                                                    possible=False
                                                    break
                                    if count == 1 or (possible and num_occur(current_new, S) > 0) :
                                            current = current_new
                                            worked = True
                                    else :
                                            nomatch.append(current_new)
                    if worked :
                            if n == 1:
                                    del tuples[i]
                            else    :
                                    tuples[i] = (n-1, s)
                            break
            if not worked:
                    add_at_start = False
    return current