问:
Superstitious Programming
Your challenge is extremely simple. Given a year as input, print all the months in that year that will contain a Friday the 13th according to the Gregorian calendar. Note that even though the Gregorian Calendar wasn't introduced until 1582, for simplicity's sake we will pretend that it has been in use since 0001 AD.

Rules

Full programs or functions are allowed.

You can take input as function arguments, from STDIN, or as command line arguments.

You are not allowed to use any date and time builtins.

You can safely assume that the input will be a valid year. If the input is smaller than 1, not a valid integer, or larger than your languages native number type, you do not have to handle this, and you get undefined behaviour.

Output can be numbers, in English, or in any other human readable format, so long as you specify the standard.

Make sure you account for leap-years. And remember, leap-years do not happen every 4 years!

Tips

Since there are so many different ways to go about this, I don't want to tell you how to do it. However, it might be confusing where to start, so here are a couple different reliable ways of determining the day of the week from a date.

Conway's doomsday-algorithm

Pick a start date with a known day of the week, such as Monday, January 1st, 0001 and find how far apart the two days are, and take that number mod 7.

Gauss's Algorithm

A variation on Gauss's Algorithm

Any of these methods

Sample IO

```<code>2016 --> May
0001 --> 4, 7
1997 --> Jun
1337 --> 09, 12
123456789 --> January, October
</code>```

As usual, this is code-golf, so standard-loopholes apply, and shortest answer wins.

var QUESTION_ID=69510,OVERRIDE_USER=31716;function answersUrl(e){return"http://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"http://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, <s> 276 </s> 219 bytes

```<code>#define R return
#define L(i) for(;i-->0;)
u(y,m){R m-1?30+((2773>>m)&1):28+(y%4==0&&y%100||y%400==0);}s(y,m,g){g+=4;L(m)g+=u(y,m),g%=7;L(y)g+=1+u(y,1),g%=7;R g;}z(y,m,r){m=12;L(m)s(y,m,13)-4||(r|=1<<(m+1));R r;}
</code>```

input from stdin output in stdout try to http://ideone.com/XtuhGj [the debug function is z]

```<code>w(y,m,r){m=12;L(m)s(y,m,u(y,m))||(r|=1<<(m+1));R r;}
/*
// ritorna il numero dei giorni di anno=y mese=m con mese in 0..11
// m==1 significa febbraio   y%4?0:y%100?1:!(y%400) non funziona
u(y,m){R m-1?30+((2773>>m)&1):28+(y%4==0&&y%100||y%400==0);}

// argomenti anno:y[0..0xFFFFFFF]  mese:m[0..11]  giorno:g[1..u(y,m)]
// ritorna il numero del giorno[0..6]
s(y,m,g)
{g+=4; // correzione per il giorno di partenza anno mese giorno = 0,1,1
 L(m)g+=  u(y,m),g%=7; // m:0..m-1  somma mod 7 i giorni del mese dell'anno y
 L(y)g+=1+u(y,1),g%=7; // y:0..y-1  somma mod 7 gli anni da 0..y-1
                       // g+=1+u(y,1) poiche' (365-28)%7=1 e 1 e' febbraio
 R g;
}

// argomenti anno:y[0..0xFFFFFFF], m=0 r=0
// calcola tutti gli ultimi giorni del mese dell'anno y che cadono di lunedi'
// e mette tali mesi come bit, dal bit 1 al bit 12 [il bit 0 sempre 0] in r
w(y,m,r){m=12;L(m)s(y,m,u(y,m))||(r|=1<<(m+1));R r;}

// argomenti anno:y[0..0xFFFFFFF], m=0 r=0
//ritorna in r il numero dei mesi che ha giorno 13 di venerdi[==4]
// e mette tali mesi come bit, dal bit 1 al bit 12 [il bit 0 sempre 0] in r
z(y,m,r){m=12;L(m)s(y,m,13)-4||(r|=1<<(m+1));R r;}
*/

#define P printf
#define W while
#define M main
#define F for
#define U unsigned
#define N int
#define B break
#define I if
#define J(a,b)  if(a)goto b
#define G goto
#define P printf
#define D double
#define C unsigned char
#define A getchar()
#define O putchar
#define Y malloc
#define Z free
#define S sizeof
#define T struct
#define E else
#define Q static
#define X continue
M()
{N y,m,g,r,arr[]={1,297,1776,2000,2016,3385}, arr1[]={2016,1,1997,1337,123456789};
 C*mese[]={"gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic"};
 C*giorno[]={"Lun","Mar","Mer","Gio","Ven","Sab","Dom"};
 P("Inserisci Anno mese giorno>");r=scanf("%d %d %d", &y, &m, &g);
 P("Inseriti> %d %d %d r=%d\n", y, m, g, r);
 I(r!=3||m>12||m<=0||g>u(y,m-1))R 0;
 r=s(y,m-1,g);// 12-> 11 -> 0..10
 P("Risultato=%d giorno=%s\n", r, giorno[r]);
 r=w(y,0,0);P(" r=%d ", r);P("\n");
 F(m=0;m<6;++m)
        {P("N anno=%d -->",arr[m]);
         r=w(arr[m],0,0); // ritorna in r i mesi tramite i suoi bit...
         F(y=1;y<13;++y) I(r&(1<<y))P("%s ",mese[y-1]);
         P("\n");
        }
 F(m=0;m<4;++m)
        {P("N anno=%d -->",arr1[m]);
         r=z(arr1[m],0,0); // ritorna in r i mesi tramite i suoi bit...
         F(y=1;y<13;++y) I(r&(1<<y))P("%s ",mese[y-1]);
         P("\n");
        }

}
</code>```

Title: Superstitious Programming

Body:
C, <s> 276 </s> 219 bytes

#define R return
#define L(i) for(;i-->0;)
u(y,m){R m-1?30+((2773>>m)&1):28+(y%4==0&&y%100||y%400==0);}s(y,m,g){g+=4;L(m)g+=u(y,m),g%=7;L(y)g+=1+u(y,1),g%=7;R g;}z(y,m,r){m=12;L(m)s(y,m,13)-4||(r|=1<<(m+1));R r;}

input from stdin output in stdout try to http://ideone.com/XtuhGj [the debug function is z]

w(y,m,r){m=12;L(m)s(y,m,u(y,m))||(r|=1<<(m+1));R r;}
/*
// ritorna il numero dei giorni di anno=y mese=m con mese in 0..11
// m==1 significa febbraio   y%4?0:y%100?1:!(y%400) non funziona
u(y,m){R m-1?30+((2773>>m)&1):28+(y%4==0&&y%100||y%400==0);}

// argomenti anno:y[0..0xFFFFFFF]  mese:m[0..11]  giorno:g[1..u(y,m)]
// ritorna il numero del giorno[0..6]
s(y,m,g)
{g+=4; // correzione per il giorno di partenza anno mese giorno = 0,1,1
 L(m)g+=  u(y,m),g%=7; // m:0..m-1  somma mod 7 i giorni del mese dell'anno y
 L(y)g+=1+u(y,1),g%=7; // y:0..y-1  somma mod 7 gli anni da 0..y-1
                       // g+=1+u(y,1) poiche' (365-28)%7=1 e 1 e' febbraio
 R g;
}

// argomenti anno:y[0..0xFFFFFFF], m=0 r=0
// calcola tutti gli ultimi giorni del mese dell'anno y che cadono di lunedi'
// e mette tali mesi come bit, dal bit 1 al bit 12 [il bit 0 sempre 0] in r
w(y,m,r){m=12;L(m)s(y,m,u(y,m))||(r|=1<<(m+1));R r;}

// argomenti anno:y[0..0xFFFFFFF], m=0 r=0
//ritorna in r il numero dei mesi che ha giorno 13 di venerdi[==4]
// e mette tali mesi come bit, dal bit 1 al bit 12 [il bit 0 sempre 0] in r
z(y,m,r){m=12;L(m)s(y,m,13)-4||(r|=1<<(m+1));R r;}
*/

#define P printf
#define W while
#define M main
#define F for
#define U unsigned
#define N int
#define B break
#define I if
#define J(a,b)  if(a)goto b
#define G goto
#define P printf
#define D double
#define C unsigned char
#define A getchar()
#define O putchar
#define Y malloc
#define Z free
#define S sizeof
#define T struct
#define E else
#define Q static
#define X continue
M()
{N y,m,g,r,arr[]={1,297,1776,2000,2016,3385}, arr1[]={2016,1,1997,1337,123456789};
 C*mese[]={"gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic"};
 C*giorno[]={"Lun","Mar","Mer","Gio","Ven","Sab","Dom"};
 P("Inserisci Anno mese giorno>");r=scanf("%d %d %d", &y, &m, &g);
 P("Inseriti> %d %d %d r=%d\n", y, m, g, r);
 I(r!=3||m>12||m<=0||g>u(y,m-1))R 0;
 r=s(y,m-1,g);// 12-> 11 -> 0..10
 P("Risultato=%d giorno=%s\n", r, giorno[r]);
 r=w(y,0,0);P(" r=%d ", r);P("\n");
 F(m=0;m<6;++m)
        {P("N anno=%d -->",arr[m]);
         r=w(arr[m],0,0); // ritorna in r i mesi tramite i suoi bit...
         F(y=1;y<13;++y) I(r&(1<<y))P("%s ",mese[y-1]);
         P("\n");
        }
 F(m=0;m<4;++m)
        {P("N anno=%d -->",arr1[m]);
         r=z(arr1[m],0,0); // ritorna in r i mesi tramite i suoi bit...
         F(y=1;y<13;++y) I(r&(1<<y))P("%s ",mese[y-1]);
         P("\n");
        }

}


问:
Print some JSON
This challenge is straightforward, but hopefully, there are plenty of avenues you can approach it:

You need to print/return a valid JSON object of at least 15 characters, not counting unessential whitespace.  Your program should work without any input.

In the interest of clarity, a JSON object starts and ends with curly braces {}, and contains zero or more key:value pairs separated by commas.  The full JSON specification can be found at json.org, and the output of your code must pass this validator.

Therefore, any of the following would not be valid:

```<code>4                               //Too short, not an object
"really, really long string"    //A string, not an object
["an","array","of","values"]    //An array is not a JSON object
{"this":4      }                //You can't count unessential whitespace
{"1":1,"2":3}                   //Too short
{"a really long string"}        //Not valid JSON, it needs a value
{'single-quoted':3}             //JSON requires double-quotes for strings
</code>```

However, the following would be valid:

```<code>{"1":1,"2":2,"3":3,"4":4}       //Long enough
{"whitespace      ":4}          //This whitespace isn't unessential
</code>```

Non-programming languages are allowed on this challenge.  You may return a string from a function, or print it out.  This is a code-golf, so answer it with as little code as possible!

答:
Bash, 18 bytes

echo {\"$PATH\":1}

This works on Mac and Linux, unless your $PATH isn't set.

ContentLicense: CC BY-SA 3.0

Title: Print some JSON


问:
Trick or Treat polyglot
Since Halloween is coming up I thought I might start a fun little code golf challenge!

The challenge is quite simple. You have to write a program that outputs either trick or treat.

"The twist?" you may ask. Well let me explain:

Your program has to do the following:

Be compilable/runnable in two different languages. Different versions of the same language don't count.

When you run the program in one language it should output trick and the other should output treat. The case is irrelevant and padding the string with whitespace characters are allowed (see examples).

This is code-golf,  so the solution with the fewest bytes wins.

A few explanations:

Valid outputs (Just for the words not for running the code in the two languages. Also adding quotes to signalize the beginning or end of the output. Do not include them in your solution!):

```<code>"trick"

"Treat"

"    TReAt"

"
     tRICk          "
</code>```

Invalid outputs:

```<code>"tri ck"

"tr
eat"

"trck"
</code>```

I'm interested to see what you can come up with! Happy Golfing!

I'd like to note that this is my first challenge so if you have suggestions on this question please leave them in the form of a comment.

Leaderboards

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

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

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

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

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

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

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

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

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

var QUESTION_ID=97472,OVERRIDE_USER=23417;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,TAGS_REG = /(<([^>]+)>)/ig;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;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 / C++, 72 bytes

```<code>#include<stdio.h>
main(){char*a[]={"trick","treat"};puts(a[1//**/2
]);}
</code>```

Compile with gcc/g++ -ansi and don't regard warnings. A C90-conforming C compiler does not recognize // as a comment but it skips /**/, leaving puts(a[1/2]);. C++ will see puts(a[1]);.

Title: Trick or Treat polyglot

Body:
C / C++, 72 bytes

#include<stdio.h>
main(){char*a[]={"trick","treat"};puts(a[1//**/2
]);}

Compile with gcc/g++ -ansi and don't regard warnings. A C90-conforming C compiler does not recognize // as a comment but it skips /**/, leaving puts(a[1/2]);. C++ will see puts(a[1]);.


问:
Generate a modulo rosace

The cool stuff

The following rosace can help calculate numbers modulo 7.

In order to do that, you must start at 0 and turn clockwise a number of steps given by the first digit. Then, for each successive digit, follow the arrow and then turn clockwise the number of steps given by that digit.

Here is how you proceed for number 294:

You start at circle 0.

You turn clockwise the number of steps given by the first digit (which is a 2, you end up at 2).

You follow the arrow there (you end up at 6).

You turn clockwise the number of steps given by the second digit (which is a 9, you end up at 1).

You follow the arrow there (you end up at 3).

You turn clockwise the number of steps given by the third number (which is 4, you end up at 0).

294 mod 7 = 0 (meaning 294 is multiple of 7).

(Video explanation if you still didn't get it)

The goal

Figure out how that works (I know but I won't tell you).

Create a program that takes a number n in parameter and that generates a rosace for mod n.

The rosace can be displayed by any means you want (ASCII, generate PNG, generate SVG, ...) as long as it could be used by a 8 years old child (so no list of rules, I want a picture)!

You can use strait lines, even if it's a bit less clear than what I made for the example, but you must show clearly the numbers that point to themselves with some kind of tail-biting arrow.

Test cases

(I only give the links between the numbers, feel free to edit my question once your program sucessfully generates them)

mod 2:

```<code>0 -> 0
1 -> 0
</code>```

mod 3:

```<code>0 -> 0
1 -> 1
2 -> 2
</code>```

mod 4:

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

mod 5:

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

mod 6:

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

mod 7:

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

mod 8:

```<code>0 -> 0
1 -> 2
2 -> 4
3 -> 6
4 -> 0
5 -> 2
6 -> 4
7 -> 6
</code>```

mod 9:

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

mod 10:

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

Rules

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

As usual, loopholes and cheats are forbidden.

答:
Mathematica, <s>124</s> 121 bytes

```<code>Graph[Join@@Thread[{k->Mod[k+1,#],k->Mod[10k,#]}~Table~{k,0,#-1}],VertexLabels->"Name",GraphLayout->"CircularEmbedding"]&
</code>```

Creates a figure as a graph with directed edges. The graph output now follows the same pattern except counter-clockwise. I prefer Greg Martin's solution a lot more since the output is much more aesthetically pleasing.

A less visually pleasant graph can be generated for 82 bytes using

```<code>Graph[Join@@({k->Mod[k+1,#],k->Mod[10k,#]}~Table~{k,0,#-1}),VertexLabels->"Name"]&
</code>```

For d = 8,

Title: Generate a modulo rosace

Body:
Mathematica, <s>124</s> 121 bytes

Graph[Join@@Thread[{k->Mod[k+1,#],k->Mod[10k,#]}~Table~{k,0,#-1}],VertexLabels->"Name",GraphLayout->"CircularEmbedding"]&

Creates a figure as a graph with directed edges. The graph output now follows the same pattern except counter-clockwise. I prefer Greg Martin's solution a lot more since the output is much more aesthetically pleasing.

A less visually pleasant graph can be generated for 82 bytes using

Graph[Join@@({k->Mod[k+1,#],k->Mod[10k,#]}~Table~{k,0,#-1}),VertexLabels->"Name"]&

For d = 8,


问:
Encode the alphabet cipher
Given a string that contains only lowercase letters, encode that string with the alphabet cipher.

To encode with the alphabet cipher (I will be using the example hello):

First, convert each letter in the string to a number depending on its position in the alphabet (a = 1, b = 2, etc.) Example: 8 5 12 12 15

Pad each number to two characters with 0s. Example: 08 05 12 12 15

Join. Example: 0805121215

Test cases

```<code>helloworld -> 08051212152315181204
codegolf -> 0315040507151206
alphabetcipher -> 0112160801020520030916080518
johncena -> 1015081403051401
</code>```

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

ContentLicense: CC BY-SA 4.0

Title: Encode the alphabet cipher

Body:
Labyrinth, 40 bytes

      ,")@
!{_10%! (
/       _
01_}:-69"


问:
Encode the column cipher
Given a string to encode, and a number of columns (the key), encode the string as follows:

I will be using the example Hello, world! and the key 3

First, write out the number of columns:

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

Next, write the text starting from the upper left, one character per column, and when you run out of columns, go to the next line.

```<code>1 2 3
H e l
l o ,
  w o
r l d
!
</code>```

Now, to get your encoded text, read the text starting from the top left corner, but this time, first read one column, and then the next, and so on. If there is not a character in the slot, put a space.

```<code>Hl r!eowl l,od
</code>```

Note that here, there is a trailing space.

This is your encoded text.

Another test case is Programming Puzzles and Code Golf SE with key 5:

```<code>1 2 3 4 5
P r o g r
a m m i n
g   P u z
z l e s
a n d   C
o d e   G
o l f   S
E
</code>```

The encoded text is PagzaooErm lndl omPedef gius    rnz CGS.

More test cases

```<code>"abcdefghijklmnopqrstuvwxyz", 2 -> "acegikmoqsuwybdfhjlnprtvxz"
"codegolf.stackexchange.com", 4 -> "cg.ccgoooskhemdltea. efaxnc "
"Pen Pineapple Apple Pen!!!", 7 -> "PeAeeapnnpp! pl!Ple!ie  n P "
"1,1,2,3,5,8,13,21,34,55,89", 10 -> "18,,,5115,3,2,8,2931 ,, 53 ,4 "
</code>```

Remember, this is code-golf, so the code with the fewest bytes wins.

答:
Python 2, 58 bytes

lambda s,n:`sum(zip(*zip(*n*[iter(s+' '*~-n)])),())`[2::5]
```

Test it on Ideone.

Title: Encode the column cipher

Body:
Python 2, 58 bytes

lambda s,n:`sum(zip(*zip(*n*[iter(s+' '*~-n)])),())`[2::5]

Test it on Ideone.


答:
Bash / Wolfram Language (a.k.a. Mathematica), 19 bytes

```<code>echo trick;#&@treat
</code>```

For Bash, # is a comment indicator so it just outputs trick. Mathematica multiplies two undefined symbols echo and trick but ignores the result and proceeds to the second command, which fully expanded goes

```<code>(Function[Slot[1]])[treat]
</code>```

and evaluates to treat.

Title: Trick or Treat polyglot

Body:
Since Halloween is coming up I thought I might start a fun little code golf challenge!

The challenge is quite simple. You have to write a program that outputs either trick or treat.

"The twist?" you may ask. Well let me explain:

Your program has to do the following:

Be compilable/runnable in two different languages. Different versions of the same language don't count.

When you run the program in one language it should output trick and the other should output treat. The case is irrelevant and padding the string with whitespace characters are allowed (see examples).

This is code-golf,  so the solution with the fewest bytes wins.

A few explanations:

Valid outputs (Just for the words not for running the code in the two languages. Also adding quotes to signalize the beginning or end of the output. Do not include them in your solution!):

```<code>"trick"

"Treat"

"    TReAt"

"
     tRICk          "
</code>```

Invalid outputs:

```<code>"tri ck"

"tr
eat"

"trck"
</code>```

I'm interested to see what you can come up with! Happy Golfing!

I'd like to note that this is my first challenge so if you have suggestions on this question please leave them in the form of a comment.

Leaderboards

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

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

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

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

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

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

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

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

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

var QUESTION_ID=97472,OVERRIDE_USER=23417;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,TAGS_REG = /(<([^>]+)>)/ig;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;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:
Bash / Wolfram Language (a.k.a. Mathematica), 19 bytes

echo trick;#&@treat

For Bash, # is a comment indicator so it just outputs trick. Mathematica multiplies two undefined symbols echo and trick but ignores the result and proceeds to the second command, which fully expanded goes

(Function[Slot[1]])[treat]

and evaluates to treat.


答:
Python 2, 46 bytes

lambda s,n:(s[0]+(s[1:]+-len(s)%n*' ')*n)[::n]
```

<p>The idea is to take the input string, copy it <code>n</code> times with the first character from removed, then takes every <code>n</code>'th character. </p>

<p>Let's look for example at <code>s="abcdef", n=3</code>, where the length is a multiple of <code>n</code>:</p>

```abcdefbcdefbcdef
^  ^  ^  ^  ^  ^
a  d  b  e  c  f
```

The first cycle through the string takes every nth character from the first one. Then, each subsequent cycle shifts one index to the right because the first character is skipped. To ensure that the length is a multiple of n, the initial string is padded with spaces.

Title: Encode the column cipher

Body:
Given a string to encode, and a number of columns (the key), encode the string as follows:

I will be using the example Hello, world! and the key 3

First, write out the number of columns:

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

Next, write the text starting from the upper left, one character per column, and when you run out of columns, go to the next line.

```<code>1 2 3
H e l
l o ,
  w o
r l d
!
</code>```

Now, to get your encoded text, read the text starting from the top left corner, but this time, first read one column, and then the next, and so on. If there is not a character in the slot, put a space.

```<code>Hl r!eowl l,od
</code>```

Note that here, there is a trailing space.

This is your encoded text.

Another test case is Programming Puzzles and Code Golf SE with key 5:

```<code>1 2 3 4 5
P r o g r
a m m i n
g   P u z
z l e s
a n d   C
o d e   G
o l f   S
E
</code>```

The encoded text is PagzaooErm lndl omPedef gius    rnz CGS.

More test cases

```<code>"abcdefghijklmnopqrstuvwxyz", 2 -> "acegikmoqsuwybdfhjlnprtvxz"
"codegolf.stackexchange.com", 4 -> "cg.ccgoooskhemdltea. efaxnc "
"Pen Pineapple Apple Pen!!!", 7 -> "PeAeeapnnpp! pl!Ple!ie  n P "
"1,1,2,3,5,8,13,21,34,55,89", 10 -> "18,,,5115,3,2,8,2931 ,, 53 ,4 "
</code>```

Remember, this is code-golf, so the code with the fewest bytes wins.

Body:
Python 2, 46 bytes

lambda s,n:(s[0]+(s[1:]+-len(s)%n*' ')*n)[::n]

The idea is to take the input string, copy it n times with the first character from removed, then takes every n'th character.

Let's look for example at s="abcdef", n=3, where the length is a multiple of n:

abcdefbcdefbcdef
^  ^  ^  ^  ^  ^
a  d  b  e  c  f

The first cycle through the string takes every nth character from the first one. Then, each subsequent cycle shifts one index to the right because the first character is skipped. To ensure that the length is a multiple of n, the initial string is padded with spaces.


问:
Alphabet to Number and Number to Alphabet

Challenge

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

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

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

Rules

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

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

Trailing whitespaces (space and newline) are allowed.

答:
Racket 58 bytes

```<code>(if(char? i)(-(char->integer i)64)(integer->char(+ 64 i)))
</code>```

Ungolfed:

```<code>(define (f i)
  (if (char? i)
      (-(char->integer i) 64)
      (integer->char (+ 64 i))))
</code>```

Testing:

```<code>(f 1)
(f 3)
(f #\A)
(f #\D)
</code>```

Output:

```<code>#\A
#\C
1
4
</code>```

Body:
Racket 58 bytes

(if(char? i)(-(char->integer i)64)(integer->char(+ 64 i)))

Ungolfed:

(define (f i)
  (if (char? i)
      (-(char->integer i) 64)
      (integer->char (+ 64 i))))

Testing:

(f 1)
(f 3)
(f #\A)
(f #\D)

Output:

#\A
#\C
1
4


答:
C / Javascript, <s>70</s> 47 bytes

(excluding comments C=22 + Javascript=14 ~= 36 )

```<code>/**\
/main(){puts("trick");}
//*/alert("treat")
</code>```

What C sees:

```<code>main(){puts("trick");}
</code>```

What javascript sees:

```<code>alert("treat")
</code>```

Explanation:

```<code>/* C comment ends with '/' on next line but js comment remains open  *\
/ //BEGIN C Block
#define function int
//*/alert("this whole line is commented in C, but // is in the js comment")

//for additional tricks...
/*Most compilers can build K&R style C with parameters like this:*/
function volume(x,y,z)/**\
/int x,y,z;/**/
{
  return x*y*z;
}

/**\
/
#undef function
#define var const char**
#define new (const char*[])
#define Array(...)  {__VA_ARGS__}
/**/

var cars = new Array("Ford", "Chevy", "Dodge");

/* Or a more readable version *\
/// BEGIN C Block
#undef var
#undef new
/* END C Block */
</code>```

Title: Trick or Treat polyglot

Body:
C / Javascript, <s>70</s> 47 bytes

(excluding comments C=22 + Javascript=14 ~= 36 )

/**\
/main(){puts("trick");}
//*/alert("treat")

What C sees:

main(){puts("trick");}

What javascript sees:

alert("treat")

Explanation:

/* C comment ends with '/' on next line but js comment remains open  *\
/ //BEGIN C Block
#define function int
//*/alert("this whole line is commented in C, but // is in the js comment")

//for additional tricks...
/*Most compilers can build K&R style C with parameters like this:*/
function volume(x,y,z)/**\
/int x,y,z;/**/
{
  return x*y*z;
}

/**\
/
#undef function
#define var const char**
#define new (const char*[])
#define Array(...)  {__VA_ARGS__}
/**/

var cars = new Array("Ford", "Chevy", "Dodge");

/* Or a more readable version *\
/// BEGIN C Block
#undef var
#undef new
/* END C Block */


答:
DASH, 33 bytes

```<code>@[="num"type#0?fc +64#0?-(tc#0)64
</code>```

Woo-hoo, first PPCG answer in my new functional programming language!

Installation and other info is all on the Github.

Usage

```<code>(@[="num"type#0?fc +64#0?-(tc#0)64])"A"  #. strings
(@[="num"type#0?fc +64#0?-(tc#0)64])26   #. numbers
</code>```

Explanation

```<code>@                      #. lambda
  [                    #. start of conditional block
    = "num" (type #0)  #. check if argument is a number
      ? fc (+ 64 #0)   #. if so, add 64 to argument and convert from charcode
      ? - (tc #0) 64   #. otherwise, convert argument to charcode and subtract 64
                       #. we can actually leave off the closing bracket for now
</code>```

Title: Alphabet to Number and Number to Alphabet

Body:
Challenge

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

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

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

Rules

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

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

Trailing whitespaces (space and newline) are allowed.

Body:
DASH, 33 bytes

@[="num"type#0?fc +64#0?-(tc#0)64

Woo-hoo, first PPCG answer in my new functional programming language!

Installation and other info is all on the Github.

Usage

(@[="num"type#0?fc +64#0?-(tc#0)64])"A"  #. strings
(@[="num"type#0?fc +64#0?-(tc#0)64])26   #. numbers

Explanation

@                      #. lambda
  [                    #. start of conditional block
    = "num" (type #0)  #. check if argument is a number
      ? fc (+ 64 #0)   #. if so, add 64 to argument and convert from charcode
      ? - (tc #0) 64   #. otherwise, convert argument to charcode and subtract 64
                       #. we can actually leave off the closing bracket for now


答:
Python 2, <s>540</s> <s>464</s> 431 bytes

Some golfing like using shorter variable names, variable substitution, list comprehension and changing everything to white (except the text).
Biggest save was changing precomputed positions to dynamically (see L).

from cv2 import*
from numpy import*
D=1024
G=zeros((D,D,3),uint8)
n=7
w=(1,1,1)
R=range(n)
c=circle
I=int
L=lambda i,r=400:(I(sin(2*pi*i/n)*r+D/2),I(D/2-cos(2*pi*i/n)*r))
for i in R:
 p,q=L(i),L((i*10)%n)
 line(G,p,L((i+1)%n),w,5)
 line(G,p,q,w,5)
 f=lambda z:I(.15*p[z]+.85*q[z])
 c(G,[(f(0),f(1)),L(i,450)][p==q],25,w,-1)
for i in R:
 c(G,L(i),50,w,-1)
 putText(G,`i`,(L(i)[0]-30,L(i)[1]+30),0,2,(0,0,0),2)
imwrite('m.png',G*255)
```

L calculates the positions of the circles by distance to origin for the big ones containing the numbers and the outer small ones that indicate self pointing.

First loop draws the connections: 1st line is the circle around and 2nd line is in the interior, a small circle is added to show direction or self pointing.

Second loop puts big circle and number.

It is obviously not as nice as the Mathematica answers, but everything made from scratch.

Title: Generate a modulo rosace

Body:
The cool stuff

The following rosace can help calculate numbers modulo 7.

In order to do that, you must start at 0 and turn clockwise a number of steps given by the first digit. Then, for each successive digit, follow the arrow and then turn clockwise the number of steps given by that digit.

Here is how you proceed for number 294:

You start at circle 0.

You turn clockwise the number of steps given by the first digit (which is a 2, you end up at 2).

You follow the arrow there (you end up at 6).

You turn clockwise the number of steps given by the second digit (which is a 9, you end up at 1).

You follow the arrow there (you end up at 3).

You turn clockwise the number of steps given by the third number (which is 4, you end up at 0).

294 mod 7 = 0 (meaning 294 is multiple of 7).

(Video explanation if you still didn't get it)

The goal

Figure out how that works (I know but I won't tell you).

Create a program that takes a number n in parameter and that generates a rosace for mod n.

The rosace can be displayed by any means you want (ASCII, generate PNG, generate SVG, ...) as long as it could be used by a 8 years old child (so no list of rules, I want a picture)!

You can use strait lines, even if it's a bit less clear than what I made for the example, but you must show clearly the numbers that point to themselves with some kind of tail-biting arrow.

Test cases

(I only give the links between the numbers, feel free to edit my question once your program sucessfully generates them)

mod 2:

```<code>0 -> 0
1 -> 0
</code>```

mod 3:

```<code>0 -> 0
1 -> 1
2 -> 2
</code>```

mod 4:

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

mod 5:

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

mod 6:

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

mod 7:

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

mod 8:

```<code>0 -> 0
1 -> 2
2 -> 4
3 -> 6
4 -> 0
5 -> 2
6 -> 4
7 -> 6
</code>```

mod 9:

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

mod 10:

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

Rules

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

As usual, loopholes and cheats are forbidden.

Body:
Python 2, <s>540</s> <s>464</s> 431 bytes

Some golfing like using shorter variable names, variable substitution, list comprehension and changing everything to white (except the text).
Biggest save was changing precomputed positions to dynamically (see L).

from cv2 import*
from numpy import*
D=1024
G=zeros((D,D,3),uint8)
n=7
w=(1,1,1)
R=range(n)
c=circle
I=int
L=lambda i,r=400:(I(sin(2*pi*i/n)*r+D/2),I(D/2-cos(2*pi*i/n)*r))
for i in R:
 p,q=L(i),L((i*10)%n)
 line(G,p,L((i+1)%n),w,5)
 line(G,p,q,w,5)
 f=lambda z:I(.15*p[z]+.85*q[z])
 c(G,[(f(0),f(1)),L(i,450)][p==q],25,w,-1)
for i in R:
 c(G,L(i),50,w,-1)
 putText(G,`i`,(L(i)[0]-30,L(i)[1]+30),0,2,(0,0,0),2)
imwrite('m.png',G*255)

L calculates the positions of the circles by distance to origin for the big ones containing the numbers and the outer small ones that indicate self pointing.

First loop draws the connections: 1st line is the circle around and 2nd line is in the interior, a small circle is added to show direction or self pointing.

Second loop puts big circle and number.

It is obviously not as nice as the Mathematica answers, but everything made from scratch.


问:
The Rule of Thumb for Title Capitalization
According to this site a general rule recommended by The U.S. Government Printing Office Style Manual is

Capitalize all words in titles of publications and documents, except
  a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and
  nor.

This might not be true as I'm unable to find such a recommendation in the Style Manual, but let's use this rule anyway.

The Challenge

Given an input string consisting of lower case words delimited by spaces, output the capitalization of the string according to the following rules

The first and last word is capitalized.

All other words are capitalized, except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.

The input string will contain at least one word and each word contains at least one letter and only characters from a to z.

This is a code golf challenge, so try to use as few bytes as possible in the language of your choice. You may write a full program or a function to accomplish the task.

Testcases

```<code>"the rule of thumb for title capitalization" -> "The Rule of Thumb for Title Capitalization"
"programming puzzles and code golf" -> "Programming Puzzles and Code Golf"
"the many uses of the letter a" -> "The Many Uses of the Letter A"
"title" -> "Title"
"and and and" -> "And and And"
"a an and as at but by for in nor of on or the to up" -> "A an and as at but by for in nor of on or the to Up"
"on computable numbers with an application to the entscheidungsproblem" -> "On Computable Numbers With an Application to the Entscheidungsproblem"
</code>```

答:
Python, 177 bytes

Delivered in function format for byte saving purposes. This is not an especially competitive answer, but it is one that doesn't require repr() or regex trickery. It is also version-agnostic; it works with Python 2 or 3.

Though it is perhaps a very by-the-rules solution.

```<code>def t(s):
 w="a an the the at by for in of on to up and as but or nor".split()
 l=[(s.title(),s)[s in w]for s in s.split()]
 for x in(0,-1):l[x]=l[x].title()
 return' '.join(l)
</code>```

Body:
Python, 177 bytes

Delivered in function format for byte saving purposes. This is not an especially competitive answer, but it is one that doesn't require repr() or regex trickery. It is also version-agnostic; it works with Python 2 or 3.

Though it is perhaps a very by-the-rules solution.

def t(s):
 w="a an the the at by for in of on to up and as but or nor".split()
 l=[(s.title(),s)[s in w]for s in s.split()]
 for x in(0,-1):l[x]=l[x].title()
 return' '.join(l)


答:
Actually, 12 bytes

Golfing suggestions welcome, especially if you can figure out a golfier way to pad spaces. Try it online!

```<code>;' *(q╪dX┬ΣΣ
</code>```

Ungolfing

```<code>      Implicit input s, then n.
;     Duplicate n. Stack: n, n, s
' *   Push n spaces.
(q    Rotate s to TOS and append the spaces to the end of s.
╪     Split s into n-length substrings.
dX    Dequeue and discard any extra spaces that remain after chunking.
      This works even when we didn't need to add spaces in the first place.
┬     Transpose the remaining substrings. This returns a list of lists of chars.
Σ     Sum the transposed substrings into one list of chars.
Σ     Sum the list of chars into one string.
      Implicit return.
</code>```

Another 12-byte version

In this version, the order of the inputs is reversed, but this can be changed if that isn't allowed. Golfing suggestions welcome. Try it online!

```<code>│l±%' *o╪┬ΣΣ
</code>```

Ungolfing

```<code>      Implicit input n first, then s.
│     Duplicate stack. Stack: s, n, s, n
l±    Push -len(s).
%     Push -len(s)%n, which gets the number of spaces we need to pad with. Call this m.
' *   Push m spaces to the stack.
o     Append the spaces to the end of s.
╪     Split s into n-length substrings.
┬     Transpose these substrings. This returns a list of lists of chars.
Σ     Sum the transposed substrings into one list of chars.
Σ     Sum the list of chars into one string.
      Implicit return.
</code>```

Title: Encode the column cipher

Body:
Actually, 12 bytes

Golfing suggestions welcome, especially if you can figure out a golfier way to pad spaces. Try it online!

;' *(q╪dX┬ΣΣ

Ungolfing

      Implicit input s, then n.
;     Duplicate n. Stack: n, n, s
' *   Push n spaces.
(q    Rotate s to TOS and append the spaces to the end of s.
╪     Split s into n-length substrings.
dX    Dequeue and discard any extra spaces that remain after chunking.
      This works even when we didn't need to add spaces in the first place.
┬     Transpose the remaining substrings. This returns a list of lists of chars.
Σ     Sum the transposed substrings into one list of chars.
Σ     Sum the list of chars into one string.
      Implicit return.

Another 12-byte version

In this version, the order of the inputs is reversed, but this can be changed if that isn't allowed. Golfing suggestions welcome. Try it online!

│l±%' *o╪┬ΣΣ

Ungolfing

      Implicit input n first, then s.
│     Duplicate stack. Stack: s, n, s, n
l±    Push -len(s).
%     Push -len(s)%n, which gets the number of spaces we need to pad with. Call this m.
' *   Push m spaces to the stack.
o     Append the spaces to the end of s.
╪     Split s into n-length substrings.
┬     Transpose these substrings. This returns a list of lists of chars.
Σ     Sum the transposed substrings into one list of chars.
Σ     Sum the list of chars into one string.
      Implicit return.


问:
The Switching Sequence

Intro

The Switching sequence is defined like so:

Start with n people standing in a circle (6 for this example).

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

Starting from person 1, the person that is to the left of the "chosen" person is removed.

```<code> 1
6    3
 5  4
</code>```

The removed person can "switch" the removal method up:

If the removed person is even (which it is in this case), the next removed person will be to the right of the next "chosen" person.

If the removed person is odd, the next removed person will be to the left of the next "chosen" person.

The next chosen person is also dependent on the previously removed person.

If the removed person is even, the next chosen person will be to the right of the previous chosen person.

If the removed person is odd, see above, but replace "right" with "left".

So the next chosen person is then 6.

Now we remove the person to the right of 6, which is 5:

```<code> 1
6    3
    4
</code>```

Because 5 is odd, the removed person is now to the left. The new chosen person is 1.

We now remove 3:

```<code> 1
6
    4
</code>```

We continue this process, until we're left with 1 number - in this example, the final number is 1. So therefore S(6) = 1.

The first few numbers are:

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

Task

Your task is to make a program (or a function) that returns S(n) (the nth number in the Switching sequence) when given n, using the least amount of bytes.

Example inputs and outputs:

```<code>1  -> 1
10 -> 6
13 -> 13
</code>```

You are guaranteed to get a positive integer.

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

Note: There is no OEIS sequence (what?), to save you the trouble of searching.

答:
Python 2, <s>183</s> 94 bytes

-4 bytes thanks to Artyer (use input() and print rather than def and return)

-1 byte thanks to FlipTack (use print-~p[0] rather than print p[0]+1)

p=range(input())
d=i=1
while p[1:]:m=p.pop(i)%2;i-=m+m-(d<0);d=-m|1;i+=d;i%=len(p)
print-~p[0]
```

<p><strong>repl.it</strong></p>

<p>This just follows the instructions given, I've noticed some pattern, maybe it could be exploited?</p>

<p>The only changes are:</p>

<ul>
<li>to use <code>0</code> based indexing (so even people are odd and vice-versa) - this is saves 5 bytes in the golfed logic and is corrected at the end with <code>+1</code></li>
<li>to use <code>1</code> as left and <code>-1</code> as right (to use a range - just like everyone is facing outwards instead)</li>
<li>to change the logic of the step where the next chosen individual is found to account for <code>pop</code>ing from the list making the "pointer" index already step one to the right in the list (or to the left in original terminology). </li>
</ul>

<p>Ungolfed:</p>

<pre class="lang-python prettyprint-override"><code>def circle(n):
    people = range(n) # p
    direction = 1 # d
    removeIndex = 1 # i
    while n > 1:
        removingMod2 = people.pop(removeIndex) % 2 # m
        removeIndex -= removingMod2 + removingMod2 - (direction == -1)
        direction = -removingMod2 or 1
        removeIndex += direction
        n -= 1
        removeIndex %= n
    return people[0] + 1
</code>```

Title: The Switching Sequence

Body:
Python 2, <s>183</s> 94 bytes

-4 bytes thanks to Artyer (use input() and print rather than def and return)

-1 byte thanks to FlipTack (use print-~p[0] rather than print p[0]+1)

p=range(input())
d=i=1
while p[1:]:m=p.pop(i)%2;i-=m+m-(d<0);d=-m|1;i+=d;i%=len(p)
print-~p[0]

repl.it

This just follows the instructions given, I've noticed some pattern, maybe it could be exploited?

The only changes are:

to use 0 based indexing (so even people are odd and vice-versa) - this is saves 5 bytes in the golfed logic and is corrected at the end with +1

to use 1 as left and -1 as right (to use a range - just like everyone is facing outwards instead)

to change the logic of the step where the next chosen individual is found to account for poping from the list making the "pointer" index already step one to the right in the list (or to the left in original terminology).

Ungolfed:

def circle(n):
    people = range(n) # p
    direction = 1 # d
    removeIndex = 1 # i
    while n > 1:
        removingMod2 = people.pop(removeIndex) % 2 # m
        removeIndex -= removingMod2 + removingMod2 - (direction == -1)
        direction = -removingMod2 or 1
        removeIndex += direction
        n -= 1
        removeIndex %= n
    return people[0] + 1


问:
Draw an hourglass
Again inspired by a task for Programming 101 here's another challenge.

Input:

A positive integer n >= 3. (has to be odd)

Output:

n lines of asterisks, where the first line has n asterisks and every new line has two asterisks less than the line before. Until hitting 1 asterisk. From there every new line has two asterisks more than the line before until getting back to n asterisks. Spaces or something like spaces have to used to align the asterisks so that it really will look like an hourglass.

General rules:

Trailing newlines are allowed but do not have to be used.

indentation is a must.

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

Since the course is taught in C++, I'm eager to see solutions in C++.

Test case (n=5):

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

Title: Draw an hourglass

Body:
Racket 177 bytes

(let p((n N)(d #t))(for((i(/(- N n)2)))(display" "))(for((i n))(display #\*))(displayln"")
(cond[(and(not d)(= n N))][(= n 1)(set! d #f)(p(+ 2 n)d)][d(p(- n 2)d)][(p(+ 2 n)d)]))

Ungolfed:

(define (f N)
  (let loop ((n N)
             (d #t))                      ; descending
    (for ((i (/(- N n)2)))
          (display " "))
    (for ((i n))
      (display #\*))
    (displayln "")
    (cond
      [(and (not d) (= n N))]             ; end
      [(= n 1) (set! d #f)
               (loop (+ 2 n) d)]
      [d (loop (- n 2) d)]
      [(loop (+ 2 n) d)]))
  )

Testing:

(f 9)

Output:

*********
 *******
  *****
   ***
    *
   ***
  *****
 *******
*********
#t


答:
Pyke, 10 bytes

```<code>k=.,Rc.,ss
</code>```

Try it here!

Title: Encode the column cipher

Body:
Pyke, 10 bytes

k=.,Rc.,ss

Try it here!


答:
Pyke, 7 bytes

```<code>F.oOO`t
</code>```

Try it here!

```<code>F       -  for i in input:
 .o     -       ord(i)
   OO   -      ^ + 4
     `  -     str(^)
      t -    ^[1:]
        - sum(^)
</code>```

Title: Encode the alphabet cipher

Body:
Given a string that contains only lowercase letters, encode that string with the alphabet cipher.

To encode with the alphabet cipher (I will be using the example hello):

First, convert each letter in the string to a number depending on its position in the alphabet (a = 1, b = 2, etc.) Example: 8 5 12 12 15

Pad each number to two characters with 0s. Example: 08 05 12 12 15

Join. Example: 0805121215

Test cases

```<code>helloworld -> 08051212152315181204
codegolf -> 0315040507151206
alphabetcipher -> 0112160801020520030916080518
johncena -> 1015081403051401
</code>```

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

Body:
Pyke, 7 bytes

F.oOO`t

Try it here!

F       -  for i in input:
 .o     -       ord(i)
   OO   -      ^ + 4
     `  -     str(^)
      t -    ^[1:]
        - sum(^)


问:
Alphabet Pattern Matching
We've had a lot of alphabet challenges.  For this challenge, you are passed the output of an alphabet challenge, and you need to output the pattern scaled to size N.

For example, if N=5 and you were passed the L-phabet:

```<code>ABCDEFGHIJKLMNOPQRSTUVWXYZ
BBCDEFGHIJKLMNOPQRSTUVWXYZ
CCCDEFGHIJKLMNOPQRSTUVWXYZ
DDDDEFGHIJKLMNOPQRSTUVWXYZ
EEEEEFGHIJKLMNOPQRSTUVWXYZ
FFFFFFGHIJKLMNOPQRSTUVWXYZ
GGGGGGGHIJKLMNOPQRSTUVWXYZ
HHHHHHHHIJKLMNOPQRSTUVWXYZ
IIIIIIIIIJKLMNOPQRSTUVWXYZ
JJJJJJJJJJKLMNOPQRSTUVWXYZ
KKKKKKKKKKKLMNOPQRSTUVWXYZ
LLLLLLLLLLLLMNOPQRSTUVWXYZ
MMMMMMMMMMMMMNOPQRSTUVWXYZ
NNNNNNNNNNNNNNOPQRSTUVWXYZ
OOOOOOOOOOOOOOOPQRSTUVWXYZ
PPPPPPPPPPPPPPPPQRSTUVWXYZ
QQQQQQQQQQQQQQQQQRSTUVWXYZ
RRRRRRRRRRRRRRRRRRSTUVWXYZ
SSSSSSSSSSSSSSSSSSSTUVWXYZ
TTTTTTTTTTTTTTTTTTTTUVWXYZ
UUUUUUUUUUUUUUUUUUUUUVWXYZ
VVVVVVVVVVVVVVVVVVVVVVWXYZ
WWWWWWWWWWWWWWWWWWWWWWWXYZ
XXXXXXXXXXXXXXXXXXXXXXXXYZ
YYYYYYYYYYYYYYYYYYYYYYYYYZ
ZZZZZZZZZZZZZZZZZZZZZZZZZZ
</code>```

You would need to output:

```<code>ABCDE
BBCDE
CCCDE
DDDDE
EEEEE
</code>```

For the purposes of explanation, I'll be using only ABCD, instead of the full alphabet.  You need to be able to match the L-phabet (above), as well as the following patterns:

The single line:

```<code>ABCD    or     A
               B
               C
               D
</code>```

The single line repeated N times

```<code>ABCD    or    AAAA
ABCD          BBBB
ABCD          CCCC
ABCD          DDDD
</code>```

The Tabula Recta:

```<code>ABCD
BCDA
CDAB
DABC
</code>```

This alphabet triangle:

```<code>A      or   AAAAAAA
AB           BBBBB
ABC           CCC
ABCD           D
ABC
AB
A
</code>```

We also have half triangles in lots of varieties:

```<code>A           AAAA      A        ABCD
BB          BBB       AB       ABC
CCC         CC        ABC      AB
DDDD        D         ABCD     A
</code>```

Finally, the square:

```<code>AAAAAAA
ABBBBBA
ABCCCBA
ABCDCBA
ABCCCBA
ABBBBBA
AAAAAAA
</code>```

All of the above patterns are of size 4.  However, you will be passed a pattern of size 26, as well as an N between 1 and 26, and you need to scale the pattern.  You do not need to handle any other patterns.

The output for 1 will always be the single character A

The output for 26 will always be the same, full-sized pattern passed in.

Trailing spaces are allowed at the end of each line, as well as a trailing newline at the end

You can find all patterns of size 26 here

This is a code-golf, so do it in as few bytes as possible!

答:
R, 483 412 bytes

```<code>    x=function(n){d=1:n;a=LETTERS[d];z=rep;f=function(...)cat(...,"\n",sep="");g=c(d,n:2-1);for(i in d)f(a[z(i,i)],if(i!=n)a[(i+1):n]);f(a);for(i in d)f(a[i]);for(i in d)f(a);for(i in d)f(z(a[i],n));for(i in d)f(a[i:n],if(i>1)a[1:i-1]);for(i in g)f(a[1:i]);for(i in d)f(z(" ",i-1),z(a[i],2*(n-i)+1));for(i in d)f(z(a[i],i));for(i in d)f(z(a[i],n-i+1));for(i in g)f(if(i>1)a[2:i-1],z(a[i],2*(n-i)+1),if(i>1)a[i:2-1])}
</code>```

This is my first time posting, I was told I didn't have a recent years experience of R, so just practise a little bit here.

Expanded

```<code>    x=function(n){
    # array of 1 to n
    d=1:n
    # first n capital letters
    a=LETTERS[d]
    # use z to represent the repeat function
    z=rep
    # use f to represent concatenate, with new line and close the gap
    f=function(...)cat(...,"\n",sep="");
    # use g to represent 1 to n then n to 1
    g=c(d,n:2-1)

    # L-phabet
    # start and repeat the first letter to i, combine the i+1 to the end
    for(i in d) f(a[z(i,i)],if(i!=n)a[(i+1):n])

    # single line - horizontal
    f(a)

    # single line - vertical
    for(i in d)f(a[i])

    # single line - repeated by row
    for(i in d)f(a)

    # single line - repeated by column
    for(i in d)f(z(a[i],n))

    # Tabula Recta
    # start from i, combine the 1 to i-1
    for(i in d) f(a[i:n],if(i>1)a[2:i-1])

    # alphabet triangle
    for(i in g)f(a[1:i])

    # alphabet triangle - upside down
    for(i in d)f(z(" ",i-1),z(a[i],2*(n-i)+1))

    # half triangles
    for(i in d)f(z(a[i],i))
    for(i in d)f(z(a[i],n-i+1))

    # the square
    # combine the first part from i to i-1 letters, repeat the i in the middle, combine the last part from i-1 to 1 letters
    for(i in g) f(if(i>1)a[2:i-1],z(a[i],2*(n-i)+1),if(i>1)a[i:2-1])
    }
</code>```

Title: Alphabet Pattern Matching

Body:
R, 483 412 bytes

    x=function(n){d=1:n;a=LETTERS[d];z=rep;f=function(...)cat(...,"\n",sep="");g=c(d,n:2-1);for(i in d)f(a[z(i,i)],if(i!=n)a[(i+1):n]);f(a);for(i in d)f(a[i]);for(i in d)f(a);for(i in d)f(z(a[i],n));for(i in d)f(a[i:n],if(i>1)a[1:i-1]);for(i in g)f(a[1:i]);for(i in d)f(z(" ",i-1),z(a[i],2*(n-i)+1));for(i in d)f(z(a[i],i));for(i in d)f(z(a[i],n-i+1));for(i in g)f(if(i>1)a[2:i-1],z(a[i],2*(n-i)+1),if(i>1)a[i:2-1])}

This is my first time posting, I was told I didn't have a recent years experience of R, so just practise a little bit here.

Expanded

    x=function(n){
    # array of 1 to n
    d=1:n
    # first n capital letters
    a=LETTERS[d]
    # use z to represent the repeat function
    z=rep
    # use f to represent concatenate, with new line and close the gap
    f=function(...)cat(...,"\n",sep="");
    # use g to represent 1 to n then n to 1
    g=c(d,n:2-1)

    # L-phabet
    # start and repeat the first letter to i, combine the i+1 to the end
    for(i in d) f(a[z(i,i)],if(i!=n)a[(i+1):n])

    # single line - horizontal
    f(a)

    # single line - vertical
    for(i in d)f(a[i])

    # single line - repeated by row
    for(i in d)f(a)

    # single line - repeated by column
    for(i in d)f(z(a[i],n))

    # Tabula Recta
    # start from i, combine the 1 to i-1
    for(i in d) f(a[i:n],if(i>1)a[2:i-1])

    # alphabet triangle
    for(i in g)f(a[1:i])

    # alphabet triangle - upside down
    for(i in d)f(z(" ",i-1),z(a[i],2*(n-i)+1))

    # half triangles
    for(i in d)f(z(a[i],i))
    for(i in d)f(z(a[i],n-i+1))

    # the square
    # combine the first part from i to i-1 letters, repeat the i in the middle, combine the last part from i-1 to 1 letters
    for(i in g) f(if(i>1)a[2:i-1],z(a[i],2*(n-i)+1),if(i>1)a[i:2-1])
    }


问:
Draw an alphabet party hat
Your task is to print this exact text:

```<code>            z
            yz
           xyz
           wxyz
          vwxyz
          uvwxyz
         tuvwxyz
         stuvwxyz
        rstuvwxyz
        qrstuvwxyz
       pqrstuvwxyz
       opqrstuvwxyz
      nopqrstuvwxyz
      mnopqrstuvwxyz
     lmnopqrstuvwxyz
     klmnopqrstuvwxyz
    jklmnopqrstuvwxyz
    ijklmnopqrstuvwxyz
   hijklmnopqrstuvwxyz
   ghijklmnopqrstuvwxyz
  fghijklmnopqrstuvwxyz
  efghijklmnopqrstuvwxyz
 defghijklmnopqrstuvwxyz
 cdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
</code>```

Case does not matter.

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

答:
Racket 137 bytes

```<code>(for((n(range 122 96 -1)))(for((i(floor(/(- n 97)2))))(display #\space))
(for((i(range n 123)))(display(integer->char i)))(displayln ""))
</code>```

Ungolfed:

```<code>(define (f)
  (for ((n (range 122 96 -1)))
       (for ((i (floor(/(- n 97)2))))
         (display #\space))
       (for ((i (range n 123)))
         (display (integer->char i)))
    (displayln "")))
</code>```

Testing:

```<code>(f)
</code>```

Output:

```<code>            z
            yz
           xyz
           wxyz
          vwxyz
          uvwxyz
         tuvwxyz
         stuvwxyz
        rstuvwxyz
        qrstuvwxyz
       pqrstuvwxyz
       opqrstuvwxyz
      nopqrstuvwxyz
      mnopqrstuvwxyz
     lmnopqrstuvwxyz
     klmnopqrstuvwxyz
    jklmnopqrstuvwxyz
    ijklmnopqrstuvwxyz
   hijklmnopqrstuvwxyz
   ghijklmnopqrstuvwxyz
  fghijklmnopqrstuvwxyz
  efghijklmnopqrstuvwxyz
 defghijklmnopqrstuvwxyz
 cdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
</code>```

Title: Draw an alphabet party hat

Body:
Racket 137 bytes

(for((n(range 122 96 -1)))(for((i(floor(/(- n 97)2))))(display #\space))
(for((i(range n 123)))(display(integer->char i)))(displayln ""))

Ungolfed:

(define (f)
  (for ((n (range 122 96 -1)))
       (for ((i (floor(/(- n 97)2))))
         (display #\space))
       (for ((i (range n 123)))
         (display (integer->char i)))
    (displayln "")))

Testing:

(f)

Output:

            z
            yz
           xyz
           wxyz
          vwxyz
          uvwxyz
         tuvwxyz
         stuvwxyz
        rstuvwxyz
        qrstuvwxyz
       pqrstuvwxyz
       opqrstuvwxyz
      nopqrstuvwxyz
      mnopqrstuvwxyz
     lmnopqrstuvwxyz
     klmnopqrstuvwxyz
    jklmnopqrstuvwxyz
    ijklmnopqrstuvwxyz
   hijklmnopqrstuvwxyz
   ghijklmnopqrstuvwxyz
  fghijklmnopqrstuvwxyz
  efghijklmnopqrstuvwxyz
 defghijklmnopqrstuvwxyz
 cdefghijklmnopqrstuvwxyz
bcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz


问:
Find the Wavy Words!
(Note: this is an easier spin-off of my previous challenge Find the Infinity Words!, which is a spin-off of my other previous challenge Find the Swirling Words! :) )

Definition of a Wavy Word:

If you connect with curves all the characters of a Wavy Word on the alphabet (A-Z) you obtain the path of a wave continuously going toward right or toward left and never changing direction, like in the diagrams below.

A Wavy Word can be:

Raising if each consecutive character is at the right (on the alphabet) of the previous one.

Decreasing if each consecutive character is at the left (on the alphabet) of the previous one.

All the even connection must be down, all the odd connections must be up.

You can ignore upper/lowercase or consider/convert all to upper case or all to lower case.

The input words are only characters in the alphabet range of A-Z, no spaces, no punctuation, or symbols.

If a word has double characters, like "SPOON", you must collapse the doubles to one character: "SPOON" > "SPON" (because if you go from O to O is zero distance).

The Wavy Words will contain at least 3 distinct characters (even after doubles collapsing).

Here there are some examples:

Task:

Write a full program or function that will take a word from standard input and will output if it is a Wavy Word or not, and in positive case, output if it is raising or decreasing. The output can be True/False/Null, 2/1/0, 1/Null/0, -1/0/1, NO/WR/WD, etc, you decide how to represent it.

Test cases:

```<code>WAVY WORDS:
  ADEPT, BEGIN, BILL, BOSS, BOOST, CHIMP,
  KNOW, SPONGE, SPOON, TROLL, WOLF

ADEPT  > YES > RAISING
BEGIN  > YES > RAISING
BILL   > YES > RAISING
BOSS   > YES > RAISING
BOOST  > YES > RAISING
CHIMP  > YES > RAISING
KNOW   > YES > RAISING
SPONGE > YES > DECREASING
SPOON  > YES > DECREASING
TROLL  > YES > DECREASING
WOLF   > YES > DECREASING

NOT WAVY WORDS:
  WATCH, EARTH, NINON, FOO, BAR, WAVE, SELECTION,
  YES, NO, DEFINITION, WATER, WINE, CODE, AAAHHHH, I, MM, ABCA
</code>```

Rules:

Shortest code wins.

Optional Task:

Find, as a list, as many Wavy Words as you can in an English dictionary, and the longest as well. You can take for example as reference the complete list of English words here.

答:
C, 164 bytes

```<code>main(){char s[99];scanf("%s",s);char *c=&s;int p=*c;while(*c^0){if(p>*c){if(c-&s[0]>1)return 0;while(*c^0){if(p<*c)return 0;p=*c;c++;}return 2;}p=*c;c++;}return 1;}
</code>```

Returns 0 if not wawy, 1 if wawy and raising, 2 if decreasing.

Title: Find the Wavy Words!

Body:
C, 164 bytes

main(){char s[99];scanf("%s",s);char *c=&s;int p=*c;while(*c^0){if(p>*c){if(c-&s[0]>1)return 0;while(*c^0){if(p<*c)return 0;p=*c;c++;}return 2;}p=*c;c++;}return 1;}

Returns 0 if not wawy, 1 if wawy and raising, 2 if decreasing.


答:
PHP, 100 bytes

```<code>$n=$m=$l=str_split($argv[1]);sort($n);rsort($m);echo(($n==$l)-($m==$l))*(count(array_unique($l))>2);
</code>```

Returns:

-1 for wavy, decreasing.

0 for not wavy.

1 for wavy, raising.

Title: Find the Wavy Words!

Body:
(Note: this is an easier spin-off of my previous challenge Find the Infinity Words!, which is a spin-off of my other previous challenge Find the Swirling Words! :) )

Definition of a Wavy Word:

If you connect with curves all the characters of a Wavy Word on the alphabet (A-Z) you obtain the path of a wave continuously going toward right or toward left and never changing direction, like in the diagrams below.

A Wavy Word can be:

Raising if each consecutive character is at the right (on the alphabet) of the previous one.

Decreasing if each consecutive character is at the left (on the alphabet) of the previous one.

All the even connection must be down, all the odd connections must be up.

You can ignore upper/lowercase or consider/convert all to upper case or all to lower case.

The input words are only characters in the alphabet range of A-Z, no spaces, no punctuation, or symbols.

If a word has double characters, like "SPOON", you must collapse the doubles to one character: "SPOON" > "SPON" (because if you go from O to O is zero distance).

The Wavy Words will contain at least 3 distinct characters (even after doubles collapsing).

Here there are some examples:

Task:

Write a full program or function that will take a word from standard input and will output if it is a Wavy Word or not, and in positive case, output if it is raising or decreasing. The output can be True/False/Null, 2/1/0, 1/Null/0, -1/0/1, NO/WR/WD, etc, you decide how to represent it.

Test cases:

```<code>WAVY WORDS:
  ADEPT, BEGIN, BILL, BOSS, BOOST, CHIMP,
  KNOW, SPONGE, SPOON, TROLL, WOLF

ADEPT  > YES > RAISING
BEGIN  > YES > RAISING
BILL   > YES > RAISING
BOSS   > YES > RAISING
BOOST  > YES > RAISING
CHIMP  > YES > RAISING
KNOW   > YES > RAISING
SPONGE > YES > DECREASING
SPOON  > YES > DECREASING
TROLL  > YES > DECREASING
WOLF   > YES > DECREASING

NOT WAVY WORDS:
  WATCH, EARTH, NINON, FOO, BAR, WAVE, SELECTION,
  YES, NO, DEFINITION, WATER, WINE, CODE, AAAHHHH, I, MM, ABCA
</code>```

Rules:

Shortest code wins.

Optional Task:

Find, as a list, as many Wavy Words as you can in an English dictionary, and the longest as well. You can take for example as reference the complete list of English words here.

Body:
PHP, 100 bytes

$n=$m=$l=str_split($argv[1]);sort($n);rsort($m);echo(($n==$l)-($m==$l))*(count(array_unique($l))>2);

Returns:

-1 for wavy, decreasing.

0 for not wavy.

1 for wavy, raising.


答:
Groovy - 31 bytes

Groovy conversion of NumberKnot's solution in java:

```{it.each{printf("%02d",it-96)}}```

Example here using various options:

http://ideone.com/vd0dTX

Title: Encode the alphabet cipher

Body:
Groovy - 31 bytes

Groovy conversion of NumberKnot's solution in java:

{it.each{printf("%02d",it-96)}}

Example here using various options:

http://ideone.com/vd0dTX


Title: Encode the alphabet cipher

Body:
Befunge-98, 19 bytes

#@~'`-:a/'0+,a%'0+,


答:
Python 2 + graphviz, 147 bytes

```<code>from graphviz import*
d=Digraph()
k=input()
p=d.edge
for j in[d.node(`i`,`i`)or i for i in range(k)]:
 p(`j`,`-~j%k`);p(`j`,`10*j%k`)
d.render("o")
</code>```

Doesn't always draw a circle, outputs a pdf file called o

Title: Generate a modulo rosace

Body:
Python 2 + graphviz, 147 bytes

from graphviz import*
d=Digraph()
k=input()
p=d.edge
for j in[d.node(`i`,`i`)or i for i in range(k)]:
 p(`j`,`-~j%k`);p(`j`,`10*j%k`)
d.render("o")

Doesn't always draw a circle, outputs a pdf file called o


问:
Pythagorean Triple Sequence

A Pythagorean triple consists of three positive integers a, b, and c, such that a2 + b2 = c2. Such a triple is commonly written (a, b, c), and a well-known example is (3, 4, 5). If (a, b, c) is a Pythagorean triple, then so is (ka, kb, kc) for any positive integer k. A primitive Pythagorean triple is one in which a, b and c are coprime.

Using this knowledge, we can create a sequence by chaining together the least lengths of triples, where the next element in the sequence is the hypotenuse (largest number) of the smallest primitive Pythagorean triple containing the previous element as the smallest one of its lengths.

Start with the smallest primitive Pythagorean triple (3, 4, 5). The sequence begins with 3, and the hypotenuse (next element in the sequence) is 5. Then find the smallest primitive Pythagorean triple with 5 as a leg, and you get (5, 12, 13). So the sequence continues with 13.

Either output the sequence forever, or take an integer input n and output the first n elements of the sequence, either zero or one indexed.

You need to support output at least through and including 28455997, but if the limit of the data type you are using was suddenly raised, it would need to work for that new limit. So you cannot hard code a list of numbers.

```<code>3
5
13
85
157
12325
90733
2449525
28455997
295742792965
171480834409967437
656310093705697045
1616599508725767821225590944157
4461691012090851100342993272805
115366949386695884000892071602798585632943213
12002377162350258332845595301471273220420939451301220405
</code>```

OEIS A239381

Similar sequences (don't output these!):

A018928

A077034 (the odd terms)

答:
PHP, 139 bytes

```<code>for($k=3;$i=$k,print("$k\n");)for($j=$i+1;($k=sqrt($m=$i*$i+$j*$j))>(int)$k||gmp_intval(gmp_gcd(gmp_gcd((int)$i,(int)$j),(int)$k))>1;$j++);
</code>```

The above code breaks after 28455997 on 32-bit systems. If higher numbers are needed, it becomes 156 bytes:

```<code>for($k=3;$i=$k,print("$k\n");)for($j=$i+1;!gmp_perfect_square($m=bcadd(bcpow($i,2),bcpow($j,2)))||gmp_intval(gmp_gcd(gmp_gcd($i,$j),$k=bcsqrt($m)))>1;$j++);
</code>```

Title: Pythagorean Triple Sequence

Body:
PHP, 139 bytes

for($k=3;$i=$k,print("$k\n");)for($j=$i+1;($k=sqrt($m=$i*$i+$j*$j))>(int)$k||gmp_intval(gmp_gcd(gmp_gcd((int)$i,(int)$j),(int)$k))>1;$j++);

The above code breaks after 28455997 on 32-bit systems. If higher numbers are needed, it becomes 156 bytes:

for($k=3;$i=$k,print("$k\n");)for($j=$i+1;!gmp_perfect_square($m=bcadd(bcpow($i,2),bcpow($j,2)))||gmp_intval(gmp_gcd(gmp_gcd($i,$j),$k=bcsqrt($m)))>1;$j++);


问:
What is the smallest positive base 10 integer that can be printed by a program shorter (in characters) than itself?
I think the question as above is clear, but just in case:

Write a full program (not just a function) which prints a positive base 10 integer, optionally followed by a single newline.

Qualifying programs will be those whose output is longer (in bytes) than the source code of the program, measured in bytes (assuming ASCII or UTF-8 encoding for the program source code).

I.e. the code must be shorter than the number of digits in the resulting number.

Leading zeros are disallowed under all circumstances. Counting leading zeroes trivialises the problem; ignoring leading zeros unnecessarily complicates the question.

The winning program will be the qualifying program which prints the integer with the smallest magnitude.

Leaderboard snippet

var QUESTION_ID = 67921;
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;
function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; }
function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; }
function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); }
getAnswers();
var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*)(?:,|[-\u2013] ).*?([\d,^!e+]+)(?=\:?[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;
var OVERRIDE_REG = /^Override\s*header:\s*/i;
function getAuthorName(a) { return a.owner.display_name; }
function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '
' + c.body.replace(OVERRIDE_REG, '') + '
'; }); var match = body.replace(/([^\n<]*)<\/sup>/g, "^$1").replace(/\(\d+(?:\^\d+,)? [\w\s]+\)/g, "").replace(/floor\(10\^(\d+)\/9\)/g, "$1 ones").replace(/(\d+) ones/g, function (_, x) { return Array(+x + 1).join(1); }).match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2].replace(/,/g, "").replace(/(\d+)\s*\^\s*(\d+)/, function (_, a, b) { return Math.pow(a, b); }).replace(/(\d+)!/, function (_, n) { for (var i = 1, j = 1; i <= n; i++) j *= i; return j; }), language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery(''+lang+'').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr> </tbody> </table></code>```

答:
Python 2, 1000000000

A simple program in a simple language. I have two answers depending on wether the python shell is permitted or not.

If it isn't, then:

```<code>print 1e9
</code>```

Which is 9 bytes and outputs 1000000000, 10 bytes.

If it is, then:

```<code>1e3
</code>```

Which is 3 bytes and outputs 1000, 4 bytes.

These ignore the .0 printed on the end of these numbers since the method returns a float and the question asks for an int.

Body:
Python 2, 1000000000

A simple program in a simple language. I have two answers depending on wether the python shell is permitted or not.

If it isn't, then:

print 1e9

Which is 9 bytes and outputs 1000000000, 10 bytes.

If it is, then:

1e3

Which is 3 bytes and outputs 1000, 4 bytes.

These ignore the .0 printed on the end of these numbers since the method returns a float and the question asks for an int.


答:
JavaScript (ES6), 84 bytes

It's a recursive solution.

```<code>f=(s,k,i=0,r=Math.ceil(s.length/k),c=s[i%r*k+i/r|0])=>k*r==i?'':(c?c:' ')+f(s,k,++i)
</code>```

Title: Encode the column cipher

Body:
Given a string to encode, and a number of columns (the key), encode the string as follows:

I will be using the example Hello, world! and the key 3

First, write out the number of columns:

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

Next, write the text starting from the upper left, one character per column, and when you run out of columns, go to the next line.

```<code>1 2 3
H e l
l o ,
  w o
r l d
!
</code>```

Now, to get your encoded text, read the text starting from the top left corner, but this time, first read one column, and then the next, and so on. If there is not a character in the slot, put a space.

```<code>Hl r!eowl l,od
</code>```

Note that here, there is a trailing space.

This is your encoded text.

Another test case is Programming Puzzles and Code Golf SE with key 5:

```<code>1 2 3 4 5
P r o g r
a m m i n
g   P u z
z l e s
a n d   C
o d e   G
o l f   S
E
</code>```

The encoded text is PagzaooErm lndl omPedef gius    rnz CGS.

More test cases

```<code>"abcdefghijklmnopqrstuvwxyz", 2 -> "acegikmoqsuwybdfhjlnprtvxz"
"codegolf.stackexchange.com", 4 -> "cg.ccgoooskhemdltea. efaxnc "
"Pen Pineapple Apple Pen!!!", 7 -> "PeAeeapnnpp! pl!Ple!ie  n P "
"1,1,2,3,5,8,13,21,34,55,89", 10 -> "18,,,5115,3,2,8,2931 ,, 53 ,4 "
</code>```

Remember, this is code-golf, so the code with the fewest bytes wins.

Body:
JavaScript (ES6), 84 bytes

It's a recursive solution.

f=(s,k,i=0,r=Math.ceil(s.length/k),c=s[i%r*k+i/r|0])=>k*r==i?'':(c?c:' ')+f(s,k,++i)


答:
Racket 353 bytes

```<code>(define(cap i)(set! i(string-append i))(define c(string-ref i 0))(string-set! i 0(if(char-upper-case? c)c(integer->char(-(char->integer c)32))))i)
(let*((ex(list"a""an""the""at""by""for""in""of""on""to""up""and""as""but""or""and""nor"))(sl(string-split s)))
(string-join(for/list((i sl)(n(in-naturals)))(cond[(= n 0)(cap i)][(member i ex)i][(cap i)]))))
</code>```

Ungolfed:

```<code>(define (f s)

  (define (cap i)                 ; sub-fn to capitalize first letter of a word
    (set! i (string-append i))
    (define c (string-ref i 0))
    (string-set! i 0
                 (if (char-upper-case? c)
                     c
                     (integer->char (-(char->integer c)32))))
    i)

  (let* ((ex (list "a""an""the""at""by""for""in""of""on""to""up""and""as""but""or""and""nor"))
         (sl (string-split s)))
    (string-join
     (for/list
         ((i sl)
          (n (in-naturals)))
       (cond
         [(= n 0) (cap i)]
         [(member i ex) i]
         [(cap i)]
         )))))
</code>```

Testing:

```<code>(f "the rule of thumb for title capitalization")
</code>```

Output:

```<code>"The Rule of Thumb for Title Capitalization"
</code>```

Body:
According to this site a general rule recommended by The U.S. Government Printing Office Style Manual is

Capitalize all words in titles of publications and documents, except
  a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and
  nor.

This might not be true as I'm unable to find such a recommendation in the Style Manual, but let's use this rule anyway.

The Challenge

Given an input string consisting of lower case words delimited by spaces, output the capitalization of the string according to the following rules

The first and last word is capitalized.

All other words are capitalized, except a, an, the, at, by, for, in, of, on, to, up, and, as, but, or, and nor.

The input string will contain at least one word and each word contains at least one letter and only characters from a to z.

This is a code golf challenge, so try to use as few bytes as possible in the language of your choice. You may write a full program or a function to accomplish the task.

Testcases

```<code>"the rule of thumb for title capitalization" -> "The Rule of Thumb for Title Capitalization"
"programming puzzles and code golf" -> "Programming Puzzles and Code Golf"
"the many uses of the letter a" -> "The Many Uses of the Letter A"
"title" -> "Title"
"and and and" -> "And and And"
"a an and as at but by for in nor of on or the to up" -> "A an and as at but by for in nor of on or the to Up"
"on computable numbers with an application to the entscheidungsproblem" -> "On Computable Numbers With an Application to the Entscheidungsproblem"
</code>```

Body:
Racket 353 bytes

(define(cap i)(set! i(string-append i))(define c(string-ref i 0))(string-set! i 0(if(char-upper-case? c)c(integer->char(-(char->integer c)32))))i)
(let*((ex(list"a""an""the""at""by""for""in""of""on""to""up""and""as""but""or""and""nor"))(sl(string-split s)))
(string-join(for/list((i sl)(n(in-naturals)))(cond[(= n 0)(cap i)][(member i ex)i][(cap i)]))))

Ungolfed:

(define (f s)

  (define (cap i)                 ; sub-fn to capitalize first letter of a word
    (set! i (string-append i))
    (define c (string-ref i 0))
    (string-set! i 0
                 (if (char-upper-case? c)
                     c
                     (integer->char (-(char->integer c)32))))
    i)

  (let* ((ex (list "a""an""the""at""by""for""in""of""on""to""up""and""as""but""or""and""nor"))
         (sl (string-split s)))
    (string-join
     (for/list
         ((i sl)
          (n (in-naturals)))
       (cond
         [(= n 0) (cap i)]
         [(member i ex) i]
         [(cap i)]
         )))))

Testing:

(f "the rule of thumb for title capitalization")

Output:

"The Rule of Thumb for Title Capitalization"


答:
CJam / HTML, <s>17</s> 14 bytes

Edit:

-3 bytes off. Thanks to @ETHProductions

Code:

```<code>TREAT<"trick"
</code>```

HTML:

```<code>TREAT<;"trick"
TREAT           print TREAT
     <          tag open: ignore rest since there is no closing bracket
</code>```

CJam:

```<code>TREAT<;"trick"
TREAT<         e#random stuff / push vars
      ;        e#discard stack
       "trick" e#literal trick
               e#implictly print
</code>```

Title: Trick or Treat polyglot

Body:
Since Halloween is coming up I thought I might start a fun little code golf challenge!

The challenge is quite simple. You have to write a program that outputs either trick or treat.

"The twist?" you may ask. Well let me explain:

Your program has to do the following:

Be compilable/runnable in two different languages. Different versions of the same language don't count.

When you run the program in one language it should output trick and the other should output treat. The case is irrelevant and padding the string with whitespace characters are allowed (see examples).

This is code-golf,  so the solution with the fewest bytes wins.

A few explanations:

Valid outputs (Just for the words not for running the code in the two languages. Also adding quotes to signalize the beginning or end of the output. Do not include them in your solution!):

```<code>"trick"

"Treat"

"    TReAt"

"
     tRICk          "
</code>```

Invalid outputs:

```<code>"tri ck"

"tr
eat"

"trck"
</code>```

I'm interested to see what you can come up with! Happy Golfing!

I'd like to note that this is my first challenge so if you have suggestions on this question please leave them in the form of a comment.

Leaderboards

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

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

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

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

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

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

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

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

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

var QUESTION_ID=97472,OVERRIDE_USER=23417;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,TAGS_REG = /(<([^>]+)>)/ig;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;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:
CJam / HTML, <s>17</s> 14 bytes

Edit:

-3 bytes off. Thanks to @ETHProductions

Code:

TREAT<"trick"

HTML:

TREAT<;"trick"
TREAT           print TREAT
     <          tag open: ignore rest since there is no closing bracket

CJam:

TREAT<;"trick"
TREAT<         e#random stuff / push vars
      ;        e#discard stack
       "trick" e#literal trick
               e#implictly print


答:
TI-Basic, 295 + 59 + 148 = 502 bytes

Now you can capitalize on your calculator. Great for school :)

Main Program, 295 bytes

Basically, the trick to matching words so all A don't become a is to enclose with spaces, such as replace " A " with " a ". This also automatically makes it so that the first and last words stay capitalized, because they do not have a space on both sides and will thus not match any of the words. (Genius, right? And super long because lowercase letters are two  bytes each...)

```<code>"("+Ans+")→Str1
"@A ~ a@An ~ an@The ~ the@At ~ at@By ~ by@For ~ for@In ~ in@Of ~ of@On ~ on@To ~ to@Up ~ up@And ~ and@As ~ as@But ~ but@Or ~ or@Nor ~ nor@→Str2
For(I,2,length(Ans
If "@"=sub(Str2,I-1,1
Then
" "+Str1+"~"+sub(Str2,I,inString(Str2,"@",I)-I)+" "
prgmQ
Ans→Str1
End
End
</code>```

Subprogram (prgmQ), 59 bytes:

```<code>Ans→Str9
inString(Ans,"~
sub(Str9,Ans,length(Str9)-Ans+1→Str8
Str9
prgmR
Repeat Str9=Ans+Str8
Ans+Str8→Str9
prgmR
End
</code>```

Subprogram (prgmR), 148 bytes:

```<code>Ans→Str0
inString(Ans,"~→Z
inString(Str0,"~",Ans+1→Y
inString(sub(Str0,1,Z-1),sub(Str0,Z+1,Ans-Z-1→X
sub(Str0,1,-1+inString(Str0,"~
If X
sub(Str0,1,X-1)+sub(Str0,Y+1,length(Str0)-Y)+sub(Str0,X+length(sub(Str0,Z+1,Y-Z-1)),Z-X-length(sub(Str0,Z+1,Y-Z-1
</code>```

P.S. ~ represents token 0x81 and @ represents token 0x7F, learn more here.

Title: The Rule of Thumb for Title Capitalization

Body:
TI-Basic, 295 + 59 + 148 = 502 bytes

Now you can capitalize on your calculator. Great for school :)

Main Program, 295 bytes

Basically, the trick to matching words so all A don't become a is to enclose with spaces, such as replace " A " with " a ". This also automatically makes it so that the first and last words stay capitalized, because they do not have a space on both sides and will thus not match any of the words. (Genius, right? And super long because lowercase letters are two  bytes each...)

"("+Ans+")→Str1
"@A ~ a@An ~ an@The ~ the@At ~ at@By ~ by@For ~ for@In ~ in@Of ~ of@On ~ on@To ~ to@Up ~ up@And ~ and@As ~ as@But ~ but@Or ~ or@Nor ~ nor@→Str2
For(I,2,length(Ans
If "@"=sub(Str2,I-1,1
Then
" "+Str1+"~"+sub(Str2,I,inString(Str2,"@",I)-I)+" "
prgmQ
Ans→Str1
End
End

Subprogram (prgmQ), 59 bytes:

Ans→Str9
inString(Ans,"~
sub(Str9,Ans,length(Str9)-Ans+1→Str8
Str9
prgmR
Repeat Str9=Ans+Str8
Ans+Str8→Str9
prgmR
End

Subprogram (prgmR), 148 bytes:

Ans→Str0
inString(Ans,"~→Z
inString(Str0,"~",Ans+1→Y
inString(sub(Str0,1,Z-1),sub(Str0,Z+1,Ans-Z-1→X
sub(Str0,1,-1+inString(Str0,"~
If X
sub(Str0,1,X-1)+sub(Str0,Y+1,length(Str0)-Y)+sub(Str0,X+length(sub(Str0,Z+1,Y-Z-1)),Z-X-length(sub(Str0,Z+1,Y-Z-1

P.S. ~ represents token 0x81 and @ represents token 0x7F, learn more here.


问:
Compute the Eulerian number
The Eulerian number A(n, m) is the number of permutations of [1, 2, ..., n] in which exactly m elements are greater than the previous element. These are also called rises. For example, if n = 3, there are 3! = 6 permutations of [1, 2, 3]

```<code>1 2 3
 < <  2 elements are greater than the previous

1 3 2
 < >  1 ...

2 1 3
 > <  1 ...

2 3 1
 < >  1 ...

3 1 2
 > <  1 ...

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

So the outputs for A(3, m) for m in [0, 1, 2, 3] will be

```<code>A(3, 0) = 1
A(3, 1) = 4
A(3, 2) = 1
A(3, 3) = 0
</code>```

Also, this is the OEIS sequence A173018.

Rules

This is code-golf so the shortest code wins.

The input n will be a nonnegative integer and m will be a integer in the range [0, 1, ..., n].

Test Cases

```<code>n   m   A(n, m)
0   0   1
1   0   1
1   1   0
2   0   1
2   1   1
2   2   0
3   0   1
3   1   4
3   2   1
3   3   0
4   0   1
4   1   11
4   2   11
4   3   1
4   4   0
5   1   26
7   4   1191
9   5   88234
10  5   1310354
10  7   47840
10  10  0
12  2   478271
15  6   311387598411
17  1   131054
20  16  1026509354985
42  42  0
</code>```

答:
Actually, <s>21</s> 19 bytes

This answer uses an algorithm similar to the one Dennis uses in his Jelly answer. The original definition counts < while I count >. This ends up being equivalent in the end. Golfing suggestions welcome. Try it online!

```<code>;R╨`;\ZdX"i>"£MΣ`Mc
</code>```

Ungolfing

```<code>         Implicit input m, then n.
;        Duplicate n. Stack: n, n, m
R        Push range [1..n].
╨        Push all n-length permutations of the range.
`...`M   Map the following function over each permutation p.
  ;\       Duplicate and rotate p so that we have a list of the next elements of p.
  Z        Zip rot_p and p.
           (order of operands here means the next element is first,
            so we need to use > later)
  dX       Remove the last pair as we don't compare the last and first elements of the list.
  "i>"£    Create a function that will flatten a list and check for a rise.
  M        Map that function over all the pairs.
  Σ        Count how many rises there are in each permutation.
c        Using the result of the map and the remaining m,
          count how many permutations have m rises.
         Implicit return.
</code>```

Title: Compute the Eulerian number

Body:
Actually, <s>21</s> 19 bytes

This answer uses an algorithm similar to the one Dennis uses in his Jelly answer. The original definition counts < while I count >. This ends up being equivalent in the end. Golfing suggestions welcome. Try it online!

;R╨`;\ZdX"i>"£MΣ`Mc

Ungolfing

         Implicit input m, then n.
;        Duplicate n. Stack: n, n, m
R        Push range [1..n].
╨        Push all n-length permutations of the range.
`...`M   Map the following function over each permutation p.
  ;\       Duplicate and rotate p so that we have a list of the next elements of p.
  Z        Zip rot_p and p.
           (order of operands here means the next element is first,
            so we need to use > later)
  dX       Remove the last pair as we don't compare the last and first elements of the list.
  "i>"£    Create a function that will flatten a list and check for a rise.
  M        Map that function over all the pairs.
  Σ        Count how many rises there are in each permutation.
c        Using the result of the map and the remaining m,
          count how many permutations have m rises.
         Implicit return.


答:
Racket 321 bytes

```<code>(let*((ld(λ(sl)(for/list((i(sub1(length sl))))(-(list-ref sl(add1 i))(list-ref sl i)))))(l(ld(remove-duplicates(map
(λ(x)(char->integer x))(string->list s)))))(am andmap)(N"Not WAVY")(d displayln))(cond[(<(length l)2)(d N)][(am(λ(x)(>= x 0))l)
(d"YES; RAISING")][(am(λ(x)(<= x 0))l)(d"YES; DECREASING")][else(d N)])))
</code>```

Ungolfed:

```<code>(define (f s)
  (let*  ((ld (lambda(sl)          ; sub-fn to get differences in list elements
                (for/list ((i (sub1(length sl))))
                  (- (list-ref sl (add1 i))
                     (list-ref sl i) ) )))
          (l (ld
              (remove-duplicates
               (map
                (lambda(x)
                  (char->integer x))
                (string->list s)))))
          (am andmap)
          (N "Not WAVY")
          (d displayln))
    (cond
      [(< (length l) 2)(d N)]
      [(am (lambda(x) (>= x 0)) l) (d "YES; RAISING")]
      [(am (lambda(x) (<= x 0)) l) (d "YES; DECREASING")]
      [else (d N)]
      )))
</code>```

Testing:

```<code>(f "ADEPT"); > YES > RAISING
(f "BEGIN"); > YES > RAISING
(f "BILL"); > YES > RAISING
(f "BOSS"); > YES > RAISING
(f "BOOST"); > YES > RAISING
(f "CHIMP"); > YES > RAISING
(f "KNOW"); > YES > RAISING
(f "SPONGE"); > YES > DECREASING
(f "SPOON"); > YES > DECREASING
(f "TROLL"); > YES > DECREASING
(f "WOLF"); > YES > DECREASING

(f "WATCH")
(f "EARTH")
(f "NINON")
(f "FOO")
(f "BAR")
(f "WAVE")
(f "SELECTION")
</code>```

Output:

```<code>YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; DECREASING
YES; DECREASING
YES; DECREASING
YES; DECREASING
Not WAVY
Not WAVY
Not WAVY
Not WAVY
Not WAVY
Not WAVY
Not WAVY
</code>```

Title: Find the Wavy Words!

Body:
Racket 321 bytes

(let*((ld(λ(sl)(for/list((i(sub1(length sl))))(-(list-ref sl(add1 i))(list-ref sl i)))))(l(ld(remove-duplicates(map
(λ(x)(char->integer x))(string->list s)))))(am andmap)(N"Not WAVY")(d displayln))(cond[(<(length l)2)(d N)][(am(λ(x)(>= x 0))l)
(d"YES; RAISING")][(am(λ(x)(<= x 0))l)(d"YES; DECREASING")][else(d N)])))

Ungolfed:

(define (f s)
  (let*  ((ld (lambda(sl)          ; sub-fn to get differences in list elements
                (for/list ((i (sub1(length sl))))
                  (- (list-ref sl (add1 i))
                     (list-ref sl i) ) )))
          (l (ld
              (remove-duplicates
               (map
                (lambda(x)
                  (char->integer x))
                (string->list s)))))
          (am andmap)
          (N "Not WAVY")
          (d displayln))
    (cond
      [(< (length l) 2)(d N)]
      [(am (lambda(x) (>= x 0)) l) (d "YES; RAISING")]
      [(am (lambda(x) (<= x 0)) l) (d "YES; DECREASING")]
      [else (d N)]
      )))

Testing:

(f "ADEPT"); > YES > RAISING
(f "BEGIN"); > YES > RAISING
(f "BILL"); > YES > RAISING
(f "BOSS"); > YES > RAISING
(f "BOOST"); > YES > RAISING
(f "CHIMP"); > YES > RAISING
(f "KNOW"); > YES > RAISING
(f "SPONGE"); > YES > DECREASING
(f "SPOON"); > YES > DECREASING
(f "TROLL"); > YES > DECREASING
(f "WOLF"); > YES > DECREASING

(f "WATCH")
(f "EARTH")
(f "NINON")
(f "FOO")
(f "BAR")
(f "WAVE")
(f "SELECTION")

Output:

YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; RAISING
YES; DECREASING
YES; DECREASING
YES; DECREASING
YES; DECREASING
Not WAVY
Not WAVY
Not WAVY
Not WAVY
Not WAVY
Not WAVY
Not WAVY