问:
The Decanting Problem
Given N decanters (0 < N < 10) with that can hold C0 ... CN-1 liters (0 < C < 50) and a goal G liters, please determine if it is possible to reach that goal using only the following actions:

Fill a decanter

Empty a decanter

Pour from one decanter to another until the one being poured to is full or the one being poured from is empty

The goal amount G must be the amount of water in one of the containers at the end. You cannot have a 'output decanter'.

Examples

N: 2

C0: 5

C1: 12

G: 1

Result: Yes

N: 3

C0: 6

C1: 9

C2: 21

G: 5

Result: No

Hint: To calculate if it is possible, check to see if G is divisible by the GCD of the capacities. Also, make sure it will fit in a container.

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

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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 leaderboard snippet:

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

var QUESTION_ID=94202,OVERRIDE_USER=12537;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

```

答:
Perl, 47 bytes

Includes +2 for -ap

Run with the jar sizes on the first line of STDIN and the target jar on the second line:

```<code>decanter.pl; echo
2 5 12
1
^D
</code>```

decanter.pl:

```<code>#!/usr/bin/perl -p
$_=($_<@G)>$_%$=;$=--while@G[@F]=grep$_%$=,@F
</code>```

This solution is unusual in that it processes the input line by line and outputs something for each of them. The output for the first line was carefully designed to be empty while the second line prints the solution. Two bytes are lost on () because < and > are designed to be non-associative in perl.

The regex solution is also nice but 49 bytes:

```<code>#!/usr/bin/perl -p
s/\d+/1x$&/eg;$_=/^(?>(1+)( |\1)*:)(\1+)$/&/$3./
</code>```

(some parts stolen from the Retina solution)

For this one give input on STDIN as jars separated by spaces and target after a ::

```<code>decanter.pl <<< "2 5 12:1"
</code>```

Hard to beat languages with a builtin gcd (21 bytes) and max (7 bytes) for this one...

Title: The Decanting Problem

Body:
Perl, 47 bytes

Includes +2 for -ap

Run with the jar sizes on the first line of STDIN and the target jar on the second line:

decanter.pl; echo
2 5 12
1
^D

decanter.pl:

#!/usr/bin/perl -p
$_=($_<@G)>$_%$=;$=--while@G[@F]=grep$_%$=,@F

This solution is unusual in that it processes the input line by line and outputs something for each of them. The output for the first line was carefully designed to be empty while the second line prints the solution. Two bytes are lost on () because < and > are designed to be non-associative in perl.

The regex solution is also nice but 49 bytes:

#!/usr/bin/perl -p
s/\d+/1x$&/eg;$_=/^(?>(1+)( |\1)*:)(\1+)$/&/$3./

(some parts stolen from the Retina solution)

For this one give input on STDIN as jars separated by spaces and target after a ::

decanter.pl <<< "2 5 12:1"

Hard to beat languages with a builtin gcd (21 bytes) and max (7 bytes) for this one...


问:
The Base in the mix
Input:

A list/array of integers for which each item is in the range of 2-36.

Output:

The sum of the integers (as base 10), where each next integer is in the base of the previous value (starting with a regular base 10).

Example:

Let's say we have an input like this: [4, 12, 34, 20, 14, 6, 25, 13, 33]

Then we have a sum like this:

```<code>4    (4  in base-10) +
6    (12 in base-4 ) +
40   (34 in base-12) +
68   (20 in base-34) +
24   (14 in base-20) +
6    (6  in base-14) +
17   (25 in base-6 ) +
28   (13 in base-26) +
42   (33 in base-13)
= 235
</code>```

Mathematical base explained:

I considered assuming everyone knows how base works, but I'll give a brief example of how it works anyway, just in case. Let's take the 34 in base-12 for example, how did we get 40?

```<code>1-34 in regular base-10:
 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34
 So, from 1 to 34 is 34 steps in base-10

1-34 in base-12:
 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2A, 2B, 30, 31, 32, 33, 34
 So, from 1 to 34 is 40 steps in base-12
</code>```

Here is perhaps a useful calculator.

Challenge rules:

Array size will be in reasonable range (like 1-100 / see test cases).

The test cases will never contain integers of which the current value is invalid for it's previous base (i.e. You will never have something like 19 in base-6 or 6 in base-6, because base-6 only contains the digits 0-5).

You can take the input any way you'd like. Can be as an int-array, as a comma/space-separated string, etc. Your call. (You are also allowed to take the int-array reversed, which could be useful for stack-based programming languages.)

General Rules:

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

Don't let code-golf languages discourage you from posting answers with non-golfing languages. Try to come up with as short an answer as possible for any programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>[4, 12, 34, 20, 14, 6, 25, 13, 33]                            ->   235
 4+ 6+  40+ 68+ 24+ 6+ 17+ 28+ 42

[5, 14, 2, 11, 30, 18]                                        ->   90
 5+ 9+  2+ 3+  33+ 38

[12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 12, 2, 11, 3, 10, 2, 10]    ->   98
 12+ 13+ 11+ 9+ 8+ 7+ 6+ 5+ 4+ 3+ 5+  2+ 3+  3+ 3+  2+ 2

[36, 36]                                                      ->   150
 36+ 114
</code>```

答:
Mathematica, 59 bytes

I wish Mathematica's function names were shorter. But otherwise I'm happy.

```<code>Tr[FromDigits@@@Transpose@{IntegerDigits/@{##,0},{10,##}}]&
</code>```

For example,

```<code>Tr[FromDigits@@@Transpose@{IntegerDigits/@{##,0},{10,##}}]&[4,12,34,20,14,6,25,13,33]
</code>```

yields 235.

{##,0} is a list of the input arguments with 0 appended (representing the numerals); {10,##} is a list of the input arguments with 10 prepended (representing the bases). That pair of lists is Transposed to associate each with numeral with its base, and FromDigits (yay!) converts each numeral-base pair to a base-10 integer, the results of which are summed by Tr.

ContentLicense: CC BY-SA 3.0

Title: The Base in the mix

Body:
Mathematica, 59 bytes

I wish Mathematica's function names were shorter. But otherwise I'm happy.

Tr[FromDigits@@@Transpose@{IntegerDigits/@{##,0},{10,##}}]&

For example,

Tr[FromDigits@@@Transpose@{IntegerDigits/@{##,0},{10,##}}]&[4,12,34,20,14,6,25,13,33]

yields 235.

{##,0} is a list of the input arguments with 0 appended (representing the numerals); {10,##} is a list of the input arguments with 10 prepended (representing the bases). That pair of lists is Transposed to associate each with numeral with its base, and FromDigits (yay!) converts each numeral-base pair to a base-10 integer, the results of which are summed by Tr.


问:
Is it a balanced number?
A number is balanced if the sum of the digits on each half of the number is equal, so: 1423 is balanced because 1+4 = 2+3, so is: 42615 because 4+2=1+5. Note that the middle digit is not included on either side (or it's included on both sides) if there's an odd number of digits.

Challenge:

Take a positive integer as input, and output a truthy value if it's balanced and a falsy value if it's unbalanced.

Test cases (true)

```<code>1
6
11
141
1221
23281453796004414
523428121656666655655556655656502809745249552466339089702361716477983610754966885128041975406005088
</code>```

Test cases (false)

```<code>10
12
110
15421
5234095123508321
6240911314399072459493765661191058613491863144152352262897351988250431140546660035648795316740212454
</code>```

There will not be numbers starting with zero, for instance 00032 instead of 32. You must support numbers up to at least 100 digits (so larger than 2^64-1). As always, optional input format, so you may surround the number with apostrophes if desired.

答:
C function, 74

l;i;t;f(char *n){l=strlen(n);for(t=i=0;i<l/2;)t+=n[i]-n[l-++i];return !t;}
```

Ideone.

ContentLicense: CC BY-SA 4.0

Title: Is it a balanced number?

Body:
C function, 74

l;i;t;f(char *n){l=strlen(n);for(t=i=0;i<l/2;)t+=n[i]-n[l-++i];return !t;}

Ideone.


问:
Is it an Odd Word?

Challenge

Given a single word as input, determine if the word is odd or even.

Odd and Even words

Assume the general rules:

```<code>odd + odd = even
even + odd = odd
odd + even = odd
even + even = even
</code>```

In the alphabet, the odd letters are:

```<code>aeiou
</code>```

And the even letters are:

```<code>bcdfghjklmnpqrstvwxyz
</code>```

The same applies to capital letters (AEIOU are odd and BCDFGHJKLMNPQRSTVWXYZ are even).

You then 'add' each of the letters in the word together. For example, the word cats is equivalent to:

```<code>even + odd + even + even
</code>```

Which simplifies to:

```<code>odd + even
</code>```

Which simplifies further to:

```<code>odd
</code>```

So the word cats is odd.

Examples

```<code>Input:  trees
Output: even
</code>```

```<code>Input:  brush
Output: odd
</code>```

```<code>Input:  CAts
Output: odd
</code>```

```<code>Input:  Savoie
Output: even
</code>```

```<code>Input:  rhythm
Output: even
</code>```

Rules

All input will be a single word which will only contain alphabetical characters.

If the word is odd, output a truthy value. If the word is even, output a falsey value.

Winning

The shortest code in bytes wins.

答:
Lithp, 56 bytes

```<code>#S::((& 1 (~ (length (split S (regex "[aeiou]" "i"))))))
</code>```

Odd words: returns 1

Even words: returns 0

This was one of my test cases for developing my language. It was modified extensively after this challenge was posted to support running code such as this.

This is the same logic as the JavaScript response above. The language is a simplistic Lisp-like dialect with a fairly small interpreter.

Ungolfed:

```<code>(
    (var F #S::(
        (var L (split S (regex "[aeiou]" "i")))
        (& 1 (~ (length L)))
    ))
    (print (call F "brush"))
)
</code>```

There is not currently an online repl to test this in, but there is a variation of this challenge in one of the provided examples that can be run with the interpreter.

Title: Is it an Odd Word?

Body:
Lithp, 56 bytes

#S::((& 1 (~ (length (split S (regex "[aeiou]" "i"))))))

Odd words: returns 1

Even words: returns 0

This was one of my test cases for developing my language. It was modified extensively after this challenge was posted to support running code such as this.

This is the same logic as the JavaScript response above. The language is a simplistic Lisp-like dialect with a fairly small interpreter.

Ungolfed:

(
    (var F #S::(
        (var L (split S (regex "[aeiou]" "i")))
        (& 1 (~ (length L)))
    ))
    (print (call F "brush"))
)

There is not currently an online repl to test this in, but there is a variation of this challenge in one of the provided examples that can be run with the interpreter.


答:
Pure bash, 38

b=10
for i;{((t+=$b#$i,b=i));}
echo $t
```

The input list is given at the command-line.  for i; automatically iterates over the input parameters (equivalent to for i in $@;).

Ideone.

Title: The Base in the mix

Body:
Input:

A list/array of integers for which each item is in the range of 2-36.

Output:

The sum of the integers (as base 10), where each next integer is in the base of the previous value (starting with a regular base 10).

Example:

Let's say we have an input like this: [4, 12, 34, 20, 14, 6, 25, 13, 33]

Then we have a sum like this:

```<code>4    (4  in base-10) +
6    (12 in base-4 ) +
40   (34 in base-12) +
68   (20 in base-34) +
24   (14 in base-20) +
6    (6  in base-14) +
17   (25 in base-6 ) +
28   (13 in base-26) +
42   (33 in base-13)
= 235
</code>```

Mathematical base explained:

I considered assuming everyone knows how base works, but I'll give a brief example of how it works anyway, just in case. Let's take the 34 in base-12 for example, how did we get 40?

```<code>1-34 in regular base-10:
 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34
 So, from 1 to 34 is 34 steps in base-10

1-34 in base-12:
 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1A, 1B, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2A, 2B, 30, 31, 32, 33, 34
 So, from 1 to 34 is 40 steps in base-12
</code>```

Here is perhaps a useful calculator.

Challenge rules:

Array size will be in reasonable range (like 1-100 / see test cases).

The test cases will never contain integers of which the current value is invalid for it's previous base (i.e. You will never have something like 19 in base-6 or 6 in base-6, because base-6 only contains the digits 0-5).

You can take the input any way you'd like. Can be as an int-array, as a comma/space-separated string, etc. Your call. (You are also allowed to take the int-array reversed, which could be useful for stack-based programming languages.)

General Rules:

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

Don't let code-golf languages discourage you from posting answers with non-golfing languages. Try to come up with as short an answer as possible for any programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>[4, 12, 34, 20, 14, 6, 25, 13, 33]                            ->   235
 4+ 6+  40+ 68+ 24+ 6+ 17+ 28+ 42

[5, 14, 2, 11, 30, 18]                                        ->   90
 5+ 9+  2+ 3+  33+ 38

[12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 12, 2, 11, 3, 10, 2, 10]    ->   98
 12+ 13+ 11+ 9+ 8+ 7+ 6+ 5+ 4+ 3+ 5+  2+ 3+  3+ 3+  2+ 2

[36, 36]                                                      ->   150
 36+ 114
</code>```

Body:
Pure bash, 38

b=10
for i;{((t+=$b#$i,b=i));}
echo $t

The input list is given at the command-line.  for i; automatically iterates over the input parameters (equivalent to for i in $@;).

Ideone.


问:
Tips for golfing in vim
I've recently realized how vim works great for golfing, especially for kolmogorov-complexity. Also, according to meta vim is a perfectly acceptable 'programming language' at least, for the scope of this site, that is.

What general tips do you have for golfing in Vim? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Vim (e.g. "remove comments" is not an answer).

Please post one tip per answer.

答:
Know your registers

Yanking or deleting text into a specific register (e.g. "aY) to use it later isn't always necessary. Vim has several registers that are automatically populated with the subjects of various commands. Type :help registers to see them all, but here's a few of particular note:

Unnamed register: "" - The last text that was yanked or deleted.

Numbered register "0 - The last text that was yanked.

Numbered registers "1–"9 - The last text that was deleted unless it was less than one line. Each time "1 is filled its previous contents are shifted to "2 and so on.

Small delete register: "- - The last text shorter than one line that was deleted.

Last inserted text: ".

In particular, the "- and "1 registers can be useful together, enabling you to delete some text with e.g. dd into the "1 register and delete some other text with D into the "- (of course, the semantics aren't identical, but often they don't need to be).

All of the registers can be a little tough to keep track of, but you can see the contents of all of your registers at any time by typing :registers.

Title: Tips for golfing in vim


问:
Draw the € sign
The goal is to output or display an image with an € (euro) sign according to the following specs (ignoring the border of the sign).

Source: http://en.wikipedia.org/wiki/File:Euro_Construction.svg

Rules:

The program / script must take the height of the € sign in pixels as an argument (empty space around the sign is optional)

The € sign can't be drawn as or from a character, directly (it's forbidden to print the € in the image) or indirectly (calculating 8364 then displaying it in a HTML page)

The output does not need to be saved to any file, it can be displayed then just shown as a screenshot

Standard “loopholes” are forbidden

Shortest code wins

答:
Processing, 232 bytes

Processing doesn't really allow taking in command line arguments since it is so specialized for drawing, but my function takes in the parameter as height to compensate.  Coordinates are hard-coded/approximated from the image above, and the entire canvas is scaled based on the input parameter to get drawings of arbitrary sizes.

```<code>void E(int h){scale(h/12,h/12);noFill();strokeWeight(1);arc(7.5,6,11,11,0.7,PI*2-0.7,OPEN);noStroke();fill(0);shearX(-PI/6);rect(3.2,4.5,9,1);rect(4.4,6.5,8,1);shearX(PI/6);fill(255);rect(11,6,9,6);triangle(8.75,6,12.25,6,12.25,0);}
</code>```

Ungolfed + entire program

```<code>void setup()
{
  size(575, 500);
}

void draw()
{
  background(255);
  E(height);
  noLoop();
}

void E(int h)
{
  scale(h/12,h/12);
  //Main "C"
  noFill();
  strokeWeight(1);
  arc(7.5,6,11,11,0.7,PI*2-0.7,OPEN);
  //settings for other shapes
  noStroke();
  //the two bars
  fill(0);
  shearX(-PI/6);
  rect(3.2,4.5,9,1);
  rect(4.4,6.5,8,1);
  //bottom cut of "C"
  shearX(PI/6);
  fill(255);
  rect(11,6,9,6);
  //top cut of "C"
  triangle(8.75,6,12.25,6,12.25,0);
}
</code>```

Output

Title: Draw the € sign

Body:
Processing, 232 bytes

Processing doesn't really allow taking in command line arguments since it is so specialized for drawing, but my function takes in the parameter as height to compensate.  Coordinates are hard-coded/approximated from the image above, and the entire canvas is scaled based on the input parameter to get drawings of arbitrary sizes.

void E(int h){scale(h/12,h/12);noFill();strokeWeight(1);arc(7.5,6,11,11,0.7,PI*2-0.7,OPEN);noStroke();fill(0);shearX(-PI/6);rect(3.2,4.5,9,1);rect(4.4,6.5,8,1);shearX(PI/6);fill(255);rect(11,6,9,6);triangle(8.75,6,12.25,6,12.25,0);}

Ungolfed + entire program

void setup()
{
  size(575, 500);
}

void draw()
{
  background(255);
  E(height);
  noLoop();
}

void E(int h)
{
  scale(h/12,h/12);
  //Main "C"
  noFill();
  strokeWeight(1);
  arc(7.5,6,11,11,0.7,PI*2-0.7,OPEN);
  //settings for other shapes
  noStroke();
  //the two bars
  fill(0);
  shearX(-PI/6);
  rect(3.2,4.5,9,1);
  rect(4.4,6.5,8,1);
  //bottom cut of "C"
  shearX(PI/6);
  fill(255);
  rect(11,6,9,6);
  //top cut of "C"
  triangle(8.75,6,12.25,6,12.25,0);
}

Output


问:
Find the minimum and maximum integers in an array, without using builtins

Challenge

Given an array of integers, received from stdin, function arguments, program arguments, or some other method:

Output only the minimum and maximum numbers in the array, through a return value, stdout, or other fitting methods.

Example session

```<code>> minmax( {0, 15, 2, 3, 7, 18, -2, 9, 6, -5, 3, 8, 9, -14} )
-14 18
</code>```

Reference implementation

```<code>// C++14

void minmax(std::vector<int> v) {
    int min = v[0]; int max = v[0];
    for(auto it : v) {
        if (*it < min)
            min = *it;
        if (*it > max)
            max = *it;
    }
    std::cout << min << ' ' << max << std::endl;
}
</code>```

Rules

You may not use a built-in function to calculate the values.

Standard loopholes disallowed.

Creative implementations encouraged.

This is code-golf, shortest answer wins but will not be selected.

Clarifications

If the array contains 1 element you need to output it twice.

If the minimum and maximum values are the same, you need to output them both.

答:
Java, 115 bytes

```<code>String f(int[]i){int t=i[0],a=t,b=t;for(int c=0;c<i.length;c++){a=i[c]<a?i[c]:a;b=i[c]>b?i[c]:b;}return""+a+" "+b;}
</code>```

Ungolfed:

```<code>String f(int[] i) {
    int t=i[0], a=t, b=t; // assigns a and b to i[0]
    for (int c=0; c < i.length; c++) { // loop through the array
        a=(i[c]<a) ? i[c] : a;
        b=(i[c]>b) ? i[c] : b; // assignment with ternary operator
    }
    return ""+a+" "+b; // returns a string
}
</code>```

My first ever code "golf" solution.

Body:
Java, 115 bytes

String f(int[]i){int t=i[0],a=t,b=t;for(int c=0;c<i.length;c++){a=i[c]<a?i[c]:a;b=i[c]>b?i[c]:b;}return""+a+" "+b;}

Ungolfed:

String f(int[] i) {
    int t=i[0], a=t, b=t; // assigns a and b to i[0]
    for (int c=0; c < i.length; c++) { // loop through the array
        a=(i[c]<a) ? i[c] : a;
        b=(i[c]>b) ? i[c] : b; // assignment with ternary operator
    }
    return ""+a+" "+b; // returns a string
}

My first ever code "golf" solution.


答:
R, <s>105</s> 96 bytes

Turns out R is very verbose. Takes input as a character.

```<code>function(x){y<-as.numeric(unlist(strsplit(x,"")));l<-length(y)%/%2;sum(tail(y,l))==sum(head(y,l))}
</code>```

Formatted nicely:

```<code>function(x){
    y=as.numeric(unlist(strsplit(x,"")))
    l=length(y)%/%2
    sum(tail(y,l))==sum(head(y,l))
}
</code>```

Explanation

y<-as.numeric(unlist(strsplit(x,""))) Split the input (a string_, and coerce it to a vector instead of a list, and then turn it back into integers.

sum(tail(y,:         tail takes the last n elements, found by:

length(y)%/%2)), where %/% is integer division, to get the ceiling of the quotient, where the length is odd.

sum(head(y,length(y)%/%2)): like tail, head takes the first n elements of the vector, found in the same way.

Edits

Saved seven bytes thanks to niam

Switched to = instead of <- , saved another two bytes.

Title: Is it a balanced number?

Body:
A number is balanced if the sum of the digits on each half of the number is equal, so: 1423 is balanced because 1+4 = 2+3, so is: 42615 because 4+2=1+5. Note that the middle digit is not included on either side (or it's included on both sides) if there's an odd number of digits.

Challenge:

Take a positive integer as input, and output a truthy value if it's balanced and a falsy value if it's unbalanced.

Test cases (true)

```<code>1
6
11
141
1221
23281453796004414
523428121656666655655556655656502809745249552466339089702361716477983610754966885128041975406005088
</code>```

Test cases (false)

```<code>10
12
110
15421
5234095123508321
6240911314399072459493765661191058613491863144152352262897351988250431140546660035648795316740212454
</code>```

There will not be numbers starting with zero, for instance 00032 instead of 32. You must support numbers up to at least 100 digits (so larger than 2^64-1). As always, optional input format, so you may surround the number with apostrophes if desired.

Body:
R, <s>105</s> 96 bytes

Turns out R is very verbose. Takes input as a character.

function(x){y<-as.numeric(unlist(strsplit(x,"")));l<-length(y)%/%2;sum(tail(y,l))==sum(head(y,l))}

Formatted nicely:

function(x){
    y=as.numeric(unlist(strsplit(x,"")))
    l=length(y)%/%2
    sum(tail(y,l))==sum(head(y,l))
}

Explanation

y<-as.numeric(unlist(strsplit(x,""))) Split the input (a string_, and coerce it to a vector instead of a list, and then turn it back into integers.

sum(tail(y,:         tail takes the last n elements, found by:

length(y)%/%2)), where %/% is integer division, to get the ceiling of the quotient, where the length is odd.

sum(head(y,length(y)%/%2)): like tail, head takes the first n elements of the vector, found in the same way.

Edits

Saved seven bytes thanks to niam

Switched to = instead of <- , saved another two bytes.


答:
JavaScript <s>95</s> 88 bytes

```<code>i=>(s=(i,a,b)=>[...i.slice(a,b)].reduce((p,e)=>p-e,0))(i=i+"",0,m=i.length/2)==s(i,m+.5)
</code>```

Explanation:

Convert input to a string, create a function that takes string segments and sums up all of the digits, and call that function for the left and right halves of the input.

Title: Is it a balanced number?

Body:
JavaScript <s>95</s> 88 bytes

i=>(s=(i,a,b)=>[...i.slice(a,b)].reduce((p,e)=>p-e,0))(i=i+"",0,m=i.length/2)==s(i,m+.5)

Explanation:

Convert input to a string, create a function that takes string segments and sums up all of the digits, and call that function for the left and right halves of the input.


问:
Write the implementation to pass this test
Given the following test, implement an addOne function in C# so it passes, without any modification to the test. TIP: Yes, it is possible.

```<code>[TestMethod]
public void TheChallenge()
{
    int a = 1;

    addOne(a);

    Assert.IsTrue(a == 2);
}
</code>```

EDIT: clarified the Assert to avoid confusion. The value of a should be 2; there's no trick there.

答:
Ummm, simply provide an implementation of AssertTrue that doesn't throw anything?

```<code>void addOne(int a){}

void AssertTrue(bool b) { }
</code>```

You never specified what testing framework is used here. It looks like MSTest, but I fired up a new test project and AssertTrue doesn't exist, so I took the liberty of implementing it myself.

EDIT

This solution might be what you were fishing for:

```<code>void addOne(int x)
{
  unsafe
  {
    int* i = &x;
    i += 4;
    *i += 1;
  }
}
</code>```

I feels pretty fragile, but it works on my box consistently. It probably depends heavily on the compiler, so hopefully it is reproducible elsewhere.

Body:
Ummm, simply provide an implementation of AssertTrue that doesn't throw anything?

void addOne(int a){}

void AssertTrue(bool b) { }

You never specified what testing framework is used here. It looks like MSTest, but I fired up a new test project and AssertTrue doesn't exist, so I took the liberty of implementing it myself.

EDIT

This solution might be what you were fishing for:

void addOne(int x)
{
  unsafe
  {
    int* i = &x;
    i += 4;
    *i += 1;
  }
}

I feels pretty fragile, but it works on my box consistently. It probably depends heavily on the compiler, so hopefully it is reproducible elsewhere.


问:
Return the flipped version of a number
When a number is shown on a calculator, it's possible to consider what various transformations of that number would look like. For example, on a seven-segment display, 2 is shown like this:

And when flipped horizontally it looks like this:

As such, the mirror image of 2 is 5.

The task in this challenge is to take a single-digit number, and return the number that's its mirror image (if possible). If its mirror image does not look like a number, return the number rotated 180 degrees (if possible). If neither of these are the case, return -1.

Here's the full list of inputs and outputs your program needs to handle:

```<code>Input   Output
0       0
1       -1
2       5
3       -1
4       -1
5       2
6       9
7       -1
8       8
9       6
</code>```

As a code-golf challenge, the shortest code wins!

答:
dimwit <s>24</s> 23 bytes (non-competing)

Edit: removed end bracket, as it is not necessary

Another question that I thought could be good for working on the language with...

```<code>R2,5,6,9,[1-7]}5,2,9,6,-1
</code>```

Explanation:

R - map replace

2,5,7,9,[1-7]} - the searches. Since 2, 5, 6, and 9 are checked first, 1-7 can be used and will simply check if it's 1, 3, 4, or 7. 0 and 8 will therefore stay the same.

5,2,9,6,-1 - the replacements. So 2 is replaced by 5, 5 is replaced by 2, etc.

Try it Here

Title: Return the flipped version of a number

Body:
dimwit <s>24</s> 23 bytes (non-competing)

Edit: removed end bracket, as it is not necessary

Another question that I thought could be good for working on the language with...

R2,5,6,9,[1-7]}5,2,9,6,-1

Explanation:

R - map replace

2,5,7,9,[1-7]} - the searches. Since 2, 5, 6, and 9 are checked first, 1-7 can be used and will simply check if it's 1, 3, 4, or 7. 0 and 8 will therefore stay the same.

5,2,9,6,-1 - the replacements. So 2 is replaced by 5, 5 is replaced by 2, etc.

Try it Here


问:
Invert a boolean array
A nice simple one

Input

Given a boolean array (Or an acceptable alternative), you can assume the array will never be more than 32 elements long.

```<code>[false, false, true, false, false]
</code>```

Output

Invert every element of the array and output it.

```<code>[true, true, false, true, true]
</code>```

Rules

You can write a full program or just a function

Standard loopholes apply

Shortest code in bytes, per language, wins!

Test cases

```<code>Input:
[true, false]
Output:
[false, true]

Input: //Example of acceptable alternative
[0,1,1]
Output:
[1,0,0]
</code>```

答:
dimwit 8 bytes (non-competing)

```<code>R1,0}0,1
</code>```

Replaces all 0's with 1's, and vice versa.

Takes input through a string of 0's and 1's, and outputs similarly.
Hopefully that's acceptable ;)

Try it here!

Title: Invert a boolean array

Body:
dimwit 8 bytes (non-competing)

R1,0}0,1

Replaces all 0's with 1's, and vice versa.

Takes input through a string of 0's and 1's, and outputs similarly.
Hopefully that's acceptable ;)

Try it here!


答:
Do calculations with the expression register

You can do calculations in both normal mode and insert mode.

Normal mode

In normal mode, if you type @= your cursor will move to the command line, where you can enter any expression. When you press enter, the result of the expression will be executed as normal mode commands.

For example, suppose you want to go to the middle column of the current line. The function call col('$') returns the number of columns in the line, so we can accomplish what by typing the following:

```<code>@=col('$')/2<CR>|
</code>```

When you press enter, the cursor returns to the buffer and vim waits for an operator (like |) as though you had just entered a number. Alternatively, you could have entered this:

```<code>@=col('$')/2.'|'
</code>```

...but of course that's more bytes.

Insert mode

You can use the expression register in insert mode, too, by pressing <Ctrl-r>= instead of @=. It works the same in normal mode, except the result of the expression you enter will be executed in insert mode. For example, if you typed <Ctrl-r>=col('$')<CR>, the number of columns in the current line would be inserted at the cursor as though you had typed it.

For more information on the expression register, type :help "=.

Reusing expressions

The last expression you used is stored in the expression register, "=. Typing @=<CR> in normal mode or <Ctrl-r>=<CR> in insert mode will evaluate the expression again, allowing you to use them much like macros.

Do calculations in substitutions

You can evaluate expressions when doing regular expression substitutions, too. All you have to do is begin your substitution with \=. For example, suppose you wanted to number the lines in this file:

```<code>foo
bar
baz
</code>```

The function call line('.') returns the current line number, so the job is easy. Entering this:

```<code>:s/^/\=line('.').' '/g<CR>
</code>```

...yields the desired result:

```<code>1 foo
2 bar
3 baz
</code>```

To use captured groups in such an expression you can use the submatch() function, where e.g. submatch(0) is equivalent to \0 in an ordinary substitution, submatch(1) is equivalent to \1, etc. This eats up a lot of keystrokes, unfortunately.

For more information on expression substitution, type :help sub-replace-expression.

Title: Tips for golfing in vim

Body:
I've recently realized how vim works great for golfing, especially for kolmogorov-complexity. Also, according to meta vim is a perfectly acceptable 'programming language' at least, for the scope of this site, that is.

What general tips do you have for golfing in Vim? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Vim (e.g. "remove comments" is not an answer).

Please post one tip per answer.

Body:
Do calculations with the expression register

You can do calculations in both normal mode and insert mode.

Normal mode

In normal mode, if you type @= your cursor will move to the command line, where you can enter any expression. When you press enter, the result of the expression will be executed as normal mode commands.

For example, suppose you want to go to the middle column of the current line. The function call col('$') returns the number of columns in the line, so we can accomplish what by typing the following:

@=col('$')/2<CR>|

When you press enter, the cursor returns to the buffer and vim waits for an operator (like |) as though you had just entered a number. Alternatively, you could have entered this:

@=col('$')/2.'|'

...but of course that's more bytes.

Insert mode

You can use the expression register in insert mode, too, by pressing <Ctrl-r>= instead of @=. It works the same in normal mode, except the result of the expression you enter will be executed in insert mode. For example, if you typed <Ctrl-r>=col('$')<CR>, the number of columns in the current line would be inserted at the cursor as though you had typed it.

For more information on the expression register, type :help "=.

Reusing expressions

The last expression you used is stored in the expression register, "=. Typing @=<CR> in normal mode or <Ctrl-r>=<CR> in insert mode will evaluate the expression again, allowing you to use them much like macros.

Do calculations in substitutions

You can evaluate expressions when doing regular expression substitutions, too. All you have to do is begin your substitution with \=. For example, suppose you wanted to number the lines in this file:

foo
bar
baz

The function call line('.') returns the current line number, so the job is easy. Entering this:

:s/^/\=line('.').' '/g<CR>

...yields the desired result:

1 foo
2 bar
3 baz

To use captured groups in such an expression you can use the submatch() function, where e.g. submatch(0) is equivalent to \0 in an ordinary substitution, submatch(1) is equivalent to \1, etc. This eats up a lot of keystrokes, unfortunately.

For more information on expression substitution, type :help sub-replace-expression.


Title: Return the flipped version of a number

Body:
When a number is shown on a calculator, it's possible to consider what various transformations of that number would look like. For example, on a seven-segment display, 2 is shown like this:

And when flipped horizontally it looks like this:

As such, the mirror image of 2 is 5.

The task in this challenge is to take a single-digit number, and return the number that's its mirror image (if possible). If its mirror image does not look like a number, return the number rotated 180 degrees (if possible). If neither of these are the case, return -1.

Here's the full list of inputs and outputs your program needs to handle:

```<code>Input   Output
0       0
1       -1
2       5
3       -1
4       -1
5       2
6       9
7       -1
8       8
9       6
</code>```

As a code-golf challenge, the shortest code wins!

Body:
C - 47 bytes [was 48 Bytes]

f(i){return(int[]){1,0,6,0,0,3,10,0,9,7}[i]-1;}

To add I/O (which other answers didn't always) for 86 bytes:

main(i){i=(int[]){1,0,6,0,0,3,10,0,9,7}[getchar()-48]-1;i<0?puts("-1"):putchar(i+48);}


问:
ASCII Odd/Even Cipher
We'll define the ASCII Odd/Even Cipher via the below pseudocode:

```<code>Define 'neighbor' as the characters adjacent to the current letter in the string

If the one of the neighbors is out of bounds of the string, treat it as \0 or null

Take an input string

For each letter in the string, do
  If the 0-based index of the current letter is even, then
    Use the binary-or of the ASCII codes of both its neighbors
  Else
    If the ASCII code of the current letter is odd, then
      Use the binary-or of itself plus the left neighbor
    Else
      Use the binary-or of itself plus the right neighbor
  In all cases,
    Convert the result back to ASCII and return it
  If this would result in a code point 127 or greater to be converted, then
    Instead return a space

Join the results of the For loop back into one string and output it
</code>```

For example, for input Hello, the output is emmol, since

The H turns to \0 | 'e' which is e

The e turns to 'e' | 'l', or 101 | 108, which is 109 or m

The first l also turns to 101 | 108 or m

The second l turns to 108 | 111, which is 111 or o

The o turns to 108 | \0, or l

Input

A sentence composed solely of printable ASCII characters, in any suitable format.

The sentence may have periods, spaces, and other punctuation, but will only ever be one line.

The sentence will be at least three characters in length.

Output

The resulting cipher, based on the rules described above, returned as a string or output.

The Rules

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

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

Examples

Input on one line, output on the following. Blank lines separate examples.

```<code>Hello
emmol

Hello, World!
emmol, ww~ved

PPCG
PSWG

Programming Puzzles and Code Golf
r wogsmmoonpuu ~ meannncoooeggonl

abcdefghijklmnopqrstuvwxyz
bcfefgnijknmno~qrsvuvw~yzz

!abcdefghijklmnopqrstuvwxyz
aaccgeggoikkomoo qsswuww yy

Test 123 with odd characters. R@*SKA0z8d862
euutu133www|todddchizsscguwssr`jS{SK{z~|v66
</code>```

答:
Mathematica, 152 bytes

```<code>FromCharacterCode[BitOr@@Which[OddQ@Max@#2,#~Drop~{2},OddQ@#[[2]],Most@#,True,Rest@#]/._?(#>126&)->32&~MapIndexed~Partition[ToCharacterCode@#,3,1,2,0]]&
</code>```

Explanation

```<code>ToCharacterCode@#
</code>```

Converts string to ASCII codes

```<code>Partition[...,3,1,2,0]
</code>```

Partitions the ASCII codes to length 3, offset 1 partitions, with padded 0s.

```<code>...~MapIndexed~...
</code>```

Applys a function for each partition.

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

If...else if... else in Mathematica.

```<code>OddQ@Max@#2
</code>```

Checks whether the index (#2) is odd. (Max is for flattening); since Mathematica index starts at 1, I used OddQ here, not EvenQ

```<code>Drop[#,{2}]
</code>```

Takes the ASCII codes of the left and right neighbors.

```<code>OddQ@#[[2]]
</code>```

Checks whether the ASCII code of the corresponding character is odd.

```<code>Most@#
</code>```

Takes the ASCII codes of the character and the left neighbor.

```<code>Rest@#
</code>```

Takes the ASCII codes of the character and the right neighbor.

```<code>BitOr
</code>```

Applys or-operation.

```<code>/._?(#>126&)->32
</code>```

Replaces all numbers greater than 126 with 32 (space).

```<code>FromCharacterCode
</code>```

Converts ASCII code back to characters and join them.

Title: ASCII Odd/Even Cipher

Body:
Mathematica, 152 bytes

FromCharacterCode[BitOr@@Which[OddQ@Max@#2,#~Drop~{2},OddQ@#[[2]],Most@#,True,Rest@#]/._?(#>126&)->32&~MapIndexed~Partition[ToCharacterCode@#,3,1,2,0]]&

Explanation

ToCharacterCode@#

Converts string to ASCII codes

Partition[...,3,1,2,0]

Partitions the ASCII codes to length 3, offset 1 partitions, with padded 0s.

...~MapIndexed~...

Applys a function for each partition.

Which[...]

If...else if... else in Mathematica.

OddQ@Max@#2

Checks whether the index (#2) is odd. (Max is for flattening); since Mathematica index starts at 1, I used OddQ here, not EvenQ

Drop[#,{2}]

Takes the ASCII codes of the left and right neighbors.

OddQ@#[[2]]

Checks whether the ASCII code of the corresponding character is odd.

Most@#

Takes the ASCII codes of the character and the left neighbor.

Rest@#

Takes the ASCII codes of the character and the right neighbor.

BitOr

Applys or-operation.

/._?(#>126&)->32

Replaces all numbers greater than 126 with 32 (space).

FromCharacterCode

Converts ASCII code back to characters and join them.


问:
Substring Chainification

Introduction

For this example, let's take the string Hello, World! and the array [3, 2, 3]. To find the substring chain, we go through the following process:

The first number of the array is 3, so we get the substring [0 - 3], which is Hel. After that, we remove the first 3 characters from the initial string, which leaves us with lo, World!.

The second number of the array is 2, so we get the substring [0 - 2] from our new string, which gives us lo. The leftover string becomes , World!.

The last number is a 3, which gives us , W. The substring chain is all of the substrings combined, which gives us:

```<code>['Hel', 'lo', ', W']
</code>```

For a more visual example:

```<code>[3, 2, 3], 'Hello, World!'
3 -> Hel
2 ->    lo
3 ->      , W
</code>```

The task

Given a non-empty string and a non-empty array only consisting of positive integers (> 0), output the substring chain. You may assume that the sum of all integers in the array does not exceed the length of the string.

You can also assume that the strings will never contain any newlines.

Test cases

```<code>Input: abcdefghijk, [2, 1, 3]
Output: ['ab', 'c', 'def']

Input: Code Golf, [4, 1]
Output: ['Code', ' ']

Input: Ayyy, [3]
Output: ['Ayy']

Input: lexicographically, [2, 2, 2, 7, 4]
Output: ['le', 'xi', 'co', 'graphic', 'ally']
</code>```

This is code-golf, so the submission with the smallest number of bytes wins!

答:
Ruby, 28 bytes

```<code>->a,w{a.map{|e|w.slice!0,e}}
</code>```

In case arguments are an array of positive integers and one string.

Title: Substring Chainification

Body:
Ruby, 28 bytes

->a,w{a.map{|e|w.slice!0,e}}

In case arguments are an array of positive integers and one string.


答:
JavaScript (ES6), 68 58 bytes (without sorting)

Oh my first try in Golf: without explicit sort (and without min max).

Thanks to @ETHproductions for golfing tips!!

```<code>a=>(b=[],a.map(n=>b[n]=0),[b.indexOf(0),b.lastIndexOf(0)])
</code>```

Does not work with negative integers.

Tried @Luis Mendo 's approach but got it 2 bytes longer... Cost for supporting negative numbers lol?

```<code>a=>[a.find(n=>a.every(e=>e>=n)),a.find(n=>a.every(e=>e<=n))]
</code>```

Could get shorter if order of output is not important:

```<code>a=>a.filter(n=>a.every(e=>e>=n)||a.every(e=>e<=n))
</code>```

Title: Find the minimum and maximum integers in an array, without using builtins

Body:
Challenge

Given an array of integers, received from stdin, function arguments, program arguments, or some other method:

Output only the minimum and maximum numbers in the array, through a return value, stdout, or other fitting methods.

Example session

```<code>> minmax( {0, 15, 2, 3, 7, 18, -2, 9, 6, -5, 3, 8, 9, -14} )
-14 18
</code>```

Reference implementation

```<code>// C++14

void minmax(std::vector<int> v) {
    int min = v[0]; int max = v[0];
    for(auto it : v) {
        if (*it < min)
            min = *it;
        if (*it > max)
            max = *it;
    }
    std::cout << min << ' ' << max << std::endl;
}
</code>```

Rules

You may not use a built-in function to calculate the values.

Standard loopholes disallowed.

Creative implementations encouraged.

This is code-golf, shortest answer wins but will not be selected.

Clarifications

If the array contains 1 element you need to output it twice.

If the minimum and maximum values are the same, you need to output them both.

Body:
JavaScript (ES6), 68 58 bytes (without sorting)

Oh my first try in Golf: without explicit sort (and without min max).

Thanks to @ETHproductions for golfing tips!!

a=>(b=[],a.map(n=>b[n]=0),[b.indexOf(0),b.lastIndexOf(0)])

Does not work with negative integers.

Tried @Luis Mendo 's approach but got it 2 bytes longer... Cost for supporting negative numbers lol?

a=>[a.find(n=>a.every(e=>e>=n)),a.find(n=>a.every(e=>e<=n))]

Could get shorter if order of output is not important:

a=>a.filter(n=>a.every(e=>e>=n)||a.every(e=>e<=n))


问:
Prime counting function

Introduction

The Prime Counting Function, also known as the Pi function \$\pi(x)\$, returns the amount of primes less than or equal to x.

Challenge

Your program will take an integer x which you can assume to be positive, and output a single integer equal to the amount of primes less than or equal to x. This is a code-golf challenge, so the winner will be the program with the fewest bytes.

You may use any language of your choosing provided that it existed before this challenge went up, but if the language has a built-in prime-counting function or a primality checking function (such as Mathematica), that function cannot be used in your code.

Example Inputs

Input:

1

Output:

0

Input:

2

Output:

1

Input:

5

Output:

3

A000720 - OEIS

答:
Pyke, <s>8</s> 6 bytes

```<code>SmPs}l
</code>```

Try it here!

Thanks to Maltysen for new algorithm

```<code>SmP    -    map(factorise, input)
   s   -   sum(^)
    }  -  uniquify(^)
     l - len(^)
</code>```

Title: Prime counting function

Body:
Pyke, <s>8</s> 6 bytes

SmPs}l

Try it here!

Thanks to Maltysen for new algorithm

SmP    -    map(factorise, input)
   s   -   sum(^)
    }  -  uniquify(^)
     l - len(^)


问:
We're no strangers to code golf, you know the rules, and so do I
Write the shortest program that prints the entire lyrics of "Never Gonna Give You Up" by Rick Astley.

Rules:

Must output the lyrics exactly as they appear in the above pastebin*. Here's the raw dump: http://pastebin.com/raw/wwvdjvEj

Cannot rely on any external resources - all lyrics must be generated by / embedded in code.

No use of existing compression algorithms (e.g. gzip / bzip2) unless you include the full algorithm in your code.

Use any language, shortest code wins.

Update, 1st June 2012:

For solutions containing non-ASCII text, the size of your solution will be counted in bytes, based on UTF-8 encoding. If you use codepoints that cannot be encoded in UTF-8, your solution will not be judged as valid.

Update, 7th June 2012:

Thank you all for your awesome solutions! I'll be accepting the shortest answer tomorrow afternoon. Right now, Peter Taylor's GolfScript answer is winning, so get cracking on some improvements if you want to beat him! :)

*There is a typo in the Pastebin (line 46, "know" should be "known").  You may either replicate it or not at your discretion.


答:
PHP, 30 bytes

```<code>foreach($argv[1] as$i)echo!$i;
</code>```

Testing code:

```<code>$argv[1] = [true,true,false,true,false,false,true,false];
foreach($argv[1] as$i)echo!$i;
</code>```

Test online

Title: Invert a boolean array

Body:
A nice simple one

Input

Given a boolean array (Or an acceptable alternative), you can assume the array will never be more than 32 elements long.

```<code>[false, false, true, false, false]
</code>```

Output

Invert every element of the array and output it.

```<code>[true, true, false, true, true]
</code>```

Rules

You can write a full program or just a function

Standard loopholes apply

Shortest code in bytes, per language, wins!

Test cases

```<code>Input:
[true, false]
Output:
[false, true]

Input: //Example of acceptable alternative
[0,1,1]
Output:
[1,0,0]
</code>```

Body:
PHP, 30 bytes

foreach($argv[1] as$i)echo!$i;

Testing code:

$argv[1] = [true,true,false,true,false,false,true,false];
foreach($argv[1] as$i)echo!$i;

Test online


答:
Python 2, <s>138</s> 131 bytes

s="\0%s\0"%input();r=''
for i in range(len(s)-2):L,M,R=map(ord,s[i:i+3]);a=i%2and[R,L][M%2]|M or L|R;r+=chr(a*(a<127)or 32)
print r
```
<p><strong>Try it online</strong> (contains all test cases)</p>
<p>Less golfed:</p>
<pre class="lang-python prettyprint-override"><code>def f(s):
    s="\0%s\0"%s
    r=''
    for i in range(1,len(s)-1):
        if i%2: # even (parity is changed by adding \x00 to the front)
            a=ord(s[i-1]) | ord(s[i+1])
        else:   # odd
            a=ord(s[i])
            if a%2: # odd
                a|=ord(s[i-1])
            else:   # even
                a|=ord(s[i+1])
        r+=chr(a if a<127 else 32)
    print r
</code>```

Try it online (ungolfed)

I add \x00 to both sides of the string so that I don't have to worry about that during bitwise or-ing. I loop along the string's original characters, doing bitwise operations and adding them to the result, following the rules for parity.

Title: ASCII Odd/Even Cipher

Body:
We'll define the ASCII Odd/Even Cipher via the below pseudocode:

```<code>Define 'neighbor' as the characters adjacent to the current letter in the string

If the one of the neighbors is out of bounds of the string, treat it as \0 or null

Take an input string

For each letter in the string, do
  If the 0-based index of the current letter is even, then
    Use the binary-or of the ASCII codes of both its neighbors
  Else
    If the ASCII code of the current letter is odd, then
      Use the binary-or of itself plus the left neighbor
    Else
      Use the binary-or of itself plus the right neighbor
  In all cases,
    Convert the result back to ASCII and return it
  If this would result in a code point 127 or greater to be converted, then
    Instead return a space

Join the results of the For loop back into one string and output it
</code>```

For example, for input Hello, the output is emmol, since

The H turns to \0 | 'e' which is e

The e turns to 'e' | 'l', or 101 | 108, which is 109 or m

The first l also turns to 101 | 108 or m

The second l turns to 108 | 111, which is 111 or o

The o turns to 108 | \0, or l

Input

A sentence composed solely of printable ASCII characters, in any suitable format.

The sentence may have periods, spaces, and other punctuation, but will only ever be one line.

The sentence will be at least three characters in length.

Output

The resulting cipher, based on the rules described above, returned as a string or output.

The Rules

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

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

Examples

Input on one line, output on the following. Blank lines separate examples.

```<code>Hello
emmol

Hello, World!
emmol, ww~ved

PPCG
PSWG

Programming Puzzles and Code Golf
r wogsmmoonpuu ~ meannncoooeggonl

abcdefghijklmnopqrstuvwxyz
bcfefgnijknmno~qrsvuvw~yzz

!abcdefghijklmnopqrstuvwxyz
aaccgeggoikkomoo qsswuww yy

Test 123 with odd characters. R@*SKA0z8d862
euutu133www|todddchizsscguwssr`jS{SK{z~|v66
</code>```

Body:
Python 2, <s>138</s> 131 bytes

s="\0%s\0"%input();r=''
for i in range(len(s)-2):L,M,R=map(ord,s[i:i+3]);a=i%2and[R,L][M%2]|M or L|R;r+=chr(a*(a<127)or 32)
print r

Try it online (contains all test cases)

Less golfed:

def f(s):
    s="\0%s\0"%s
    r=''
    for i in range(1,len(s)-1):
        if i%2: # even (parity is changed by adding \x00 to the front)
            a=ord(s[i-1]) | ord(s[i+1])
        else:   # odd
            a=ord(s[i])
            if a%2: # odd
                a|=ord(s[i-1])
            else:   # even
                a|=ord(s[i+1])
        r+=chr(a if a<127 else 32)
    print r

Try it online (ungolfed)

I add \x00 to both sides of the string so that I don't have to worry about that during bitwise or-ing. I loop along the string's original characters, doing bitwise operations and adding them to the result, following the rules for parity.


答:
Ruby <s>133</s> <s>128</s> <s>108</s> 106 bytes

Jordan helped me save 20 bytes and cia_rana helped me save 2 bytes :)

->s{p s[-i=-1]+s.bytes.each_cons(3).map{|x,y,z|i+=1;a=i%2>0?x|z :y%2>0?y|x :y|z;a>126?' ':a.chr}*""+s[-2]}
```
<p><code>s</code> is taken as the input string.</p>
<p>Example output with <code>s="Test 123 with odd characters. R@*SKA0z8d862"</code>:</p>
<pre class="lang-ruby prettyprint-override"><code>"euutu133www|todddchizsscguwssr`jS{SK{z~|v66"
</code>```

Explanation

The above code is very unreadable so here is an explanation. The code is kind of hacky, I'm quit new to ruby so I bet there is a shorter way to do this :)

b=s[1] # for the first character we always use the right neighbour
       # because `\0 | x` will always return x any way. 0 is the
       # left neighbour and x is the right neigbour
s.bytes.each_cons(3).with_index{|c,i| # oh boy, first we convert the string to ascii with each_byte
                                          # we then traverse the resulting array with three elements at
                                          # a time (so for example if s equals "Hello", c will be equal
                                          # to [72, 101, 108])
  if (i+1) % 2 < 1 # if the middle letter (which is considered our current letter) is even
    a = c[0] | c[2] # we use the result of binary-or of its neighbours
  else
    if c[1] % 2 > 0 # if the code of the current letter is odd
      a = c[1] | c[0] # we use the result of binary-or of itself and its left neighbour
    else
      a = c[1] | c[2] # we use the result of binary-or of itself and its right neighbour
    end
  end
  if a>126
    b<<' ' # if the result we use is greater or equal to 127 we use a space
  else
    b<<a.chr # convert the a ascii value back to a character
  end
}
p b+s[-2] # same as the first comment but now we know that x | \0 will always be x
          # this time x is the last characters left neighbour
```

Title: ASCII Odd/Even Cipher

Body:
Ruby <s>133</s> <s>128</s> <s>108</s> 106 bytes

Jordan helped me save 20 bytes and cia_rana helped me save 2 bytes :)

->s{p s[-i=-1]+s.bytes.each_cons(3).map{|x,y,z|i+=1;a=i%2>0?x|z :y%2>0?y|x :y|z;a>126?' ':a.chr}*""+s[-2]}

s is taken as the input string.

Example output with s="Test 123 with odd characters. R@*SKA0z8d862":

"euutu133www|todddchizsscguwssr`jS{SK{z~|v66"

Explanation

The above code is very unreadable so here is an explanation. The code is kind of hacky, I'm quit new to ruby so I bet there is a shorter way to do this :)

b=s[1] # for the first character we always use the right neighbour
       # because `\0 | x` will always return x any way. 0 is the
       # left neighbour and x is the right neigbour
s.bytes.each_cons(3).with_index{|c,i| # oh boy, first we convert the string to ascii with each_byte
                                          # we then traverse the resulting array with three elements at
                                          # a time (so for example if s equals "Hello", c will be equal
                                          # to [72, 101, 108])
  if (i+1) % 2 < 1 # if the middle letter (which is considered our current letter) is even
    a = c[0] | c[2] # we use the result of binary-or of its neighbours
  else
    if c[1] % 2 > 0 # if the code of the current letter is odd
      a = c[1] | c[0] # we use the result of binary-or of itself and its left neighbour
    else
      a = c[1] | c[2] # we use the result of binary-or of itself and its right neighbour
    end
  end
  if a>126
    b<<' ' # if the result we use is greater or equal to 127 we use a space
  else
    b<<a.chr # convert the a ascii value back to a character
  end
}
p b+s[-2] # same as the first comment but now we know that x | \0 will always be x
          # this time x is the last characters left neighbour


答:
Perl, <s>63</s> 62 bytes

Includes +4 for -lp

Give input on STDIN

oddeven.pl:

```<code>#!/usr/bin/perl -lp
s%.%(--$|?$n|$':$&|(ord$&&1?$n:$'))&($n=$&,~v0)%eg;y;\x7f-\xff; ;
</code>```

This works as shown, but to get the claimed score this must be put in a file without final ; and newline and the \xhh escapes must be replaced by their literal values. You can do this by putting the code above in the file and running:

```<code>perl -0pi -e 's/\\x(..)/chr hex $1/eg;s/;\n$//' oddeven.pl
</code>```

Title: ASCII Odd/Even Cipher

Body:
Perl, <s>63</s> 62 bytes

Includes +4 for -lp

Give input on STDIN

oddeven.pl:

#!/usr/bin/perl -lp
s%.%(--$|?$n|$':$&|(ord$&&1?$n:$'))&($n=$&,~v0)%eg;y;\x7f-\xff; ;

This works as shown, but to get the claimed score this must be put in a file without final ; and newline and the \xhh escapes must be replaced by their literal values. You can do this by putting the code above in the file and running:

perl -0pi -e 's/\\x(..)/chr hex $1/eg;s/;\n$//' oddeven.pl


答:
MATL, <s>11, 10, 8</s>, 5 bytes

```<code>:pYFn
</code>```

Try it online!

I wrote a version that had a really cool explanation of how MATL's matrices work:

:YF!s1=1

But it's no longer relevant. Check out the revision history if you want to see it.

New explanation:

```<code>:p      % Compute factorial(input)
  YF    % Get the exponenents of prime factorization
    n   % Get the length of the array
</code>```

Three bytes saved thanks to Dennis's genius solution

Title: Prime counting function

Body:
Introduction

The Prime Counting Function, also known as the Pi function \$\pi(x)\$, returns the amount of primes less than or equal to x.

Challenge

Your program will take an integer x which you can assume to be positive, and output a single integer equal to the amount of primes less than or equal to x. This is a code-golf challenge, so the winner will be the program with the fewest bytes.

You may use any language of your choosing provided that it existed before this challenge went up, but if the language has a built-in prime-counting function or a primality checking function (such as Mathematica), that function cannot be used in your code.

Example Inputs

Input:

1

Output:

0

Input:

2

Output:

1

Input:

5

Output:

3

A000720 - OEIS

Body:
MATL, <s>11, 10, 8</s>, 5 bytes

:pYFn

Try it online!

I wrote a version that had a really cool explanation of how MATL's matrices work:

:YF!s1=1

But it's no longer relevant. Check out the revision history if you want to see it.

New explanation:

:p      % Compute factorial(input)
  YF    % Get the exponenents of prime factorization
    n   % Get the length of the array

Three bytes saved thanks to Dennis's genius solution


答:
Pyth - <s>7</s> 6 bytes

Since others are using prime factorization functions...

```<code>l{sPMS
</code>```

Test Suite.

Title: Prime counting function

Body:
Pyth - <s>7</s> 6 bytes

Since others are using prime factorization functions...

l{sPMS

Test Suite.


问:
Find the largest number n positions away from n
A sequel to this question.

Task

Given an array of positive integers, find the largest element k for which:

There exists some positive integer distance n, so that the element in the array located n places to the left or right from k equals n.

The array is guaranteed to contain at least one element satisfying this condition.

The shortest code (in bytes) wins. You may choose whichever I/O format you like.

Example

Given the input

```<code>[4, 6, 7, 9, 3, 6, 5, 7, 2]
</code>```

The eligible values are:

The 4, as there is a 7 located 7 positions to its right

The first 6, as there is a 3 located 3 positions to its right

The 3, as there is a 4 located 4 positions to its left

The 5, as there is a 2 located 2 positions to its right

The second 7, as there is a 3 located 3 positions to its left.

Of these values, the largest is 7.

Test cases

```<code>[1, 13] → 13
[2, 9, 8, 3, 72, 2] → 8
[5, 28, 14, 5, 6, 3, 4, 7] → 14
[1, 3, 5, 15, 4, 1, 2, 6, 7, 7] → 7
[5, 1, 3, 5, 2, 5, 5, 8, 5, 1, 5, 1, 2, 3] → 5
[5, 12, 2, 5, 4, 7, 3, 3, 6, 2, 10, 5, 5, 5, 4, 1, 8, 5] → 10
</code>```

答:
Ruby 56 bytes

My smallest ruby solution.

```<code>->n{x=[];i=0;n.map{|v|x<<n[v+i]&&v+i<n.size;i+=1};x.max}
</code>```

Pretty easy to test in rails console

```<code>a = ->n{x=[];i=0;n.map{|v|x<<n[v+i]&&v+i<n.size;i+=1};x.max}
a[[1, 13]
=> 13
a[[2, 9, 8, 3, 72, 2]]
=> 8
a[[5, 12, 2, 5, 4, 7, 3, 3, 6, 2, 10, 5, 5, 5, 4, 1, 8, 5]]
=> 10
</code>```

This started at 63 bytes, thanks for the suggestions to help trim it down!

Body:
Ruby 56 bytes

My smallest ruby solution.

->n{x=[];i=0;n.map{|v|x<<n[v+i]&&v+i<n.size;i+=1};x.max}

Pretty easy to test in rails console

a = ->n{x=[];i=0;n.map{|v|x<<n[v+i]&&v+i<n.size;i+=1};x.max}
a[[1, 13]
=> 13
a[[2, 9, 8, 3, 72, 2]]
=> 8
a[[5, 12, 2, 5, 4, 7, 3, 3, 6, 2, 10, 5, 5, 5, 4, 1, 8, 5]]
=> 10

This started at 63 bytes, thanks for the suggestions to help trim it down!


答:
Bash + coreutils, 30

seq $1|factor|egrep -c :.\\S+$
```
<p>Ideone.</p>
<hr />
<h1>Bash + coreutils + BSD-games package, 22</h1>
<pre class="lang-bash prettyprint-override"><code>primes 1 $[$1+1]|wc -l
</code>```

This shorter answer requires that you have the bsdgames package installed: sudo apt install bsdgames.

Title: Prime counting function

Body:
Bash + coreutils, 30

seq $1|factor|egrep -c :.\\S+$

Ideone.

Bash + coreutils + BSD-games package, 22

primes 1 $[$1+1]|wc -l

This shorter answer requires that you have the bsdgames package installed: sudo apt install bsdgames.


答:
C - 101 bytes

```<code>i,k;f(char*p){for(i=0;*p;++p,++i)putchar((k=i&1?*p&1?*p|p[-1]:*p|p[1]:i?p[-1]|p[1]:p[1])<127?k:' ');}
</code>```

We don't even have to check if it's the last item in the string because strings in C are null-terminated.

Explanation

Rather simple:

Use &1 to test for odd/evenness and ternary expressions to replace if/elses. Increment the char *p to reduce the number of brackets required.

Title: ASCII Odd/Even Cipher

Body:
C - 101 bytes

i,k;f(char*p){for(i=0;*p;++p,++i)putchar((k=i&1?*p&1?*p|p[-1]:*p|p[1]:i?p[-1]|p[1]:p[1])<127?k:' ');}

We don't even have to check if it's the last item in the string because strings in C are null-terminated.

Explanation

Rather simple:

Use &1 to test for odd/evenness and ternary expressions to replace if/elses. Increment the char *p to reduce the number of brackets required.


问:
Identify the compiler
The challenge

You are given a function compile(s: String): Integer which returns 0 if s could be compiled and anything other than 0 if it failed (the resulting code is not important).

The thing is that you don't know for what language the function is made for, so it is up to you to figure that out by giving the function small snippets of code and observing what it returns. The good part is that a team of scientists have tried before you and have narrowed down the list to C, C++, C#, Java and JavaScript (these are the only widespread languages which have similar syntax I could think of).

Rules

General code-golf rules apply.

There is no strict output format; as long as it's readable and understandable it's ok.

If these 5 languages are not enough for you then you can add your own favourites and you'll be rewarded with extra stars (★) (that do nothing).

Note1: the compiler is up to date with the latest standard of whatever language it's designed for.

Note2: I know JavaScript does not compile, but it goes though some parsing process; if it's valid JavaScript code then it passes

答:
Total snippet length 8; test program 83 (C)

Distinguish JavaScript and C from C++, Java, and C#

```<code>a;
</code>```

Distinguish JavaScript from C

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

Distinguish C++ from C# and Java

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

Distinguish C# and Java

```<code>[:a]
</code>```

C code to determine the language

```<code>#define C(x)compile(#x)?
main(){puts(C(a;)C(#)C([:a])"J":"C#":"C+":C(0)"C":"JS");}
</code>```

Snippets tested with

C: gcc 4.7.2 with -std=c99

C++: g++ 4.7.2 with -std=c++11

Java: javac 1.7.0_09

JavaScript: JavaScript-C 1.8.5

C#: Mono C# compiler version 2.10.8.0

Title: Identify the compiler

Body:
Total snippet length 8; test program 83 (C)

Distinguish JavaScript and C from C++, Java, and C#

a;

Distinguish JavaScript from C

0

Distinguish C++ from C# and Java

#

Distinguish C# and Java

[:a]

C code to determine the language

#define C(x)compile(#x)?
main(){puts(C(a;)C(#)C([:a])"J":"C#":"C+":C(0)"C":"JS");}

Snippets tested with

C: gcc 4.7.2 with -std=c99

C++: g++ 4.7.2 with -std=c++11

Java: javac 1.7.0_09

JavaScript: JavaScript-C 1.8.5

C#: Mono C# compiler version 2.10.8.0


答:
Jelly, <s>8</s> 5 bytes

3 bytes saved thanks to @Dennis!

```<code>RÆESL
</code>```

Try it online!

Port of DJMcMayhem's MATL answer (former version) refined by Dennis.

```<code>R          Range of input argument
 ÆE        List of lists of exponents of prime-factor decomposition
   S       Vectorized sum. This right-pads inner lists with zeros
    L      Length of result
</code>```

Title: Prime counting function

Body:
Jelly, <s>8</s> 5 bytes

3 bytes saved thanks to @Dennis!

RÆESL

Try it online!

Port of DJMcMayhem's MATL answer (former version) refined by Dennis.

R          Range of input argument
 ÆE        List of lists of exponents of prime-factor decomposition
   S       Vectorized sum. This right-pads inner lists with zeros
    L      Length of result


答:
PowerShell v2+, 98 bytes

```<code>param($n)if($j='001'[$n]){}else{for($i=1;$i-lt$n){for(;'1'*++$i-match'^(?!(..+)\1+$)..'){$j++}}}$j
</code>```

Caution: This is slow for large input.

Basically the unary-based lookup from Is this number a prime?, coupled with a for loop and a $j++ counter. A little additional logic on the front to account for edge cases input 1 and 2, due to how the fenceposting works in the for loops.

Title: Prime counting function

Body:
PowerShell v2+, 98 bytes

param($n)if($j='001'[$n]){}else{for($i=1;$i-lt$n){for(;'1'*++$i-match'^(?!(..+)\1+$)..'){$j++}}}$j

Caution: This is slow for large input.

Basically the unary-based lookup from Is this number a prime?, coupled with a for loop and a $j++ counter. A little additional logic on the front to account for edge cases input 1 and 2, due to how the fenceposting works in the for loops.


答:
05AB1E, 5 bytes

Assumes that prime factorization builtins are allowed.

Code:

```<code>LÒ1ùg
</code>```

Explanation:

```<code>L      # Get the range [1, ..., input]
 Ò     # Prime factorize each with duplicates
  1ù   # Keep the elements with length 1
    g  # Get the length of the resulting array
</code>```

Uses the CP-1252 encoding. Try it online!

Title: Prime counting function

Body:
05AB1E, 5 bytes

Assumes that prime factorization builtins are allowed.

Code:

LÒ1ùg

Explanation:

L      # Get the range [1, ..., input]
 Ò     # Prime factorize each with duplicates
  1ù   # Keep the elements with length 1
    g  # Get the length of the resulting array

Uses the CP-1252 encoding. Try it online!


答:
Retina 0.8.2, <s>31</s> 22 bytes

Byte count assumes ISO 8859-1 encoding.

```<code>.+
$*
(?!(..+)\1+$).\B
</code>```

Try it online - Input much larger than 2800 either times out or runs out of memory.

References:

Martin's range generator

Martin's prime checker

Title: Prime counting function

Body:
Retina 0.8.2, <s>31</s> 22 bytes

Byte count assumes ISO 8859-1 encoding.

.+
$*
(?!(..+)\1+$).\B

Try it online - Input much larger than 2800 either times out or runs out of memory.

References:

Martin's range generator

Martin's prime checker


答:
05AB1E, 3 bytes

```<code>!fg
</code>```

This assumes that factorization built-ins are allowed. Try it online!

How it works

```<code>!    Compute the factorial of the input.
 f   Determine its unique prime factors.
  g  Get the length of the resulting list.
</code>```

Title: Prime counting function

Body:
05AB1E, 3 bytes

!fg

This assumes that factorization built-ins are allowed. Try it online!

How it works

!    Compute the factorial of the input.
 f   Determine its unique prime factors.
  g  Get the length of the resulting list.


答:
Python 2, 73 bytes

def f(n):x=map(int,str(n));d=len(x)/2;print sum(x[:d])==sum(x[-d:])or d<1
```

Tests are at ideone

We have to use str() rather than `` since n may be outside the range of signed int.

Title: Is it a balanced number?

Body:
A number is balanced if the sum of the digits on each half of the number is equal, so: 1423 is balanced because 1+4 = 2+3, so is: 42615 because 4+2=1+5. Note that the middle digit is not included on either side (or it's included on both sides) if there's an odd number of digits.

Challenge:

Take a positive integer as input, and output a truthy value if it's balanced and a falsy value if it's unbalanced.

Test cases (true)

```<code>1
6
11
141
1221
23281453796004414
523428121656666655655556655656502809745249552466339089702361716477983610754966885128041975406005088
</code>```

Test cases (false)

```<code>10
12
110
15421
5234095123508321
6240911314399072459493765661191058613491863144152352262897351988250431140546660035648795316740212454
</code>```

There will not be numbers starting with zero, for instance 00032 instead of 32. You must support numbers up to at least 100 digits (so larger than 2^64-1). As always, optional input format, so you may surround the number with apostrophes if desired.

Body:
Python 2, 73 bytes

def f(n):x=map(int,str(n));d=len(x)/2;print sum(x[:d])==sum(x[-d:])or d<1

Tests are at ideone

We have to use str() rather than `` since n may be outside the range of signed int.


Title: Prime counting function

Body:
C#, 157 bytes

n=>{int c=0,i=1,j;bool f;for(;i<=n;i++){if(i==1);else if(i<=3)c++;else if(i%2==0|i%3==0);else{j=5;f=1>0;while(j*j<=i)if(i%j++==0)f=1<0;c+=f?1:0;}}return c;};

Full program with test cases:

using System;

class a
{
    static void Main()
    {
        Func<int, int> s = n =>
            {
                int c = 0, i = 1, j;
                bool f;
                for (; i <= n; i++)
                {
                    if (i == 1) ;
                    else if (i <= 3) c++;
                    else if (i % 2 == 0 | i % 3 == 0) ;
                    else
                    {
                        j = 5;
                        f = 1 > 0;
                        while (j * j <= i)
                            if (i % j++ == 0)
                                f = 1 < 0;
                        c += f ? 1 : 0;
                    }
                }
                return c;
            };

        Console.WriteLine("1 -> 0 : " + (s(1) == 0 ? "OK" : "FAIL"));
        Console.WriteLine("2 -> 1 : " + (s(2) == 1 ? "OK" : "FAIL"));
        Console.WriteLine("5 -> 3 : " + (s(5) == 3 ? "OK" : "FAIL"));
        Console.WriteLine("10 -> 4 : " + (s(10) == 4 ? "OK" : "FAIL"));
        Console.WriteLine("100 -> 25 : " + (s(100) == 25 ? "OK" : "FAIL"));
        Console.WriteLine("1,000 -> 168 : " + (s(1000) == 168 ? "OK" : "FAIL"));
        Console.WriteLine("10,000 -> 1,229 : " + (s(10000) == 1229 ? "OK" : "FAIL"));
        Console.WriteLine("100,000 -> 9,592 : " + (s(100000) == 9592 ? "OK" : "FAIL"));
        Console.WriteLine("1,000,000 -> 78,498 : " + (s(1000000) == 78498 ? "OK" : "FAIL"));
    }
}

Starts to take awhile once you go above 1 million.


答:
Scala, 77 bytes

Like Java, must take Strings.

I'm sure someone could find an improvement.

def f(s:String)=(for(i<-0 until s.length/2)yield s(i)-s(s.length-i-1)).sum==0

Can test online

Title: Is it a balanced number?


答:
JavaScript (ES6), <s>50+2</s> <s>46+2</s> 43 bytes

Saved <s>3</s> 5 bytes thanks to Neil:

f=n=>n&&eval(`for(z=n;n%--z;);1==z`)+f(n-1)
```
<p><code>eval</code> can access the <code>n</code> parameter.<br />
The <code>eval(...)</code> checks if <code>n</code> is prime.</p>
<hr>
<p><strong>Previous solutions:</strong><br />
Byte count should be +2 because I forgot to name the function <code>f=</code> (needed for recursion)</p>
<p>46+2 bytes (Saved 3 bytes thanks to ETHproductions):</p>
<pre class="lang-js prettyprint-override"><code>n=>n&&eval(`for(z=n=${n};n%--z;);1==z`)+f(n-1)
</code>```

50+2 bytes:

n=>n&&eval(`for(z=${n};${n}%--z&&z;);1==z`)+f(n-1)
```

Title: Prime counting function

Body:
JavaScript (ES6), <s>50+2</s> <s>46+2</s> 43 bytes

Saved <s>3</s> 5 bytes thanks to Neil:

f=n=>n&&eval(`for(z=n;n%--z;);1==z`)+f(n-1)

eval can access the n parameter.

The eval(...) checks if n is prime.

Previous solutions:

Byte count should be +2 because I forgot to name the function f= (needed for recursion)

46+2 bytes (Saved 3 bytes thanks to ETHproductions):

n=>n&&eval(`for(z=n=${n};n%--z;);1==z`)+f(n-1)

50+2 bytes:

n=>n&&eval(`for(z=${n};${n}%--z&&z;);1==z`)+f(n-1)


答:
Perl, 33 bytes

Includes +1 for -p

Give the input number on STDIN

primecount.pl

```<code>#!/usr/bin/perl -p
$_=1x$_;$_=s%(?!(11+)\1+$)%%eg-2
</code>```

Gives the wrong result for 0 but that's OK, the op asked for support for positive integers only.

Title: Prime counting function

Body:
Perl, 33 bytes

Includes +1 for -p

Give the input number on STDIN

primecount.pl

#!/usr/bin/perl -p
$_=1x$_;$_=s%(?!(11+)\1+$)%%eg-2

Gives the wrong result for 0 but that's OK, the op asked for support for positive integers only.


答:
Jelly, 3 bytes

```<code>ÆRL
</code>```

Jelly has a built-in prime counting function, ÆC and a prime checking function, ÆP, this instead uses a built-in prime generating function, ÆR and takes the length L.

I guess this is about as borderline as using prime factorisation built-ins, which would also take 3 bytes with !Æv (! factorial, Æv count prime factors)

Title: Prime counting function

Body:
Introduction

The Prime Counting Function, also known as the Pi function \$\pi(x)\$, returns the amount of primes less than or equal to x.

Challenge

Your program will take an integer x which you can assume to be positive, and output a single integer equal to the amount of primes less than or equal to x. This is a code-golf challenge, so the winner will be the program with the fewest bytes.

You may use any language of your choosing provided that it existed before this challenge went up, but if the language has a built-in prime-counting function or a primality checking function (such as Mathematica), that function cannot be used in your code.

Example Inputs

Input:

1

Output:

0

Input:

2

Output:

1

Input:

5

Output:

3

A000720 - OEIS

Body:
Jelly, 3 bytes

ÆRL

Jelly has a built-in prime counting function, ÆC and a prime checking function, ÆP, this instead uses a built-in prime generating function, ÆR and takes the length L.

I guess this is about as borderline as using prime factorisation built-ins, which would also take 3 bytes with !Æv (! factorial, Æv count prime factors)


答:
Matlab, 60 bytes

Continuing my attachment to one-line Matlab functions. Without using a factorisation built-in:

```<code>f=@(x) nnz(arrayfun(@(x) x-2==nnz(mod(x,[1:1:x])),[1:1:x]));
</code>```

Given that a prime y has only two factors in [1,y]: we count the numbers in the range [1,x] which have only two factors.

Using factorisation allows for significant shortening (down to 46 bytes).

```<code>g=@(x) size(unique(factor(factorial(x))),2);
</code>```

Conclusion: Need to look into them golfing languages :D

Title: Prime counting function

Body:
Matlab, 60 bytes

Continuing my attachment to one-line Matlab functions. Without using a factorisation built-in:

f=@(x) nnz(arrayfun(@(x) x-2==nnz(mod(x,[1:1:x])),[1:1:x]));

Given that a prime y has only two factors in [1,y]: we count the numbers in the range [1,x] which have only two factors.

Using factorisation allows for significant shortening (down to 46 bytes).

g=@(x) size(unique(factor(factorial(x))),2);

Conclusion: Need to look into them golfing languages :D


答:
Jelly, <s>13 11 10 9 8 7</s> 6 bytes

Using no built-in prime functions whatsoever

-1 byte thanks to @miles (use a table)

-1 byte thanks to @Dennis (convert from unary to count up the divisors)

```<code>ḍþḅ1ċ2
</code>```

TryItOnline

Or see the first 100 terms of the series n=[1,100], also at TryItOnline

How?

```<code>ḍþḅ1ċ2 - Main link: n
 þ     - table or outer product, n implicitly becomes [1,2,3,...n]
ḍ      - divides
  ḅ1   - Convert from unary: number of numbers in [1,2,3,...,n] that divide x
                             (numbers greater than x do not divide x)
    ċ2 - count 2s: count the numbers in [1,2,3,...,n] with exactly 2 divisors
                   (only primes have 2 divisors: 1 and themselves)
</code>```

Title: Prime counting function

Body:
Jelly, <s>13 11 10 9 8 7</s> 6 bytes

Using no built-in prime functions whatsoever

-1 byte thanks to @miles (use a table)

-1 byte thanks to @Dennis (convert from unary to count up the divisors)

ḍþḅ1ċ2

TryItOnline

Or see the first 100 terms of the series n=[1,100], also at TryItOnline

How?

ḍþḅ1ċ2 - Main link: n
 þ     - table or outer product, n implicitly becomes [1,2,3,...n]
ḍ      - divides
  ḅ1   - Convert from unary: number of numbers in [1,2,3,...,n] that divide x
                             (numbers greater than x do not divide x)
    ċ2 - count 2s: count the numbers in [1,2,3,...,n] with exactly 2 divisors
                   (only primes have 2 divisors: 1 and themselves)


答:
MATL, 9 bytes

This avoids prime-factor decomposition. Its complexity is O(n²).

```<code>:t!\~s2=s
</code>```

Try it online!

```<code>:     % Range [1 2 ... n] (row vector)
t!    % Duplicate and transpose into a column vector
\     % Modulo with broadcast. Gives matrix in which entry (i,j) is i modulo j, with
      % i, j in [1 2 ... n]. A value 0 in entry (i,j) means i is divisible by j
~     % Negate. Now 1 means i is divisible by j
s     % Sum of each column. Gives row vector with the number of divisors of each j
2=    % Compare each entry with 2. A true result corresponds to a prime
s     % Sum
</code>```

Title: Prime counting function

Body:
MATL, 9 bytes

This avoids prime-factor decomposition. Its complexity is O(n²).

:t!\~s2=s

Try it online!

:     % Range [1 2 ... n] (row vector)
t!    % Duplicate and transpose into a column vector
\     % Modulo with broadcast. Gives matrix in which entry (i,j) is i modulo j, with
      % i, j in [1 2 ... n]. A value 0 in entry (i,j) means i is divisible by j
~     % Negate. Now 1 means i is divisible by j
s     % Sum of each column. Gives row vector with the number of divisors of each j
2=    % Compare each entry with 2. A true result corresponds to a prime
s     % Sum


答:
Java, 118 bytes

```<code>int f(int[]a){int t=0,i,j,z=0,l=a.length;while(t<l*l){i=t/l;j=t++%l;z=a[i]>z&&((i<j?j-i:i-j)==a[j])?a[i]:z;}return z;}
</code>```

Title: Find the largest number n positions away from n

Body:
A sequel to this question.

Task

Given an array of positive integers, find the largest element k for which:

There exists some positive integer distance n, so that the element in the array located n places to the left or right from k equals n.

The array is guaranteed to contain at least one element satisfying this condition.

The shortest code (in bytes) wins. You may choose whichever I/O format you like.

Example

Given the input

```<code>[4, 6, 7, 9, 3, 6, 5, 7, 2]
</code>```

The eligible values are:

The 4, as there is a 7 located 7 positions to its right

The first 6, as there is a 3 located 3 positions to its right

The 3, as there is a 4 located 4 positions to its left

The 5, as there is a 2 located 2 positions to its right

The second 7, as there is a 3 located 3 positions to its left.

Of these values, the largest is 7.

Test cases

```<code>[1, 13] → 13
[2, 9, 8, 3, 72, 2] → 8
[5, 28, 14, 5, 6, 3, 4, 7] → 14
[1, 3, 5, 15, 4, 1, 2, 6, 7, 7] → 7
[5, 1, 3, 5, 2, 5, 5, 8, 5, 1, 5, 1, 2, 3] → 5
[5, 12, 2, 5, 4, 7, 3, 3, 6, 2, 10, 5, 5, 5, 4, 1, 8, 5] → 10
</code>```

Body:
Java, 118 bytes

int f(int[]a){int t=0,i,j,z=0,l=a.length;while(t<l*l){i=t/l;j=t++%l;z=a[i]>z&&((i<j?j-i:i-j)==a[j])?a[i]:z;}return z;}


答:
JavaScript (ES6), <s>45</s> 43 bytes

```<code>f=(n,x=n)=>n>1&&(--x<2)+(n%x?f(n,x):f(n-1))
</code>```

A modification of my <s>36</s> <s>35</s> 33-byte primality function (1 byte saved by @Neil, 2 by @Arnauld):

```<code>f=(n,x=n)=>n>1&--x<2||n%x&&f(n,x)
</code>```

(I can't post this anywhere because Is this number a prime? only accepts full programs...)

Test snippet

f=(n,x=n)=>n>1&&(--x<2)+(n%x?f(n,x):f(n-1))```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input type="number" oninput="console.log('f('+this.value+') is '+f(this.value))" value=2></code>```

Title: Prime counting function

Body:
JavaScript (ES6), <s>45</s> 43 bytes

f=(n,x=n)=>n>1&&(--x<2)+(n%x?f(n,x):f(n-1))

A modification of my <s>36</s> <s>35</s> 33-byte primality function (1 byte saved by @Neil, 2 by @Arnauld):

f=(n,x=n)=>n>1&--x<2||n%x&&f(n,x)

(I can't post this anywhere because Is this number a prime? only accepts full programs...)

Test snippet

f=(n,x=n)=>n>1&&(--x<2)+(n%x?f(n,x):f(n-1))

<input type="number" oninput="console.log('f('+this.value+') is '+f(this.value))" value=2>


问:
String Distance

Challenge

Given an input of an all-lowercase string [a-z], output the total distance between the letters.

Example

```<code>Input: golf

Distance from g to o : 8
Distance from o to l : 3
Distance from l to f : 6

Output: 17
</code>```

Rules

Standard loopholes forbidden

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

The alphabet can be traversed from either direction. You must always use the shortest path. (i.e the distance between x and c is 5).

Test cases

```<code>Input: aa
Output: 0

Input: stack
Output: 18

Input: zaza
Output: 3

Input: valleys
Output: 35
</code>```

答:
Scala, 68 bytes

```<code>def f(s:String)=(for(i<-0 to s.length-2)yield (s(i)-s(i+1)).abs).sum
</code>```

Criticism is welcome.

Title: String Distance

Body:
Scala, 68 bytes

def f(s:String)=(for(i<-0 to s.length-2)yield (s(i)-s(i+1)).abs).sum

Criticism is welcome.


Title: String Distance

Body:
Challenge

Given an input of an all-lowercase string [a-z], output the total distance between the letters.

Example

```<code>Input: golf

Distance from g to o : 8
Distance from o to l : 3
Distance from l to f : 6

Output: 17
</code>```

Rules

Standard loopholes forbidden

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

The alphabet can be traversed from either direction. You must always use the shortest path. (i.e the distance between x and c is 5).

Test cases

```<code>Input: aa
Output: 0

Input: stack
Output: 18

Input: zaza
Output: 3

Input: valleys
Output: 35
</code>```

Body:
C, 70 bytes <s>76 bytes</s>

k,i;f(char *s){for(i=0;*++s;i+=(k=abs(*s-s[-1]))>13?26-k:k);return i;}


答:
PHP, <s>96</s> 92 bytes

```<code>for($j=$argv[1]-1;$j>0;$j--){$p=1;for($i=2;$i<$j;$i++)if(is_int($j/$i))$p=0;$t+=$p;}echo $t;
</code>```

Saved 4 bytes thanks to Roman Gräf

Test online

Ungolfed testing code:

```<code>$argv[1] = 5;

for($j=$argv[1]-1;$j>0;$j--) {
    $p=1;
    for($i=2;$i<$j;$i++) {
        if(is_int($j/$i)) {
            $p=0;
        }
    }
    $t+=$p;
}
echo $t;
</code>```

Test online

Title: Prime counting function

Body:
PHP, <s>96</s> 92 bytes

for($j=$argv[1]-1;$j>0;$j--){$p=1;for($i=2;$i<$j;$i++)if(is_int($j/$i))$p=0;$t+=$p;}echo $t;

Saved 4 bytes thanks to Roman Gräf

Test online

Ungolfed testing code:

$argv[1] = 5;

for($j=$argv[1]-1;$j>0;$j--) {
    $p=1;
    for($i=2;$i<$j;$i++) {
        if(is_int($j/$i)) {
            $p=0;
        }
    }
    $t+=$p;
}
echo $t;

Test online


答:
Python 2, 45 bytes

f=lambda n,k=1,p=1:n/k and p%k+f(n,k+1,p*k*k)
```

Uses the Wilson's Theorem prime generator. The product p tracks (k-1)!^2, and p%k is 1 for primes and 0 for nonprimes.

Title: Prime counting function

Body:
Python 2, 45 bytes

f=lambda n,k=1,p=1:n/k and p%k+f(n,k+1,p*k*k)

Uses the Wilson's Theorem prime generator. The product p tracks (k-1)!^2, and p%k is 1 for primes and 0 for nonprimes.


问:
Create a pyramidal matrix
A pyramidal matrix is a square matrix where all numbers increase or decrease from the center point, like the two matrices below:

```<code>1  1  1  1  1
1  2  2  2  1
1  2  3  2  1
1  2  2  2  1
1  1  1  1  1
</code>```

Or:

```<code>3  3  3  3  3
3  2  2  2  3
3  2  1  2  3
3  2  2  2  3
3  3  3  3  3
</code>```

Given a non-zero integer n, create a pyramidal matrix where the numbers goes from 1 to n either in increasing order (if n<0), or decreasing order (if n>0) from the center. If n is even, then there will be 4 center numbers (see the examples).

As always:

Optional input and output format

Number of spaces, delimiter etc. is optional

Test cases:

```<code>1
1

-1
1

5
1  1  1  1  1  1  1  1  1
1  2  2  2  2  2  2  2  1
1  2  3  3  3  3  3  2  1
1  2  3  4  4  4  3  2  1
1  2  3  4  5  4  3  2  1
1  2  3  4  4  4  3  2  1
1  2  3  3  3  3  3  2  1
1  2  2  2  2  2  2  2  1
1  1  1  1  1  1  1  1  1

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

```<code>2
1  1  1  1
1  2  2  1
1  2  2  1
1  1  1  1

-2
2  2  2  2
2  1  1  2
2  1  1  2
2  2  2  2

-4
4  4  4  4  4  4  4  4
4  3  3  3  3  3  3  4
4  3  2  2  2  2  3  4
4  3  2  1  1  2  3  4
4  3  2  1  1  2  3  4
4  3  2  2  2  2  3  4
4  3  3  3  3  3  3  4
4  4  4  4  4  4  4  4
</code>```

答:
Mathematica, 78 bytes

```<code>Abs[Fold[ArrayPad[#,1,#2]&,Table[0,#,#]&@Mod[#,2,1],Range[Abs@#-1]]+1~Min~-#]&
</code>```

Explanation

```<code>Table[0,#,#]&@Mod[#,2,1]
</code>```

Make initial matrix: 1x1 if odd, 2x2 if even.

```<code>Range[Abs@#-1]
</code>```

Generate a list from 1 to abs(input) - 1.

```<code>Fold[ArrayPad[#,1,#2]&, ..., ...]
</code>```

Pad the initial array using the aforementioned list.

```<code>... +1~Min~-#
</code>```

Add 1 or -input, whichever is smaller.

```<code>Abs
</code>```

Apply absolute value to the entire matrix.

Title: Create a pyramidal matrix

Body:
Mathematica, 78 bytes

Abs[Fold[ArrayPad[#,1,#2]&,Table[0,#,#]&@Mod[#,2,1],Range[Abs@#-1]]+1~Min~-#]&

Explanation

Table[0,#,#]&@Mod[#,2,1]

Make initial matrix: 1x1 if odd, 2x2 if even.

Range[Abs@#-1]

Generate a list from 1 to abs(input) - 1.

Fold[ArrayPad[#,1,#2]&, ..., ...]

Pad the initial array using the aforementioned list.

... +1~Min~-#

Add 1 or -input, whichever is smaller.

Abs

Apply absolute value to the entire matrix.


答:
C (gcc), <s>46</s> 27 bytes

f(i){i="BAGAADKAJH"[i]-66;}
```

Try it online!

Title: Return the flipped version of a number

Body:
When a number is shown on a calculator, it's possible to consider what various transformations of that number would look like. For example, on a seven-segment display, 2 is shown like this:

And when flipped horizontally it looks like this:

As such, the mirror image of 2 is 5.

The task in this challenge is to take a single-digit number, and return the number that's its mirror image (if possible). If its mirror image does not look like a number, return the number rotated 180 degrees (if possible). If neither of these are the case, return -1.

Here's the full list of inputs and outputs your program needs to handle:

```<code>Input   Output
0       0
1       -1
2       5
3       -1
4       -1
5       2
6       9
7       -1
8       8
9       6
</code>```

As a code-golf challenge, the shortest code wins!

Body:
C (gcc), <s>46</s> 27 bytes

f(i){i="BAGAADKAJH"[i]-66;}

Try it online!


答:
Turtlèd, 40 bytes (noncompeting)

```<code>!.(3'1)(4'1)(1l'-)(2'5l)(5'2)(6'9l)(9'6)
</code>```

Try it online!

Explanation

```<code>!                                          take input
 .                                         write first char of input to cell
  (3'1)                                    if cell is 3, write 1
       (4'1)                               if cell is 4, write 1
            (1l'-)                         If cell is 1, move left and write -
                  (2'5l)                   If cell is 2, write 5 and move left
                        (5'2)              If cell is 5, write 2
                             (6'9l)        If cell is 6, write 9 and move left
                                   (9'6)   If cell is 9, write 6
</code>```

Title: Return the flipped version of a number

Body:
Turtlèd, 40 bytes (noncompeting)

!.(3'1)(4'1)(1l'-)(2'5l)(5'2)(6'9l)(9'6)

Try it online!

Explanation

!                                          take input
 .                                         write first char of input to cell
  (3'1)                                    if cell is 3, write 1
       (4'1)                               if cell is 4, write 1
            (1l'-)                         If cell is 1, move left and write -
                  (2'5l)                   If cell is 2, write 5 and move left
                        (5'2)              If cell is 5, write 2
                             (6'9l)        If cell is 6, write 9 and move left
                                   (9'6)   If cell is 9, write 6


问:
Checkmate (aka the urinal problem)
My Precalc teacher has one of his favorite problems that he made up (or more likely <s>stole</s> inspired by xkcd) that involves a row of n urinals. "Checkmate" is a situation in which every urinal is already occupied OR has an occupied urinal next to them. For instance, if a person is an X, then

X-X--X

is considered checkmate. Note that a person cannot occupy a urinal next to an already occupied urinal.

Task

Your program will take a number through stdin, command line args, or a function argument. Your program will then print out or return the number of ways that checkmate can occur in with the inputted number of urinals.

Examples

0 -> 1 (the null case counts as checkmate)

1 -> 1 (X)

2 -> 2 (X- or -X)

3 -> 2 (X-X or -X-)

4 -> 3 (X-X-, -X-X, or X--X)

5 -> 4 (X-X-X, X--X-, -X-X-, or -X--X)

6 -> 5 (X-X-X-, X--X-X, X-X--X, -X--X- or -X-X-X)

7 -> 7 (X-X-X-X, X--X-X-, -X-X--X, -X--X-X, X-X--X-, X--X--X or -X-X-X-)

8 -> 9 (-X--X--X, -X--X-X-, -X-X--X-, -X-X-X-X, X--X--X-, X--X-X-X, X-X--X-X, X-X-X--X, X-X-X-X-)

...

Scoring

The smallest program in bytes wins.

答:
Actually, 18 bytes

This is an Actually port of Dennis' longer Jelly answer. Golfing suggestions welcome. Try it online!

```<code>3+;╖½Lur⌠;τ╜-@█⌡MΣ
</code>```

Ungolfing

```<code>         Implicit input n.
3+       Add 3. For readibility, m = n+3.
;╖       Duplicate and store one copy of m in register 0.
½Lu      floor(m/2) + 1.
r        Range from 0 to (floor(m/2)+1), inclusive.
⌠...⌡M   Map the following function over the range. Variable k.
  ;        Duplicate k.
  τ╜-      Push m-2k. Stack: [m-2k, k]
  @█       Swap k and m-2k and take binomial (k, m-2k).
            If m-2k > k, █ returns 0, which does not affect the sum() that follows.
         End function.
Σ        Sum the list that results from the map.
         Implicit return.
</code>```

Title: Checkmate (aka the urinal problem)

Body:
Actually, 18 bytes

This is an Actually port of Dennis' longer Jelly answer. Golfing suggestions welcome. Try it online!

3+;╖½Lur⌠;τ╜-@█⌡MΣ

Ungolfing

         Implicit input n.
3+       Add 3. For readibility, m = n+3.
;╖       Duplicate and store one copy of m in register 0.
½Lu      floor(m/2) + 1.
r        Range from 0 to (floor(m/2)+1), inclusive.
⌠...⌡M   Map the following function over the range. Variable k.
  ;        Duplicate k.
  τ╜-      Push m-2k. Stack: [m-2k, k]
  @█       Swap k and m-2k and take binomial (k, m-2k).
            If m-2k > k, █ returns 0, which does not affect the sum() that follows.
         End function.
Σ        Sum the list that results from the map.
         Implicit return.


问:
Print the alphabet without using each vowel
Inspiration: in 1939, a man named Ernest Vincent Wright wrote a novel called Gadsby without using the letter 'e'.

Your task is to write a set of (up to 5) programs in any language (which has a text-based syntax*) to output all 26 letters of the alphabet in order.  However for each vowel aeiou, at least one of the programs must not include any occurrence of the vowel.

So there must be

a program that does not use 'a' or 'A' anywhere in the syntax of the program.

a program that does not use 'e' or 'E' anywhere in the syntax of the program.

a program that does not use 'i'  or 'I' anywhere in the syntax of the program.

a program that does not use 'o' or 'O' anywhere in the syntax of the program.

a program that does not use 'u' or 'U' anywhere in the syntax of the program.

All of them must output abcdefghijklmnopqrstuvwxyz.

The winner shall be the solution where the length of all programs is the shortest.

* since the constraint wouldn't be much of a challenge in Piet or Whitespace

答:
 Befunge, 26

```<code>>"`">1+:"z"`v
:,  ^      @_
</code>```

Minimizing whitespace is part of the challenge of Befunge, so I included it in the character count. It might be possible to take out some of that whitespace, but the instructions themselves seem minimal.

Body:
 Befunge, 26

>"`">1+:"z"`v
:,  ^      @_

Minimizing whitespace is part of the challenge of Befunge, so I included it in the character count. It might be possible to take out some of that whitespace, but the instructions themselves seem minimal.


答:
Python, 29 bytes

lambda s:s[s.sort():1]+s[-1:]
```

Test it on Ideone.

Body:
Challenge

Given an array of integers, received from stdin, function arguments, program arguments, or some other method:

Output only the minimum and maximum numbers in the array, through a return value, stdout, or other fitting methods.

Example session

```<code>> minmax( {0, 15, 2, 3, 7, 18, -2, 9, 6, -5, 3, 8, 9, -14} )
-14 18
</code>```

Reference implementation

```<code>// C++14

void minmax(std::vector<int> v) {
    int min = v[0]; int max = v[0];
    for(auto it : v) {
        if (*it < min)
            min = *it;
        if (*it > max)
            max = *it;
    }
    std::cout << min << ' ' << max << std::endl;
}
</code>```

Rules

You may not use a built-in function to calculate the values.

Standard loopholes disallowed.

Creative implementations encouraged.

This is code-golf, shortest answer wins but will not be selected.

Clarifications

If the array contains 1 element you need to output it twice.

If the minimum and maximum values are the same, you need to output them both.

Body:
Python, 29 bytes

lambda s:s[s.sort():1]+s[-1:]

Test it on Ideone.