答:
C++, 61 bytes.  (or 66 bytes to actually hit the disk on Linux+XFS+lazytime)

Timestamp metadata I/O only:

```<code>#include <fstream>
int main(){for(;;){std::ofstream a("a");}}
</code>```

The disk I/O is due to a's mod time changing, which will be written to disk occasionally.  (very occasionally with the commonly-use lazytime mount option.  Also see my C answer.)

Write data before closing:

```<code>#include <fstream>
int main(){for(;;){std::ofstream a("a");a<<4;}}
</code>```

Actually hits the disk: lights up my hard drive light.  (Linux 4.2.0, XFS, lazytime)

The ofstream constructor opens the file, and the destructor closes it again.  There are no resource leaks, so this will actually run forever without running out of memory, file handles, or disk space.

strace output:

```<code>open("a", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
write(3, "4", 1)                        = 1      # not present with first version
close(3)                                = 0
... repeating
</code>```

Title: Shortest code for infinite disk I/O

Body:
C++, 61 bytes.  (or 66 bytes to actually hit the disk on Linux+XFS+lazytime)

Timestamp metadata I/O only:

#include <fstream>
int main(){for(;;){std::ofstream a("a");}}

The disk I/O is due to a's mod time changing, which will be written to disk occasionally.  (very occasionally with the commonly-use lazytime mount option.  Also see my C answer.)

Write data before closing:

#include <fstream>
int main(){for(;;){std::ofstream a("a");a<<4;}}

Actually hits the disk: lights up my hard drive light.  (Linux 4.2.0, XFS, lazytime)

The ofstream constructor opens the file, and the destructor closes it again.  There are no resource leaks, so this will actually run forever without running out of memory, file handles, or disk space.

strace output:

open("a", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
write(3, "4", 1)                        = 1      # not present with first version
close(3)                                = 0
... repeating


问:
Fibonacci products
You can decompose a number greater than 0 as a unique sum of positive Fibonacci numbers. In this question we do this by repeatedly subtracting the largest possible positive Fibonacci number. E.g.:

```<code>1 = 1
2 = 2
3 = 3
4 = 3 + 1
12 = 8 + 3 + 1
13 = 13
100 = 89 + 8 + 3
</code>```

Now, I call a Fibonacci product the same lists as above, but with the addition replaced by multiplication. For example, \$f(100) = 89 \times 8 \times 3 = 2136\$.

Write a program or function that given a positive integer n returns the Fibonacci product of that number.

Testcases:

```<code>1: 1
2: 2
3: 3
4: 3
5: 5
6: 5
7: 10
8: 8
9: 8
42: 272
1000: 12831
12345: 138481852236
</code>```

答:
RETURN, 44 bytes

```<code>[a:[a;][1$[¤¤+$a;->~][]#%$␌a;\-a:]#␁[¤][×]#]
</code>```

Try it here.

Astonishingly inefficient anonymous lambda that leaves result on Stack2. Usage:

```<code>12345[a:[a;][1$[¤¤+$a;->~][]#%$␌a;\-a:]#␁[¤][×]#]!
</code>```

NOTE: ␌ and ␁ are placeholders for their respective unprintable chars: Form Feed and Start of Heading.

Explanation

```<code>[                                           ]  lambda
 a:                                            store input to a
   [  ][                         ]#            while loop
    a;                                           check if a is truthy
        1$[¤¤+$a;->~][]#%                        if so, generate all fibonacci numbers less than a
                         $␌                      push copy of TOS to stack2
                           a;\-a:                a-=TOS
                                   ␁[¤][×]#   get product of stack2
</code>```

ContentLicense: CC BY-SA 4.0

Title: Fibonacci products

Body:
RETURN, 44 bytes

[a:[a;][1$[¤¤+$a;->~][]#%$␌a;\-a:]#␁[¤][×]#]

Try it here.

Astonishingly inefficient anonymous lambda that leaves result on Stack2. Usage:

12345[a:[a;][1$[¤¤+$a;->~][]#%$␌a;\-a:]#␁[¤][×]#]!

NOTE: ␌ and ␁ are placeholders for their respective unprintable chars: Form Feed and Start of Heading.

Explanation

[                                           ]  lambda
 a:                                            store input to a
   [  ][                         ]#            while loop
    a;                                           check if a is truthy
        1$[¤¤+$a;->~][]#%                        if so, generate all fibonacci numbers less than a
                         $␌                      push copy of TOS to stack2
                           a;\-a:                a-=TOS
                                   ␁[¤][×]#   get product of stack2

ContentLicense: CC BY-SA 3.0


问:
Code-Golf: Lattice Points inside a Circle
The following picture shows the problem:

Write a function that, given an integer as the circle radius, calculates the number of lattice points inside the centered circle (including the boundary).

The image shows:

```<code>f[1] = 5  (blue points)
f[2] = 13 (blue + red points)
</code>```

other values for your checking/debugging:

```<code>f[3]    = 29
f[10]   = 317
f[1000] = 3,141,549
f[2000] = 12,566,345
</code>```

Should have a reasonable performance. Let's say less than a minute for f[1000].

Shortest code wins. Usual Code-Golf rules apply.

Please post the calculation and timing of f[1001] as an example.

答:
Mathematica, 35 characters

```<code>f[n_]:=Sum[SquaresR[2,k],{k,0,n^2}]
</code>```

Lifted from https://oeis.org/A000328

https://reference.wolfram.com/language/ref/SquaresR.html

SquaresR[2,k] is the number of ways to represent k as the sum of two squares, which is the same as the number of lattice points on a circle of radius k^2. Sum from k=0 to k=n^2 to find all the points on or inside a circle of radius n.

ContentLicense: CC BY-SA 2.5

Body:
Mathematica, 35 characters

f[n_]:=Sum[SquaresR[2,k],{k,0,n^2}]

Lifted from https://oeis.org/A000328

https://reference.wolfram.com/language/ref/SquaresR.html

SquaresR[2,k] is the number of ways to represent k as the sum of two squares, which is the same as the number of lattice points on a circle of radius k^2. Sum from k=0 to k=n^2 to find all the points on or inside a circle of radius n.


问:
Shortest code for infinite disk I/O
(Just open 50 tabs in Google Chrome :D (just kidding, no you can't))

Shortest code for infinite disk I/O any language, C# example:

using System.IO;

namespace FileApp {
    static class Program {
        public static void Main() {
            do {
                File.WriteAllText("a", "a");
                File.Delete("a");
            } while (true);
        }
    }
}
```

You can't just fill the entire disk though, as then it would halt in the end and would be finite.

And you can't do reading only, infinite writing has to happen. (It has to kill my SSD after enough runtime.)

Get cracking! :)

答:
C on amd64 Linux, 36 bytes (timestamp only), <s>52</s> 49 bytes (real disk activity)

I hard-code the open(2) flags, so this is not portable to other ABIs.  Linux on other platforms likely uses the same O_TRUNC, etc., but other POSIX OSes may not.

+4 bytes to pass a correct permission arg to make sure the file is created with owner write access, see below.  (This happens to work with gcc 5.2)

somewhat-portable ANSI C, 38/51 bytes (timestamp only), 52/67 bytes (real disk activity)

Based on @Cat's answer, with a tip from @Jens.

The first number is for implementations where an int can hold FILE *fopen()'s return value, second number if we can't do that.  On Linux, heap addresses happen to be in the low 32 bits of address space, so it works even without -m32 or -mx32.  (Declaring void*fopen(); is shorter than #include <stdio.h>)

Timestamp metadata I/O only:

```<code>main(){for(;;)close(open("a",577));}   // Linux x86-64

//void*fopen();       // compile with -m32 or -mx32 or whatever, so an int holds a pointer.
main(){for(;;)fclose(fopen("a","w"));}
</code>```

Writing a byte, actually hitting the disk on Linux 4.2.0 + XFS + lazytime:

```<code>main(){for(;write(open("a",577),"",1);close(3));}
</code>```

write is the for-loop condition, which is fine since it always returns 1.  close is the increment.

```<code>// semi-portable: storing a FILE* in an int.  Works on many systems
main(f){for(;f=fopen("a","w");fclose(f))fputc(0,f);}                 // 52 bytes

// Should be highly portable, except to systems that require prototypes for all functions.
void*f,*fopen();main(){for(;f=fopen("a","w");fclose(f))fputc(0,f);}   // 67 bytes
</code>```

Explanation of the non-portable version:

The file is created with random garbage permissions.  With gcc 5.2, with -O0 or -O3, it happens to include owner write permission, but this is not guaranteed.  0666 is decimal 438.  A 3rd arg to open would take another 4 bytes.  We're already hard-coding O_TRUNC and so on, but this could break with a different compiler or libc on the same ABI.

We can't omit the 2nd arg to open, because the garbage value happens to include O_EXCL, and O_TRUNC|O_APPEND, so open fails with EINVAL.

We don't need to save the return value from open().  We assume it's 3, because it always will be.  Even if we start with fd 3 open, it will be closed after the first iteration.  Worst-case, open keeps opening new fds until 3 is the last available file descriptor.  So, up to the first 65531 write() calls could fail with EBADF, but will then work normally with every open creating fd = 3.

577 = 0x241 = O_WRONLY|O_CREAT|O_TRUNC on x86-64 Linux.  Without O_TRUNC, the inode mod time and change time aren't updated, so a shorter arg isn't possible.  O_TRUNC is still essential for the version that calls write to produce actual disk activity, not rewrite in place.

I see some answers that open("a",1).  O_CREAT is required if a doesn't already exist.  O_CREAT is defined as octal 0100 (64, 0x40) on Linux.

No resource leaks, so it can run forever.  strace output:

```<code>open("a", O_WRONLY|O_CREAT|O_TRUNC, 03777762713526650) = 3
close(3)                                = 0
... repeating
</code>```

or

```<code>open("a", O_WRONLY|O_CREAT|O_TRUNC, 01) = 3
write(3, "\0", 1)                       = 1   # This is the terminating 0 byte in the empty string we pass to write(2)
close(3)                                = 0
</code>```

I got the decimal value of the open flags for this ABI using strace -eraw=open on my C++ version.

On a filesystem with the Linux lazytime mount option enabled, a change that only affects inode timestamps will only cause one write per 24 hours.  With that mount option disabled, timestamp updating might be a viable way to wear out your SSD.  (However, several other answers only do metadata I/O).

alternatives:

shorter non-working:

main(){for(;;)close(write(open("a",577),"",3));} uses write's return value to pass a 3 arg to close.  It saves another byte, but doesn't work with gcc -O0 or -O3 on amd64.  The garbage in the 3rd arg to open is different, and doesn't include write permission.  a gets created the first time, but future iterations all fail with -EACCESS.

longer, working, with different system calls:

main(c){for(open("a",65);pwrite(3,"",1);)sync();}  rewrites a byte in-place and calls sync() to sync all filesystems system-wide.  This keeps the drive light lit up.

We don't care which byte, so we don't pass 4th arg to pwrite.  Yay for sparse files:

```<code>$ ll -s a
300K -rwx-wx--- 1 peter peter 128T May 15 11:43 a
</code>```

Writing one byte at an offset of ~128TiB led to xfs using 300kiB of space to hold the extent map, I guess.  Don't try this on OS X with HFS+: IIRC, HFS+ doesn't support sparse files, so it will fill the disk.

XFS is a proper 64bit filesystem, supporting individual files up to 8 exabytes.  i.e. 2^63-1, the maximum value off_t can hold.

strace output:

```<code>open("a", O_WRONLY|O_CREAT, 03777711166007270) = 3
pwrite(3, "\0", 1, 139989929353760)     = 1
sync()                                  = 0
pwrite(3, "\0", 1, 139989929380071)     = 1
sync()                                  = 0
...
</code>```

Title: Shortest code for infinite disk I/O

Body:
C on amd64 Linux, 36 bytes (timestamp only), <s>52</s> 49 bytes (real disk activity)

I hard-code the open(2) flags, so this is not portable to other ABIs.  Linux on other platforms likely uses the same O_TRUNC, etc., but other POSIX OSes may not.

+4 bytes to pass a correct permission arg to make sure the file is created with owner write access, see below.  (This happens to work with gcc 5.2)

somewhat-portable ANSI C, 38/51 bytes (timestamp only), 52/67 bytes (real disk activity)

Based on @Cat's answer, with a tip from @Jens.

The first number is for implementations where an int can hold FILE *fopen()'s return value, second number if we can't do that.  On Linux, heap addresses happen to be in the low 32 bits of address space, so it works even without -m32 or -mx32.  (Declaring void*fopen(); is shorter than #include <stdio.h>)

Timestamp metadata I/O only:

main(){for(;;)close(open("a",577));}   // Linux x86-64

//void*fopen();       // compile with -m32 or -mx32 or whatever, so an int holds a pointer.
main(){for(;;)fclose(fopen("a","w"));}

Writing a byte, actually hitting the disk on Linux 4.2.0 + XFS + lazytime:

main(){for(;write(open("a",577),"",1);close(3));}

write is the for-loop condition, which is fine since it always returns 1.  close is the increment.

// semi-portable: storing a FILE* in an int.  Works on many systems
main(f){for(;f=fopen("a","w");fclose(f))fputc(0,f);}                 // 52 bytes

// Should be highly portable, except to systems that require prototypes for all functions.
void*f,*fopen();main(){for(;f=fopen("a","w");fclose(f))fputc(0,f);}   // 67 bytes

Explanation of the non-portable version:

The file is created with random garbage permissions.  With gcc 5.2, with -O0 or -O3, it happens to include owner write permission, but this is not guaranteed.  0666 is decimal 438.  A 3rd arg to open would take another 4 bytes.  We're already hard-coding O_TRUNC and so on, but this could break with a different compiler or libc on the same ABI.

We can't omit the 2nd arg to open, because the garbage value happens to include O_EXCL, and O_TRUNC|O_APPEND, so open fails with EINVAL.

We don't need to save the return value from open().  We assume it's 3, because it always will be.  Even if we start with fd 3 open, it will be closed after the first iteration.  Worst-case, open keeps opening new fds until 3 is the last available file descriptor.  So, up to the first 65531 write() calls could fail with EBADF, but will then work normally with every open creating fd = 3.

577 = 0x241 = O_WRONLY|O_CREAT|O_TRUNC on x86-64 Linux.  Without O_TRUNC, the inode mod time and change time aren't updated, so a shorter arg isn't possible.  O_TRUNC is still essential for the version that calls write to produce actual disk activity, not rewrite in place.

I see some answers that open("a",1).  O_CREAT is required if a doesn't already exist.  O_CREAT is defined as octal 0100 (64, 0x40) on Linux.

No resource leaks, so it can run forever.  strace output:

open("a", O_WRONLY|O_CREAT|O_TRUNC, 03777762713526650) = 3
close(3)                                = 0
... repeating

or

open("a", O_WRONLY|O_CREAT|O_TRUNC, 01) = 3
write(3, "\0", 1)                       = 1   # This is the terminating 0 byte in the empty string we pass to write(2)
close(3)                                = 0

I got the decimal value of the open flags for this ABI using strace -eraw=open on my C++ version.

On a filesystem with the Linux lazytime mount option enabled, a change that only affects inode timestamps will only cause one write per 24 hours.  With that mount option disabled, timestamp updating might be a viable way to wear out your SSD.  (However, several other answers only do metadata I/O).

alternatives:

shorter non-working:

main(){for(;;)close(write(open("a",577),"",3));} uses write's return value to pass a 3 arg to close.  It saves another byte, but doesn't work with gcc -O0 or -O3 on amd64.  The garbage in the 3rd arg to open is different, and doesn't include write permission.  a gets created the first time, but future iterations all fail with -EACCESS.

longer, working, with different system calls:

main(c){for(open("a",65);pwrite(3,"",1);)sync();}  rewrites a byte in-place and calls sync() to sync all filesystems system-wide.  This keeps the drive light lit up.

We don't care which byte, so we don't pass 4th arg to pwrite.  Yay for sparse files:

$ ll -s a
300K -rwx-wx--- 1 peter peter 128T May 15 11:43 a

Writing one byte at an offset of ~128TiB led to xfs using 300kiB of space to hold the extent map, I guess.  Don't try this on OS X with HFS+: IIRC, HFS+ doesn't support sparse files, so it will fill the disk.

XFS is a proper 64bit filesystem, supporting individual files up to 8 exabytes.  i.e. 2^63-1, the maximum value off_t can hold.

strace output:

open("a", O_WRONLY|O_CREAT, 03777711166007270) = 3
pwrite(3, "\0", 1, 139989929353760)     = 1
sync()                                  = 0
pwrite(3, "\0", 1, 139989929380071)     = 1
sync()                                  = 0
...


问:
Shortest infinite loop producing no output
Your task is to create the shortest infinite loop!

The point of this challenge is to create an infinite loop producing no output, unlike its possible duplicate. The reason to this is because the code might be shorter if no output is given.

Rules

Each submission must be a full program.

You must create the shortest infinite loop.

Even if your program runs out of memory eventually, it is still accepted as long as it is running the whole time from the start to when it runs out of memory. Also when it runs out of memory, it should still not print anything to STDERR.

The program must take no input (however, reading from a file is allowed), and should not print anything to STDOUT. Output to a file is also forbidden.

The program must not write anything to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge.
-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. :D

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

This is not about finding the language with the shortest infinite loop program. This is about finding the shortest infinite loop program in every language. Therefore, I will not accept an answer.

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 Brainf**k-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

There should be a website such as Wikipedia, Esolangs, or GitHub for the language. For example, if the language is CJam, then one could link to the site in the header like #[CJam](http://sourceforge.net/p/cjam/wiki/Home/), X bytes.

Standard loopholes are not allowed.

(I have taken some of these rules from Martin Büttner's "Hello World" challenge)

Please feel free to post in the comments to tell me how this challenge could be  improved.

Catalogue

This is a Stack Snippet which generates both an alphabetical catalogue of the used languages, and an overall leaderboard. To make sure your answer shows up, please start it with this Markdown header:

```<code># Language name, X bytes
</code>```

Obviously replacing Language name and X bytes with the proper items. If you want to link to the languages' website, use this template, as posted above:

```<code>#[Language name](http://link.to/the/language), X bytes
</code>```

Now, finally, here's the snippet: (Try pressing "Full page" for a better view.)

var QUESTION_ID=59347;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=41805;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"//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"//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,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.toLowerCase()>b.lang_raw.toLowerCase())return 1;if(a.lang_raw.toLowerCase()<b.lang_raw.toLowerCase())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:500px;float:left}#language-list{padding:10px;padding-right:40px;width:500px;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

```

答:
Seed, 3 bytes

0 0

Equivalent to an empty Befunge program.


问:
Calculate the Trump Tax
If elected president, Donald Trump plans to implement a system of four income tax brackets (full details can be found on his website here). Your job is to take two inputs, annual income and filing status (single, married, or head of household), and output the income tax that must be paid.

Income Tax Brackets

(We are only interested in the income tax rate; you can ignore the long-term capital gain rate).

Note that income taxes are computed using marginal rates — that is, you only pay the bracket rate for the portion that exceeds the bracket's minimum amount.

For example, a single filer making $45,000 a year would pay 0% on the first $25,000, and 10% on the $20,000 after that, for a total of $2,000 in taxes.

A married couple filing jointly for $500,000 would count 25% only on the amount exceeding $300,000, and add $45,000 to that to account for the income earned in lower brackets (which is 10% of $50,000 plus 20% of $200,000).

Input/Output

Input/Output is flexible. You can take input as command-line arguments or prompt for inputs, as well as either return or output/display the result. The inputs and output must be numbers, but you are free to determine what the second number would be (for example, 0 = single, 1 = married, 2 = head of household). Just don't be ridiculous - Single digit numbers only.

Also, functionality for decimal inputs (i.e. including cents) is undefined, so you only have to worry about integer inputs. For your output, you may either output a decimal value or round it to the nearest whole number.

Test Cases

Although the second number's range can be flexible as stated above, these test cases assume that 0 = single, 1 = married, and 2 = head of household:

```<code>25000  0 --> 0
37501  2 --> 0.1 or 0
51346  1 --> 134.6 or 135
75000  0 --> 7500
75000  1 --> 2500
123456 2 --> 13441.2 or 13441
424242 0 --> 91060.5 or 91061
</code>```

Title: Calculate the Trump Tax

Body:
JavaScript (ES6), 52 bytes

(i,m,g=b=>i>b&&(i-=b)/10)=>g(m=15e4/m)+g(m)+g(m*4)/2

Key:

6 = Single
3 = Married
4 = Head


问:
Continuously expanding code
Your job is to write a program that rewrites and makes itself longer on each run of the program.

Challenge

The program will print Hello, World!\n (\n denotes a newline). Then, it will modify its own file so that the new program length is exactly 2x the length at runtime. This modified file when run, will print Hello, World!\nHello, World!\n. When run a third time, the file will print Hello, World!\nHello, World!\nHello, World!\nHello, World!\n.

More simply, on the nth run of the program, it will output 2^(n-1) instances of Hello, World!\n, and have a program length of 2^(n-1) the length of the original.

This is code-golf, so shortest code (before first run) wins. Please comment if you need something is not clear.

Edit: To get past the restriction of file-rewriting, your program may print the modified source along with the Hello, World!\ns at a +40% penalty.

答:
PHP, 100

More efficient, 101

```<code><?$a=$argv[0];$b=file_get_contents($a);file_put_contents($a,$b.substr($b,81,20));echo"Hello World\n";
</code>```

This script is appending an echo"Hello World";, but because you said the size should also vary, and because it's shorter, I'm also having this script:

Shorter, 100

```<code><?$a=$argv[0];$b=file_get_contents($a);file_put_contents($a,$b.substr($b,2,98));echo"Hello World\n";
</code>```

This script is appending itself, in a way it adds one Hello World, but this version will overall take more space and takes longer to execute.

Example

But the scripts don't vary when it comes to the output:

```<code>root@raspberrypi:~/stack# php hello_expand.php
Hello World
root@raspberrypi:~/stack# php hello_expand.php
Hello World
Hello World
root@raspberrypi:~/stack# php hello_expand.php
Hello World
Hello World
Hello World
</code>```

Title: Continuously expanding code

Body:
PHP, 100

More efficient, 101

<?$a=$argv[0];$b=file_get_contents($a);file_put_contents($a,$b.substr($b,81,20));echo"Hello World\n";

This script is appending an echo"Hello World";, but because you said the size should also vary, and because it's shorter, I'm also having this script:

Shorter, 100

<?$a=$argv[0];$b=file_get_contents($a);file_put_contents($a,$b.substr($b,2,98));echo"Hello World\n";

This script is appending itself, in a way it adds one Hello World, but this version will overall take more space and takes longer to execute.

Example

But the scripts don't vary when it comes to the output:

root@raspberrypi:~/stack# php hello_expand.php
Hello World
root@raspberrypi:~/stack# php hello_expand.php
Hello World
Hello World
root@raspberrypi:~/stack# php hello_expand.php
Hello World
Hello World
Hello World


问:
Zeroes at the end of a factorial
Write a program or function that finds the number of zeroes at the end of n! in base 10, where n is an input number (in any desired format).

It can be assumed that n is a positive integer, meaning that n! is also an integer. There are no zeroes after a decimal point in n!. Also, it can be assumed that your programming language can handle the value of n and n!.

Test cases

```<code>1
==> 0

5
==> 1

100
==> 24

666
==> 165

2016
==> 502

1234567891011121314151617181920
==> 308641972752780328537904295461
</code>```

This is code golf. Standard rules apply. The shortest code in bytes wins.

答:
Ruby, <s>70</s> <s>61</s> <s>51</s> 49 bytes

Version 3 with thanks to Kenny Lau and daniero

->n{(n-n.to_s(5).chars.map(&:to_i).reduce(:+))/4}
```

<p><strong>Edit:</strong> Turns out you can save two bytes by mapping <code>to_i</code> <em>before</em> you <code>reduce</code>. Weird :P</p>

<p>This function subtracts the sum of <code>n</code>'s base 5 digits from <code>n</code> and then divides that result by 4. This is related to the sum of the geometric series <code>1+5+25+..+5**n = (5**n+1)/4</code>.</p>

<p>As an example (again, with thanks to Kenny Lau), consider <code>358</code> (<code>2413</code> in base 5) minus its base 5 digits.</p>

<pre class="lang-ruby prettyprint-override"><code>2413-2-4-1-3
= (2000-2) + (400-4) + (10-1) + (3-3)
# consider that 1000-1=444 and you'll see why every 5**n is multiplied by 4
= 2*444 + 4*44 + 1*4 + 3*0
= 2*(4*5**0+4*5**1+4*5**2) + 4*(4*5**0+4*5**1) + 1*(4*5**0) + 3*()
= 348
</code>```

Divide 348 by 4 and you get f(358) = 87.

Version 2 with thanks to Kenny Lau

->n{s=(1..n).reduce(:*).to_s;s.size-s.reverse.to_i.to_s.size}
```

<p>This function calculates <code>n!</code> then subtracts the <code>size</code> of <code>n!</code> from the <code>size</code> of <code>(n!).reverse.to_i.to_s</code>, which removes all the zeroes, thus, returning the <code>size</code> of the zeroes themselves.</p>

<p><strong>Version 1</strong></p>

<pre class="lang-ruby prettyprint-override"><code>->n{s=n.to_s(5).chars;(0...s.size).reduce{|a,b|a+(s[0,b]*'').to_i(5)}}
</code>```

This a variation of the "How many 5s are there in the prime factorization of n!?" trick that uses Ruby's simple base conversion builtins.

The golfing is a bit of a pain though, with converting from Integer to String to Array, grabbing part of the Array and converting that to String to Integer again for the reduce. Any golfing suggestions are welcome.

Title: Zeroes at the end of a factorial

Body:
Ruby, <s>70</s> <s>61</s> <s>51</s> 49 bytes

Version 3 with thanks to Kenny Lau and daniero

->n{(n-n.to_s(5).chars.map(&:to_i).reduce(:+))/4}

Edit: Turns out you can save two bytes by mapping to_i before you reduce. Weird :P

This function subtracts the sum of n's base 5 digits from n and then divides that result by 4. This is related to the sum of the geometric series 1+5+25+..+5**n = (5**n+1)/4.

As an example (again, with thanks to Kenny Lau), consider 358 (2413 in base 5) minus its base 5 digits.

2413-2-4-1-3
= (2000-2) + (400-4) + (10-1) + (3-3)
# consider that 1000-1=444 and you'll see why every 5**n is multiplied by 4
= 2*444 + 4*44 + 1*4 + 3*0
= 2*(4*5**0+4*5**1+4*5**2) + 4*(4*5**0+4*5**1) + 1*(4*5**0) + 3*()
= 348

Divide 348 by 4 and you get f(358) = 87.

Version 2 with thanks to Kenny Lau

->n{s=(1..n).reduce(:*).to_s;s.size-s.reverse.to_i.to_s.size}

This function calculates n! then subtracts the size of n! from the size of (n!).reverse.to_i.to_s, which removes all the zeroes, thus, returning the size of the zeroes themselves.

Version 1

->n{s=n.to_s(5).chars;(0...s.size).reduce{|a,b|a+(s[0,b]*'').to_i(5)}}

This a variation of the "How many 5s are there in the prime factorization of n!?" trick that uses Ruby's simple base conversion builtins.

The golfing is a bit of a pain though, with converting from Integer to String to Array, grabbing part of the Array and converting that to String to Integer again for the reduce. Any golfing suggestions are welcome.


答:
Java, 38 bytes

int z(int n){return n>0?n/5+z(n/5):0;}
```

<h2>Full program, with ungolfed method:</h2>

<pre class="lang-java prettyprint-override"><code>import java.util.Scanner;

public class Q79762{
    int zero_ungolfed(int number){
        if(number == 0){
            return 0;
        }
        return number/5 + zero_ungolfed(number/5);
    }
    int z(int n){return n>0?n/5+z(n/5):0;}
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        System.out.println(new Q79762().zero_ungolfed(n));
        System.out.println(new Q79762().z(n));
    }
}
</code>```

Title: Zeroes at the end of a factorial

Body:
Write a program or function that finds the number of zeroes at the end of n! in base 10, where n is an input number (in any desired format).

It can be assumed that n is a positive integer, meaning that n! is also an integer. There are no zeroes after a decimal point in n!. Also, it can be assumed that your programming language can handle the value of n and n!.

Test cases

```<code>1
==> 0

5
==> 1

100
==> 24

666
==> 165

2016
==> 502

1234567891011121314151617181920
==> 308641972752780328537904295461
</code>```

This is code golf. Standard rules apply. The shortest code in bytes wins.

Body:
Java, 38 bytes

int z(int n){return n>0?n/5+z(n/5):0;}

Full program, with ungolfed method:

import java.util.Scanner;

public class Q79762{
    int zero_ungolfed(int number){
        if(number == 0){
            return 0;
        }
        return number/5 + zero_ungolfed(number/5);
    }
    int z(int n){return n>0?n/5+z(n/5):0;}
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        System.out.println(new Q79762().zero_ungolfed(n));
        System.out.println(new Q79762().z(n));
    }
}


问:
Write the shortest self-identifying program (a quine variant)
Write a program that will generate a "true" output iff the input matches the source code of the program, and which generates a "false" output iff the input does not match the source code of the program.

This problem can be described as being related to quines, as the program must be able to somehow compute its own source code in the process.

This is code golf: standard rules apply.  Your program must not access any special files, such as the file of its own source code.

Edit: If you so choose, true/false can be replaced with True/False or 1/0.

Example

If the source code of your program is bhiofvewoibh46948732));:/)4, then here is what your program must do:

Input (Stdin)

```<code>bhiofvewoibh46948732));:/)4
</code>```

Output (Stdout)

```<code>true
</code>```

Input

```<code>(Anything other than your source code)
</code>```

Output

```<code>false
</code>```

答:
Python 2, 47 bytes

```<code>_='_=%r;print _%%_==input()';print _%_==input()
</code>```

A simple quine with the added check.

Body:
Python 2, 47 bytes

_='_=%r;print _%%_==input()';print _%_==input()

A simple quine with the added check.


问:
Shortest code for longest output
This one is pretty simple.

Write the shortest program you can, while generating the most output.

To make it fun, programs that produce infinite output will be disqualified.

The winner is the program with the largest output size/code size ratio.

The results are based on what works on my computer, which is a Mac running Mac OS X 10.7.5 with an Intel Core i5 and 8GB of memory.

答:
Python 3, 115 bytes, runs for 7983 years (unknown # of chars)

EDIT: ymbirtt beat me to it ._.

I know, this isn't really short, and I know that the other Python answer is much longer, But I decided to give this a shot.

The program runs for about 8000 years, which, as you know, is a pretty long time.

What it does is continuously get the current time using the datetime.datetime.now() function, and it compares it to 9999-12-31 24:59:59.999999, which is as far as I know the maximum date in Python.

If is is equal, the program stops. If it isn't, it continously outputs a.

```<code>import datetime
while 1:
    if str(datetime.datetime.now())=="9999-12-31 24:59:59.999999":exit
    else:print("a")
</code>```

Title: Shortest code for longest output

Body:
Python 3, 115 bytes, runs for 7983 years (unknown # of chars)

EDIT: ymbirtt beat me to it ._.

I know, this isn't really short, and I know that the other Python answer is much longer, But I decided to give this a shot.

The program runs for about 8000 years, which, as you know, is a pretty long time.

What it does is continuously get the current time using the datetime.datetime.now() function, and it compares it to 9999-12-31 24:59:59.999999, which is as far as I know the maximum date in Python.

If is is equal, the program stops. If it isn't, it continously outputs a.

import datetime
while 1:
    if str(datetime.datetime.now())=="9999-12-31 24:59:59.999999":exit
    else:print("a")


问:
Virtual Keyboard Text Input
On modern game consoles and other devices without traditional keyboards, trying to input text is a nightmare. Having to type with a few buttons and a joystick on a virtual keyboard is annoying, and I like to make as few movements/button presses as possible.

The keyboard you will be using looks like this:

```<code>+---+---+---+---+---+---+---+---+---+---+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 |
+---+---+---+---+---+---+---+---+---+---+
| q | w | e | r | t | y | u | i | o | p |
+---+---+---+---+---+---+---+---+---+---+
| a | s | d | f | g | h | j | k | l | - |
+---+---+---+---+---+---+---+---+---+---+
| z | x | c | v | b | n | m | _ | @ | . |
+---+---+---+---+---+---+---+---+---+---+
</code>```

The following operations can be used:

L: move one square to the left on the keyboard (wraps)

R: move one square to the right on the keyboard (wraps)

U: move one square up on the keyboard (wraps)

D: move one square down on the keyboard (wraps)

Y: insert a space

B: move the insertion pointer one space to the left (does nothing if pointer is at the beginning)

F: move the insertion pointer one space to the right (does nothing if pointer is at the end)

C: toggle caps lock

A: insert the selected character at the position of the insertion pointer

Given an input string containing only ASCII characters that can be typed using the above keyboard and commands (matches [a-zA-Z0-9 _@.-]*), output a sequence of commands that will result in the output string. The initial position of the cursor is on the 1 key (the top-left), and caps lock is initially off.

Scoring

For any given string, a naive approach would be, for each character in the string, navigate to the character on the keyboard by the shortest path, toggle caps lock if necessary, and select the character. Such a naive approach would generate a command of length (length of input string) + (sum of Manhattan distances on keyboard between consecutive non-space characters) + (number of times the string alternates between lowercase and uppercase characters) + (1 if string starts with an uppercase letter else 0). For example, the naive approach for 101 would result in ALARA, a length 5 command, and Noob 5 would result in DDDRRRRRCAUURRRCAADDLLLLAYUUUA, a length 30 command.

Your submission, however, seeks to do better than the naive approach. For each input string, your submission will receive points equal to the number of commands the naive approach uses minus the number of commands your submission outputs. Your overall score will be the sum of the individual scores.

Rules

Submissions will be run on a Cloud9 free virtual workspace. The workspace has 512 MB of RAM, 2 GB of disk space, 8 Intel(R) Xeon(R) CPUs @ 2.50 GHz (full CPU info, found by running cat /proc/cpuinfo, can be found here), and is running 64-bit Ubuntu 14.04 Trusty. You may request access to the testing workspace in order to run and score your submission, or I can score it for you.

Submissions will be run once per test case. Storing state between runs is forbidden. Submissions may not write to or read from any files other than the source file (which may not be modified between runs), with the possible exception of reading an input file if required.

Submissions are limited to 1 minute of runtime for each test case. Submissions may output multiple solutions, but only the last valid solution within the allotted time will be used for scoring. Failure to output any valid solutions within the allotted time will result in a score of 0 for that test case.

Please include directions on how to invoke your submission, as well as any tools/libraries that need to be installed that aren't included with a standard Ubuntu 14.04 install.

The winner will be the submission with the largest score. In the event of a tie, the submission with the better algorithmic complexity will win. If the tie is still not resolved, the first submission to reach the score and algorithmic complexity will win.

Submissions may not optimize for the test cases. I reserve the right to change the test cases if I feel there is a need.

Test cases

Format: input string => naive score

(if you see any errors in these, please leave a comment with the correction)

```<code>101 => 5
quip => 12
PPCG => 15
Mego => 25
Noob 5 => 26
penguin => 27
867-5309 => 32
2_sPoOkY_4_mE => 60
The Nineteenth Byte => 76
penguins@SouthPole.org => 95
8xM3R__5ltZgrkJ.-W b => 98
correcthorsebatterystaple => 104
verylongRUNSOFCAPSandnocaps => 118
This is an English sentence. => 122
WNtza.akjzSP2GI0V9X .0epmUQ-mo => 131
Programming Puzzles and Code Golf => 140
</code>```

答:
C

The score is 193.

```<code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define LEFT 'L'
#define RIGHT 'R'
#define CAPS 'C'
#define UP 'U'
#define DOWN 'D'
#define SPACE 'Y'
#define CURSORLEFT 'B'
#define CURSORRIGHT 'F'
#define APPLY 'A'
#define TABLEX 10
#define TABLEY 4
#define casediff(A,B) (isupper(A)*islower(B)+islower(A)*isupper(B))
typedef struct {int x; int y;} coord;
coord letters[300];
#define initLetter(letter, X, Y) \
letters[letter].x=X, letters[letter].y=Y
#define initAllLetters(); \
initLetter('1',0,0);\
initLetter('1',0,0);\
initLetter('2',1,0);\
initLetter('2',1,0);\
initLetter('3',2,0);\
initLetter('3',2,0);\
initLetter('4',3,0);\
initLetter('4',3,0);\
initLetter('5',4,0);\
initLetter('5',4,0);\
initLetter('6',5,0);\
initLetter('6',5,0);\
initLetter('7',6,0);\
initLetter('7',6,0);\
initLetter('8',7,0);\
initLetter('8',7,0);\
initLetter('9',8,0);\
initLetter('9',8,0);\
initLetter('0',9,0);\
initLetter('0',9,0);\
initLetter('Q',0,1);\
initLetter('q',0,1);\
initLetter('W',1,1);\
initLetter('w',1,1);\
initLetter('E',2,1);\
initLetter('e',2,1);\
initLetter('R',3,1);\
initLetter('r',3,1);\
initLetter('T',4,1);\
initLetter('t',4,1);\
initLetter('Y',5,1);\
initLetter('y',5,1);\
initLetter('U',6,1);\
initLetter('u',6,1);\
initLetter('I',7,1);\
initLetter('i',7,1);\
initLetter('O',8,1);\
initLetter('o',8,1);\
initLetter('P',9,1);\
initLetter('p',9,1);\
initLetter('A',0,2);\
initLetter('a',0,2);\
initLetter('S',1,2);\
initLetter('s',1,2);\
initLetter('D',2,2);\
initLetter('d',2,2);\
initLetter('F',3,2);\
initLetter('f',3,2);\
initLetter('G',4,2);\
initLetter('g',4,2);\
initLetter('H',5,2);\
initLetter('h',5,2);\
initLetter('J',6,2);\
initLetter('j',6,2);\
initLetter('K',7,2);\
initLetter('k',7,2);\
initLetter('L',8,2);\
initLetter('l',8,2);\
initLetter('-',9,2);\
initLetter('-',9,2);\
initLetter('Z',0,3);\
initLetter('z',0,3);\
initLetter('X',1,3);\
initLetter('x',1,3);\
initLetter('C',2,3);\
initLetter('c',2,3);\
initLetter('V',3,3);\
initLetter('v',3,3);\
initLetter('B',4,3);\
initLetter('b',4,3);\
initLetter('N',5,3);\
initLetter('n',5,3);\
initLetter('M',6,3);\
initLetter('m',6,3);\
initLetter('_',7,3);\
initLetter('_',7,3);\
initLetter('@',8,3);\
initLetter('@',8,3);\
initLetter('.',9,3);\
initLetter('.',9,3);
typedef struct {int length; char instr[300];} movement;
movecasefold(char*instr,coord A, coord B){
    register int i=0;int j;
    if(A.x<B.x)
     if(B.x-A.x<=TABLEX/2)
      for(;B.x-A.x!=i;)instr[i++]=RIGHT;
     else
      for(;TABLEX-B.x+A.x!=i;)instr[i++]=LEFT;
    else if(A.x>B.x)
     if(A.x-B.x<=TABLEX/2)
      for(;A.x-B.x!=i;)instr[i++]=LEFT;
     else
      for(;TABLEX-A.x+B.x!=i;)instr[i++]=RIGHT;
    j=i;
    if(A.y<B.y)
     if(B.y-A.y<=TABLEY/2)
      for(;B.y-A.y!=i-j;)instr[i++]=DOWN;
     else
      for(;TABLEY-B.y+A.y!=i-j;)instr[i++]=UP;
    else if(A.y>B.y)
     if(A.y-B.y<=TABLEY/2)
      for(;A.y-B.y!=i-j;)instr[i++]=UP;
     else
      for(;TABLEY-A.y+B.y!=i-j;)instr[i++]=DOWN;
    instr[i]='\0';
    return i;
}
char sentence[50], oldcase, oldletter;
int sentencelength;
typedef struct {
int sentencetoorder[50];
int ordertosentence[50];
int length;
} order;
ordercopy(order*a, order b){
register int i;
for(i=0;++i<sentencelength;) a->sentencetoorder[i]=b.sentencetoorder[i], a->ordertosentence[i]=b.ordertosentence[i];
a->length=b.length;
}
order currentOrder;
movetwo(char*instr,int A, int B){
    register int j; int i=0;
    if(A<B)
    { for(j=A+1;j<B;j++)
      if(currentOrder.sentencetoorder[j]<currentOrder.sentencetoorder[B])
       instr[i++]=CURSORRIGHT;
    }
    else
    { for(j=A;j>B;j--)
      if(currentOrder.sentencetoorder[j]<currentOrder.sentencetoorder[B])
       instr[i++]=CURSORLEFT;
    }
    if(sentence[B]==' '){
        instr[i++]=SPACE;
        instr[i]='\0';
        return i;
    }
    i+=movecasefold(instr+i,letters[oldletter],letters[sentence[B]]);
    oldletter=sentence[B];
    if(casediff(oldcase,sentence[B]))oldcase=sentence[B],instr[i++]=CAPS;
    instr[i++]=APPLY;
    instr[i]='\0';
    return i;
}
moveall(char*instr){
    int j;int i = 0;
    oldcase='a';
    oldletter='1';
    for(j=0;++j<sentencelength;)
        i+=movetwo(instr+i,currentOrder.ordertosentence[j-1],currentOrder.ordertosentence[j]);
    return i;
}
iteration();
main(){
initAllLetters();
gets(sentence+1);*sentence='1';sentencelength=strlen(sentence);
int i;
for(i=0;++i<sentencelength;)currentOrder.sentencetoorder[i]=currentOrder.ordertosentence[i]=i;
char instr[300];
currentOrder.length=moveall(instr);
puts(instr);
while(iteration());
}
#define inside(item, start, stop) (((start)<=(item))&((item)<(stop)))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
iteration(){
char instr[300];
register int i;
int newstart, start, l;
static order oldorder, neworder;
ordercopy(&oldorder,currentOrder);
ordercopy(&neworder,currentOrder);
for(l=0;++l<sentencelength-1;)
for(start=0;++start<sentencelength-l;)
for(newstart=0;++newstart<sentencelength-l;)
if(start!=newstart){
 for(i=0;++i<sentencelength;)
  if(inside(i,start,start+l))currentOrder.ordertosentence[i-start+newstart]=oldorder.ordertosentence[i];
  else if(inside(i,min(start,newstart),max(start+l,newstart+l)))currentOrder.ordertosentence[newstart<start?i+l:(i-l)]=oldorder.ordertosentence[i];
  else currentOrder.ordertosentence[i]=oldorder.ordertosentence[i];
 for(i=0;++i<sentencelength;) currentOrder.sentencetoorder[currentOrder.ordertosentence[i]]=i;
  currentOrder.length=moveall(instr);
 if(currentOrder.length<neworder.length){
  puts(instr);
  ordercopy(&neworder, currentOrder);
 }
}
ordercopy(&currentOrder, neworder);
return neworder.length<oldorder.length;
}
</code>```

Compile with as "gcc virtualKeyboard.c".
Run it without arguments "./a.out". It reads the input from stdin and writes the output to stdout.

Title: Virtual Keyboard Text Input

Body:
C

The score is 193.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define LEFT 'L'
#define RIGHT 'R'
#define CAPS 'C'
#define UP 'U'
#define DOWN 'D'
#define SPACE 'Y'
#define CURSORLEFT 'B'
#define CURSORRIGHT 'F'
#define APPLY 'A'
#define TABLEX 10
#define TABLEY 4
#define casediff(A,B) (isupper(A)*islower(B)+islower(A)*isupper(B))
typedef struct {int x; int y;} coord;
coord letters[300];
#define initLetter(letter, X, Y) \
letters[letter].x=X, letters[letter].y=Y
#define initAllLetters(); \
initLetter('1',0,0);\
initLetter('1',0,0);\
initLetter('2',1,0);\
initLetter('2',1,0);\
initLetter('3',2,0);\
initLetter('3',2,0);\
initLetter('4',3,0);\
initLetter('4',3,0);\
initLetter('5',4,0);\
initLetter('5',4,0);\
initLetter('6',5,0);\
initLetter('6',5,0);\
initLetter('7',6,0);\
initLetter('7',6,0);\
initLetter('8',7,0);\
initLetter('8',7,0);\
initLetter('9',8,0);\
initLetter('9',8,0);\
initLetter('0',9,0);\
initLetter('0',9,0);\
initLetter('Q',0,1);\
initLetter('q',0,1);\
initLetter('W',1,1);\
initLetter('w',1,1);\
initLetter('E',2,1);\
initLetter('e',2,1);\
initLetter('R',3,1);\
initLetter('r',3,1);\
initLetter('T',4,1);\
initLetter('t',4,1);\
initLetter('Y',5,1);\
initLetter('y',5,1);\
initLetter('U',6,1);\
initLetter('u',6,1);\
initLetter('I',7,1);\
initLetter('i',7,1);\
initLetter('O',8,1);\
initLetter('o',8,1);\
initLetter('P',9,1);\
initLetter('p',9,1);\
initLetter('A',0,2);\
initLetter('a',0,2);\
initLetter('S',1,2);\
initLetter('s',1,2);\
initLetter('D',2,2);\
initLetter('d',2,2);\
initLetter('F',3,2);\
initLetter('f',3,2);\
initLetter('G',4,2);\
initLetter('g',4,2);\
initLetter('H',5,2);\
initLetter('h',5,2);\
initLetter('J',6,2);\
initLetter('j',6,2);\
initLetter('K',7,2);\
initLetter('k',7,2);\
initLetter('L',8,2);\
initLetter('l',8,2);\
initLetter('-',9,2);\
initLetter('-',9,2);\
initLetter('Z',0,3);\
initLetter('z',0,3);\
initLetter('X',1,3);\
initLetter('x',1,3);\
initLetter('C',2,3);\
initLetter('c',2,3);\
initLetter('V',3,3);\
initLetter('v',3,3);\
initLetter('B',4,3);\
initLetter('b',4,3);\
initLetter('N',5,3);\
initLetter('n',5,3);\
initLetter('M',6,3);\
initLetter('m',6,3);\
initLetter('_',7,3);\
initLetter('_',7,3);\
initLetter('@',8,3);\
initLetter('@',8,3);\
initLetter('.',9,3);\
initLetter('.',9,3);
typedef struct {int length; char instr[300];} movement;
movecasefold(char*instr,coord A, coord B){
    register int i=0;int j;
    if(A.x<B.x)
     if(B.x-A.x<=TABLEX/2)
      for(;B.x-A.x!=i;)instr[i++]=RIGHT;
     else
      for(;TABLEX-B.x+A.x!=i;)instr[i++]=LEFT;
    else if(A.x>B.x)
     if(A.x-B.x<=TABLEX/2)
      for(;A.x-B.x!=i;)instr[i++]=LEFT;
     else
      for(;TABLEX-A.x+B.x!=i;)instr[i++]=RIGHT;
    j=i;
    if(A.y<B.y)
     if(B.y-A.y<=TABLEY/2)
      for(;B.y-A.y!=i-j;)instr[i++]=DOWN;
     else
      for(;TABLEY-B.y+A.y!=i-j;)instr[i++]=UP;
    else if(A.y>B.y)
     if(A.y-B.y<=TABLEY/2)
      for(;A.y-B.y!=i-j;)instr[i++]=UP;
     else
      for(;TABLEY-A.y+B.y!=i-j;)instr[i++]=DOWN;
    instr[i]='\0';
    return i;
}
char sentence[50], oldcase, oldletter;
int sentencelength;
typedef struct {
int sentencetoorder[50];
int ordertosentence[50];
int length;
} order;
ordercopy(order*a, order b){
register int i;
for(i=0;++i<sentencelength;) a->sentencetoorder[i]=b.sentencetoorder[i], a->ordertosentence[i]=b.ordertosentence[i];
a->length=b.length;
}
order currentOrder;
movetwo(char*instr,int A, int B){
    register int j; int i=0;
    if(A<B)
    { for(j=A+1;j<B;j++)
      if(currentOrder.sentencetoorder[j]<currentOrder.sentencetoorder[B])
       instr[i++]=CURSORRIGHT;
    }
    else
    { for(j=A;j>B;j--)
      if(currentOrder.sentencetoorder[j]<currentOrder.sentencetoorder[B])
       instr[i++]=CURSORLEFT;
    }
    if(sentence[B]==' '){
        instr[i++]=SPACE;
        instr[i]='\0';
        return i;
    }
    i+=movecasefold(instr+i,letters[oldletter],letters[sentence[B]]);
    oldletter=sentence[B];
    if(casediff(oldcase,sentence[B]))oldcase=sentence[B],instr[i++]=CAPS;
    instr[i++]=APPLY;
    instr[i]='\0';
    return i;
}
moveall(char*instr){
    int j;int i = 0;
    oldcase='a';
    oldletter='1';
    for(j=0;++j<sentencelength;)
        i+=movetwo(instr+i,currentOrder.ordertosentence[j-1],currentOrder.ordertosentence[j]);
    return i;
}
iteration();
main(){
initAllLetters();
gets(sentence+1);*sentence='1';sentencelength=strlen(sentence);
int i;
for(i=0;++i<sentencelength;)currentOrder.sentencetoorder[i]=currentOrder.ordertosentence[i]=i;
char instr[300];
currentOrder.length=moveall(instr);
puts(instr);
while(iteration());
}
#define inside(item, start, stop) (((start)<=(item))&((item)<(stop)))
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
iteration(){
char instr[300];
register int i;
int newstart, start, l;
static order oldorder, neworder;
ordercopy(&oldorder,currentOrder);
ordercopy(&neworder,currentOrder);
for(l=0;++l<sentencelength-1;)
for(start=0;++start<sentencelength-l;)
for(newstart=0;++newstart<sentencelength-l;)
if(start!=newstart){
 for(i=0;++i<sentencelength;)
  if(inside(i,start,start+l))currentOrder.ordertosentence[i-start+newstart]=oldorder.ordertosentence[i];
  else if(inside(i,min(start,newstart),max(start+l,newstart+l)))currentOrder.ordertosentence[newstart<start?i+l:(i-l)]=oldorder.ordertosentence[i];
  else currentOrder.ordertosentence[i]=oldorder.ordertosentence[i];
 for(i=0;++i<sentencelength;) currentOrder.sentencetoorder[currentOrder.ordertosentence[i]]=i;
  currentOrder.length=moveall(instr);
 if(currentOrder.length<neworder.length){
  puts(instr);
  ordercopy(&neworder, currentOrder);
 }
}
ordercopy(&currentOrder, neworder);
return neworder.length<oldorder.length;
}

Compile with as "gcc virtualKeyboard.c".
Run it without arguments "./a.out". It reads the input from stdin and writes the output to stdout.


答:
Retina, 33 bytes

Takes input in unary.

Returns output in unary.

```
+`^(?=1)(1{5})*1*
$#1$*1;$#1$*
;

```

(Note the trailing linefeed.)

Try it online!

How it works:

The first stage:

```<code>+`^(?=1)(1{5})*1*
$#1$*1;$#1$*
</code>```

Slightly ungolfed:

```<code>+`^(?=1)(11111)*1*\b
$#1$*1;$#1$*1
</code>```

What it does:

Firstly, find the greatest number of 11111 that can be matched.

Replace by that number

Effectively floor-divides by 5.

The lookahead (?=1) assures that the number is positive.

The +` means repeat until idempotent.

So, the first stage is "repeated floor-division by 5"

If the input is 100 (in unary), then the text is now:

```<code>;;1111;11111111111111111111
</code>```

Second stage:

```
;

```

Just removes all semi-colons.

Title: Zeroes at the end of a factorial

Body:
Retina, 33 bytes

Takes input in unary.

Returns output in unary.

+`^(?=1)(1{5})*1*
$#1$*1;$#1$*
;

(Note the trailing linefeed.)

Try it online!

How it works:

The first stage:

+`^(?=1)(1{5})*1*
$#1$*1;$#1$*

Slightly ungolfed:

+`^(?=1)(11111)*1*\b
$#1$*1;$#1$*1

What it does:

Firstly, find the greatest number of 11111 that can be matched.

Replace by that number

Effectively floor-divides by 5.

The lookahead (?=1) assures that the number is positive.

The +` means repeat until idempotent.

So, the first stage is "repeated floor-division by 5"

If the input is 100 (in unary), then the text is now:

;;1111;11111111111111111111

Second stage:

;

Just removes all semi-colons.


问:
What is the most frequent word?

What is the most frequent word?

Given a sentence, your program must make its way through it, counting the frequencies of each word, then output the most used word. Because a sentence has no fixed length, and so can get very long, your code must be as short as possible.

Rules/Requirements

Each submission should be either a full program or function. If it is a function, it must be runnable by only needing to add the function call to the bottom of the program. Anything else (e.g. headers in C), must be included.

There must be a free interpreter/compiler available for your language.

If it is possible, provide a link to a site where your program can be tested.

Your program must not write anything to STDERR.

Your program should take input from STDIN (or the closest alternative in your language).

Standard loopholes are forbidden.

Your program must be case-insensitive (tHe, The and the all contribute to the count of the).

If there is no most frequent word (see test case #3), your program should output nothing.

Definition of a 'word':

You get the list of words by splitting the input text on spaces. The input will never contain any other type of whitespace than plain spaces (in particular no newlines). However, the final words should only contain alphanumerics (a-z, A-Z, 0-9), hyphens (-) and apostrophes ('). You can make that so by removing all other characters or by replacing them by space before doing the word splitting. To remain compatible with previous versions of the rules, apostrophes are not required to be included.

Test Cases

```<code>The man walked down the road.
==> the

-----

Slowly, he ate the pie, savoring each delicious bite. He felt like he was truly happy.
==> he

-----

This sentence has no most frequent word.
==>

-----

"That's... that's... that is just terrible!" he said.
==> that's / thats

-----

The old-fashioned man ate an old-fashioned cake.
==> old-fashioned

-----

IPv6 looks great, much better than IPv4, except for the fact that IPv6 has longer addresses.
==> IPv6

-----

This sentence with words has at most two equal most frequent words.
==>
</code>```

Note: The third and seventh test cases have no output, you may choose either on the fourth.

Scoring

Programs are scored according to bytes. The usual character set is UTF-8, if you are using another please specify.

When the challenge finishes, the program with the least bytes (it's called code-golf), will win.

Submissions

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

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

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

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

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

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

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

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

Leaderboard

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

/* Configuration */

var QUESTION_ID = 79576; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 53406; // This should be the user ID of the challenge author.

/* App */

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,]*[^\s,]),.*?(\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,
      });

  });

  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;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) 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: bold;
}

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

```

答:
Tcl 8.6, 196 bytes

```<code>lmap s [join [read stdin] \ ] {dict incr d [regsub -all {[^\w-]} [string tol $s] {}]}
set y [dict fi $d v [lindex [lsort [dict v $d]] end]]
if {[llength $y]!=2} {set y {}}
puts "==> [lindex $y 0]"
</code>```

(Alas, I can't figure out how to get it any smaller than that...)

Explanation

It uses several obscure Tcl idioms to do stuff.

[join [read stdin] " "]
— input string→list of whitespace-separated words

lmap ...
— iterate over every element of that list. (Shorter than foreach and effectually identical since the result is discarded.)

[regsub ... [string tolower ...]]
— Convert the string to lowercase and strip all characters except for word characters and the hyphen.

[dict incr d ...]
— Create/modify a dictionary/word→count histogram.

set y ...
— Sort the dictionary values, take the largest one, and return all (key,value) pairs corresponding to it.

if...
— There must be exactly two elements: a single (key,value) pair, else there is nothing to print.

puts...
— Print the key in the key value pair, if any. (No word has spaces.)

You can play with it using CodeChef.

Title: What is the most frequent word?

Body:
Tcl 8.6, 196 bytes

lmap s [join [read stdin] \ ] {dict incr d [regsub -all {[^\w-]} [string tol $s] {}]}
set y [dict fi $d v [lindex [lsort [dict v $d]] end]]
if {[llength $y]!=2} {set y {}}
puts "==> [lindex $y 0]"

(Alas, I can't figure out how to get it any smaller than that...)

Explanation

It uses several obscure Tcl idioms to do stuff.

[join [read stdin] " "]
— input string→list of whitespace-separated words

lmap ...
— iterate over every element of that list. (Shorter than foreach and effectually identical since the result is discarded.)

[regsub ... [string tolower ...]]
— Convert the string to lowercase and strip all characters except for word characters and the hyphen.

[dict incr d ...]
— Create/modify a dictionary/word→count histogram.

set y ...
— Sort the dictionary values, take the largest one, and return all (key,value) pairs corresponding to it.

if...
— There must be exactly two elements: a single (key,value) pair, else there is nothing to print.

puts...
— Print the key in the key value pair, if any. (No word has spaces.)

You can play with it using CodeChef.


问:
Do these squares overlap?
Given the coordinates of the upper left corners of two squares and their side lengths, determine whether the squares overlap. A square includes the top and left lines, but not the bottom and right lines. That is, a point (a,b) is inside a square with side length k that starts at (x,y) if and only if x <= a < x+k and y <= b < y+k. A square with side length 0 is degenerate and will not be considered here, thus, k will be positive.

As usual, all standard rules apply. Input and output may be in whatever form is convenient, so long as it's human readable and there is no precomputation. Be sure to specify what input format you use. Your code should take six numbers and output truthy if the squares overlap and falsy otherwise.

Test Cases

```<code>x1 y1 k1  x2 y2 k2  overlap?
 1  1  1   0  1  1  false
 0  0  3   1  1  1  true
 1  1  1   0  0  3  true
 0  0  3   2  1  2  true
 0  0  2   1  1  2  true
 1  1  2   0  0  2  true
 0  1  2   1  0  2  true
 1  0  2   0  1  2  true
 2  0  2   0  2  2  false
 1  0  3   0  1  1  false
 0  2  3   0  0  2  false
</code>```

All inputs will be non-negative integers. That said, I expect that many or most solutions will also be able to handle negatives and floats.

答:
Octave, 17 bytes

```<code>@(a,b)a-flip(a)<b
</code>```

Same logic as my MATLAB answer above, except that Octave supports automatic broadcasting of dimensions so we can replace [b,b] with simply b.

All test cases here

Title: Do these squares overlap?

Body:
Octave, 17 bytes

@(a,b)a-flip(a)<b

Same logic as my MATLAB answer above, except that Octave supports automatic broadcasting of dimensions so we can replace [b,b] with simply b.

All test cases here


答:
Tcl, 111 bytes

```<code>lassign {1001 0 -1} r R x
while {[incr x]<$r} {set R [expr {$R+floor(sqrt($r*$r-$x*$x))}]}
puts [expr {4*$R+1}]
</code>```

Simple discrete x loop over quadrant I, counting largest y using the Pythagorean Theorem at each step. Result is 4 times the sum plus one (for the center point).

The size of the program depends on the value of r. Replace {1001 0 -1} with "$argv 0 -1" and you can run it with any command-line argument value for r.

Computes f(1001) → 3147833.0 in about 1030 microseconds, AMD Sempron 130 2.6GHz 64-bit processor, Windows 7.

Obviously, the larger the radius, the closer the approximation to PI: f(10000001) runs in about 30 seconds producing a 15-digit value, which is about the precision of a IEEE double.

Title: Code-Golf: Lattice Points inside a Circle

Body:
The following picture shows the problem:

Write a function that, given an integer as the circle radius, calculates the number of lattice points inside the centered circle (including the boundary).

The image shows:

```<code>f[1] = 5  (blue points)
f[2] = 13 (blue + red points)
</code>```

other values for your checking/debugging:

```<code>f[3]    = 29
f[10]   = 317
f[1000] = 3,141,549
f[2000] = 12,566,345
</code>```

Should have a reasonable performance. Let's say less than a minute for f[1000].

Shortest code wins. Usual Code-Golf rules apply.

Please post the calculation and timing of f[1001] as an example.

Body:
Tcl, 111 bytes

lassign {1001 0 -1} r R x
while {[incr x]<$r} {set R [expr {$R+floor(sqrt($r*$r-$x*$x))}]}
puts [expr {4*$R+1}]

Simple discrete x loop over quadrant I, counting largest y using the Pythagorean Theorem at each step. Result is 4 times the sum plus one (for the center point).

The size of the program depends on the value of r. Replace {1001 0 -1} with "$argv 0 -1" and you can run it with any command-line argument value for r.

Computes f(1001) → 3147833.0 in about 1030 microseconds, AMD Sempron 130 2.6GHz 64-bit processor, Windows 7.

Obviously, the larger the radius, the closer the approximation to PI: f(10000001) runs in about 30 seconds producing a 15-digit value, which is about the precision of a IEEE double.


问:
Reverse a 1-dimensional array
Note: This challenge is not the same.

Challenge

Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays (although we've got one for n-dimensional ones)! This should operate only on the 1st dimension, not on all dimensions of an array.

Rules

Standard loopholes are denied

[[1, 2], [3, 4]] becomes [[3, 4], [1, 2]], not [[4, 3], [2, 1]].

This is code-golf, but no answer is accepted. Go beat the others!

You can get the array any way, except hardcoding. You can also get a string and process it.

The input will be an array (yes, commas or no commas, it needs to be an array).

Test cases

These are the test cases:

```<code>[1, 2, 3, 4]
[1, 2, 'hello', 'world!']
[[1, 2, 3, 4], [2, 3, 4, 1]]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
</code>```

These are the supposed results:

```<code>[4, 3, 2, 1]
['world!', 'hello', 2, 1]
[[2, 3, 4, 1], [1, 2, 3, 4]]
[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
</code>```

You may accept input as [1 2 3 4], or even 1 2 3 4, or any other form or array your language has.

答:
Pyke, 1 byte

```<code>_
</code>```

Try it here!

Pyke has implicit input and output. Polyglot with Pyth, Jolf,

Title: Reverse a 1-dimensional array

Body:
Pyke, 1 byte

_

Try it here!

Pyke has implicit input and output. Polyglot with Pyth, Jolf,


问:
Golf Text into DNA

Text to DNA golf

Challenge

Convert input into a DNA output.

Algorithm

Convert text into ASCII code points (e.g. codegolf -> [99, 111, 100, 101, 103, 111, 108, 102])

String the ASCII codes together (e.g. 99111100101103111108102)

Convert to binary (e.g. 10100111111001101001011010001000011001101011011110000110010111111011000000110)

Pad 0s onto the end to make an even number of characters (e.g. 101001111110011010010110100010000110011010110111100001100101111110110000001100)

Replace 00 with A, 01 with C, 10 with G, and 11 with T (e.g. GGCTTGCGGCCGGAGACGCGGTCTGACGCCTTGTAAATA)

Output

Test Cases

```<code>codegolf > GGCTTGCGGCCGGAGACGCGGTCTGACGCCTTGTAAATA
ppcg > GGCTAATTGTCGCACTT
} > TTGG (padding)
</code>```

Specifications

This is code-golf

Your program must accept spaces in input.

Your program must work for codegolf.

答:
Python 2, <s>109</s> 103 bytes

lambda s,j=''.join:j('ACGT'[int(j(t),2)]for t in
zip(*[iter(bin(int(j(`ord(c)`for c in s))*2)[2:])]*2))
```

Test it on Ideone.

Title: Golf Text into DNA

Body:
Python 2, <s>109</s> 103 bytes

lambda s,j=''.join:j('ACGT'[int(j(t),2)]for t in
zip(*[iter(bin(int(j(`ord(c)`for c in s))*2)[2:])]*2))

Test it on Ideone.


答:
J, 7 bytes

Monadic function, taking argument on the right.

```<code>3{:@q:!
</code>```

If x is positive, x q: y returns the exponents in a prime factorization of y, for only the first x primes. The 3-rd prime is 5 and {: takes the tail of a list.

Note that you have to input integers with an x at the end, or else J will treat them as floats.

```<code>   3{:@q:! 100x
24
   3{:@q:! 666x
165
   3{:@q:! 2016x
502
</code>```

Try it yourself at tryj.tk, though be warned that this online interpreter will complain if you try anything larger than 1343.

If you want something that doesn't compute n! and hence doesn't require it fit in an integer, use the recursive solution <.@%&5(+$:@)^:*. (tryj.tk is still whiny on large inputs.)

Title: Zeroes at the end of a factorial

Body:
J, 7 bytes

Monadic function, taking argument on the right.

3{:@q:!

If x is positive, x q: y returns the exponents in a prime factorization of y, for only the first x primes. The 3-rd prime is 5 and {: takes the tail of a list.

Note that you have to input integers with an x at the end, or else J will treat them as floats.

   3{:@q:! 100x
24
   3{:@q:! 666x
165
   3{:@q:! 2016x
502

Try it yourself at tryj.tk, though be warned that this online interpreter will complain if you try anything larger than 1343.

If you want something that doesn't compute n! and hence doesn't require it fit in an integer, use the recursive solution <.@%&5(+$:@)^:*. (tryj.tk is still whiny on large inputs.)


问:
Convert header levels to numbers

Introduction

Nodes in tree structures (e.g. headings in a long document, law paragraphs, etc.) are often created by assigning a specific header level (h1, h2, etc.) to each item, but outputted with additional node numbers for each level (1., 1.1., etc.), e.g.:

```<code>1. Intro (h1)
1.1. About this (h2)
1.2. Target audience (h2)
2. Actual stuff (h1)
3. More stuff (h1)
3.1. Details (h2)
3.1.1. Special points (h3)
3.2. Specifics (h2)
3.2.1. Minutiae (h3)
3.2.2. Petitesses (h3)
3.3. Specifications (h2)
4. Index (h1)
5. Appendices (h1)
</code>```

Input

Given (by any means) a list of header levels (the X's in hX above) like:

```<code>[1,2,2,1,1,2,3,2,3,3,2,1,1]
</code>```

Input will always begin with a 1, and Inputn+1 is in the range [1,1+Inputn].

Input will only contain numbers in the range [1,256].

Output

Return (by any means) the list of lists (or matrix - see below) of node numbers (dot-separated above):

```<code>[[1],[1,1],[1,2],[2],[3],[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],[4],[5]]
</code>```

You may return scalars instead of one-element sub-lists:

```<code>[1,[1,1],[1,2],2,3,[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],4,5]
</code>```

You may return a matrix (or list of lists) which is padded with zeros so that all rows (sub-lists) have the same length:

```<code>[[1,0,0]
 [1,1,0]
 [1,2,0]
 [2,0,0]
 [3,0,0]
 [3,1,0]
 [3,1,1]
 [3,2,0]
 [3,2,1]
 [3,2,2]
 [3,3,0]
 [4,0,0]
 [5,0,0]]
</code>```

Additional rules

The reverse process of all this is just the length of each sub-list. You must also include a reverse program in the same language. Your score is the total byte count of your two programs. If you return zero-padded results on the first prgram, your reverse code must handle such input.

Please explain your code so we all can learn from it.

This is code golf, because I'll need to read it on a phone screen and type it into a computer. - No, really, this is not meme-ness!

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

Forward, <s>8</s> 6 bytes

```<code>ḣ+Ṭ}ð\
</code>```

Try it online!

Backward, 2 bytes

```<code>L€
</code>```

Try it online!

How it works

Forward

```<code>ḣ+Ṭ}ð\  Main link. Argument: A (list of integers)

    ð\  Cumulatively reduce A by the dyadic chain to the left. Arguments: x, y
ḣ       Head; Truncate x to y items.
  Ṭ}    Untruth; yield a list of y-1 zeroes and 1 one.
 +      Compute the vectorized sum of both results.
</code>```

Backward

```<code>L€      Main link. Argument: A (nested list)

L       Length.
 €      Map the previous link over all items in A.
</code>```

Title: Convert header levels to numbers

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

Forward, <s>8</s> 6 bytes

ḣ+Ṭ}ð\

Try it online!

Backward, 2 bytes

L€

Try it online!

How it works

Forward

ḣ+Ṭ}ð\  Main link. Argument: A (list of integers)

    ð\  Cumulatively reduce A by the dyadic chain to the left. Arguments: x, y
ḣ       Head; Truncate x to y items.
  Ṭ}    Untruth; yield a list of y-1 zeroes and 1 one.
 +      Compute the vectorized sum of both results.

Backward

L€      Main link. Argument: A (nested list)

L       Length.
 €      Map the previous link over all items in A.


Title: Golf Text into DNA

Body:
Text to DNA golf

Challenge

Convert input into a DNA output.

Algorithm

Convert text into ASCII code points (e.g. codegolf -> [99, 111, 100, 101, 103, 111, 108, 102])

String the ASCII codes together (e.g. 99111100101103111108102)

Convert to binary (e.g. 10100111111001101001011010001000011001101011011110000110010111111011000000110)

Pad 0s onto the end to make an even number of characters (e.g. 101001111110011010010110100010000110011010110111100001100101111110110000001100)

Replace 00 with A, 01 with C, 10 with G, and 11 with T (e.g. GGCTTGCGGCCGGAGACGCGGTCTGACGCCTTGTAAATA)

Output

Test Cases

```<code>codegolf > GGCTTGCGGCCGGAGACGCGGTCTGACGCCTTGTAAATA
ppcg > GGCTAATTGTCGCACTT
} > TTGG (padding)
</code>```

Specifications

This is code-golf

Your program must accept spaces in input.

Your program must work for codegolf.

Body:
J, 52 bytes

 3 :'''ACGT''{~#._2,\#:".,&''x''":(,&:(":"0))/3&u:y'

Usage: 3 :'''ACGT''{~#._2,\#:".,&''x''":(,&:(":"0))/3&u:y' 'codegolf' ==> GGCTTGCGGCCGGAGACGCGGTCTGACGCCTTGTAAATA


答:
Pyth, 11 + 2 = 13 bytes

Forward:

```<code>m=X_1<+Y0d1
</code>```

Demonstration

Backward:

```<code>lM
</code>```

I like this one.

How it works:

```<code>m=X_1<+Y0d1
               Implicit: Y = []
m              Map over the input, with d being the map variable
      +Y0      Add a 0 on to the end of Y
     <   d     Slice down to the first d elements
  X_1     1    Increment the last one
 =             Assign the result back to Y
</code>```

The resultant list will contain each value that Y takes on, which is the desired sequence.

Embarrassment cured.

Title: Convert header levels to numbers

Body:
Introduction

Nodes in tree structures (e.g. headings in a long document, law paragraphs, etc.) are often created by assigning a specific header level (h1, h2, etc.) to each item, but outputted with additional node numbers for each level (1., 1.1., etc.), e.g.:

```<code>1. Intro (h1)
1.1. About this (h2)
1.2. Target audience (h2)
2. Actual stuff (h1)
3. More stuff (h1)
3.1. Details (h2)
3.1.1. Special points (h3)
3.2. Specifics (h2)
3.2.1. Minutiae (h3)
3.2.2. Petitesses (h3)
3.3. Specifications (h2)
4. Index (h1)
5. Appendices (h1)
</code>```

Input

Given (by any means) a list of header levels (the X's in hX above) like:

```<code>[1,2,2,1,1,2,3,2,3,3,2,1,1]
</code>```

Input will always begin with a 1, and Inputn+1 is in the range [1,1+Inputn].

Input will only contain numbers in the range [1,256].

Output

Return (by any means) the list of lists (or matrix - see below) of node numbers (dot-separated above):

```<code>[[1],[1,1],[1,2],[2],[3],[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],[4],[5]]
</code>```

You may return scalars instead of one-element sub-lists:

```<code>[1,[1,1],[1,2],2,3,[3,1],[3,1,1],[3,2],[3,2,1],[3,2,2],[3,3],4,5]
</code>```

You may return a matrix (or list of lists) which is padded with zeros so that all rows (sub-lists) have the same length:

```<code>[[1,0,0]
 [1,1,0]
 [1,2,0]
 [2,0,0]
 [3,0,0]
 [3,1,0]
 [3,1,1]
 [3,2,0]
 [3,2,1]
 [3,2,2]
 [3,3,0]
 [4,0,0]
 [5,0,0]]
</code>```

Additional rules

The reverse process of all this is just the length of each sub-list. You must also include a reverse program in the same language. Your score is the total byte count of your two programs. If you return zero-padded results on the first prgram, your reverse code must handle such input.

Please explain your code so we all can learn from it.

This is code golf, because I'll need to read it on a phone screen and type it into a computer. - No, really, this is not meme-ness!

Body:
Pyth, 11 + 2 = 13 bytes

Forward:

m=X_1<+Y0d1

Demonstration

Backward:

lM

I like this one.

How it works:

m=X_1<+Y0d1
               Implicit: Y = []
m              Map over the input, with d being the map variable
      +Y0      Add a 0 on to the end of Y
     <   d     Slice down to the first d elements
  X_1     1    Increment the last one
 =             Assign the result back to Y

The resultant list will contain each value that Y takes on, which is the desired sequence.

Embarrassment cured.


答:
Python 3, 126 bytes

```<code>lambda v:"".join(["ACGT"[int(x,2)]for x in map(''.join,zip(*[iter((bin(int("".join([str(ord(i))for i in v])))+"0")[2:])]*2))])
</code>```

Title: Golf Text into DNA

Body:
Python 3, 126 bytes

lambda v:"".join(["ACGT"[int(x,2)]for x in map(''.join,zip(*[iter((bin(int("".join([str(ord(i))for i in v])))+"0")[2:])]*2))])


问:
Calculate the Fermat Point of a Triangle
This is somewhat similar to The centers of a triangle, but with a different point. The Fermat Point is the point P in triangle ABC such that the value of AP + BP + CP is minimized. There are two cases:

If there is an angle greater than 120 degrees, that vertex is the fermat point. Otherwise, draw equilateral triangles on each of the sides of ABC. Connect the far vertex of each equilateral triangle to the opposite vertex of triangle ABC. Doing this for each of the three equilateral triangles results in a single common point of intersection for all three lines, which is the Fermat Point.

It should run within 5 seconds on a reasonable machine.

Input: A set of 3 points, not necessarily integers. This can be taken as a nested array, string, list of tuples, etc. (whatever suits your language).

Output: The coordinates of the Fermat point, again, however your language best handles points. Floating point inaccuracies will not be counted against you.

Test Cases:

```<code>[[1, 1], [2, 2], [1, 2]] --> [1.2113248654051871, 1.788675134594813]
[[-1, -1], [-2, -1], [0, 0]] --> [-1, -1]
[[-1, -1], [1, -1], [0, 1]] --> [0, -0.42264973081037427]
[[0, 0], [0.5, 0.8660254037844386], [-5, 0]] --> [0, 0]
[[0, 0], [0, -5], [-0.8660254037844386, 0.5]] --> [0, 0]
</code>```

This is code golf so shortest code wins!

答:
Python 3.5, <s>1019</s> <s>1016</s> <s>998</s> <s>982</s> <s>969</s> 953 bytes:

```<code>from math import*
def H(z,a,b):c=complex;T=lambda A,B:abs(c(*A)-c(*B));d=T(z,a);e=T(z,b);f=T(a,b);g=[d,e,f];h=max(g);g.remove(h);i=acos((sum(i*i for i in g)-(h*h))/(2*g[0]*g[-1]));_=[[z,a],[z,b],[a,b]];j,s,t=cos,sin,atan;N=[[b,a]for a,b in zip([b,a,z],[max(i,key=i.get)if i!=''else''for i in[{(g[0]+(h*j(t(l))),g[1]+(h*s(t(l)))):T(k,(g[0]+(h*j(t(l))),g[1]+(h*s(t(l))))),(g[0]-(h*j(t(l))),g[1]-(h*s(t(l)))):T(k,(g[0]-(h*j(t(l))),g[1]-(h*s(t(l)))))}if l else{(g[0]+h,g[1]):T(k,(g[0]+h,g[1])),(g[0]-h,g[1]):T(k,(g[0]-h,g[1]))}if l==0else''for g,h,l,k in zip([((a[0]+b[0])/2,(a[1]+b[1])/2)for a,b in _],[(3**0.5)*(i/2)for i in[d,e,f]],[-1/p if p else''if p==0else 0for p in[((a[1]-b[1])/(a[0]-b[0]))if a[0]-b[0]else''for a,b in _]],[b,a,z])]])if b!=''];I=N[0][0][1];J=N[0][0][0];K=N[1][0][1];G=N[1][0][0];A=(N[0][1][1]-I)/(N[0][1][0]-J);B=I-(A*J);C=(K-N[1][1][1])/(G-N[1][1][0]);D=K-(C*G);X=(D-B)/(A-C);Y=(A*X)+B;return[[X,Y],[[a,b][h==d],z][h==f]][i>2.0943]
</code>```

Incredibly long compared to other answers, but hey, at least it works! I could not be happier with the result I got as this has got to be one of the hardest challenges I have ever done. I am just so happy that it actually works! :D Now, onto the more technical notes:

This function takes each ordered pair in as a list or a tuple. For instance, H((1,1),(2,2),(1,2)) will work, but so will H([1,1],[2,2],[1,2]).

Outputs the coordinates of the points in either a list of integers or floating points depending on whether or not one angle more than or equal to 120º exists.

This may output -0.0 in place of 0.0 for some inputs. For instance, the output for the input [-1, -1], [1, -1], [0, 1] is [-0.0, -0.4226497308103744]. <s>I hope this is okay, although if it isn't, I will change it, though it will cost me a few more bytes.</s> This is okay, as confirmed by OP.

Should be accurate up to at least 13 to 14 significant figures.

I will try and golf this more over time. An explanation, possibly very long, coming soon.

Try It Online! (Ideone)

Body:
Python 3.5, <s>1019</s> <s>1016</s> <s>998</s> <s>982</s> <s>969</s> 953 bytes:

from math import*
def H(z,a,b):c=complex;T=lambda A,B:abs(c(*A)-c(*B));d=T(z,a);e=T(z,b);f=T(a,b);g=[d,e,f];h=max(g);g.remove(h);i=acos((sum(i*i for i in g)-(h*h))/(2*g[0]*g[-1]));_=[[z,a],[z,b],[a,b]];j,s,t=cos,sin,atan;N=[[b,a]for a,b in zip([b,a,z],[max(i,key=i.get)if i!=''else''for i in[{(g[0]+(h*j(t(l))),g[1]+(h*s(t(l)))):T(k,(g[0]+(h*j(t(l))),g[1]+(h*s(t(l))))),(g[0]-(h*j(t(l))),g[1]-(h*s(t(l)))):T(k,(g[0]-(h*j(t(l))),g[1]-(h*s(t(l)))))}if l else{(g[0]+h,g[1]):T(k,(g[0]+h,g[1])),(g[0]-h,g[1]):T(k,(g[0]-h,g[1]))}if l==0else''for g,h,l,k in zip([((a[0]+b[0])/2,(a[1]+b[1])/2)for a,b in _],[(3**0.5)*(i/2)for i in[d,e,f]],[-1/p if p else''if p==0else 0for p in[((a[1]-b[1])/(a[0]-b[0]))if a[0]-b[0]else''for a,b in _]],[b,a,z])]])if b!=''];I=N[0][0][1];J=N[0][0][0];K=N[1][0][1];G=N[1][0][0];A=(N[0][1][1]-I)/(N[0][1][0]-J);B=I-(A*J);C=(K-N[1][1][1])/(G-N[1][1][0]);D=K-(C*G);X=(D-B)/(A-C);Y=(A*X)+B;return[[X,Y],[[a,b][h==d],z][h==f]][i>2.0943]

Incredibly long compared to other answers, but hey, at least it works! I could not be happier with the result I got as this has got to be one of the hardest challenges I have ever done. I am just so happy that it actually works! :D Now, onto the more technical notes:

This function takes each ordered pair in as a list or a tuple. For instance, H((1,1),(2,2),(1,2)) will work, but so will H([1,1],[2,2],[1,2]).

Outputs the coordinates of the points in either a list of integers or floating points depending on whether or not one angle more than or equal to 120º exists.

This may output -0.0 in place of 0.0 for some inputs. For instance, the output for the input [-1, -1], [1, -1], [0, 1] is [-0.0, -0.4226497308103744]. <s>I hope this is okay, although if it isn't, I will change it, though it will cost me a few more bytes.</s> This is okay, as confirmed by OP.

Should be accurate up to at least 13 to 14 significant figures.

I will try and golf this more over time. An explanation, possibly very long, coming soon.

Try It Online! (Ideone)


答:
Actually, 1 byte

```<code>R
</code>```

Reverses the input list. These are words to make this answer long enough.

Title: Reverse a 1-dimensional array

Body:
Note: This challenge is not the same.

Challenge

Believe it or not, we haven't got ONE challenge for reversing one-dimensional arrays (although we've got one for n-dimensional ones)! This should operate only on the 1st dimension, not on all dimensions of an array.

Rules

Standard loopholes are denied

[[1, 2], [3, 4]] becomes [[3, 4], [1, 2]], not [[4, 3], [2, 1]].

This is code-golf, but no answer is accepted. Go beat the others!

You can get the array any way, except hardcoding. You can also get a string and process it.

The input will be an array (yes, commas or no commas, it needs to be an array).

Test cases

These are the test cases:

```<code>[1, 2, 3, 4]
[1, 2, 'hello', 'world!']
[[1, 2, 3, 4], [2, 3, 4, 1]]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]
</code>```

These are the supposed results:

```<code>[4, 3, 2, 1]
['world!', 'hello', 2, 1]
[[2, 3, 4, 1], [1, 2, 3, 4]]
[23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
</code>```

You may accept input as [1 2 3 4], or even 1 2 3 4, or any other form or array your language has.

Body:
Actually, 1 byte

R

Reverses the input list. These are words to make this answer long enough.


问:
Find the program that prints this integer sequence (Cops' thread)
This is the cops' thread. The robbers' thread goes here.

The last cops-and-robbers thread was already 4 months ago.

The cop's task

The cop's task is to write a program/function that takes a positive (or non-negative) integer and outputs/returns another integer.

The cop must state it if the program is intolerant towards zero.

The cop will provide at least 2 sample inputs/outputs.

For example, if I have decided to write the Fibonacci sequence, I would write this in my answer:

```
a(0) returns 0
a(3) returns 2
```

The number of examples is up to the cop's discretion.

However, the sequence must actually exist in the On-Line Encyclopedia of Integer Sequences®, so no pseudo-random number generator for you. :(

The cop can hide as many characters as is so wished.

For example, if my program is:

```<code>function a(n)
    if n>2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Then I would hide these characters as I want:

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

The robber's task

is obviously to find the original source code.

However, any proposed source code that produces the same set of output also counts as valid, as long as it is also found in OEIS.

Tips for the cops

<s>The search function in the OEIS only works for consecutive terms, so if you want to hide your sequence, then just leave a hole anywhere.</s>

Apparently there is no way to hide the sequence. Put this in mind when you choose the sequence.

Your score is the number of bytes in your code.

The winner will be the submission with the lowest score that hasn't been cracked in 7 days.

Only submissions that are posted in 2016 April are eligible for the win. Submissions that are posted later than this are welcome, but cannot win.

In order to claim the win you need to reveal the full code and the OEIS sequence (after 7 days).

Your post should be formatted like this (NN is the number of characters):

Lua, 98 bytes

Output:

```<code>a(0) returns 0
a(3) returns 2
</code>```

Code (# marks unrevealed characters):

```<code>function a(n)
    if ### then
        ########
    else
        ######################
    end
end
</code>```

If the code is cracked, insert [Cracked](link to cracker) in the header.
If the submission is safe, insert "Safe" in the header and reveal the full code in your answer. Only answers that have revealed the full code will be eligible for the win.

Body:
05AB1E, 10 bytes, Cracked

##3##1+*1+

0-indexed.

0 ==> 1
4 ==> 61
5 ==> 91
9 ==> 271

Original Program:

 UX3*X1+*1+


Title: Convert header levels to numbers

Body:
Ruby, 44 + 17 = 61 bytes

Forward:

->x{l=[]
x.map{|e|l=l[0,e-=1]<<(l[e]||0)+1}}

Backward:

->x{x.map &:size}


问:
Find the program that prints this integer sequence (Robbers' thread)
This is the robbers' thread. The cops' thread goes here.

In the cops thread, the task was to write a program/function that takes a positive (or non-negative) integer and outputs/returns another number (not necessarily integer). The robbers task is to unscramble the code the cops used to produce this output.

The cracked code doesn't have to be identical, as long as it has the same length and any revealed characters are in the correct positions. The language must also be the same (version numbers can be different). The output must of course be identical.

No-ops can be used in robber's solution.

The winner of the robbers thread will be the user who has cracked the
most submissions by May 7th 2016. If there's a tie, the user who has cracked submissions with the longest combined code will win.

The submission should be formatted like this:

Language, nn characters (including link to answer), Cop's username

Code:

```<code>function a(n)
    if n<2 then
        return n
    else
        return a(n-1) + a(n-2)
    end
end
</code>```

Output

```<code>a(0) returns 0
a(3) returns 2
</code>```

Optional explanation and comments.

答:
05AB1E, 10 bytes, George Gibson, A003215

Code:

```<code>Ds3*s1+*1+
</code>```

Explanation:

Computes 3*n*(n+1)+1 which is the oeis sequence A003215.

Body:
05AB1E, 10 bytes, George Gibson, A003215

Code:

Ds3*s1+*1+

Explanation:

Computes 3*n*(n+1)+1 which is the oeis sequence A003215.


问:
Make the longest cat program
There's been challenges for the shortest cat program, but as far as I know, there hasn't been any for the longest one.

A cat program is a program that copies its input to its output. Here's an example:

```<code>Input: Hello
Output: Hello

Input: cat
Output: cat
</code>```

So, the rules are simple:

The program has to copy its input to its output

No loopholes allowed.

This is code-bowling, so the longest code wins.

Also, I'm quite new here, so if you don't like this challenge, then please do tell me why so I'll be able to make better ones later!

答:
Lenguage, 23855 bytes

Program: Any file that is 23855 bytes long

Based off the brainfuck cat program on an interpreter returns 0 on EOF:

```<code>,[.,]
</code>```

Title: Make the longest cat program

Body:
Lenguage, 23855 bytes

Program: Any file that is 23855 bytes long

Based off the brainfuck cat program on an interpreter returns 0 on EOF:

,[.,]


答:
Brachylog, theoretically infinite

```<code>.............................................................................................
</code>```

You can add as many periods as you like.

The first period will unify the output with the input. The second period will unify the output with the output (which is always true), the third period will unify the output with the output, etc.

Title: Make the longest cat program

Body:
There's been challenges for the shortest cat program, but as far as I know, there hasn't been any for the longest one.

A cat program is a program that copies its input to its output. Here's an example:

```<code>Input: Hello
Output: Hello

Input: cat
Output: cat
</code>```

So, the rules are simple:

The program has to copy its input to its output

No loopholes allowed.

This is code-bowling, so the longest code wins.

Also, I'm quite new here, so if you don't like this challenge, then please do tell me why so I'll be able to make better ones later!

Body:
Brachylog, theoretically infinite

.............................................................................................

You can add as many periods as you like.

The first period will unify the output with the input. The second period will unify the output with the output (which is always true), the third period will unify the output with the output, etc.


问:
Print the AdamN tile
Adam7 is an interlacing algorithm for raster images, such as PNG. It is called the "Adam7" algorithm because it was invented by Adam M. Costello, and it is generated by following a certain pattern 7 times. One of the cool things about the Adam7 algorithm that makes it really fun for code golf, is that the pattern can be repeated an arbitrary number of times, as long as it's odd. Back when 1996 when the PNG standard was developed, using only 7 iterations was seen as sufficient, since the 9 iterations was too complex, and 5 iterations is not as efficient.

Here is the first iteration of the tile:

```<code>a
</code>```

Pretty simple. This is an "Adam1" tile. Here's how we get to the next iteration, the "Adam3" tile.

Since our last tile was 1x1, we double the height and width, and the next one will be 2x2. First, we start with an 'a' in the upper left corner.

```<code>a-
--
</code>```

Step 2, copy this pattern to the right, and increase the letter we're on by one.

```<code>ab
--
</code>```

Step 3, same as step 2, but copy down instead of right.

```<code>ab
cc
</code>```

Boom. The "Adam3" tile. Let's do the "Adam5" also, so you can actually see how the algorithm works. This tile will, again, be twice as large, so 4x4. Again, we start with a a in the upper left corner:

```<code>a---
----
----
----
</code>```

Double this pattern, increase the letter, and move it to the right:

```<code>a-b-
----
----
----
</code>```

Again, this time down.

```<code>a-b-
----
c-c-
----
</code>```

Again, this time to the right.

```<code>adbd
----
cdcd
----
</code>```

Again, this time down.

```<code>adbd
eeee
cdcd
eeee
</code>```

This is the "Adam5" tile. Here is the ASCII representation of the Adam7 tile:

```<code>afdfbfdf
gggggggg
efefefef
gggggggg
cfdfcfdf
gggggggg
efefefef
gggggggg
</code>```

And while we're at it, here is a fun animation of each step of the Adam7 tile (although it does several tiles side by side):

The challenge

Given a positive odd number N, output the "AdamN" tile. You can use any default method of IO. Since we're using the alphabet in lieu of numbers, you only need to handle inputs up to 25. You can choose to output lower-case or upper-case characters as long as you specify and it's consistent.

Sample IO

1:

```<code>a-
--
</code>```0

3:

```<code>a-
--
</code>```1

5:

```<code>a-
--
</code>```2

7:

```<code>afdfbfdf
gggggggg
efefefef
gggggggg
cfdfcfdf
gggggggg
efefefef
gggggggg
</code>```

9:

```<code>ahfhdhfhbhfhdhfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii
ehfhehfhehfhehfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii
chfhdhfhchfhdhfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii
ehfhehfhehfhehfh
iiiiiiiiiiiiiiii
ghghghghghghghgh
iiiiiiiiiiiiiiii
</code>```

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

答:
Pyth, 38 bytes

```<code>u:+r:jK@;tyHGb++b*^2H@;yHb6b+bKbh/Q2"a
</code>```

Try it here!

I would expect this to be easily golfable.

Title: Print the AdamN tile

Body:
Pyth, 38 bytes

u:+r:jK@;tyHGb++b*^2H@;yHb6b+bKbh/Q2"a

Try it here!

I would expect this to be easily golfable.