答:
Perl, 31 + 2 (-lp) = 33 bytes

This solution is from @Ton Hospel (13 bytes shorter thant mine).

```<code>s%.%(lc$&gt$&?u:l)."c chop"%eeg
</code>```

But you'll need l and p switches on. To run it :

```<code>perl -lpe 's%.%(lc$&gt$&?u:l)."c chop"%eeg'
</code>```

Body:
Perl, 31 + 2 (-lp) = 33 bytes

This solution is from @Ton Hospel (13 bytes shorter thant mine).

s%.%(lc$&gt$&?u:l)."c chop"%eeg

But you'll need l and p switches on. To run it :

perl -lpe 's%.%(lc$&gt$&?u:l)."c chop"%eeg'


问:
Reverse a string while maintaining the capitalization in the same places
The goal here is to simply reverse a string, with one twist:

Keep the capitalization in the same places.

Example Input 1: Hello, Midnightas

Example Output 1: SathginDim ,olleh

Example Input 2: .Q

Exmaple Output 2: q.

Rules:

Output to STDOUT, input from STDIN

The winner will be picked 13th of July on GMT+3 12:00 (One week)

The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.

Any punctuation ending up in a position where there was an upper-case letter must be ignored.

答:
Python 2, 73 bytes

Since the rules specify the input is ascii:

lambda s:''.join([z.lower,z.upper]['@'<c<'[']()for c,z in zip(s,s[::-1]))
```

All the credit goes to @Mego though, but I had not the reputation to just comment on his answer.

ContentLicense: CC BY-SA 3.0

Body:
Python 2, 73 bytes

Since the rules specify the input is ascii:

lambda s:''.join([z.lower,z.upper]['@'<c<'[']()for c,z in zip(s,s[::-1]))

All the credit goes to @Mego though, but I had not the reputation to just comment on his answer.


答:
MATL, 13 bytes

```<code>PktGtk<)Xk5M(
</code>```

Try it online!

```<code>Pk      % Implicit inpput. Flip, lowercase
t       % Duplicate
Gtk<    % Logical index of uppercase letters in the input string
)       % Get letters at those positions in the flipped string
Xk      % Make them uppercase
5M(     % Assign them to the indicated positions. Implicit display
</code>```

Title: Reverse a string while maintaining the capitalization in the same places

Body:
The goal here is to simply reverse a string, with one twist:

Keep the capitalization in the same places.

Example Input 1: Hello, Midnightas

Example Output 1: SathginDim ,olleh

Example Input 2: .Q

Exmaple Output 2: q.

Rules:

Output to STDOUT, input from STDIN

The winner will be picked 13th of July on GMT+3 12:00 (One week)

The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.

Any punctuation ending up in a position where there was an upper-case letter must be ignored.

Body:
MATL, 13 bytes

PktGtk<)Xk5M(

Try it online!

Pk      % Implicit inpput. Flip, lowercase
t       % Duplicate
Gtk<    % Logical index of uppercase letters in the input string
)       % Get letters at those positions in the flipped string
Xk      % Make them uppercase
5M(     % Assign them to the indicated positions. Implicit display


答:
CJam, 22 bytes

```<code>q_W%.{el\'[,65>&{eu}&}
</code>```

Test it here.

Body:
CJam, 22 bytes

q_W%.{el\'[,65>&{eu}&}

Test it here.


问:
Leave a Comment
Task:

Make a program that leaves a comment on this question. The content should be 1234567890123456.

Edits:

You may leave your usernames and passwords as U and P if you are
using username and password. (if applicable)

No URL Shorteners (if applicable)

You may not use the browser console.

答:
Swift 2.2 on iOS, 380 bytes

```<code>let r = NSMutableURLRequest(URL:NSURL(string:"http://codegolf.stackexchange.com/posts/84546/comments")!)
r.HTTPMethod = "POST"
r.HTTPBody = try!NSJSONSerialization.dataWithJSONObject(["comment":"1234567890123456","fkey":UIWebView().stringByEvaluatingJavaScriptFromString("localstorage.getItem('se:fkey')")!],options:[])
NSURLSession.sharedSession().dataTaskWithRequest(r).resume()
</code>```

Assumes the user is logged in to Code Golf with Safari and has cookies enabled.  Also assumes UIKit is implicitly imported and available.  JSON serialization is so verbose in Cocoa...  Might update this with a Swift 3 solution and optionally macOS/Linux testable answers.

ContentLicense: CC BY-SA 4.0

Title: Leave a Comment

Body:
Swift 2.2 on iOS, 380 bytes

let r = NSMutableURLRequest(URL:NSURL(string:"http://codegolf.stackexchange.com/posts/84546/comments")!)
r.HTTPMethod = "POST"
r.HTTPBody = try!NSJSONSerialization.dataWithJSONObject(["comment":"1234567890123456","fkey":UIWebView().stringByEvaluatingJavaScriptFromString("localstorage.getItem('se:fkey')")!],options:[])
NSURLSession.sharedSession().dataTaskWithRequest(r).resume()

Assumes the user is logged in to Code Golf with Safari and has cookies enabled.  Also assumes UIKit is implicitly imported and available.  JSON serialization is so verbose in Cocoa...  Might update this with a Swift 3 solution and optionally macOS/Linux testable answers.


问:
Implement Takewhile

Introduction and Credit

Today without a fancy prelude: Please implement takewhile.

A variation of this (on a non-trivial data structure) was an assignment at my university functional programming course. This assignment is now closed and has been discussed in class and I have my professor's permission to post it here (I asked explicitly).

Specification

Input

The input will be a list (or your language's equivalent concept) of positive integers.

Output

The output should be a list (or your language's equivalent concept) of positive integers.

What to do?

Your task is to implement takewhile (language built-ins are allowed) with the predicate that the number under consideration is even (to focus on takewhile).

So you iterate over the list from start to end and while the condition (is even) holds, you copy to the output-list and as soon as you hit an element that doesn't make the condition true, you abort the operation and output (a step-by-step example is below). This higher-order functionality is also called takeWhile (takewhile).

Potential corner cases

The order of the output list compared to the input list may not be changed, e.g. [14,42,2] may not become [42,14].

The empty list is a valid in- and output.

Who wins?

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

Standard rules apply of course.

Test Vectors

```<code>[14, 42, 2324, 97090, 4080622, 171480372] -> [14, 42, 2324, 97090, 4080622, 171480372]
[42, 14, 42, 2324] -> [42, 14, 42, 2324]
[7,14,42] -> []
[] -> []
[171480372, 13, 14, 42] -> [171480372]
[42, 14, 42, 43, 41, 4080622, 171480372] -> [42, 14, 42]
</code>```

Step-by-Step Example

```<code>Example Input: [42, 14, 42, 43, 41, 4080622, 171480372]

Consider first element: 42
42 is even (21*2)
Put 42 into output list, output list is now [42]

Consider second element: 14
14 is even (7*2)
Put 14 into output list, output list is now [42,14]

Consider third element: 42
42 is even (21*2)
Put 42 into output list, output list is now [42,14,42]

Consider fourth element: 43
43 is not even (2*21+1)
Drop 43 and return the current output list

return [42,14,42]
</code>```

答:
C, <s>73</s> <s>69</s> <s>63</s> <s>60</s> <s>54</s> <s>45</s> 42

This requires a NULL-terminated array of strings as input.
It modifies the parameter by chopping the list down to only even entries.

```<code>f(char**v){for(;*v&&~atoi(*v++)&1;);*v=0;}
</code>```

If printing is allowed (45 bytes, doesn't modify parameter):

```<code>f(char**v){for(;*v&&~atoi(*v)&1;puts(*v++));}
</code>```

Here is the previous complete program version (63 bytes):

```<code>i;main(int c,char**v){for(;(++i<c)-(atoi(v[i])&1);puts(v[i]));}
</code>```

Takes input as program arguments.

Title: Implement Takewhile

Body:
C, <s>73</s> <s>69</s> <s>63</s> <s>60</s> <s>54</s> <s>45</s> 42

This requires a NULL-terminated array of strings as input.
It modifies the parameter by chopping the list down to only even entries.

f(char**v){for(;*v&&~atoi(*v++)&1;);*v=0;}

If printing is allowed (45 bytes, doesn't modify parameter):

f(char**v){for(;*v&&~atoi(*v)&1;puts(*v++));}

Here is the previous complete program version (63 bytes):

i;main(int c,char**v){for(;(++i<c)-(atoi(v[i])&1);puts(v[i]));}

Takes input as program arguments.


答:
C#, <s>86</s> 85 bytes

s=>string.Concat(s.Reverse().Select((c,i)=>s[i]>96?char.ToLower(c):char.ToUpper(c)));
```

<p>A C# lambda where the input and the output is a string. You can try it on .NetFiddle.</p>

<hr>

<p><s>I am struggling to understand why I cant achieve to convert <code>char.ToLower(c)</code> to <code>c+32</code>. I hope to fix it!</s></p>

<p>12 bytes saved thanks to @PeterTaylor (<code>c|32</code> to add 32 to the ascii value of <code>c</code> and <code>c&~32</code> to substract 32). The result would be 72 bytes (but can fail on non alpha char). </p>

<pre class="lang-cs prettyprint-override"><code>s=>string.Join("",s.Reverse().Select((c,i)=>(char)(s[i]>96?c|32:c&~32)));
</code>```

Body:
C#, <s>86</s> 85 bytes

s=>string.Concat(s.Reverse().Select((c,i)=>s[i]>96?char.ToLower(c):char.ToUpper(c)));

A C# lambda where the input and the output is a string. You can try it on .NetFiddle.

<s>I am struggling to understand why I cant achieve to convert char.ToLower(c) to c+32. I hope to fix it!</s>

12 bytes saved thanks to @PeterTaylor (c|32 to add 32 to the ascii value of c and c&~32 to substract 32). The result would be 72 bytes (but can fail on non alpha char).

s=>string.Join("",s.Reverse().Select((c,i)=>(char)(s[i]>96?c|32:c&~32)));


问:
Add two numbers
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is code-golf, answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

```<code>1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17
</code>```

Or as CSV:

```<code>a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17
</code>```

Leaderboard

var QUESTION_ID=84260,OVERRIDE_USER=8478;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

```

答:
Batch, 52 Bytes

```<code>set/p x=
set/p y=
set/a z=%x%+%y%
echo %z%
pause>nul
</code>```

This is the lowest byte number you will have while still making the program work. I did the challenge by making a program, not just what the operation was. This method will allow you to input any number and then any other number, including negatives, and the program will output a number.

Title: Add two numbers

Body:
Batch, 52 Bytes

set/p x=
set/p y=
set/a z=%x%+%y%
echo %z%
pause>nul

This is the lowest byte number you will have while still making the program work. I did the challenge by making a program, not just what the operation was. This method will allow you to input any number and then any other number, including negatives, and the program will output a number.


问:
Can you Golf Golf?
You are required to generate a random 18-hole golf course.

Example output:

```<code>[3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4]
</code>```

Rules:

Your program must output a list of hole lengths for exactly 18 holes

Each hole must have a length of 3, 4 or 5

The hole lengths must add up to 72 for the entire course

Your program must be able to produce every possible hole configuration with some non-zero-probability (the probabilities of each configuration need not be equal, but feel free to claim extra kudos if this is the case)

答:
Groovy

126 chars

```<code>def a=[];while(1){(new Random().nextInt(3)!=1&&a.size()<17?a<<3<<5:a<<4);if(a.size()==18)break};Collections.shuffle(a);print a
</code>```

... ooooh, what a waste of chars :)

110 chars

```<code>def a=[];while(a.size()<18){(new Random().next(2)>1&&a.size()<17?a<<3<<5:a<<4)};Collections.shuffle(a);print a
</code>```

Title: Can you Golf Golf?

Body:
Groovy

126 chars

def a=[];while(1){(new Random().nextInt(3)!=1&&a.size()<17?a<<3<<5:a<<4);if(a.size()==18)break};Collections.shuffle(a);print a

... ooooh, what a waste of chars :)

110 chars

def a=[];while(a.size()<18){(new Random().next(2)>1&&a.size()<17?a<<3<<5:a<<4)};Collections.shuffle(a);print a


答:
Racket, 146 bytes

```<code>(λ(s)(build-string(string-length s)(λ(n)((if(char-upper-case?(string-ref s n))char-upcase char-downcase)(list-ref(reverse(string->list s))n)))))
</code>```

Racket is bad at this whole "golfing" thing.

Shrug  As always, any help with shortening this would be much appreciated.

Body:
Racket, 146 bytes

(λ(s)(build-string(string-length s)(λ(n)((if(char-upper-case?(string-ref s n))char-upcase char-downcase)(list-ref(reverse(string->list s))n)))))

Racket is bad at this whole "golfing" thing.

Shrug  As always, any help with shortening this would be much appreciated.


问:
Was it Really Canada Day?
July 1st is Canada day (yay Canada)! Or is it?  It seems that the Wikipedia page for this day has a lot of Canada related content, but is there another day which is more Canadian?

Your task is to write a program or function which takes a date (month and day) as input and returns or outputs the number of mentions of "Canada" on the Wikipedia page for the inputed date.
Some rules:

Dates may be input in any reasonable format of your choice

Your submission must pull data from the url en.wikipedia.org/wiki/Month_Day.

Only "Canada" must be searched for and counted included substrings, and only in title case. "Canadian" does not count, however "Canada's" does count. As long as the exact, case-senstitive text "Canada" exists within a string, it is a match

Contents of the page are considered anything within the corresponding .html file (i.e. what shows up if you download as page as a .html and open it in Notepad)

Result may be output to STDOUT, returned, or displayed in any other reasonable manner

Test Cases:

```<code>July 1 => 34
May 14 => 1
Oct 31 => 2
July 4 => 2
</code>```

This is code golf, so shortest submission wins

(As an unrewarded bonus, I'm interested to see what the day with the highest count is)

答:
PowerShell, 52 bytes

```<code>((iwr enwp.org/$($args[0]))-csplit"Canada").length-1
</code>```

Input as July_1.

iwr is short for Invoke-WebRequest.

$($args[0]) is first command line argument. Start script as OhCanada.ps1 July_1.

-csplit is case sensitive split.

Title: Was it Really Canada Day?

Body:
PowerShell, 52 bytes

((iwr enwp.org/$($args[0]))-csplit"Canada").length-1

Input as July_1.

iwr is short for Invoke-WebRequest.

$($args[0]) is first command line argument. Start script as OhCanada.ps1 July_1.

-csplit is case sensitive split.


问:
Dig to Australia - antipodes

Background

Countless generations of children have wondered where they would end up if they dug a hole directly downwards. It turns out that this would, unsurprisingly, be rather dangerous, but anyway...

Antipodes are points that are directly opposite each other on the Earth's surface. This means that if a line was drawn between the two points, it would pass through the centre of the Earth.

Challenge

Write a program or function that, given a point, finds its antipode.

In this challenge, points are represented using the longitude-latitude system and degrees, arc minutes and arc seconds. To find the antipode, swap the directions of each ordinate (N <-> S and W <-> E) and subtract the longitude ordinate from 180 degrees.

Example:

Take the point N 50 26 23 W 4 18 29. Swap the directions to give S 50 26 23 E 4 18 29. Subtract the longitude ordinate from 180 0 0 to give 175 41 31, leaving the antipode coordinates as S 50 26 23 E 175 41 31.

Rules

Input

A set of latitude-longitude coordinates, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.

Output

The latitude-longitude coordinates of the antipode, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.

Take reasonable to mean that each part of the coordinate can be distinguished unambiguously.

Specs

The direction for the latitude ordinate is N or S, and that for the longitude ordinate is W or E.

All coordinate values are integers. The degree value will be between 0 and 90 for latitude, and between 0 and 180 for longitude. The arc minute and arc second values for both ordinates will be between 0 and 59.

If all the values for an ordinate are 0, either direction is acceptable.

There is no need to zero-pad any values.

No latitude ordinate will ever  be larger than 90 degrees, and no longitude ordinate will ever be larger than 180 degrees.

Standard loopholes apply.

Test cases

```<code>N 50 26 23 W 4 18 29 -> S 50 26 23 E 175 41 31

S 43 9 9 E 0 0 5     -> N 43 9 9 W 179 59 55

N 0 0 0 E 0 0 0      -> S/N 0 0 0 W/E 180 0 0 (either direction fine in each case)

S 1 2 3 W 4 5 6      -> N 1 2 3 E 175 54 54

S 9 21 43 W 150 7 59 -> N 9 21 43 E 29 52 1

S 27 40 2 W 23 0 0   -> N 27 40 2 E 157 0 0

N 0 58 37 W 37 0 0   -> S 0 58 37 E 143 0 0
</code>```

Useful links

Latitude and longitude

Antipodes

Arc minutes and arc seconds

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

答:
Befunge, <s>122</s> <s>114</s> 111 Bytes (110 characters)

```<code>~"N"-v
 v"N"_"S"
v>,&.&.&.~"W"-
_"E"v"W"
+:v >,&"´"\-&"Z"*&
v\_\.00..@.-\"<".-1\ <
>1-.:"Z"/"<"\-\"Z"%:#^_\..@
</code>```

Input format:

```<code>N 50 26 23W 4 18 29
</code>```

Notice the longitude direction and the arc seconds must be huddled together

You may test the code here

Title: Dig to Australia - antipodes

Body:
Befunge, <s>122</s> <s>114</s> 111 Bytes (110 characters)

~"N"-v
 v"N"_"S"
v>,&.&.&.~"W"-
_"E"v"W"
+:v >,&"´"\-&"Z"*&
v\_\.00..@.-\"<".-1\ <
>1-.:"Z"/"<"\-\"Z"%:#^_\..@

Input format:

N 50 26 23W 4 18 29

Notice the longitude direction and the arc seconds must be huddled together

You may test the code here


答:
Perl, 21 bytes

20 bytes code + 1 bytes command line (-p)

```<code>s/ ?\d*[13579]\b.*//
</code>```

Usage example:

```<code>echo "20 4 6 5 3 4" | perl -pe "s/ ?\d*[13579]\b.*//"
</code>```

Title: Implement Takewhile

Body:
Introduction and Credit

Today without a fancy prelude: Please implement takewhile.

A variation of this (on a non-trivial data structure) was an assignment at my university functional programming course. This assignment is now closed and has been discussed in class and I have my professor's permission to post it here (I asked explicitly).

Specification

Input

The input will be a list (or your language's equivalent concept) of positive integers.

Output

The output should be a list (or your language's equivalent concept) of positive integers.

What to do?

Your task is to implement takewhile (language built-ins are allowed) with the predicate that the number under consideration is even (to focus on takewhile).

So you iterate over the list from start to end and while the condition (is even) holds, you copy to the output-list and as soon as you hit an element that doesn't make the condition true, you abort the operation and output (a step-by-step example is below). This higher-order functionality is also called takeWhile (takewhile).

Potential corner cases

The order of the output list compared to the input list may not be changed, e.g. [14,42,2] may not become [42,14].

The empty list is a valid in- and output.

Who wins?

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

Standard rules apply of course.

Test Vectors

```<code>[14, 42, 2324, 97090, 4080622, 171480372] -> [14, 42, 2324, 97090, 4080622, 171480372]
[42, 14, 42, 2324] -> [42, 14, 42, 2324]
[7,14,42] -> []
[] -> []
[171480372, 13, 14, 42] -> [171480372]
[42, 14, 42, 43, 41, 4080622, 171480372] -> [42, 14, 42]
</code>```

Step-by-Step Example

```<code>Example Input: [42, 14, 42, 43, 41, 4080622, 171480372]

Consider first element: 42
42 is even (21*2)
Put 42 into output list, output list is now [42]

Consider second element: 14
14 is even (7*2)
Put 14 into output list, output list is now [42,14]

Consider third element: 42
42 is even (21*2)
Put 42 into output list, output list is now [42,14,42]

Consider fourth element: 43
43 is not even (2*21+1)
Drop 43 and return the current output list

return [42,14,42]
</code>```

Body:
Perl, 21 bytes

20 bytes code + 1 bytes command line (-p)

s/ ?\d*[13579]\b.*//

Usage example:

echo "20 4 6 5 3 4" | perl -pe "s/ ?\d*[13579]\b.*//"


答:
PHP, 148 bytes

same approach as my JavaScript answer, look there for a breakdown

+16 function overhead

+17 for $ signs

+12 for parantheses (different operator precedence)

+4 for foreach because PHP´s array_map has a huge overhead

+1 for (60-$v)%60 because $v&&60-$v casts to boolean in PHP

-8 by working on the original

-4 by using chr, ord and some arithmetics on the direction swap

```<code>function f(&$a){foreach($a as$i=>$v)$a[$i]=$i%4?($i>6?(60-$v)%60:($i>5?(59-$v+!$a[7])%60:($i>4?179-$v+!($a[7]|$a[6]):$v))):chr(($i?156:161)-ord($v));}
</code>```

function works on original

format: array with 2x (1 uppercase char, 3 int)

tests

```<code>function out($a){if(!is_array($a))return$a;$r=[];foreach($a as$v)$r[]=out($v);return'['.join(',',$r).']';}
function cmp($a,$b){if(is_numeric($a)&&is_numeric($b))return 1e-2<abs($a-$b);if(is_array($a)&&is_array($b)&&count($a)==count($b)){foreach($a as $v){$w = array_shift($b);if(cmp($v,$w))return true;}return false;}return strcmp($a,$b);}
$samples=[
N,50,26,23,W,4,18,29,   S,50,26,23,E,175,41,31,
S,43,9,9,E,0,0,5,       N,43,9,9,W,179,59,55,
N,0,0,0,E,0,0,0,        S,0,0,0,W,180,0,0,
S,1,2,3,W,4,5,6,        N,1,2,3,E,175,54,54,
S,9,21,43,W,150,7,59,   N,9,21,43,E,29,52,1,
S,27,40,2,W,23,0,0,     N,27,40,2,E,157,0,0,
N,0,58,37,W,37,0,0,     S,0,58,37,E,143,0,0,
];
while ($samples)
{
    $xx=$x=array_splice($samples,0,8);
    $ee=$e=array_splice($samples,0,8);
    func($x); test($xx,$ee,$x);
    func($e); test($ee,$xx,$e);
}
</code>```

abandoned ideas

no loop approach with carry flags: +5

loop backwards with carry flags: +7

I could turn this into a program for PHP<5.4, but never mind: -3

Title: Dig to Australia - antipodes

Body:
Background

Countless generations of children have wondered where they would end up if they dug a hole directly downwards. It turns out that this would, unsurprisingly, be rather dangerous, but anyway...

Antipodes are points that are directly opposite each other on the Earth's surface. This means that if a line was drawn between the two points, it would pass through the centre of the Earth.

Challenge

Write a program or function that, given a point, finds its antipode.

In this challenge, points are represented using the longitude-latitude system and degrees, arc minutes and arc seconds. To find the antipode, swap the directions of each ordinate (N <-> S and W <-> E) and subtract the longitude ordinate from 180 degrees.

Example:

Take the point N 50 26 23 W 4 18 29. Swap the directions to give S 50 26 23 E 4 18 29. Subtract the longitude ordinate from 180 0 0 to give 175 41 31, leaving the antipode coordinates as S 50 26 23 E 175 41 31.

Rules

Input

A set of latitude-longitude coordinates, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.

Output

The latitude-longitude coordinates of the antipode, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.

Take reasonable to mean that each part of the coordinate can be distinguished unambiguously.

Specs

The direction for the latitude ordinate is N or S, and that for the longitude ordinate is W or E.

All coordinate values are integers. The degree value will be between 0 and 90 for latitude, and between 0 and 180 for longitude. The arc minute and arc second values for both ordinates will be between 0 and 59.

If all the values for an ordinate are 0, either direction is acceptable.

There is no need to zero-pad any values.

No latitude ordinate will ever  be larger than 90 degrees, and no longitude ordinate will ever be larger than 180 degrees.

Standard loopholes apply.

Test cases

```<code>N 50 26 23 W 4 18 29 -> S 50 26 23 E 175 41 31

S 43 9 9 E 0 0 5     -> N 43 9 9 W 179 59 55

N 0 0 0 E 0 0 0      -> S/N 0 0 0 W/E 180 0 0 (either direction fine in each case)

S 1 2 3 W 4 5 6      -> N 1 2 3 E 175 54 54

S 9 21 43 W 150 7 59 -> N 9 21 43 E 29 52 1

S 27 40 2 W 23 0 0   -> N 27 40 2 E 157 0 0

N 0 58 37 W 37 0 0   -> S 0 58 37 E 143 0 0
</code>```

Useful links

Latitude and longitude

Antipodes

Arc minutes and arc seconds

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

Body:
PHP, 148 bytes

same approach as my JavaScript answer, look there for a breakdown

+16 function overhead

+17 for $ signs

+12 for parantheses (different operator precedence)

+4 for foreach because PHP´s array_map has a huge overhead

+1 for (60-$v)%60 because $v&&60-$v casts to boolean in PHP

-8 by working on the original

-4 by using chr, ord and some arithmetics on the direction swap

function f(&$a){foreach($a as$i=>$v)$a[$i]=$i%4?($i>6?(60-$v)%60:($i>5?(59-$v+!$a[7])%60:($i>4?179-$v+!($a[7]|$a[6]):$v))):chr(($i?156:161)-ord($v));}

function works on original

format: array with 2x (1 uppercase char, 3 int)

tests

function out($a){if(!is_array($a))return$a;$r=[];foreach($a as$v)$r[]=out($v);return'['.join(',',$r).']';}
function cmp($a,$b){if(is_numeric($a)&&is_numeric($b))return 1e-2<abs($a-$b);if(is_array($a)&&is_array($b)&&count($a)==count($b)){foreach($a as $v){$w = array_shift($b);if(cmp($v,$w))return true;}return false;}return strcmp($a,$b);}
$samples=[
N,50,26,23,W,4,18,29,   S,50,26,23,E,175,41,31,
S,43,9,9,E,0,0,5,       N,43,9,9,W,179,59,55,
N,0,0,0,E,0,0,0,        S,0,0,0,W,180,0,0,
S,1,2,3,W,4,5,6,        N,1,2,3,E,175,54,54,
S,9,21,43,W,150,7,59,   N,9,21,43,E,29,52,1,
S,27,40,2,W,23,0,0,     N,27,40,2,E,157,0,0,
N,0,58,37,W,37,0,0,     S,0,58,37,E,143,0,0,
];
while ($samples)
{
    $xx=$x=array_splice($samples,0,8);
    $ee=$e=array_splice($samples,0,8);
    func($x); test($xx,$ee,$x);
    func($e); test($ee,$xx,$e);
}

abandoned ideas

no loop approach with carry flags: +5

loop backwards with carry flags: +7

I could turn this into a program for PHP<5.4, but never mind: -3


问:
Groups of repeating items

Challenge description

Given a list / array of items, display all groups of consecutive repeating items.

Input / output description

Your input is a list / array of items (you can assume all of them are of the same type). You don't need to support every type your language has, but is has to support at least one (preferably int, but types like boolean, although not very interesting, are also fine). Sample outputs:

```<code>[4, 4, 2, 2, 9, 9] -> [[4, 4], [2, 2], [9, 9]]
[1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4] -> [[1, 1, 1], [2, 2], [3, 3, 3], [4, 4, 4, 4]]
[1, 1, 1, 3, 3, 1, 1, 2, 2, 2, 1, 1, 3] -> [[1, 1, 1], [3, 3], [1, 1], [2, 2, 2], [1, 1], [3]]
[9, 7, 8, 6, 5] -> [[9], [7], [8], [6], [5]]
[5, 5, 5] -> [[5, 5, 5]]
['A', 'B', 'B', 'B', 'C', 'D', 'X', 'Y', 'Y', 'Z'] -> [['A'], ['B', 'B', 'B'], ['C'], ['D'], ['X'], ['Y', 'Y'], ['Z']]
[True, True, True, False, False, True, False, False, True, True, True] -> [[True, True, True], [False, False], [True], [False, False], [True, True, True]]
[0] -> [[0]]
</code>```

As for empty lists, output is undefined - it can be nothing, an empty list, or an exception - whatever suits your golfing purposes the best. You don't have to create a separate list of lists either, so this is a perfectly valid output as well:

```<code>[1, 1, 1, 2, 2, 3, 3, 3, 4, 9] ->

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

The important thing is to keep the groups separated in some way. This is code-golf so the shortest code in bytes wins

答:
Befunge, <s>47</s> <s>41</s> 38 Bytes

```<code>&:&:.92pv.<
g29:&:-1_@|!-
92p25*,.^ >:
</code>```

Input format:

```<code>number_of_values-1         values (separated by a space)
</code>```

You may test the code here

Previous version with explanations :

```<code>&:&:.00pv.<
g00:&:-1_@|!-
v*52p00:  <
>,.     ^
</code>```

The interpet's cursor follows the symbols > v < ^. If the cursor is at the end of a line and is going to the right, it will loop back to the beginning (same principle for other directions).

&: : Gets the first input put it to the stack and duplicates it (to the stack)

&:.00pv : Gets the second input, prints it and saves it into the code, at the coordinates (0,0) [erasing the first '&']. Then, go down

_ : Test if last value of the stack (the number of values) is equals to 0 and set the cursor's direction to the right if it is, to the left if it isn't

1-: : Removes 1 from the number of values

&:00g-!| : Compares the next input with the one stored at (0,0). Set the cursor's direction to up if they are equal, to down if they aren't

. : Displays a numeric value

:00p52*,. : Override the last saved value to the current value, then displays \n (ascii 10, 5*2) followed by the value

@ : Terminates the program

Title: Groups of repeating items

Body:
Befunge, <s>47</s> <s>41</s> 38 Bytes

&:&:.92pv.<
g29:&:-1_@|!-
92p25*,.^ >:

Input format:

number_of_values-1         values (separated by a space)

You may test the code here

Previous version with explanations :

&:&:.00pv.<
g00:&:-1_@|!-
v*52p00:  <
>,.     ^

The interpet's cursor follows the symbols > v < ^. If the cursor is at the end of a line and is going to the right, it will loop back to the beginning (same principle for other directions).

&: : Gets the first input put it to the stack and duplicates it (to the stack)

&:.00pv : Gets the second input, prints it and saves it into the code, at the coordinates (0,0) [erasing the first '&']. Then, go down

_ : Test if last value of the stack (the number of values) is equals to 0 and set the cursor's direction to the right if it is, to the left if it isn't

1-: : Removes 1 from the number of values

&:00g-!| : Compares the next input with the one stored at (0,0). Set the cursor's direction to up if they are equal, to down if they aren't

. : Displays a numeric value

:00p52*,. : Override the last saved value to the current value, then displays \n (ascii 10, 5*2) followed by the value

@ : Terminates the program


问:
Help me figure out what TeX I can use!
On TeX.SE the Help Centre says that the following is on topic:

```<code>Formats like LaTeX, ConTeXt and plain TeX
Engines like pdfTeX, LuaTeX and XeTeX
Distributions like TeX Live, MiKTeX, and MacTeX
Related software and tools, BibTeX, MakeIndex, Lyx, etc.
</code>```

I wanted you to write a program to tell me whether my TeX is in the on-topic types of TeX.

An explicit list of the valid TeX-s is as follows:

MetaPost

PostScript

MetaFUN

TeX

LaTeX

LuaLaTeX

LuaTeX

ConTeXt

BibTeX

pdfTeX

Lyx

MakeIndex

TeX Live

XeLaTeX

XeTeX

MacTeX

MiKTeX

Rules

You may use any language.

This is code-golf, to the shortest answer wins.

If you use Regex, you can just match correct ones.

You only need to match one at a time: no

Lyx
BibTeX

You must check with capitalization listed here.

Tests

```<code>TeX -> True/1/<match>
pTeX -> False/0/<not-match>
ConTeXt -> True/1/<match>
context -> False/0/<not-match>
MetaFun -> False/0/<not-match>
MetaFUN -> True/1/<match>
</code>```

P.S. Bonus points for an on-topic TeX answer!

答:
Perl 5, 103 bytes

102 bytes, plus 1 for -pe instead of e. Stdin→stdout.

```<code>$_=/^(Meta(Post|FUN)|TeX Live|PostScript|((Xe|Lua)?(La)?|Bib|pdf|M(ac|iK))TeX|ConTeXt|Lyx|MakeIndex)$/
</code>```

Title: Help me figure out what TeX I can use!

Body:
Perl 5, 103 bytes

102 bytes, plus 1 for -pe instead of e. Stdin→stdout.

$_=/^(Meta(Post|FUN)|TeX Live|PostScript|((Xe|Lua)?(La)?|Bib|pdf|M(ac|iK))TeX|ConTeXt|Lyx|MakeIndex)$/


答:
Python 83

```<code>import random as r;x=[]
while sum(x)!=72:x=[r.randint(3,5) for i in 18*[0]]
print x
</code>```

Like sgrieve's solution, but without numpy

Golfing Adrien Plisson's solution:
120->108 characters

```<code>import random as r,itertools as i
r.choice([g for g in i.product(*([3,4,5,6]for l in 18*[0]))if sum(g)==72])
</code>```

MATLAB 53

```<code>x=[];
while sum(x)~=72
x=3+floor(rand(1,18)*3);
end
x
</code>```

Output:

x =
       4     3     4     4     4     4     5     4     4     3     4     4     3     5     3     5     4     5

Title: Can you Golf Golf?

Body:
You are required to generate a random 18-hole golf course.

Example output:

```<code>[3 4 3 5 5 4 4 4 5 3 3 4 4 3 4 5 5 4]
</code>```

Rules:

Your program must output a list of hole lengths for exactly 18 holes

Each hole must have a length of 3, 4 or 5

The hole lengths must add up to 72 for the entire course

Your program must be able to produce every possible hole configuration with some non-zero-probability (the probabilities of each configuration need not be equal, but feel free to claim extra kudos if this is the case)

Body:
Python 83

import random as r;x=[]
while sum(x)!=72:x=[r.randint(3,5) for i in 18*[0]]
print x

Like sgrieve's solution, but without numpy

Golfing Adrien Plisson's solution:
120->108 characters

import random as r,itertools as i
r.choice([g for g in i.product(*([3,4,5,6]for l in 18*[0]))if sum(g)==72])

MATLAB 53

x=[];
while sum(x)~=72
x=3+floor(rand(1,18)*3);
end
x

Output:

x =
       4     3     4     4     4     4     5     4     4     3     4     4     3     5     3     5     4     5


答:
Jolf, 21 bytes

Try it here!

```<code>Μid?&γ._pXiS=pxHHpxγγ
</code>```

Explanation

```<code>Μid?&γ._pXiS=pxHHpxγγ
Μid                   (Μ)ap (i)nput with (d)is fucntion:
   ?        =pxHH     (H is current element) if H = lowercase(H)
    &γ._pXiS          and set γ to the uppercase entity in the reversed string
                 pxγ  lowercase γ
                    γ else, return γ
</code>```

Body:
The goal here is to simply reverse a string, with one twist:

Keep the capitalization in the same places.

Example Input 1: Hello, Midnightas

Example Output 1: SathginDim ,olleh

Example Input 2: .Q

Exmaple Output 2: q.

Rules:

Output to STDOUT, input from STDIN

The winner will be picked 13th of July on GMT+3 12:00 (One week)

The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.

Any punctuation ending up in a position where there was an upper-case letter must be ignored.

Body:
Jolf, 21 bytes

Try it here!

Μid?&γ._pXiS=pxHHpxγγ

Explanation

Μid?&γ._pXiS=pxHHpxγγ
Μid                   (Μ)ap (i)nput with (d)is fucntion:
   ?        =pxHH     (H is current element) if H = lowercase(H)
    &γ._pXiS          and set γ to the uppercase entity in the reversed string
                 pxγ  lowercase γ
                    γ else, return γ


问:
Full Width Text
Full width text is text that has a space after every character, including the last one. For instance, the first sentence of this question becomes:

```<code>F u l l   w i d t h   t e x t   i s   t e x t   t h a t   h a s   a   s p a c e   a f t e r   e v e r y   c h a r a c t e r ,   i n c l u d i n g   t h e   l a s t   o n e .
</code>```

Write a program that takes a line in text from standard input and outputs it as full-width text to standard out.

Leaderboard

var QUESTION_ID=75979,OVERRIDE_USER=52353;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

```

答:
C#, 35 bytes

s=>string.Join(" ",s.ToList())+" ";
```

C# lambda where the input and the output are string. You can try it on .NetFiddle.

Title: Full Width Text

Body:
C#, 35 bytes

s=>string.Join(" ",s.ToList())+" ";

C# lambda where the input and the output are string. You can try it on .NetFiddle.


答:
Swift 2.2, <s>48</s> 46 bytes

```<code>for c in i.characters{print(c,terminator:" ")}
</code>```

Hey, at least it's shorter than Java...  Saved 2 chars by using a for in loop instead of a forEach closure.

Title: Full Width Text

Body:
Full width text is text that has a space after every character, including the last one. For instance, the first sentence of this question becomes:

```<code>F u l l   w i d t h   t e x t   i s   t e x t   t h a t   h a s   a   s p a c e   a f t e r   e v e r y   c h a r a c t e r ,   i n c l u d i n g   t h e   l a s t   o n e .
</code>```

Write a program that takes a line in text from standard input and outputs it as full-width text to standard out.

Leaderboard

var QUESTION_ID=75979,OVERRIDE_USER=52353;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

```

Body:
Swift 2.2, <s>48</s> 46 bytes

for c in i.characters{print(c,terminator:" ")}

Hey, at least it's shorter than Java...  Saved 2 chars by using a for in loop instead of a forEach closure.


答:
PHP, 65 bytes

```<code>echo substr_count(file_get_contents('http://enwp.org'),'Canada');
</code>```

Title: Was it Really Canada Day?

Body:
July 1st is Canada day (yay Canada)! Or is it?  It seems that the Wikipedia page for this day has a lot of Canada related content, but is there another day which is more Canadian?

Your task is to write a program or function which takes a date (month and day) as input and returns or outputs the number of mentions of "Canada" on the Wikipedia page for the inputed date.
Some rules:

Dates may be input in any reasonable format of your choice

Your submission must pull data from the url en.wikipedia.org/wiki/Month_Day.

Only "Canada" must be searched for and counted included substrings, and only in title case. "Canadian" does not count, however "Canada's" does count. As long as the exact, case-senstitive text "Canada" exists within a string, it is a match

Contents of the page are considered anything within the corresponding .html file (i.e. what shows up if you download as page as a .html and open it in Notepad)

Result may be output to STDOUT, returned, or displayed in any other reasonable manner

Test Cases:

```<code>July 1 => 34
May 14 => 1
Oct 31 => 2
July 4 => 2
</code>```

This is code golf, so shortest submission wins

(As an unrewarded bonus, I'm interested to see what the day with the highest count is)

Body:
PHP, 65 bytes

echo substr_count(file_get_contents('http://enwp.org'),'Canada');


答:
Octave, <s>51</s> 50 bytes

<s>@(s)merge(isupper(s),b=flip(toupper(s)),tolower(b))</s>

@(s)merge(s>64&s<91,b=flip(toupper(s)),tolower(b))
```


问:
Calculate the sum of ILD

Input:

An integer

Output:

Sum of the input itself + the length of the input + each individual digit of the input.

```<code>nr + nr-length + {sum of digits} = output
</code>```

Examples:

Input: 99

Output: 99 (nr) + 2 (nr-length) + (9 + 9) (digits) → 119

Input: 123

Output: 123 + 3 + (1 + 2 + 3) → 132

Challenge rules:

The input can also contain negative input, which are resolved special. The -/minus-sign is also +1 for the length, and is part of the first digit.

For example:

Input: -123

Output: -123 + 4 + (-1 + 2 + 3) → -115

You can assume that the input nor output will ever be outside the range of an (32-bit) integer.

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-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, 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>87901 → 87931
123 → 132
99 → 119
5 → 11
1 → 3
0 → 1
-3 → -4
-123 → -115
-900 → -905
-87901 → -87886
</code>```

Semi-related: Count Sum of all Digits

答:
C, <s>132</s> <s>116</s> <s>113</s> 80

```<code>t,c;f(char*v){for(c=atoi(v+=t=*v==45);*v;t=0,++v)c+=t?50-*v-2*c:*v-47;return c;}
</code>```

Function f() takes the input as a string and returns the result as an integer. Full program version (113 bytes):

```<code>t;main(int c,char**v){char*p=v[1];c=atoi(p+=t=*p==45);for(c=t?-c:c;*p;++p,t=0)c+=t?50-*p:*p-47;printf("%d\n",c);}
</code>```

Requires one argument.

Title: Calculate the sum of ILD

Body:
C, <s>132</s> <s>116</s> <s>113</s> 80

t,c;f(char*v){for(c=atoi(v+=t=*v==45);*v;t=0,++v)c+=t?50-*v-2*c:*v-47;return c;}

Function f() takes the input as a string and returns the result as an integer. Full program version (113 bytes):

t;main(int c,char**v){char*p=v[1];c=atoi(p+=t=*p==45);for(c=t?-c:c;*p;++p,t=0)c+=t?50-*p:*p-47;printf("%d\n",c);}

Requires one argument.


答:
Javascript (using external library) (178 bytes)

```<code>(s)=>_.From(s).Aggregate((t,e)=>{if(0===t.Items.length)return t.Items.push([e]),t;var s=t.Items[t.Items.length-1];return s[0]===e?(s.push(e),t):(t.Items.push([e]),t)},{Items:[]})
</code>```

Disclaimer: I am using a library I wrote to implement LINQ from C# into JS. It didn't exactly help me win but oh well

Title: Groups of repeating items

Body:
Challenge description

Given a list / array of items, display all groups of consecutive repeating items.

Input / output description

Your input is a list / array of items (you can assume all of them are of the same type). You don't need to support every type your language has, but is has to support at least one (preferably int, but types like boolean, although not very interesting, are also fine). Sample outputs:

```<code>[4, 4, 2, 2, 9, 9] -> [[4, 4], [2, 2], [9, 9]]
[1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4] -> [[1, 1, 1], [2, 2], [3, 3, 3], [4, 4, 4, 4]]
[1, 1, 1, 3, 3, 1, 1, 2, 2, 2, 1, 1, 3] -> [[1, 1, 1], [3, 3], [1, 1], [2, 2, 2], [1, 1], [3]]
[9, 7, 8, 6, 5] -> [[9], [7], [8], [6], [5]]
[5, 5, 5] -> [[5, 5, 5]]
['A', 'B', 'B', 'B', 'C', 'D', 'X', 'Y', 'Y', 'Z'] -> [['A'], ['B', 'B', 'B'], ['C'], ['D'], ['X'], ['Y', 'Y'], ['Z']]
[True, True, True, False, False, True, False, False, True, True, True] -> [[True, True, True], [False, False], [True], [False, False], [True, True, True]]
[0] -> [[0]]
</code>```

As for empty lists, output is undefined - it can be nothing, an empty list, or an exception - whatever suits your golfing purposes the best. You don't have to create a separate list of lists either, so this is a perfectly valid output as well:

```<code>[1, 1, 1, 2, 2, 3, 3, 3, 4, 9] ->

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

The important thing is to keep the groups separated in some way. This is code-golf so the shortest code in bytes wins

Body:
Javascript (using external library) (178 bytes)

(s)=>_.From(s).Aggregate((t,e)=>{if(0===t.Items.length)return t.Items.push([e]),t;var s=t.Items[t.Items.length-1];return s[0]===e?(s.push(e),t):(t.Items.push([e]),t)},{Items:[]})

Disclaimer: I am using a library I wrote to implement LINQ from C# into JS. It didn't exactly help me win but oh well


答:
Python, 66 bytes

f=lambda s,i=0:s[i:]and(s[~i]*2).title()[~('@'<s[i]<'[')]+f(s,i+1)
```

Recurses through the indices i, taking the character s[~i] from the back and the case of s[i] from the front. Being capital is checked as lying in the contiguous range @ABC...XYZ[.
Credit to FryAmTheEggman from the (_*2).title() trick.

Body:
Python, 66 bytes

f=lambda s,i=0:s[i:]and(s[~i]*2).title()[~('@'<s[i]<'[')]+f(s,i+1)

Recurses through the indices i, taking the character s[~i] from the back and the case of s[i] from the front. Being capital is checked as lying in the contiguous range @ABC...XYZ[.
Credit to FryAmTheEggman from the (_*2).title() trick.


答:
gs2, 2 bytes

```<code>c-
</code>```

Try it online!

c is a grouping built-in that does exactly this, so we call it on STDIN (which is a string, i.e., a list of chars) and get a list of strings. Sadly, the result is indistinguishable from the input, so we need to add separators! - (join by spaces) does the trick.

An alternative answer is cα (2 bytes of CP437), which simply wraps c into an anonymous function.

Title: Groups of repeating items

Body:
gs2, 2 bytes

c-

Try it online!

c is a grouping built-in that does exactly this, so we call it on STDIN (which is a string, i.e., a list of chars) and get a list of strings. Sadly, the result is indistinguishable from the input, so we need to add separators! - (join by spaces) does the trick.

An alternative answer is cα (2 bytes of CP437), which simply wraps c into an anonymous function.


答:
TCC - 4 bytes

```<code><>ci
</code>```

Try it online!

Explanation:

```<code>     - output is implicit in TCC
<>   - reverse string
  c  - preserve capitalization
   i - get input
</code>```

Body:
TCC - 4 bytes

<>ci

Try it online!

Explanation:

     - output is implicit in TCC
<>   - reverse string
  c  - preserve capitalization
   i - get input


答:
MATL, <s>8</s> 7 bytes

Removed 1 byte thanks to @Suever

```<code>ly&Y'Y{
</code>```

Works with integers/floats/chars/booleans/unicorn points/other imaginary inputs.

For booleans, inputs are T/F, outputs are 1/0.

Try it online!

Grouped and Repeated

```<code>ly&Y'Y{
l          % push 1 onto the stack
 y         % duplicate the input
  &Y'      % run-length encoding (secondary output only)
     Y{    % break up array into cell array of subarrays
</code>```

Title: Groups of repeating items

Body:
MATL, <s>8</s> 7 bytes

Removed 1 byte thanks to @Suever

ly&Y'Y{

Works with integers/floats/chars/booleans/unicorn points/other imaginary inputs.

For booleans, inputs are T/F, outputs are 1/0.

Try it online!

Grouped and Repeated

ly&Y'Y{
l          % push 1 onto the stack
 y         % duplicate the input
  &Y'      % run-length encoding (secondary output only)
     Y{    % break up array into cell array of subarrays


答:
PHP, 128 bytes

```<code>$s=$argv[1];$l=strrev($s);for($i=0;$i<strlen($s);++$i){echo(strtolower($s[$i])!==$s[$i]?strtoupper($l[$i]):strtolower($l[$i]));}
</code>```

I may attempt to optimize this further but I'll just leave it as is for now.

Body:
PHP, 128 bytes

$s=$argv[1];$l=strrev($s);for($i=0;$i<strlen($s);++$i){echo(strtolower($s[$i])!==$s[$i]?strtoupper($l[$i]):strtolower($l[$i]));}

I may attempt to optimize this further but I'll just leave it as is for now.


答:
Factor, 55 bytes

```<code>[ dup [ odd? ] find drop over length over swap ? head ]
</code>```

Using the following substitution regexes, the test cases from the question can be turned into a Factor test suite.

```<code>s/\[((?:\d*(?: )?)*)\]\s+->\s+\[((?:\d*(?: )?)*)\]/{ { $2 } } [ { $1 } take-while-even ] unit-test/g
s/,//g
</code>```

takewhile-even.factor

```<code>USING: kernel math sequences ;
IN: takewhile-even

: take-while-even ( seq -- newseq )
  dup [ odd? ] find drop over length over swap ? head ;
</code>```

takewhile-even-tests.factor

```<code>USING: tools.test takewhile-even ;
IN: takewhile-even.tests

{ { 14 42 2324 97090 4080622 171480372 } } [ { 14 42 2324 97090 4080622 171480372 } take-while-even ] unit-test
{ { 42 14 42 2324 } } [ { 42 14 42 2324 } take-while-even ] unit-test
{ {  } } [ { 7 14 42 } take-while-even ] unit-test
{ {  } } [ {  } take-while-even ] unit-test
{ { 171480372 } } [ { 171480372 13 14 42 } take-while-even ] unit-test
{ { 42 14 42 } } [ { 42 14 42 43 41 4080622 171480372 } take-while-even ] unit-test
</code>```

Run them with "takewhile-even" test.

Title: Implement Takewhile

Body:
Introduction and Credit

Today without a fancy prelude: Please implement takewhile.

A variation of this (on a non-trivial data structure) was an assignment at my university functional programming course. This assignment is now closed and has been discussed in class and I have my professor's permission to post it here (I asked explicitly).

Specification

Input

The input will be a list (or your language's equivalent concept) of positive integers.

Output

The output should be a list (or your language's equivalent concept) of positive integers.

What to do?

Your task is to implement takewhile (language built-ins are allowed) with the predicate that the number under consideration is even (to focus on takewhile).

So you iterate over the list from start to end and while the condition (is even) holds, you copy to the output-list and as soon as you hit an element that doesn't make the condition true, you abort the operation and output (a step-by-step example is below). This higher-order functionality is also called takeWhile (takewhile).

Potential corner cases

The order of the output list compared to the input list may not be changed, e.g. [14,42,2] may not become [42,14].

The empty list is a valid in- and output.

Who wins?

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

Standard rules apply of course.

Test Vectors

```<code>[14, 42, 2324, 97090, 4080622, 171480372] -> [14, 42, 2324, 97090, 4080622, 171480372]
[42, 14, 42, 2324] -> [42, 14, 42, 2324]
[7,14,42] -> []
[] -> []
[171480372, 13, 14, 42] -> [171480372]
[42, 14, 42, 43, 41, 4080622, 171480372] -> [42, 14, 42]
</code>```

Step-by-Step Example

```<code>Example Input: [42, 14, 42, 43, 41, 4080622, 171480372]

Consider first element: 42
42 is even (21*2)
Put 42 into output list, output list is now [42]

Consider second element: 14
14 is even (7*2)
Put 14 into output list, output list is now [42,14]

Consider third element: 42
42 is even (21*2)
Put 42 into output list, output list is now [42,14,42]

Consider fourth element: 43
43 is not even (2*21+1)
Drop 43 and return the current output list

return [42,14,42]
</code>```

Body:
Factor, 55 bytes

[ dup [ odd? ] find drop over length over swap ? head ]

Using the following substitution regexes, the test cases from the question can be turned into a Factor test suite.

s/\[((?:\d*(?: )?)*)\]\s+->\s+\[((?:\d*(?: )?)*)\]/{ { $2 } } [ { $1 } take-while-even ] unit-test/g
s/,//g

takewhile-even.factor

USING: kernel math sequences ;
IN: takewhile-even

: take-while-even ( seq -- newseq )
  dup [ odd? ] find drop over length over swap ? head ;

takewhile-even-tests.factor

USING: tools.test takewhile-even ;
IN: takewhile-even.tests

{ { 14 42 2324 97090 4080622 171480372 } } [ { 14 42 2324 97090 4080622 171480372 } take-while-even ] unit-test
{ { 42 14 42 2324 } } [ { 42 14 42 2324 } take-while-even ] unit-test
{ {  } } [ { 7 14 42 } take-while-even ] unit-test
{ {  } } [ {  } take-while-even ] unit-test
{ { 171480372 } } [ { 171480372 13 14 42 } take-while-even ] unit-test
{ { 42 14 42 } } [ { 42 14 42 43 41 4080622 171480372 } take-while-even ] unit-test

Run them with "takewhile-even" test.


答:
Javascript (using external library) (224 bytes)

```<code>(s)=>{t=_.From(s);var cnt=t.Count();var caps=t.Select(x=>{return x.toUpperCase()===x&&x.toLowerCase()!==x}).ToArray(),i=-1;return t.AggregateRight((a,b)=>{i++;var c=caps[i];return c?a+b.toUpperCase():a+b.toLowerCase()},"");}
</code>```

Disclaimer: Using a library I wrote to bring C#'s LINQ to Javascript

Body:
The goal here is to simply reverse a string, with one twist:

Keep the capitalization in the same places.

Example Input 1: Hello, Midnightas

Example Output 1: SathginDim ,olleh

Example Input 2: .Q

Exmaple Output 2: q.

Rules:

Output to STDOUT, input from STDIN

The winner will be picked 13th of July on GMT+3 12:00 (One week)

The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.

Any punctuation ending up in a position where there was an upper-case letter must be ignored.

Body:
Javascript (using external library) (224 bytes)

(s)=>{t=_.From(s);var cnt=t.Count();var caps=t.Select(x=>{return x.toUpperCase()===x&&x.toLowerCase()!==x}).ToArray(),i=-1;return t.AggregateRight((a,b)=>{i++;var c=caps[i];return c?a+b.toUpperCase():a+b.toLowerCase()},"");}

Disclaimer: Using a library I wrote to bring C#'s LINQ to Javascript


问:
Lithp Tranthlator
My friend made a lisp translator the other day, that is to say it took a string and converted s=>th and S=>Th. It was quite long and I thought that it could be golfed.

So the task is to make a program/function that takes an input string, translates it in to lisp and outputs the string

Test case

```<code>Sam and Sally like Sheep        Tham and Thally like Thheep
Sally likes sausages            Thally liketh thauthageth
Sally sells seashells           Thally thellth theathhellth
</code>```

Note that it doesn't matter that h gets repeated all the time

This is code golf so shortest answer wins

答:
TCC - 28 bytes

```<code>=SO;i;{'s';'th';{'S';'Th';SO
</code>```

Try it online!

Explanation:

```<code>=SO;i;                       - Load input (i) into SO (string operations)
      {'s';'th';             - Replace 's' with 'th' in SO
                {'S';'Th';   - Replace 'S' with 'Th' in SO
                          SO - Implicit print of SO
</code>```

Title: Lithp Tranthlator

Body:
TCC - 28 bytes

=SO;i;{'s';'th';{'S';'Th';SO

Try it online!

Explanation:

=SO;i;                       - Load input (i) into SO (string operations)
      {'s';'th';             - Replace 's' with 'th' in SO
                {'S';'Th';   - Replace 'S' with 'Th' in SO
                          SO - Implicit print of SO


答:
Javascript (using external library) (45 bytes)

Using a library I wrote to bring LINQ to Javascript, I was able to write the following:

```<code>(i)=>i+(i+"").length+_.From(i+"").Sum(x=>x|0)
</code>```

Title: Calculate the sum of ILD

Body:
Input:

An integer

Output:

Sum of the input itself + the length of the input + each individual digit of the input.

```<code>nr + nr-length + {sum of digits} = output
</code>```

Examples:

Input: 99

Output: 99 (nr) + 2 (nr-length) + (9 + 9) (digits) → 119

Input: 123

Output: 123 + 3 + (1 + 2 + 3) → 132

Challenge rules:

The input can also contain negative input, which are resolved special. The -/minus-sign is also +1 for the length, and is part of the first digit.

For example:

Input: -123

Output: -123 + 4 + (-1 + 2 + 3) → -115

You can assume that the input nor output will ever be outside the range of an (32-bit) integer.

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-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, 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>87901 → 87931
123 → 132
99 → 119
5 → 11
1 → 3
0 → 1
-3 → -4
-123 → -115
-900 → -905
-87901 → -87886
</code>```

Semi-related: Count Sum of all Digits

Body:
Javascript (using external library) (45 bytes)

Using a library I wrote to bring LINQ to Javascript, I was able to write the following:

(i)=>i+(i+"").length+_.From(i+"").Sum(x=>x|0)


问:
Loop without 'looping'
A question similar to this has been asked a couple of years ago, but this one is even trickier.

The challenge is simple. Write a program (in your language of choice) that repeatedly executes code without using any repetition structures such as while, for, do while, foreach or goto (So for all you nitpickers, you can't use a loop). However, recursion is not allowed, in the function calling itself sense (see definition below). That would make this challenge far too easy.

There is no restriction on what needs to be executed in the loop, but post an explanation with your answer so that others can understand exactly what is being implemented.

For those who may be hung up on definitions, the definition of a loop for this question is:

A programming language statement which allows code to be repeatedly executed.

And the definition of recursion for this question will be your standard recursive function definition:

A function that calls itself.

Winner will be the answer that has the most upvotes on July 16th at 10 AM eastern time. Good luck!

UPDATE:

To calm confusion that is still being expressed this may help:

Rules as stated above:

Don't use loops or goto

Functions cannot call themselves

Do whatever you want in the 'loop'

If you want to implement something and the rules don't explicitly disallow it, go ahead and do it. Many answers have already bent the rules.

答:
Javascript ( 159 bytes )

This program relies on setInterval from javascript to iterate through an Enumerator (iterator). Uses a library I wrote to create an enumerator, and prints the value to the console

```<code>var e = _.Range(0,10).GetEnumerator();var id = setInterval(function(){var next = e.Next();if(next.Done){clearInterval(id);return;}console.log(next.Value);},1);
</code>```

Title: Loop without 'looping'

Body:
Javascript ( 159 bytes )

This program relies on setInterval from javascript to iterate through an Enumerator (iterator). Uses a library I wrote to create an enumerator, and prints the value to the console

var e = _.Range(0,10).GetEnumerator();var id = setInterval(function(){var next = e.Next();if(next.Done){clearInterval(id);return;}console.log(next.Value);},1);


答:
05AB1E, <s>37</s> 34 bytes

```<code>`60©3L<Rm*O3°648*s-®‰`s®‰s‚˜)'€ÃÂ‡
</code>```

Explained

```<code>`                                      # split input to 4 lines with longitude on top
 60©3L<Rm*O                            # convert longitude to seconds
            3°648*                     # longitude 180 0 0 in seconds
                  s-                   # subtract our longitude from this
                    ®‰`                # get seconds part
                       s®‰             # get minute and degrees part
                          s‚˜)         # join to list
                              '€ÃÂ‡    # translate directions
</code>```

Try it online

Edit: Saved 3 bytes thanks to Adnan.

Title: Dig to Australia - antipodes

Body:
Background

Countless generations of children have wondered where they would end up if they dug a hole directly downwards. It turns out that this would, unsurprisingly, be rather dangerous, but anyway...

Antipodes are points that are directly opposite each other on the Earth's surface. This means that if a line was drawn between the two points, it would pass through the centre of the Earth.

Challenge

Write a program or function that, given a point, finds its antipode.

In this challenge, points are represented using the longitude-latitude system and degrees, arc minutes and arc seconds. To find the antipode, swap the directions of each ordinate (N <-> S and W <-> E) and subtract the longitude ordinate from 180 degrees.

Example:

Take the point N 50 26 23 W 4 18 29. Swap the directions to give S 50 26 23 E 4 18 29. Subtract the longitude ordinate from 180 0 0 to give 175 41 31, leaving the antipode coordinates as S 50 26 23 E 175 41 31.

Rules

Input

A set of latitude-longitude coordinates, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.

Output

The latitude-longitude coordinates of the antipode, in any reasonable format, where each ordinate contains a direction, a number of degrees, a number of arc minutes, and a number of arc seconds.

Take reasonable to mean that each part of the coordinate can be distinguished unambiguously.

Specs

The direction for the latitude ordinate is N or S, and that for the longitude ordinate is W or E.

All coordinate values are integers. The degree value will be between 0 and 90 for latitude, and between 0 and 180 for longitude. The arc minute and arc second values for both ordinates will be between 0 and 59.

If all the values for an ordinate are 0, either direction is acceptable.

There is no need to zero-pad any values.

No latitude ordinate will ever  be larger than 90 degrees, and no longitude ordinate will ever be larger than 180 degrees.

Standard loopholes apply.

Test cases

```<code>N 50 26 23 W 4 18 29 -> S 50 26 23 E 175 41 31

S 43 9 9 E 0 0 5     -> N 43 9 9 W 179 59 55

N 0 0 0 E 0 0 0      -> S/N 0 0 0 W/E 180 0 0 (either direction fine in each case)

S 1 2 3 W 4 5 6      -> N 1 2 3 E 175 54 54

S 9 21 43 W 150 7 59 -> N 9 21 43 E 29 52 1

S 27 40 2 W 23 0 0   -> N 27 40 2 E 157 0 0

N 0 58 37 W 37 0 0   -> S 0 58 37 E 143 0 0
</code>```

Useful links

Latitude and longitude

Antipodes

Arc minutes and arc seconds

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

Body:
05AB1E, <s>37</s> 34 bytes

`60©3L<Rm*O3°648*s-®‰`s®‰s‚˜)'€ÃÂ‡

Explained

`                                      # split input to 4 lines with longitude on top
 60©3L<Rm*O                            # convert longitude to seconds
            3°648*                     # longitude 180 0 0 in seconds
                  s-                   # subtract our longitude from this
                    ®‰`                # get seconds part
                       s®‰             # get minute and degrees part
                          s‚˜)         # join to list
                              '€ÃÂ‡    # translate directions

Try it online

Edit: Saved 3 bytes thanks to Adnan.


答:
Perl 6, 29 bytes

$_=get;put .flip.samecase($_)
```


问:
Tips for golfing in Rust
While Rust is very, very rarely competitive in code golfing competitions (Java is often shorter), it can still be fun to golf in. What are some tricks for making Rust code shorter?

Please post only one tip in each answer.

答:
Avoid .iter().enumerate()

Let's say you have some x that implements the IntoIterator Trait and you need to call a function f that takes the index of an element and a reference to it.
The standard way of doing this is

```<code>x.iter().enumerate().map(f)
</code>```

instead you can do

```<code>(0..).zip(x).map(f)
</code>```

and save yourself not only the unusually long enumerate but also the call to iter!

Title: Tips for golfing in Rust

Body:
Avoid .iter().enumerate()

Let's say you have some x that implements the IntoIterator Trait and you need to call a function f that takes the index of an element and a reference to it.
The standard way of doing this is

x.iter().enumerate().map(f)

instead you can do

(0..).zip(x).map(f)

and save yourself not only the unusually long enumerate but also the call to iter!


问:
Antiprime Champions
Consider the following table for the function d(n), which calculates the number of factors that n is divisible by without a remainder:

```<code>n    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ...
d(n) | 1 | 2 | 2 | 3 | 2 | 4 | 2 | 4 | 3 | 4  | 2  | 6  | ...
</code>```

Going from left to right, it is possible to determine the "champion" of the current subsequence:

The first champion in the sequence [1] is n = 1 with d(1) = 1.

The second champion in the next sequence, [1, 2] is n = 2 with d(2) = 2.

The sequence [1, 2, 3] has no new champions, because d(3) = d(2) = 2, and 2 earned the title first.

The third champion appears the sequence [1, 2, 3, 4]: d(4) = 3, which is greater than the previous champion with d(2) = 2.

The next champion is 6 in [1, 2, 3, 4, 5, 6] with d(6) = 4.

The next champion is 12 with d(12) = 6.

The champions can be denoted in the table:

```<code>n    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ...
d(n) | 1 | 2 | 2 | 3 | 2 | 4 | 2 | 4 | 3 | 4  | 2  | 6  | ...
       x   x       x       x                         x
</code>```

You task is the following: Write a program that given an integer n, print all champions in the range [1, n] (n inclusive). The output format does not matter (test cases below display array format). Standard code golf rules and scoring applies.

Test cases

```<code>1 -> [1]
2 -> [1, 2]
3 -> [1, 2]
4 -> [1, 2, 4]
5 -> [1, 2, 4]
6 -> [1, 2, 4, 6]
7 -> [1, 2, 4, 6]
8 -> [1, 2, 4, 6]
9 -> [1, 2, 4, 6]
10 -> [1, 2, 4, 6]
11 -> [1, 2, 4, 6]
12 -> [1, 2, 4, 6, 12]
24 -> [1, 2, 4, 6, 12, 24]
36 -> [1, 2, 4, 6, 12, 24, 36]
</code>```

Hint: The output should always be a prefix of the List of Highly Composite Numbers.

答:
05AB1E, <s>16</s> 15 bytes

```<code>0U>GNÑg©X›i®UN,
</code>```

Explanation

```<code>0U               # initialize the record as 0
  >G             # for each number in 1 to N
    NÑg©         # get number of divisors
        X›i      # if number of divisors is a new record
           ®U    # save new record
             N,  # print the new record holder on a new line
</code>```

Try it online

Title: Antiprime Champions

Body:
05AB1E, <s>16</s> 15 bytes

0U>GNÑg©X›i®UN,

Explanation

0U               # initialize the record as 0
  >G             # for each number in 1 to N
    NÑg©         # get number of divisors
        X›i      # if number of divisors is a new record
           ®U    # save new record
             N,  # print the new record holder on a new line

Try it online


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

```<code>0i:t!\~sY>hdf
</code>```

Try it online!

Explanation

```<code>0      % Push 0
i:     % Take input n. Push [1 2 ... n]
t!\    % 2D array of all combinations of modulo between elements of [1 2 ... n]
~s     % Sum of zeros of each column. Gives number of divisors for [1 2 ... n]
Y>     % Cumulative maximum
h      % Concatenate with 0
d      % Consecutive differences
f      % Indices of nonzero elements. Implicitly display
</code>```

Title: Antiprime Champions

Body:
Consider the following table for the function d(n), which calculates the number of factors that n is divisible by without a remainder:

```<code>n    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ...
d(n) | 1 | 2 | 2 | 3 | 2 | 4 | 2 | 4 | 3 | 4  | 2  | 6  | ...
</code>```

Going from left to right, it is possible to determine the "champion" of the current subsequence:

The first champion in the sequence [1] is n = 1 with d(1) = 1.

The second champion in the next sequence, [1, 2] is n = 2 with d(2) = 2.

The sequence [1, 2, 3] has no new champions, because d(3) = d(2) = 2, and 2 earned the title first.

The third champion appears the sequence [1, 2, 3, 4]: d(4) = 3, which is greater than the previous champion with d(2) = 2.

The next champion is 6 in [1, 2, 3, 4, 5, 6] with d(6) = 4.

The next champion is 12 with d(12) = 6.

The champions can be denoted in the table:

```<code>n    | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | ...
d(n) | 1 | 2 | 2 | 3 | 2 | 4 | 2 | 4 | 3 | 4  | 2  | 6  | ...
       x   x       x       x                         x
</code>```

You task is the following: Write a program that given an integer n, print all champions in the range [1, n] (n inclusive). The output format does not matter (test cases below display array format). Standard code golf rules and scoring applies.

Test cases

```<code>1 -> [1]
2 -> [1, 2]
3 -> [1, 2]
4 -> [1, 2, 4]
5 -> [1, 2, 4]
6 -> [1, 2, 4, 6]
7 -> [1, 2, 4, 6]
8 -> [1, 2, 4, 6]
9 -> [1, 2, 4, 6]
10 -> [1, 2, 4, 6]
11 -> [1, 2, 4, 6]
12 -> [1, 2, 4, 6, 12]
24 -> [1, 2, 4, 6, 12, 24]
36 -> [1, 2, 4, 6, 12, 24, 36]
</code>```

Hint: The output should always be a prefix of the List of Highly Composite Numbers.

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

0i:t!\~sY>hdf

Try it online!

Explanation

0      % Push 0
i:     % Take input n. Push [1 2 ... n]
t!\    % 2D array of all combinations of modulo between elements of [1 2 ... n]
~s     % Sum of zeros of each column. Gives number of divisors for [1 2 ... n]
Y>     % Cumulative maximum
h      % Concatenate with 0
d      % Consecutive differences
f      % Indices of nonzero elements. Implicitly display


答:
Jelly, 10 bytes

```<code>0rÆDL€»\IT
</code>```

Try it online!

Title: Antiprime Champions

Body:
Jelly, 10 bytes

0rÆDL€»\IT

Try it online!


问:
What's the second non-repeating character?
Based on this question from Code Review

Given a non-empty string of printable ASCII characters, output the second non-repeating character. For example, for input DEFD, output F.

Input

A single string, in any suitable format.

Output

The second character that doesn't repeat, when reading left-to-right, again in a suitable format.

The output character is case-insensitive.

If no such character exists (e.g., all characters repeat), output an empty string.

Rules

The algorithm should ignore case. That is, D and d count as the same character.

Either a full program or a function are acceptable.

The input string will be guaranteed non-empty (i.e., at least one character in length).

The input string is ASCII. Any valid character could repeat, not just alphanumeric (this includes spaces).

Standard loopholes are forbidden.

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

Examples

Input is on first line, output is on second line.

```<code>DEFD
F

FEED
D

This is an example input sentence.
x

...,,,..,,!@
@

ABCDefgHijklMNOPqrsTuVWxyz
B

AAAAAABBBBB

Thisxthis

This this.
.
</code>```

答:
Javascript (using external Library) (107 bytes)

Crushed this using a library I wrote. Not sure if I have to count the declaration of variable "s", which is the string in question.

```<code>(s)=>_.From(s).ToLookup(y=>y.toLowerCase(),z=>z).Where(g=>g.Value.Count()==1).Select(x=>x.Key).ElementAt(1)
</code>```

This will handle an empty string input, an input with only one non-repeating character, and an input with 2+ non-repeating characters

Body:
Javascript (using external Library) (107 bytes)

Crushed this using a library I wrote. Not sure if I have to count the declaration of variable "s", which is the string in question.

(s)=>_.From(s).ToLookup(y=>y.toLowerCase(),z=>z).Where(g=>g.Value.Count()==1).Select(x=>x.Key).ElementAt(1)

This will handle an empty string input, an input with only one non-repeating character, and an input with 2+ non-repeating characters


问:
Output quater-imaginary base numbers in binary
Write a function or program that outputs Quater-imaginary base displayed as binary digits. The number base is 2i, where i is the square root of -1. See Complex Number for more details on i. Each digit position can go from 0 to 3 (quaternary), as each real and imaginary part is -4 times as large as the previous real and imaginary part. The quaternary digits in binary are as follows: 0: 00, 1: 01, 2: 10 & 3: 11.

Breakdown of digit positions:

```<code>re   im       16 -8i  -4  2i   1 -0.5i, etc.
 4    0        1   0   3   0   0        (quaternary representation)
              01  00  11  00  00        (binary representation)
</code>```

The number 100110000 is 1x16 + 3x-4 = 16 + -12 = 4.

```<code>re   im       16 -8i  -4  2i   1 -0.5i, etc.
 0    5        0   0   0   3   0   2    (quaternary representation)
              00  00  00  11  00 .10    (binary representation)
</code>```

The number 1100.1 is 3x2i + 2x-0.5i = 6i + -i = 5i.

Your code will take a pair of numbers, which could be integer or floating point, and will output the complex number as a string of binary digits. The first number will be real, the second input number will be the imaginary value. A binary point must only be printed if there are non-zero number positions below 1 (i.e. if any of the positions for -0.5i, -0.25, 0.125i, etc. have a non-zero digit). Leading and trailing zeros are not allowed, except for a single zero digit immediately before the binary point if there are no other digits. The output must not start with a binary point (*00.1 - wrong, 0.1 - right, *.1 - wrong, *0.10 - wrong). You may assume that all input numbers will have finite binary representations.

Test numbers:

```<code>re   im            output
 0    0                 0
 1    0                 1
 2    0                10
 3    0                11
 4    0         100110000
-1    0             10011
-2    0             10010
-3    0             10001
 0    1               100.1
 0    2               100
 0    3              1000.1
 0    4              1000
 0   -1                 0.1
 0   -2           1001100
 0   -3           1001100.1
 3    4              1011
 4    3         100111000.1
 6   -9         101110010.1
-6    9       10011100110.1
-9   -6           1110111
 0.5 14.125   10011001101.001001
</code>```

Note: The output of all integer values will end in .1 if the imaginary part is odd.

Standard code-golf.

答:
JavaScript (ES6), 340 bytes

```<code>f=x=>[0,...x.toString(16)].reverse().map(d=>s=d<'.'?s:d<`0`?d+s.slice(0,-1):`${(c=+`0x${d}`+(c>>4)+m^m)>>2&3}${c&3}`+s,c=s='.',m=x<0?3:12)&&s
g=(s,t,n=s.indexOf`.`,m=t.indexOf`.`)=>n<m?g(0+s,t):n>m?g(s,0+t):t[s.length]?g(s+0,t):s.replace(/\d/g,(c,i)=>`${t[i]>>1}${t[i]&1}${c>>1}${c&1}`).replace(/^0+(\d)|\.?0*$/g,'$1')
(r,i)=>g(f(r),f(i/2))
</code>```

f converts a number into base -4 (with trailing . if the number is an integer). g takes two base -4 numbers, pads them at both ends to the same length and . position, shuffles the digits together, converts everything from base 4 to base 2, then finally strips leading and trailing zeros.

Explanation: To represent the given complex number in modified-base 2i we need to represent the real part and half of the complex part (i.e. dividing the imaginary part by 2i) in base 2i² (i.e. -4), shuffle the digits together, and then convert them from base 4 to base 2. To represent a real number in base -4 we start with the base 4 conversion. Alternate digits have the correct sign (in the case of a positive number, these are the digits in the even positions; in the case of a negative number, these are the digits in the odd positions) but the remaining digits have the wrong sign and a correction needs to be applied. Examples:

```<code> 0 -> 000 -> 000 (no correction needed)
 4 -> 010 -> 130 }
 8 -> 020 -> 120 } (correction includes carry)
12 -> 030 -> 110 }
</code>```

As you can see, the correction is 8 minus the original digit, mod 8. However a slightly more convenient calculation is the original digit, plus 3, xor 3 (indeed in 32-bit integer arithmetic we could simply write +0xCCCCCCCC^0xCCCCCCCC to convert the entire number in one go). Finally as the correction applies to alternate digits it is simpler to do an initial conversion to base 16 which automatically picks up pairs of base 4 digits, then correct using a factor of either 3 or 0xC as appropriate. It just remains to ignore the - sign.

Body:
JavaScript (ES6), 340 bytes

f=x=>[0,...x.toString(16)].reverse().map(d=>s=d<'.'?s:d<`0`?d+s.slice(0,-1):`${(c=+`0x${d}`+(c>>4)+m^m)>>2&3}${c&3}`+s,c=s='.',m=x<0?3:12)&&s
g=(s,t,n=s.indexOf`.`,m=t.indexOf`.`)=>n<m?g(0+s,t):n>m?g(s,0+t):t[s.length]?g(s+0,t):s.replace(/\d/g,(c,i)=>`${t[i]>>1}${t[i]&1}${c>>1}${c&1}`).replace(/^0+(\d)|\.?0*$/g,'$1')
(r,i)=>g(f(r),f(i/2))

f converts a number into base -4 (with trailing . if the number is an integer). g takes two base -4 numbers, pads them at both ends to the same length and . position, shuffles the digits together, converts everything from base 4 to base 2, then finally strips leading and trailing zeros.

Explanation: To represent the given complex number in modified-base 2i we need to represent the real part and half of the complex part (i.e. dividing the imaginary part by 2i) in base 2i² (i.e. -4), shuffle the digits together, and then convert them from base 4 to base 2. To represent a real number in base -4 we start with the base 4 conversion. Alternate digits have the correct sign (in the case of a positive number, these are the digits in the even positions; in the case of a negative number, these are the digits in the odd positions) but the remaining digits have the wrong sign and a correction needs to be applied. Examples:

 0 -> 000 -> 000 (no correction needed)
 4 -> 010 -> 130 }
 8 -> 020 -> 120 } (correction includes carry)
12 -> 030 -> 110 }

As you can see, the correction is 8 minus the original digit, mod 8. However a slightly more convenient calculation is the original digit, plus 3, xor 3 (indeed in 32-bit integer arithmetic we could simply write +0xCCCCCCCC^0xCCCCCCCC to convert the entire number in one go). Finally as the correction applies to alternate digits it is simpler to do an initial conversion to base 16 which automatically picks up pairs of base 4 digits, then correct using a factor of either 3 or 0xC as appropriate. It just remains to ignore the - sign.


问:
Reverse a string while maintaining the capitalization in the same places
The goal here is to simply reverse a string, with one twist:

Keep the capitalization in the same places.

Example Input 1: Hello, Midnightas

Example Output 1: SathginDim ,olleh

Example Input 2: .Q

Exmaple Output 2: q.

Rules:

Output to STDOUT, input from STDIN

The winner will be picked 13th of July on GMT+3 12:00 (One week)

The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.

Any punctuation ending up in a position where there was an upper-case letter must be ignored.

答:
PowerShell, <s>154</s>, <s>152</s>, <s>99</s>, 86 bytes

Thank you @TimmyD for saving me a whopping 47 bytes (I also saved an additional 6)

Thank you @TessellatingHeckler for saving an additional 13 bytes.

Latest:

```<code>param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
</code>```

Original:

```<code>param($a);$x=0;(($a[-1..-$a.length])|%{$_=$_.tostring().tolower();if([regex]::matches($a,"[A-Z]").index-contains$x){$_.toupper()}else{$_};$x++})-join''
</code>```

Normal formatting:

Latest (looks best as two lines in my opinion):

```<code>param($a)
-join($a[$a.length..0] | %{("$_".ToLower(), "$_".ToUpper())[$a[$i++] -in 65..90]})
</code>```

Explanation:

```<code>param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
param($a)
# Sets the first passed parameter to variable $a
         -join(                                                                      )
# Converts a char array to a string
               $a[$a.length..0]
# Reverses $a as a char array
                               |%{                                                  }
# Shorthand pipe to foreach loop
                                  ("$_".ToLower(),"$_".ToUpper())
# Creates an array of the looped char in lower and upper cases
                                                                 [$a[$i++]-in65..90]
# Resolves to 1 if the current index of $a is upper, which would output "$_".ToUpper() which is index 1 of the previous array
</code>```

Original:

```<code>param($a)
$x = 0
(($a[-1..-$a.length]) | %{
    $_ = $_.tostring().tolower()
    if([regex]::matches($a,"[A-Z]").index -contains $x){
            $_.toupper()
        }else{
            $_
        }
        $x++
    }
) -join ''
</code>```

First time poster here, was motivated because I rarely see PowerShell, <s>but at <s>154</s> 152 bytes on this one... I can see why!</s> Any suggestions appreciated.

I have learned that I must completely change my way of thinking to golf in code and its fun!

Body:
PowerShell, <s>154</s>, <s>152</s>, <s>99</s>, 86 bytes

Thank you @TimmyD for saving me a whopping 47 bytes (I also saved an additional 6)

Thank you @TessellatingHeckler for saving an additional 13 bytes.

Latest:

param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})

Original:

param($a);$x=0;(($a[-1..-$a.length])|%{$_=$_.tostring().tolower();if([regex]::matches($a,"[A-Z]").index-contains$x){$_.toupper()}else{$_};$x++})-join''

Normal formatting:

Latest (looks best as two lines in my opinion):

param($a)
-join($a[$a.length..0] | %{("$_".ToLower(), "$_".ToUpper())[$a[$i++] -in 65..90]})

Explanation:

param($a)-join($a[$a.length..0]|%{("$_".ToLower(),"$_".ToUpper())[$a[$i++]-in65..90]})
param($a)
# Sets the first passed parameter to variable $a
         -join(                                                                      )
# Converts a char array to a string
               $a[$a.length..0]
# Reverses $a as a char array
                               |%{                                                  }
# Shorthand pipe to foreach loop
                                  ("$_".ToLower(),"$_".ToUpper())
# Creates an array of the looped char in lower and upper cases
                                                                 [$a[$i++]-in65..90]
# Resolves to 1 if the current index of $a is upper, which would output "$_".ToUpper() which is index 1 of the previous array

Original:

param($a)
$x = 0
(($a[-1..-$a.length]) | %{
    $_ = $_.tostring().tolower()
    if([regex]::matches($a,"[A-Z]").index -contains $x){
            $_.toupper()
        }else{
            $_
        }
        $x++
    }
) -join ''

First time poster here, was motivated because I rarely see PowerShell, <s>but at <s>154</s> 152 bytes on this one... I can see why!</s> Any suggestions appreciated.

I have learned that I must completely change my way of thinking to golf in code and its fun!


答:
Ruby, 53 bytes

Input is STDIN, output is STDOUT. In Ruby, out-of-index positions in an array or string return nil, which is not printed.

String#count is a strange function in Ruby because instead of counting the number of occurrences for the string that was passed in, it counts the number of occurrences for each letter in that string. It's usually annoying but we can use it to our advantage this time. String#swapcase swaps upper and lower case letters.

```<code>$><<gets.chars.reject{|c|$_.count(c+c.swapcase)>1}[1]
</code>```

Old version that wasn't safe against special characters like . - 46 bytes

```<code>$><<gets.chars.reject{|c|$_=~/#{c}.*#{c}/i}[1]
</code>```

Title: What's the second non-repeating character?

Body:
Based on this question from Code Review

Given a non-empty string of printable ASCII characters, output the second non-repeating character. For example, for input DEFD, output F.

Input

A single string, in any suitable format.

Output

The second character that doesn't repeat, when reading left-to-right, again in a suitable format.

The output character is case-insensitive.

If no such character exists (e.g., all characters repeat), output an empty string.

Rules

The algorithm should ignore case. That is, D and d count as the same character.

Either a full program or a function are acceptable.

The input string will be guaranteed non-empty (i.e., at least one character in length).

The input string is ASCII. Any valid character could repeat, not just alphanumeric (this includes spaces).

Standard loopholes are forbidden.

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

Examples

Input is on first line, output is on second line.

```<code>DEFD
F

FEED
D

This is an example input sentence.
x

...,,,..,,!@
@

ABCDefgHijklMNOPqrsTuVWxyz
B

AAAAAABBBBB

Thisxthis

This this.
.
</code>```

Body:
Ruby, 53 bytes

Input is STDIN, output is STDOUT. In Ruby, out-of-index positions in an array or string return nil, which is not printed.

String#count is a strange function in Ruby because instead of counting the number of occurrences for the string that was passed in, it counts the number of occurrences for each letter in that string. It's usually annoying but we can use it to our advantage this time. String#swapcase swaps upper and lower case letters.

$><<gets.chars.reject{|c|$_.count(c+c.swapcase)>1}[1]

Old version that wasn't safe against special characters like . - 46 bytes

$><<gets.chars.reject{|c|$_=~/#{c}.*#{c}/i}[1]


问:
Write all possible Braille characters
An interesting puzzle came to me looking at the elevator buttons this morning.

You are required to generate a list of all Braille patterns that fit in a 2x3 grid.  Use a hash # to denote a bump and a hyphen - to denote a flat area.

Expected output sample:

```<code>#-
--
--

##
--
--

#-
#-
--

(and so on...)
</code>```

Rules:

Your program must separate each pattern by at least one character or line.

The patterns may be generated in any order.

All patterns, regardless of what the Braille alphabet actually uses, should be produced.  The completely blank pattern is optional.

Only unique bump patterns should be generated.  The following patterns are considered equivilent as the bumps are in an identical arangement.  In these cases, use the pattern that is closest to the top-left corner (ie. the first option in this example.)

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

Bonus points if you can make it work for any x by y sized grid. (EDIT: Within reasonable bounds.  Up to 4x4 is enough for proof of concept.)

Reading the wiki article, it appears there are 45 patterns (including the blank) that meet this puzzle's rules.

答:
Python - 121 112

blank is not included

```<code>from itertools import*
print'\n'.join('%s%s\n'*3%b for(b,n)in zip(product(*['_#']*6),range(64))if n&48and n&42)
</code>```

Title: Write all possible Braille characters

Body:
Python - 121 112

blank is not included

from itertools import*
print'\n'.join('%s%s\n'*3%b for(b,n)in zip(product(*['_#']*6),range(64))if n&48and n&42)


答:
VIM, 46 bytes

It'd be three bytes g~G if we didn't need to read from stdin or write to stdout, but oh well...

```<code>vim -es '+normal! g~G' '+%print|q!' /dev/stdin
</code>```

To test this, run

```<code>echo "testString" | vim -es '+normal! g~G' '+%print|q!' /dev/stdin
</code>```

This is my first submission on here, not sure if this kind of submission is acceptable.

Body:
The goal here is to simply reverse a string, with one twist:

Keep the capitalization in the same places.

Example Input 1: Hello, Midnightas

Example Output 1: SathginDim ,olleh

Example Input 2: .Q

Exmaple Output 2: q.

Rules:

Output to STDOUT, input from STDIN

The winner will be picked 13th of July on GMT+3 12:00 (One week)

The input may only consist of ASCII symbols, making it easier for programs that do not use any encoding that contains non-ASCII characters.

Any punctuation ending up in a position where there was an upper-case letter must be ignored.

Body:
VIM, 46 bytes

It'd be three bytes g~G if we didn't need to read from stdin or write to stdout, but oh well...

vim -es '+normal! g~G' '+%print|q!' /dev/stdin

To test this, run

echo "testString" | vim -es '+normal! g~G' '+%print|q!' /dev/stdin

This is my first submission on here, not sure if this kind of submission is acceptable.


答:
C, 188

```<code>main(int c,char**v){int n=*v[1]==78?83:78,e=*v[5]==69?87:69,b=648000-(atoi(v[6])*3600+atoi(v[7])*60+atoi(v[8]));printf("%c %s %s %s %c %d %d %d\n",n,v[2],v[3],v[4],e,b/3600,b/60%60,b%60);}
</code>```

Requires 8 program arguments, will fail otherwise. Pass arguments like N 50 26 23 W 4 18 29. Direction indicators N, S, E, W, must be capitalized.

Title: Dig to Australia - antipodes

Body:
C, 188

main(int c,char**v){int n=*v[1]==78?83:78,e=*v[5]==69?87:69,b=648000-(atoi(v[6])*3600+atoi(v[7])*60+atoi(v[8]));printf("%c %s %s %s %c %d %d %d\n",n,v[2],v[3],v[4],e,b/3600,b/60%60,b%60);}

Requires 8 program arguments, will fail otherwise. Pass arguments like N 50 26 23 W 4 18 29. Direction indicators N, S, E, W, must be capitalized.


问:
Is it a sum-free set?
A set is sum-free if no two (not necessarily distinct) elements when added together are part of the set itself.

For example, {1, 5, 7} is sum-free, because all members are odd, and two odd numbers when added together are always even. On the other hand, {2, 4, 9, 13} is not sum-free, as either 2 + 2 = 4 or 4 + 9 = 13 add together to a member of the set.

Write a program or function that takes a set as input, and outputs a Truthy value if the set is sum-free, and Falsy otherwise.

Examples:

```<code>Sum-free:
{}
{4}
{1, 5, 7}
{16, 1, 4, 9}

Not sum-free:
{0}
{1, 4, 5, 7}
{3, 0}
{16, 1, 4, 8}
</code>```

答:
Pyth - <s>8</s> 5 bytes

Thanks to @FryAmTheEggman for saving me 3 bytes.

```<code>!@sM*
</code>```

Test Suite.

```<code>!             Logical not. This makes the empty intersection true and vice versa.
 @    Q       Setwise intersection with input (implictly).
  sM          Map sum to all the pairs.
   *QQ        Get all pairs by doing cartesian product with input*input (implicit).
</code>```

Title: Is it a sum-free set?

Body:
Pyth - <s>8</s> 5 bytes

Thanks to @FryAmTheEggman for saving me 3 bytes.

!@sM*

Test Suite.

!             Logical not. This makes the empty intersection true and vice versa.
 @    Q       Setwise intersection with input (implictly).
  sM          Map sum to all the pairs.
   *QQ        Get all pairs by doing cartesian product with input*input (implicit).