问:
1, 2, Fizz, 4, Buzz

Introduction

In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other catalogue challenges, there is "Hello World!" and "Is this number a prime?".

Challenge

Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Output

The output will be a list of numbers (and Fizzes, Buzzes and FizzBuzzes) separated by a newline (either \n or \r\n). A trailing newline is acceptable, but a leading newline is not.  Apart from your choice of newline, the output should look exactly like this:

```<code>1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
</code>```

The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation.

Further Rules

This is not about finding the language with the shortest approach for playing FizzBuzz, this is about finding the shortest approach in every language. Therefore, no answer will be marked as accepted.

Submissions are scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score--if in doubt, please ask on Meta.

Nothing can be printed to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge. If anyone wants to abuse this by creating a language where the empty program generates FizzBuzz output, then congrats for paving the way for a very boring answer.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Alphuck and ???), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

Because the output is fixed, you may hardcode the output (but this may not be the shortest option).

You may use preexisting solutions, as long as you credit the original author of the program.

Standard loopholes are otherwise disallowed.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the authors actually had to put effort into golfing the code.

Catalogue

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
<s>Word</s> VBA, 124 <s>189</s> bytes

```<code>Sub f()
For i=1 To 100
r=""
If i Mod 3=0 Then r="Fizz"
If i Mod 5=0 Then r=r & "Buzz"
If r="" Then r=i
Debug.?r
Next
End Sub
</code>```

The code breakdown is fairly simple (yay, BASIC).

Loop from 1 to 100

```<code>For i=1 To 100
</code>```

Set a variable to be an empty string

```<code>r=""
</code>```

Check the value on the counter to see if we should set the variable to Fizz

```<code>If i Mod 3=0 Then r="Fizz"
</code>```

Check the counter to see if we need to add Buzz (adding it to an empty string is the same as setting that variable to Buzz)

```<code>If i Mod 5=0 Then r=r & "Buzz"
</code>```

Check to see if the variable is still empty and therefore needs to be set to the counter value

```<code>If r="" Then r=i
</code>```

Prints the results to the immediate window

```<code>t = t & r & vbCr
</code>```

EDIT: Used @Taylor-Scott's suggestions to tighten it up. Relies on the meta discussion about counting characters when your IDE forces whitespace. Specifically the conclusion that if you can paste the code from the answer into the IDE and run it without issues, then you don't have to count the results of autoformatting.

Title: 1, 2, Fizz, 4, Buzz

Body:
<s>Word</s> VBA, 124 <s>189</s> bytes

Sub f()
For i=1 To 100
r=""
If i Mod 3=0 Then r="Fizz"
If i Mod 5=0 Then r=r & "Buzz"
If r="" Then r=i
Debug.?r
Next
End Sub

The code breakdown is fairly simple (yay, BASIC).

Loop from 1 to 100

For i=1 To 100

Set a variable to be an empty string

r=""

Check the value on the counter to see if we should set the variable to Fizz

If i Mod 3=0 Then r="Fizz"

Check the counter to see if we need to add Buzz (adding it to an empty string is the same as setting that variable to Buzz)

If i Mod 5=0 Then r=r & "Buzz"

Check to see if the variable is still empty and therefore needs to be set to the counter value

If r="" Then r=i

Prints the results to the immediate window

t = t & r & vbCr

EDIT: Used @Taylor-Scott's suggestions to tighten it up. Relies on the meta discussion about counting characters when your IDE forces whitespace. Specifically the conclusion that if you can paste the code from the answer into the IDE and run it without issues, then you don't have to count the results of autoformatting.


问:
How many minimum days will he take to complete N units of work?
A person has to complete N units of work; the nature of work is the same.

In order to get the hang of the work, he completes only one unit of work in the first day.

He wishes to celebrate the completion of work, so he decides to complete one unit of work in the last day.

He is only allowed to complete x, x+1 or x-1 units of work in a day, where x is the units of work completed on the previous day.

Your task is to create a program or function that will compute the minimum number of days will he take to complete N units of work.

Sample Input and Ouput:

```<code>input -> output (corresponding work_per_day table)
-1    -> 0      []
0     -> 0      []
2     -> 2      [1,1]
3     -> 3      [1,1,1]
5     -> 4      [1,1,2,1] or [1,2,1,1]
9     -> 5      [1,2,3,2,1]
13    -> 7      [1,2,2,2,3,2,1]
</code>```

Input may be taken through STDIN or as function argument, or in any appropriate way.

Output may be printed or as the result of a function, or in any appropriate way.

This is code-golf. Shortest solution wins.

答:
Pyke, 8 bytes

```<code>#X4f)ltt
</code>```

Try it here!

Uses same algorithm as @KennyLau

ContentLicense: CC BY-SA 3.0

Body:
Pyke, 8 bytes

#X4f)ltt

Try it here!

Uses same algorithm as @KennyLau


问:
Reverse Greek Conversion Golf

Introduction

You must create a function to convert Greek numerals into Arabic numerals. The input will be a Greek numeral less than 1000 and more than 0. This is the reverse of my previous challenge.

Algorithm

Split input into letters (e.g. ΡΚΓ -> Ρ, Κ, Γ)

Take each letter, and change to character found in table below, for letter symbol, (e.g. ΡΚΓ -> Ρ, Κ, Γ -> 100, 20, 3).

Add (e.g. ΡΚΓ -> Ρ, Κ, Γ -> 100, 20, 3 -> 123)

Specifications

No built-in number-system conversion

Input will be capitalized as in example.

Output must be in base 10.

ΡΡΡΡ will never happen. It will be Υ.

Test Cases

```<code>ΡΚΓ -> 123
Η -> 8
ΨΟΖ -> 777
Ρ -> 100
ΧϜ -> 606
ΡϘ -> 190
ΜΒ -> 42
Ν -> 50
</code>```

Table

```<code>Α = 1 = Alpha = 913 UTF-8
Β = 2 = Beta = 914 UTF-8
Γ = 3 = Gamma = 915 UTF-8
Δ = 4 = Delta = 916 UTF-8
Ε = 5 = Epsilon = 917 UTF-8
Ϝ = 6 = DiGamma = 988 UTF-8
Ζ = 7 = Zeta = 918 UTF-8
Η = 8 = Eta = 919 UTF-8
Θ = 9 = Theta = 920 UTF-8

Ι = 10 = Iota = 921 UTF-8
Κ = 20 = Kappa = 922 UTF-8
Λ = 30 = Lambda = 923 UTF-8
Μ = 40 = Mu = 924 UTF-8
Ν = 50 = Nu = 925 UTF-8
Ξ = 60 = Xi = 926 UTF-8
Ο = 70 = Omicron = 927 UTF-8
Π = 80 = Pi = 928 UTF-8
Ϙ = 90 = Koppa = 984 UTF-8

Ρ = 100 = Rho = 929 UTF-8
Σ = 200 = Sigma = 931 UTF-8
Τ = 300 = Tau = 932 UTF-8
Υ = 400 = Upsilon = 933 UTF-8
Φ = 500 = Phi = 934 UTF-8
Χ = 600 = Chi = 935 UTF-8
Ψ = 700 = Psi = 936 UTF-8
Ω = 800 = Omega = 937 UTF-8
Ϡ = 900 = SamPi = 992 UTF-8
</code>```

答:
Jelly, <s>47</s> 45 bytes

```<code>⁵*×‘}
“#'nn(2jj33556;r”Or2/F+878Ọ
¢iÐ€’d9ñ/€S
</code>```

Try it online! or verify all test cases.

Title: Reverse Greek Conversion Golf

Body:
Jelly, <s>47</s> 45 bytes

⁵*×‘}
“#'nn(2jj33556;r”Or2/F+878Ọ
¢iÐ€’d9ñ/€S

Try it online! or verify all test cases.


答:
Python 3, 188 Bytes

```<code>def f(x,l=list,z=0):
 r=l(range(1,10));R=[a*10for a in r]
 for a,b in l(zip(l("ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ"),r+R+[a*10for a in R])):
  z+=(0,b)[a in x]
 return z
</code>```

Try it out! (Test cases included)

Title: Reverse Greek Conversion Golf

Body:
Introduction

You must create a function to convert Greek numerals into Arabic numerals. The input will be a Greek numeral less than 1000 and more than 0. This is the reverse of my previous challenge.

Algorithm

Split input into letters (e.g. ΡΚΓ -> Ρ, Κ, Γ)

Take each letter, and change to character found in table below, for letter symbol, (e.g. ΡΚΓ -> Ρ, Κ, Γ -> 100, 20, 3).

Add (e.g. ΡΚΓ -> Ρ, Κ, Γ -> 100, 20, 3 -> 123)

Specifications

No built-in number-system conversion

Input will be capitalized as in example.

Output must be in base 10.

ΡΡΡΡ will never happen. It will be Υ.

Test Cases

```<code>ΡΚΓ -> 123
Η -> 8
ΨΟΖ -> 777
Ρ -> 100
ΧϜ -> 606
ΡϘ -> 190
ΜΒ -> 42
Ν -> 50
</code>```

Table

```<code>Α = 1 = Alpha = 913 UTF-8
Β = 2 = Beta = 914 UTF-8
Γ = 3 = Gamma = 915 UTF-8
Δ = 4 = Delta = 916 UTF-8
Ε = 5 = Epsilon = 917 UTF-8
Ϝ = 6 = DiGamma = 988 UTF-8
Ζ = 7 = Zeta = 918 UTF-8
Η = 8 = Eta = 919 UTF-8
Θ = 9 = Theta = 920 UTF-8

Ι = 10 = Iota = 921 UTF-8
Κ = 20 = Kappa = 922 UTF-8
Λ = 30 = Lambda = 923 UTF-8
Μ = 40 = Mu = 924 UTF-8
Ν = 50 = Nu = 925 UTF-8
Ξ = 60 = Xi = 926 UTF-8
Ο = 70 = Omicron = 927 UTF-8
Π = 80 = Pi = 928 UTF-8
Ϙ = 90 = Koppa = 984 UTF-8

Ρ = 100 = Rho = 929 UTF-8
Σ = 200 = Sigma = 931 UTF-8
Τ = 300 = Tau = 932 UTF-8
Υ = 400 = Upsilon = 933 UTF-8
Φ = 500 = Phi = 934 UTF-8
Χ = 600 = Chi = 935 UTF-8
Ψ = 700 = Psi = 936 UTF-8
Ω = 800 = Omega = 937 UTF-8
Ϡ = 900 = SamPi = 992 UTF-8
</code>```

Body:
Python 3, 188 Bytes

def f(x,l=list,z=0):
 r=l(range(1,10));R=[a*10for a in r]
 for a,b in l(zip(l("ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ"),r+R+[a*10for a in R])):
  z+=(0,b)[a in x]
 return z

Try it out! (Test cases included)


问:
Greek Conversion Golf

Introduction

You must create a function to convert Arabic numerals into Greek numerals. The input will be an integer less than 1000 and more than 0.

Algorithm

Split number into digits (e.g. 123 -> 1, 2, 3)

Take each digit, and change to character found in table below, for letter symbol or letter name, (e.g. 123 -> 1, 2, 3 -> ΡΚΓ or RhoKappaGamma).

Specifications

No built-in number-system conversion

Result must be capitalized as in example.

Input will be in base 10.

Test Cases

```<code>123 -> RhoKappaGamma or ΡΚΓ
8 -> Eta or Η
777 -> PsiOmicronZeta or ΨΟΖ
100 -> Rho or Ρ
606 -> ChiDiGamma or ΧϜ
</code>```

Table

```<code>Α = 1 = Alpha = 913 UTF-8
Β = 2 = Beta = 914 UTF-8
Γ = 3 = Gamma = 915 UTF-8
Δ = 4 = Delta = 916 UTF-8
Ε = 5 = Epsilon = 917 UTF-8
Ϝ = 6 = DiGamma = 988 UTF-8
Ζ = 7 = Zeta = 918 UTF-8
Η = 8 = Eta = 919 UTF-8
Θ = 9 = Theta = 920 UTF-8

Ι = 10 = Iota = 921 UTF-8
Κ = 20 = Kappa = 922 UTF-8
Λ = 30 = Lambda = 923 UTF-8
Μ = 40 = Mu = 924 UTF-8
Ν = 50 = Nu = 925 UTF-8
Ξ = 60 = Xi = 926 UTF-8
Ο = 70 = Omicron = 927 UTF-8
Π = 80 = Pi = 928 UTF-8
Ϙ = 90 = Koppa = 984 UTF-8

Ρ = 100 = Rho = 929 UTF-8
Σ = 200 = Sigma = 931 UTF-8
Τ = 300 = Tau = 932 UTF-8
Υ = 400 = Upsilon = 933 UTF-8
Φ = 500 = Phi = 934 UTF-8
Χ = 600 = Chi = 935 UTF-8
Ψ = 700 = Psi = 936 UTF-8
Ω = 800 = Omega = 937 UTF-8
Ϡ = 900 = SamPi = 992 UTF-8
</code>```

Title: Greek Conversion Golf

Body:
Julia, 84 bytes

f(x,p=0)=x>0?f(x÷10,p+9)"$(x%10<1?"":"/0123z456789:;<=>v?ABCDEFG~"[p+x%10]+866)":""

Try it online!


问:
CamelCase2snake_case()
Write a function to convert CamelCased text to snake_case: FunctionForHTMLManipulation becomes function_for_html_manipulation

The input text will be a single suitable identifier in many languages. It must start with an English letter, then be followed by any number of English letters or digits. No other characters (spaces, symbols, etc.) are allowed.

Each "word" within the CamelCased text will start with a capital letter unless at the beginning of the text or immediately after a digit, and be followed by zero or more letters, all of the same case. Groups of digits will be considered as separate words but pass through unchanged.

In other words, a lowercase letter followed by an uppercase letter indicates a word break. Any letter and digit next to each other indicates a word break. An uppercase letter followed by another uppercase letter and a lowercase letter indicates a word break.

...lU... => ...l_u...

...l9... => ...l_9...

...U9... => ...u_9...

...9l... => ...9_l...

...9U... => ...9_u...

...UUl... => ...u_ul...

Both Buy24Beers and buy24beers become buy_24_beers.

MacDonaldAndObrian becomes mac_donald_and_obrian.

MACDonaldAndOBrian becomes mac_donald_and_o_brian.

答:
Retina, <s>61</s> 37 bytes

```<code>r1>`[A-Z]?[a-z]+|[A-Z]+|\d+
_$&
T`L`l
</code>```

Try it online! (Slightly modified to run a full test suite.)

Explanation

Instead of finding word boundaries to insert underscores, we simply match each word and prepend a _. Matching words from the left is a bit annoying because of the UUl rule, but using .NET's right-to-left matching we can easily match words greedily. To avoid a leading _, we make use of Retina's limits.

```<code>r1>`[A-Z]?[a-z]+|[A-Z]+|\d+
_$&
</code>```

The r activates right-to-left mode, the 1> tells Retina to process everything except the first match (counting from left to right). Then there's four types of "words": Ulll, lll, UUU, ddd. These are easily matched with the given pattern. The substitution just writes a _ followed by the word itself.

```<code>T`L`l
</code>```

This simply turns upper case into lower case to complete the transformation.

Title: CamelCase2snake_case()

Body:
Retina, <s>61</s> 37 bytes

r1>`[A-Z]?[a-z]+|[A-Z]+|\d+
_$&
T`L`l

Try it online! (Slightly modified to run a full test suite.)

Explanation

Instead of finding word boundaries to insert underscores, we simply match each word and prepend a _. Matching words from the left is a bit annoying because of the UUl rule, but using .NET's right-to-left matching we can easily match words greedily. To avoid a leading _, we make use of Retina's limits.

r1>`[A-Z]?[a-z]+|[A-Z]+|\d+
_$&

The r activates right-to-left mode, the 1> tells Retina to process everything except the first match (counting from left to right). Then there's four types of "words": Ulll, lll, UUU, ddd. These are easily matched with the given pattern. The substitution just writes a _ followed by the word itself.

T`L`l

This simply turns upper case into lower case to complete the transformation.


答:
JavaScript (ES7), 115 bytes

s=>[...s].map(c=>n+=((i="ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ".search(c))%9+1)*10**(i/9|0),n=0)|n
```

Title: Reverse Greek Conversion Golf


答:
Python 3, 112

Saved 4 bytes thanks to vaultah.

Booyah, beating JS!

lambda x,z="ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ".find:sum((z(c)%9+1)*10**(z(c)//9)for c in x)
```
<p>With test cases:</p>
<pre class="lang-python prettyprint-override"><code>assert(f("ΡΚΓ")==123)
assert(f("Η")==8)
assert(f("ΨΟΖ")==777)
assert(f("Ρ")==100)
assert(f("ΧϜ")==606)
</code>```

Loops through the string and uses its index in the list of potentials chars to calculate how much it's worth.

Title: Reverse Greek Conversion Golf

Body:
Python 3, 112

Saved 4 bytes thanks to vaultah.

Booyah, beating JS!

lambda x,z="ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ".find:sum((z(c)%9+1)*10**(z(c)//9)for c in x)

With test cases:

assert(f("ΡΚΓ")==123)
assert(f("Η")==8)
assert(f("ΨΟΖ")==777)
assert(f("Ρ")==100)
assert(f("ΧϜ")==606)

Loops through the string and uses its index in the list of potentials chars to calculate how much it's worth.


答:
JavaScript (ES6), 116 bytes

```<code>s=>[...s].map(c=>n+=+((i="ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ".search(c))%9+1+"e"+(i/9|0)),n=0)|n
</code>```

Only 1 byte longer than ES7!

Title: Reverse Greek Conversion Golf

Body:
JavaScript (ES6), 116 bytes

s=>[...s].map(c=>n+=+((i="ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ".search(c))%9+1+"e"+(i/9|0)),n=0)|n

Only 1 byte longer than ES7!


问:
A Numpad's Knight Numbers
For the non-zero digits on a standard numpad

```<code>789
456
123
</code>```

consider placing a chess knight at any digit and moving it around with any number of normal L-shaped jumps, tracing out a positive decimal integer. What positive integers can be expressed in such a way?

One of them is 38, since the knight could start on the 3 and move left and up to the 8. 381 and 383 are also possible.

3 itself is possible if no jumps are taken (which is allowed). 5 is as well, but no other digits can be reached from the 5, so it is the only number where the digit 5 appears.

Write a program or function that takes in a positive decimal integer (you may take it as a string if desired) and prints or returns a truthy value if the number can be expressed by a knight on a numpad in the way described, but otherwise outputs a falsy value.

The shortest code in bytes wins. Tiebreaker is earlier answer

Examples

Truthy:

```<code>1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 18, 38, 61, 81, 294, 349, 381, 383, 729, 767, 38183, 38383, 18349276, 183492761, 618349276
</code>```

Falsy:

```<code>10, 11, 50, 53, 55, 65, 95, 100, 180, 182, 184, 185, 186, 187, 188, 189, 209, 305, 2009, 5030, 3838384, 4838383, 183492760
</code>```

答:
Java 8, <s>179</s> 167 Bytes

Places the number pad ints (minus 5 and 0) in a circle. l holds the circle index of these ints. If the difference of two indices is +/- 3 mod 8,  then there is a knights move between the ints corresponding to those indices. Note that x is an int[].

x->{if(x.length<2)return 1;int[] l={0,0,1,2,7,0,3,6,5,4};int o=l[x[1]];for(int i:x){int n=l[i];if(i%5==0||(Math.abs(n-o)!=3&&Math.abs(n-o)!=5))return 0;o=n;}return 1;}
```

Update

-11 [16-12-10] Switched to a  lambda

-1 [16-12-10] Use <2 instead of ==1

Title: A Numpad's Knight Numbers

Body:
Java 8, <s>179</s> 167 Bytes

Places the number pad ints (minus 5 and 0) in a circle. l holds the circle index of these ints. If the difference of two indices is +/- 3 mod 8,  then there is a knights move between the ints corresponding to those indices. Note that x is an int[].

x->{if(x.length<2)return 1;int[] l={0,0,1,2,7,0,3,6,5,4};int o=l[x[1]];for(int i:x){int n=l[i];if(i%5==0||(Math.abs(n-o)!=3&&Math.abs(n-o)!=5))return 0;o=n;}return 1;}

Update

-11 [16-12-10] Switched to a  lambda

-1 [16-12-10] Use <2 instead of ==1


答:
Python, 43 bytes

```<code>f=lambda n,i=1:i-1if i*i>=n*4 else f(n,i+1)
</code>```

Title: How many minimum days will he take to complete N units of work?

Body:
A person has to complete N units of work; the nature of work is the same.

In order to get the hang of the work, he completes only one unit of work in the first day.

He wishes to celebrate the completion of work, so he decides to complete one unit of work in the last day.

He is only allowed to complete x, x+1 or x-1 units of work in a day, where x is the units of work completed on the previous day.

Your task is to create a program or function that will compute the minimum number of days will he take to complete N units of work.

Sample Input and Ouput:

```<code>input -> output (corresponding work_per_day table)
-1    -> 0      []
0     -> 0      []
2     -> 2      [1,1]
3     -> 3      [1,1,1]
5     -> 4      [1,1,2,1] or [1,2,1,1]
9     -> 5      [1,2,3,2,1]
13    -> 7      [1,2,2,2,3,2,1]
</code>```

Input may be taken through STDIN or as function argument, or in any appropriate way.

Output may be printed or as the result of a function, or in any appropriate way.

This is code-golf. Shortest solution wins.

Body:
Python, 43 bytes

f=lambda n,i=1:i-1if i*i>=n*4 else f(n,i+1)


问:
Tips for golfing in PARI/GP
PARI/GP is a free computer algebra system. It is designed for (algebraic) number theory, not golfing, but that's part of the attraction. Unsurprisingly, it fares best at mathematical tasks; its support for string manipulation is primitive. (Having said that, advice for golfing non-mathematical tasks is also welcome.)

As usual, please post one tip per answer.

These tips should be at least somewhat specific to PARI/GP; advice which applies to 'most' languages belongs at Tips for golfing in <all languages>. Some general tips which don't need to be included:

Compress whitespace. (In GP all whitespace outside of strings is optional.)

Use single-character variables. (There are 50 choices, a-z and A-Z except I and O.)

Use < and > rather than <= and >= when possible.

Chain assignments. (a=b=c or a+=b*=c)

答:
In a string context (e.g. the arguments of print or Str), commas are unnecessary:

i=99
print(i" bottles of beer on the wall")
```

<p>This is even true if one of the arguments is an assignment. The following is equivalent to the above:</p>

<pre class="lang-default prettyprint-override"><code>print(i=99" bottles of beer on the wall")
</code>```

Unassigned variables evaluate to their name in a string context:

for(i=1,2,print(i" bottl"e" of beer on the wall.");e=es)
```

<p>produces:</p>

<pre class="lang-default prettyprint-override"><code>1 bottle of beer on the wall.
2 bottles of beer on the wall.
</code>```

In a multi-line context { ... }, the closing brace is unnecessary.

print({"this is line one
this is line two")
```

Documentation

In REPL:

?* - show all commands.

?<command> - show brief documentation for a command.

Online documentation:

http://pari.math.u-bordeaux.fr/dochtml/html.stable/

Title: Tips for golfing in PARI/GP

Body:
In a string context (e.g. the arguments of print or Str), commas are unnecessary:

i=99
print(i" bottles of beer on the wall")

This is even true if one of the arguments is an assignment. The following is equivalent to the above:

print(i=99" bottles of beer on the wall")

Unassigned variables evaluate to their name in a string context:

for(i=1,2,print(i" bottl"e" of beer on the wall.");e=es)

produces:

1 bottle of beer on the wall.
2 bottles of beer on the wall.

In a multi-line context { ... }, the closing brace is unnecessary.

print({"this is line one
this is line two")

Documentation

In REPL:

?* - show all commands.

?<command> - show brief documentation for a command.

Online documentation:

http://pari.math.u-bordeaux.fr/dochtml/html.stable/


问:
Can Gravity Guy Make It?
Gravity Guy is a game where the only user input is a single key that flips the direction of gravity. Given an ASCII art level, determine if it is possible for Gravity Guy to reach the end.

Rules

The initial direction of gravity is down.

The first column of the input will always contain only one #, which Gravity Guy starts on top of.

Each iteration, he moves to the character directly on his right.

If his path is blocked and he moves into a #, the player loses.

After moving, the player can optionally switch gravity from down to up, or up to down.

Gravity Guy then falls on to the next # (in the current direction of gravity).

If there is no # to fall on to and he falls off the grid, the player loses.

If Gravity Guy moves off the right side of the input grid, the player wins.

Example

If this was the input grid:

```<code>  ###

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

Gravity Guy would start at the x and the be at these positions after each iteration. ^ = switch gravity to up and v = switch gravity to down.

```<code>v                        ^                               v
-------------------------------------------------------------
  ###   |    ###   |    ###   |    ###   |    ###   |    ###
x       |          |    x     |     x    |      x   |
#  #    |  #x #    |  #  #    |  #  #    |  #  #    |  #  # x
 ### #  |   ### #  |   ### #  |   ### #  |   ### #  |   ### #
</code>```

As you can see, by switching gravity at these times Gravity Guy reaches the end, so this input would return a truthy value.

Specifications

Input grid can be in any appropriate "grid" format (multiline string padded with spaces, array of line strings, array of array of characters, etc).

If it is possible for the player to win the level, output a truthy value. If not, output a falsey value.

The width and height of the grid will be 50 characters at most.

This is code-golf, may the shortest code in bytes win!

Test Cases

(each case separated by ----------, any blank lines should also be padded with spaces)

True

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

----------

###

----------

   #####

####

----------

 #####
 # # #

# # #
 #####

----------

   ############

######      ######

   ############

----------

  ###   ###
     # #
####  #  ####
    #   #
     # #
      #

----------

    ######
   #
 ##
     #######
###     #
   #    #
    #####

----------

    #####
   #    #
 ##     #
     #######
###
   #
    ######

----------

  ###

#  # #
 ###

----------

  ###  ###

###     ##
   #    #
    #####

----------

  #
     #   #
       #
#   #     #
        #
   #
      #
 #

----------

    ##### ####
   #     #    #
  #   # #  ##  #
             #  #
#####  ####   #
               #
     #########

----------

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

False

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

----------

### ###

----------

    #
 ### ###

#### ###
    #

----------

  ###     ###
     # # #
####  # #  ####
    #     #
     #   #
      # #
       #

----------

  #######
  #     #
 ## #####

### ######
  #     #
  #######

----------

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

答:
JavaScript (ES6), 174 bytes

```<code>a=>[...a[0]].map((_,i)=>[...t].map(x=>s[x]<'#'&&g(s.indexOf('#',x),-1)&&g(s.lastIndexOf('#',x),1),s=a.map(s=>s[i]),t=new Set),t=new Set([0]),g=(i,d)=>i<0||t.add(i+d))&&t.size
</code>```

Takes a horizontal array of strings and returns the number of exit points. Transposing the array costs me 29 bytes. Ungolfed:

```<code>function gravity(array) {
    var set = new Set;
    set.add(0); // starting point
    for (var i = 0; i < array[0].length; i++) {
        var s = array.map(s => s[i]); // transpose array
        var old = set;
        set = new Set;
        for (var x of old) {
            if (s[x] == '#') continue; // hit wall
            var j = s.indexOf('#', x); // try downward gravity
            if (j >= 0) set.add(j - 1);
            j = s.lastIndexOf('#', x); // try upward gravity
            if (j >= 0) set.add(j + 1);
        }
    }
    return set.size;
}
</code>```

Title: Can Gravity Guy Make It?

Body:
JavaScript (ES6), 174 bytes

a=>[...a[0]].map((_,i)=>[...t].map(x=>s[x]<'#'&&g(s.indexOf('#',x),-1)&&g(s.lastIndexOf('#',x),1),s=a.map(s=>s[i]),t=new Set),t=new Set([0]),g=(i,d)=>i<0||t.add(i+d))&&t.size

Takes a horizontal array of strings and returns the number of exit points. Transposing the array costs me 29 bytes. Ungolfed:

function gravity(array) {
    var set = new Set;
    set.add(0); // starting point
    for (var i = 0; i < array[0].length; i++) {
        var s = array.map(s => s[i]); // transpose array
        var old = set;
        set = new Set;
        for (var x of old) {
            if (s[x] == '#') continue; // hit wall
            var j = s.indexOf('#', x); // try downward gravity
            if (j >= 0) set.add(j - 1);
            j = s.lastIndexOf('#', x); // try upward gravity
            if (j >= 0) set.add(j + 1);
        }
    }
    return set.size;
}


答:
Haskell, <s>116</s> 113 bytes

```<code>f x=sum[v|d<-x,(l,v)<-zip"ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ"$(*)<$>[1,10,100]<*>[1..9],d==l]
</code>```

Usage example: map f ["ΡΚΓ","Η","ΨΟΖ","Ρ","ΧϜ","ΡϘ","ΜΒ","Ν"] -> [123,8,777,100,606,190,42,50].

Lookup the value of the greek letter from a list of pairs (letter, value) and sum. The list of values is build by (*)<$>[1,10,100]<*>[1..9], where (*)<$>[1,10,100] builds a list of functions [(*1),(*10),(*100)] (multiply by 1, 10 and 100) which are applied separately to the elements of [1..9] and concatenated into a single list.

Edit: 3 bytes with thanks to @xnor.

Title: Reverse Greek Conversion Golf

Body:
Haskell, <s>116</s> 113 bytes

f x=sum[v|d<-x,(l,v)<-zip"ΑΒΓΔΕϜΖΗΘΙΚΛΜΝΞΟΠϘΡΣΤΥΦΧΨΩϠ"$(*)<$>[1,10,100]<*>[1..9],d==l]

Usage example: map f ["ΡΚΓ","Η","ΨΟΖ","Ρ","ΧϜ","ΡϘ","ΜΒ","Ν"] -> [123,8,777,100,606,190,42,50].

Lookup the value of the greek letter from a list of pairs (letter, value) and sum. The list of values is build by (*)<$>[1,10,100]<*>[1..9], where (*)<$>[1,10,100] builds a list of functions [(*1),(*10),(*100)] (multiply by 1, 10 and 100) which are applied separately to the elements of [1..9] and concatenated into a single list.

Edit: 3 bytes with thanks to @xnor.


问:
Driftsort an array
Driftsort is a simple way to "sort" an array. It works by "sliding" or "rotating" the elements over in the array until the array is sorted, or until the array fails to be sorted.

Let's walk through two examples. First, consider the array [10, 2, 3, 4, 7]. Since the array is not sorted, we rotate it once. (This can happen in either direction, so long as it remains the same direction.) Then, the array becomes:

```<code>[7, 10, 2, 3, 4]
</code>```

This is not sorted, so we rotate again.

```<code>[4, 7, 10, 2, 3]
</code>```

And again:

```<code>[3, 4, 7, 10, 2]
</code>```

And a final time:

```<code>[2, 3, 4, 7, 10]
</code>```

And it's sorted! So the array [10, 2, 3, 4, 7] is driftsortable. Here are all the rotations of the array, for clarity:

```<code>[10, 2, 3, 4, 7]
[7, 10, 2, 3, 4]
[4, 7, 10, 2, 3]
[3, 4, 7, 10, 2]
[2, 3, 4, 7, 10]
</code>```

Consider now the array [5, 3, 9, 2, 6, 7]. Look at its rotations:

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

None of these arrays are sorted, so the array [5, 3, 9, 2, 6, 7] is not driftsortable.

Objective Given a nonempty array/list of integers as input to a program/function, implement driftsort on the input and output it, or output a falsey value (or an empty array/list) if it cannot be driftsorted. The integers are bound to your languages max/min, but this must be at least 255 for the max, and 0 for the min.

You may use built-in sorting methods, but not a built-in which solves the challenge.

This is a code-golf, so the shortest program in bytes.

Test cases

```<code>input => output
[1] => [1]
[5, 0, 5] => [0, 5, 5]
[3, 2, 1] => false
[0, 9, 3] => false
[1, 2, 3, 4] => [1, 2, 3, 4]
[4, 1, 2, 3] => [1, 2, 3, 4]
[0, 2, 0, 2] => false
[5, 3, 9, 2, 6, 7] => false
[0, 0, 0, 0, 0, 0, 0] => [0, 0, 0, 0, 0, 0, 0]
[75, 230, 30, 42, 50] => [30, 42, 50, 75, 230]
[255, 255, 200, 200, 203] => [200, 200, 203, 255, 255]
</code>```

答:
PHP, 98 bytes

Outputs a 1 if driftsortable, else nothing

```<code>$a=$argv[1];$b=$a;sort($a);foreach($a as $v){echo($a===$b?1:'');array_unshift($b, array_pop($b));}
</code>```

Title: Driftsort an array

Body:
PHP, 98 bytes

Outputs a 1 if driftsortable, else nothing

$a=$argv[1];$b=$a;sort($a);foreach($a as $v){echo($a===$b?1:'');array_unshift($b, array_pop($b));}


问:
4, 8, 15, 16, 23, 42

4, 8, 15, 16, 23, 42

Write a program that outputs this sequence of numbers infinitely. However, The Numbers must not appear in your source code anywhere.

The following is not a valid Java program to output The Numbers because The Numbers appear in its source code:

```<code>class TheNumbers {
    public static void main(String[] args) {
        for(int n = 0;;) System.out.println(
            n == 4 ? n = 8 :
            n == 8 ? n = 15 :
            n == 15 ? n = 16 :
            n == 16 ? n = 23 :
            n == 23 ? n = 42 : (n = 4)
        );
    }
}
</code>```

The definition of "The Numbers must not appear in your source code" is as follows:

You must not use the numeral 4.

You must not use the numeral 8.

You must not use the numeral 1 followed by the numeral 5.

You must not use the numeral 1 followed by the numeral 6.

You must not use the numeral 2 followed by the numeral 3.

If your language ignores certain characters that can be placed between the numerals, it's not a valid substitution. So for example if your language interprets the literal 1_5 as 15, this would count as the numeral 1 followed by the numeral 5.

Alternative bases are included in the restriction, so for example:

Binary 100 can't be used as a substitute for 4.

Octal 10 can't be used as a substitute for 8.

Hexadecimal F can't be used as a substitute for 15.

Therefore, the following is a valid (but not very inspired) Java program to output The Numbers because The Numbers do not appear in its source code:

```<code>class TheNumbers {
    public static void main(String[] args) {
        for(int n = '*';;) {
            System.out.println(n -= '&');
            System.out.println(n *= 2);
            System.out.println(n += 7);
            System.out.println(++n);
            System.out.println(n += 7);
            System.out.println(n += 19);
        }
    }
}
</code>```

Note that in that program, '*' and '&' are substituted for the integers 42 and 38, because otherwise the numerals 4 and 8 would appear in its source code.

The definition of "outputs the sequence infinitely" is open to interpretation. So, for example, a program that outputs glyphs getting smaller until they are "infinitely" small would be valid.

Kudos if you are able to generate the sequence in some way that's not basically hard-coding each number.

Deriving it to a formula. My impression is there is not one but maybe there is or it can be faked.

Fixing a pseudo-random generator to return the sequence.

This is a popularity contest, so be creative. The answer with the most up votes on March 26th is the winner.

答:
JavaScript

var numbers = (Math.pow(0.07697703609326959*99200,2)*6997299).toString().split('0')
var i = 0
setInterval(function(){
  document.getElementsByTagName('html')[0].innerHTML += numbers[i++%6]+' '
},50)
```

What I've done, is write a script that takes a number 408015016023042. Since there are no 0's in the sequence of numbers, I could put one in between every digit as splitting point.

The script then loops through some processes to find numbers by which the number can be:

Divided

Square-rooted

Divided again

Without:

Generating any of the forbidden numbers

Creating a floating point issue

I simply took a random match from a whole list of matches, and there is my answer, simply put into a setInterval.

It splits the number at the 0's, and loops through them, pushing them into the DOM.

You can try it in this Fiddle.

I've also put my script in this Fiddle with which I've looked up my answer. It's also compatible with sequences that contain all of the 0 - 9 digits.

Title: 4, 8, 15, 16, 23, 42

Body:
JavaScript

var numbers = (Math.pow(0.07697703609326959*99200,2)*6997299).toString().split('0')
var i = 0
setInterval(function(){
  document.getElementsByTagName('html')[0].innerHTML += numbers[i++%6]+' '
},50)

What I've done, is write a script that takes a number 408015016023042. Since there are no 0's in the sequence of numbers, I could put one in between every digit as splitting point.

The script then loops through some processes to find numbers by which the number can be:

Divided

Square-rooted

Divided again

Without:

Generating any of the forbidden numbers

Creating a floating point issue

I simply took a random match from a whole list of matches, and there is my answer, simply put into a setInterval.

It splits the number at the 0's, and loops through them, pushing them into the DOM.

You can try it in this Fiddle.

I've also put my script in this Fiddle with which I've looked up my answer. It's also compatible with sequences that contain all of the 0 - 9 digits.


答:
MATL, 11 bytes

```<code>E:t*4/G<f0)
</code>```

Similar algorithm to @KennyLau except that rather than looping indefinitely, I loop from 1...2n to save some bytes.

Try it Online!

Explanation

```<code>    % Implicitly grab the input
E   % Double the input
:   % Create an array from 1...2n
t*  % Square each element
4/  % Divide each element by 4
G<  % Test if each element is less than G
f   % Get the indices of the TRUE elements in the array from the previous operation
0)  % Get the last index (the first index where T*T/4 >= n)
    % Implicitly display the result.
</code>```

Body:
MATL, 11 bytes

E:t*4/G<f0)

Similar algorithm to @KennyLau except that rather than looping indefinitely, I loop from 1...2n to save some bytes.

Try it Online!

Explanation

    % Implicitly grab the input
E   % Double the input
:   % Create an array from 1...2n
t*  % Square each element
4/  % Divide each element by 4
G<  % Test if each element is less than G
f   % Get the indices of the TRUE elements in the array from the previous operation
0)  % Get the last index (the first index where T*T/4 >= n)
    % Implicitly display the result.


答:
Retina, 72 bytes

```<code>T`_Ι-ΠϘ0ΡΣ-ΩϠ`dl
[a-j]
$0aa
\d
$&0
T`_Α-ΕϜΖ-Θl`dd
\d+
$*
1
</code>```

Try it online.

Explanation

Basically - replace every Greek symbol with the number that it represents, then return the sum of all the resulting numbers:

Transliterate 10s digits to Arabic and 100s digits to the Latin alphabet (0-9 => a-j):

```<code>T`_Ι-ΠϘ0ΡΣ-ΩϠ`dl
</code>```

Append "aa " to any 100s digits:

```<code>[a-j]
$0aa
</code>```

Append "0 " to any 10s digits:

```<code>\d
$&0
</code>```

Transliterate 1's digits and Latin alphabet to Arabic:

```<code>T`_Α-ΕϜΖ-Θl`dd
</code>```

Convert all space-separated decimal numbers to unary:

```<code>\d+
$*
</code>```

Count the total number of unary 1s:

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

Title: Reverse Greek Conversion Golf

Body:
Retina, 72 bytes

T`_Ι-ΠϘ0ΡΣ-ΩϠ`dl
[a-j]
$0aa
\d
$&0
T`_Α-ΕϜΖ-Θl`dd
\d+
$*
1

Try it online.

Explanation

Basically - replace every Greek symbol with the number that it represents, then return the sum of all the resulting numbers:

Transliterate 10s digits to Arabic and 100s digits to the Latin alphabet (0-9 => a-j):

T`_Ι-ΠϘ0ΡΣ-ΩϠ`dl

Append "aa " to any 100s digits:

[a-j]
$0aa

Append "0 " to any 10s digits:

\d
$&0

Transliterate 1's digits and Latin alphabet to Arabic:

T`_Α-ΕϜΖ-Θl`dd

Convert all space-separated decimal numbers to unary:

\d+
$*

Count the total number of unary 1s:

1


答:
Jelly, 5 bytes

```<code>×4’½Ḟ
</code>```

This uses a closed form of @LeakyNun's approach.

Try it online!

Due to a lucky coincidence, Ḟ is overloaded as floor/real for real/complex numbers. This is one of the only three overloaded atoms in Jelly.

How it works

```<code>×4’½Ḟ  Main link. Argument: n (integer)

×4     Compute 4n.
  ’    Decrement; yield 4n - 1.
   ½   Square root; yield sqrt(4n - 1).
       If n < 2, this produces an imaginary number.
    Ḟ  If sqrt(4n - 1) is real, round it down to the nearest integer.
       If sqrt(4n - 1) is complex, compute its real part (0).
</code>```

Body:
Jelly, 5 bytes

×4’½Ḟ

This uses a closed form of @LeakyNun's approach.

Try it online!

Due to a lucky coincidence, Ḟ is overloaded as floor/real for real/complex numbers. This is one of the only three overloaded atoms in Jelly.

How it works

×4’½Ḟ  Main link. Argument: n (integer)

×4     Compute 4n.
  ’    Decrement; yield 4n - 1.
   ½   Square root; yield sqrt(4n - 1).
       If n < 2, this produces an imaginary number.
    Ḟ  If sqrt(4n - 1) is real, round it down to the nearest integer.
       If sqrt(4n - 1) is complex, compute its real part (0).


问:
The Versatile Integer Printer
Write a piece of code that is executable in at least three different languages. The code must output the integer 1 in language number one, 2 in language number two, 3 in language number three etc.

Rules:

The output must be only the integer, but trailing newlines are OK.

The code can't take input of any kind

Different major versions of the same language are considered unique. So, your code can be executable in Python 2 and Python 3, however Python 2.5 and Python 2.7 are not considered unique.

You may use a new language if and only if it has an esolang/wiki article, available interpreter and documentation, and has been used by at least two users on PPCG prior to using it in this challenge. It must also adhere to these 4 rules.

The score of your submission is the number of bytes in your code divided by the number of languages it can run in cubed. So, a 54 byte solution that is executable in 3 languages will have a score of 2:

```<code>54 / 3^3 = 2
</code>```

Lower score is better.

ContentLicense: CC BY-SA 4.0

Title: The Versatile Integer Printer

Body:
30 languages, 248 bytes, \$\frac {248} {30^3} = 0.009185\$

#|#?15g,@   	    kkmNmSaIeoe99+{\#/-;n@0ea
#[9!@>.>.eeaww#-1@*"12"	L
#{
###
#`{
25
print(4^2 +7)/2

"""
Jo is here.
$'main'MoO OOM
 7
>Jo, 30
>X Jo
f::=~27
::=]##}#(prin 29)
print (7/6*24)###;alert 2#-[>+<-----]>-.|#(write(if(= 1/5 .2)26 3))"""

Edit: Beatnik removed since primality testing in Beatnik might not be possible.

The code has tabs in it (which can get mangled by Stack Exchange) and a trailing newline, so here's the xxd:

00000000: 237c 233f 3135 672c 4020 2020 0920 2020  #|#?15g,@   .
00000010: 206b 6b6d 4e6d 5361 4965 6f65 3939 2b7b   kkmNmSaIeoe99+{
00000020: 5c23 2f2d 3b6e 4030 6561 0a23 5b39 2140  \#/-;n@0ea.#[9!@
00000030: 3e2e 3e2e 6565 6177 7723 2d31 402a 2231  >.>.eeaww#-1@*"1
00000040: 3222 094c 0a23 7b20 090a 2323 230a 2360  2".L.#{ ..###.#`
00000050: 7b0a 3235 0a70 7269 6e74 2834 5e32 202b  {.25.print(4^2 +
00000060: 3729 2f32 0a0a 0a22 2222 0a4a 6f20 6973  7)/2...""".Jo is
00000070: 2068 6572 652e 0a24 276d 6169 6e27 4d6f   here..$'main'Mo
00000080: 4f20 4f4f 4d0a 2037 0a3e 4a6f 2c20 3330  O OOM. 7.>Jo, 30
00000090: 0a3e 5820 4a6f 0a66 3a3a 3d7e 3237 0a3a  .>X Jo.f::=~27.:
000000a0: 3a3d 5d23 237d 2328 7072 696e 2032 3929  :=]##}#(prin 29)
000000b0: 0a70 7269 6e74 2028 372f 362a 3234 2923  .print (7/6*24)#
000000c0: 2323 3b61 6c65 7274 2032 232d 5b3e 2b3c  ##;alert 2#-[>+<
000000d0: 2d2d 2d2d 2d5d 3e2d 2e7c 2328 7772 6974  -----]>-.|#(writ
000000e0: 6528 6966 283d 2031 2f35 202e 3229 3236  e(if(= 1/5 .2)26
000000f0: 2033 2929 2222 220a                       3))""".

Alternatively, you can copy and paste the code from this "Try it online!" link.

This is pretty badly golfed, but I wanted to play off the idea that, once you have enough languages, byte count doesn't matter as much any more. Having said that there are some languages I could still easily add (e.g. Objeck) but are currently too long to be useful. I'm running out of good languages though, so I might stop here for now.

Run all programs with </dev/null 2>/dev/null (i.e. empty input, surpressed STDERR).

The explanation's quite long, so here's an executive summary:

No.
Lang.
Non-esolang?
2D esolang?
BF/BF-deriv?

1
COW
✗
✗
✓

2
CoffeeScript
✓
✗
✗

3
Common Lisp
✓
✗
✗

4
Retina
✗
✗
✗

5
Befunge-93
✗
✓
✗

6
Python 2
✓
✗
✗

7
Rail
✗
✓
✗

8
ETA
✗
✗
✗

9
Prelude
✗
✗
✗

10
Gol><>
✗
✓
✗

11
evil
✗
✗
✗

12
Foo
✗
✗
✓

13
Ruby
✓
✗
✗

14
><>
✗
✓
✗

15
Brian & Chuck
✗
✗
✓

16
Whitespace
✗
✗
✗

17
3var
✗
✗
✗

18
Axo
✗
✓
✗

19
Labyrinth
✗
✓
✗

20
Starry
✗
✗
✗

21
Fission
✗
✓
✗

22
Brainfuck
✗
✗
✓

23
Julia
✓
✗
✗

24
Lily
✓
✗
✗

25
GolfScript
✗
✗
✗

26
Chicken Scheme
✓
✗
✗

27
Thue
✗
✗
✗

28
Perl 6
✓
✗
✗

29
Picolisp
✓
✗
✗

30
TRANSCRIPT
✗
✗
✗

1. COW

COW is a Brainfuck derivative with additional commands, one of which is numeric output. Anything invalid is ignored, so the executed program is merely

MoO OOM

which increments the cell to 1 then prints it as a number.

2. CoffeeScript (includes interpreter)

CoffeeScript sees:

# comments
###
multiline comment
###;alert 2# comment

which simply alerts 2.

(Yes, it'd probably be better if another language took this slot, but I'm too lazy to reshuffle at this point :P)

3. Common Lisp | ideone

Common Lisp (clisp) sees:

#|
multiline comment
|#(write(if(= 1/5 .2)26 3))"""

1/5 is a rational and not equal to 0.2, so 3 is printed. The proceeding """ is a syntax error.

Note that print seems to output a preceding newline and trailing space in Common Lisp.  However, luckily, write works in both Common Lisp and Chicken Scheme.

4. Retina | Try it online!

Restrictions introduced: Every second line starting from the first needs to be a valid regex.

Every pair of lines form a replacement stage, replacing instances of matches of the first line's regex with the second line. In the middle, we have the pair

"""

which replaces the initial empty string with """. The final empty line, not part of any pair, is treated as a match stage, counting the number of matches of the regex. There are four instances of empty string in """, namely 1"2"3"4.

5. Befunge-93 | Interpreter

Befunge is a 2D language, and the relevant instructions are

# # 15g,@

in the first line, and the 5 in the 25 line. # skips the next instruction, 15g gets the char at position (1, 5) in the code (the 5 in the 25 line), , outputs the char and @ halts.

6. Python 2 | ideone

Python sees:

# comments
25
print(4^2 +7)/2

"""
multiline string
"""

(4^2+7)/2 = (xor(4,2)+7)/2 = (6+7)/2 = 13/2 = 6, which gets printed.

7. Rail | Try it online!

Rail is a 2D language, and execution start from the $ of the main function, heading southeast. Thus, the relevant portion of code is

$'main'
 7
  o
   J

with the o and J coming from lines used by TRANSCRIPT. After outputting 7, the train hits an unrecognised J instruction, which crashes the program.

8. ETA | Try it online!

Restrictions introduced: Chars before the ETA program should not be in etaoinsh.

ETA only recognises the letters etaoinsh and their uppercase versions, meaning the code starts off with

NSaIeoe

n...e pushes a base 7 number based on what's within the delimiters, which for SaI is 624, or 312 in decimal. o then outputs as char, apparently after modulo 256, giving the char 8 (code point 56). e then tries to divide with an empty stack, which fails.

9. Prelude | Try it online!

Restrictions introduced: No more than one of () in any column, () matched reading a column at a time, no infinite loops caused by ().

This requires the Python interpreter to have NUMERIC_OUTPUT = True set.

Prelude is a language where each line is executed separately. A lot of chars get executed, but the important part is the

9!

on the second line, which outputs 9. () in Prelude denote a loop, but thanks to the prominence of #s (which pop from the stack), the tops of the stacks are always 0 by the time a loop is hit, so none of them are run. Prelude's source code restrictions regarding () introduced some extraneous spaces though.

10. Gol><> | Interpreter

This part (and ><>) work like Martin's answer. The relevant code is

#                                      ;n@0ea

Gol><> is a 2D language and # reflects the IP, making it travel leftwards. It wraps around, push 10, 14 and 0 to the stack. @ then rotates the stack, bringing 10 to the top, n outputs it and ; halts the program.

11. evil |  Try it online!

This part's also similar to Martin's answer.

evil ignores everything except lowercase letters. Ignoring a few more characters, the relevant part is

aeeeaeeaww

where a increments the variable A, e is evil's weave function which shuffles the bits of A, and w outputs A. Hence we output 1 twice, giving 11.

But what about the rest of the instructions, and especially that w on the last line? Let's just say that sometimes it's easiest to just mess with the code and pray it still works in everything which, here, it somehow did...

12. Foo | Try it online!

Foo outputs anything between double quotes, so the relevant part is the

"12"

on the second line. However, since we need double quotes later we use a method similar to Martin's answer to make Foo error out, namely the preceding #-1@. It's unclear why that works in a language which soldiers on in the face of empty stack and division by zero errors, but I'm glad it does.

13. Ruby | ideone

Like Python, Ruby sees:

# comments
25
print(4^2 +7)/2

"""
multiline string
"""

However, it's worth noting that the multiline string is actually three separate strings ("", "...", "") concatenated together. The print line outputs (4^2+7) = xor(4,2)+7 = 6+7 = 13, before erroring out trying to divide nil by 2.

14. ><> | Try it online!

This part's the same as the Gol><> part, except @ brings the 14 up to the top instead, which gets outputted.

15. Brian & Chuck | Try it online!

Brian & Chuck is a BF derivative with two tapes, where one tape's instruction pointer is the other tape's memory pointer. In the absence of ```, the first two lines of the source code are used to initialise the tapes.

The relevant chars in the first two lines are:

   ?15
#     >.>.

The ? in Brian's tape passes control over to Chuck in the cell being pointed to (the #) is nonzero. Chuck then executes >.>., outputting the two chars after the question mark.

16. Whitespace | Interpreter

Using STL for space, tab and line feed respectively, the start of the program is:

SSSTSSSSL
TL
STL
L
L

The first line pushes 16 (+10000 base 2), the preceding TLST prints it as a number. The next three newlines halt the program.

Note, however, that this program is interpreter specific. The rest of the code syntax errors in most interpreters, so a more lenient interpreter is required, like the one linked above.

17. 3var | Try it online!

Of the first line, a slew of instructions get executed, but the relevant ones are

kkmmao#/

Due to ETA's restriction, we use k to decrement the variable B rather than a to increment it. kk decrements B to -2 and mm squares B twice to 16, which is incremented to 17 with a. This is then outputted with o.

# is then used to reset B to 0, and / causes the program to error out via division by 0.

18. Axo | Try it online!

Restrictions introduced: No instructions before the Axo program which change the direction of the IP

Once again, a slew of instructions get executed in the first line, but the relevant ones are

# # 15 ,@            9 9  + {   \

Axo is a 2D language like Befunge, and # is similarly a bridge that skips the next instruction, but only if the top of the stack is zero. 15, push to the stack, but the stack is emptied with @. 99+ then pushes 18, { outputs and \ halts.

19. Labyrinth | Try it online!

Labyrinth is another 2D language, and the executed instructions are

#|#
 [9!@

# pushes the length of the stack, which is 0 the first time. | is bitwise OR, not changing anything since the stack just has 0s at this point, and the second # now pushes 1 due to the lone zero. We turn right due to the 1, 9 converts this 1 to 1*10+9 = 19, ! prints it and @ halts.

This program relies on the fact that [ is not currently a recognised instruction, and hence is treated as a wall.

20. Starry | Try it online!

Restrictions introduced: All +s must have at least one preceding space

If we strip away unrecognised characters, the relevant part of the code is

,       +.. +

, is input, but since we pipe from /dev/null there is none, pushing 0 to the stack. A + with n >= 5 preceding spaces pushes n-5, so the next instruction pushes 2. .. then outputs these two digits in reverse order.

Next we have a + with a single preceding space, which duplicates. However, the stack is empty, so we error out.

21. Fission | Try it online!

The only relevant part for Fission is

*"12"L

L spawns an atom moving leftward, "21" prints 21 and * halts.

22. Brainfuck | Try it online!

Introduced restrictions: No . before the first [

This requires an interpreter which gives 0 on EOF and has 8-bit cells. The relevant code is

,+-[>.>.-+.>,>]-[>+<-----]>-..

The inital - is to offset the +, and the first [...] is not executed since the cell is 0. The following -[>+<-----]>- sets the cell to the char code of 2, and .. outputs it twice.

23. Julia | Try it online!

Julia sees:

# comments
25
print(4^2 +7)/2

What's printed is 4^2+7 = pow(4,2)+7 = 16+7 = 23, and the program errors out trying to divide nothing by 2. Note that Julia doesn't seem to mind the fact that the rest of the code would cause a syntax error anyway.

24. Lily | Interpreter

Lily sees:

# comment
#[
multiline comment
]## comment
print (7/6*24)# comment

7/6*24 = 1*24 = 24 is printed.

25. GolfScript | Try it online!

GolfScript sees:

# comments
25
print(

GolfScript is stack-based, so 25 is pushed to the stack, then popped and printed with print. ( then tries to decrement the implicit empty string on the stack, which fails and errors out the program.

26. Chicken Scheme | ideone

Chicken Scheme has the same #| ... |# multiline comment syntax as Common Lisp. However, in

(write(if(= 1/5 .2)26 3))

1/5 is a float which is equal to 0.2, so 26 is outputted instead.

27. Thue | Try it online!

Thue is a language based on string rewriting. The first relevant part is

f::=~27
::=

which defines a substitution f -> 27 then denotes the end of substitutions with ::=. The lone f in if is then replaced with 27, which is outputted.

28. Perl 6 | ideone

Perl 6 has a new comment syntax, namely #`(some bracket) which is a multiline comment all the way to the matching bracket. Thus, Perl 6 sees:

# comments
#`{
multiline comment
}# comment
print (7/6*24)# comment

which prints 7/6*24 = 28.

29. Picolisp | ideone

Picolisp sees:

# comment
#{
multiline comment
}#(prin 29)

which prints 29. The line afterwards then causes a syntax error.

30. TRANSCRIPT | Try it online!

TRANSCRIPT is a thematic esolang modelled after text adventures. Unrecognised lines are ignored (which allows you to add extra story/flavour text amongst the actual code instructions), so the relevant lines are:

Jo is here.
>Jo, 30
>X Jo

The first line declares a string variable Jo, using a two-letter name since one-letter names seem to fail. The second line sets this string to "30", which is outputted by X ("examine") in the third line.


答:
Perl, <s>93</s> <s>89</s> <s>81</s> <s>77</s> <s>76</s> <s>75</s> 74 bytes

Includes +2 for -0p

Run with the input pattern (with all lines space padded to the same length) on STDIN:

```<code>gravity.pl < gravity.txt
</code>```

gravity.pl:

```<code>#!/usr/bin/perl -0p
/
/;$n=".{@-}";s/#$n\K( $n)*\b |(^|w)([w ]$n)*\K $n#/w|$&/es&&redo;$_=m;w
</code>```

This file based version needs the final newline, so that is really 75 bytes. But the commandline based version doesn't need that extra newline so this counts as 74 bytes:

```<code>perl -0pe '/
/;$n=".{@-}";s/#$n\K( $n)*\b |(^|w)([w ]$n)*\K $n#/w|$&/es&&redo;$_=m;w' < gravity.txt
</code>```

Explanation:

This will construct a string with a w in each positions gravity guy can reach.
So for the second to last truthy example it will construct:

```<code>     #########
    ##### ####
   #wwwww#wwww#
  #w  # #w ##ww#
wwwww wwwwwww#ww#
#####  ####  w#ww
     wwwwwwwwww#
     #########
</code>```

So gravity guy can make it if and only if there is a w in the last column.
The string will be constructed by replacing one reachable space by w in each round.

Each replacement will be of the form

```<code>s/prefix \K space postfix/ w | $& /e
</code>```

which will demand that the space is preceded by prefix and followed by postfix but replace only the space by w without needing lots of advanced grouping.

Assume $n contains a regex that will progress just enough that the left and right sides are exactly below each other. Then the relevant regexes are:

```<code>/^( $n)*\K $n#/       From the first position drop down as long as you
                      encounter spaces until you encounter a #.
                      This puts gravity guy on his starting platform

/#$n\K( $n)*\b /      A space immediately below a # and if you (optionally)
                      go down further from there (as as the descent is
                      over spaces) you get to a space that follows a word
                      boundary. The only way to get a word boundary is if
                      there is a w in front of that space. This selects the
                      position gravity guy ends up on if starting from that
                      w and gravity is up
/w([w ]$n)*\K $n#/    A w followed by a space (or w) and if you go down from
                      there as long as it is over spaces (or w) you finally
                      end up on a space directly above a #. This handles the
                      gravity down case. The test uses "space or w" instead
                      of just space to handle this case:

                       #
                      ww
                      #x
                       #

                      Position x is currently a space and must be replaced by a
                      w but the gravity up regex has already put a w directly
                      after the w gravity guy takes off from. So for gravity
                      down we must handle w as if it is still a space. This
                      is not needed for gravity up because regex always matches
                      starting at the earliest possible character, so
                      gravity up matches before gravity down
</code>```

With that out of the way the program is easy:

```<code>#!/usr/bin/perl -0p   Slurp all of STDIN into $_, at the end print $_

/\n/                  Match the first newline (needed to measure the row
                      length)
$n=".{@-}"            $n effectively becomes rowlength-1 times ".". This
                      will be the regex that goes one step down a column

s/#$n\K( $n)*\b |(^|w)([w ]$n)*\K $n#/w|$&/es

                     This is the 3 regexes shown above combined. The s
                     modifier is needed so the . in $n also matches newline

    &&redo           Keep looping as long as w's keep getting added

$_=m;w\n;            Check if the last column contains a w: He made it!
                     The \n; at the end is not written. These 2 bytes sneakily
                     come from the -p option for the ; and the -e option
                     for the \n
</code>```

Title: Can Gravity Guy Make It?

Body:
Gravity Guy is a game where the only user input is a single key that flips the direction of gravity. Given an ASCII art level, determine if it is possible for Gravity Guy to reach the end.

Rules

The initial direction of gravity is down.

The first column of the input will always contain only one #, which Gravity Guy starts on top of.

Each iteration, he moves to the character directly on his right.

If his path is blocked and he moves into a #, the player loses.

After moving, the player can optionally switch gravity from down to up, or up to down.

Gravity Guy then falls on to the next # (in the current direction of gravity).

If there is no # to fall on to and he falls off the grid, the player loses.

If Gravity Guy moves off the right side of the input grid, the player wins.

Example

If this was the input grid:

```<code>  ###

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

Gravity Guy would start at the x and the be at these positions after each iteration. ^ = switch gravity to up and v = switch gravity to down.

```<code>v                        ^                               v
-------------------------------------------------------------
  ###   |    ###   |    ###   |    ###   |    ###   |    ###
x       |          |    x     |     x    |      x   |
#  #    |  #x #    |  #  #    |  #  #    |  #  #    |  #  # x
 ### #  |   ### #  |   ### #  |   ### #  |   ### #  |   ### #
</code>```

As you can see, by switching gravity at these times Gravity Guy reaches the end, so this input would return a truthy value.

Specifications

Input grid can be in any appropriate "grid" format (multiline string padded with spaces, array of line strings, array of array of characters, etc).

If it is possible for the player to win the level, output a truthy value. If not, output a falsey value.

The width and height of the grid will be 50 characters at most.

This is code-golf, may the shortest code in bytes win!

Test Cases

(each case separated by ----------, any blank lines should also be padded with spaces)

True

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

----------

###

----------

   #####

####

----------

 #####
 # # #

# # #
 #####

----------

   ############

######      ######

   ############

----------

  ###   ###
     # #
####  #  ####
    #   #
     # #
      #

----------

    ######
   #
 ##
     #######
###     #
   #    #
    #####

----------

    #####
   #    #
 ##     #
     #######
###
   #
    ######

----------

  ###

#  # #
 ###

----------

  ###  ###

###     ##
   #    #
    #####

----------

  #
     #   #
       #
#   #     #
        #
   #
      #
 #

----------

    ##### ####
   #     #    #
  #   # #  ##  #
             #  #
#####  ####   #
               #
     #########

----------

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

False

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

----------

### ###

----------

    #
 ### ###

#### ###
    #

----------

  ###     ###
     # # #
####  # #  ####
    #     #
     #   #
      # #
       #

----------

  #######
  #     #
 ## #####

### ######
  #     #
  #######

----------

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

Body:
Perl, <s>93</s> <s>89</s> <s>81</s> <s>77</s> <s>76</s> <s>75</s> 74 bytes

Includes +2 for -0p

Run with the input pattern (with all lines space padded to the same length) on STDIN:

gravity.pl < gravity.txt

gravity.pl:

#!/usr/bin/perl -0p
/
/;$n=".{@-}";s/#$n\K( $n)*\b |(^|w)([w ]$n)*\K $n#/w|$&/es&&redo;$_=m;w

This file based version needs the final newline, so that is really 75 bytes. But the commandline based version doesn't need that extra newline so this counts as 74 bytes:

perl -0pe '/
/;$n=".{@-}";s/#$n\K( $n)*\b |(^|w)([w ]$n)*\K $n#/w|$&/es&&redo;$_=m;w' < gravity.txt

Explanation:

This will construct a string with a w in each positions gravity guy can reach.
So for the second to last truthy example it will construct:

     #########
    ##### ####
   #wwwww#wwww#
  #w  # #w ##ww#
wwwww wwwwwww#ww#
#####  ####  w#ww
     wwwwwwwwww#
     #########

So gravity guy can make it if and only if there is a w in the last column.
The string will be constructed by replacing one reachable space by w in each round.

Each replacement will be of the form

s/prefix \K space postfix/ w | $& /e

which will demand that the space is preceded by prefix and followed by postfix but replace only the space by w without needing lots of advanced grouping.

Assume $n contains a regex that will progress just enough that the left and right sides are exactly below each other. Then the relevant regexes are:

/^( $n)*\K $n#/       From the first position drop down as long as you
                      encounter spaces until you encounter a #.
                      This puts gravity guy on his starting platform

/#$n\K( $n)*\b /      A space immediately below a # and if you (optionally)
                      go down further from there (as as the descent is
                      over spaces) you get to a space that follows a word
                      boundary. The only way to get a word boundary is if
                      there is a w in front of that space. This selects the
                      position gravity guy ends up on if starting from that
                      w and gravity is up
/w([w ]$n)*\K $n#/    A w followed by a space (or w) and if you go down from
                      there as long as it is over spaces (or w) you finally
                      end up on a space directly above a #. This handles the
                      gravity down case. The test uses "space or w" instead
                      of just space to handle this case:

                       #
                      ww
                      #x
                       #

                      Position x is currently a space and must be replaced by a
                      w but the gravity up regex has already put a w directly
                      after the w gravity guy takes off from. So for gravity
                      down we must handle w as if it is still a space. This
                      is not needed for gravity up because regex always matches
                      starting at the earliest possible character, so
                      gravity up matches before gravity down

With that out of the way the program is easy:

#!/usr/bin/perl -0p   Slurp all of STDIN into $_, at the end print $_

/\n/                  Match the first newline (needed to measure the row
                      length)
$n=".{@-}"            $n effectively becomes rowlength-1 times ".". This
                      will be the regex that goes one step down a column

s/#$n\K( $n)*\b |(^|w)([w ]$n)*\K $n#/w|$&/es

                     This is the 3 regexes shown above combined. The s
                     modifier is needed so the . in $n also matches newline

    &&redo           Keep looping as long as w's keep getting added

$_=m;w\n;            Check if the last column contains a w: He made it!
                     The \n; at the end is not written. These 2 bytes sneakily
                     come from the -p option for the ; and the -e option
                     for the \n


问:
Regex Golf: Verify a Sudoku Solution
Write a regex which matches any valid sudoku solution and doesn't match any invalid sudoku solution. The input is an unrolled version of the sudoku, i.e. there are no line delimiters. E.g. the following board:

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

would be given as:

```<code>725893461841657392396142758473516829168429537952378146234761985687935214519284673
</code>```

The rules are probably common knowledge by now, but just in case... a sudoku board is valid if and only if:

Each row contains the digits from 1 to 9 exactly once.

Each column contains the digits from 1 to 9 exactly once.

Each of the nine 3x3 subgrids contains the digits from 1 to 9 exactly once.

Rules

Your answer should consist of a single regex, without any additional code (except, optionally, a list of regex modifiers required to make your solution work). You must not use features of your language's regex flavour that allow you to invoke code in the hosting language (e.g. Perl's e modifier).

You can use any regex flavour which existed before this challenge, but please specify the flavour.

Do not assume that the regex is anchored implicitly. E.g. if you're using Python, assume that your regex is used with re.search and not with re.match. Your regex does not need to match the entire string. It just needs to match at least one substring (which may be empty) for valid solutions and yield no matches for invalid solutions.

You may assume that the input will always be a string of 81 positive digits.

This is regex golf, so the shortest regex in bytes wins. If your language requires delimiters (usually /.../) to denote regular expressions, don't count the delimiters themselves. If your solution requires modifiers, add one byte per modifier.

Test Cases

Valid boards:

```<code>123456789456789123789123456231564897564897231897231564312645978645978312978312645
725893461841657392396142758473516829168429537952378146234761985687935214519284673
395412678824376591671589243156928437249735186738641925983164752412857369567293814
679543182158926473432817659567381294914265738283479561345792816896154327721638945
867539142324167859159482736275398614936241587481756923592873461743615298618924375
954217683861453729372968145516832497249675318783149256437581962695324871128796534
271459386435168927986273541518734269769821435342596178194387652657942813823615794
237541896186927345495386721743269158569178432812435679378652914924813567651794283
168279435459863271273415986821354769734692518596781342615947823387526194942138657
863459712415273869279168354526387941947615238138942576781596423354821697692734185
768593142423176859951428736184765923572389614639214587816942375295837461347651298
243561789819327456657489132374192865926845317581673294162758943735914628498236571
243156789519847326687392145361475892724918653895263471152684937436729518978531264
498236571735914628162758943581673294926845317374192865657489132819327456243561789
978531264436729518152684937895263471724918653361475892687392145519847326243156789
341572689257698143986413275862341957495726831173985426519234768734869512628157394
</code>```

Invalid boards:

```<code>519284673725893461841657392396142758473516829168429537952378146234761985687935214
839541267182437659367158924715692843624973518573864192298316475941285736456729381
679543182158926473432817659567381294914256738283479561345792816896154327721638945
867539142324167859159482736275398684936241517481756923592873461743615298618924375
754219683861453729372968145516832497249675318983147256437581962695324871128796534
271459386435168927986273541518734269769828435342596178194387652657942813823615794
237541896186927345378652914743269158569178432812435679495386721924813567651794283
168759432459613278273165984821594763734982516596821347615437829387246195942378651
869887283619214453457338664548525781275424668379969727517385163319223917621449519
894158578962859187461322315913849812241742157275462973384219294849882291119423759
123456789456789123564897231231564897789123456897231564312645978645978312978312645
145278369256389147364197258478512693589623471697431582712845936823956714931764825
243561789829317456657489132374192865916845327581673294162758943735924618498236571
243156789529847316687392145361475892714928653895263471152684937436719528978531264
498236571735924618162758943581673294916845327374192865657489132829317456243561789
978531264436719528152684937895263471714928653361475892687392145529847316243156789
342571689257698143986413275861342957495726831173985426519234768734869512628157394
345678192627319458892451673468793521713524986951862347179246835534187269286935714
341572689257698143986413275862341957495726831173985426519234768734869512628517394
</code>```

For further test cases, you can use this CJam script which takes a valid board as input and randomly shuffles it to give a new valid board (input format irrelevant as long as it contains only digits and optionally whitespace).

If your regex is compatible with the .NET flavour, you can test it online using Retina. A valid solution should print 0 for invalid boards and some positive integer for valid boards. To run all test cases at once, use this template and insert the regex on the second line. If you need regex modifiers, prepend a ` to the regex and put the standard modifier letters in front of it.

答:
Ruby regex, 71 78 73 bytes

```<code>^(?!.*(?=(.))(.{9}+|(.(?!.{9}*$))+|(?>.(?!.{3}*$)|(.(?!.{27}*$)){7})+)\1)
</code>```

I don't really know Ruby but apparently it doesn't complain about cascaded quantifiers.

Try it here.

.NET regex, 79 78 75 or 77 bytes

Because Martin thinks this is possible... But I guess he will just incorporate these changes too.

```<code>^(?!(.)+((.{9})+|(?>(.{9})+
|.)+|(?((...)*
)(?>(.{27})+
|.){7}|.)+)(?<=\1))
</code>```

Requires a trailing newline in the input to work. I'm not sure whether I'm allowed to do this (probably not).

Try it here.

The 77 byte sane version:

```<code>^(?!(.)+((.{9})+|((?!(.{9})*$).)+|(?((...)*$)((?!(.{27})*$).){7}|.)+)(?<=\1))
</code>```

Thanks Neil for pointing out the error in my previous version and golfing off 1 byte (for the (...)*).

Try it here.

PCRE, 77 78 bytes

```<code>^(?!.*(?=(.))((.{9})+|(.(?!(?3)*$))+|(?(?=.(...)*$)(.(?!(.{27})*$)){7}|.)+)\1)
</code>```

Just for completeness.

Try it here.

Another version, also 78 bytes:

```<code>^(?!.*(?=(.))((.{9})+|(.(?!(?3)*$))+|(?>.(?!(...)*$)|(.(?!(.{27})*$)){7})+)\1)
</code>```

Try it here.

Explanation

```<code>^(?!.*                    # Match a string that doesn't contain the pattern,
                          # at any position.
  (?=(.))                 # Capture the next character.
  (
    (.{9})+               # Any 9*n characters. The next character is in
                          # the same column as the captured one.
  |
    (.(?!(.{9})*$))+      # Any n characters not followed by a positions 9*m
                          # to the end. The next character is in the same row
                          # as the captured one.
  |
    (                     # Any n occasions of...
    ?(.(...)*$)           # If it is at a position 3*k+1 to the end:
      (.(?!(.{27})*$)){7} # Then count 7*m characters that are not followed
                          # by a position 27*j to the end,
    |
      .                   # Else count any character.
    )+                    # The next character is in the same block as the
                          # captured one.
  )
  \1                      # Fail if the next character is the captured character.
)
</code>```

Title: Regex Golf: Verify a Sudoku Solution

Body:
Ruby regex, 71 78 73 bytes

^(?!.*(?=(.))(.{9}+|(.(?!.{9}*$))+|(?>.(?!.{3}*$)|(.(?!.{27}*$)){7})+)\1)

I don't really know Ruby but apparently it doesn't complain about cascaded quantifiers.

Try it here.

.NET regex, 79 78 75 or 77 bytes

Because Martin thinks this is possible... But I guess he will just incorporate these changes too.

^(?!(.)+((.{9})+|(?>(.{9})+
|.)+|(?((...)*
)(?>(.{27})+
|.){7}|.)+)(?<=\1))

Requires a trailing newline in the input to work. I'm not sure whether I'm allowed to do this (probably not).

<a href="http://retina.tryitonline.net/#code=bWAkCk4KJShHYApeKD8hKC4pKygoLns5fSkrfCg_Piguezl9KStOfC4pK3woPygoLi4uKSpOKSg_PiguezI3fSkrTnwuKXs3fXwuKSspKD88PVwxKSk&input=MTIzNDU2Nzg5NDU2Nzg5MTIzNzg5MTIzNDU2MjMxNTY0ODk3NTY0ODk3MjMxODk3MjMxNTY0MzEyNjQ1OTc4NjQ1OTc4MzEyOTc4MzEyNjQ1CjcyNTg5MzQ2MTg0MTY1NzM5MjM5NjE0Mjc1ODQ3MzUxNjgyOTE2ODQyOTUzNzk1MjM3ODE0NjIzNDc2MTk4NTY4NzkzNTIxNDUxOTI4NDY3MwozOTU0MTI2Nzg4MjQzNzY1OTE2NzE1ODkyNDMxNTY5Mjg0MzcyNDk3MzUxODY3Mzg2NDE5MjU5ODMxNjQ3NTI0MT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ODkyNjg3MzkyMTQ1NTI5ODQ3MzE2MjQzMTU2Nzg5CjM0MjU3MTY4OTI1NzY5ODE0Mzk4NjQxMzI3NTg2MTM0Mjk1NzQ5NTcyNjgzMTE3Mzk4NTQyNjUxOTIzNDc2ODczNDg2OTUxMjYyODE1NzM5NAoxMjM0NTY3ODkyMzQ1Njc4OTEzNDU2Nzg5MTI0NTY3ODkxMjM1Njc4OTEyMzQ2Nzg5MTIzNDU3ODkxMjM0NTY4OTEyMzQ1Njc5MTIzNDU2Nzg" rel="noreferrer">Try it here.

The 77 byte sane version:

^(?!(.)+((.{9})+|((?!(.{9})*$).)+|(?((...)*$)((?!(.{27})*$).){7}|.)+)(?<=\1))

Thanks Neil for pointing out the error in my previous version and golfing off 1 byte (for the (...)*).

<a href="http://retina.tryitonline.net/#code=JShHYApeKD8hKC4pKygoLns5fSkrfCgoPyEoLns5fSkqJCkuKSt8KD8oKC4uLikqJCkoKD8hKC57Mjd9KSokKS4pezd9fC4pKykoPzw9XDEpKQ&input=MTIzNDU2Nzg5NDU2Nzg5MTIzNzg5MTIzNDU2MjMxNTY0ODk3NTY0ODk3MjMxODk3MjMxNTY0MzEyNjQ1OTc4NjQ1OTc4MzEyOTc4MzEyNjQ1CjcyNTg5MzQ2MTg0MTY1NzM5MjM5NjE0Mjc1ODQ3MzUxNjgyOTE2ODQyOTUzNzk1MjM3ODE0NjIzNDc2MTk4NTY4NzkzNTIxNDUxOTI4NDY3MwozOTU0MTI2Nzg4MjQzNzY1OTE2NzE1ODkyNDMxNTY5Mjg0MzcyNDk3MzUxODY3Mzg2NDE5MjU5ODMxNjQ3NTI0MTI4NTczNjk1NjcyOTM4MTQKNjc5NTQzMTgyMTU4OTI2NDczNDMyODE3NjU5NTY3MzgxMjk0OTE0MjY1NzM4MjgzNDc5NTYxMzQ1NzkyODE2ODk2MTU0MzI3NzIxNjM4OTQ1Cjg2NzUzOTE0MjMyNDE2Nzg1OTE1OTQ4MjczNjI3NTM5ODYxNDkzNjI0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nzg5MTI0NTY3ODkxMjM1Njc4OTEyMzQ2Nzg5MTIzNDU3ODkxMjM0NTY4OTEyMzQ1Njc5MTIzNDU2Nzg" rel="noreferrer">Try it here.

PCRE, 77 78 bytes

^(?!.*(?=(.))((.{9})+|(.(?!(?3)*$))+|(?(?=.(...)*$)(.(?!(.{27})*$)){7}|.)+)\1)

Just for completeness.

Try it here.

Another version, also 78 bytes:

^(?!.*(?=(.))((.{9})+|(.(?!(?3)*$))+|(?>.(?!(...)*$)|(.(?!(.{27})*$)){7})+)\1)

Try it here.

Explanation

^(?!.*                    # Match a string that doesn't contain the pattern,
                          # at any position.
  (?=(.))                 # Capture the next character.
  (
    (.{9})+               # Any 9*n characters. The next character is in
                          # the same column as the captured one.
  |
    (.(?!(.{9})*$))+      # Any n characters not followed by a positions 9*m
                          # to the end. The next character is in the same row
                          # as the captured one.
  |
    (                     # Any n occasions of...
    ?(.(...)*$)           # If it is at a position 3*k+1 to the end:
      (.(?!(.{27})*$)){7} # Then count 7*m characters that are not followed
                          # by a position 27*j to the end,
    |
      .                   # Else count any character.
    )+                    # The next character is in the same block as the
                          # captured one.
  )
  \1                      # Fail if the next character is the captured character.
)


答:
Python, 28 bytes

lambda n:max(4*n-1,0)**.5//1
```

Outputs a float. The max is there to give 0 for n<=0 while avoiding an error for square root of negative.

Body:
Python, 28 bytes

lambda n:max(4*n-1,0)**.5//1

Outputs a float. The max is there to give 0 for n<=0 while avoiding an error for square root of negative.


答:
JavaScript (ES2016), 24 bytes

Shortened version of the ES6 variant below thanks to @Florent and the Exponentiation Operator (currently only in Firefox nightly builds or transpilers).

n=>(n-1)**.5+(n+1)**.5|0
```

<h1>JavaScript (ES6), 30 bytes</h1>

<pre class="lang-js prettyprint-override"><code>n=>(s=Math.sqrt)(n-1)+s(n+1)|0
</code>```

Based upon this sequence.

f=n=>(s=Math.sqrt)(n-1)+s(n+1)|0

units.oninput = () => output.value = f(+units.value||0);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><label>Units: <input id="units" type="number" value="0" /></label>
<label>Days: <input id="output" type="number" value="0" disabled /></label></code>```

Body:
JavaScript (ES2016), 24 bytes

Shortened version of the ES6 variant below thanks to @Florent and the Exponentiation Operator (currently only in Firefox nightly builds or transpilers).

n=>(n-1)**.5+(n+1)**.5|0

JavaScript (ES6), 30 bytes

n=>(s=Math.sqrt)(n-1)+s(n+1)|0

Based upon this sequence.

f=n=>(s=Math.sqrt)(n-1)+s(n+1)|0

units.oninput = () => output.value = f(+units.value||0);

<label>Units: <input id="units" type="number" value="0" /></label>
<label>Days: <input id="output" type="number" value="0" disabled /></label>


问:
What's the missing column/row? (GCJ 2016-1A rankfile)
There is an N x N square of numbers.

All columns increase strictly monotonically from top to down

All rows increase strictly monotonically from left to right

There is exactly one valid answer for each input.

You are given 2N-1 rows of N numbers representing rows or columns in this square. The task is to find the row that isn't in the input.

Your Task

Write a program or function that outputs the row or column that isn't in the input.

Input

First, you get the number N.

Then follow 2N-1 lines of N space-separated numbers, representing rows or columns of this N x N square. The lines are given in left-to-right or top-down order. There may be multiple equal lines. It is ok to omit the initial N from the input, or modify the input format as you like.

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

Output

Your program or function should output a single line of N numbers; the row or column from the square that was not present in the input. You may change the output format as you please.

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

This would correspond to one of two squares:

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

Either way, the output is the same.

Bonus

Your solution should be able to calculate 2 ≤ N ≤ 10 within a minute on a normal computer. If your solution handles the big input, 2 ≤ N ≤ 50, within a minute, you get -10% byte count.

Test cases

```<code>2
22 222
2 22
22 222
-> 2 22

3
1 2 3
2 3 5
3 5 6
2 3 4
1 2 3
-> 3 4 6

4
11 14 16 22
3 6 9 11
6 7 11 14
9 11 15 19
10 11 19 22
6 7 10 11
3 6 8 10
-> 8 10 15 16
</code>```

Note that you can simply change what line in these inputs that is omitted, and reorder them in any way you want, to generate new test cases.

This is a simplified version of Google Code Jam 2016 round 1A problem B: Rank and File. The original Google Code Jam problem, where you can get more test cases (but without answers), is available here: https://code.google.com/codejam/contest/4304486/dashboard#s=p1

答:
CJam, 5 - 10% = 4.5

This is an unnamed function (block) that takes an array of arrays and returns an array:

```<code>{:^$}
</code>```

(With some inspiration from Dennis)

Try it online

And here is the code I actually submitted at GCJ (24 bytes):

```<code>li2*({l~}*]$e`{(2%*~}%S*
</code>```

Try it online

Explanation:

This basically lists the values that appear an odd number of times.

```<code>:^    reduce by symmetric difference; pairs of duplicate values "cancel" each other
$     sort the resulting array
</code>```

Body:
CJam, 5 - 10% = 4.5

This is an unnamed function (block) that takes an array of arrays and returns an array:

{:^$}

(With some inspiration from Dennis)

Try it online

And here is the code I actually submitted at GCJ (24 bytes):

li2*({l~}*]$e`{(2%*~}%S*

Try it online

Explanation:

This basically lists the values that appear an odd number of times.

:^    reduce by symmetric difference; pairs of duplicate values "cancel" each other
$     sort the resulting array


问:
Chris Pine's "Deaf Grandma"
I'm a mentor at RubyLearning and one of the exercises we give to our students is the "Deaf Grandma" exercise from Chris Pine's book "Learn to Program". Here's the description:

Write a Deaf Grandma program. Whatever you say to grandma (whatever
  you type in), she should respond with:
  "Huh?! Speak up, sonny!", unless you
  shout it (type in all capitals). If
  you shout, she can hear you (or at
  least she thinks so) and yells back:
  "No, not since 1938!"

To make your program really believable, have grandma shout a
  different year each time; maybe any
  year at random between 1930 and 1950.
  (This part is optional, and would be
  much easier if you read the section on
  Ruby's random number generator at the
  end of the methods chapter.) You can't
  stop talking to grandma until you
  shout "BYE".

After several course iterations I tried to see how small I can get this and now have it down to 112 characters:

```<code>puts (s||='').upcase==s ? "NO, NOT SINCE #{1930+rand(21)}!":"HUH?! SPEAK UP, SONNY!" until(s=gets.chomp)=="BYE"
</code>```

I'm curious to see in how few characters this can be achieved in the language of your choice, because I think Ruby is already doing really well here.

Edit: The Perl solution posted below led to

```<code>ruby -nle 'puts($_=="BYE"?exit: $_.upcase!? "HUH?! SEPAK UP, SONNY!":"NO, NOT SINCE #{1930+rand(21)}!")'
</code>```

which is 92 characters for the expression + 2 more for the n and l options.

答:
Windows PowerShell, <s>121</s> 117

Due to the nature of the task this looks pretty much identical to Ty Auvil's solution, although it was written independently:

```<code>for(;($j=read-host)-cne'BYE'){if($j-cmatch'[a-z]'){'Huh?! Speak up, sonny!'}else{"No, not since 19$(30..50|random)"}}
</code>```

Thanks to SpellingD for the suggestion,

Title: Chris Pine's "Deaf Grandma"

Body:
Windows PowerShell, <s>121</s> 117

Due to the nature of the task this looks pretty much identical to Ty Auvil's solution, although it was written independently:

for(;($j=read-host)-cne'BYE'){if($j-cmatch'[a-z]'){'Huh?! Speak up, sonny!'}else{"No, not since 19$(30..50|random)"}}

Thanks to SpellingD for the suggestion,