问:
Print a 10 by 10 grid of asterisks

Background

This is a standard textbook example to demonstrate for loops.

This is one of the first programs I learnt when I started learning programming ~10 years ago.

Task

You are to print this exact text:

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

Specs

You may have extra trailing newlines.

You may have extra trailing spaces (U+0020) at the end of each line, including the extra trailing newlines.

Scoring

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

答:
Brachylog v1, 15 bytes

```<code>9ye,"*":9jw@Nw\
</code>```

Try it online!

Explanation

This exploits backtracking to loop; we create ten useless choice points at the beginning so that it writes ten times the string "**********\n".

```<code>9ye,         Pick a number between 0 and 9 (there are thus 10 choice points here)
"*":9j       Concatenate "*" 9 times to itself
w@Nw         Write that string and write a line break
\            False (trigger backtracking: pich another one of the ten numbers)
</code>```

Title: Print a 10 by 10 grid of asterisks

Body:
Brachylog v1, 15 bytes

9ye,"*":9jw@Nw\

Try it online!

Explanation

This exploits backtracking to loop; we create ten useless choice points at the beginning so that it writes ten times the string "**********\n".

9ye,         Pick a number between 0 and 9 (there are thus 10 choice points here)
"*":9j       Concatenate "*" 9 times to itself
w@Nw         Write that string and write a line break
\            False (trigger backtracking: pich another one of the ten numbers)


问:
Snakes all around

Challenge

The challenge is simple: print a snake.

You will get the length of the snake as input.

A snake of length 2 looks like this:

```<code>==(:)-
</code>```

A snake of length 7 looks like this:

```<code>=======(:)-
</code>```

In other words, the length of a snake is how many equal signs are before the head.

Usage

Let's say I made a C++ implementation and compiled it to ./getsnake.

I could run it like so:

```<code>$ ./getsnake 10
==========(:)-
</code>```

Clarifications

Standard loopholes are disallowed.

You can get input and output in any acceptable way.

You can assume all inputs given are positive integers.

You may write a function instead of a regular program.

答:
Cheddar, 15 bytes (noncompeting)

```<code>n->'='*n+'(:)-'
</code>```

A straightforward answer.

ContentLicense: CC BY-SA 3.0

Title: Snakes all around

Body:
Cheddar, 15 bytes (noncompeting)

n->'='*n+'(:)-'

A straightforward answer.


问:
Determine if a number is divisible by 13 (without using 13 itself)
Your challenge, should you choose to accept it, is to create a function or a program that outputs "yes" if a given number is divisible by 13 and outputs "no" if it isn't.

Rules:

 - You're not allowed to use the number 13 anywhere.

 - No cop-out synonyms for 13 either (like using 15 - 2).

 - Bonus points will be awarded for not using modulus, additional bonus for not using division.

Scoring:

 - Your score will be the number of bytes in your code (whitespace not included) multiplied by your bonus.

 - If you didn't use modulus, that bonus is 0.90; if you didn't use division, that bonus is 0.90.

 - If you didn't use either, that bonus is 0.80.

 - The lower your score, the better.

The input will always be an integer greater than 0 and less than 2^32.

Your output should be a simple "yes" or "no".

Clarifications:

 - Using some roundabout method of generating the number 13 for use is acceptable.  Simple arithmetic synonyms like (10 + 3) are not allowed.

 - The function or program must literally output "yes" or "no" for if the given number is divisible by 13.

 - As always, clever solutions are recommended, but not required.

答:
Common Lisp (71 bytes * 0.8) = 56.8

Simple recursion, really.

(defun w(x)(if(> x 14)(w(- x 13))(if(> 14 x 12)(print'yes)(print'no))))

Ungolfed:

```<code>(defun w (x)
  (if (> x 14)
      (w (- x 13))
      (if (> 14 x 12)
          (print 'yes)
          (print 'no))))
</code>```

Body:
Common Lisp (71 bytes * 0.8) = 56.8

Simple recursion, really.

(defun w(x)(if(> x 14)(w(- x 13))(if(> 14 x 12)(print'yes)(print'no))))

Ungolfed:

(defun w (x)
  (if (> x 14)
      (w (- x 13))
      (if (> 14 x 12)
          (print 'yes)
          (print 'no))))


Title: Snakes all around

Body:
Challenge

The challenge is simple: print a snake.

You will get the length of the snake as input.

A snake of length 2 looks like this:

```<code>==(:)-
</code>```

A snake of length 7 looks like this:

```<code>=======(:)-
</code>```

In other words, the length of a snake is how many equal signs are before the head.

Usage

Let's say I made a C++ implementation and compiled it to ./getsnake.

I could run it like so:

```<code>$ ./getsnake 10
==========(:)-
</code>```

Clarifications

Standard loopholes are disallowed.

You can get input and output in any acceptable way.

You can assume all inputs given are positive integers.

You may write a function instead of a regular program.

Body:
Neoscript, 15 bytes

{n|'=*n+"(:)-"}


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

Please post one tip per answer.

答:
Use ' (quote) as synonym for "" for single words.

Quote stops evaluation of symbol, allowing you to e.g. print it. Note that the casing is dependant on *print-case* variable (most of the time it's in the upcase).

```<code>(print"yes")
(print'yes) ; saved a byte!
</code>```

Title: Tips for golfing in Common Lisp

Body:
Use ' (quote) as synonym for "" for single words.

Quote stops evaluation of symbol, allowing you to e.g. print it. Note that the casing is dependant on *print-case* variable (most of the time it's in the upcase).

(print"yes")
(print'yes) ; saved a byte!


问:
My Squiggly Lamp
While moving, I broke my lamp. Now, I need a new one. It's your job to make me a lamp! I'm not sure what size I want, though I know I want a squiggly one.

Your program/function must take in a number input, and print out a lamp with that many squiggles/bumps.

Examples:

Input:2

Output:

```
/--\
 ()
 ()
/__\
```

Input:3

Output:

```
/--\
 ()
 ()
 ()
/__\
```

Input:5

Output:

```
/--\
 ()
 ()
 ()
 ()
 ()
/__\
```

Rules:

0 & negative numbers don't matter

To give the lamps (an this challenge) more of a variety, you must change the lamp shade.

They must be 4 characters wide and 1 character high.

They can be in any shape, including non-lamp-shade shapes.

They must not contain whitespace.

The base must stay the same.

You must show an example input & output with your lamp shade.

Shortest code wins!

Title: My Squiggly Lamp

Body:
Neoscript, 28 bytes

{n|"[~~]
"+" ()
"*n+"/--\\"}


问:
Keep nonzeros and their neighbours
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.

The challenge

Given an array of integer values, remove all zeros that are not flanked by some nonzero value.

Equivalently, an entry should be kept either if it's a nonzero or if it's a zero that is immediately close to a nonzero value.

The entries that are kept should maintain in the output the order they had in the input.

Example

Given

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0]
</code>```

the values that should be removed are marked with an x:

```<code>[2 0 4 -3 0 x 0 3 0 0 2 0 x]
</code>```

and so the output should be

```<code>[2 0 4 -3 0 0 3 0 0 2 0]
</code>```

Rules

The input array may be empty (and then the output should be empty too).

Input and output formats are flexible as usual: array, list, string, or anything that is reasonable.

Code golf, fewest best.

Test cases

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0] -> [2 0 4 -3 0 0 3 0 0 2 0]
[] -> []
[1] -> [1]
[4 3 8 5 -6] -> [4 3 8 5 -6]
[4 3 8 0 5 -6] -> [4 3 8 0 5 -6]
[0] -> []
[0 0] -> []
[0 0 0 0] -> []
[0 0 0 8 0 1 0 0] -> [0 8 0 1 0]
[-5 0 5] -> [-5 0 5]
[50 0] -> [50 0]
</code>```

答:
APL, 14 bytes

```<code>{⍵/⍨×3∨/0,⍵,0}
</code>```

Test:

```<code>      {⍵/⍨×3∨/0,⍵,0}2 0 4 ¯3 0 0 0 3 0 0 2 0 0
2 0 4 ¯3 0 0 3 0 0 2 0
</code>```

Explanation:

0,⍵,0: add a zero to the beginning and the end of ⍵

×3∨/: find the sign of the GCD of every group of three adjacent numbers (this will be 0 if they are all zero and 1 otherwise).

⍵/⍨: select all the items from ⍵ for which the result was 1.

Title: Keep nonzeros and their neighbours

Body:
APL, 14 bytes

{⍵/⍨×3∨/0,⍵,0}

Test:

      {⍵/⍨×3∨/0,⍵,0}2 0 4 ¯3 0 0 0 3 0 0 2 0 0
2 0 4 ¯3 0 0 3 0 0 2 0

Explanation:

0,⍵,0: add a zero to the beginning and the end of ⍵

×3∨/: find the sign of the GCD of every group of three adjacent numbers (this will be 0 if they are all zero and 1 otherwise).

⍵/⍨: select all the items from ⍵ for which the result was 1.


答:
Brain-Flak 142 bytes

Try it online!

```<code>(<()>)(()){{}([]<([]){{}({}<>)<>({}<>)<>({}<>)<>(<>({}<>)<>({}<>)<>({})<>){{}((<()>))}{}{}([][()])}{}{}<>{}([]){{}({}<>)<>([])}{}<>>[[]])}{}{}
</code>```

Explanation

```<code>(<()>)                    #Pad the top with an extra zero
(()){{}([]<...>[[]])}{}   #Until the stack height remains the same
 ([]){{}...([][()])}{}    #Until the stack height is one
  ({}<>)<>                #Move the top three to the other stack
  ({}<>)<>
  ({}<>)<>
  (...)                   #Push the sum of the top three
   <>({}<>)               #Move the second and third back
   <>({}<>)
   <>({})<>               #Leave the top of the stack
  {{}...}{}               #If the sum is not zero
   ((<()>))               #Add a buffer to the top of the stack
  {}                      #Pop the buffer/middle value
 {}                       #Remove extra zero
 <>                       #Switch to the off stack
 {}                       #Remove extra zero
 ([]){{}({}<>)<>([])}{}<> #Move the entire off stack back
</code>```

Title: Keep nonzeros and their neighbours

Body:
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.

The challenge

Given an array of integer values, remove all zeros that are not flanked by some nonzero value.

Equivalently, an entry should be kept either if it's a nonzero or if it's a zero that is immediately close to a nonzero value.

The entries that are kept should maintain in the output the order they had in the input.

Example

Given

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0]
</code>```

the values that should be removed are marked with an x:

```<code>[2 0 4 -3 0 x 0 3 0 0 2 0 x]
</code>```

and so the output should be

```<code>[2 0 4 -3 0 0 3 0 0 2 0]
</code>```

Rules

The input array may be empty (and then the output should be empty too).

Input and output formats are flexible as usual: array, list, string, or anything that is reasonable.

Code golf, fewest best.

Test cases

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0] -> [2 0 4 -3 0 0 3 0 0 2 0]
[] -> []
[1] -> [1]
[4 3 8 5 -6] -> [4 3 8 5 -6]
[4 3 8 0 5 -6] -> [4 3 8 0 5 -6]
[0] -> []
[0 0] -> []
[0 0 0 0] -> []
[0 0 0 8 0 1 0 0] -> [0 8 0 1 0]
[-5 0 5] -> [-5 0 5]
[50 0] -> [50 0]
</code>```

Body:
Brain-Flak 142 bytes

Try it online!

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

Explanation

(<()>)                    #Pad the top with an extra zero
(()){{}([]<...>[[]])}{}   #Until the stack height remains the same
 ([]){{}...([][()])}{}    #Until the stack height is one
  ({}<>)<>                #Move the top three to the other stack
  ({}<>)<>
  ({}<>)<>
  (...)                   #Push the sum of the top three
   <>({}<>)               #Move the second and third back
   <>({}<>)
   <>({})<>               #Leave the top of the stack
  {{}...}{}               #If the sum is not zero
   ((<()>))               #Add a buffer to the top of the stack
  {}                      #Pop the buffer/middle value
 {}                       #Remove extra zero
 <>                       #Switch to the off stack
 {}                       #Remove extra zero
 ([]){{}({}<>)<>([])}{}<> #Move the entire off stack back


问:
Write a program that uses all printable non-alphanumeric ASCII symbols
In particular, use each of these symbols at least once in your source code:

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

Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count (but their delimiters such as /**/ or "" do count).

The program should not perform any action. It just has to compile and do nothing when run.

If for some reason some of the symbols cannot be used in the language of your choice, explain that rigorously (what and why must be excluded).

Update: A few answers used symbols withing regular expressions. I'd consider this a bit problematic, it's the same thing as putting them into string literals or comments (that's why I put etc. in that requirement). Please try without this. I also updated the requirement above.

Update: Shortest code wins (tagged as code-golf). As suggested, we'll most likely need some tie-breaker criteria. I suggest that if there is a tie, the winning one is the one in which the ASCII symbols appear as much ordered as possible. Formally: Filter out the first occurrence of each of the listed symbols from a program. This will result in a permutation on the listed symbols. The program with less inversion number of its permutation wins.

Update: I'd be happy to see some/more solutions in regular/mainstream languages, such as C(++), Java, Scala, Haskell, etc.

答:
C# (91 characters)

```<code>#define a
class a{static int @Main(){return(char)1.1*""[0]/1%1-1+1!=1?1:~1^1>>1<<1&1+'\0';}}
</code>```

As far as I know, The $ character is not a valid character outside string literals, so I didn't use it in my answer.

EDIT : Thanks to Peter Taylor, I shortened the code.

Body:
C# (91 characters)

#define a
class a{static int @Main(){return(char)1.1*""[0]/1%1-1+1!=1?1:~1^1>>1<<1&1+'\0';}}

As far as I know, The $ character is not a valid character outside string literals, so I didn't use it in my answer.

EDIT : Thanks to Peter Taylor, I shortened the code.


问:
Print the Capitals without the Capitals
Whoa, whoa, whoa ... stop typing your program. No, I don't mean "print ABC...." I'm talking the capitals of the United States.

Specifically, print all the city/state combinations given in the following list

in any order

with your choice of delimiters (e.g., Baton Rouge`LA_Indianapolis`IN_... is acceptable), so long as it's unambiguous which words are cities, which are states, and which are different entries

without using any of ABCDEFGHIJKLMNOPQRSTUVWXYZ in your source code

Output should be to STDOUT or equivalent.

EDIT - Whoops!

<edit>

While typing up the list from memory (thanks to the Animaniacs, as described below), I apparently neglected Washington, DC, which isn't a state capital, but is in the song, and is sometimes included in "lists of capitals" (like the Mathematica answer below). I had intended to include that city in this list, but missed it, somehow. As a result, answers that don't have that city won't be penalized, and answers that do have that city won't be penalized, either. Essentially, it's up to you whether Washington, DC is included in your ouput or not. Sorry about that, folks!

</edit>

```<code>Baton Rouge, LA
Indianapolis, IN
Columbus, OH
Montgomery, AL
Helena, MT
Denver, CO
Boise, ID
Austin, TX
Boston, MA
Albany, NY
Tallahassee, FL
Santa Fe, NM
Nashville, TN
Trenton, NJ
Jefferson, MO
Richmond, VA
Pierre, SD
Harrisburg, PA
Augusta, ME
Providence, RI
Dover, DE
Concord, NH
Montpelier, VT
Hartford, CT
Topeka, KS
Saint Paul, MN
Juneau, AK
Lincoln, NE
Raleigh, NC
Madison, WI
Olympia, WA
Phoenix, AZ
Lansing, MI
Honolulu, HI
Jackson, MS
Springfield, IL
Columbia, SC
Annapolis, MD
Cheyenne, WY
Salt Lake City, UT
Atlanta, GA
Bismarck, ND
Frankfort, KY
Salem, OR
Little Rock, AR
Des Moines, IA
Sacramento, CA
Oklahoma City, OK
Charleston, WV
Carson City, NV
</code>```

(h/t to Animaniacs for the list of capitals)

Take a bonus of -20% if your submission doesn't explicitly have the numbers 65 through 90 or the number 1 in the code. Generating these numbers (e.g., a=5*13 or a="123"[0] or a=64;a++ or the like) is allowed under this bonus, explicitly having them (e.g., a=65 or a="1 23 456"[0]) is not.

Leaderboard

var QUESTION_ID=60650,OVERRIDE_USER=42963;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+(?:[.]\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

```

答:
Python 2, 639 bytes - 20% = 511.2

```<code>t="labaton rouge,inindianapolis,ohcolumbus,almontgomery,mthelena,codenver,idboise,txaustin,maboston,nyalbany,fltallahassee,nmsanta fe,tnnashville,njtrenton,mojefferson,varichmond,sdpierre,paharrisburg,meaugusta,riprovidence,dedover,nhconcord,vtmontpelier,cthartford,kstopeka,mnsaint paul,akjuneau,nelincoln,ncraleigh,wimadison,waolympia,azphoenix,milansing,hihonolulu,msjackson,ilspringfield,sccolumbia,mdannapolis,wycheyenne,utsalt lake city,gaatlanta,ndbismarck,kyfrankfurt,orsalem,arlittle rock,iades moines,casacramento,okoklahoma city,wvcharleston,nvcarson city".split(",");print[(t[n][:2].upper(),t[n][2:].title())for n in range(50)]
</code>```

The version bellow (675 bytes) has ''.join([w.capitalize()for w in t[n][2:].split()]) in it, which I just discovered can be replace by .title(), and is an anonymous function. In both answers, the state abbreviations are attached to the capitals.

```<code>lambda t="labaton rouge,inindianapolis,ohcolumbus,almontgomery,mthelena,codenver,idboise,txaustin,maboston,nyalbany,fltallahassee,nmsanta fe,tnnashville,njtrenton,mojefferson,varichmond,sdpierre,paharrisburg,meaugusta,riprovidence,dedover,nhconcord,vtmontpelier,cthartford,kstopeka,mnsaint paul,akjuneau,nelincoln,ncraleigh,wimadison,waolympia,azphoenix,milansing,hihonolulu,msjackson,ilspringfield,sccolumbia,mdannapolis,wycheyenne,utsalt lake city,gaatlanta,ndbismarck,kyfrankfurt,orsalem,arlittle rock,iades moines,casacramento,okoklahoma city,wvcharleston,nvcarson city".split(","):[(t[n][:2].upper(),''.join([w.capitalize()for w in t[n][2:].split()]))for n in range(50)]
</code>```

Title: Print the Capitals without the Capitals

Body:
Python 2, 639 bytes - 20% = 511.2

t="labaton rouge,inindianapolis,ohcolumbus,almontgomery,mthelena,codenver,idboise,txaustin,maboston,nyalbany,fltallahassee,nmsanta fe,tnnashville,njtrenton,mojefferson,varichmond,sdpierre,paharrisburg,meaugusta,riprovidence,dedover,nhconcord,vtmontpelier,cthartford,kstopeka,mnsaint paul,akjuneau,nelincoln,ncraleigh,wimadison,waolympia,azphoenix,milansing,hihonolulu,msjackson,ilspringfield,sccolumbia,mdannapolis,wycheyenne,utsalt lake city,gaatlanta,ndbismarck,kyfrankfurt,orsalem,arlittle rock,iades moines,casacramento,okoklahoma city,wvcharleston,nvcarson city".split(",");print[(t[n][:2].upper(),t[n][2:].title())for n in range(50)]

The version bellow (675 bytes) has ''.join([w.capitalize()for w in t[n][2:].split()]) in it, which I just discovered can be replace by .title(), and is an anonymous function. In both answers, the state abbreviations are attached to the capitals.

lambda t="labaton rouge,inindianapolis,ohcolumbus,almontgomery,mthelena,codenver,idboise,txaustin,maboston,nyalbany,fltallahassee,nmsanta fe,tnnashville,njtrenton,mojefferson,varichmond,sdpierre,paharrisburg,meaugusta,riprovidence,dedover,nhconcord,vtmontpelier,cthartford,kstopeka,mnsaint paul,akjuneau,nelincoln,ncraleigh,wimadison,waolympia,azphoenix,milansing,hihonolulu,msjackson,ilspringfield,sccolumbia,mdannapolis,wycheyenne,utsalt lake city,gaatlanta,ndbismarck,kyfrankfurt,orsalem,arlittle rock,iades moines,casacramento,okoklahoma city,wvcharleston,nvcarson city".split(","):[(t[n][:2].upper(),''.join([w.capitalize()for w in t[n][2:].split()]))for n in range(50)]


问:
Fraction to exact decimal
Write a program or function that given two integers a, b outputs a string containing a decimal number representing the fraction a/b exactly.

If a/b is integer, simply output the value, without a decimal dot or leading zeroes:

```<code>123562375921304812375087183597 / 2777 -> 44494913907563850333124661
81 / 3 -> 27
-6 / 2 -> -3
</code>```

If a/b is not integer but has a finite representation in base 10, output the value without leading or trailing zeroes (except a single zero before the dot):

```<code>1 / 2 -> 0.5
3289323463 / -250000000 -> -13.157293852
</code>```

Finally, if and only if (so no 0.999...) a/b is not integer and does not have a finite representation, output the finite part followed by the repeating part in parenthesis. The repeating part must be as small as possible, and start as early as possible.

```<code>-1 / 3 -> -0.(3)
235 / 14 -> 16.7(857142)
123 / 321 -> 0.(38317757009345794392523364485981308411214953271028037)
355 / 113 -> 3.(1415929203539823008849557522123893805309734513274336283185840707964601769911504424778761061946902654867256637168)
</code>```

Your program must work for all above examples in under 10 seconds on a modern desktop PC. Smallest program in bytes wins.

答:
Perl 6, <s> 63 58 </s> 50 bytes

{->$a,$b {$a~"($b)"x?$b}(|($^a.FatRat/$^b).base-repeating(10))}
```

<pre class="lang-perl6 prettyprint-override"><code>{->\a,$b {a~"($b)"x?$b}(|($^a.FatRat/$^b).base-repeating)}
</code>```

{$/=($^a.FatRat/$^b).base-repeating;$0~"($1)"x?$1}
```

<p>Test it</p>

<p>If you don't care that it will only work with denominators that fit into a 64 bit integer it can be shortened to just 43 bytes:</p>

<pre class="lang-perl6 prettyprint-override"><code>{$/=($^a/$^b).base-repeating;$0~"($1)"x?$1}
</code>```

Expanded:

{
  # store in match variable so that we can
  # use ｢$0｣ and ｢$1｣
  $/ = (

    # turn the first value into a FatRat so that
    # it will continue to work for all Int inputs
    $^a.FatRat / $^b

  ).base-repeating;

  # ｢$0｣ is short for ｢$/[0]｣ which is the non-repeating part
  $0

  # string concatenated with
  ~

  # string repeat once if $1 is truthy (the repeating part)
  # otherwise it will be an empty Str
  "($1)" x ?$1
}
```

Title: Fraction to exact decimal

Body:
Perl 6, <s> 63 58 </s> 50 bytes

{->$a,$b {$a~"($b)"x?$b}(|($^a.FatRat/$^b).base-repeating(10))}

{->\a,$b {a~"($b)"x?$b}(|($^a.FatRat/$^b).base-repeating)}

{$/=($^a.FatRat/$^b).base-repeating;$0~"($1)"x?$1}

<a href="https://tio.run/nexus/perl6#xVLLbtswELzzK4hAaChUkrkPcskYTnPqBxQ9p1ActTDqOoYtBwnS9NfTVWQ7vrSHXqrTcjQ7s0vObtvZ@9jMp2an1edu20@N@fFo383vbjs7e3kqJjNXXLfNx7b/1PaT4vqmbG7abVdvunXX9ovVt2nhf525Asqzhw8FPL9o91WvQls7s85Y6wApRCQJGYE8JxhqnwQShSwVikhpZ5f2nJkzZ6DsJURKwRMRIMcI59UglKCikYkyInWscERqGhE4AL4JI0KYMiFxpKrG4Mdv3wTUQBDMaoZ7xaNH7RtH5YjqBhXwiENsxKUgwLj/qwtVhHDwdZQIRIJ4n4mDZKaMAYkicwo56SUkBkDgHAgFPCZPsteioE6wH4EaBwx6bxk9BcoJyfuUtC9IQFRfXS35QD6LOoGqsdqg@qeQ2IuXHDl6kJgzQPDMyCJJIvgImWP2GAOnKBhiJIGYhjFKzcB62a7s@/Eh9fj1bnN41frSFl@ssxffu0d3tVitd31Z2Yv7drnrXNE9rLt5392WtrRPutBia4couZ9H5pFyUjbrbrM0zy9/j4qd2CEswwR/jopJoDwaSCimjkPTcKjJGDgcNBzmLReKviXjlXuaC2Pqo@KYCaNTKgI8QKdxMDrvQEUYTf4xCUZDMOjDq@f/CMFv" rel="nofollow noreferrer" title="Perl 6 – TIO Nexus">Test it

If you don't care that it will only work with denominators that fit into a 64 bit integer it can be shortened to just 43 bytes:

{$/=($^a/$^b).base-repeating;$0~"($1)"x?$1}

Expanded:

{
  # store in match variable so that we can
  # use ｢$0｣ and ｢$1｣
  $/ = (

    # turn the first value into a FatRat so that
    # it will continue to work for all Int inputs
    $^a.FatRat / $^b

  ).base-repeating;

  # ｢$0｣ is short for ｢$/[0]｣ which is the non-repeating part
  $0

  # string concatenated with
  ~

  # string repeat once if $1 is truthy (the repeating part)
  # otherwise it will be an empty Str
  "($1)" x ?$1
}


Title: Print a 10 by 10 grid of asterisks

Body:
Background

This is a standard textbook example to demonstrate for loops.

This is one of the first programs I learnt when I started learning programming ~10 years ago.

Task

You are to print this exact text:

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

Specs

You may have extra trailing newlines.

You may have extra trailing spaces (U+0020) at the end of each line, including the extra trailing newlines.

Scoring

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

Body:
Befunge '98, 31 bytes

a>:|>1++:9`#@_a,
v*'[^
>,v1
-v>


问:
Be respectful in the restroom
Of course, the SE network is very knowledgeable about how to be respectful in the restroom, but for those of you who need a recap, being respectful means flushing the toilet, etc. Most importantly, though, it means using the stall as far away from others as possible.

The challenge

Given a blueprint of a set of stalls with indications of which ones are in use as a string, you must return or print from a function or program where the most respectful place to do your business is.

The input

```<code> 0 1 2 3 4 5    <- The stall number which is not actually visible in the input.
| | |-| |-|-|   <- the stalls
</code>```

The stalls are numbered in ascending order from left to right. There will always be at least one empty stall. There can be up to 50 stalls in an input. You can also take the input as an array or string of 0s and 1s or booleans if you prefer to do so.

Stalls in use have - in them (in between the pipes).

The output

The most respectful stall to go to is the one that is on average farthest away from the ones in use. The distance between two stalls is the absolute value of the difference of the numbers above them.

Just to be clear: you are finding the average distance from all of the stalls—not just the neighboring ones.

You must output the lowest number of the most respectful stall to go to that is empty.

Examples

```<code>Input:
|-| |-| OR 101
Output:
1

Input:
| | |-| |-|-| OR 001011
Output:
0

Input:
|-| |-| | | | |-|-| OR 101000011
Output:
1

Input:
|-| | | | | |-|-| | | | | OR 100000110000
Output:
11

Input:
|-|-|-|-| | | | | | |-| OR 11110000001
Output:
9

Input:
|-| | OR 10
Output:
1

Input:
|-| | |-| OR 1001
Output:
1
</code>```

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

You can use 0 or 1 based indexing in your answer — whichever you prefer; if you use 1 based indexing, then you must say so explicitly in your answer.

答:
Jelly, 13 bytes

1-indexed.

```<code>³Tạ⁸S
JUÇÞḟTṪ
</code>```

Try it online!

Algorithm

Naive implementation of the question.

Title: Be respectful in the restroom

Body:
Jelly, 13 bytes

1-indexed.

³Tạ⁸S
JUÇÞḟTṪ

Try it online!

Algorithm

Naive implementation of the question.


答:
Java "only" <s>270 200 196 187 196 138 148</s> 146 bytes!

saved <s> 4 13</s> countless bytes thanks to Leaky Nun! <s>1 byte thanks to Micheal</s>
Golfed

int m(boolean[]b){int r=0,l=b.length,i,j,k=0,z=r;for(i=0;i<l;i++){if(b[i])for(j=0,k=0;j<l;j++)if(!b[j])k+=i>j?i-j:j-i;if(k>z){r=i;z=k;}}return r;}
```
<p>Ungolfed</p>
<pre class="lang-java prettyprint-override"><code>int m(int[] s) {
        int l=s.length,i,j=0,k=0;
    boolean[] b = new boolean[l];
    int[] a = new int[l];
    //see what stalls are open
    for (i = 0; i < s.length; i++) {
        if (s[i] == 0){
            b[i] = true;
        }
    }
    //assign the sum of distance to the a[]
    for (i = 0; i < l; i++) {
        if (b[i]) {
            for (j = 0; j < l; j++) {
                if (!b[j]) {
                    a[i]+= Math.abs(i - j);
                }
            }
        }
    }
    //find the stall the greatest distance away breaking ties based on the furthest left
    for (i = 0; i < l; i++) {
        if (b[i] && (a[i] > k || k == 0)) {
            k = a[i];
            j=i;
        }
    }
    //return the index
    return j;
}
</code>```

input as an boolean array where true implies an open stall.

Title: Be respectful in the restroom

Body:
Of course, the SE network is very knowledgeable about how to be respectful in the restroom, but for those of you who need a recap, being respectful means flushing the toilet, etc. Most importantly, though, it means using the stall as far away from others as possible.

The challenge

Given a blueprint of a set of stalls with indications of which ones are in use as a string, you must return or print from a function or program where the most respectful place to do your business is.

The input

```<code> 0 1 2 3 4 5    <- The stall number which is not actually visible in the input.
| | |-| |-|-|   <- the stalls
</code>```

The stalls are numbered in ascending order from left to right. There will always be at least one empty stall. There can be up to 50 stalls in an input. You can also take the input as an array or string of 0s and 1s or booleans if you prefer to do so.

Stalls in use have - in them (in between the pipes).

The output

The most respectful stall to go to is the one that is on average farthest away from the ones in use. The distance between two stalls is the absolute value of the difference of the numbers above them.

Just to be clear: you are finding the average distance from all of the stalls—not just the neighboring ones.

You must output the lowest number of the most respectful stall to go to that is empty.

Examples

```<code>Input:
|-| |-| OR 101
Output:
1

Input:
| | |-| |-|-| OR 001011
Output:
0

Input:
|-| |-| | | | |-|-| OR 101000011
Output:
1

Input:
|-| | | | | |-|-| | | | | OR 100000110000
Output:
11

Input:
|-|-|-|-| | | | | | |-| OR 11110000001
Output:
9

Input:
|-| | OR 10
Output:
1

Input:
|-| | |-| OR 1001
Output:
1
</code>```

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

You can use 0 or 1 based indexing in your answer — whichever you prefer; if you use 1 based indexing, then you must say so explicitly in your answer.

Body:
Java "only" <s>270 200 196 187 196 138 148</s> 146 bytes!

saved <s> 4 13</s> countless bytes thanks to Leaky Nun! <s>1 byte thanks to Micheal</s>
Golfed

int m(boolean[]b){int r=0,l=b.length,i,j,k=0,z=r;for(i=0;i<l;i++){if(b[i])for(j=0,k=0;j<l;j++)if(!b[j])k+=i>j?i-j:j-i;if(k>z){r=i;z=k;}}return r;}

Ungolfed

int m(int[] s) {
        int l=s.length,i,j=0,k=0;
    boolean[] b = new boolean[l];
    int[] a = new int[l];
    //see what stalls are open
    for (i = 0; i < s.length; i++) {
        if (s[i] == 0){
            b[i] = true;
        }
    }
    //assign the sum of distance to the a[]
    for (i = 0; i < l; i++) {
        if (b[i]) {
            for (j = 0; j < l; j++) {
                if (!b[j]) {
                    a[i]+= Math.abs(i - j);
                }
            }
        }
    }
    //find the stall the greatest distance away breaking ties based on the furthest left
    for (i = 0; i < l; i++) {
        if (b[i] && (a[i] > k || k == 0)) {
            k = a[i];
            j=i;
        }
    }
    //return the index
    return j;
}

input as an boolean array where true implies an open stall.


问:
Can you outgolf me? (Cops section)

Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

Python 2, 16 bytes, score = 15 / 16 = 0.9375

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

More information can be found here.

Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

Rules

The task you need to do is an OEIS sequence of your choice.

Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).

Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).

In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.

Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)

Input and output are both in decimal (base 10)

Leaderboard

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

Uncracked submissions

 Language	 Score	 User

Sort by: score creation

Safe submissions

 Language	 Score	 User

```

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

答:
M, 9 bytes, score 0.6667 (6 / 9) [cracked]

```<code>r©0+’Ac®Ḅ
</code>```

A tad cheaty since M and Jelly are quite similar, but allowed by the rules. @miles' crack to my Jelly answer doesn't work in M; it lacks the œċ atom.

This calculates sequence A119259. Try it online!

Title: Can you outgolf me? (Cops section)

Body:
M, 9 bytes, score 0.6667 (6 / 9) [cracked]

r©0+’Ac®Ḅ

A tad cheaty since M and Jelly are quite similar, but allowed by the rules. @miles' crack to my Jelly answer doesn't work in M; it lacks the œċ atom.

This calculates sequence A119259. Try it online!


答:
Perl 6 (43 chars)

Let's define a infix operator with a rather unusual name:

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

It's not a literal nor a literal in a RE or anything hidden in a comment. You don't believe me? Running the following program will output "2":

```<code>sub infix:<!"#$%&'()*+,-./:;=?@[]^_´\|~>($a, $b){ $a + $b }
say 1 !"#$%&'()*+,-./:;=?@[]^_´\|~ 1;
</code>```

But I'm quite sure you nitpickers will extend the rules further to exclude redefinition of the language itself to make us perl lubbers unhappy. :(

Title: Write a program that uses all printable non-alphanumeric ASCII symbols

Body:
In particular, use each of these symbols at least once in your source code:

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

Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count (but their delimiters such as /**/ or "" do count).

The program should not perform any action. It just has to compile and do nothing when run.

If for some reason some of the symbols cannot be used in the language of your choice, explain that rigorously (what and why must be excluded).

Update: A few answers used symbols withing regular expressions. I'd consider this a bit problematic, it's the same thing as putting them into string literals or comments (that's why I put etc. in that requirement). Please try without this. I also updated the requirement above.

Update: Shortest code wins (tagged as code-golf). As suggested, we'll most likely need some tie-breaker criteria. I suggest that if there is a tie, the winning one is the one in which the ASCII symbols appear as much ordered as possible. Formally: Filter out the first occurrence of each of the listed symbols from a program. This will result in a permutation on the listed symbols. The program with less inversion number of its permutation wins.

Update: I'd be happy to see some/more solutions in regular/mainstream languages, such as C(++), Java, Scala, Haskell, etc.

Body:
Perl 6 (43 chars)

Let's define a infix operator with a rather unusual name:

sub infix:<!"#$%&'()*+,-./:;=?@[]^_´\|~>{}

It's not a literal nor a literal in a RE or anything hidden in a comment. You don't believe me? Running the following program will output "2":

sub infix:<!"#$%&'()*+,-./:;=?@[]^_´\|~>($a, $b){ $a + $b }
say 1 !"#$%&'()*+,-./:;=?@[]^_´\|~ 1;

But I'm quite sure you nitpickers will extend the rules further to exclude redefinition of the language itself to make us perl lubbers unhappy. :(


答:
Perl 84 + 3 (-alp flags) = 87 bytes

for$i(0..$#F){$t=0;map{$t+=abs($i-$_)*$F[$_]}0..$#F;($m,$_)=($t,$i)if$m<$t&&!$F[$i]}
```

<p>Needs <code>-alp</code> flags to run. Takes a string of 1 and 0 separated by spaces as input. For instance :</p>

```perl -alpe '$m=0;for$i(0..$#F){$t=0;map{$t+=abs($i-$_)*$F[$_]}0..$#F;($m,$_)=($t,$i)if$m<$t&&!$F[$i]}' <<< "1 0 1
0 0 1 0 1 1
1 0 1 0 0 0 0 1 1
1 0 0 0 0 0 1 1 0 0 0 0
1 1 1 1 0 0 0 0 0 0 1
1 0"
```

Note that I added $m=0 at the begining, but that's only to test it on multiple entries.

Title: Be respectful in the restroom

Body:
Perl 84 + 3 (-alp flags) = 87 bytes

for$i(0..$#F){$t=0;map{$t+=abs($i-$_)*$F[$_]}0..$#F;($m,$_)=($t,$i)if$m<$t&&!$F[$i]}

Needs -alp flags to run. Takes a string of 1 and 0 separated by spaces as input. For instance :

perl -alpe '$m=0;for$i(0..$#F){$t=0;map{$t+=abs($i-$_)*$F[$_]}0..$#F;($m,$_)=($t,$i)if$m<$t&&!$F[$i]}' <<< "1 0 1
0 0 1 0 1 1
1 0 1 0 0 0 0 1 1
1 0 0 0 0 0 1 1 0 0 0 0
1 1 1 1 0 0 0 0 0 0 1
1 0"

Note that I added $m=0 at the begining, but that's only to test it on multiple entries.


问:
Find the repetend of the decimal representation!
In this challenge 2 years ago, we found the period of a unit fraction (1/n where n is a natural number).

Now, your task is to write a program/function to find the repetend of a unit fraction.

The repetend is the part of the decimal expansion which repeats infinitely, like:

The decimal representation of 1/6 is 0.16666..., then the repetend is 6.

The decimal representation of 1/11 is 0.090909..., then the repetend is 09.

The decimal representation of 1/28 is 0.0357142857142857142857..., then the repetend is 571428.

Specs

Input in any reasonable format.

Output the repetend in decimal, string or list.

For 1/7 (0.142857142857...), you must output 142857 instead of 428571.

For 1/13 (0.076923076923076923...), you must output 076923 instead of 76923.

No brute force, please.

Testcases

```<code>Input    Output
1        0
2        0
3        3
7        142857
13       076923
17       0588235294117647
28       571428
70       142857
98       102040816326530612244897959183673469387755
9899     000101020305081321345590463683200323264976260228305889483786241034447924032730578846348115971310233356904737852308313971108192746742095161127386604707546216789574704515607637135064147893726639054449944438832205273259925244974239822204263056874431760783917567431053641781998181634508536215779371653702394181230427315890493989291847661379937367410849580765733912516415799575714718658450348520052530558642287099707041115264168097787655318719062531568845337912920497019901
</code>```

Scoring

This is code-golf. Shortest solution in bytes win.

No answer would be accepted, because the goal is not to find the language capable of producing the shortest solution, but the shortest solution in each language.

Leaderboard

var QUESTION_ID=78850,OVERRIDE_USER=42854;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

```

Body:
Perl 6, 37 bytes

{(1.FatRat/$_).base-repeating[1]||~0}
~0 max (1.FatRat/*).base-repeating[1]

If you don't care that it will only work with denominators that fit into a 64 bit integer you can remove the method call to .FatRat.

Explanation:

# return ｢"0"｣ if ｢.base-repeating｣ would return ｢""｣
~0

# ｢&infix<max>｣ returns the numerically largest value
# or it's first value if they are numerically equal
max

(
  # turn 1 into a FatRat so it will work
  # with denominators of arbitrary size
  1.FatRat

  # divided by
  /

  # the input
  *

# get the second value from calling the
# method ｢.base-repeating｣
).base-repeating[1]

Test:

#! /usr/bin/env perl6
use v6.c;
use Test;

my &code = ~0 max (1.FatRat/*).base-repeating[1];
# stupid highlighter */
# Perl has never had // or /* */ comments

my @tests = (
  1    => '0',
  2    => '0',
  3    => '3',
  6    => '6',
  7    => '142857',
  11   => '09',
  13   => '076923',
  17   => '0588235294117647',
  28   => '571428',
  70   => '142857',
  98   => '102040816326530612244897959183673469387755',
  9899 => '000101020305081321345590463683200323264976260228305889483786241034447924032730578846348115971310233356904737852308313971108192746742095161127386604707546216789574704515607637135064147893726639054449944438832205273259925244974239822204263056874431760783917567431053641781998181634508536215779371653702394181230427315890493989291847661379937367410849580765733912516415799575714718658450348520052530558642287099707041115264168097787655318719062531568845337912920497019901',
);

plan +@tests;

for @tests -> $_ ( :key($input), :value($expected) ) {
  is code($input), $expected, "1/$input";
}

1..12
ok 1 - 1/1
ok 2 - 1/2
ok 3 - 1/3
ok 4 - 1/6
ok 5 - 1/7
ok 6 - 1/11
ok 7 - 1/13
ok 8 - 1/17
ok 9 - 1/28
ok 10 - 1/70
ok 11 - 1/98
ok 12 - 1/9899


答:
MATL, 14 bytes

```<code>~ftGf!-|Xs&X>)
</code>```

Try it online!

Output is 1-based.

Explanation

```<code>~f     % Implicitly take input. Compute row vector with indices of zeros
t      % Duplicate that
Gf!    % Push input again. Compute column vector of indices of ones
-|     % Absolute differences with broadcast. Gives 2D array with all combinations
Xs     % Sum of each column
&X>    % Arg max. Gives the index of the first maximizer if there are several
)      % Index into row vector of indices of zeros. Implictly display
</code>```

Title: Be respectful in the restroom

Body:
MATL, 14 bytes

~ftGf!-|Xs&X>)

Try it online!

Output is 1-based.

Explanation

~f     % Implicitly take input. Compute row vector with indices of zeros
t      % Duplicate that
Gf!    % Push input again. Compute column vector of indices of ones
-|     % Absolute differences with broadcast. Gives 2D array with all combinations
Xs     % Sum of each column
&X>    % Arg max. Gives the index of the first maximizer if there are several
)      % Index into row vector of indices of zeros. Implictly display


问:
Slices of triangular alphabets
Given an input number n from 1 to 26 (or 0 to 25), output the alphabet reading left-to-right up to and including that corresponding letter, with a=1, b=2, c=3, .... The twist is the letters must also be repeated vertically corresponding to their position in the alphabet. Odd numbers (when 1-indexed) should be balanced across the horizontal line, while even numbers should alternate between favoring the top or bottom (you can choose which direction to go first). If you're 0-indexing, then swap odd/even in the previous sentence.

Worded another way -- if the alphabetical value of a letter ? is #, then there should be # copies of that letter in the output, all of them in the #th column. These letters should be evenly balanced above and below the horizontal line that has the a. If the letters cannot be balanced evenly, then alternate having the "extra" letter above and below that line.

Here are the first six outputs (n = 1,2,3,4,5,6, 1-indexed, choosing to alternate to the bottom first), separated by newlines, so you can see the pattern. Comments explaining the pattern start with #.

```<code>a         # On a line by itself

ab
 b        # The "extra" letter is below the horizontal

  c
abc       # The 'c' splits evenly
 bc

   d      # Because the 'b' was below, the extra 'd' must be above
  cd
abcd
 bcd

   de
  cde
abcde     # The 'e' balances
 bcde
    e

   def
  cdef
abcdef
 bcdef
    ef
     f    # Since the 'd' was above, the extra 'f' must be below
</code>```

(skip a few to n=26)

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

Rules

You can choose to output in uppercase or lowercase, but it must be consistent.

The output cannot have extraneous whitespace, except for an optional trailing newline.

Either a full program or a function are acceptable.

The input number can be taken via any suitable format.

Standard loopholes are forbidden.

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

答:
Python 2, 101 99 bytes

```<code>r=range(input())
for x in sorted(r,key=lambda x:x*-(x&2)):print bytearray([97+i,32][i<x]for i in r)
</code>```

xsot saved two bytes by realizing x*-(x&2) suffices as a sorting key — the bottom half of the resulting image is unaffected due to sorted guaranteeing a stable sort.

Title: Slices of triangular alphabets

Body:
Python 2, 101 99 bytes

r=range(input())
for x in sorted(r,key=lambda x:x*-(x&2)):print bytearray([97+i,32][i<x]for i in r)

xsot saved two bytes by realizing x*-(x&2) suffices as a sorting key — the bottom half of the resulting image is unaffected due to sorted guaranteeing a stable sort.


答:
Ruby, <s>79</s> <s>78</s> 76 + n flag = 77 bytes

Output is 0-based indexing. Input is STDIN line of 0's and 1's.

```<code>p (r=0...~/$/).max_by{|i|k=0;$_[i]>?0?0:r.map{|j|k+=$_[j]<?1?0:(j-i).abs};k}
</code>```

Title: Be respectful in the restroom

Body:
Ruby, <s>79</s> <s>78</s> 76 + n flag = 77 bytes

Output is 0-based indexing. Input is STDIN line of 0's and 1's.

p (r=0...~/$/).max_by{|i|k=0;$_[i]>?0?0:r.map{|j|k+=$_[j]<?1?0:(j-i).abs};k}


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

```<code>JạþTS×¬MḢ
</code>```

Uses 1-based indexing. Try it online! or verify all test cases.

How it works

```<code>JạþTS×¬MḢ  Main link. Argument: A (array of Booleans)

J          Yield all indices of A.
   T       Yield all truthy indices of A.
 ạþ        Compute the table of absolute differences.
    S      Compute the sums of all columns.
           For each index, this yields the sum of all distances to occupied stalls.
     ×¬    Multiply each sum by the logical NOT of the corresponding Boolean in A.
           This zeroes sums that correspond to occupied stalls.
       M   Maximal; yield an array of all indices of maximal sums.
        Ḣ  Head; extract the first index.
</code>```

Title: Be respectful in the restroom

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

JạþTS×¬MḢ

Uses 1-based indexing. Try it online! or verify all test cases.

How it works

JạþTS×¬MḢ  Main link. Argument: A (array of Booleans)

J          Yield all indices of A.
   T       Yield all truthy indices of A.
 ạþ        Compute the table of absolute differences.
    S      Compute the sums of all columns.
           For each index, this yields the sum of all distances to occupied stalls.
     ×¬    Multiply each sum by the logical NOT of the corresponding Boolean in A.
           This zeroes sums that correspond to occupied stalls.
       M   Maximal; yield an array of all indices of maximal sums.
        Ḣ  Head; extract the first index.


答:
Ruby, <s>87</s> 76 bytes

Threw this first draft quickly together, but in the meantime Value Ink had already posted an 80 byte Ruby answer...

edit: took off some bytes with help from Value Ink:

```<code>->a{(r=0...a.size).max_by{|i|a[i]?0:r.map{|j|a[j]?(i-j).abs: 0}.reduce(:+)}}
</code>```

It's an anonymous function that takes an array of truthy/falsy values, like for instance so:

f=->->a{(r=0...a.size).max_by{|i|a[i]?0:r.map{|j|a[j]?(i-j).abs: 0}.reduce(:+)}}
# Test case number 5:
p f[[1, 1, 1, 1, nil, nil, nil, nil, nil, nil, 1]] # => 9
```

Title: Be respectful in the restroom

Body:
Ruby, <s>87</s> 76 bytes

Threw this first draft quickly together, but in the meantime Value Ink had already posted an 80 byte Ruby answer...

edit: took off some bytes with help from Value Ink:

->a{(r=0...a.size).max_by{|i|a[i]?0:r.map{|j|a[j]?(i-j).abs: 0}.reduce(:+)}}

It's an anonymous function that takes an array of truthy/falsy values, like for instance so:

f=->->a{(r=0...a.size).max_by{|i|a[i]?0:r.map{|j|a[j]?(i-j).abs: 0}.reduce(:+)}}
# Test case number 5:
p f[[1, 1, 1, 1, nil, nil, nil, nil, nil, nil, 1]] # => 9


答:
Javascript ES6 - <s>98</s> <s>95</s> <s>91</s> <s>86</s> <s>84</s> 88 bytes

Edit: Seems that the leftmost-stall should be used in the case of a tie. Squared distances no longer work, reverted to absolute distance.

```<code>(r,x=0,f=g=>r.reduce(g,0))=>f((p,o,i)=>x<(o=f((p,c,j)=>p+c*!o*Math.abs(i-j)))?(x=o,i):p)
</code>```

Ungolfed:

```<code>(r,                            // string input
 x=0,                          // current max distance
 f=g=>r.reduce(g,0))=>         // iterator function
   f((p,o,i)=>                 // for each stall
     x<(o=f((p,c,j)=>          // iterate through all stalls and
       p+c*!o*Math.abs(i-j)))? //   calculate sum of distances from current stall
     (x=o,i):                  // if total dist is greater than x, update x, return index
     p)                        //   else return previous max index
</code>```

Test runs:

```<code>f=(r,x=0,f=g=>r.reduce(g,0))=>f((p,c,i)=>x<(c=+c?0:f((p,c,j)=>p+c*Math.abs(i-j)))?(x=c,i):p)
f([1,0,1])                   // 1
f([0,0,1,0,1,1])             // 0
f([1,0,1,0,0,0,0,1,1])       // 1
f([1,0,0,0,0,0,1,1,0,0,0,0]) // 11
f([1,1,1,1,0,0,0,0,0,0,1])   // 9
f([1,0])                     // 1
</code>```

Title: Be respectful in the restroom

Body:
Javascript ES6 - <s>98</s> <s>95</s> <s>91</s> <s>86</s> <s>84</s> 88 bytes

Edit: Seems that the leftmost-stall should be used in the case of a tie. Squared distances no longer work, reverted to absolute distance.

(r,x=0,f=g=>r.reduce(g,0))=>f((p,o,i)=>x<(o=f((p,c,j)=>p+c*!o*Math.abs(i-j)))?(x=o,i):p)

Ungolfed:

(r,                            // string input
 x=0,                          // current max distance
 f=g=>r.reduce(g,0))=>         // iterator function
   f((p,o,i)=>                 // for each stall
     x<(o=f((p,c,j)=>          // iterate through all stalls and
       p+c*!o*Math.abs(i-j)))? //   calculate sum of distances from current stall
     (x=o,i):                  // if total dist is greater than x, update x, return index
     p)                        //   else return previous max index

Test runs:

f=(r,x=0,f=g=>r.reduce(g,0))=>f((p,c,i)=>x<(c=+c?0:f((p,c,j)=>p+c*Math.abs(i-j)))?(x=c,i):p)
f([1,0,1])                   // 1
f([0,0,1,0,1,1])             // 0
f([1,0,1,0,0,0,0,1,1])       // 1
f([1,0,0,0,0,0,1,1,0,0,0,0]) // 11
f([1,1,1,1,0,0,0,0,0,0,1])   // 9
f([1,0])                     // 1


答:
Brainf*ck, 32 characters

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

Prints a smiley face (if your console can output ASCII symbol 1)

Yay, a Branf*ck solution that beats Golfscript! :P

If you insist on no output, just exchange the + and . :

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

Body:
Brainf*ck, 32 characters

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

Prints a smiley face (if your console can output ASCII symbol 1)

Yay, a Branf*ck solution that beats Golfscript! :P

If you insist on no output, just exchange the + and . :

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


Title: Be respectful in the restroom

Body:
J, 27 bytes

(#{:@-.~]/:[:+/]|@-/~#)i.@#

Online interpreter.


答:
Cheddar, 78 bytes

```<code>a->([[]]+a.map((e,i)->e|(i?a[i-1]:0)|(i-a.len+1?a[i+1]:0)?[e]:[])).reduce((+))
</code>```

Test suite.

Cheddar has no filter, so filtering is done by wrapping the elements we want and transforming the elements we don't want into empty arrays, and then concatenate everything.

For example, [0,0,0,8,0,1,0,0] becomes [[],[],[0],[8],[0],[1],[0],[]], and then the concatenated array would be [0,8,0,1,0].

Title: Keep nonzeros and their neighbours

Body:
Taken from this question at Stack Overflow. Thanks also to @miles and @Dada for suggesting test inputs that address some corner cases.

The challenge

Given an array of integer values, remove all zeros that are not flanked by some nonzero value.

Equivalently, an entry should be kept either if it's a nonzero or if it's a zero that is immediately close to a nonzero value.

The entries that are kept should maintain in the output the order they had in the input.

Example

Given

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0]
</code>```

the values that should be removed are marked with an x:

```<code>[2 0 4 -3 0 x 0 3 0 0 2 0 x]
</code>```

and so the output should be

```<code>[2 0 4 -3 0 0 3 0 0 2 0]
</code>```

Rules

The input array may be empty (and then the output should be empty too).

Input and output formats are flexible as usual: array, list, string, or anything that is reasonable.

Code golf, fewest best.

Test cases

```<code>[2 0 4 -3 0 0 0 3 0 0 2 0 0] -> [2 0 4 -3 0 0 3 0 0 2 0]
[] -> []
[1] -> [1]
[4 3 8 5 -6] -> [4 3 8 5 -6]
[4 3 8 0 5 -6] -> [4 3 8 0 5 -6]
[0] -> []
[0 0] -> []
[0 0 0 0] -> []
[0 0 0 8 0 1 0 0] -> [0 8 0 1 0]
[-5 0 5] -> [-5 0 5]
[50 0] -> [50 0]
</code>```

Body:
Cheddar, 78 bytes

a->([[]]+a.map((e,i)->e|(i?a[i-1]:0)|(i-a.len+1?a[i+1]:0)?[e]:[])).reduce((+))

<a href="http://cheddar.tryitonline.net/#code=dmFyIGYgPSBhLT4oW1tdXSthLm1hcCgoZSxpKS0-ZXwoaT9hW2ktMV06MCl8KGktYS5sZW4rMT9hW2krMV06MCk_W2VdOltdKSkucmVkdWNlKCgrKSkKcHJpbnQoZihbMiwwLDQsLTMsMCwwLDAsMywwLDAsMiwwLDBdKSkKcHJpbnQoZihbXSkpCnByaW50KGYoWzFdKSkKcHJpbnQoZihbNCwzLDgsNSwtNl0pKQpwcmludChmKFs0LDMsOCwwLDUsLTZdKSkKcHJpbnQoZihbMF0pKQpwcmludChmKFswLDBdKSkKcHJpbnQoZihbMCwwLDAsMF0pKQpwcmludChmKFswLDAsMCw4LDAsMSwwLDBdKSkKcHJpbnQoZihbLTUsMCw1XSkpCnByaW50KGYoWzUwLDBdKSk&input=&debug=on" rel="nofollow">Test suite.

Cheddar has no filter, so filtering is done by wrapping the elements we want and transforming the elements we don't want into empty arrays, and then concatenate everything.

For example, [0,0,0,8,0,1,0,0] becomes [[],[],[0],[8],[0],[1],[0],[]], and then the concatenated array would be [0,8,0,1,0].


答:
Pyth, 26 bytes

A perfect score for a challenge about alphabet.

```<code>j_C.e<u_G/k2.[.|1Q*hkbdQ<G
</code>```

Try it online!

Title: Slices of triangular alphabets

Body:
Given an input number n from 1 to 26 (or 0 to 25), output the alphabet reading left-to-right up to and including that corresponding letter, with a=1, b=2, c=3, .... The twist is the letters must also be repeated vertically corresponding to their position in the alphabet. Odd numbers (when 1-indexed) should be balanced across the horizontal line, while even numbers should alternate between favoring the top or bottom (you can choose which direction to go first). If you're 0-indexing, then swap odd/even in the previous sentence.

Worded another way -- if the alphabetical value of a letter ? is #, then there should be # copies of that letter in the output, all of them in the #th column. These letters should be evenly balanced above and below the horizontal line that has the a. If the letters cannot be balanced evenly, then alternate having the "extra" letter above and below that line.

Here are the first six outputs (n = 1,2,3,4,5,6, 1-indexed, choosing to alternate to the bottom first), separated by newlines, so you can see the pattern. Comments explaining the pattern start with #.

```<code>a         # On a line by itself

ab
 b        # The "extra" letter is below the horizontal

  c
abc       # The 'c' splits evenly
 bc

   d      # Because the 'b' was below, the extra 'd' must be above
  cd
abcd
 bcd

   de
  cde
abcde     # The 'e' balances
 bcde
    e

   def
  cdef
abcdef
 bcdef
    ef
     f    # Since the 'd' was above, the extra 'f' must be below
</code>```

(skip a few to n=26)

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

Rules

You can choose to output in uppercase or lowercase, but it must be consistent.

The output cannot have extraneous whitespace, except for an optional trailing newline.

Either a full program or a function are acceptable.

The input number can be taken via any suitable format.

Standard loopholes are forbidden.

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

Body:
Pyth, 26 bytes

A perfect score for a challenge about alphabet.

j_C.e<u_G/k2.[.|1Q*hkbdQ<G

Try it online!


答:
JavaScript (ES6), <s>87</s> <s>86</s> <s>82</s> 75 bytes

```<code>a=>a.map((u,i)=>u||(a.map((v,j)=>u+=v*(i>j?i-j:j-i)),u>x&&(x=d,r=i)),x=0)|r
</code>```

Takes a boolean array (true/false or 1/0). No point calculating the average distance since they're all using the same common factor, so just calculating the total distance for each stall and finding the first index of the highest one. Edit: Saved 1 byte by using * instead of &&. Saved 5 bytes by finding the highest distance manually based on a comment by @Dendrobium. Saved 7 bytes by reusing u as the pseudo-reduce accumulator based on a comment by @edc65.

Title: Be respectful in the restroom

Body:
Of course, the SE network is very knowledgeable about how to be respectful in the restroom, but for those of you who need a recap, being respectful means flushing the toilet, etc. Most importantly, though, it means using the stall as far away from others as possible.

The challenge

Given a blueprint of a set of stalls with indications of which ones are in use as a string, you must return or print from a function or program where the most respectful place to do your business is.

The input

```<code> 0 1 2 3 4 5    <- The stall number which is not actually visible in the input.
| | |-| |-|-|   <- the stalls
</code>```

The stalls are numbered in ascending order from left to right. There will always be at least one empty stall. There can be up to 50 stalls in an input. You can also take the input as an array or string of 0s and 1s or booleans if you prefer to do so.

Stalls in use have - in them (in between the pipes).

The output

The most respectful stall to go to is the one that is on average farthest away from the ones in use. The distance between two stalls is the absolute value of the difference of the numbers above them.

Just to be clear: you are finding the average distance from all of the stalls—not just the neighboring ones.

You must output the lowest number of the most respectful stall to go to that is empty.

Examples

```<code>Input:
|-| |-| OR 101
Output:
1

Input:
| | |-| |-|-| OR 001011
Output:
0

Input:
|-| |-| | | | |-|-| OR 101000011
Output:
1

Input:
|-| | | | | |-|-| | | | | OR 100000110000
Output:
11

Input:
|-|-|-|-| | | | | | |-| OR 11110000001
Output:
9

Input:
|-| | OR 10
Output:
1

Input:
|-| | |-| OR 1001
Output:
1
</code>```

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

You can use 0 or 1 based indexing in your answer — whichever you prefer; if you use 1 based indexing, then you must say so explicitly in your answer.

Body:
JavaScript (ES6), <s>87</s> <s>86</s> <s>82</s> 75 bytes

a=>a.map((u,i)=>u||(a.map((v,j)=>u+=v*(i>j?i-j:j-i)),u>x&&(x=d,r=i)),x=0)|r

Takes a boolean array (true/false or 1/0). No point calculating the average distance since they're all using the same common factor, so just calculating the total distance for each stall and finding the first index of the highest one. Edit: Saved 1 byte by using * instead of &&. Saved 5 bytes by finding the highest distance manually based on a comment by @Dendrobium. Saved 7 bytes by reusing u as the pseudo-reduce accumulator based on a comment by @edc65.


答:
ArnoldC, 171 bytes

```<code>IT'S SHOWTIME
HEY CHRISTMAS TREE i
YOU SET US UP 10
STICK AROUND i
TALK TO THE HAND "**********"
GET TO THE CHOPPER i
GET DOWN 1
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED
</code>```

Just for the fun of it. Nothing fancy going on here, just loops 10 times printing ********** each time.

Title: Print a 10 by 10 grid of asterisks

Body:
Background

This is a standard textbook example to demonstrate for loops.

This is one of the first programs I learnt when I started learning programming ~10 years ago.

Task

You are to print this exact text:

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

Specs

You may have extra trailing newlines.

You may have extra trailing spaces (U+0020) at the end of each line, including the extra trailing newlines.

Scoring

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

Body:
ArnoldC, 171 bytes

IT'S SHOWTIME
HEY CHRISTMAS TREE i
YOU SET US UP 10
STICK AROUND i
TALK TO THE HAND "**********"
GET TO THE CHOPPER i
GET DOWN 1
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

Just for the fun of it. Nothing fancy going on here, just loops 10 times printing ********** each time.


答:
Jelly, 25 bytes

```<code>RØaxŒgz⁶W€;ṚL‘$¡¥/Ṛ⁸H¤¡j⁷
</code>```

Try it online! or verify all test cases.

Title: Slices of triangular alphabets

Body:
Jelly, 25 bytes

RØaxŒgz⁶W€;ṚL‘$¡¥/Ṛ⁸H¤¡j⁷

Try it online! or verify all test cases.


问:
Convert xxd output to shellcode
Taking some output from xxd and turning it into usable shellcode by hand is no fun, so your job is to automate the process.

Rules

Your submission can be a function, lambda, script, or any reasonable equivalent of those. You may print the result, or if your submission is a function/lambda then you may also return it.

You program must take three arguments, the first being a string containing the output of xxd, ran with no arguments other than a filename, like this: xxd some_file. Here's an example of what the the first argument will look like:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Your need to take that middle section containing the bytes (the first 8 columns after the :) and turn it into shellcode by removing any whitespace, then putting a \x before each byte.

Here's what the output should be for the input above (ignoring any other arguments):

\x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e\x58\x58\x58\x58\x59\x59\x59\x59

You can assume the first argument will always be a valid xxd output, ran with no arguments other than the filename.

Your output should also be a string where the backslashes are literal backslashes, not used as escape characters. So when I say "\x65", I'm not talking about the byte 0x65, or even the letter "A". In code, it would be the string "\x65".

The second argument specifies where in the xxd output the shellcode should start, and the third specifies where it should end. If the third argument is -1, it will end at the end of xxd output. The second and third argument will also always be non negative, except for when the third is -1

Here are some test cases:

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: 7, Argument 3: e (these are both strings representing hexadecimal numbers)

Output: \xc9\xcd\x80\xeb\x16\x5b\x31\xc0

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: 0, Argument 3: 2e

Output: \x31\xc0\xb0\x46\x31\xdb\x31\xc9\xcd\x80\xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e

Argument 1:

```<code>00000000: 31c0 b046 31db 31c9 cd80 eb16 5b31 c088  1..F1.1.....[1..
00000010: 4307 895b 0889 430c b00b 8d4b 088d 530c  C..[..C....K..S.
00000020: cd80 e8e5 ffff ff2f 6269 6e2f 7368 4e58  ......./bin/shNX
00000030: 5858 5859 5959 59                        XXXYYYY
</code>```

Argument 2: a, Argument 3: -1

Output: \xeb\x16\x5b\x31\xc0\x88\x43\x07\x89\x5b\x08\x89\x43\x0c\xb0\x0b\x8d\x4b\x08\x8d\x53\x0c\xcd\x80\xe8\xe5\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68\x4e\x58\x58\x58\x58\x59\x59\x59\x59

The code with the least bytes wins. The winner will be announced in seven days, on August 15, 2016 (but submissions after then are still appreciated).

Update

Congrats to @Adnan to winning the challenge!

答:
Python 3.5, 125 bytes

```<code>import re
lambda s,b,e:re.sub(r'(\w\w)',r'\\x\1',re.sub(r'^.*?:|  .*$|\s','',s,0,8)[2*int(b,16):[2*int(e,16)+2,None][e<'0']])
</code>```

Ungolfed:

```<code>def f(s,b,e):
    b = 2*int(b,16)
    e = [2*int(e,16)+2,None][e<'0']
    x = re.sub(r'''(?v)   # verbose (not in golfed version)
            ^.*?:     # match begining of line to the ':'
           |  .*$     # or match '  ' to end of line
           |\s        # or match whitespace
           ''',
           '',        # replacement
           s,
           0,         # replace all matches
           re.M       # multiline mode
           )
    y = re.sub(r'(\w\w)', # match pairs of 'word' characters
           r'\\x\1',  # insert \x
            x[b:e])
    return y
</code>```

Title: Convert xxd output to shellcode

Body:
Python 3.5, 125 bytes

import re
lambda s,b,e:re.sub(r'(\w\w)',r'\\x\1',re.sub(r'^.*?:|  .*$|\s','',s,0,8)[2*int(b,16):[2*int(e,16)+2,None][e<'0']])

Ungolfed:

def f(s,b,e):
    b = 2*int(b,16)
    e = [2*int(e,16)+2,None][e<'0']
    x = re.sub(r'''(?v)   # verbose (not in golfed version)
            ^.*?:     # match begining of line to the ':'
           |  .*$     # or match '  ' to end of line
           |\s        # or match whitespace
           ''',
           '',        # replacement
           s,
           0,         # replace all matches
           re.M       # multiline mode
           )
    y = re.sub(r'(\w\w)', # match pairs of 'word' characters
           r'\\x\1',  # insert \x
            x[b:e])
    return y


答:
Python, 69 bytes, score = 0.97 (67÷69), cracked

```<code>f=lambda n:reduce(lambda x,y:x*y,range(1,n+1),1)
lambda n:f(n*2)/f(n)
</code>```

Computes A001813

Title: Can you outgolf me? (Cops section)

Body:
Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

Python 2, 16 bytes, score = 15 / 16 = 0.9375

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

More information can be found here.

Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

Rules

The task you need to do is an OEIS sequence of your choice.

Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).

Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).

In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.

Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)

Input and output are both in decimal (base 10)

Leaderboard

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

Uncracked submissions

 Language	 Score	 User

Sort by: score creation

Safe submissions

 Language	 Score	 User

```

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

Body:
Python, 69 bytes, score = 0.97 (67÷69), cracked

f=lambda n:reduce(lambda x,y:x*y,range(1,n+1),1)
lambda n:f(n*2)/f(n)

Computes A001813


问:
A tiny adventure
Text adventure games have a pretty set formula; there's a world composed of a series of rooms / spaces, the player can move around these rooms, and there are some items in the rooms. Items can be picked up by the player, put down, used to access other rooms (e.g. keys), and combined with other items to make new items.

Challenge

Your challenge is to write a text adventure runtime in the fewest bytes (code golf). To keep things simple, all you need to do is output a truthy or falsey value depending on whether a given series of commands would win a given game or not (no interactivity, no human friendly output, etc.)

Game Rules

The world is always composed of a corridor with 10 connected rooms. Each room requires a key to enter, but can be exited at any time without a key (so it's some kind of latch lock I guess);

The player begins in room 0, and wins if they ever enter room 9 (once they reach room 9 they can do whatever they like, including go to another room, and they will still have won);

Each room can contain any number of items;

There are up to 26 items, named A-Z, and no item will appear more than once in the world;

The player can pick up items from the current room and place them in their inventory (they can also drop items from their inventory into the current room);

The player's maximum inventory size is finite, and will be provided with the level details;

At the beginning of the game, the player's inventory is always empty;

There is no limit to the maximum number of items in a room (though the implicit limit would be 26, since that is the total number of items);

Items A-J are keys which can be used to enter rooms 0-9 (i.e. the player can move to room 0 if they have item A, to room 1 if they have B, etc. note that keys are not required to leave a room, and the player begins in room 0, so the key "A" is only required if the player wants to return to room 0);

Items in the player's inventory can be combined to create new items (which will be created in the player's inventory) — the permitted combinations will be provided with the level details;

Combining items consumes the original items (i.e. if one of the items was a key, it will no-longer be possible to use that key);

If the player tries to do something impossible (e.g. pick up an item which is not in the current room / drop an item they don't have / combine items they don't have / go to a room they don't have the key for), nothing happens and they can continue;

The player will never give a nonsense command (e.g. go to room 11).

So a simple game might look like this:

```<code>  v
+---+---+---+---+---+---+---+---+---+---+
| C |   | J |   |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|               CORRIDOR                |
+---------------------------------------+
Inventory capacity: 99
</code>```

Room 0 contains item "C" (which is the key to room 2). Room 2 contains item "J" (which is the key to room 9). The player can win the game by picking up C, moving to room 2, picking up J, then moving to room 9.

A more complex game might be:

```<code>  v
+---+---+---+---+---+---+---+---+---+---+
| C |   | X |YZ |   |   |   |   |   |   |
+---+---+---+---+---+---+---+---+---+---+
|               CORRIDOR                |
+---------------------------------------+
Inventory capacity: 10
C+X => D
Y+Z => J
</code>```

Now the player can win by picking up C, moving to room 2, picking up X, combining C with X to create D, then moving to room 3. They can now pick up and combine Y and Z to get J, allowing them to go to room 9.

Input Format

There's a fair bit of input to handle, and that's a pretty boring task, so the input format is very flexible. You will get the following data, and how it should be sent to your program is largely up to you:

The initial contents of each room (list of 0 or more items for each room);

A collection of permitted item combinations (each contains 2 input items and their output item — note that the input items are unordered);

The maximum inventory size (integer, 0 <= size <= 26);

The list of commands the player attempted.

The player's commands can be:

[P]ick up <item> - picks up an item from the room and puts it into the player's inventory (if there is space)

[D]rop <item> - drops an item from the player's inventory into the current room

[C]ombine <item1> <item2> - combines 2 items in the player's inventory to produce a new item

[G]o to <room> - travels to the chosen room if the player has the required key

For example, the input format I used for testing was simple program arguments:

./adventure YZ '' '' '' '' '' '' '' '' ''  1 YZJ         2          PY PZ CYZ G9
#           r0 r1 r2 r3 r4 r5 r6 r7 r8 r9  combinations  inv. size  commands...
# means:
#  room 0 starts with items Y & Z, all other rooms start empty
#  1 combination is possible: Y+Z => J
#  max inventory size is 2
#  player commands are [P]ick up Y, [P]ick up Z, [C]ombine Y and Z, [G]o to room 9
#  (in this example, the player wins)
```

<p>But if some other format makes it easier, that's fine (e.g. special delimiter characters / multiple lines / different ordering / serialised to JSON / etc.)</p>

<h1>Output Format</h1>

<p>Your program should return some truthy output if the player's commands cause them to win the game, and some falsey output otherwise. This could be a recognisable message to stdout, a program return code, or whatever your language of choice provides. All other output will be ignored.</p>

<h1>Test Cases</h1>

<p>The following bash script provides a test harness which will check most situations. It has been written to use the format described above, but modifying it to use a different format is just a case of adding a conversion in the <code>invoke</code> function.</p>

<pre class="lang-sh prettyprint-override"><code>#!/bin/sh

PROG="$1";

if [[ -z "$PROG" ]]; then
    echo "Usage: $0 <program-to-test>";
    exit 1;
fi;

function invoke {
    "$PROG" "$@"
}

RED="\033[1;31m";
GREEN="\033[1;32m";
RESET="\033[m";
FAILURES="0";

function pass {
    if ! invoke "$@" >/dev/null 2>&1; then
        echo "${RED}Expected pass, got fail:${RESET} $*" >&2;
        (( FAILURES = "$FAILURES" + 1 ));
        invoke "$@" 2>&1;
    fi;
}

function fail {
    if invoke "$@" >/dev/null 2>&1; then
        echo "${RED}Expected fail, got pass:${RESET} $*" >&2;
        (( FAILURES = "$FAILURES" + 1 ));
        invoke "$@" 2>&1;
    fi;
}

echo "Running tests...";

#    R0  R1  R2  R3  R4  R5  R6  R7  R8  R9  C      I  Cmd...
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ G9;
fail ''  J   ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ PJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  G9 PJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      1  PJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      0  PJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ DJ G9;
fail J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ PJ DJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ DJ PJ G9;
pass J   ''  ''  ''  ''  ''  ''  ''  ''  ''  0      9  PJ DJ PJ G9;
pass B   CJ  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PB G1 DB PC PJ G9;
fail B   CJ  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PB G1 DB PB PC PJ G9;
pass AJ  ''  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PA PJ G9;
pass B   D   ''  J   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G3 DB PJ G9;
fail B   D   ''  J   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G2 DB PJ G9;
fail B   D   ''  J   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G3 PJ G9;
fail B   D   J   C   ''  ''  ''  ''  ''  ''  0      2  PB G1 PD G3 PJ G9;
pass AJ  ''  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PA PJ G9 G0;
fail ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ G3 DJ G0 PJ G9;
pass ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ G3 DJ G0 G3 PJ G9;
fail ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ G3 DJ G0 DD G3 PJ G9;
pass ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      3  PA PD PJ DD G3 DJ G0 DD G3 PJ G9;
fail ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      1  PA DA DA PD PJ G9;
pass ADJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      1  PA DA DA PJ G9;
fail ABCDEFGHIKLMNOPQRSTUVWXYZ  J  '' '' '' '' '' '' '' '' 0 26 PA PB PC PD PE PF PG PH PI PJ PK PL PM PN PO PP PQ PR PS PT PU PV PW PX PY PZ G9;
pass ABCDEFGHIJKLMNOPQRSTUVWXYZ '' '' '' '' '' '' '' '' '' 0 26 PA PB PC PD PE PF PG PH PI PJ PK PL PM PN PO PP PQ PR PS PT PU PV PW PX PY PZ G9;
fail YZJ ''  ''  ''  ''  ''  ''  ''  ''  ''  0      2  PY PZ CYZ PJ G9;
pass YZJ ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PJ G9;
pass YZJ ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PJ CWJ G9;
fail XYZJ '' ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PX PJ G9;
fail XYZJ '' ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PX DY DZ PJ G9;
pass XYZJ '' ''  ''  ''  ''  ''  ''  ''  ''  1 YZW  2  PY PZ CYZ PX DW PJ G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  CYZ G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ DJ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ DJ PY PZ CYZ G9;
fail WZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PW PZ CYZ G9;
fail WZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CYZ G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  2  PY PZ CZY G9;
pass YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 ZYJ  2  PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PY PZ CYZ PY PZ CYZ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PY PZ CYZ PJ G9;
fail YZ  ''  ''  ''  ''  ''  ''  ''  ''  ''  1 YZJ  1  PJ G9;
pass BW  UV  ''  ''  ''  ''  ''  ''  ''  ''  3 BUR WVS RSJ  2  PB PW G1 DW PU CBU DR PW PV CVW PR CRS G9;
fail BW  AUV ''  ''  ''  ''  ''  ''  ''  ''  3 BUR WVS RSJ  2  PB G1 PU CBU DR PA PB G0 DA PW G1 PV CVW PR CRS G9;
pass BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PC PA PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW UV  ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PC PA PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU PA PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PA G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PB G0 DA PW G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PA PB G0 DA G1 DB PV CVW PR CRS G9;
fail BCW AUV ''  ''  ''  ''  ''  ''  ''  ''  3 CUR WVS RSJ  2  PB PC G1 DB PU CCU DR PA PB G0 DA PW G1 DB CVW PR CRS G9;
pass BFK LG  M   N   O   CDE PQR U   W   ''  10 BPT CQS TSH HUI IWV VFA GRX MXZ ANY YZJ  5 \
  PB PF PK G1 PL PG G6 DB DK DL G5 PC PD PE G6 DF G2 PM G6 DM DC G3 PN G4 PO G6 DN DO DD DE \
  PB PP CBP PC PQ CCQ CTS G7 PU CUH G8 PW CWI G6 PF CVF PR PM PN CGR CMX CAN CYZ G9
fail BFK LG  M   N   O   CDE PQR U   W   ''  10 BPT CQS TSH HUI IWV VFA GRX MXZ ANY YZJ  5 \
  PB PF PK G1 PL PG G6 DB DK DL G5 PC PD PE G6 DF G6 DM DC G3 PN G4 PO PM G6 DN DO DD DE \
  PB PP CBP PC PQ CCQ CTS G7 PU CUH G8 PW CWI G6 PF CVF PR PM PN CGR CMX CAN CYZ G9

if (( "$FAILURES" == "0" )); then
    echo "${GREEN}All tests passed${RESET}";
else
    echo "${RED}Total failures: $FAILURES${RESET}";
fi;
</code>```

Winning

Standard code golf: shortest code (in bytes) wins. Entries must follow the game rules, which in practice means they must pass all test cases (more tests may be added if necessary).

答:
C, 338 bytes

I had a go at minifying my own test program. I think it went quite well, even if it is the longest answer so far!

#define P c[(i<j?i:j)*25+i+j]
#define F for(q=atoi(*++v);r
#define X c[r*91+i]
r,i,j,c[2405];main(q,v)char**v;{for(r=10;--r;)for(++v;i=**v;++*v)++X;++v;F<q;++r)i=**++v,j=1[*v],P=2[*v];r=9;F&&*++v;c[i=1[*v]]&&j==68?c[i]=!++X,++q:j>79&&q*X?c[i]=!--X,--q:j==71&&c[i+17]?r=57-i:j<68&&c[i]*c[j=2[*v]]&&P?c[i]=c[j]=0,c[P]=++q:0)j=**v;return r;}
```

<p>This uses a few tricks to save space:</p>

<ul>
<li>Rooms are loaded in reverse so that checking for room 9 becomes checking for room 0, which is cheaper</li>
<li>Room 9's contents never matter, so it is skipped when reading the input and used to store the inventory instead</li>
<li>The room contents and item combinations are stored in the same array. Because items are stored at their ascii values, they never overlap.</li>
</ul>

<p>Breakdown:</p>

<pre class="lang-c prettyprint-override"><code>#define P c[(i<j?i:j)*25+i+j]       // item combination lookup (input: i,j)
#define X c[r*91+i]                 // room item lookup (input: r,i)
r,i,j,c[2405];                      // globals default to 0
main(q,v)char**v;{                  // K&R syntax to save bytes
    for(r=10;--r;)                  // Load rooms 0-8, store as 9-1
        for(++v;i=**v;++*v)
            ++X;
    ++v;                            // Skip room 9
    for(q=atoi(*++v);r<q;++r)       // For each combination
        i=**++v,
        j=1[*v],                    // Use index[array] syntax to avoid (brackets)
        P=2[*v];                    // Record combination
    r=9;                            // Begin in room 0 (9 in memory)
    for(q=atoi(*++v);               // Load inventory size
                     r              // While not in room 9 (0 in memory)...
                      &&*++v;       // ...and still have user commands
                                    // (ISO C promises a NULL at the end of argv)
        c[i=1[*v]]&&j==68?          // If 'D'rop, and we have the item:
            c[i]=!++X,              //  Drop it
            ++q:                    //  Increase our inventory capacity
        j>79&&                      // If 'P'ick up, and...
              q                     // ...we have capacity in our inventory and...
               *X?                  // ...the item is in the room:
            c[i]=!--X,              //  Pick it up
            --q:                    //  Decrease our inventory capacity
        j==71&&c[i+17]?             // If 'G'o to room, and we have the key:
            r=57-i:                 //  Go to the room
        j<68&&                      // If 'C'ombine, and...
              c[i]*c[j=2[*v]]       // ...we have the items and...
                             &&P?   // ...they can be combined
            c[i]=c[j]=0,            //  Remove the items
            c[P]=++q:               //  Add the combined item and increase capacity
        0                           // Unrecognised or invalid command
    )
        j=**v;                      // 'j' is the command letter (happens first)
    return r;                       // Return the final room (0 = truthy in shell)
}
</code>```

Partially inspired by @edc65's answer.

I was so close to getting ;*++*v; and c[P][c] into the code for ultimate confusion, but unfortunately other options turned out to be shorter :(

Title: A tiny adventure

Body:
C, 338 bytes

I had a go at minifying my own test program. I think it went quite well, even if it is the longest answer so far!

#define P c[(i<j?i:j)*25+i+j]
#define F for(q=atoi(*++v);r
#define X c[r*91+i]
r,i,j,c[2405];main(q,v)char**v;{for(r=10;--r;)for(++v;i=**v;++*v)++X;++v;F<q;++r)i=**++v,j=1[*v],P=2[*v];r=9;F&&*++v;c[i=1[*v]]&&j==68?c[i]=!++X,++q:j>79&&q*X?c[i]=!--X,--q:j==71&&c[i+17]?r=57-i:j<68&&c[i]*c[j=2[*v]]&&P?c[i]=c[j]=0,c[P]=++q:0)j=**v;return r;}

This uses a few tricks to save space:

Rooms are loaded in reverse so that checking for room 9 becomes checking for room 0, which is cheaper

Room 9's contents never matter, so it is skipped when reading the input and used to store the inventory instead

The room contents and item combinations are stored in the same array. Because items are stored at their ascii values, they never overlap.

Breakdown:

#define P c[(i<j?i:j)*25+i+j]       // item combination lookup (input: i,j)
#define X c[r*91+i]                 // room item lookup (input: r,i)
r,i,j,c[2405];                      // globals default to 0
main(q,v)char**v;{                  // K&R syntax to save bytes
    for(r=10;--r;)                  // Load rooms 0-8, store as 9-1
        for(++v;i=**v;++*v)
            ++X;
    ++v;                            // Skip room 9
    for(q=atoi(*++v);r<q;++r)       // For each combination
        i=**++v,
        j=1[*v],                    // Use index[array] syntax to avoid (brackets)
        P=2[*v];                    // Record combination
    r=9;                            // Begin in room 0 (9 in memory)
    for(q=atoi(*++v);               // Load inventory size
                     r              // While not in room 9 (0 in memory)...
                      &&*++v;       // ...and still have user commands
                                    // (ISO C promises a NULL at the end of argv)
        c[i=1[*v]]&&j==68?          // If 'D'rop, and we have the item:
            c[i]=!++X,              //  Drop it
            ++q:                    //  Increase our inventory capacity
        j>79&&                      // If 'P'ick up, and...
              q                     // ...we have capacity in our inventory and...
               *X?                  // ...the item is in the room:
            c[i]=!--X,              //  Pick it up
            --q:                    //  Decrease our inventory capacity
        j==71&&c[i+17]?             // If 'G'o to room, and we have the key:
            r=57-i:                 //  Go to the room
        j<68&&                      // If 'C'ombine, and...
              c[i]*c[j=2[*v]]       // ...we have the items and...
                             &&P?   // ...they can be combined
            c[i]=c[j]=0,            //  Remove the items
            c[P]=++q:               //  Add the combined item and increase capacity
        0                           // Unrecognised or invalid command
    )
        j=**v;                      // 'j' is the command letter (happens first)
    return r;                       // Return the final room (0 = truthy in shell)
}

Partially inspired by @edc65's answer.

I was so close to getting ;*++*v; and c[P][c] into the code for ultimate confusion, but unfortunately other options turned out to be shorter :(


答:
Matlab, 87 bytes

```<code>n=input('');k=numel(n);[a b]=ndgrid(1:k);[x y]=max(sum(abs(a-b).*repmat(n,k,1)').*~n);y
</code>```

Takes array of ones and zeros; uses 1-based indexing.

Like some other answers maximises total not average distance.

Probably there's some more golfing possible...

Title: Be respectful in the restroom

Body:
Matlab, 87 bytes

n=input('');k=numel(n);[a b]=ndgrid(1:k);[x y]=max(sum(abs(a-b).*repmat(n,k,1)').*~n);y

Takes array of ones and zeros; uses 1-based indexing.

Like some other answers maximises total not average distance.

Probably there's some more golfing possible...


Body:
In particular, use each of these symbols at least once in your source code:

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

Symbols inside comments, string literals, regexps (or any other kinds of literals etc.) don't count (but their delimiters such as /**/ or "" do count).

The program should not perform any action. It just has to compile and do nothing when run.

If for some reason some of the symbols cannot be used in the language of your choice, explain that rigorously (what and why must be excluded).

Update: A few answers used symbols withing regular expressions. I'd consider this a bit problematic, it's the same thing as putting them into string literals or comments (that's why I put etc. in that requirement). Please try without this. I also updated the requirement above.

Update: Shortest code wins (tagged as code-golf). As suggested, we'll most likely need some tie-breaker criteria. I suggest that if there is a tie, the winning one is the one in which the ASCII symbols appear as much ordered as possible. Formally: Filter out the first occurrence of each of the listed symbols from a program. This will result in a permutation on the listed symbols. The program with less inversion number of its permutation wins.

Update: I'd be happy to see some/more solutions in regular/mainstream languages, such as C(++), Java, Scala, Haskell, etc.

Body:
C, 48 chars

Kind of cheating.

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