答:
J, <s>33</s> 31

```<code>3{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
2{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
1{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
0{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
</code>```

We select the element from the boxed list that we need.

Old solution, 33 bytes

```<code>'Hi, Hello!'
'Hi']>:+:i.13
'Hi']<' '
'Hello, bye!'
</code>```

Calculated here, requires ES6 browser

```<code>'Hi, Hello!'    12 / 2 = 6
'Hi']>:+:i.13    + l.d. 10
'Hi']<' '        + l.d.  8
'Hello, bye!'    + l.d.  9
                      = 33
</code>```

Requires the console interpreter for 'Hi']<' ', which uses the fact that displayed boxed items use the required ASCII border; we just box a space in this case.

Bonus code in jolf:

```<code>u+~:/lFx2~m]x0_1d~LH.xhS
</code>```

Just call this with an array containing your solutions to calculate the scores! Alternatively, open up the console and type in:

```<code>jolf("u+~:/lFx2~m]x0_1d~LH.xhS", ["p1", "p2", "p3", "p4"]);
</code>```

Title: Hi, can you draw some odd art? Bye!

Body:
Create a program that outputs "Hi, Hello!" in k bytes. By altering n bytes, the code should output all odd numbers in the range 5 <= x <= 25.
Changing another m bytes should result in a code that prints the following frame in ASCII-art:

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

Change another o bytes, and print Hello, bye!.

m, n and o are calculated in Levenshtein distance (cumulative). n is the distance from the first to the second code. m is the distance between the second and third and so on.

The score of your submission will be 0.5*k + n + m + o.

As an example:

```<code>The code that prints `Hi, Hello!` is 30 bytes.              15
Add two bytes and remove one and print the odd numbers     + 3
Alter three bytes in place, and add one to print the box   + 4
Remove four bytes and print `Hello, bye!`                  + 4
Total score:                                                26
</code>```

Rules

All codes must be in the same language

You have to follow the given order (i.e. the first code prints Hi, Hello, the second prints the numbers etc.)

The strings and ASCII-box must be exactly as specified. The list of digits can be on any suitable format

Body:
J, <s>33</s> 31

3{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
2{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
1{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'
0{(a,', bye!');(<' ');(>:+:i.13);'Hi, ',(a=:'Hello'),'!'

We select the element from the boxed list that we need.

Old solution, 33 bytes

'Hi, Hello!'
'Hi']>:+:i.13
'Hi']<' '
'Hello, bye!'

Calculated here, requires ES6 browser

'Hi, Hello!'    12 / 2 = 6
'Hi']>:+:i.13    + l.d. 10
'Hi']<' '        + l.d.  8
'Hello, bye!'    + l.d.  9
                      = 33

Requires the console interpreter for 'Hi']<' ', which uses the fact that displayed boxed items use the required ASCII border; we just box a space in this case.

Bonus code in jolf:

u+~:/lFx2~m]x0_1d~LH.xhS

Just call this with an array containing your solutions to calculate the scores! Alternatively, open up the console and type in:

jolf("u+~:/lFx2~m]x0_1d~LH.xhS", ["p1", "p2", "p3", "p4"]);


问:
Hi, can you draw some odd art? Bye!
Create a program that outputs "Hi, Hello!" in k bytes. By altering n bytes, the code should output all odd numbers in the range 5 <= x <= 25.
Changing another m bytes should result in a code that prints the following frame in ASCII-art:

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

Change another o bytes, and print Hello, bye!.

m, n and o are calculated in Levenshtein distance (cumulative). n is the distance from the first to the second code. m is the distance between the second and third and so on.

The score of your submission will be 0.5*k + n + m + o.

As an example:

```<code>The code that prints `Hi, Hello!` is 30 bytes.              15
Add two bytes and remove one and print the odd numbers     + 3
Alter three bytes in place, and add one to print the box   + 4
Remove four bytes and print `Hello, bye!`                  + 4
Total score:                                                26
</code>```

Rules

All codes must be in the same language

You have to follow the given order (i.e. the first code prints Hi, Hello, the second prints the numbers etc.)

The strings and ASCII-box must be exactly as specified. The list of digits can be on any suitable format

ContentLicense: CC BY-SA 3.0

Title: Hi, can you draw some odd art? Bye!

Body:
Haskell, 41

"Hi, Hello!"
--[5,7..25]
--"+-+\n| |\n+-+"
--"Hello, bye!"

--"Hi, Hello"
[5,7..25]
--"+-+\n| |\n+-+"
--"Hello, bye!"

--"Hi,Hello"
--[5,7..25]
"+-+\n| |\n+-+"
--"Hello, bye!"

--"Hi,Hello"
--[5,7..25]
--"+-+\n| |\n+-+"
"Hello, bye!"

The initial program is 58 bytes, i.e. a score of 29. Each of the successors adds -- and removes -- for a score of 4, so the total is 29 + 3*4 = 41.

Haskell 33.5

If returning the list of numbers as a String, i.e. "[5,7,9,11,13,15,17,19,21,23,25]" is fine, then

["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!0
["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!1
["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!2
["Hi, Hello!",show[5,7..25],"+-+\n| |\n+-+","Hello, bye!"]!!3

works for 61/2 + 1 + 1 +1 = 33.5


答:
05AB1E, 42 ÷ 2 = 21 + 1 + 1 + 1 = 24

Hi, Hello code:

```<code>”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\\\
</code>```

Try it online!.

Odd numbers code:

```<code>”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\\
</code>```

Try it online!.

Box code:

```<code>”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\
</code>```

Try it online!

Hello, bye code:

```<code>”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª
</code>```

Try it online!.

Uses CP-1252 encoding.

Title: Hi, can you draw some odd art? Bye!

Body:
05AB1E, 42 ÷ 2 = 21 + 1 + 1 + 1 = 24

Hi, Hello code:

”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\\\

Try it online!.

Odd numbers code:

”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\\

Try it online!.

Box code:

”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª\

Try it online!

Hello, bye code:

”Hi,Ÿ™!”25ÅÉ¦¦"+-+
"©"| |
"®««“Ÿ™,Þ¡!“ª

Try it online!.

Uses CP-1252 encoding.


问:
Print the nth prime that contains n
This question will be a twist on finding the nth prime number.

Challenge

You must write a program that will take one input n, and output the nth prime number whose decimal representation contains the decimal representation of n as a subtring.

Confused? Here are some examples.

```<code>n=1
Primes: 2, 3, 5, 7, 11
                    ^1 first prime that contains a 1
Output: 11

n=2
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
        ^1                          ^2 second prime that contains a 2
Output: 23

n=3
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
           ^1           ^2          ^3 third prime that contains a 3
Output: 23

n=10
Primes: 2, 3, 5, 7, 11, ..., 97, 101, 103, 107, 109, ..., 997, 1009, 1013, 1019, 1021, 1031, 1033
                                 ^1   ^2   ^3   ^4             ^5    ^6    ^7    ^8    ^9    ^10 tenth prime that contains a 10
Output: 1033
</code>```

This is code-golf, so lowest byte count wins.

If something is confusing, please leave a comment.

答:
Julia, <s>61</s> 60 bytes

f(n,k=0,m=1)=k<n&&f(n,k+isprime(m)contains("$m","$n"),m+1)+1
```

Try it online!

Title: Print the nth prime that contains n

Body:
Julia, <s>61</s> 60 bytes

f(n,k=0,m=1)=k<n&&f(n,k+isprime(m)contains("$m","$n"),m+1)+1

Try it online!


答:
Fuzzy Octo Guacamole, 58/2 + 1 + 1 + 1 = 32 byte-points

```<code>"Hi, Hello!""Hello, bye!"%@0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
</code>```

This code as-is prints Hi, Hello!.  By changing the % to a space ( ), you get Hello, bye!. By changing the first @ to a space ( ), you get the list of odd numbers, starting with 5 and ending with 25.. And finally, by changing the 0 to a space,  , you get +-+\n| |\n+-+.

The 4 pieces of code (iterated removals):

```<code>"Hi, Hello!""Hello, bye!"%@0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!" @0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!"  0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!"   {25*!5[X2a]@}"+-+"X"| |"X"+-+"
</code>```

Title: Hi, can you draw some odd art? Bye!

Body:
Fuzzy Octo Guacamole, 58/2 + 1 + 1 + 1 = 32 byte-points

"Hi, Hello!""Hello, bye!"%@0{25*!5[X2a]@}"+-+"X"| |"X"+-+"

This code as-is prints Hi, Hello!.  By changing the % to a space ( ), you get Hello, bye!. By changing the first @ to a space ( ), you get the list of odd numbers, starting with 5 and ending with 25.. And finally, by changing the 0 to a space,  , you get +-+\n| |\n+-+.

The 4 pieces of code (iterated removals):

"Hi, Hello!""Hello, bye!"%@0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!" @0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!"  0{25*!5[X2a]@}"+-+"X"| |"X"+-+"
"Hi, Hello!""Hello, bye!"   {25*!5[X2a]@}"+-+"X"| |"X"+-+"


问:
Get the most dominant color!
In this challenge, your task is to write a program that takes in an image and returns the most dominant color in it. Dominant color here means the color with which most of the image is covered (see the test cases for a better understanding).

Input

An image's path. You'll have to load that image in your program. You can take the input as STDIN, function argument or whatever suits your language. You may assume that the image will have only .png extension.

Output

The most dominant color in any format. (But it should be accurate, you can't return Red for #f88379). The type of output depends on you. If there is an equal distribution of colors in the image or there are more than one dominant color, then your program should return "Equal". You can show the output by printing on screen, logging on command line or console, or whatever suits you.

Test Cases

=> Red/#ff0000/rgba(255,0,0)

.

=> "Equal"

=> White (or the same color in any other format)

In these test cases, I have posted images rather than image paths, but you'll be given image paths only as input.

Note If your language contains a built-in for this, then you must NOT use it. Please add a screenshot or a link to a screenshot to prove that your program works.

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

答:
MATL, <s>30</s> <s>26</s> 23 bytes

Save some bytes by using mode with explicit output specification 6#XM.

```<code>2#YiwX:6#XMgY)tn3>?x'='
</code>```

Previously (26 byte solution)

```<code>2#YiwX:S&Y'tX>=Y)tn3>?x'='
</code>```

Doesn't work online, because of imread. imread can take a path or directly read a url.

Explanation:

```<code>2#Yi       % read image, returns a matrix of colours, and a matrix
           % that indexes each pixel to the corresponding row of the colour matrix
w          % swap elements in stack
X:         % linearize index matrix to column array
6#XMg      % use mode to find most common colour indices, convert to matrix (g)
Y)         % get corresponding rows of colour matrix
tn3>       % duplicate and see if it has more than 3 elements
?          % if there is more than one most common colour
x          % delete most common colours from stack
'='        % push string onto stack
           % implicitly finish loop and display stack contents
</code>```

Output is, for the first image, 1 0 0 (RGB triple), for the second =, and for the third, 1 1 1. For example, a screenshot form Matlab:

Note that you need to escape string delimiters when running MATL code from the Matlab command window, hence the ''=''. The > indicates MATL is asking for user input, in this I gave it the URL of the first test case, and the result is 1 0 0.

Title: Get the most dominant color!

Body:
MATL, <s>30</s> <s>26</s> 23 bytes

Save some bytes by using mode with explicit output specification 6#XM.

2#YiwX:6#XMgY)tn3>?x'='

Previously (26 byte solution)

2#YiwX:S&Y'tX>=Y)tn3>?x'='

Doesn't work online, because of imread. imread can take a path or directly read a url.

Explanation:

2#Yi       % read image, returns a matrix of colours, and a matrix
           % that indexes each pixel to the corresponding row of the colour matrix
w          % swap elements in stack
X:         % linearize index matrix to column array
6#XMg      % use mode to find most common colour indices, convert to matrix (g)
Y)         % get corresponding rows of colour matrix
tn3>       % duplicate and see if it has more than 3 elements
?          % if there is more than one most common colour
x          % delete most common colours from stack
'='        % push string onto stack
           % implicitly finish loop and display stack contents

Output is, for the first image, 1 0 0 (RGB triple), for the second =, and for the third, 1 1 1. For example, a screenshot form Matlab:

Note that you need to escape string delimiters when running MATL code from the Matlab command window, hence the ''=''. The > indicates MATL is asking for user input, in this I gave it the URL of the first test case, and the result is 1 0 0.


问:
On the Subject of Passwords
In Keep Talking and Nobody Explodes, players are tasked with defusing bombs based on information from their "experts" (other people with a manual). Each bomb is made up of modules, one of which can be passwords, where the expert is given this list of possible passwords, all five letters long:

```<code>about   after   again   below   could
every   first   found   great   house
large   learn   never   other   place
plant   point   right   small   sound
spell   still   study   their   there
these   thing   think   three   water
where   which   world   would   write
</code>```

And the player is given a list of 6 possible letters for each place in the password. Given the possible letter combinations, output the correct password. Input can be in any reasonable format (2D array, string separated by newline, etc.) You may discount the code which you use to compress/generate the list/string/array/whatever of passwords. (Thanks @DenkerAffe)

NOTE: Passwords are case insensitive. You may assume that input will only solve for one password.

Examples / Test Cases

Input here will be represented as a array of strings.

```<code>["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"] => first
["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"] => large
["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"] => still
</code>```

答:
Pyth, 13 bytes

```<code>:#%*"[%s]"5Q0c"ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE"5
</code>```

Test suite.

```<code> #             filter possible words on
:           0  regex match, with pattern
  %        Q   format input as
    "[%s]"     surround each group of letters with brackets (regex char class)
   *      5    repeat format string 5 times for 5 groups of letters
</code>```

Title: On the Subject of Passwords

Body:
Pyth, 13 bytes

:#%*"[%s]"5Q0c"ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE"5

<a href="https://pyth.herokuapp.com/?code=%3A%23%25%2a%22%5B%25s%5D%225Q0c%22ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE%225&input=%5B%22FGARTW%22%2C%22LKSIRE%22%2C%22UHRKPA%22%2C%22TGYSTG%22%2C%22LUOTEU%22%5D&test_suite=1&test_suite_input=%5B%22FGARTW%22%2C%22LKSIRE%22%2C%22UHRKPA%22%2C%22TGYSTG%22%2C%22LUOTEU%22%5D%0A%5B%22ULOIPE%22%2C%22GEYARF%22%2C%22SHRGWE%22%2C%22JEHSDG%22%2C%22EJHDSP%22%5D%0A%5B%22SHWYEU%22%2C%22YEUTLS%22%2C%22IHEWRA%22%2C%22HWULER%22%2C%22EUELJD%22%5D&debug=0" rel="noreferrer">Test suite.

 #             filter possible words on
:           0  regex match, with pattern
  %        Q   format input as
    "[%s]"     surround each group of letters with brackets (regex char class)
   *      5    repeat format string 5 times for 5 groups of letters


答:
Bash, 22 bytes

```<code>grep `printf [%s] $@`< <(echo ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE | sed 's/...../&\n/g')
</code>```

Run like so:

```<code>llama@llama:~$ bash passwords.sh FGARTW LKSIRE UHRKPA TGYSTG LUOTEU
FIRST
</code>```

```<code>      printf [%s] $@    surround all command line args with brackets
grep `              `   output all input lines that match this as a regex
                     <  use the following file as input to grep
</code>```

Title: On the Subject of Passwords

Body:
In Keep Talking and Nobody Explodes, players are tasked with defusing bombs based on information from their "experts" (other people with a manual). Each bomb is made up of modules, one of which can be passwords, where the expert is given this list of possible passwords, all five letters long:

```<code>about   after   again   below   could
every   first   found   great   house
large   learn   never   other   place
plant   point   right   small   sound
spell   still   study   their   there
these   thing   think   three   water
where   which   world   would   write
</code>```

And the player is given a list of 6 possible letters for each place in the password. Given the possible letter combinations, output the correct password. Input can be in any reasonable format (2D array, string separated by newline, etc.) You may discount the code which you use to compress/generate the list/string/array/whatever of passwords. (Thanks @DenkerAffe)

NOTE: Passwords are case insensitive. You may assume that input will only solve for one password.

Examples / Test Cases

Input here will be represented as a array of strings.

```<code>["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"] => first
["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"] => large
["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"] => still
</code>```

Body:
Bash, 22 bytes

grep `printf [%s] $@`< <(echo ABOUTAFTERAGAINBELOWCOULDEVERYFIRSTFOUNDGREATHOUSELARGELEARNNEVEROTHERPLACEPLANTPOINTRIGHTSMALLSOUNDSPELLSTILLSTUDYTHEIRTHERETHESETHINGTHINKTHREEWATERWHEREWHICHWORLDWOULDWRITE | sed 's/...../&\n/g')

Run like so:

llama@llama:~$ bash passwords.sh FGARTW LKSIRE UHRKPA TGYSTG LUOTEU
FIRST

      printf [%s] $@    surround all command line args with brackets
grep `              `   output all input lines that match this as a regex
                     <  use the following file as input to grep


答:
Ruby, <s>48</s> <s>42</s> 39 bytes

Now that it's done, it's very similar to the Pyth solution, <s>but without %s formatting</s> to the point where it's basically a direct port now.

If you only output the result with puts, you don't need the [0] at the end since puts will deal with that for you.

```<code>->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}
</code>```

With test cases:

```<code>f=->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}

w = %w{about after again below could
every first found great house
large learn never other place
plant point right small sound
spell still study their there
these thing think three water
where which world would write}

puts f.call(w, ["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"]) # first
puts f.call(w, ["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"]) # large
puts f.call(w, ["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"]) # still
</code>```

Title: On the Subject of Passwords

Body:
Ruby, <s>48</s> <s>42</s> 39 bytes

Now that it's done, it's very similar to the Pyth solution, <s>but without %s formatting</s> to the point where it's basically a direct port now.

If you only output the result with puts, you don't need the [0] at the end since puts will deal with that for you.

->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}

With test cases:

f=->w,l{w.grep(/#{'[%s]'*l.size%l}/i)[0]}

w = %w{about after again below could
every first found great house
large learn never other place
plant point right small sound
spell still study their there
these thing think three water
where which world would write}

puts f.call(w, ["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"]) # first
puts f.call(w, ["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"]) # large
puts f.call(w, ["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"]) # still


答:
Python 3, 186 Bytes

```<code>from PIL import Image;from collections import*;c=Counter(Image.open(input()).convert("RGB").getdata());d=c.most_common();print("equal") if d[0][1]==d[1][1] else print(c.most_common()[0])
</code>```

Image 1 prints: ((255, 0, 0), 139876)

Image 2 prints: equal

Image 3 prints: ((255, 255, 255), 101809)

Ungolfed:
```<code>from PIL import Image
from collections import *
c = Counter(Image.open(input()).convert("RGB").getdata())
d = c.most_common()
print("equal") if d[0][1] == d[1][1] else print(c.most_common()[0])
</code>```

Proof:

Title: Get the most dominant color!

Body:
In this challenge, your task is to write a program that takes in an image and returns the most dominant color in it. Dominant color here means the color with which most of the image is covered (see the test cases for a better understanding).

Input

An image's path. You'll have to load that image in your program. You can take the input as STDIN, function argument or whatever suits your language. You may assume that the image will have only .png extension.

Output

The most dominant color in any format. (But it should be accurate, you can't return Red for #f88379). The type of output depends on you. If there is an equal distribution of colors in the image or there are more than one dominant color, then your program should return "Equal". You can show the output by printing on screen, logging on command line or console, or whatever suits you.

Test Cases

=> Red/#ff0000/rgba(255,0,0)

.

=> "Equal"

=> White (or the same color in any other format)

In these test cases, I have posted images rather than image paths, but you'll be given image paths only as input.

Note If your language contains a built-in for this, then you must NOT use it. Please add a screenshot or a link to a screenshot to prove that your program works.

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

Body:
Python 3, 186 Bytes

from PIL import Image;from collections import*;c=Counter(Image.open(input()).convert("RGB").getdata());d=c.most_common();print("equal") if d[0][1]==d[1][1] else print(c.most_common()[0])

Image 1 prints: ((255, 0, 0), 139876)

Image 2 prints: equal

Image 3 prints: ((255, 255, 255), 101809)

Ungolfed:

from PIL import Image
from collections import *
c = Counter(Image.open(input()).convert("RGB").getdata())
d = c.most_common()
print("equal") if d[0][1] == d[1][1] else print(c.most_common()[0])

Proof:

ContentLicense: CC BY-SA 4.0


答:
Jelly, 23

First program, 40 bytes

```<code>“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
1£
</code>```

Try it online!

Second program, edit distance 1

```<code>“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
2£
</code>```

Try it online!

Third program, edit distance 1

```<code>“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
3£
</code>```

Try it online!

Fourth program, edit distance 1

```<code>“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
4£
</code>```

Try it online!

How it works

In all Jelly programs, every line defines a link. The last one is the main link and is executed automatically by the interpreter.

The quick £ inspects the number before it and calls the link on that line, so it suffices to place the four individual programs on different lines and call the appropriate one.

First program

```<code>“"©ĊĠȦẋạ»
</code>```

This simply uses Jelly's built-in compression, constructing the string as Hi, (bare string), Hello (dictionary word) and ! (bare string).

Second program

```<code>5r25m2
</code>```

5 sets the left argument to 5, r25 creates a range up to 25 and m2 selects every second element.

Third program

```<code>“+-+¶| ”ȮṖṚ
</code>```

“+-+¶| ” sets the left argument to that string, Ȯ prints it explicitly, Ṗ removes the last character and Ṛ reverses the result. The reversed string gets printed implicitly.

Fourth program

```<code>“(ʠƤ,ụȤ»
</code>```

Akin to the first program, this compresses the output string as Hello (dictionary word), , (bare string), bye (dictionary word, leading space) and ! (bare string).

Title: Hi, can you draw some odd art? Bye!

Body:
Jelly, 23

First program, 40 bytes

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
1£

Try it online!

Second program, edit distance 1

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
2£

Try it online!

Third program, edit distance 1

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
3£

Try it online!

Fourth program, edit distance 1

“"©ĊĠȦẋạ»
5r25m2
“+-+¶| ”ȮṖṚ
“(ʠƤ,ụȤ»
4£

Try it online!

How it works

In all Jelly programs, every line defines a link. The last one is the main link and is executed automatically by the interpreter.

The quick £ inspects the number before it and calls the link on that line, so it suffices to place the four individual programs on different lines and call the appropriate one.

First program

“"©ĊĠȦẋạ»

This simply uses Jelly's built-in compression, constructing the string as Hi, (bare string), Hello (dictionary word) and ! (bare string).

Second program

5r25m2

5 sets the left argument to 5, r25 creates a range up to 25 and m2 selects every second element.

Third program

“+-+¶| ”ȮṖṚ

“+-+¶| ” sets the left argument to that string, Ȯ prints it explicitly, Ṗ removes the last character and Ṛ reverses the result. The reversed string gets printed implicitly.

Fourth program

“(ʠƤ,ụȤ»

Akin to the first program, this compresses the output string as Hello (dictionary word), , (bare string), bye (dictionary word, leading space) and ! (bare string).


答:
JavaScript (ES6), 71 bytes

```<code>w=>l=>w.filter(s=>eval("for(b=1,i=5;i--;)b&=!!~l[i].indexOf(s[i])")[0])
</code>```

Usage:

```<code>f=w=>l=>w.filter(s=>eval("for(b=1,i=5;i--;)b&=!!~l[i].indexOf(s[i])")[0])
f(array_of_words)(array_of_letters)
</code>```

Title: On the Subject of Passwords

Body:
JavaScript (ES6), 71 bytes

w=>l=>w.filter(s=>eval("for(b=1,i=5;i--;)b&=!!~l[i].indexOf(s[i])")[0])

Usage:

f=w=>l=>w.filter(s=>eval("for(b=1,i=5;i--;)b&=!!~l[i].indexOf(s[i])")[0])
f(array_of_words)(array_of_letters)


问:
Calculate the Numpad Taxicab
Credit goes where credit is due

Given two digits, x, and y, calculate the shortest number of horizontal or vertical jumps to get from x to y on a standard numpad, e.g.

```<code>789
456
123
00
</code>```

You can safely assume that all inputs will be 0-9, and you do not have to handle invalid inputs. The input may be the same number twice, which has a distance of 0.

IO can be in any reasonable format, and standard loopholes are forbidden. Shortest answer in bytes wins!

Sample IO:

```<code>1, 4: 1
1, 8: 3
3, 7: 4
8, 2: 2
6, 1: 3
0, 9: 4
4, 4: 0
0, 4: 2
</code>```

答:
Python 2, 61 bytes

lambda x,y:abs(x/-3-y/-3)+abs((x or 1.5)%-3-(y or 1.5)%-3)//1
```

<p>Test it on Ideone.</p>

<h3>How it works</h3>

<ul>
<li><p><strong>Vertical distance</strong></p>

<p>Integer division always round <em>down</em> to the nearest integer in Python, yielding the following results for the 10 possible dividends divided by <strong>-3</strong>.</p>

<pre class="lang-python prettyprint-override"><code> 0  1  2  3  4  5  6  7  8  9
 0 -1 -1 -1 -2 -2 -2 -3 -3 -3
</code>```

Thus, we can compute the vertical distance between x and y as abs(x/-3-y/-3).

Horizontal distance

For columns, we can avoid treating 0 as a special case by replacing it with 1.5, thus placing it "between" the first and second column.

Modulus (%) always has the sign of the divisor in Python, yielding the following results for the 10 possible dividend modulo -3.

   0  1  2  3  4  5  6  7  8  9
-1.5 -2 -1  0 -2 -1  0 -2 -1  0
```

Thus, by rounding down (//1) the result of abs((x or 1.5)%-3-(y or 1.5)%-3), we can compute the horizontal difference between x and y.

Title: Calculate the Numpad Taxicab

Body:
Python 2, 61 bytes

lambda x,y:abs(x/-3-y/-3)+abs((x or 1.5)%-3-(y or 1.5)%-3)//1

Test it on Ideone.

How it works

Vertical distance

Integer division always round down to the nearest integer in Python, yielding the following results for the 10 possible dividends divided by -3.

 0  1  2  3  4  5  6  7  8  9
 0 -1 -1 -1 -2 -2 -2 -3 -3 -3

Thus, we can compute the vertical distance between x and y as abs(x/-3-y/-3).

Horizontal distance

For columns, we can avoid treating 0 as a special case by replacing it with 1.5, thus placing it "between" the first and second column.

Modulus (%) always has the sign of the divisor in Python, yielding the following results for the 10 possible dividend modulo -3.

   0  1  2  3  4  5  6  7  8  9
-1.5 -2 -1  0 -2 -1  0 -2 -1  0

Thus, by rounding down (//1) the result of abs((x or 1.5)%-3-(y or 1.5)%-3), we can compute the horizontal difference between x and y.


问:
Randomly Assign People to Tasks
The challenge is to assign people to tasks randomly~.
From stdin you get 2 lines. Line one is a comma-separated list of names. Line 2 is a comma-separated list of jobs.
The output required is one line per task person combo.
The line should be formatted as Name:task.
If there are not enough people for jobs or vice verse then they will not be output.

~ Randomly is defined as each run with the same input has a reasonably different output.

Example Input:

```<code>Bob,John,Susan,Josie,Kim,Tom
Bins,Floor,Windows
</code>```

Example Output:

```<code>Bob:Windows
Susan:Bins
Kim:Floor
</code>```

答:
Q, 38 Bytes

```<code>t:{$[n:&/#:'x:{(-#x)?x}'x;+n#/:x;0N]}
</code>```

NOTE.- input and output format not exactly as proposed (see test)

Test

```<code>."\\S ",$7h$.z.t    /To accomplish a random output we mofify seed based on internal clock
t(`Bob`John`Susan`Josie`Kim`Tom; `Bins`Floor`Windows)
/generates (`Susan`Windows;`Kim`Bins;`John`Floor) (a different result each run)
</code>```

Explanation

(-seqLen)?seq Shuffles the sequence

x:{(-#x)?x}'x shuffles each sequence of x (argument with sequence of names and sequence of works) and reassign to x

n:&/#:'x Assigns to n the minimum over (&/) each sequence lengths (#:'x)

$[n;+n#/:x;0N] If n (if n is not 0), executes flip n take of each seq, Else returns null

Title: Randomly Assign People to Tasks

Body:
Q, 38 Bytes

t:{$[n:&/#:'x:{(-#x)?x}'x;+n#/:x;0N]}

NOTE.- input and output format not exactly as proposed (see test)

Test

."\\S ",$7h$.z.t    /To accomplish a random output we mofify seed based on internal clock
t(`Bob`John`Susan`Josie`Kim`Tom; `Bins`Floor`Windows)
/generates (`Susan`Windows;`Kim`Bins;`John`Floor) (a different result each run)

Explanation

(-seqLen)?seq Shuffles the sequence

x:{(-#x)?x}'x shuffles each sequence of x (argument with sequence of names and sequence of works) and reassign to x

n:&/#:'x Assigns to n the minimum over (&/) each sequence lengths (#:'x)

$[n;+n#/:x;0N] If n (if n is not 0), executes flip n take of each seq, Else returns null


答:
Julia, 56 bytes

x->sum(abs(-([[divrem(t>0?t+2:.5,3)...]for t=x]...)))÷1
```

Try it online!

Title: Calculate the Numpad Taxicab

Body:
Credit goes where credit is due

Given two digits, x, and y, calculate the shortest number of horizontal or vertical jumps to get from x to y on a standard numpad, e.g.

```<code>789
456
123
00
</code>```

You can safely assume that all inputs will be 0-9, and you do not have to handle invalid inputs. The input may be the same number twice, which has a distance of 0.

IO can be in any reasonable format, and standard loopholes are forbidden. Shortest answer in bytes wins!

Sample IO:

```<code>1, 4: 1
1, 8: 3
3, 7: 4
8, 2: 2
6, 1: 3
0, 9: 4
4, 4: 0
0, 4: 2
</code>```

Body:
Julia, 56 bytes

x->sum(abs(-([[divrem(t>0?t+2:.5,3)...]for t=x]...)))÷1

Try it online!


问:
"99 Bottles of Beer"
Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible.

Lyrics:

```<code>99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

....

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
</code>```

Rules:

Your program must log to STDOUT or an acceptable alternative, or be returned from a function (with or without a trailing newline).

Your program must be a full, runnable program or function.

Languages specifically written to submit a 0-byte answer to this challenge are allowed, just not particularly interesting.

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

This is different from the output by HQ9+ or 99. Any answers written in these languages will be deleted.

As this is a catalog challenge, this is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
PHP, 172 bytes

<?for(;100>$a=1+$a." bottle$o[21] of beer";$o="
Take one down and pass it around, $b.

".$g="$b, $a.$o")$b="$a on the wall";echo"$g
Go to the store and buy some more, $b.";
```

The most significant trick is $o[21]. On the first iteration, $o will be undefined, resulting in an empty string. On each iteration after, it refers to the first s of pass.

Title: "99 Bottles of Beer"

Body:
PHP, 172 bytes

<?for(;100>$a=1+$a." bottle$o[21] of beer";$o="
Take one down and pass it around, $b.

".$g="$b, $a.$o")$b="$a on the wall";echo"$g
Go to the store and buy some more, $b.";

The most significant trick is $o[21]. On the first iteration, $o will be undefined, resulting in an empty string. On each iteration after, it refers to the first s of pass.


答:
JavaScript (ES6), <s>301</s> <s>328</s> 312 bytes

```<code>(u,b)=>{i=new Image;i.src=u;e=document.createElement`canvas`;c=e.getContext`2d`;i.onload=_=>{w=e.width=i.width;h=e.height=i.height;c.drawImage(i,0,0);d=c.getImageData(0,0,w,h).data;for(o={},i=0;i<d.length;)++o[s=d.slice(i,i+=4)]?0:o[s]=1;b(o[(a=Object.keys(o).sort((a,b)=>o[b]-o[a]))[0]]==o[a[1]]?"Equal":a[0])}}
</code>```

Feel free to golf further, this feels as long as Java to me personally.

This supports transparent images so alpha channel is included in output value.

The reason it's longer than before is because now that I've tested, <s>it requires Image to contain the attribute crossOrigin, and</s> the arguments to getImageData() are not optional.

See Meta PCG for removal of CORS from byte count.

Usage

```<code>f("http://i.imgur.com/H5OmRVh.jpg", alert)
</code>```

That will asynchronously alert a color quadruplet or "Equal" after the image is loaded and counted.

The callback is not considered part of the program length because it is allowed as input by the OP in this special case.

How it works

It constructs an Image, a Canvas, and a CanvasRenderingContext2D, then draws the image to the canvas after setting its width and height correctly. It then counts occurrences of each color by implicitly converting each quadruplet to a string and generating a hash of counters. After that, it sorts the hash keys by descending count before comparing the highest two occurrences and determining whether to return the first quadruplet string in the sorted array or the string "Equal".

If the demo below displays a SecurityError, the domain of the image URL you chose does not support CORS.

Demo

f = (u, b) => {
  let i = new Image;
  i.crossOrigin = ''; // CORS added for demo
  i.src = u;
  let e = document.createElement `canvas`;
  let c = e.getContext `2d`;
  i.onload = _ => {
    w = e.width = i.width;
    h = e.height = i.height;
    c.drawImage(i, 0, 0);
    d = c.getImageData(0, 0, w, h).data;
    for (o = {}, i = 0; i < d.length;)
      ++o[s = d.slice(i, i += 4)] ? 0 : o[s] = 1;
    b(o[(a = Object.keys(o).sort((a, b) => o[b] - o[a]))[0]] == o[a[1]] ? "Equal" : a[0])
  }
}
l = i => {
  let p = i.nextElementSibling;
  p.src = i.value;
  f(`http://crossorigin.me/${i.value}`, c => p.nextElementSibling.value = c);
}
document.getElementById `i`.addEventListener('update', e => {
  l(e.target)
})
Array.prototype.slice.call(document.querySelectorAll`.i`, 0, 3).forEach(l)```
<pre class="snippet-code-css lang-css prettyprint-override"><code>input {
  display: block;
  box-sizing: border-box;
  width: 205px;
  height: 18px;
}

input.o {
  position: relative;
  top: -36px;
}

img {
  display: block;
  position: relative;
  box-sizing: border-box;
  top: -18px;
  left: 209px;
  height: 40px;
}</code>```

<input class=i disabled value="http://i.stack.imgur.com/rqsAX.png">

<input class=o disabled>
<input class=i disabled value="http://i.stack.imgur.com/KECpJ.png">

<input class=o disabled>
<input class=i disabled value="http://i.stack.imgur.com/DRCWd.png">

<input class=o disabled>
<input class=i id=i placeholder="Try any image!">

<input class=o id=o disabled>```

Title: Get the most dominant color!

Body:
JavaScript (ES6), <s>301</s> <s>328</s> 312 bytes

(u,b)=>{i=new Image;i.src=u;e=document.createElement`canvas`;c=e.getContext`2d`;i.onload=_=>{w=e.width=i.width;h=e.height=i.height;c.drawImage(i,0,0);d=c.getImageData(0,0,w,h).data;for(o={},i=0;i<d.length;)++o[s=d.slice(i,i+=4)]?0:o[s]=1;b(o[(a=Object.keys(o).sort((a,b)=>o[b]-o[a]))[0]]==o[a[1]]?"Equal":a[0])}}

Feel free to golf further, this feels as long as Java to me personally.

This supports transparent images so alpha channel is included in output value.

The reason it's longer than before is because now that I've tested, <s>it requires Image to contain the attribute crossOrigin, and</s> the arguments to getImageData() are not optional.

See Meta PCG for removal of CORS from byte count.

Usage

f("http://i.imgur.com/H5OmRVh.jpg", alert)

That will asynchronously alert a color quadruplet or "Equal" after the image is loaded and counted.

The callback is not considered part of the program length because it is allowed as input by the OP in this special case.

How it works

It constructs an Image, a Canvas, and a CanvasRenderingContext2D, then draws the image to the canvas after setting its width and height correctly. It then counts occurrences of each color by implicitly converting each quadruplet to a string and generating a hash of counters. After that, it sorts the hash keys by descending count before comparing the highest two occurrences and determining whether to return the first quadruplet string in the sorted array or the string "Equal".

If the demo below displays a SecurityError, the domain of the image URL you chose does not support CORS.

Demo

f = (u, b) => {
  let i = new Image;
  i.crossOrigin = ''; // CORS added for demo
  i.src = u;
  let e = document.createElement `canvas`;
  let c = e.getContext `2d`;
  i.onload = _ => {
    w = e.width = i.width;
    h = e.height = i.height;
    c.drawImage(i, 0, 0);
    d = c.getImageData(0, 0, w, h).data;
    for (o = {}, i = 0; i < d.length;)
      ++o[s = d.slice(i, i += 4)] ? 0 : o[s] = 1;
    b(o[(a = Object.keys(o).sort((a, b) => o[b] - o[a]))[0]] == o[a[1]] ? "Equal" : a[0])
  }
}
l = i => {
  let p = i.nextElementSibling;
  p.src = i.value;
  f(`http://crossorigin.me/${i.value}`, c => p.nextElementSibling.value = c);
}
document.getElementById `i`.addEventListener('update', e => {
  l(e.target)
})
Array.prototype.slice.call(document.querySelectorAll`.i`, 0, 3).forEach(l)

input {
  display: block;
  box-sizing: border-box;
  width: 205px;
  height: 18px;
}

input.o {
  position: relative;
  top: -36px;
}

img {
  display: block;
  position: relative;
  box-sizing: border-box;
  top: -18px;
  left: 209px;
  height: 40px;
}

<input class=i disabled value="http://i.stack.imgur.com/rqsAX.png">
<img>
<input class=o disabled>
<input class=i disabled value="http://i.stack.imgur.com/KECpJ.png">
<img>
<input class=o disabled>
<input class=i disabled value="http://i.stack.imgur.com/DRCWd.png">
<img>
<input class=o disabled>
<input class=i id=i placeholder="Try any image!">
<img>
<input class=o id=o disabled>


问:
Create a fractal tree
What I would like to see is a fractal tree being drawn where the you can input an integer, and the output will be a fractal tree with the entered amount of branch steps.

Rules:

The fractal should be a line fractal tree:

the shape of the fractal should also be the same as this picture.

Each branch should decrease by 25% in width for each time it splits

The final layer of branches should be an 1px wide line

Shortest code wins

Tip: this site might be useful.

答:
CoffeeScript (using Canvas) (289 bytes)

The following creates branches until the pixel width is less than 1px. The width and height of the image created is 500px. To see the virtual image that the program draws, add document.body.appendChild(c) to the last line of the code.

```<code>c=document.createElement 'canvas'
c.width=c.height=500
t=c.getContext '2d'
m=Math
b=m.PI/8
f=(w,l,x,y,a)->
    t.beginPath()
    t.moveTo x,y
    X=x+m.cos(a)*l
    Y=y+m.sin(a)*l
    t.lineWidth=w
    t.lineTo X,Y
    t.stroke()
    if w >= 1
        f w*3/4,l*3/4,X,Y,a+b
        f w*3/4,l*3/4,X,Y,a-b
f 10,90,250,0,m.PI/2
</code>```

Title: Create a fractal tree

Body:
CoffeeScript (using Canvas) (289 bytes)

The following creates branches until the pixel width is less than 1px. The width and height of the image created is 500px. To see the virtual image that the program draws, add document.body.appendChild(c) to the last line of the code.

c=document.createElement 'canvas'
c.width=c.height=500
t=c.getContext '2d'
m=Math
b=m.PI/8
f=(w,l,x,y,a)->
    t.beginPath()
    t.moveTo x,y
    X=x+m.cos(a)*l
    Y=y+m.sin(a)*l
    t.lineWidth=w
    t.lineTo X,Y
    t.stroke()
    if w >= 1
        f w*3/4,l*3/4,X,Y,a+b
        f w*3/4,l*3/4,X,Y,a-b
f 10,90,250,0,m.PI/2


答:
Java, 194 180 173 <s>171</s> 112 Bytes

Code:

```<code>a->{int i=1,j,n,r=0;for(j=n=new Integer(a);(r+=++i>=j&(""+j).contains(""+n)?1:0)!=n;j+=j%i==0?i=1:0);return j;}
</code>```

Ungolfed:

```<code>class P{
    static int i=1,j,n,r;
    public static void main(String[]s) {
        for(
                j=n=new Integer(s[0]); //executes once before first iteration
                (r+=++i>=j&(""+j).contains(""+n)?1:0)!=n; //executes on first and every iteration
                j+=j%i==0?i=1:0 //executes after first and every iteration
           ) {
            ;
        }
        System.out.print(j);
    }
}
</code>```

Title: Print the nth prime that contains n

Body:
This question will be a twist on finding the nth prime number.

Challenge

You must write a program that will take one input n, and output the nth prime number whose decimal representation contains the decimal representation of n as a subtring.

Confused? Here are some examples.

```<code>n=1
Primes: 2, 3, 5, 7, 11
                    ^1 first prime that contains a 1
Output: 11

n=2
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
        ^1                          ^2 second prime that contains a 2
Output: 23

n=3
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
           ^1           ^2          ^3 third prime that contains a 3
Output: 23

n=10
Primes: 2, 3, 5, 7, 11, ..., 97, 101, 103, 107, 109, ..., 997, 1009, 1013, 1019, 1021, 1031, 1033
                                 ^1   ^2   ^3   ^4             ^5    ^6    ^7    ^8    ^9    ^10 tenth prime that contains a 10
Output: 1033
</code>```

This is code-golf, so lowest byte count wins.

If something is confusing, please leave a comment.

Body:
Java, 194 180 173 <s>171</s> 112 Bytes

Code:

a->{int i=1,j,n,r=0;for(j=n=new Integer(a);(r+=++i>=j&(""+j).contains(""+n)?1:0)!=n;j+=j%i==0?i=1:0);return j;}

Ungolfed:

class P{
    static int i=1,j,n,r;
    public static void main(String[]s) {
        for(
                j=n=new Integer(s[0]); //executes once before first iteration
                (r+=++i>=j&(""+j).contains(""+n)?1:0)!=n; //executes on first and every iteration
                j+=j%i==0?i=1:0 //executes after first and every iteration
           ) {
            ;
        }
        System.out.print(j);
    }
}


答:
JavaScript (ES6), 62 bytes

```<code>(l,p)=>p.find(w=>l.every((s,i)=>eval(`/[${s}]/i`).test(w[i])))
</code>```

53 bytes on Firefox 48 or earlier:

```<code>(l,p)=>p.find(w=>l.every((s,i)=>~s.search(w[i],"i")))
</code>```

Would have been 49 bytes if not for that case insensitivity requirement:

```<code>(l,p)=>p.find(w=>l.every((s,i)=>~s.search(w[i])))
</code>```

f=
  (l,p)=>p.find(w=>l.every((s,i)=>eval(`/[${s}]/i`).test(w[i])))
;
p=["about","after","again","below","could","every","first","found","great","house","large","learn","never","other","place","plant","point","right","small","sound","spell","still","study","their","there","these","thing","think","three","water","where","which","world","would","write"];
o1.value=f(["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"],p)
o2.value=f(["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"],p)
o3.value=f(["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"],p)```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=o1><input id=o2><input id=o3></code>```

Title: On the Subject of Passwords

Body:
JavaScript (ES6), 62 bytes

(l,p)=>p.find(w=>l.every((s,i)=>eval(`/[${s}]/i`).test(w[i])))

53 bytes on Firefox 48 or earlier:

(l,p)=>p.find(w=>l.every((s,i)=>~s.search(w[i],"i")))

Would have been 49 bytes if not for that case insensitivity requirement:

(l,p)=>p.find(w=>l.every((s,i)=>~s.search(w[i])))

f=
  (l,p)=>p.find(w=>l.every((s,i)=>eval(`/[${s}]/i`).test(w[i])))
;
p=["about","after","again","below","could","every","first","found","great","house","large","learn","never","other","place","plant","point","right","small","sound","spell","still","study","their","there","these","thing","think","three","water","where","which","world","would","write"];
o1.value=f(["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"],p)
o2.value=f(["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"],p)
o3.value=f(["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"],p)

<input id=o1><input id=o2><input id=o3>


答:
Python, <s>64</s> <s>60</s> 57 bytes

Code to create word list w as string, words are space-separated (bytes are discounted from solution code length):

```<code>w="about after again below could every first found great house large learn never other place plant point right small sound spell still study their there these thing think three water where which world would write"
</code>```

Current solution (57 bytes): saved 3 bytes thanks to @RootTwo

```<code>import re;f=lambda a:re.findall("(?i)\\b"+"[%s]"*5%a,w)[0]
</code>```

This function takes a tuple (no list!) of exactly 5 strings which represent the possible letters for each password character as input.

See this code running on ideone.com

Second version (60 bytes):

```<code>import re;f=lambda a:re.findall("\\b"+"[%s]"*5%a+"(?i)",w)[0]
</code>```

This function takes a tuple (no list!) of exactly 5 strings which represent the possible letters for each password character as input.

See this code running on ideone.com

First version (64 bytes):

```<code>import re;f=lambda a:re.findall("\\b["+"][".join(a)+"](?i)",w)[0]
</code>```

This function takes any iterable (e.g. list or tuple) of exactly 5 strings which represent the possible letters for each password character as input.

See this code running on ideone.com

Title: On the Subject of Passwords

Body:
In Keep Talking and Nobody Explodes, players are tasked with defusing bombs based on information from their "experts" (other people with a manual). Each bomb is made up of modules, one of which can be passwords, where the expert is given this list of possible passwords, all five letters long:

```<code>about   after   again   below   could
every   first   found   great   house
large   learn   never   other   place
plant   point   right   small   sound
spell   still   study   their   there
these   thing   think   three   water
where   which   world   would   write
</code>```

And the player is given a list of 6 possible letters for each place in the password. Given the possible letter combinations, output the correct password. Input can be in any reasonable format (2D array, string separated by newline, etc.) You may discount the code which you use to compress/generate the list/string/array/whatever of passwords. (Thanks @DenkerAffe)

NOTE: Passwords are case insensitive. You may assume that input will only solve for one password.

Examples / Test Cases

Input here will be represented as a array of strings.

```<code>["FGARTW","LKSIRE","UHRKPA","TGYSTG","LUOTEU"] => first
["ULOIPE","GEYARF","SHRGWE","JEHSDG","EJHDSP"] => large
["SHWYEU","YEUTLS","IHEWRA","HWULER","EUELJD"] => still
</code>```

Body:
Python, <s>64</s> <s>60</s> 57 bytes

Code to create word list w as string, words are space-separated (bytes are discounted from solution code length):

w="about after again below could every first found great house large learn never other place plant point right small sound spell still study their there these thing think three water where which world would write"

Current solution (57 bytes): saved 3 bytes thanks to @RootTwo

import re;f=lambda a:re.findall("(?i)\\b"+"[%s]"*5%a,w)[0]

This function takes a tuple (no list!) of exactly 5 strings which represent the possible letters for each password character as input.

See this code running on ideone.com

Second version (60 bytes):

import re;f=lambda a:re.findall("\\b"+"[%s]"*5%a+"(?i)",w)[0]

This function takes a tuple (no list!) of exactly 5 strings which represent the possible letters for each password character as input.

See this code running on ideone.com

First version (64 bytes):

import re;f=lambda a:re.findall("\\b["+"][".join(a)+"](?i)",w)[0]

This function takes any iterable (e.g. list or tuple) of exactly 5 strings which represent the possible letters for each password character as input.

See this code running on ideone.com


答:
Brachylog, 25 bytes

```<code>:@laL,["about":"after":"again":"below":"could":"every":"first":"found":"great":"house":"large":"learn":"never":"other":"place":"plant":"point":"right":"small":"sound":"spell":"still":"study":"their":"there":"these":"thing":"think":"three":"water":"where":"which":"world":"would":"write"]:Jm.'(:ImC,L:Im'mC)
</code>```

The uncounted bytes are the array of words, including the square brackets.

Explanation

```<code>:@laL                          Unifies L with the input where each string is lowercased
     ,[...]:Jm.                Unifies the Output with one of the words
               '(            ) True if what's in the parentheses is false,
                               else backtrack and try another word
                 :ImC          Unify C with the I'th character of the output
                     ,L:Im'mC  True if C is not part of the I'th string of L
</code>```

Title: On the Subject of Passwords

Body:
Brachylog, 25 bytes

:@laL,["about":"after":"again":"below":"could":"every":"first":"found":"great":"house":"large":"learn":"never":"other":"place":"plant":"point":"right":"small":"sound":"spell":"still":"study":"their":"there":"these":"thing":"think":"three":"water":"where":"which":"world":"would":"write"]:Jm.'(:ImC,L:Im'mC)

The uncounted bytes are the array of words, including the square brackets.

Explanation

:@laL                          Unifies L with the input where each string is lowercased
     ,[...]:Jm.                Unifies the Output with one of the words
               '(            ) True if what's in the parentheses is false,
                               else backtrack and try another word
                 :ImC          Unify C with the I'th character of the output
                     ,L:Im'mC  True if C is not part of the I'th string of L


答:
Bash + GNU coreutils, 66 Bytes

In contrast to @Doorknob's solution, this one only needs things that are installed on every GNU/Linux:

```<code>for((n=2;;n++)){
[ `factor $n|wc -w` -eq 2 ]&&grep $1<<<$n&&exit
}
</code>```

Title: Print the nth prime that contains n

Body:
Bash + GNU coreutils, 66 Bytes

In contrast to @Doorknob's solution, this one only needs things that are installed on every GNU/Linux:

for((n=2;;n++)){
[ `factor $n|wc -w` -eq 2 ]&&grep $1<<<$n&&exit
}


答:
JavaScript, 80 ÷ 2 + 1 + 1 + 1 = 43

```<code>_=>[`Hi, Hello!`,`5 7 9 11 13 15 17 19 21 23 25`,`+-+
| |
+-+`,`Hello, bye!`][0]
</code>```

Change the 0 to 1, 2, or 3 as appropriate. I tried generating the odd numbers but that cost me a byte.

Title: Hi, can you draw some odd art? Bye!

Body:
Create a program that outputs "Hi, Hello!" in k bytes. By altering n bytes, the code should output all odd numbers in the range 5 <= x <= 25.
Changing another m bytes should result in a code that prints the following frame in ASCII-art:

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

Change another o bytes, and print Hello, bye!.

m, n and o are calculated in Levenshtein distance (cumulative). n is the distance from the first to the second code. m is the distance between the second and third and so on.

The score of your submission will be 0.5*k + n + m + o.

As an example:

```<code>The code that prints `Hi, Hello!` is 30 bytes.              15
Add two bytes and remove one and print the odd numbers     + 3
Alter three bytes in place, and add one to print the box   + 4
Remove four bytes and print `Hello, bye!`                  + 4
Total score:                                                26
</code>```

Rules

All codes must be in the same language

You have to follow the given order (i.e. the first code prints Hi, Hello, the second prints the numbers etc.)

The strings and ASCII-box must be exactly as specified. The list of digits can be on any suitable format

Body:
JavaScript, 80 ÷ 2 + 1 + 1 + 1 = 43

_=>[`Hi, Hello!`,`5 7 9 11 13 15 17 19 21 23 25`,`+-+
| |
+-+`,`Hello, bye!`][0]

Change the 0 to 1, 2, or 3 as appropriate. I tried generating the odd numbers but that cost me a byte.


问:
Divisor reduction
A divisor of a number n is any number that evenly divides n, including 1 and n itself. The number of divisors d(n) is how many divisors a number has. Here's d(n) for the first couple n:

```<code>n    divisors    d(n)
1    1           1
2    1, 2        2
3    1, 3        2
4    1, 2, 4     3
5    1, 5        2
6    1, 2, 3, 6  4
</code>```

We can repeatedly subtract the number of divisors from a number. For example:

```<code>16                  = 16
16 - d(16) = 16 - 5 = 11
11 - d(11) = 11 - 2 = 9
 9 - d( 9) =  9 - 3 = 6
 6 - d( 6) =  6 - 4 = 2
 2 - d( 2) =  2 - 2 = 0
</code>```

In this case it took 5 steps to get to 0.

Write a program or function that given a nonnegative number n returns the number of steps it takes to reduce it to 0 by repeated subtraction of the number of divisors.

Examples:

```<code>0, 0
1, 1
6, 2
16, 5
100, 19
100000, 7534
</code>```

答:
JavaScript (ES6), <s>64</s> 51 bytes

```<code>f=n=>n&&[...Array(m=n)].map((_,i)=>m-=n%++i<1)|f(m)+1
</code>```

Don't ask me why I was unnecessarily using tail recursion.

Title: Divisor reduction

Body:
JavaScript (ES6), <s>64</s> 51 bytes

f=n=>n&&[...Array(m=n)].map((_,i)=>m-=n%++i<1)|f(m)+1

Don't ask me why I was unnecessarily using tail recursion.


答:
05AB1E, <s>12</s> 10 bytes

Code:

```<code>[Ð>#Ñg-¼]¾
</code>```

Explanation:

```<code>[           # start infinite loop
 Ð          # triplicate current number
  >#        # increase by 1 and break if true
    Ñg      # get number of divisors
      -     # subtract number of divisors from number
       ¼    # increase counter
        ]   # end loop
         ¾  # print counter
</code>```

Try it online

Edit: 2 bytes saved and a bug with input 0 fixed thanks to @Adnan

Title: Divisor reduction

Body:
A divisor of a number n is any number that evenly divides n, including 1 and n itself. The number of divisors d(n) is how many divisors a number has. Here's d(n) for the first couple n:

```<code>n    divisors    d(n)
1    1           1
2    1, 2        2
3    1, 3        2
4    1, 2, 4     3
5    1, 5        2
6    1, 2, 3, 6  4
</code>```

We can repeatedly subtract the number of divisors from a number. For example:

```<code>16                  = 16
16 - d(16) = 16 - 5 = 11
11 - d(11) = 11 - 2 = 9
 9 - d( 9) =  9 - 3 = 6
 6 - d( 6) =  6 - 4 = 2
 2 - d( 2) =  2 - 2 = 0
</code>```

In this case it took 5 steps to get to 0.

Write a program or function that given a nonnegative number n returns the number of steps it takes to reduce it to 0 by repeated subtraction of the number of divisors.

Examples:

```<code>0, 0
1, 1
6, 2
16, 5
100, 19
100000, 7534
</code>```

Body:
05AB1E, <s>12</s> 10 bytes

Code:

[Ð>#Ñg-¼]¾

Explanation:

[           # start infinite loop
 Ð          # triplicate current number
  >#        # increase by 1 and break if true
    Ñg      # get number of divisors
      -     # subtract number of divisors from number
       ¼    # increase counter
        ]   # end loop
         ¾  # print counter

Try it online

Edit: 2 bytes saved and a bug with input 0 fixed thanks to @Adnan


问:
Toggle a string

The challenge involve simply toggling a string within another string.

Explanation

If the toggle string is a substring of the main string, remove all instances of the toggle string from the main string; otherwise, append the toggle string at the end of the main string.

Rules

All string are composed of printable ASCII characters

The function should take two parameters: the main string and the toggle string.

The main string can be empty.

The toggle string cannot be empty.

The result should be a string, which can be empty.

The shortest answer wins.

Examples

```<code>function toggle(main_string, toggle_string){ ... }

toggle('this string has 6 words ', 'now')
=> 'this string has 6 words now'

toggle('this string has 5 words now', ' now')
=> 'this string has 5 words'
</code>```

Tests cases

```<code>'','a'          => 'a'
'a','a'         => ''

'b','a'         => 'ba'
'ab','a'        => 'b'

'aba','a'       => 'b'
'ababa', 'aba'  => 'ba'
</code>```

答:
Kotlin, 61 Bytes

```<code>{m:String,t:String->var n=m.replace(t,"");if(m==n)m+t else n}
</code>```

This is would be shorter if assignment was an expression in Kotlin,and parameters were mutable,and there was a ternary conditional operator, sadly this isn't the case :(

Try it Online!

UnGolfed

```<code>fun t(m:String, t:String):String{
    var n=m.replace(t, "")
    return if(m==n)m+t else n
}
</code>```

Title: Toggle a string

Body:
Kotlin, 61 Bytes

{m:String,t:String->var n=m.replace(t,"");if(m==n)m+t else n}

This is would be shorter if assignment was an expression in Kotlin,and parameters were mutable,and there was a ternary conditional operator, sadly this isn't the case :(

Try it Online!

UnGolfed

fun t(m:String, t:String):String{
    var n=m.replace(t, "")
    return if(m==n)m+t else n
}


答:
Unix tools + imagemagick, 122 bytes

```<code>convert png:- ppm:-|tail -n +4|xxd -c3 -p|sort|uniq -c|sort -n|tail -n2|awk '{S[NR]=$1}END{print S[1]==S[2]?"equal":S[2]}'
</code>```

Expects the input png in stdin, prints the most dominant color in hex (RRGGBB) format.

How it works:

convert png:- ppm:- converts a png file to binary P6 ppm format

tail -n +4 skips the ppm header

xxd -c3 -p puts every RGB byte triplets on a new line in hex format

sort|uniq -c|sort -n orders the colors by their number of occurrence

tail -n2 gets the two most dominant colors

awk ...: prints the more dominant color or equal

Title: Get the most dominant color!

Body:
In this challenge, your task is to write a program that takes in an image and returns the most dominant color in it. Dominant color here means the color with which most of the image is covered (see the test cases for a better understanding).

Input

An image's path. You'll have to load that image in your program. You can take the input as STDIN, function argument or whatever suits your language. You may assume that the image will have only .png extension.

Output

The most dominant color in any format. (But it should be accurate, you can't return Red for #f88379). The type of output depends on you. If there is an equal distribution of colors in the image or there are more than one dominant color, then your program should return "Equal". You can show the output by printing on screen, logging on command line or console, or whatever suits you.

Test Cases

=> Red/#ff0000/rgba(255,0,0)

.

=> "Equal"

=> White (or the same color in any other format)

In these test cases, I have posted images rather than image paths, but you'll be given image paths only as input.

Note If your language contains a built-in for this, then you must NOT use it. Please add a screenshot or a link to a screenshot to prove that your program works.

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

Body:
Unix tools + imagemagick, 122 bytes

convert png:- ppm:-|tail -n +4|xxd -c3 -p|sort|uniq -c|sort -n|tail -n2|awk '{S[NR]=$1}END{print S[1]==S[2]?"equal":S[2]}'

Expects the input png in stdin, prints the most dominant color in hex (RRGGBB) format.

How it works:

convert png:- ppm:- converts a png file to binary P6 ppm format

tail -n +4 skips the ppm header

xxd -c3 -p puts every RGB byte triplets on a new line in hex format

sort|uniq -c|sort -n orders the colors by their number of occurrence

tail -n2 gets the two most dominant colors

awk ...: prints the more dominant color or equal


答:
Java 8, <s>192</s> <s>183</s> <s>181</s> 171 bytes (full program)

interface M{static void main(String[]a){long n=new Long(a[0]),c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(a[0])?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);System.out.print(r);}}
```
<p>Try it online.</p>
<p><strong>Explanation:</strong></p>
<pre class="lang-java prettyprint-override"><code>interface M{                    // Class
  static void main(String[]a){  //  Mandatory main-method
    long n=new Long(a[0]),      //   Input argument as number
         c=0,                   //   Counter, starting at 0
         r=1,                   //   Result-number, starting at 1
         m,i;                   //   Temp number
    for(;c<n;                   //   Loop as long as `c` does not equals `n`
        c+=                     //     After every iteration: increase `c` by:
           m>1                  //      If the current `r` is a prime,
           &(r+"").contains(a[0])?
                                //      and this prime contains the input `n`
            1                   //       Increase `c` by 1
           :                    //      Else:
            0)                  //       Leave `c` the same
      for(m=++r,                //    Increase `r` by 1 first with `++r`, and set `m` to it
          i=2;i<m;              //    Inner loop `i` in the range [2, `m`)
        m=m%i++<1?              //     If `m` is divisible by `i`
           0                    //      Change `m` to 0 (so it's not a prime)
          :                     //     Else:
           m);                  //      Leave `m` unchanged
    System.out.print(r);}}      //    Print `r` as result
</code>```

Java 8, 105 bytes (lambda function)

n->{int c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(n+"")?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);return r;}
```

Try it online.

Same as above, but with n as integer input and without the verbose class stuff.

Title: Print the nth prime that contains n

Body:
Java 8, <s>192</s> <s>183</s> <s>181</s> 171 bytes (full program)

interface M{static void main(String[]a){long n=new Long(a[0]),c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(a[0])?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);System.out.print(r);}}

Try it online.

Explanation:

interface M{                    // Class
  static void main(String[]a){  //  Mandatory main-method
    long n=new Long(a[0]),      //   Input argument as number
         c=0,                   //   Counter, starting at 0
         r=1,                   //   Result-number, starting at 1
         m,i;                   //   Temp number
    for(;c<n;                   //   Loop as long as `c` does not equals `n`
        c+=                     //     After every iteration: increase `c` by:
           m>1                  //      If the current `r` is a prime,
           &(r+"").contains(a[0])?
                                //      and this prime contains the input `n`
            1                   //       Increase `c` by 1
           :                    //      Else:
            0)                  //       Leave `c` the same
      for(m=++r,                //    Increase `r` by 1 first with `++r`, and set `m` to it
          i=2;i<m;              //    Inner loop `i` in the range [2, `m`)
        m=m%i++<1?              //     If `m` is divisible by `i`
           0                    //      Change `m` to 0 (so it's not a prime)
          :                     //     Else:
           m);                  //      Leave `m` unchanged
    System.out.print(r);}}      //    Print `r` as result

Java 8, 105 bytes (lambda function)

n->{int c=0,r=1,m,i;for(;c<n;c+=m>1&(r+"").contains(n+"")?1:0)for(m=++r,i=2;i<m;m=m%i++<1?0:m);return r;}

Try it online.

Same as above, but with n as integer input and without the verbose class stuff.


答:
Julia, 31 bytes

```<code>f(n)=n<1?0:f(sum(n%(1:n).>0))+1
</code>```

Straightforward recursive implementation.

Title: Divisor reduction

Body:
Julia, 31 bytes

f(n)=n<1?0:f(sum(n%(1:n).>0))+1

Straightforward recursive implementation.


答:
Clojure, 118 bytes

```<code>(defn s[n](nth(filter(fn[x](if(.contains(str x)(str n))(not-any? #(=(mod x %)0)(range 2 x))))(drop 2(range)))(dec n)))
</code>```

Just gets the nth element of lazy infinite sequence of numbers which are prime and have n in their string representation.

You can try it here : https://ideone.com/ioBJjt

Title: Print the nth prime that contains n

Body:
This question will be a twist on finding the nth prime number.

Challenge

You must write a program that will take one input n, and output the nth prime number whose decimal representation contains the decimal representation of n as a subtring.

Confused? Here are some examples.

```<code>n=1
Primes: 2, 3, 5, 7, 11
                    ^1 first prime that contains a 1
Output: 11

n=2
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
        ^1                          ^2 second prime that contains a 2
Output: 23

n=3
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
           ^1           ^2          ^3 third prime that contains a 3
Output: 23

n=10
Primes: 2, 3, 5, 7, 11, ..., 97, 101, 103, 107, 109, ..., 997, 1009, 1013, 1019, 1021, 1031, 1033
                                 ^1   ^2   ^3   ^4             ^5    ^6    ^7    ^8    ^9    ^10 tenth prime that contains a 10
Output: 1033
</code>```

This is code-golf, so lowest byte count wins.

If something is confusing, please leave a comment.

Body:
Clojure, 118 bytes

(defn s[n](nth(filter(fn[x](if(.contains(str x)(str n))(not-any? #(=(mod x %)0)(range 2 x))))(drop 2(range)))(dec n)))

Just gets the nth element of lazy infinite sequence of numbers which are prime and have n in their string representation.

You can try it here : https://ideone.com/ioBJjt


答:
Pyth, 10 bytes

```<code>tl.ulf%NTS
</code>```

Test suite.

Explanation

```<code>tl.ulf%NTS
tl.ulf%NTSNQ  implicit variables at the end
           Q  obtain the input number
  .u      N   repeat the following until result no longer unique:
         S        generate range from 1 to N
     f            filter for:
      %NT             T in that range, which N%T is truthy (not zero)
    l             length of that list
                  that means, we found the number of "non-divisors" of N
tl            number of iterations, minus 1.
</code>```

Title: Divisor reduction

Body:
Pyth, 10 bytes

tl.ulf%NTS

Test suite.

Explanation

tl.ulf%NTS
tl.ulf%NTSNQ  implicit variables at the end
           Q  obtain the input number
  .u      N   repeat the following until result no longer unique:
         S        generate range from 1 to N
     f            filter for:
      %NT             T in that range, which N%T is truthy (not zero)
    l             length of that list
                  that means, we found the number of "non-divisors" of N
tl            number of iterations, minus 1.


答:
Rust, 84 bytes

```<code>fn toggle(a:&str,b:&str)->String{let mut r=a.replace(b,"");if&r==a{r.push_str(b)}r}
</code>```

Try it on play.rust-lang.org.

Title: Toggle a string

Body:
The challenge involve simply toggling a string within another string.

Explanation

If the toggle string is a substring of the main string, remove all instances of the toggle string from the main string; otherwise, append the toggle string at the end of the main string.

Rules

All string are composed of printable ASCII characters

The function should take two parameters: the main string and the toggle string.

The main string can be empty.

The toggle string cannot be empty.

The result should be a string, which can be empty.

The shortest answer wins.

Examples

```<code>function toggle(main_string, toggle_string){ ... }

toggle('this string has 6 words ', 'now')
=> 'this string has 6 words now'

toggle('this string has 5 words now', ' now')
=> 'this string has 5 words'
</code>```

Tests cases

```<code>'','a'          => 'a'
'a','a'         => ''

'b','a'         => 'ba'
'ab','a'        => 'b'

'aba','a'       => 'b'
'ababa', 'aba'  => 'ba'
</code>```

Body:
Rust, 84 bytes

fn toggle(a:&str,b:&str)->String{let mut r=a.replace(b,"");if&r==a{r.push_str(b)}r}

Try it on play.rust-lang.org.


答:
Jelly, <s>10</s> 9 bytes

1 byte thanks to Dennis ♦.

Port of my answer in Pyth.

```<code>ÆDLạµÐĿL’
</code>```

Try it online!

Test suite.

Explanation

```<code>_ÆDL$$ÐĿL’
      ÐĿ    Repeat the following until result no longer unique:
 ÆD             Yield the array of the divisors
   L            Yield the length of the array
_               Subtract that from the number
        L   Number of iterations
         ’  Minus one.
</code>```

Title: Divisor reduction

Body:
Jelly, <s>10</s> 9 bytes

1 byte thanks to Dennis ♦.

Port of my answer in Pyth.

ÆDLạµÐĿL’

Try it online!

Test suite.

Explanation

_ÆDL$$ÐĿL’
      ÐĿ    Repeat the following until result no longer unique:
 ÆD             Yield the array of the divisors
   L            Yield the length of the array
_               Subtract that from the number
        L   Number of iterations
         ’  Minus one.


答:
MATL, 14 bytes

```<code>`t~?x@q.]t:\zT
</code>```

Try it online!

Explanation

```<code>`            T  % Infinite loop
 t~?    ]       % Duplicate number. Is it non-zero?
    x@q.        % If so: delete number, push iteration index minus 1, break loop
         t:\    % Duplicate, range, modulo (remainder). Divisors give a 0 remainder
            z   % Number of non-zero elements; that is, of non-divisors
</code>```

Title: Divisor reduction

Body:
MATL, 14 bytes

`t~?x@q.]t:\zT

Try it online!

Explanation

`            T  % Infinite loop
 t~?    ]       % Duplicate number. Is it non-zero?
    x@q.        % If so: delete number, push iteration index minus 1, break loop
         t:\    % Duplicate, range, modulo (remainder). Divisors give a 0 remainder
            z   % Number of non-zero elements; that is, of non-divisors


问:
Find the Factorial!
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

$$n!:=\begin{cases}1 & n=0\\n\cdot(n-1)!&n>0\end{cases}$$

In plain English the factorial of 0 is 1 and the factorial of n, where n is larger than 0 is n times the factorial of one less than n.

Your code should perform input and output using a standard methods.

Requirements:

Does not use any built-in libraries that can calculate the factorial (this includes any form of eval)

Can calculate factorials for numbers up to 125

Can calculate the factorial for the number 0 (equal to 1)

Completes in under a minute for numbers up to 125

The shortest submission wins, in the case of a tie the answer with the most votes at the time wins.

答:
Pyke, 2 bytes

```<code>SB
</code>```

Try it here!

```<code>   - implicit input
S  -  range(1, input+1)
 B - product(^)
</code>```

Title: Find the Factorial!

Body:
Pyke, 2 bytes

SB

Try it here!

   - implicit input
S  -  range(1, input+1)
 B - product(^)


问:
Count up forever
Write a program that counts up forever, starting from one.

Rules:

Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.

Your program must be a full, runnable program, and not a function or snippet.

Your program must output each number with a separating character in between (a newline, space, tab or comma), but this must be consistent for all numbers.

You may print the numbers in decimal, in unary or in base 256 where each digit is represented by a byte value.

Your program must count at least as far as 2128 (inclusive) without problems and without running out of memory on a reasonable desktop PC. In particular, this means if you're using unary, you cannot store a unary representation of the current number in memory.

Unlike our usual rules, feel free to use a language (or language version) even if it's newer than this challenge. Languages specifically written to submit a 0-byte answer to this challenge are fair game but not particularly interesting.

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

This is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Lua, 27 Bytes

i=1::a::i=i+1print(i)goto a
```

Title: Count up forever


答:
R, 50 bytes

Pretty simple implementation. Try it online

```<code>z=scan();i=0;while(z>0){z=z-sum(z%%1:z<1);i=i+1};i
</code>```

Title: Divisor reduction

Body:
R, 50 bytes

Pretty simple implementation. Try it online

z=scan();i=0;while(z>0){z=z-sum(z%%1:z<1);i=i+1};i


问:
Fibonacci products
You can decompose a number greater than 0 as a unique sum of positive Fibonacci numbers. In this question we do this by repeatedly subtracting the largest possible positive Fibonacci number. E.g.:

```<code>1 = 1
2 = 2
3 = 3
4 = 3 + 1
12 = 8 + 3 + 1
13 = 13
100 = 89 + 8 + 3
</code>```

Now, I call a Fibonacci product the same lists as above, but with the addition replaced by multiplication. For example, \$f(100) = 89 \times 8 \times 3 = 2136\$.

Write a program or function that given a positive integer n returns the Fibonacci product of that number.

Testcases:

```<code>1: 1
2: 2
3: 3
4: 3
5: 5
6: 5
7: 10
8: 8
9: 8
42: 272
1000: 12831
12345: 138481852236
</code>```

答:
Q, 47 Bytes

```<code>m:{*/1_-':|(0<){y-x x bin y}[*+60(|+\)\1 0]\x}
</code>```

Test

```<code>+(i;m'i:1 2 3 4 5 6 7 8 9 42 1000 12345)
</code>```

read it as pairs (i,map(m,i)), where m is the calculating function and i the different args

writes

```<code>1     1
2     2
3     3
4     3
5     5
6     5
7     10
8     8
9     8
42    272
1000  12831
12345 138481852236
</code>```

Explanation

n funtion\arg    applies function(function(function(...function(args))) n times (internally uses tal recursion), and returns the sequence of results. We calculate the 60 first items of fibonnaci series as *+60(|+\)\1 0. In that case the function is (|+): +\ applied over a sequence calculates partial sums (ex +\1 2 3 is 1 3 6), and | reverses seq. So each 'iteration' we calculate partial sums of the two previous fibonacci number and return the partial sums reversed. 60(|+\)\1 0 generates sequences 1  0, 1  1, 2  1, 3  2, 5  3, 8  5, 13 8, 21 13, ... *+ applied over this result flip (traspose) it and takes the first. Result is sequence 1 1 2 3 5 8 13 21 34 55 ..

(cond)function\args applies function(function(..function(args))) while cond true, and returns the sequence of partial results

function[arg] applied over a function of more than one argument creates a projection (partial application)

We can give name to the args, but the implicit names are x,y,z

{y-x x bin y}[*+60(|+\)\1 0] declares a lambda with args x,y with partial projection (arg x is fibonacci series, calculates as *+60(|+)\1 0). x represent fibonacci values, and y the number to process. Binary search (bin) is used to locate the index of the greater fibonacci number <=y (x bin y), and substract the corresponding value of x.

To calculate product from partial resuls we reverse them and calculate difference of each pair (-':|), drop the first (1_ because is 0) and multiply over (*/).

If we are interested in accumulated sum the code is the same, but with +/ instead of */. We can also use any other diadic operator instead of + or *

About execution efficiency

I know that in this contest efficiency is not an issue. But in this problem we can range from lineal cost to exponential cost, so i'm curious about it.

I developed a second version (length 48 Bytes excluding comment) and repeated test cases battery 1000 times on both versions.

```<code>f:*+60(|+\)\1 0;m:{*/1_-':|(0<){x-f f bin x}\x}    /new version
</code>```

execution time is: original version 0'212 seg, new version 0'037 seg

Original version calculates fibbonaci serie once per function application; new version calculates fibonacci just one.

In both cases calculation of fibonacci series uses tail recursion

Title: Fibonacci products

Body:
Q, 47 Bytes

m:{*/1_-':|(0<){y-x x bin y}[*+60(|+\)\1 0]\x}

Test

+(i;m'i:1 2 3 4 5 6 7 8 9 42 1000 12345)

read it as pairs (i,map(m,i)), where m is the calculating function and i the different args

writes

1     1
2     2
3     3
4     3
5     5
6     5
7     10
8     8
9     8
42    272
1000  12831
12345 138481852236

Explanation

n funtion\arg    applies function(function(function(...function(args))) n times (internally uses tal recursion), and returns the sequence of results. We calculate the 60 first items of fibonnaci series as *+60(|+\)\1 0. In that case the function is (|+): +\ applied over a sequence calculates partial sums (ex +\1 2 3 is 1 3 6), and | reverses seq. So each 'iteration' we calculate partial sums of the two previous fibonacci number and return the partial sums reversed. 60(|+\)\1 0 generates sequences 1  0, 1  1, 2  1, 3  2, 5  3, 8  5, 13 8, 21 13, ... *+ applied over this result flip (traspose) it and takes the first. Result is sequence 1 1 2 3 5 8 13 21 34 55 ..

(cond)function\args applies function(function(..function(args))) while cond true, and returns the sequence of partial results

function[arg] applied over a function of more than one argument creates a projection (partial application)

We can give name to the args, but the implicit names are x,y,z

{y-x x bin y}[*+60(|+\)\1 0] declares a lambda with args x,y with partial projection (arg x is fibonacci series, calculates as *+60(|+)\1 0). x represent fibonacci values, and y the number to process. Binary search (bin) is used to locate the index of the greater fibonacci number <=y (x bin y), and substract the corresponding value of x.

To calculate product from partial resuls we reverse them and calculate difference of each pair (-':|), drop the first (1_ because is 0) and multiply over (*/).

If we are interested in accumulated sum the code is the same, but with +/ instead of */. We can also use any other diadic operator instead of + or *

About execution efficiency

I know that in this contest efficiency is not an issue. But in this problem we can range from lineal cost to exponential cost, so i'm curious about it.

I developed a second version (length 48 Bytes excluding comment) and repeated test cases battery 1000 times on both versions.

f:*+60(|+\)\1 0;m:{*/1_-':|(0<){x-f f bin x}\x}    /new version

execution time is: original version 0'212 seg, new version 0'037 seg

Original version calculates fibbonaci serie once per function application; new version calculates fibonacci just one.

In both cases calculation of fibonacci series uses tail recursion


问:
Shortest code to produce infinite output
Write the shortest code you can that produces an infinite output.

That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code wins.

Here's a list of answers that I think are really clever, so they can get credit:

The comma is both code and data

Infinite errors (that counts)

Infinite warnings (that also counts)

What's Marbelous?

Leaderboard

var QUESTION_ID=13152,OVERRIDE_USER=8611;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

```

答:
Scratch, 3 bytes

(scoring used)

Adds a blank item to list = repeatedly and indefinitely.


答:
PHP 65

```<code>function f($s,$v){return($m=str_replace($v,'',$s))==$s?$s.$v:$m;}
</code>```

Inspired from Kevin Cruijssen's java example.

Title: Toggle a string

Body:
PHP 65

function f($s,$v){return($m=str_replace($v,'',$s))==$s?$s.$v:$m;}

Inspired from Kevin Cruijssen's java example.


答:
Clojure, 53 bytes

```<code>#(reduce +(map(fn[x](* x x))(range 1(Math/sqrt %)2)))
</code>```

You can check it here: https://ideone.com/WKS4DA

Title: Sum the odd square numbers less than N

Body:
Write a program or function to output the sum of the odd square numbers (OEIS #A016754) less than an input n.

The first 44 numbers in the sequence are:

```<code>1, 9, 25, 49, 81, 121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961, 1089,
1225, 1369, 1521, 1681, 1849, 2025, 2209, 2401, 2601, 2809, 3025, 3249, 3481,
3721, 3969, 4225, 4489, 4761, 5041, 5329, 5625, 5929, 6241, 6561, 6889, 7225, 7569
</code>```

The formula for the sequence is a(n) = ( 2n + 1 ) ^ 2.

Notes

Your program's behaviour may be undefined for n < 1 (that is, all valid inputs are >= 1.)

Test cases

```<code>1 => 0
2 => 1
9 => 1
10 => 10
9801 => 156849
9802 => 166650
10000 => 166650
</code>```

Body:
Clojure, 53 bytes

#(reduce +(map(fn[x](* x x))(range 1(Math/sqrt %)2)))

You can check it here: https://ideone.com/WKS4DA


答:
Python, 49 bytes

```<code>f=lambda n:n and-~f(sum(n%~x<0for x in range(n)))
</code>```

orlp helped save a byte! And Sp3000 saved two more. Thanks!

Title: Divisor reduction

Body:
A divisor of a number n is any number that evenly divides n, including 1 and n itself. The number of divisors d(n) is how many divisors a number has. Here's d(n) for the first couple n:

```<code>n    divisors    d(n)
1    1           1
2    1, 2        2
3    1, 3        2
4    1, 2, 4     3
5    1, 5        2
6    1, 2, 3, 6  4
</code>```

We can repeatedly subtract the number of divisors from a number. For example:

```<code>16                  = 16
16 - d(16) = 16 - 5 = 11
11 - d(11) = 11 - 2 = 9
 9 - d( 9) =  9 - 3 = 6
 6 - d( 6) =  6 - 4 = 2
 2 - d( 2) =  2 - 2 = 0
</code>```

In this case it took 5 steps to get to 0.

Write a program or function that given a nonnegative number n returns the number of steps it takes to reduce it to 0 by repeated subtraction of the number of divisors.

Examples:

```<code>0, 0
1, 1
6, 2
16, 5
100, 19
100000, 7534
</code>```

Body:
Python, 49 bytes

f=lambda n:n and-~f(sum(n%~x<0for x in range(n)))

orlp helped save a byte! And Sp3000 saved two more. Thanks!


Title: Divisor reduction

Body:
C, 52 bytes

g,o;l(f){for(g=o=f;o;f%o--||--g);return f?1+l(g):0;}


答:
PowerShell v2+, <s>74</s> 67 bytes

```<code>param($n)for($o=0;$n-gt0){$a=0;1..$n|%{$a+=!($n%$_)};$n-=$a;$o++}$o
</code>```

Seems pretty lengthy in comparison to some of the other answers...

Takes input $n, enters a for loop with the condition that $n is greater than 0. Each loop iteration we set helper $a, then loop through every number from 1 up to $n. Each inner loop we check against every number to see if it's a divisor, and if so we increment our helper $a (using Boolean negation and implicit cast-to-int). Then, we subtract how many divisors we've found $n-=$a and increment our counter $o++. Finally, we output $o.

Takes a long time to execute, since it's a significant for-loop construct. For example, running n = 10,000 on my machine (1yr old Core i5) takes almost 3 minutes.

Title: Divisor reduction

Body:
PowerShell v2+, <s>74</s> 67 bytes

param($n)for($o=0;$n-gt0){$a=0;1..$n|%{$a+=!($n%$_)};$n-=$a;$o++}$o

Seems pretty lengthy in comparison to some of the other answers...

Takes input $n, enters a for loop with the condition that $n is greater than 0. Each loop iteration we set helper $a, then loop through every number from 1 up to $n. Each inner loop we check against every number to see if it's a divisor, and if so we increment our helper $a (using Boolean negation and implicit cast-to-int). Then, we subtract how many divisors we've found $n-=$a and increment our counter $o++. Finally, we output $o.

Takes a long time to execute, since it's a significant for-loop construct. For example, running n = 10,000 on my machine (1yr old Core i5) takes almost 3 minutes.


答:
PowerShell v2+, <s>108</s> 99 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

```<code>param($n)for(){for(;'1'*++$i-match'^(?!(..+)\1+$)..'){if("$i"-like"*$n*"){if(++$o-eq$n){$i;exit}}}}
</code>```

Takes input $n, enters an infinite for() loop. Each iteration, we use a for loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the loop. (For example, running just for(){for(;'1'*++$i-match'^(?!(..+)\1+$)..'){$i}} will output 2, 3, 5, 7... separated by newlines).

Then a simple -like check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime and the process repeats.

Title: Print the nth prime that contains n

Body:
This question will be a twist on finding the nth prime number.

Challenge

You must write a program that will take one input n, and output the nth prime number whose decimal representation contains the decimal representation of n as a subtring.

Confused? Here are some examples.

```<code>n=1
Primes: 2, 3, 5, 7, 11
                    ^1 first prime that contains a 1
Output: 11

n=2
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
        ^1                          ^2 second prime that contains a 2
Output: 23

n=3
Primes: 2, 3, 5, 7, 11, 13, 17, 19, 23
           ^1           ^2          ^3 third prime that contains a 3
Output: 23

n=10
Primes: 2, 3, 5, 7, 11, ..., 97, 101, 103, 107, 109, ..., 997, 1009, 1013, 1019, 1021, 1031, 1033
                                 ^1   ^2   ^3   ^4             ^5    ^6    ^7    ^8    ^9    ^10 tenth prime that contains a 10
Output: 1033
</code>```

This is code-golf, so lowest byte count wins.

If something is confusing, please leave a comment.

Body:
PowerShell v2+, <s>108</s> 99 bytes

Ooof. The lack of any sort of built-in prime calculation/checking really hurts here.

param($n)for(){for(;'1'*++$i-match'^(?!(..+)\1+$)..'){if("$i"-like"*$n*"){if(++$o-eq$n){$i;exit}}}}

Takes input $n, enters an infinite for() loop. Each iteration, we use a for loop wrapped around the PowerShell regex prime checker (h/t to Martin) to turn it into a prime generator by incrementing $i each time through the loop. (For example, running just for(){for(;'1'*++$i-match'^(?!(..+)\1+$)..'){$i}} will output 2, 3, 5, 7... separated by newlines).

Then a simple -like check to see if $n is somewhere in $i, and increment our counter $o. If we've reached where $n and $o are equal, output $i and exit. Otherwise we continue through the for to find the next prime and the process repeats.


答:
Mathematica 30 bytes

```<code>Total[Range[1,Sqrt[#-1],2]^2]&
</code>```

This unnamed function squares all odd numbers less than the input (Range[1,Sqrt[#-1],2]) and adds them.

Title: Sum the odd square numbers less than N

Body:
Mathematica 30 bytes

Total[Range[1,Sqrt[#-1],2]^2]&

This unnamed function squares all odd numbers less than the input (Range[1,Sqrt[#-1],2]) and adds them.


问:
Calculator that adds char values

Task

Build a calculator, that takes any string, from a file, stdin or whatever, and adds up all the values of the chars.

Example

```<code>Input
Hello World!

Output
1085
</code>```

Rules

The calculator needs to accept just ASCII encoding.

The shortest code wins.

Notes

Regarding to the comment of m.buettner, I need to say, I didn't thought of the multibyte part.

So I leave it as a bonus thing aswell.

The calculator should be run as written, so no need to modify before compiling or interpreting.

Bonus

Thanks to Synthetica, here is one more bonus,

The program that has the lowest output when you use its code as its input wins gets a star.

I don't want to modify it completly.

If you write it additional to output the (right) value in UTF-8 you get a star.

The code that executes fastest on my Laptop (Lenovo Yoga 13 Intel Core i5 3317U 1.7Ghz, 8GB RAM, 128GB SSD, Intel HD 4000, Windows 8) gets a star.

Web codes will run first under IE11 with chakra and then in FireFox 29.0.1 with SpiderMonkey

Linux code will run on a Raspberry Pi with Raspbian.

The teststring is this:

```<code>q/%8hnp>T%y?'wNb\},9krW &D9']K$n;l.3O+tE*$*._B^s!@k\&Cl:EO1zo8sVxEvBxCock_I+2o6 yeX*0Xq:tS^f)!!7=!tk9K<6#/E`ks(D'$z$\6Ac+MT&[s[]_Y(`<g%"w%cW'`c&q)D$0#C$QGf>?A$iawvc,}`9!('`c&q)D$0#C$QGf>?A$iawvc,}`9!(
</code>```

Have fun coding :)

Bonusscoring

I plan to do the scoring at this Saturday so the 07.06.14, all answers after that date won't get bonus points ;)

You can download the code I gonna use for testing here feel free to fork and improve it :)

Little update because of the bonus, my laptop is partially broken so I will do it probably next weekend, I am really sorry for that :(

答:
Clojure, 31 bytes

```<code>#(reduce +(map int(read-line)))
</code>```

Really straightforward. Gets its input from stdin, works with Unicode.

Title: Calculator that adds char values

Body:
Clojure, 31 bytes

#(reduce +(map int(read-line)))

Really straightforward. Gets its input from stdin, works with Unicode.


答:
bash + sed, 28 bytes

```<code>sed "s/$2//g;t;s/$/$2/"<<<$1
</code>```

The script lives in a toggle-string.bash file, which we call with bash toggle-string.bash mainstring togglestring.

s/$2//g removes the toggle string from the main string

t jumps to the end if the previous substitution was successful (ie. the main string contained the toggle string)

/$/$2/ adds the toggle string at the end ($), if we didn't jump to the end

bash is required for the herestring

Title: Toggle a string

Body:
The challenge involve simply toggling a string within another string.

Explanation

If the toggle string is a substring of the main string, remove all instances of the toggle string from the main string; otherwise, append the toggle string at the end of the main string.

Rules

All string are composed of printable ASCII characters

The function should take two parameters: the main string and the toggle string.

The main string can be empty.

The toggle string cannot be empty.

The result should be a string, which can be empty.

The shortest answer wins.

Examples

```<code>function toggle(main_string, toggle_string){ ... }

toggle('this string has 6 words ', 'now')
=> 'this string has 6 words now'

toggle('this string has 5 words now', ' now')
=> 'this string has 5 words'
</code>```

Tests cases

```<code>'','a'          => 'a'
'a','a'         => ''

'b','a'         => 'ba'
'ab','a'        => 'b'

'aba','a'       => 'b'
'ababa', 'aba'  => 'ba'
</code>```

Body:
bash + sed, 28 bytes

sed "s/$2//g;t;s/$/$2/"<<<$1

The script lives in a toggle-string.bash file, which we call with bash toggle-string.bash mainstring togglestring.

s/$2//g removes the toggle string from the main string

t jumps to the end if the previous substitution was successful (ie. the main string contained the toggle string)

/$/$2/ adds the toggle string at the end ($), if we didn't jump to the end

bash is required for the herestring


答:
Python 3, 69/2 + 1 + 1 + 1 = 37.5 points.

It's the same approach as the other answers, but in Python.

```<code>print(['Hi, Hello!',*range(5,27,2),'+-+\n| |\n+-+','Hello, bye!'][1])
</code>```

Change the number to the one you want for a distance of 1.

Title: Hi, can you draw some odd art? Bye!

Body:
Create a program that outputs "Hi, Hello!" in k bytes. By altering n bytes, the code should output all odd numbers in the range 5 <= x <= 25.
Changing another m bytes should result in a code that prints the following frame in ASCII-art:

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

Change another o bytes, and print Hello, bye!.

m, n and o are calculated in Levenshtein distance (cumulative). n is the distance from the first to the second code. m is the distance between the second and third and so on.

The score of your submission will be 0.5*k + n + m + o.

As an example:

```<code>The code that prints `Hi, Hello!` is 30 bytes.              15
Add two bytes and remove one and print the odd numbers     + 3
Alter three bytes in place, and add one to print the box   + 4
Remove four bytes and print `Hello, bye!`                  + 4
Total score:                                                26
</code>```

Rules

All codes must be in the same language

You have to follow the given order (i.e. the first code prints Hi, Hello, the second prints the numbers etc.)

The strings and ASCII-box must be exactly as specified. The list of digits can be on any suitable format

Body:
Python 3, 69/2 + 1 + 1 + 1 = 37.5 points.

It's the same approach as the other answers, but in Python.

print(['Hi, Hello!',*range(5,27,2),'+-+\n| |\n+-+','Hello, bye!'][1])

Change the number to the one you want for a distance of 1.