问:
CAPTCHA Modified by Evil Mathematician

CAPTCHA Modified by Evil Mathematician

I accidentally incurred the wrath of an eccentric passive-aggressive mathematician. As part of his demented idea of payback, he modified the CAPTCHA system on my favorite website. Up until now, it would just ask a moderately challenging math question, like 3+2^4, and I would simply type the answer, 19, to verify that I am a human being. But now, thanks to my mathematical nemesis, the CAPTCHA questions are obnoxiously hard to calculate by hand and it keeps me from logging into my profile!

From what I can tell, this is what he has done. The CAPTCHA images seem to still be the same, but the way it calculates the correct answer has changed. It takes the expression displayed in the image and rotates the operations. You wouldn't believe how long it took me to figure this out T__T.

Because of this fiasco, I need a program/function that takes in one of these expressions as a string, evaluates it and returns the result so that I can log onto my website! To make this a game, fewest bytes win.

Ok, you have the idea, lets walk through an example. Suppose that the CAPTCHA displayed an image with 6+5+4-3*2/1. Normally the answer would 9. Instead, we now have to rotate the operations to the right and that gives us 6/5+4+3-2*1. At this point, we evaluate it to be 6.2

Summary

Steps to evaluate the string input:

Rotate the operation to the right

Evaluate the result

Specifications

Full program or function

Standard I/O

Takes an expression

Prints/Returns the evaluated result

After the op rotation

Possible operations are +-/*^

The negatives for negative numbers stays with the number when rotating

Follow the normal order of operations after the rotation is completed

Using integer division is allowed

Possible numbers are positive/negative integers

This does not include 0

Parentheses could be included, but aren't rotated

Test Cases

```<code>Input     -> Output
1+3       -> 4
7+6       -> 13
1+1-2     -> 2
3*4+2     -> 11
-7^4      -> -2401
3*7+1-3   -> -1
-9+4/4    -> 1.75
(4*1)+8   -> 40
1+2-3*4/5 -> -16.5
1+-2*3    -> 1
3*4--2    -> 11
30-2/7    -> 8
120*3-4+10-> 122
(13^-12)+11 -> 1
</code>```

Update

[16-07-28] Fixed typo in last test case. I had posted the expression after rotating it once >___> , so that rotating a second time gave an incorrect answer. It is fixed now! Thanks to @sintax!

[16-08-13] Removed broke test case. Thanks again to @sintax!

答:
Python 3.5, <s>118</s> <s>113</s> 164 bytes:

```<code>from re import*
def R(U):Z='(?<!\d)-\d+|\d+|[()]';O=sub(Z,'',U);print(eval(sub(Z,'%s',U).translate(str.maketrans(O,O[::-1])).replace('^','**')%tuple(findall(Z,U))))
</code>```

A named function. Can probably be golfed down more. This will take quite a while and apparently plenty of memory to compute the solution for the input:

```<code>((22^22)+2*2^2^2^2*2-2+222222+22222*-2222-2*222*2*2+2^-2+(2+2+2+2+2)+222/222+2+22*2*2)*2*2*2
</code>```

<s>I started processing this with my program about 30 minutes ago as of the time of this edit (9:52 PM on July 27, 2016) and it is still going.</s> <s>EDIT: Well, it eventually started to take up too much memory, so I had to stop it at around 1 hour after I started, at around 10:52 PM on July 7, 2016.</s>

EDIT # 2: Well, even for the updated last test case it's pretty much the same thing, as it takes quite a while for my program to start finding the answer before it eventually quits out on me with error code 137.

Try It Online for the Rest of the Test Cases! (Ideone)

Title: CAPTCHA Modified by Evil Mathematician

Body:
Python 3.5, <s>118</s> <s>113</s> 164 bytes:

from re import*
def R(U):Z='(?<!\d)-\d+|\d+|[()]';O=sub(Z,'',U);print(eval(sub(Z,'%s',U).translate(str.maketrans(O,O[::-1])).replace('^','**')%tuple(findall(Z,U))))

A named function. Can probably be golfed down more. This will take quite a while and apparently plenty of memory to compute the solution for the input:

((22^22)+2*2^2^2^2*2-2+222222+22222*-2222-2*222*2*2+2^-2+(2+2+2+2+2)+222/222+2+22*2*2)*2*2*2

<s>I started processing this with my program about 30 minutes ago as of the time of this edit (9:52 PM on July 27, 2016) and it is still going.</s> <s>EDIT: Well, it eventually started to take up too much memory, so I had to stop it at around 1 hour after I started, at around 10:52 PM on July 7, 2016.</s>

EDIT # 2: Well, even for the updated last test case it's pretty much the same thing, as it takes quite a while for my program to start finding the answer before it eventually quits out on me with error code 137.

Try It Online for the Rest of the Test Cases! (Ideone)


问:
Number to String

Number to String

Instructions

Convert a signed 32-bit integer to a string (base-10 preferably) without any string formatting calls (or built in type coercion that will directly convert a number to a string).

Negative numbers must include leading -.

Score Calculation

Shortest byte length; Tie breaker by efficiency (execution time)

答:
Jelly, <s>14</s> 12 bytes

```
<s>”-“”<?0³AD+48Ọ</s>
<0”-x³AD+48Ọ
```

Try it online!

ContentLicense: CC BY-SA 3.0

Title: Number to String

Body:
Jelly, <s>14</s> 12 bytes

<s>”-“”<?0³AD+48Ọ</s>
<0”-x³AD+48Ọ

Try it online!


答:
JavaScript ES6, <s>61</s> <s>57</s> <s>46</s> <s>45</s> 42 bytes

Apparently this is what you want.

Apparently Leaky Nun saved me 17 bytes.

Output in binary:

```<code>f=n=>n<0?"-"+f(-n):n?f(n>>1)+"01"[n%2]:"0"
</code>```

Output in decimal:

```<code>f=n=>n<0?"-"+f(-n):n<10?"0123456789"[n]:f(n/10|0)+f(n%10)
</code>```

Title: Number to String

Body:
Number to String

Instructions

Convert a signed 32-bit integer to a string (base-10 preferably) without any string formatting calls (or built in type coercion that will directly convert a number to a string).

Negative numbers must include leading -.

Score Calculation

Shortest byte length; Tie breaker by efficiency (execution time)

Body:
JavaScript ES6, <s>61</s> <s>57</s> <s>46</s> <s>45</s> 42 bytes

Apparently this is what you want.

Apparently Leaky Nun saved me 17 bytes.

Output in binary:

f=n=>n<0?"-"+f(-n):n?f(n>>1)+"01"[n%2]:"0"

Output in decimal:

f=n=>n<0?"-"+f(-n):n<10?"0123456789"[n]:f(n/10|0)+f(n%10)


问:
Prime Wednesdays

Prime Wednesdays

Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime Wednesday. For consistency use the Gregorian calendar for all dates.

Input

The input to your program/function will be a year (eg 2016) and is flexible. The year will be an integer between 1912 and 2233 inclusive.

Output

The output is also flexible and should be the number of prime Wednesdays (eg 18).

Scoring

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

Test Cases

input     -> output

  --------------------

  1912  ->   19

  1914  ->   16

  1984  ->   17

  1996  ->   19

  2063  ->   19

  2150  ->   16

  2199  ->   18

  2233  ->   18

答:
Python 2.7, <s>166</s>, <s>165</s>, 150 bytes

```<code>from datetime import*
y=input()
d,c=date(y,1,1),0
while d.year==y:n=d.day;c+=n>1<2==d.weekday()>0<all(n%x for x in range(2,n));d+=timedelta(1)
print c
</code>```

There is certainly room for improvement here.  I am rather new to golfing in python.  This uses the datetime module.  It loops through all the days in the year adding one to an accumulator if it fits the criterion.  It then prints the result.  Most of the heavy lifting is in the module so the code can be quite slim.

One byte saved thanks to Morgan Thrapp and 15 bytes saved by Pietu1998.

Title: Prime Wednesdays

Body:
Python 2.7, <s>166</s>, <s>165</s>, 150 bytes

from datetime import*
y=input()
d,c=date(y,1,1),0
while d.year==y:n=d.day;c+=n>1<2==d.weekday()>0<all(n%x for x in range(2,n));d+=timedelta(1)
print c

There is certainly room for improvement here.  I am rather new to golfing in python.  This uses the datetime module.  It loops through all the days in the year adding one to an accumulator if it fits the criterion.  It then prints the result.  Most of the heavy lifting is in the module so the code can be quite slim.

One byte saved thanks to Morgan Thrapp and 15 bytes saved by Pietu1998.


Title: Prime Wednesdays

Body:
Prime Wednesdays

Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime Wednesday. For consistency use the Gregorian calendar for all dates.

Input

The input to your program/function will be a year (eg 2016) and is flexible. The year will be an integer between 1912 and 2233 inclusive.

Output

The output is also flexible and should be the number of prime Wednesdays (eg 18).

Scoring

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

Test Cases

input     -> output

  --------------------

  1912  ->   19

  1914  ->   16

  1984  ->   17

  1996  ->   19

  2063  ->   19

  2150  ->   16

  2199  ->   18

  2233  ->   18

Body:
Python 2, <s>95</s> <s>93</s> <s>68</s> 67 bytes

lambda y:0x10ea2c8dbb06c5619/5**((y+((y-22)/99-y/2002)*16)%28)%5+16

Thanks to @Josay for golfing off 1 byte!

Test it on Ideone.


Title: Prime Wednesdays

Body:
Brain-Flak, <s>6588</s>, <s>2310</s>, <s>2308</s>, 2290 bytes

First things first, I did not write nearly 100% of this program, which is probably evidenced by the enormous size of the program.  Most of this code was written by my own Brain-Flak golfing algorithm.  Along with an additional python script I wrote to prompt it in the right direction.

<a href="http://brain-flak.tryitonline.net/#code=KHt9PCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKSgpKCkpKXt9e30pe30pWygpKCldKSgpKSgpKCkpWygpKCkoKSgpXSkoKSkoKSgpKCkpWygpKCkoKV0pKCkoKSlbKCkoKSgpXSkoKSgpKVsoKV0pKSgpKSgpKCkpWygpKCkoKSgpXSkoKSkoKSgpKCkpWygpKCkoKV0pKCkpKCkpWygpXSlbKCldKSgpKCkoKSlbKCkoKV0pKCkoKSlbKCkoKSgpKCldKSgpKCkpKCkpWygpKCldKSgpKSgpKCkpWygpKCkoKSgpXSkoKSgpKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSkoKSlbKCldKVsoKV0pKCkoKSgpKVsoKSgpXSkoKSgpKVsoKSgpKCkoKV0pKCkoKSkoKSlbKCkoKV0pKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSlbKCkoKSgpXSkoKSgpKVsoKSgpKCldKSgpKCkpWygpXSkpKCkpKCkoKSlbKCkoKSgpKCldKSgpKSgpKCkoKSk-WygoKCgoKCgoKCgpKCkoKSgpKCkpKXt9e30pe30pe30pe30pe31bKCldKXt9KXt9KXt9XSl7KHt9WygpXTx7fT4pfXt9KHt9PHt7fX0-KQ&input=MTk5Nw" rel="noreferrer">Try it online!

({}<(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((()()())){}{}){})[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])()())[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])())()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())[()()()])())())[()])[()])()()())[()()])()())[()()()()])()())())[()()])())()())[()()()()])())()()())[()()()])()())[()()()])()())[()]))())()())[()()()()])())()()())>[(((((((((()()()()())){}{}){}){}){}){}[()]){}){}){}]){({}[()]<{}>)}{}({}<{{}}>)

While this program is quite long for code golf, it really is decently short for Brain-Flak.  Currently the world record for integer division is over 1000 bytes.

Explanation

The algorithm is quite simple.  Because there is a limited number of years available (321) it simply pushes the answers in reverse order under the input and uses a lookup algorithm to find the correct answer. While hardcoding all 321 possibilities may seem rather inefficient with an task as complex as this one and a language as esoteric as brain-flak it may very well be the best solution.  (I plan to find out in the coming week).

Since most of the 321 numbers are about 18 on average and they differ by very little from year to year instead of pushing all the numbers individually I push the first year (2233) normally and then just duplicate and change the value a bit for each year after.  This way instead of paying to push ~18 for all 321 years I only pay to push ~2 for every year.

Once all the answers have been pushed it subtracts 1912 from the input ({}[(((((((((()()()()())){}{}){}){}){}){}[()]){}){}){}]) (This may be suboptimal, I rewrote the optimizer to skip certain values that I believed would not be optimal because hardcoding numbers is a super-exponential process and running it to completion may have taken a few days).

It then subtracts one from the first element and pops the second element until the result reaches zero, {({}[()]<{}>)}.

It pops the zero, {} and all the elements below the top element ({}<{{}}>).


问:
Big or Little Endian
Write a program or function that outputs an L if run on a little endian architecture or a B if run on a big endian architecture. Lower case output l or b is also acceptable.

There is no input.

Scoring is code golf, so the code with the fewest bytes wins.

Edit: As per the comments below, I am clarifying that the entry must be able to run on either architecture.

I believe that there is only one answer that this affects, and that answer has clearly indicated that this is the case.

答:
Node, 42 bytes

```<code>n=>require('os').endianness()[0]
</code>```

Pro: there's a builtin. Con: property names are very long

Title: Big or Little Endian

Body:
Node, 42 bytes

n=>require('os').endianness()[0]

Pro: there's a builtin. Con: property names are very long


答:
Dyalog APL, <s>28</s> <s>19</s> <s>16</s> 15 bytes

Both solutions below require ⎕IO←0, which is default on many systems.

In cooperation with my CTO:

```<code>'BL'⊃⍨⊃11⎕DR'⊢'
</code>```

11⎕DR'⊢' interpret the character as 1 bit Boolean

  {0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0} on big-endian systems

  {1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0} on little-endian systems

⊃ pick the first number, i.e. 0 on big endian systems, and 1 on little-endian systems

'BL'⊃⍨ use that to pick from the string

This one is a bit interesting, as it requires storing in the "Classic" character set to be only 15 bytes, but must be executed in the "Unicode" interpreter to get a two byte representation. However, this is not a contradiction as the Unicode interpreter can load Classic workspaces.

Old solution:

```<code>'LB'⊃⍨'E'⎕FPROPS⎕D⎕FCREATE 0
</code>```

⎕D⎕FCREATE 0 create an APL component file with the name 0123456789

'E'⎕FPROPS query endian-ness (0=little, 1=big)

'LB'⊃⍨ pick from the string

Title: Big or Little Endian

Body:
Write a program or function that outputs an L if run on a little endian architecture or a B if run on a big endian architecture. Lower case output l or b is also acceptable.

There is no input.

Scoring is code golf, so the code with the fewest bytes wins.

Edit: As per the comments below, I am clarifying that the entry must be able to run on either architecture.

I believe that there is only one answer that this affects, and that answer has clearly indicated that this is the case.

Body:
Dyalog APL, <s>28</s> <s>19</s> <s>16</s> 15 bytes

Both solutions below require ⎕IO←0, which is default on many systems.

In cooperation with my CTO:

'BL'⊃⍨⊃11⎕DR'⊢'

11⎕DR'⊢' interpret the character as 1 bit Boolean

  {0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0} on big-endian systems

  {1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0} on little-endian systems

⊃ pick the first number, i.e. 0 on big endian systems, and 1 on little-endian systems

'BL'⊃⍨ use that to pick from the string

This one is a bit interesting, as it requires storing in the "Classic" character set to be only 15 bytes, but must be executed in the "Unicode" interpreter to get a two byte representation. However, this is not a contradiction as the Unicode interpreter can load Classic workspaces.

Old solution:

'LB'⊃⍨'E'⎕FPROPS⎕D⎕FCREATE 0

⎕D⎕FCREATE 0 create an APL component file with the name 0123456789

'E'⎕FPROPS query endian-ness (0=little, 1=big)

'LB'⊃⍨ pick from the string


问:
Removing unique elements from string
I came upon this question, because it seems to be very common use-case to find unique characters in string. But what if we want to get rid of them?

Input contains only lower case alphabets. Only letters from a to z are used. Input length may be from 1 to 1000 characters.

Example:

input: helloworld

output: llool

Objective: Shortest code wins

Language: Any of the top 20 of TIOBE languages

答:
Ocaml, <s>139</s> 133

Uses ExtLib's ExtString.String

```<code>open ExtString.String
let f s=let g c=fold_left(fun a d->a+Obj.magic(d=c))0 s in replace_chars(fun c->if g c=1 then""else of_char c)s
</code>```

Non-golfed version

```<code>open ExtString.String
let f s =
  let g c =
    fold_left
      (fun a c' -> a + Obj.magic (c' = c))
      0
      s
  in replace_chars
  (fun c ->
    if g c = 1
    then ""
    else of_char c)
  s
</code>```

The function g returns the number of occurences of c in the string s. The function f replaces all chars either by the empty string or the string containing the char depending on the number of occurences. Edit: I shortened the code by 6 characters by abusing the internal representation of bools :-)

Oh, and ocaml is 0 on the TIOBE index ;-)

Title: Removing unique elements from string

Body:
Ocaml, <s>139</s> 133

Uses ExtLib's ExtString.String

open ExtString.String
let f s=let g c=fold_left(fun a d->a+Obj.magic(d=c))0 s in replace_chars(fun c->if g c=1 then""else of_char c)s

Non-golfed version

open ExtString.String
let f s =
  let g c =
    fold_left
      (fun a c' -> a + Obj.magic (c' = c))
      0
      s
  in replace_chars
  (fun c ->
    if g c = 1
    then ""
    else of_char c)
  s

The function g returns the number of occurences of c in the string s. The function f replaces all chars either by the empty string or the string containing the char depending on the number of occurences. Edit: I shortened the code by 6 characters by abusing the internal representation of bools :-)

Oh, and ocaml is 0 on the TIOBE index ;-)


答:
JavaScript ES6, 50 bytes

_=>"BL"[new Int8Array(Int16Array.of(1).buffer)[0]]
```

I don’t know who decided it was a good idea for TypedArray objects to expose the native endianness of the interpreter, but here we are.

Title: Big or Little Endian

Body:
JavaScript ES6, 50 bytes

_=>"BL"[new Int8Array(Int16Array.of(1).buffer)[0]]

I don’t know who decided it was a good idea for TypedArray objects to expose the native endianness of the interpreter, but here we are.


问:
Output a Magical 8 Trapezium
Your task is to output a Magical 8 Trapezium:

```<code>        1 × 8 + 1 = 9
       12 × 8 + 2 = 98
      123 × 8 + 3 = 987
     1234 × 8 + 4 = 9876
    12345 × 8 + 5 = 98765
   123456 × 8 + 6 = 987654
  1234567 × 8 + 7 = 9876543
 12345678 × 8 + 8 = 98765432
123456789 × 8 + 9 = 987654321
</code>```

Output in your chosen language in the fewest bytes possible.

Note the number of spaces at the start of each line to maintain the trapezium shape.

Trailing spaces are allowed.

You can use × or the letter x - whichever you prefer.

答:
Object Pascal (FPC), <s>156</s> <s>127</s>  103 bytes

Trivial solution, <s>using the Format library func</s>. Shaved some more bytes by using only integers and no strings. Reduced in size thanks to @manatwork (for teaching me some basic stuff about writeln).

var i,c:int64;begin i:=0;for c in[1..9]do begin i:=i*10+c;WriteLn(i:9,' x 8 + ',c,' = ',i*8+c);end;end.
```
<p>Try it online!</p>
<p>Ungolfed:</p>
<pre class="lang-pascal prettyprint-override"><code>var
  i, c: int64;
begin
  i := 0;
  for c in [1..9] do
  begin
    i := i*10+c;
    WriteLn(i:9, ' x 8 + ', c, ' = ', i*8+c);
  end;
end.
</code>```

Title: Output a Magical 8 Trapezium

Body:
Object Pascal (FPC), <s>156</s> <s>127</s>  103 bytes

Trivial solution, <s>using the Format library func</s>. Shaved some more bytes by using only integers and no strings. Reduced in size thanks to @manatwork (for teaching me some basic stuff about writeln).

var i,c:int64;begin i:=0;for c in[1..9]do begin i:=i*10+c;WriteLn(i:9,' x 8 + ',c,' = ',i*8+c);end;end.

Try it online!

Ungolfed:

var
  i, c: int64;
begin
  i := 0;
  for c in [1..9] do
  begin
    i := i*10+c;
    WriteLn(i:9, ' x 8 + ', c, ' = ', i*8+c);
  end;
end.

ContentLicense: CC BY-SA 4.0


答:
Racket, <s>35</s> 28 bytes

(if(system-big-endian?)'B'L)
```

'B or 'L respectively. Let me know if this is not specific enough :)

Title: Big or Little Endian

Body:
Racket, <s>35</s> 28 bytes

(if(system-big-endian?)'B'L)

'B or 'L respectively. Let me know if this is not specific enough :)


答:
Ruby, 3130 chars.

```<code>puts [1].pack("s")>"\01"??L:?B
</code>```

Hmm, must be a better way. Count 5 characters less if the char need not to be output as I think other solutions omit printing. i.e. remove the "puts " part if you don't want anything printed.

Title: Big or Little Endian

Body:
Ruby, 3130 chars.

puts [1].pack("s")>"\01"??L:?B

Hmm, must be a better way. Count 5 characters less if the char need not to be output as I think other solutions omit printing. i.e. remove the "puts " part if you don't want anything printed.


答:
Perl 5, 21 + 1 = 22 bytes

Run with perl -E.

say ord pack(S,1)?L:B
```

Tested on amd64 (little-endian) and mips (big-endian).

Title: Big or Little Endian

Body:
Perl 5, 21 + 1 = 22 bytes

Run with perl -E.

say ord pack(S,1)?L:B

Tested on amd64 (little-endian) and mips (big-endian).


答:
Python 3, 195 bytes:

import re;I=input();x=[i for i in I if i in'+-*/^'];print(eval(''.join([i[0]+i[1]for i in[i for i in map(list,zip(*[[i for i in re.split('[+*/^-]',I)],x[-1:]+x[:-1]+['']]))]]).replace('^','**')))
```

Takes input on STDIN and leaves a number on STDOUT. I know that R. Kap already posted a Python answer, but the method I used is actually pretty interesting, so I thought I'll post this anyway.

The program first makes an the list: [chunks splitted by math chars, math chars rotated to the right]. It then transposes the array, flattens, converts to string, and evaluates.

Title: CAPTCHA Modified by Evil Mathematician

Body:
CAPTCHA Modified by Evil Mathematician

I accidentally incurred the wrath of an eccentric passive-aggressive mathematician. As part of his demented idea of payback, he modified the CAPTCHA system on my favorite website. Up until now, it would just ask a moderately challenging math question, like 3+2^4, and I would simply type the answer, 19, to verify that I am a human being. But now, thanks to my mathematical nemesis, the CAPTCHA questions are obnoxiously hard to calculate by hand and it keeps me from logging into my profile!

From what I can tell, this is what he has done. The CAPTCHA images seem to still be the same, but the way it calculates the correct answer has changed. It takes the expression displayed in the image and rotates the operations. You wouldn't believe how long it took me to figure this out T__T.

Because of this fiasco, I need a program/function that takes in one of these expressions as a string, evaluates it and returns the result so that I can log onto my website! To make this a game, fewest bytes win.

Ok, you have the idea, lets walk through an example. Suppose that the CAPTCHA displayed an image with 6+5+4-3*2/1. Normally the answer would 9. Instead, we now have to rotate the operations to the right and that gives us 6/5+4+3-2*1. At this point, we evaluate it to be 6.2

Summary

Steps to evaluate the string input:

Rotate the operation to the right

Evaluate the result

Specifications

Full program or function

Standard I/O

Takes an expression

Prints/Returns the evaluated result

After the op rotation

Possible operations are +-/*^

The negatives for negative numbers stays with the number when rotating

Follow the normal order of operations after the rotation is completed

Using integer division is allowed

Possible numbers are positive/negative integers

This does not include 0

Parentheses could be included, but aren't rotated

Test Cases

```<code>Input     -> Output
1+3       -> 4
7+6       -> 13
1+1-2     -> 2
3*4+2     -> 11
-7^4      -> -2401
3*7+1-3   -> -1
-9+4/4    -> 1.75
(4*1)+8   -> 40
1+2-3*4/5 -> -16.5
1+-2*3    -> 1
3*4--2    -> 11
30-2/7    -> 8
120*3-4+10-> 122
(13^-12)+11 -> 1
</code>```

Update

[16-07-28] Fixed typo in last test case. I had posted the expression after rotating it once >___> , so that rotating a second time gave an incorrect answer. It is fixed now! Thanks to @sintax!

[16-08-13] Removed broke test case. Thanks again to @sintax!

Body:
Python 3, 195 bytes:

import re;I=input();x=[i for i in I if i in'+-*/^'];print(eval(''.join([i[0]+i[1]for i in[i for i in map(list,zip(*[[i for i in re.split('[+*/^-]',I)],x[-1:]+x[:-1]+['']]))]]).replace('^','**')))

Takes input on STDIN and leaves a number on STDOUT. I know that R. Kap already posted a Python answer, but the method I used is actually pretty interesting, so I thought I'll post this anyway.

The program first makes an the list: [chunks splitted by math chars, math chars rotated to the right]. It then transposes the array, flattens, converts to string, and evaluates.


答:
PHP 5.6, <s>41</s> 31 bytes (thx to isertusernamehere)

<?=unpack(S,"\x01\x00")[1]-1?B:L;

PHP 7, 41 bytes

echo unpack('S',"\x01\x00")[1]-1?'B':'L';

Idea stolen from: https://stackoverflow.com/a/24785578/2496717

Title: Big or Little Endian


答:
C#, 60 52 bytes

C# is surprisingly competitive in this one.

char e=>System.BitConverter.IsLittleEndian?'L':'B';
```

<p>Credits to Groo for the C#6 syntax.</p>

<p>60 bytes:</p>

<pre class="lang-cs prettyprint-override"><code>char e(){return System.BitConverter.IsLittleEndian?'L':'B';}
</code>```

Title: Big or Little Endian

Body:
C#, 60 52 bytes

C# is surprisingly competitive in this one.

char e=>System.BitConverter.IsLittleEndian?'L':'B';

Credits to Groo for the C#6 syntax.

60 bytes:

char e(){return System.BitConverter.IsLittleEndian?'L':'B';}


问:
Verify a Tower of Hanoi solution
If you don't know what the Tower of Hanoi is, I'll explain it briefly: There are three rods and some discs each of which has a different size. In the beginning all discs are on the first tower, in sorted order: The biggest one is at the bottom, the smallest at the top. The goal is to bring all the discs over to the third rod. Sounds easy? Here's the catch: You can't place a disc on top of a disc that is smaller than the other disc; you can only hold one disc in your hand at a time to move them to another rod and you can only place the disc on rods, not on the table, you sneaky bastard.

ascii example solution:

```<code>  A      B      C
  |      |      |
 _|_     |      |
__|__    |      |

  A      B      C
  |      |      |
  |      |      |
__|__   _|_     |

  A      B      C
  |      |      |
  |      |      |
  |     _|_   __|__

  A      B      C
  |      |      |
  |      |     _|_
  |      |    __|__
</code>```

Challenge

There are three rods called A,B and C. (You can also call them 1,2 and 3 respectivly if that helps) In the beginning all n discs are on rod A(1).

Your challenge is to verify a solution for the tower of hanoi. You'll need to make sure that:

In the end all n discs are on rod C(3).

For any given disc at any given state there is no smaller disc below it.

No obvious errors like trying to take discs from an empty rod or moving discs to nonexistant rods.

(the solution does not have to be optimal.)

Input

Your program will receive two inputs:

The number of discs n (an integer)

The moves which are taken, which will consist of a set of tuples of: (tower to take the currently uppermost disc from),(tower to take this disc to) where each tuple refers to a move. You can choose how they are represented. For example something like the following ways of representing the solution for n=2 which I've drawn in ascii above. (I'll use the first one in the test cases, because it's easy on the eyes):

"A->B ; A->C ; B->C"

[("A","B"),("A","C"),("B","C")]

[(1,2),(1,3),(2,3)]

"ABACBC"

[1,2,1,3,2,3]

Output

Truthy, if the conditions that can be found under "challenge" hold.

Falsy, if they don't.

Test cases:

True:

```<code>n=1, "A->C"

n=1, "A->B ; B->C"

n=2, "A->B ; A->C ; B->C"

n=2, "A->C ; C->B ; A->C ; B->C"

n=2, "A->C ; A->B ; C->B ; B->A ; B->C ; A->C"

n=3, "A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; A->C"

n=4, "A->B ; A->C ; B->C ; A->B ; C->A ; C->B ; A->B ; A->C ; B->C ; B->A ; C->A ; B->C ; A->B ; A->C ; B->C"
</code>```

False:

3rd one suggested by @MartinEnder, 7th by @Joffan

```<code>n=1, "A->B"

n=1, "C->A"

n=2, "A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; A->C"

n=2, "A->B ; A->C ; C->B"

n=2, "A->C ; A->B ; C->B ; B->A"

n=2, "A->C ; A->C"

n=3, "A->B ; A->D; A->C ; D->C ; A->C"

n=3, "A->C ; A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; A->C"

n=3, "A->C ; A->B ; C->B ; A->B ; B->C ; B->A ; B->C ; A->C"

n=3, "A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; C->B"

n=4, "A->B ; A->C ; B->C ; A->B ; C->A ; C->B ; A->B ; A->C ; B->C ; B->A ; C->A ; B->C ; A->B ; A->C"

n=4, "A->B ; A->B ; A->B ; A->C ; B->C ; B->C ; B->C"
</code>```

This is code-golf, shortest solution wins. Standard rules and loopholes apply. No batteries included.

答:
Retina, <s>167</s> <s>165</s> <s>157</s> <s>150</s> 123 bytes

This totally looks like a challenge that should be solved with a single regex... (despite the header saying "Retina", this is just a vanilla .NET regex, matching valid inputs).

```<code>^(?=\D*((?=(?<3>1+))1)+)((?=A(?<1-3>.+)|B(?<1-4>.+)|C(?<1-5>.+)).(?=A.*(?!\3)(\1)|B.*(?!\4)(\1)|C.*(?!\5)(\1)).)+(?!\3|\4)1
</code>```

Input format is the list of instructions of the form AB, followed by n in unary using the digit 1. There are no separators. Output is 1 for valid and 0 for invalid.

Try it online! (The first two characters enable a linefeed-separated test suite.)

Alternative solution, same byte count:

```<code>^(?=\D*((?=(?<3>1+))1)+)((?=A(?<1-3>.+)|B(?<1-4>.+)|C(?<1-5>.+)).(?=A.*(?!\3)(\1)|B.*(?!\4)(\1)|C.*(?!\5)(\1)).)+(?<-5>1)+$
</code>```

This can possibly be shortened by using 1, 11 and 111 instead of A, B and C but I'll have to look into that later. It might also be shorter to split the program into several stages, but where's the challenge in that? ;)

Explanation

This solution makes heavy use of .NET's balancing groups. For a full explanation see my post on Stack Overflow, but the gist is that capturing groups in .NET are stacks, where each new capture pushes another substring and where it's also possible to pop from such a stack again. This lets you count various quantities in a string. In this case it lets us implement the three rods directly as three different capturing groups where each disc is represented by a capture.

To move discs around between rods we make use of a weird quirk of the (?...) syntax. Normally, this pops a capture from stack B and pushes onto stack A the string between that popped capture and the beginning of this group. So (?a).(?c) matched against abc would leave A empty and B with b (as opposed to c). However, due to .NET variable-length lookbehinds it's possible for the captures of (?...) and (?...) to overlap. For whatever reason, if that's the case, the intersection of the two groups is pushed onto B. I've detailed this behaviour in the "advanced section" on balancing groups in this answer.

On to the regex. Rods A, B and C correspond to groups 3, 4 and 5 in the regex. Let's start by initialising rod A:

```<code>^                 # Ensure that we start at the beginning of the input.
(?=               # Lookahead so that we don't actually move the cursor.
  \D*             # Skip all the instructions by matching non-digit characters.
  (               # For each 1 at the end of the input...
    (?=(?<3>1+))  # ...push the remainder of the string (including that 1)
                  # onto stack 3.
  1)+
)
</code>```

So e.g. if the input ends with 111, then group 3/rod A will now hold the list of captures [111, 11, 1] (the top being on the right).

The next bit of the code has the following structure:

```<code>(
  (?=A...|B...|C...).
  (?=A...|B...|C...).
)+
</code>```

Each iteration of this loop processes one instruction. The first alternation pulls a disc from the given rod (onto a temporary group), the second alternation puts that that disc onto the other given rod. We'll see in a moment how this works and how we ensure that the move is valid.

First, taking a disc off the source rod:

```<code>(?=
  A(?<1-3>.+)
|
  B(?<1-4>.+)
|
  C(?<1-5>.+)
)
</code>```

This uses the weird group-intersection behaviour I've described above. Note that group 3, 4 and 5 will always hold substrings of 1s at the end of the string whose length corresponds to the disc's size. We now use (?<1-N>.+) to pop the top disc off stack N and push the intersection of this substring with the match .+ onto stack 1. Since .+ always necessarily covers the entire capture popped off N, we know that this simply moves the capture.

Next, we put this disc from stack 1 onto the stack corresponding to the second rod:

```<code>(?=
  A.*(?!\3)(\1)
|
  B.*(?!\4)(\1)
|
  C.*(?!\5)(\1)
)
</code>```

Note that we don't have to clean up stack 1, we can just leave the disc there, since we'll put a new one on top before using the stack again. That means we can avoid the (?...) syntax and simply copy the string over with (\1). To ensure that the move is valid we use the negative lookahead (?!\N). This ensures that, from the position where we want to match the current disc, it's impossible to match the disc already on stack N. This can only happen if either a) \N will never match because the stack is completely empty or b)the disc on top of stackNis larger than the one we're trying to match with\1`.

Finally, all that's left is ensuring that a) we've matched all instructions and b) rods A and B are empty, so that all discs have been moved onto C.

```<code>(?!\3|\4)1
</code>```

We simply check that neither \3 nor \4 can match (which is only the case if both are empty, because any actual disc would match) and that we can then match a 1 so that we haven't omitted any instructions.

Title: Verify a Tower of Hanoi solution

Body:
Retina, <s>167</s> <s>165</s> <s>157</s> <s>150</s> 123 bytes

This totally looks like a challenge that should be solved with a single regex... (despite the header saying "Retina", this is just a vanilla .NET regex, matching valid inputs).

^(?=\D*((?=(?<3>1+))1)+)((?=A(?<1-3>.+)|B(?<1-4>.+)|C(?<1-5>.+)).(?=A.*(?!\3)(\1)|B.*(?!\4)(\1)|C.*(?!\5)(\1)).)+(?!\3|\4)1

Input format is the list of instructions of the form AB, followed by n in unary using the digit 1. There are no separators. Output is 1 for valid and 0 for invalid.

<a href="http://retina.tryitonline.net/#code=JWBeKD89XEQqKCg_PSg_PDM-MSspKTEpKykoKD89QSg_PDEtMz4uKyl8Qig_PDEtND4uKyl8Qyg_PDEtNT4uKykpLig_PUEuKig_IVwzKShcMSl8Qi4qKD8hXDQpKFwxKXxDLiooPyFcNSkoXDEpKS4pKyg_IVwzfFw0KTE&input=QUMxCkFCQkMxCkFCQUNCQzExCkFDQ0JBQ0JDMTEKQUNBQkNCQkFCQ0FDMTEKQUNBQkNCQUNCQUJDQUMxMTEKQUJBQ0JDQUJDQUNCQUJBQ0JDQkFDQUJDQUJBQ0JDMTExMQpBQjEKQ0ExCkFCQUNDQjExCkFDQUJDQkJBMTEKQUNBQzExCkFDQUNBQkNCQUNCQUJDQUMxMTEKQUNBQkNCQUJCQ0JBQkNBQzExMQpBQ0FCQ0JBQ0JBQkNDQjExMQpBQkFDQkNBQkNBQ0JBQkFDQkNCQUNBQkNBQkFDMTExMQpBQkFCQUJBQ0JDQkNCQzExMTE" rel="nofollow noreferrer">Try it online! (The first two characters enable a linefeed-separated test suite.)

Alternative solution, same byte count:

^(?=\D*((?=(?<3>1+))1)+)((?=A(?<1-3>.+)|B(?<1-4>.+)|C(?<1-5>.+)).(?=A.*(?!\3)(\1)|B.*(?!\4)(\1)|C.*(?!\5)(\1)).)+(?<-5>1)+$

This can possibly be shortened by using 1, 11 and 111 instead of A, B and C but I'll have to look into that later. It might also be shorter to split the program into several stages, but where's the challenge in that? ;)

Explanation

This solution makes heavy use of .NET's balancing groups. For a full explanation see my post on Stack Overflow, but the gist is that capturing groups in .NET are stacks, where each new capture pushes another substring and where it's also possible to pop from such a stack again. This lets you count various quantities in a string. In this case it lets us implement the three rods directly as three different capturing groups where each disc is represented by a capture.

To move discs around between rods we make use of a weird quirk of the (?<A-B>...) syntax. Normally, this pops a capture from stack B and pushes onto stack A the string between that popped capture and the beginning of this group. So (?<A>a).(?<B-A>c) matched against abc would leave A empty and B with b (as opposed to c). However, due to .NET variable-length lookbehinds it's possible for the captures of (?<A>...) and (?<B-A>...) to overlap. For whatever reason, if that's the case, the intersection of the two groups is pushed onto B. I've detailed this behaviour in the "advanced section" on balancing groups in this answer.

On to the regex. Rods A, B and C correspond to groups 3, 4 and 5 in the regex. Let's start by initialising rod A:

^                 # Ensure that we start at the beginning of the input.
(?=               # Lookahead so that we don't actually move the cursor.
  \D*             # Skip all the instructions by matching non-digit characters.
  (               # For each 1 at the end of the input...
    (?=(?<3>1+))  # ...push the remainder of the string (including that 1)
                  # onto stack 3.
  1)+
)

So e.g. if the input ends with 111, then group 3/rod A will now hold the list of captures [111, 11, 1] (the top being on the right).

The next bit of the code has the following structure:

(
  (?=A...|B...|C...).
  (?=A...|B...|C...).
)+

Each iteration of this loop processes one instruction. The first alternation pulls a disc from the given rod (onto a temporary group), the second alternation puts that that disc onto the other given rod. We'll see in a moment how this works and how we ensure that the move is valid.

First, taking a disc off the source rod:

(?=
  A(?<1-3>.+)
|
  B(?<1-4>.+)
|
  C(?<1-5>.+)
)

This uses the weird group-intersection behaviour I've described above. Note that group 3, 4 and 5 will always hold substrings of 1s at the end of the string whose length corresponds to the disc's size. We now use (?<1-N>.+) to pop the top disc off stack N and push the intersection of this substring with the match .+ onto stack 1. Since .+ always necessarily covers the entire capture popped off N, we know that this simply moves the capture.

Next, we put this disc from stack 1 onto the stack corresponding to the second rod:

(?=
  A.*(?!\3)(\1)
|
  B.*(?!\4)(\1)
|
  C.*(?!\5)(\1)
)

Note that we don't have to clean up stack 1, we can just leave the disc there, since we'll put a new one on top before using the stack again. That means we can avoid the (?<A-B>...) syntax and simply copy the string over with (\1). To ensure that the move is valid we use the negative lookahead (?!\N). This ensures that, from the position where we want to match the current disc, it's impossible to match the disc already on stack N. This can only happen if either a) \N will never match because the stack is completely empty or b)the disc on top of stackNis larger than the one we're trying to match with\1`.

Finally, all that's left is ensuring that a) we've matched all instructions and b) rods A and B are empty, so that all discs have been moved onto C.

(?!\3|\4)1

We simply check that neither \3 nor \4 can match (which is only the case if both are empty, because any actual disc would match) and that we can then match a 1 so that we haven't omitted any instructions.


答:
Common Lisp, 27 bytes

Tested on SBCL and ECL. For a portable approach, one should use trivial-features.

```<code>(lambda()'L #+big-endian'B)
</code>```

The #+ notation is a read-time condition, that reads the next form only if the conditional expression evaluates to true. Here the condition is the whole #+big-endian text which means that the test is satisfied if the :big-endian keyword belongs to the *FEATURES* list (a list which contains among other things platform-specific information). The following expression is 'B, which is either read or skipped according to the outcome of the test.
If your platform is big-endian and you write the above form in the REPL, it is exactly as if you wrote the following:

```<code>CL-USER>(lambda()'L 'B)
</code>```

 (NB.CL-USER> is the prompt)

A function's body is an implicit PROGN, meaning that only the evaluation of the last expression is returned. So the above actually returns symbol ̀B.
If however the read-time condition evaluates to false, the form reads as if you wrote:

```<code>CL-USER>(lambda()'L)
</code>```

... which simply returns symbol L.

Title: Big or Little Endian

Body:
Common Lisp, 27 bytes

Tested on SBCL and ECL. For a portable approach, one should use trivial-features.

(lambda()'L #+big-endian'B)

The #+ notation is a read-time condition, that reads the next form only if the conditional expression evaluates to true. Here the condition is the whole #+big-endian text which means that the test is satisfied if the :big-endian keyword belongs to the *FEATURES* list (a list which contains among other things platform-specific information). The following expression is 'B, which is either read or skipped according to the outcome of the test.
If your platform is big-endian and you write the above form in the REPL, it is exactly as if you wrote the following:

CL-USER>(lambda()'L 'B)

 (NB.CL-USER> is the prompt)

A function's body is an implicit PROGN, meaning that only the evaluation of the last expression is returned. So the above actually returns symbol ̀B.
If however the read-time condition evaluates to false, the form reads as if you wrote:

CL-USER>(lambda()'L)

... which simply returns symbol L.


答:
Perl, 28 24 characters (includes 1 for 'p' option)

```<code>s/./$&x(s!$&!$&!g>1)/eg
</code>```

Usage:

```<code>> perl -pe 's/./$&x(s!$&!$&!g>1)/eg'
helloworld
llool
</code>```

At first I thought I could do this with negative look-ahead and negative look-behind, but it turns out that negative look-behinds must have a fixed length. So I went for nested regexes instead. With thanks to mob for the $& tip.

Title: Removing unique elements from string

Body:
I came upon this question, because it seems to be very common use-case to find unique characters in string. But what if we want to get rid of them?

Input contains only lower case alphabets. Only letters from a to z are used. Input length may be from 1 to 1000 characters.

Example:

input: helloworld

output: llool

Objective: Shortest code wins

Language: Any of the top 20 of TIOBE languages

Body:
Perl, 28 24 characters (includes 1 for 'p' option)

s/./$&x(s!$&!$&!g>1)/eg

Usage:

> perl -pe 's/./$&x(s!$&!$&!g>1)/eg'
helloworld
llool

At first I thought I could do this with negative look-ahead and negative look-behind, but it turns out that negative look-behinds must have a fixed length. So I went for nested regexes instead. With thanks to mob for the $& tip.


答:
Mathematica, 22

```<code>{B,L}[[$ByteOrdering]]
</code>```

This probably breaks some rule about not using a built-in function but I'm not really interested in rube goldberging an alternative.

Title: Big or Little Endian

Body:
Mathematica, 22

{B,L}[[$ByteOrdering]]

This probably breaks some rule about not using a built-in function but I'm not really interested in rube goldberging an alternative.


问:
Convert exponents into ASCII art

Task

Your task is to convert strings like this:

```<code>abc^d+ef^g + hijk^l - M^NO^P (Ag^+)
</code>```

To strings like this:

```<code>   d   g       l    N P    +
abc +ef  + hijk  - M O  (Ag )
</code>```

Which is an approximation to abcd+efg + hijkl - MNOP (Ag+)

In words, raise the characters directly next to carets to the upper line, one character for one caret.

Specs

Extra trailing whitespaces in the output are allowed.

No chained carets like m^n^o will be given as input.

A caret will not be followed immediately by a space or by another caret.

A caret will not be preceded immediately by a space.

All carets will be preceded by at least one character and followed by at least one character.

The input string will only contain printable ASCII characters (U+0020 - U+007E)

Instead of two lines of output, you are allowed to output an array of two strings.

To those who speak regex: the input string will match this regex:

```<code>/^(?!.*(\^.\^|\^\^|\^ | \^))(?!\^)[ -~]*(?<!\^)$/
</code>```

Leaderboard

var QUESTION_ID=86647,OVERRIDE_USER=48934;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

```

答:
Coconut, <s>122 114</s> 96 bytes

Edit: <s>8</s> 26 bytes down with help from Leaky Nun.

def e(s,l)=''==l and s or"^"==l[0]and l[1]+e(s+' ',l[2:])or' '+e(s+l[0],l[1:])
f=print..e$('\n')
```
<p>So as I learned today python has a ternary conditional operator, or in fact two of them: <code><true_expr> if <condition> else <false_expr></code> and <code><condition> and <true_expr> or <false_expr></code> with last one coming with one char less.<br />
A python conform version can be ideoned.</p>
<hr />
<p>First attempt:</p>
<pre class="lang-py prettyprint-override"><code>def e(s,l):
 case l:
  match['^',c]+r:return c+e(s+' ',r)
  match[c]+r:return' '+e(s+c,r)
 else:return s
f=print..e$('\n')
</code>```

Calling with f("abc^d+ef^g + hijk^l - M^NO^P (Ag^+)") prints

```<code>   d   g       l    N P    +
abc +ef  + hijk  - M O  (Ag )
</code>```

Anyone tried golfing in coconut yet? It enriches python with more functional programming concepts like the pattern matching and function concatenation (with ..) used above. As this is my first try at coconut, any tips would be appreciated.

This could definitely be shortened as any valid python code is also valid coconut and shorter python answers have been posted, however I tried to find a purely functional solution.

Title: Convert exponents into ASCII art

Body:
Coconut, <s>122 114</s> 96 bytes

Edit: <s>8</s> 26 bytes down with help from Leaky Nun.

def e(s,l)=''==l and s or"^"==l[0]and l[1]+e(s+' ',l[2:])or' '+e(s+l[0],l[1:])
f=print..e$('\n')

So as I learned today python has a ternary conditional operator, or in fact two of them: <true_expr> if <condition> else <false_expr> and <condition> and <true_expr> or <false_expr> with last one coming with one char less.

A python conform version can be ideoned.

First attempt:

def e(s,l):
 case l:
  match['^',c]+r:return c+e(s+' ',r)
  match[c]+r:return' '+e(s+c,r)
 else:return s
f=print..e$('\n')

Calling with f("abc^d+ef^g + hijk^l - M^NO^P (Ag^+)") prints

   d   g       l    N P    +
abc +ef  + hijk  - M O  (Ag )

Anyone tried golfing in coconut yet? It enriches python with more functional programming concepts like the pattern matching and function concatenation (with ..) used above. As this is my first try at coconut, any tips would be appreciated.

This could definitely be shortened as any valid python code is also valid coconut and shorter python answers have been posted, however I tried to find a purely functional solution.


答:
MATL, <s>38</s> <s>36</s> 34 bytes

```<code>FT+"@llI$YO]q&:t8XO!s9\~)9#1$ZOZps
</code>```

Try it online! Or verify all test cases (takes a few seconds).

Explanation

```<code>FT+     % Input year implicitly. Add [0 1] element-wise. Gives array with input year
        % and next year
"       % For each of those two years
  @     %   Push year
  ll    %   Push 1 twice. This indicates January 1.
  I$YO  %   Convert year, month, day to serial date number
]       % End for each. We now have the serial date number for January 1 of the input
        % year and that of the following year
q       % Subtract 1 to the latter, to yield December 31 of the input year
&:      % Inclusive range between those two numbers. This gives an array of serial date
        % numbers for the whole input year
t       % Push another copy of that array
8XO     % Convert to date string with format 8. This gives weekday as "Mon", "Tue" etc.
        % The result is a 3-column 2D char array, where each row is a day
!s      % Transpose, sum of each column. 'Wed' gives 288 (sum of ASCII codes)
9\~     % 288 gives 0 modulo 9, and is the only weekday to do so. So we compute modulo 9
        % and negate. This gives true for Wednesdays, false for the rest
)       % Apply as logical index into the array of serial date numbers
9#1$ZO  % Array of month numbers corresponding to those serial date numbers
Zp      % Array that contains true for prime numbers, false for the rest
s       % Sum of array. Display implicitly
</code>```

Title: Prime Wednesdays

Body:
Prime Wednesdays

Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime Wednesday. For consistency use the Gregorian calendar for all dates.

Input

The input to your program/function will be a year (eg 2016) and is flexible. The year will be an integer between 1912 and 2233 inclusive.

Output

The output is also flexible and should be the number of prime Wednesdays (eg 18).

Scoring

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

Test Cases

input     -> output

  --------------------

  1912  ->   19

  1914  ->   16

  1984  ->   17

  1996  ->   19

  2063  ->   19

  2150  ->   16

  2199  ->   18

  2233  ->   18

Body:
MATL, <s>38</s> <s>36</s> 34 bytes

FT+"@llI$YO]q&:t8XO!s9\~)9#1$ZOZps

Try it online! Or verify all test cases (takes a few seconds).

Explanation

FT+     % Input year implicitly. Add [0 1] element-wise. Gives array with input year
        % and next year
"       % For each of those two years
  @     %   Push year
  ll    %   Push 1 twice. This indicates January 1.
  I$YO  %   Convert year, month, day to serial date number
]       % End for each. We now have the serial date number for January 1 of the input
        % year and that of the following year
q       % Subtract 1 to the latter, to yield December 31 of the input year
&:      % Inclusive range between those two numbers. This gives an array of serial date
        % numbers for the whole input year
t       % Push another copy of that array
8XO     % Convert to date string with format 8. This gives weekday as "Mon", "Tue" etc.
        % The result is a 3-column 2D char array, where each row is a day
!s      % Transpose, sum of each column. 'Wed' gives 288 (sum of ASCII codes)
9\~     % 288 gives 0 modulo 9, and is the only weekday to do so. So we compute modulo 9
        % and negate. This gives true for Wednesdays, false for the rest
)       % Apply as logical index into the array of serial date numbers
9#1$ZO  % Array of month numbers corresponding to those serial date numbers
Zp      % Array that contains true for prime numbers, false for the rest
s       % Sum of array. Display implicitly


答:
php, 141 bytes

```<code><?php $a=$argv;for($t=[$f=range($a[++$i],1),[],[]];($r=array_pop($t[$a[++$i]]))&&$r<(end($t[$a[++$i]])?:$r+1);)$t[$a[$i]][]=$r;echo$t[2]==$f;
</code>```

Command line script, takes input as the height then a series of array indexes (0 indexed) e.g. 1 0 2 or 2 0 1 0 2 1 2 for the 1 or 2 height shortest test cases.

Echos 1 on true cases and nothing on false ones.

Gives 2 notices and 1 warning so needs to be run in an environment that silences those.

Title: Verify a Tower of Hanoi solution

Body:
If you don't know what the Tower of Hanoi is, I'll explain it briefly: There are three rods and some discs each of which has a different size. In the beginning all discs are on the first tower, in sorted order: The biggest one is at the bottom, the smallest at the top. The goal is to bring all the discs over to the third rod. Sounds easy? Here's the catch: You can't place a disc on top of a disc that is smaller than the other disc; you can only hold one disc in your hand at a time to move them to another rod and you can only place the disc on rods, not on the table, you sneaky bastard.

ascii example solution:

```<code>  A      B      C
  |      |      |
 _|_     |      |
__|__    |      |

  A      B      C
  |      |      |
  |      |      |
__|__   _|_     |

  A      B      C
  |      |      |
  |      |      |
  |     _|_   __|__

  A      B      C
  |      |      |
  |      |     _|_
  |      |    __|__
</code>```

Challenge

There are three rods called A,B and C. (You can also call them 1,2 and 3 respectivly if that helps) In the beginning all n discs are on rod A(1).

Your challenge is to verify a solution for the tower of hanoi. You'll need to make sure that:

In the end all n discs are on rod C(3).

For any given disc at any given state there is no smaller disc below it.

No obvious errors like trying to take discs from an empty rod or moving discs to nonexistant rods.

(the solution does not have to be optimal.)

Input

Your program will receive two inputs:

The number of discs n (an integer)

The moves which are taken, which will consist of a set of tuples of: (tower to take the currently uppermost disc from),(tower to take this disc to) where each tuple refers to a move. You can choose how they are represented. For example something like the following ways of representing the solution for n=2 which I've drawn in ascii above. (I'll use the first one in the test cases, because it's easy on the eyes):

"A->B ; A->C ; B->C"

[("A","B"),("A","C"),("B","C")]

[(1,2),(1,3),(2,3)]

"ABACBC"

[1,2,1,3,2,3]

Output

Truthy, if the conditions that can be found under "challenge" hold.

Falsy, if they don't.

Test cases:

True:

```<code>n=1, "A->C"

n=1, "A->B ; B->C"

n=2, "A->B ; A->C ; B->C"

n=2, "A->C ; C->B ; A->C ; B->C"

n=2, "A->C ; A->B ; C->B ; B->A ; B->C ; A->C"

n=3, "A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; A->C"

n=4, "A->B ; A->C ; B->C ; A->B ; C->A ; C->B ; A->B ; A->C ; B->C ; B->A ; C->A ; B->C ; A->B ; A->C ; B->C"
</code>```

False:

3rd one suggested by @MartinEnder, 7th by @Joffan

```<code>n=1, "A->B"

n=1, "C->A"

n=2, "A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; A->C"

n=2, "A->B ; A->C ; C->B"

n=2, "A->C ; A->B ; C->B ; B->A"

n=2, "A->C ; A->C"

n=3, "A->B ; A->D; A->C ; D->C ; A->C"

n=3, "A->C ; A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; A->C"

n=3, "A->C ; A->B ; C->B ; A->B ; B->C ; B->A ; B->C ; A->C"

n=3, "A->C ; A->B ; C->B ; A->C ; B->A ; B->C ; C->B"

n=4, "A->B ; A->C ; B->C ; A->B ; C->A ; C->B ; A->B ; A->C ; B->C ; B->A ; C->A ; B->C ; A->B ; A->C"

n=4, "A->B ; A->B ; A->B ; A->C ; B->C ; B->C ; B->C"
</code>```

This is code-golf, shortest solution wins. Standard rules and loopholes apply. No batteries included.

Body:
php, 141 bytes

<?php $a=$argv;for($t=[$f=range($a[++$i],1),[],[]];($r=array_pop($t[$a[++$i]]))&&$r<(end($t[$a[++$i]])?:$r+1);)$t[$a[$i]][]=$r;echo$t[2]==$f;

Command line script, takes input as the height then a series of array indexes (0 indexed) e.g. 1 0 2 or 2 0 1 0 2 1 2 for the 1 or 2 height shortest test cases.

Echos 1 on true cases and nothing on false ones.

Gives 2 notices and 1 warning so needs to be run in an environment that silences those.


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

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

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

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

Test cases:

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

Or as CSV:

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

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Hexagony, 9 bytes

?{?+@/!'/

Embiggened:

```<code>   ? { ?
  + @ / !
 ' / . . .
  . . . .
   . . .
</code>```

Try it online!

Interestingly, this is only 2 bytes shorter than (what I think is) the most basic version, which is:

```<code>   ? { ?
  . . . .
 ' + ! @ .
  . . . .
   . . .
</code>```

This requires 7 commands, of which one (?, which reads a number from STDIN). Now, as 7 is the 2nd centered hexagonal number, it might be able to fit inside a hexagon of side length 2, if you can use a single flow control character and reuse the ?. I've not been able to figure that out yet though :o(

Title: Add two numbers

Body:
Hexagony, 9 bytes

?{?+@/!'/

Embiggened:

   ? { ?
  + @ / !
 ' / . . .
  . . . .
   . . .

Try it online!

Interestingly, this is only 2 bytes shorter than (what I think is) the most basic version, which is:

   ? { ?
  . . . .
 ' + ! @ .
  . . . .
   . . .

This requires 7 commands, of which one (?, which reads a number from STDIN). Now, as 7 is the 2nd centered hexagonal number, it might be able to fit inside a hexagon of side length 2, if you can use a single flow control character and reuse the ?. I've not been able to figure that out yet though :o(


答:
Dyalog APL, 30, but soon to be 16 bytes

⍎w⊣((w∊f)/w)←¯1⌽w∩f←'+-×÷'⊣w←⍞
```
<p>Ungolfed, explained version:</p>
<p><code>w ← ⍞</code> Prompt for input (of the expression) and assign to <em>w</em></p>
<p><code>f ← '+-×÷'</code> assign the symbols to <em>f</em></p>
<p><code>((w ∊ f) / w) ← ¯1 ⌽ w ∩ f</code> using membership of <em>f</em> as mask, reassign those positions in <em>w</em> to the corresponding character in the cyclic 1-step-right rotated intersection of <em>w</em> and <em>f</em> (the symbols)</p>
<p><code>⍎w</code> execute the modified expression</p>
<p>There is no special handling of minus/negative, because APL uses the distinct symbols <code>-</code> and <code>¯</code>.</p>
<p>See the rotation of symbols on TryAPL!</p>
<p>In version 16 it will be much shorter as a function which takes the expression as argument:</p>
<pre class="lang-apl prettyprint-override"><code>⍎¯1∘⌽@(∊∘'+-×÷')
</code>```

Execute ⍎ the negative one step rotation ¯1∘⌽ done on @ members of the symbols set (∊∘'+-×÷').

Title: CAPTCHA Modified by Evil Mathematician

Body:
Dyalog APL, 30, but soon to be 16 bytes

⍎w⊣((w∊f)/w)←¯1⌽w∩f←'+-×÷'⊣w←⍞

Ungolfed, explained version:

w ← ⍞ Prompt for input (of the expression) and assign to w

f ← '+-×÷' assign the symbols to f

((w ∊ f) / w) ← ¯1 ⌽ w ∩ f using membership of f as mask, reassign those positions in w to the corresponding character in the cyclic 1-step-right rotated intersection of w and f (the symbols)

⍎w execute the modified expression

There is no special handling of minus/negative, because APL uses the distinct symbols - and ¯.

See the rotation of symbols on TryAPL!

In version 16 it will be much shorter as a function which takes the expression as argument:

⍎¯1∘⌽@(∊∘'+-×÷')

Execute ⍎ the negative one step rotation ¯1∘⌽ done on @ members of the symbols set (∊∘'+-×÷').


答:
C, 34 bytes

This assumes ASCII character encoding

```<code>main(a){putchar(66+10**(char*)a);}
</code>```

Call without argument.

Explanation:

On call, a will be 1. *(char*)a accesses the first byte of a, which on little-endian platforms will be 1, on big-endian platforms will be 0.

On big-endian platforms, this code will therefore pass 66 + 10*0 = 66 to putchar. 66 is the ASCII code for B. On little-endian platforms, it will pass 66 + 10*1 = 76, which is the ASCII code for L.

Title: Big or Little Endian

Body:
Write a program or function that outputs an L if run on a little endian architecture or a B if run on a big endian architecture. Lower case output l or b is also acceptable.

There is no input.

Scoring is code golf, so the code with the fewest bytes wins.

Edit: As per the comments below, I am clarifying that the entry must be able to run on either architecture.

I believe that there is only one answer that this affects, and that answer has clearly indicated that this is the case.

Body:
C, 34 bytes

This assumes ASCII character encoding

main(a){putchar(66+10**(char*)a);}

Call without argument.

Explanation:

On call, a will be 1. *(char*)a accesses the first byte of a, which on little-endian platforms will be 1, on big-endian platforms will be 0.

On big-endian platforms, this code will therefore pass 66 + 10*0 = 66 to putchar. 66 is the ASCII code for B. On little-endian platforms, it will pass 66 + 10*1 = 76, which is the ASCII code for L.


答:
JavaScript (ES7), 154 bytes

f=
s=>[(s=s.replace(/(\(*-?\d+\)*)(.?)/g,(_,d,o)=>a.push(d)&&o,a=[])).slice(-1),...s.slice(0,-1)].map((o,i)=>a[i]+=o)&&eval(a.join` `.replace(/\^/g,'**'))
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=i placeholder=Input><input id=o placeholder=Output><input type=button value=Go onclick=o.value=f(i.value);></code>```

Works by removing the values into a separate array so that the operators can be rotated.

Title: CAPTCHA Modified by Evil Mathematician

Body:
CAPTCHA Modified by Evil Mathematician

I accidentally incurred the wrath of an eccentric passive-aggressive mathematician. As part of his demented idea of payback, he modified the CAPTCHA system on my favorite website. Up until now, it would just ask a moderately challenging math question, like 3+2^4, and I would simply type the answer, 19, to verify that I am a human being. But now, thanks to my mathematical nemesis, the CAPTCHA questions are obnoxiously hard to calculate by hand and it keeps me from logging into my profile!

From what I can tell, this is what he has done. The CAPTCHA images seem to still be the same, but the way it calculates the correct answer has changed. It takes the expression displayed in the image and rotates the operations. You wouldn't believe how long it took me to figure this out T__T.

Because of this fiasco, I need a program/function that takes in one of these expressions as a string, evaluates it and returns the result so that I can log onto my website! To make this a game, fewest bytes win.

Ok, you have the idea, lets walk through an example. Suppose that the CAPTCHA displayed an image with 6+5+4-3*2/1. Normally the answer would 9. Instead, we now have to rotate the operations to the right and that gives us 6/5+4+3-2*1. At this point, we evaluate it to be 6.2

Summary

Steps to evaluate the string input:

Rotate the operation to the right

Evaluate the result

Specifications

Full program or function

Standard I/O

Takes an expression

Prints/Returns the evaluated result

After the op rotation

Possible operations are +-/*^

The negatives for negative numbers stays with the number when rotating

Follow the normal order of operations after the rotation is completed

Using integer division is allowed

Possible numbers are positive/negative integers

This does not include 0

Parentheses could be included, but aren't rotated

Test Cases

```<code>Input     -> Output
1+3       -> 4
7+6       -> 13
1+1-2     -> 2
3*4+2     -> 11
-7^4      -> -2401
3*7+1-3   -> -1
-9+4/4    -> 1.75
(4*1)+8   -> 40
1+2-3*4/5 -> -16.5
1+-2*3    -> 1
3*4--2    -> 11
30-2/7    -> 8
120*3-4+10-> 122
(13^-12)+11 -> 1
</code>```

Update

[16-07-28] Fixed typo in last test case. I had posted the expression after rotating it once >___> , so that rotating a second time gave an incorrect answer. It is fixed now! Thanks to @sintax!

[16-08-13] Removed broke test case. Thanks again to @sintax!

Body:
JavaScript (ES7), 154 bytes

f=
s=>[(s=s.replace(/(\(*-?\d+\)*)(.?)/g,(_,d,o)=>a.push(d)&&o,a=[])).slice(-1),...s.slice(0,-1)].map((o,i)=>a[i]+=o)&&eval(a.join` `.replace(/\^/g,'**'))
;

<input id=i placeholder=Input><input id=o placeholder=Output><input type=button value=Go onclick=o.value=f(i.value);>

Works by removing the values into a separate array so that the operators can be rotated.


答:
Ruby, 71 bytes

This answer is based on xnor's Python 2 answer.

->n{a,=t=[1];(s=t;a+=1;(t=s+t.map{|z|z*a};n/=a)while n%a<1)while n>1;t}
```

<p>A same-length alternative is:</p>

<pre class="lang-ruby prettyprint-override"><code>->n{a,=t=[1];(a+=1;(t+=t.map{|z|z*a};n/=a)while n%a<1)while n>1;t.uniq}
</code>```

Ungolfing:

def f(num)
  factor = 1
  list = [1]
  while num != 1
    s = list
    factor += 1
    while num % factor == 0
      list = s + list.map{|z| z*factor}
      num /= factor
    end
  end
  return list
end

def g(num)
  factor = 1
  list = [1]
  while num != 1
    factor += 1
    while num % factor == 0
      list += list.map{|z| z*factor}
      num /= factor
    end
  end
  return list.uniq
end
```

Title: Sort a number's divisors by prime factorization

Body:
Given an input of an integer \$n ≥ 2\$, output a list of its divisors sorted by the
exponents in their prime factorizations, in ascending order, ordering first by
the largest prime, then by the second largest, and so on.

As an example, take the integer \$72\$, which is \$2^3\cdot3^2\$. It has
the divisors

```<code>1     3^0 · 2^0
2     3^0 · 2^1
3     3^1 · 2^0
4     3^0 · 2^2
6     3^1 · 2^1
8     3^0 · 2^3
9     3^2 · 2^0
12    3^1 · 2^2
18    3^2 · 2^1
24    3^1 · 2^3
36    3^2 · 2^2
72    3^2 · 2^3
</code>```

When sorted in ascending order by the exponents on the prime factors, with
larger primes taking priority, this becomes

```<code>1     3^0 · 2^0
2     3^0 · 2^1
4     3^0 · 2^2
8     3^0 · 2^3
3     3^1 · 2^0
6     3^1 · 2^1
12    3^1 · 2^2
24    3^1 · 2^3
9     3^2 · 2^0
18    3^2 · 2^1
36    3^2 · 2^2
72    3^2 · 2^3
</code>```

Note that the list is sorted first by the order of the exponent of 3, and then
by the exponent of 2. You can also think of this as reading from left to right
and top to bottom across the following grid:

```<code>        2^0  2^1  2^2  2^3

3^0     1    2    4    8
3^1     3    6    12   24
3^2     9    18   36   72
</code>```

Test cases:

```<code>2 => 1 2
72 => 1 2 4 8 3 6 12 24 9 18 36 72
101 => 1 101
360 => 1 2 4 8 3 6 12 24 9 18 36 72 5 10 20 40 15 30 60 120 45 90 180 360
3780 => 1 2 4 3 6 12 9 18 36 27 54 108 5 10 20 15 30 60 45 90 180 135 270 540 7 14 28 21 42 84 63 126 252 189 378 756 35 70 140 105 210 420 315 630 1260 945 1890 3780
30030 => 1 2 3 6 5 10 15 30 7 14 21 42 35 70 105 210 11 22 33 66 55 110 165 330 77 154 231 462 385 770 1155 2310 13 26 39 78 65 130 195 390 91 182 273 546 455 910 1365 2730 143 286 429 858 715 1430 2145 4290 1001 2002 3003 6006 5005 10010 15015 30030
65536 => 1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536
74088 => 1 2 4 8 3 6 12 24 9 18 36 72 27 54 108 216 7 14 28 56 21 42 84 168 63 126 252 504 189 378 756 1512 49 98 196 392 147 294 588 1176 441 882 1764 3528 1323 2646 5292 10584 343 686 1372 2744 1029 2058 4116 8232 3087 6174 12348 24696 9261 18522 37044 74088
</code>```

Since this is code-golf, the shortest code in bytes wins.

Body:
Ruby, 71 bytes

This answer is based on xnor's Python 2 answer.

->n{a,=t=[1];(s=t;a+=1;(t=s+t.map{|z|z*a};n/=a)while n%a<1)while n>1;t}

A same-length alternative is:

->n{a,=t=[1];(a+=1;(t+=t.map{|z|z*a};n/=a)while n%a<1)while n>1;t.uniq}

Ungolfing:

def f(num)
  factor = 1
  list = [1]
  while num != 1
    s = list
    factor += 1
    while num % factor == 0
      list = s + list.map{|z| z*factor}
      num /= factor
    end
  end
  return list
end

def g(num)
  factor = 1
  list = [1]
  while num != 1
    factor += 1
    while num % factor == 0
      list += list.map{|z| z*factor}
      num /= factor
    end
  end
  return list.uniq
end


答:
AWK - 11 bytes

The code:

```<code>{$0=$1+$2}1
</code>```

Can run as:

```<code>awk '{$0=$1+$2}1' <<< "98.342 77.123"
</code>```

Could also store the code in a file sum.awk and run as:

```<code>awk -f sum.awk <<< "98.342 77.123"
</code>```

If you wanted a program that wouldn't require knowing that you were using awk, you could create a file sum that looks like:

```<code>#!/bin/awk -f
{$0=$1+$2}1
</code>```

Assuming of course that the awk executable is located at /bin/awk.
If this file is made executable, it could simply be run as:

```<code> sum <<< "98.342 77.123"
</code>```

or

```<code>echo "98.342 77.123" | sum
</code>```

Or place the numbers in a file, DATA, and run as:

```<code>sum DATA
</code>```

A tiny bit of explanation. $0 represents a single line of input that is also automatically split into numbered fields.  This line is then overwritten by the assignment.  The lone 1 acts as a label that always evaluates to true and its default action is to simply print the current $0.

Title: Add two numbers

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

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

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

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

Test cases:

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

Or as CSV:

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

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
AWK - 11 bytes

The code:

{$0=$1+$2}1

Can run as:

awk '{$0=$1+$2}1' <<< "98.342 77.123"

Could also store the code in a file sum.awk and run as:

awk -f sum.awk <<< "98.342 77.123"

If you wanted a program that wouldn't require knowing that you were using awk, you could create a file sum that looks like:

#!/bin/awk -f
{$0=$1+$2}1

Assuming of course that the awk executable is located at /bin/awk.
If this file is made executable, it could simply be run as:

 sum <<< "98.342 77.123"

or

echo "98.342 77.123" | sum

Or place the numbers in a file, DATA, and run as:

sum DATA

A tiny bit of explanation. $0 represents a single line of input that is also automatically split into numbered fields.  This line is then overwritten by the assignment.  The lone 1 acts as a label that always evaluates to true and its default action is to simply print the current $0.


答:
J, 12 characters

Having entered a valid Perl answer, here's an invalid (language not in the TIOBE top 20) answer.

```<code>a=:#~1<+/@e.
</code>```

Usage:

```<code>   a 'helloworld'
llool
</code>```

Declares a verb a which outputs only non unique items.

Title: Removing unique elements from string

Body:
I came upon this question, because it seems to be very common use-case to find unique characters in string. But what if we want to get rid of them?

Input contains only lower case alphabets. Only letters from a to z are used. Input length may be from 1 to 1000 characters.

Example:

input: helloworld

output: llool

Objective: Shortest code wins

Language: Any of the top 20 of TIOBE languages

Body:
J, 12 characters

Having entered a valid Perl answer, here's an invalid (language not in the TIOBE top 20) answer.

a=:#~1<+/@e.

Usage:

   a 'helloworld'
llool

Declares a verb a which outputs only non unique items.


问:
Count sum of all digits
This challenge is to write a program or script which counts the sum of all digits within the integers from 1 up to and including a given number.

Input, one positive integer.
Output, the sum of digits in that number and all smaller numbers.

Examples:

```<code>Input: 5
Integer Sequence: 1, 2, 3, 4, 5
Sum of Digits: 1 + 2 + 3 + 4 + 5 = 15

Input: 12
Integer Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
Sum of Digits: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 + 1 + 1 + 1 + 2 = 51
</code>```

To be clear, this is to count a sum of the digits - not the integers. For single-digit inputs, this will be the same. However, inputs larger than 10 will have different responses. This would be an incorrect response:

```<code>Input: 12
Output: 78
</code>```

Another example, to show the difference:

```<code>Input: 10

Integer Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Sum of Integers (INCORRECT RESPONSE): 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55

Digit Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0
Sum of Digits (CORRECT RESPONSE): 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 = 46
</code>```

A larger test case (CORRECT RESPONSE):

```<code>Input: 1000000
Output: 27000001
</code>```

Rules & Guidelines:

Submitted code must be a complete program or script - not just a function. If the code requires includes, imports, etc., they must be included in the posted code.

The number must be input by the user - not hard-coded. Input may be received as a command-line argument, file, stdin, or any other means by which your language can take user input.

The code must be able to properly handle inputs at least up to (2^64)-1.

The code should only output the sum.

Submitted programs & scripts should be user-friendly and not wasteful of computer resources (e.g.: they should not declare insanely-large arrays to hold every character). There is no strict bonus or penalty for this, but please be good programmers.

Scoring:

Primary scoring mechanism is by code length. Lower scores are better. The following bonuses and penalties also apply:

-25 Bonus if your code can handle all positive numbers, for example: 1234567891234567891234564789087414984894900000000

-50 Bonus if your code can handle simple expressions, for example 55*96-12. To qualify for this bonus, the code should handle + - / * (addition, subtraction, division, multiplication) operators and enforce order of operations. Division is regular integer division.

The given example (55*96-12) evaluates to 5268. Your code should return the same for either of those inputs - correct answer is 81393.

-10 Bonus if your code qualifies for the -50 bonus and can handle the ^ (exponent) operator.

-100 Bonus if your code qualifies for the -50 bonus and does not use eval or similar to handle expressions.

+300 Penalty if your code relies upon any web resources.

答:
Java, 145 bytes

```<code>class X{public static void main(String[]a){long n=Long.parseLong(a[0]),s=0,i,z;for(i=1;i<=n;i++)for(z=i;z>0;z/=10)s+=z%10;System.out.print(s);}}
</code>```

Tried to do with bonuses, but it turns out it wasn't worth it.

Title: Count sum of all digits

Body:
Java, 145 bytes

class X{public static void main(String[]a){long n=Long.parseLong(a[0]),s=0,i,z;for(i=1;i<=n;i++)for(z=i;z>0;z/=10)s+=z%10;System.out.print(s);}}

Tried to do with bonuses, but it turns out it wasn't worth it.


答:
PowerShell v3+, <s>99</s> 95 bytes

Brute force approach --

```<code>param($y)(1..12|%{$m=$_;2,3,5,7,11,13,17,19,23,29,31|?{(date "$m-$_-$y").DayofWeek-eq3}}).Count
</code>```

Takes input $y, loops from 1 to 12, stores the month temporarily into $m, then loops over every prime from 2 to 31. For each of those, we construct a Get-Date of that particular day, then select only those with DayOfWeek -equal to 3 (i.e., Wednesday). Encapsulates that all in a parens to formulate an array, and takes the .Count thereof.

Alternatively, mathematical approach --

PowerShell v3+, 105 bytes

```<code>param($y)(16,19,18,20,16,18,19)[($a=(date "1-1-$y").DayOfWeek)]+(1,-3,0,1,2)[$y%5]*($a-in0,2,3,4)*!($y%4)
</code>```

Winds up being just a hair longer than the brute force approach, but I'm including it here since it may be beneficial to others.

Again takes input $y as the year. This time we're performing strictly math operations based on the first day of the year. We first calculate what day of the week that is, and store that into $a for use later. That indexes into the first array, which gets us the number that is usually correct. We have to add to that a second index based on whether it's a potential leap year, whether it's a Sunday, Tuesday, Wednesday, or Thursday, and based on what the year is.

This is based on the following observation. The first column is what day of week January 1st is, the second is the usual output. Unless the year is one of the middle numbers, then it's the number in parens instead. The final column describes how the %5 indexing works.

```<code>Jan-1 -> #  ... Except if $y=       (then it's this number) | $y % 5 =
Sun   -> 16 ... 1928 1956 1984 etc. (17)                    |    3
Mon   -> 19
Tue   -> 18 ... 1924 1952 1980 etc. (20)                    |    4
Wed   -> 20 ... 1936 1964 1992 etc. (17)                    |    1
Thur  -> 16 ... 1920 1948 1976 etc. (17)                    |    0
Fri   -> 18
Sat   -> 19
</code>```

Note: Both of these assume en-us is the current PowerShell setting for culture/date information. The date formatting and DayOfWeek number may need to be adjusted accordingly for other culture variants.

Title: Prime Wednesdays

Body:
Prime Wednesdays

Your task is to count the number of Wednesdays that fall on a prime day of the month in a particular year. For instance, 7-13-16 is a prime Wednesday. For consistency use the Gregorian calendar for all dates.

Input

The input to your program/function will be a year (eg 2016) and is flexible. The year will be an integer between 1912 and 2233 inclusive.

Output

The output is also flexible and should be the number of prime Wednesdays (eg 18).

Scoring

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

Test Cases

input     -> output

  --------------------

  1912  ->   19

  1914  ->   16

  1984  ->   17

  1996  ->   19

  2063  ->   19

  2150  ->   16

  2199  ->   18

  2233  ->   18

Body:
PowerShell v3+, <s>99</s> 95 bytes

Brute force approach --

param($y)(1..12|%{$m=$_;2,3,5,7,11,13,17,19,23,29,31|?{(date "$m-$_-$y").DayofWeek-eq3}}).Count

Takes input $y, loops from 1 to 12, stores the month temporarily into $m, then loops over every prime from 2 to 31. For each of those, we construct a Get-Date of that particular day, then select only those with DayOfWeek -equal to 3 (i.e., Wednesday). Encapsulates that all in a parens to formulate an array, and takes the .Count thereof.

Alternatively, mathematical approach --

PowerShell v3+, 105 bytes

param($y)(16,19,18,20,16,18,19)[($a=(date "1-1-$y").DayOfWeek)]+(1,-3,0,1,2)[$y%5]*($a-in0,2,3,4)*!($y%4)

Winds up being just a hair longer than the brute force approach, but I'm including it here since it may be beneficial to others.

Again takes input $y as the year. This time we're performing strictly math operations based on the first day of the year. We first calculate what day of the week that is, and store that into $a for use later. That indexes into the first array, which gets us the number that is usually correct. We have to add to that a second index based on whether it's a potential leap year, whether it's a Sunday, Tuesday, Wednesday, or Thursday, and based on what the year is.

This is based on the following observation. The first column is what day of week January 1st is, the second is the usual output. Unless the year is one of the middle numbers, then it's the number in parens instead. The final column describes how the %5 indexing works.

Jan-1 -> #  ... Except if $y=       (then it's this number) | $y % 5 =
Sun   -> 16 ... 1928 1956 1984 etc. (17)                    |    3
Mon   -> 19
Tue   -> 18 ... 1924 1952 1980 etc. (20)                    |    4
Wed   -> 20 ... 1936 1964 1992 etc. (17)                    |    1
Thur  -> 16 ... 1920 1948 1976 etc. (17)                    |    0
Fri   -> 18
Sat   -> 19

Note: Both of these assume en-us is the current PowerShell setting for culture/date information. The date formatting and DayOfWeek number may need to be adjusted accordingly for other culture variants.


答:
Octave, 86 bytes

This is not fast, by any stretch. But that's not really the goal of a code golf, is it?

```<code>function r=p(y)r=0;for(i=698346:7:815953)d=datevec(i);r+=d(1)==y*isprime(d(3));end;end
</code>```

Octave can track dates by "date number" - number of days elapsed where Jan 1, 0 is day 1. By this measure, Jan 3, 1912 (the first Wednesday in our set) is day 698,346. Start there, and iterate through every 7th day (all Wednesdays) until the end of 2233, and add 1 if the year is the target year AND the month-day is prime.

Title: Prime Wednesdays

Body:
Octave, 86 bytes

This is not fast, by any stretch. But that's not really the goal of a code golf, is it?

function r=p(y)r=0;for(i=698346:7:815953)d=datevec(i);r+=d(1)==y*isprime(d(3));end;end

Octave can track dates by "date number" - number of days elapsed where Jan 1, 0 is day 1. By this measure, Jan 3, 1912 (the first Wednesday in our set) is day 698,346. Start there, and iterate through every 7th day (all Wednesdays) until the end of 2233, and add 1 if the year is the target year AND the month-day is prime.


问:
Do X without Y
Usually, it is said that "Doing X without Y" can be a trap to beginners writing challenges (source). However, I am cocky and think that I can definitely make an X without any Ys. Randomly. Oh yes, this will be good.

Challenge: Given an odd integer n greater than or equal to 1, output an ex of side length n made of random printable ascii characters sans "y" and "Y", and the space. All allowed characters must have a nonzero chance of occurring, but not necessarily uniform. This is a code-golf so the shortest code in bytes wins. You should, however, randomize each char--that is, the struts of the ex shouldn't be equal, unless if by chance.

The chars to appear

```<code>!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXZ[\]^_`abcdefghijklmnopqrstuvwxz{|}~"
</code>```

Constructing the ex

Side length 1:

```<code>x
</code>```

Side length 3:

```<code>x x
 x
x x
</code>```

Side length 5:

```<code>x   x
 x x
  x
 x x
x   x
</code>```

etc.

Example outputs

```<code>input
output
empty line

3
h 2
 ^
9 5

1
:

5
D   1
 W z
  W
 q j
W   1
</code>```

Example implementation

You do not need to handle invalid inputs.

function generate(sideLength){
    var result = "";
    var INNER = "@"
    for(var i = 0; i < sideLength; i++){
        var p = i < sideLength / 2 ? i : sideLength - i - 1;
        result += " ".repeat(p) + ((sideLength / 2 | 0) == p ? "" : INNER) + " ".repeat(Math.max(sideLength - p * 2 - 2, 0)) + INNER + "\n";
    }

    return result.replace(RegExp(INNER, "g"), function(e){
        let c = "y";
        while(c === "y" || c === "Y"){
            c = String.fromCharCode((Math.random() * 94) + 33 | 0);
        }
        return c;
    });
}

function print(v){
    output.innerHTML = "";
    output.appendChild(document.createTextNode(v));
}

function update(){
    var n = Number(input.value);
    if(n !== Math.floor(n)) print("error: " + n + " is not an integer.");
    else if(n % 2 === 0)    print("error: " + n + " is not odd.");
    else if(n < 1)          print("error: " + n + "is less than one.");
    else                    print(generate(n));
}

input.onchange = update;

update();```
<pre class="snippet-code-css lang-css prettyprint-override"><code>* {
  font-family: Consolas, monospace;
}

#output {
  white-space: pre;
}</code>```

<input id="input" min=1 value=1 type=Number>

```

Title: Do X without Y

Body:
MATLAB, 86 bytes

a=@(n)(char(changem(randi(92,n),33+[0:55 57:87 89:93],1:92).*(eye(n)|fliplr(eye(n)))))

Some examples:

>> a(1)

ans =

i

>> a(3)

ans =

~ {
 Z
* ^

>>a(5)

ans =

k   E
 | M
  }
 ] s
b   t

>> a(10)

ans =

Q        k
 +      a
  j    w
   X  [
    rO
    %3
   P  d
  K    q
 r      &
?        v


答:
Kotlin, 42 bytes

```<code>{(""+java.nio.ByteOrder.nativeOrder())[0]}
</code>```

Pretty straightforward. Uses "native" Java API. This is a lambda of () -> Char type.

String templates don't help much, unfortunately (still 42 bytes):

```<code>{"${java.nio.ByteOrder.nativeOrder()}"[0]}
</code>```

Function approach (48 bytes):

```<code>fun e()=(""+java.nio.ByteOrder.nativeOrder())[0]
</code>```

Title: Big or Little Endian

Body:
Kotlin, 42 bytes

{(""+java.nio.ByteOrder.nativeOrder())[0]}

Pretty straightforward. Uses "native" Java API. This is a lambda of () -> Char type.

String templates don't help much, unfortunately (still 42 bytes):

{"${java.nio.ByteOrder.nativeOrder()}"[0]}

Function approach (48 bytes):

fun e()=(""+java.nio.ByteOrder.nativeOrder())[0]


问:
Generate a Stack Exchange Favicon
Do you recognize the PPCG logo?
it looks like this, when you do an ascii art of it.

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

Now, In this Code Golf, You will make a code, that makes logos for other sites, similar to the PPCG logo.

What You should do

The "Shortened" string will be the string, with all upper case letters and numbers in the input string.(Which would be PPCG when the input string is Programming Puzzles & Code Golf)

The "Box" (

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

)
should fit the Shortened string perfectly.(No bigger or smaller)

Also the v part should be exactly 1 down and 1 left to the down right +.

Then output the box which has the shortened string in it.

Example

Stack Overflow:

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

Area 51:

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

Rules

You may assume that the input contains at least one digit or upper case letter.

Standard code-golf rules apply.

答:
APL, 52 49 bytes

```<code>{x⍪2⌽'v'↑⍨≢⍉x←⍉z⍪⍨(z←'+|+')⍪'-','-',⍨⍪⍵/⍨⍵∊⎕D,⎕A}
</code>```

(down to 49 thanks to the comment).

Title: Generate a Stack Exchange Favicon

Body:
APL, 52 49 bytes

{x⍪2⌽'v'↑⍨≢⍉x←⍉z⍪⍨(z←'+|+')⍪'-','-',⍨⍪⍵/⍨⍵∊⎕D,⎕A}

(down to 49 thanks to the comment).