答:
Jelly, 8 bytes

```<code>ṛŒsḟḟȧµ\
</code>```

Try it online! or verify all test cases.

How it works

```<code>ṛŒsḟḟȧµ\  Main link. Argument: s (string)

      µ   Convert all links to the left into a chain (unknown arity) and begin a
          new chain.
       \  Do a cumulative reduce by the chain to the left.
          Left argument:   r (previous result or first character)
          Right argument:  c (next character)
ṛ           Set the return value to c.
 Œs         Swap c's case.
    ḟ       Remove c from r (if present).
            This yields an empty string if c and r are identical (repeated letter
            with the same case or non-letter) and r otherwise.
            Note that r will be empty if the previous character has been removed.
   ḟ        Remove the resulting characters (if any) from c with swapped case.
            This yields c with swapped case if the result to the right does not
            contain c; otherwise, it yields the empty string.
     ȧ      Flat logical AND with c.
            Replace swapped case c with c; do not modify an empty string.
</code>```

Title: Remove duplicated & switched case

Body:
Jelly, 8 bytes

ṛŒsḟḟȧµ\

Try it online! or verify all test cases.

How it works

ṛŒsḟḟȧµ\  Main link. Argument: s (string)

      µ   Convert all links to the left into a chain (unknown arity) and begin a
          new chain.
       \  Do a cumulative reduce by the chain to the left.
          Left argument:   r (previous result or first character)
          Right argument:  c (next character)
ṛ           Set the return value to c.
 Œs         Swap c's case.
    ḟ       Remove c from r (if present).
            This yields an empty string if c and r are identical (repeated letter
            with the same case or non-letter) and r otherwise.
            Note that r will be empty if the previous character has been removed.
   ḟ        Remove the resulting characters (if any) from c with swapped case.
            This yields c with swapped case if the result to the right does not
            contain c; otherwise, it yields the empty string.
     ȧ      Flat logical AND with c.
            Replace swapped case c with c; do not modify an empty string.


问:
Remove duplicated & switched case

Goal

The goal of this challenge is: given a string as input, remove duplicate pairs of letters, if the second item in the pair is of opposite capitalization. (i.e. uppercase becomes lowercase and vice-versa).

Pairs should be replaced from left to right. For example, aAa should become aa and not aA.

Inputs & outputs:

```<code>Input:         Output:
bBaAdD         bad
NniIcCeE       Nice
Tt eE Ss tT    T e S t
sS Ee tT       s E t
1!1!1sStT!     1!1!1st!
nN00bB         n00b
(eE.gG.)       (e.g.)
Hh3lL|@!       H3l|@!
Aaa            Aa
aaaaa          aaaaa
aaAaa          aaaa
</code>```

The input consists of printable ASCII symbols.

You shouldn't remove duplicated digits or other non-letter characters.

Acknowledgement

This challenge is the opposite of @nicael 's "Duplicate & switch case". Can you reverse it?

Thank you for all contributors from the sandbox!

Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

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 snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</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

```

答:
Python 3, <s>64</s> <s>59</s> 58 bytes

r=input()
for c in r:r=c[c.swapcase()==r!=c:];print(end=r)
```

Test it on Ideone.

ContentLicense: CC BY-SA 3.0

Title: Remove duplicated & switched case

Body:
Python 3, <s>64</s> <s>59</s> 58 bytes

r=input()
for c in r:r=c[c.swapcase()==r!=c:];print(end=r)

Test it on Ideone.


问:
Coercing a string to an integer in GolfScript
GolfScript automatically coerces values, according to the following ‘priority’ sequence:

integer → array → string → block

(listed from lowest to highest.)

This means that "1"7+ leaves the string "17" on the stack (and not 8), because strings have a higher priority than integers.

[To those GolfScript veterans – apologies for insulting your respective intelligences.]

How would it be possible to do this the other way? That is, to coerce a string into an integer?

答:
There's an operator ~ in golfscript, which does the following: bitwise not, dump, eval.

Therefore, "1" will give the string "1" while "1"~ will evaluate that string (into the integer 1).

Then, all you need to do is "1"~7+.

Try it online!


答:
C, 66 bytes

```<code>l;main(c){for(;~(c=getchar());)l=l^c^32|!isalpha(c)?putchar(c):0;}
</code>```

Title: Remove duplicated & switched case

Body:
Goal

The goal of this challenge is: given a string as input, remove duplicate pairs of letters, if the second item in the pair is of opposite capitalization. (i.e. uppercase becomes lowercase and vice-versa).

Pairs should be replaced from left to right. For example, aAa should become aa and not aA.

Inputs & outputs:

```<code>Input:         Output:
bBaAdD         bad
NniIcCeE       Nice
Tt eE Ss tT    T e S t
sS Ee tT       s E t
1!1!1sStT!     1!1!1st!
nN00bB         n00b
(eE.gG.)       (e.g.)
Hh3lL|@!       H3l|@!
Aaa            Aa
aaaaa          aaaaa
aaAaa          aaaa
</code>```

The input consists of printable ASCII symbols.

You shouldn't remove duplicated digits or other non-letter characters.

Acknowledgement

This challenge is the opposite of @nicael 's "Duplicate & switch case". Can you reverse it?

Thank you for all contributors from the sandbox!

Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

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 snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</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

```

Body:
C, 66 bytes

l;main(c){for(;~(c=getchar());)l=l^c^32|!isalpha(c)?putchar(c):0;}


问:
Draw the national flag of Iceland
This year's UEFA Euro 2016 is over and besides a couple of negative headlines there has been a very positive surprise as well – the Iceland national football team. Let's draw their national flag.

Input

Well, obviously this challenge has no input.

Output

Draw the flag of Iceland in any applicable visual format of at least 100 x 72 pixels or 25 x 18 characters.

Save the output to a file or present it instantly – example formats are: images like png, jpg etc., vector graphics, draw on HTML canvas or even use non-whitespace characters for visualization.

Use these colors: blue: #0048e0, white: #ffffff and red: #d72828.

If your language doesn't support specific color values, use the standard values for red, blue and white from the ANSI color codes.

Draw the flag with the correct proportions, as shown in the figure below:

Boilerplate

You can write a program or a function. If it is an anonymous function, please include an example of how to invoke it.

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

Standard loopholes are disallowed.

Leaderboard

var QUESTION_ID = 85141; // 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 = 41859; // This should be the user ID of the challenge author.
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 (! /<a/.test(lang)) lang = '' + lang + '';lang = jQuery(lang).text().toLowerCase();languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link, uniq: lang};});var langs = [];for (var lang in languages)if (languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function (a, b) {if (a.uniq > b.uniq) return 1;if (a.uniq < b.uniq) 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/Sites/codegolf/all.css?v=617d0685f6f3">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

If you can't find your answer, format your language and byte count as explained in the Leaderboard's "Info Section".

This challenge is inspired by Draw the national flag of france.

Title: Draw the national flag of Iceland

Body:
KA Processing, 79 bytes

stroke(255);background(0,72,224);fill(215,40,40);rect(0,8,25,2);rect(8,0,2,18);

Try it here!


问:
Dice from Changing Random Generator

Introduction

You are given a random integer generator with the following implementation

The first invocation always returns 1.

The second invocation returns a random integer between 1 and 2.

The third invocation returns a random integer between 1 and 3.

The nth invocation returns a random integer between 1 and n, inclusive.

Based on the above function, write a random dice generator that is perfectly random, returning a value between 1 and 6 (inclusive) with equal probability.

Rules

Your program/function should result in a random integer between 1 and 6, inclusive, in some usable form, i.e., to standard output or as a function return value.

The ascending random number generator above can be defined as a "free" function in your program (i.e., doesn't count toward your character count), or a separate script/program that is executed as needed, assuming the state (n) is persistent between calls.

Assume that no more than 1000 dice rolls will ever be requested in a single use case of your program, and the initial random number generator can be reset to 1 at the end of 1000 dice rolls to avoid overflow of n.

Your program may not use any other source of random numbers except the ascending random generator defined above.  You may of course request multiple random numbers from the random number generator for each single dice roll output.

This is code-golf, so winner is shortest answer or most votes in the event of a tie.  If you can generate 1000 dice rolls using less than 1000 generated random numbers, give yourself a 10-point efficiency bonus.

Example

```<code>./asc-rand
1 # random integer between 1 and 1
./asc-rand
1 # random integer between 1 and 2
./asc-rand
3 # random integer between 1 and 3
./asc-rand
4 # random integer between 1 and 4

# dice-gen generates random dice based on output of asc-rand program.
./dice-gen
3
./dice-gen
6
./dice-gen
5
./dice-gen
1
</code>```

答:
Python 65 63

```<code>i=7
while i>5:[R()for x in range(9)];i=int(`R()`[-1])
print i+1
</code>```

The function R() is the ascending randomizer.

Usage:

```<code>$ ./rollDice.py
3
$ ./rollDice.py
5
</code>```

Title: Dice from Changing Random Generator

Body:
Python 65 63

i=7
while i>5:[R()for x in range(9)];i=int(`R()`[-1])
print i+1

The function R() is the ascending randomizer.

Usage:

$ ./rollDice.py
3
$ ./rollDice.py
5


问:
Lithp Tranthlator
My friend made a lisp translator the other day, that is to say it took a string and converted s=>th and S=>Th. It was quite long and I thought that it could be golfed.

So the task is to make a program/function that takes an input string, translates it in to lisp and outputs the string

Test case

```<code>Sam and Sally like Sheep        Tham and Thally like Thheep
Sally likes sausages            Thally liketh thauthageth
Sally sells seashells           Thally thellth theathhellth
</code>```

Note that it doesn't matter that h gets repeated all the time

This is code golf so shortest answer wins

答:
x86 machine code, 19 bytes

In hex:

```<code>86ac3c5374043c73750440aab068aa84c075eec3
</code>```

Input: ESI: input string, EDI: output buffer.

Disassembly:

```<code>_loop:
0:  ac          lodsb
1:  3c 53       cmp al,'S'
3:  74 04       je _th
5:  3c 73       cmp al,'s'
7:  75 04       jne _nth
_th:
9:  40          inc eax     ;[Ss]->[Tt]
a:  aa          stosb
b:  b0 68       mov al,'h'
_nth:
d:  aa          stosb
e:  84 c0       test al,al
10: 75 ee       jnz _loop
12: c3          ret
</code>```

Title: Lithp Tranthlator

Body:
x86 machine code, 19 bytes

In hex:

86ac3c5374043c73750440aab068aa84c075eec3

Input: ESI: input string, EDI: output buffer.

Disassembly:

_loop:
0:  ac          lodsb
1:  3c 53       cmp al,'S'
3:  74 04       je _th
5:  3c 73       cmp al,'s'
7:  75 04       jne _nth
_th:
9:  40          inc eax     ;[Ss]->[Tt]
a:  aa          stosb
b:  b0 68       mov al,'h'
_nth:
d:  aa          stosb
e:  84 c0       test al,al
10: 75 ee       jnz _loop
12: c3          ret


答:
JavaScript (ES6), <s>71</s> 68 bytes

```<code>s=>s.replace(/./g,c=>l=c!=l&&c>'0'&&parseInt(c+l,36)%37<1?'':c,l='')
</code>```

Explanation:

```<code>s=>s.replace(/./g,c=>   Loop over each character in the string
 l=                     Save result for next loop
  c!=l&&                Check whether characters differ
  c>'@'&&               Check minimum character code
  parseInt(c+l,36)%37<1 Check if characters have same value
  ?'':c,                If so then delete this character
 l='')                  Initial empty previous character
</code>```

Given c>'@', the only way for parseInt(c+l,36) to be a multiple of 37 is for both c and l to have the same value (they can't have zero value because we excluded space and zero, and if they have no value then the expression will evaluate to NaN<1 which is false) is for them to be the same letter. However, we know that they're not the same letter case-sensitively, so they must be the same case-insensitively.

Note that this algorithm only works if I check every character; if I try to simplify it by matching on letters it will then fail on things like "a+A".

Edit: Saved 3 bytes thanks to @edc65.

Title: Remove duplicated & switched case

Body:
JavaScript (ES6), <s>71</s> 68 bytes

s=>s.replace(/./g,c=>l=c!=l&&c>'0'&&parseInt(c+l,36)%37<1?'':c,l='')

Explanation:

s=>s.replace(/./g,c=>   Loop over each character in the string
 l=                     Save result for next loop
  c!=l&&                Check whether characters differ
  c>'@'&&               Check minimum character code
  parseInt(c+l,36)%37<1 Check if characters have same value
  ?'':c,                If so then delete this character
 l='')                  Initial empty previous character

Given c>'@', the only way for parseInt(c+l,36) to be a multiple of 37 is for both c and l to have the same value (they can't have zero value because we excluded space and zero, and if they have no value then the expression will evaluate to NaN<1 which is false) is for them to be the same letter. However, we know that they're not the same letter case-sensitively, so they must be the same case-insensitively.

Note that this algorithm only works if I check every character; if I try to simplify it by matching on letters it will then fail on things like "a+A".

Edit: Saved 3 bytes thanks to @edc65.


问:
Write a program to display directory treehouse
Given a directory (such as C:/), given from stdin or read from a file, produce a directory tree, with each file/folder indented based on its depth.

Example

If I have a C:/ drive which only contains two folders foo and bar, and bar is empty while foo contains baz.txt, then running with input C:/ produces:

```<code>C:/
    bar/
    foo/
        baz.txt
</code>```

while running with input C:/foo/ should produce

```<code>foo/
    baz.txt
</code>```

As this is codegolf, lowest byte count wins. The file extensions (such as baz.txt) are optional.
Extra notes: hidden files can be ignored, directories must actually exist, it can be assumed that files do not contain unprintable characters or new lines but all other printable ASCII characters are fine (file names with spaces must be supported). Output can be written to file or stdout. The indentations can be made up of either a tab character or 4 spaces.

答:
bash, <s>61</s> <s>58</s> 54 bytes

```<code>find "$1" -exec ls -Fd {} \;|perl -pe's|.*?/(?!$)|  |g'
</code>```

Takes input as a command line argument, outputs on STDOUT.

Note that the spaces near the end before the |g are actually a tab character (SE converts them to spaces when displaying posts).

```<code>find              crawl directory tree recursively
"$1"              starting at the input directory
-exec             and for each file found, execute...
ls -Fd {} \;      append a trailing slash if it's a directory (using -F of ls)
|perl -pe         pipe each line to perl
'
s|                replace...
.*?/              each parent directory in the file's path...
(?!$)             that doesn't occur at the end of the string...
|    |            with a tab character...
g                 globally
'
</code>```

Thanks to @Dennis for 4 bytes!

Body:
bash, <s>61</s> <s>58</s> 54 bytes

find "$1" -exec ls -Fd {} \;|perl -pe's|.*?/(?!$)|  |g'

Takes input as a command line argument, outputs on STDOUT.

Note that the spaces near the end before the |g are actually a tab character (SE converts them to spaces when displaying posts).

find              crawl directory tree recursively
"$1"              starting at the input directory
-exec             and for each file found, execute...
ls -Fd {} \;      append a trailing slash if it's a directory (using -F of ls)
|perl -pe         pipe each line to perl
'
s|                replace...
.*?/              each parent directory in the file's path...
(?!$)             that doesn't occur at the end of the string...
|    |            with a tab character...
g                 globally
'

Thanks to @Dennis for 4 bytes!


答:
JavaScript (ES6) 70

(s,p,q)=>s.replace(/./g,c=>p!=c&q===(d=parseInt(c,36))?q='':(q=d,p=c))
```
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>f=(s,p,q)=>s.replace(/./g,c=>p!=c&q===(d=parseInt(c,36))?q='':(q=d,p=c))

;
[['bBaAdD','bad']
,['NniIcCeE','Nice']
,['Tt eE Ss tT','T e S t']
,['sS Ee tT','s E t']
,['1!1!1sStT!','1!1!1st!']
,['nN00bB','n00b']
,['(eE.gG.)','(e.g.)']
,['Hh3lL|@!','H3l|@!']
,['Aaa','Aa']
,['aaaaa','aaaaa']
,['aaAaa','aaaa']]
.forEach(
  x=>
  {
    var i=x[0],k=x[1],r=f(i)
    console.log(k==r?'OK':'KO',i,r)
  }
)</code>```

Title: Remove duplicated & switched case

Body:
JavaScript (ES6) 70

(s,p,q)=>s.replace(/./g,c=>p!=c&q===(d=parseInt(c,36))?q='':(q=d,p=c))

f=(s,p,q)=>s.replace(/./g,c=>p!=c&q===(d=parseInt(c,36))?q='':(q=d,p=c))

;
[['bBaAdD','bad']
,['NniIcCeE','Nice']
,['Tt eE Ss tT','T e S t']
,['sS Ee tT','s E t']
,['1!1!1sStT!','1!1!1st!']
,['nN00bB','n00b']
,['(eE.gG.)','(e.g.)']
,['Hh3lL|@!','H3l|@!']
,['Aaa','Aa']
,['aaaaa','aaaaa']
,['aaAaa','aaaa']]
.forEach(
  x=>
  {
    var i=x[0],k=x[1],r=f(i)
    console.log(k==r?'OK':'KO',i,r)
  }
)


答:
Convex, 18 bytes

```<code>V±V.+'.+'|*\ô{0=}%
</code>```

Try it online!

Similar approach as @Leaky Nun's Pyth answer. It constructs the array ["aA" "bB" ... "zZ" "Aa" "Bb" ... "Zz" '.], joins by the '| character, and tests the input based on that regex. Then it takes the first character of each match.

Title: Remove duplicated & switched case

Body:
Convex, 18 bytes

V±V.+'.+'|*\ô{0=}%

Try it online!

Similar approach as @Leaky Nun's Pyth answer. It constructs the array ["aA" "bB" ... "zZ" "Aa" "Bb" ... "Zz" '.], joins by the '| character, and tests the input based on that regex. Then it takes the first character of each match.


问:
I programming puzzles, il code golf

Background

The Italian definite article (corresponding to English the) has seven different forms: l', il, lo, gli, i, la, le. Which one to use depends on three variables:

Gender: masculine / feminine.

Number: singular / plural.

Initial letter of the subsequent word: vowel / consonant type A / consonant type B.

Vowel is any of these: aeiou.

Consonant type B is any of these cases: s- followed by another consonant, z-, gn-, pn-, ps-, x-, i- followed by vowel (this i acts as a semivowel).

Consonant type A is a consonant that is not type B.

The table shows the article form to be used in each of the twelve combinations of the three above variables. Note that the l' form is attached to the following word with a single quote and without a space.

The challenge

Input a word and one or two strings, numbers or Booleans indicating gender and number. (The initial letters will have to be obtained from the input word).

The input word will be a sequence of lowercase ASCII letters. Accented vowels will be replaced by their non-accented versions (for example, realtà will be input as realta).

The gender and number inputs can be separate numbers, Booleans or strings, or a combined number of string (for example, 1 for masculine singular, 2 for feminine singular, etc).

Any reasonable format and separator can be used, as long as it is specified in the answer.

Output the word preceded by the appropriate form of the article, with space or single quote as needed. The output should also be lowercase. Trailing or leading blank space is allowed.

Code golf, shortest wins.

Test cases

In the following I use the input letters m, f to specify gender, and s, p for number (this is just one possible input format).

```<code>Input               Output              Comment

macchina f s        la macchina         Initial letter is cons. A
zio m s             lo zio              Initial letter is cons. B
libri m p           i libri             Initial letter is cons. A
ieri m s            lo ieri             Initial letter is cons. B
aquile f p          le aquile           Initial letter is vowel
spagnoli m p        gli spagnoli        Initial letter is cons. B
golf m s            il golf             Initial letter is cons. A
ombra f s           l'ombra             Initial letter is vowel
impossibili m p     gli impossibili     Initial letter is vowel
</code>```

答:
Python 3, 235 bytes

I was interested to see how short I could get this in Python without regexes. It turns out that this is not the best option...

```<code>lambda s,c,v='aeiou':[["l'",'il','lo'],['gli','i','gli'],["l'",'la','la'],['le']*3][c][[[1,2][s[0]=='s'and s[1]not in v or s[0]in'zx'or s[:2]in['gn','pn','ps']or s[0]=='i'and s[1]in v],0][s[0]in v and not(s[0]=='i'and s[1]in v)]]+' '+s
</code>```

An anonymous function that takes input via argument of the word s and the gender-number code c as an integer, using the following mapping:

```<code>0 - Masculine Singular
1 - Masculine Plural
2 - Feminine Singular
3 - Feminine Plural
</code>```

and returns the word with the correct article.

How it works

A list containing the possibilities for each c as separate lists is created. The list is then indexed into using the value of c, yielding a 3-element list with the relevant options. A list index is now chosen by indexing into another nested list with the results of Boolean expressions. If the first character of s is a vowel and is not i followed by a vowel, the option for vowel is yielded via the returning of the index 0. Else, a Boolean expression returning True for cons. B and False for cons. A is evaluated, yielding the indices 2 and 1 respectively. Finally, the index is used to yield the article, which is concatenated with a space and the original string before being returned.

Try it on Ideone

Title: I programming puzzles, il code golf

Body:
Python 3, 235 bytes

I was interested to see how short I could get this in Python without regexes. It turns out that this is not the best option...

lambda s,c,v='aeiou':[["l'",'il','lo'],['gli','i','gli'],["l'",'la','la'],['le']*3][c][[[1,2][s[0]=='s'and s[1]not in v or s[0]in'zx'or s[:2]in['gn','pn','ps']or s[0]=='i'and s[1]in v],0][s[0]in v and not(s[0]=='i'and s[1]in v)]]+' '+s

An anonymous function that takes input via argument of the word s and the gender-number code c as an integer, using the following mapping:

0 - Masculine Singular
1 - Masculine Plural
2 - Feminine Singular
3 - Feminine Plural

and returns the word with the correct article.

How it works

A list containing the possibilities for each c as separate lists is created. The list is then indexed into using the value of c, yielding a 3-element list with the relevant options. A list index is now chosen by indexing into another nested list with the results of Boolean expressions. If the first character of s is a vowel and is not i followed by a vowel, the option for vowel is yielded via the returning of the index 0. Else, a Boolean expression returning True for cons. B and False for cons. A is evaluated, yielding the indices 2 and 1 respectively. Finally, the index is used to yield the article, which is concatenated with a space and the original string before being returned.

Try it on Ideone


问:
Directory calculation
For this challenge, you will be given an absolute path, and a "new" path (which can be absolute or relative), and you need to return the final path.

For example, if your current directory was /var/tmp/test:

my_dir or my_dir/  should return /var/tmp/test/my_dir

../../my_dir should return /var/my_dir

/my_dir/./ should return /my_dir

../../../../../ should return /

To be more pedantic:

A directory is a non-empty string consisting of alphanumeric characters and the symbols -,_, or .

A path is a list of 0 or more directories, separated using /.  An absolute path starts with a /, a relative path does not.  Paths can include an ending /.

You need to "resolve" the second path, given the first path.

The process of resolving is:

Test if the second path is relative.  If so, then insert the absolute path's directories to the beginning of the second path.

If any of the directories is .., then remove it and the preceding directory.  If it is the first directory, then simply remove it.

If any of the directories is ., then remove it.

Output the final absolute path.  You should not output an ending /.

You do not need to handle incorrect input.  The commands should work, whether or not the directories passed actually exist on your machine.  You can assume that everything is a directory, even if it has an extension.

Test cases

```<code>Absolute      New          Output
"/a/b/c"      "d"       -> "/a/b/c/d"
"/a/b/c/"     "d"       -> "/a/b/c/d"
"/a/b/c/"     "d/"      -> "/a/b/c/d"
"/a/b/c"      "/d"      -> "/d"
"/a/b/c"      "/d/"     -> "/d"
"/../a/b/c/"  "d"       -> "/a/b/c/d"
"/a/../b/c/"  "d"       -> "/b/c/d"
"/a/b/../c"   "d"       -> "/a/c/d"
"/a/b/c/.."   "d"       -> "/a/b/d"
"/a/b/c/"     ".."      -> "/a/b"
"/a/b/c"      "../d"    -> "/a/b/d"
"/a/b/c"      "/../d"   -> "/d"
"/a/b/c"      ""        -> "/a/b/c"
"/a/b/c"      "."       -> "/a/b/c"
"/a/b/c"      "./d"     -> "/a/b/c/d"
"/a/b/c"      "/./d"    -> "/d"
"/a/b/c"      "d.txt"   -> "/a/b/c/d.txt"
"/a/b/c"      "d."      -> "/a/b/c/d."
"/a/b/c"      ".txt"    -> "/a/b/c/.txt"
"/a/b/c"      ".txt/d"  -> "/a/b/c/.txt/d"
"/a/b/."      "./././." -> "/a/b"
"/direc"      "tory"    -> "/direc/tory"
"/a-_.b/"     "__._-."  -> "/a-_.b/__._-."
"/a/b"        "../.."   -> "/"
"/a/b"        "../../.."-> "/"
"/a"          "../../.."-> "/"
"/"           ""        -> "/"
"/"           "a"       -> "/a"
"/.."         "a"       -> "/a"
"/."          ""        -> "/"
</code>```

This is a code-golf, so make your submissions as short as possible in your favorite language!

答:
Bash, 38 bytes

```<code>[[ $2 = /* ]]||p=$1
realpath -sm $p/$2
</code>```

Doesn't require root privileges and makes no assumptions about existing or non-existing files, directories or symbolic links.

Test it on Ideone.

How it works

[[ $2 = /* ]] tests if the second command-line argument begins with /.

If it doesn't, the path is relative and p=$1 sets variable p to the first command-line argument.

This way $p/$2 is /$2 if $2 is an absolute path and $1/$2 if it is a realtive one.

Finally, realpath -sm $p/$2 prints the canonical absolute path of $p/$2. The -s switch makes realpath ignore symbolic links, and the -m switch missing components.

Title: Directory calculation

Body:
Bash, 38 bytes

[[ $2 = /* ]]||p=$1
realpath -sm $p/$2

Doesn't require root privileges and makes no assumptions about existing or non-existing files, directories or symbolic links.

Test it on Ideone.

How it works

[[ $2 = /* ]] tests if the second command-line argument begins with /.

If it doesn't, the path is relative and p=$1 sets variable p to the first command-line argument.

This way $p/$2 is /$2 if $2 is an absolute path and $1/$2 if it is a realtive one.

Finally, realpath -sm $p/$2 prints the canonical absolute path of $p/$2. The -s switch makes realpath ignore symbolic links, and the -m switch missing components.


问:
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. 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. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

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 snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</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

```

答:
Sesos, 2 bytes

```<code>V0
</code>```

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

set numin  ; Switch to numeric input.
set numout ; Switch to numeric output.

get        ; Read an integer from STDIN and save in in the current cell.
nop        ; Set an entry marker.
    put    ; Print the integer in the current cell.
           ; (implicit jnz)
           ;     If the integer in the current cell is non-zero,
           ;     jump to the previous instruction.
```

Title: Implement a Truth-Machine

Body:
Sesos, 2 bytes

V0

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

set numin  ; Switch to numeric input.
set numout ; Switch to numeric output.

get        ; Read an integer from STDIN and save in in the current cell.
nop        ; Set an entry marker.
    put    ; Print the integer in the current cell.
           ; (implicit jnz)
           ;     If the integer in the current cell is non-zero,
           ;     jump to the previous instruction.


问:
Save the pilot!

Question

We are captured by robot army on their space station. Our space ship pilot is in the prison which is in level 1. There is only one way how to escape and it's rescuing your space ship pilot. It mean's moving from level N to level 1. However because it's very risky you need to get to the prison in the least number of steps as possible.

Conditions

There are 4 ways how to move:

Move from level N to level N - 1 e.g. from 12 to 11

Move from level N to level N + 1 e.g. from 12 to 13

Use teleport from level 2k to level k e.g. from 12 to 6

Use teleport from level 3k to level k e.g. from 12 to 4

Teleports are only one-way (you can get from 12 to 4 but it's imposible to get from 4 to 12)

Every action takes one step

Input

Input should be read from STDIN, or the closest alternative in your programming language. Input consists of an integer n where 1 <= n <= 10^8.

Output

The output should be the minimum number of steps it takes to go from n to level 1.

Examples

```<code>Level         Minimum number of steps
1             0
8             3
10            3
267           7
100,000,000   25
</code>```

Try to code program that will help us to save our space ship pilot from the prison in the shortest time and return home!

The shortest code will win!

答:
32-bit x86 machine code, 59 bytes

In hex:

```<code>31c9487435405031d231dbb103f7f14a7c070f94c301d008d353e8e3ffffff5b00c3585331d2b102f7f152e8d2ffffff5a00d05a38d076019240c3
</code>```

The machine language per se has no concept of standard input. Since the challenge is pure computational, I opted to write a function taking input parameter in EAX and returning result in AL.

The math behind the code is nicely explained by @Jakube: the search is conducted only among the paths having teleports interspersed with no more than one one-level moves. The performance is about 12000 test cases per second in the lower end of input range and 50 cases per second in the upper end. The memory consumption is 12 bytes of stack space per recursion level.

```<code>0:  31 c9               xor ecx, ecx
_proc:
2:  48                  dec eax
3:  74 35               je _ret       ;if (EAX==1) return 0;
5:  40                  inc eax       ;Restore EAX
6:  50                  push eax
7:  31 d2               xor edx, edx  ;Prepare EDX for 'div'
9:  31 db               xor ebx, ebx
b:  b1 03               mov cl, 3
d:  f7 f1               div ecx       ;EAX=int(EAX/3); EDX=EAX%3
f:  4a                  dec edx       ;EDX is [-1..1]
10: 7c 07               jl _div3      ;EDX<0 (i.e. EAX%3==0)
12: 0f 94 c3            sete bl       ;BL=EDX==0?1:0
15: 01 d0               add eax, edx  ;If EAX%3==2, we'd go +1 level before teleport
17: 08 d3               or bl, dl     ;BL=EAX%3!=0
_div3:
19: 53                  push ebx      ;Save register before...
1a: e8 e3 ff ff ff      call _proc    ;...recursive call
1f: 5b                  pop ebx
20: 00 c3               add bl, al    ;BL is now # of steps if taken 3n->n route (adjusted) less one
22: 58                  pop eax       ;Restore original input parameter's value
23: 53                  push ebx
24: 31 d2               xor edx, edx
26: b1 02               mov cl, 2
28: f7 f1               div ecx       ;EAX=EAX>>1; EDX=EAX%2
2a: 52                  push edx      ;Save register before...
2b: e8 d2 ff ff ff      call _proc    ;...another recursive call
30: 5a                  pop edx
31: 00 d0               add al, dl    ;AL is now # of steps if using 2n->n route (adjusted) less one
33: 5a                  pop edx
34: 38 d0               cmp al, dl    ;Compare two routes
36: 76 01               jbe _nsw
38: 92                  xchg eax, edx ;EAX=min(EAX,EDX)
_nsw:
39: 40                  inc eax       ;Add one for the teleport itself
_ret:
3a: c3                  ret
</code>```

Title: Save the pilot!

Body:
32-bit x86 machine code, 59 bytes

In hex:

31c9487435405031d231dbb103f7f14a7c070f94c301d008d353e8e3ffffff5b00c3585331d2b102f7f152e8d2ffffff5a00d05a38d076019240c3

The machine language per se has no concept of standard input. Since the challenge is pure computational, I opted to write a function taking input parameter in EAX and returning result in AL.

The math behind the code is nicely explained by @Jakube: the search is conducted only among the paths having teleports interspersed with no more than one one-level moves. The performance is about 12000 test cases per second in the lower end of input range and 50 cases per second in the upper end. The memory consumption is 12 bytes of stack space per recursion level.

0:  31 c9               xor ecx, ecx
_proc:
2:  48                  dec eax
3:  74 35               je _ret       ;if (EAX==1) return 0;
5:  40                  inc eax       ;Restore EAX
6:  50                  push eax
7:  31 d2               xor edx, edx  ;Prepare EDX for 'div'
9:  31 db               xor ebx, ebx
b:  b1 03               mov cl, 3
d:  f7 f1               div ecx       ;EAX=int(EAX/3); EDX=EAX%3
f:  4a                  dec edx       ;EDX is [-1..1]
10: 7c 07               jl _div3      ;EDX<0 (i.e. EAX%3==0)
12: 0f 94 c3            sete bl       ;BL=EDX==0?1:0
15: 01 d0               add eax, edx  ;If EAX%3==2, we'd go +1 level before teleport
17: 08 d3               or bl, dl     ;BL=EAX%3!=0
_div3:
19: 53                  push ebx      ;Save register before...
1a: e8 e3 ff ff ff      call _proc    ;...recursive call
1f: 5b                  pop ebx
20: 00 c3               add bl, al    ;BL is now # of steps if taken 3n->n route (adjusted) less one
22: 58                  pop eax       ;Restore original input parameter's value
23: 53                  push ebx
24: 31 d2               xor edx, edx
26: b1 02               mov cl, 2
28: f7 f1               div ecx       ;EAX=EAX>>1; EDX=EAX%2
2a: 52                  push edx      ;Save register before...
2b: e8 d2 ff ff ff      call _proc    ;...another recursive call
30: 5a                  pop edx
31: 00 d0               add al, dl    ;AL is now # of steps if using 2n->n route (adjusted) less one
33: 5a                  pop edx
34: 38 d0               cmp al, dl    ;Compare two routes
36: 76 01               jbe _nsw
38: 92                  xchg eax, edx ;EAX=min(EAX,EDX)
_nsw:
39: 40                  inc eax       ;Add one for the teleport itself
_ret:
3a: c3                  ret


问:
"Hello, World!"
So... uh... this is a bit embarrassing. But we don't have a plain "Hello, World!" challenge yet (despite having 35 variants tagged with hello-world, and counting). While this is not the most interesting code golf in the common languages, finding the shortest solution in certain esolangs can be a serious challenge. For instance, to my knowledge it is not known whether the shortest possible Brainfuck solution has been found yet.

Furthermore, while all of <s>Wikipedia</s> (the Wikipedia entry has been deleted but there is a copy at archive.org
), esolangs and Rosetta Code have lists of "Hello, World!" programs, none of these are interested in having the shortest for each language (there is also this GitHub repository). If we want to be a significant site in the code golf community, I think we should try and create the ultimate catalogue of shortest "Hello, World!" programs (similar to how our basic quine challenge contains some of the shortest known quines in various languages). So let's do this!

The Rules

Each submission must be a full program.

The program must take no input, and print Hello, World! to STDOUT (this exact byte stream, including capitalization and punctuation) plus an optional trailing newline, and nothing else.

The program must not write anything to STDERR.

If anyone wants to abuse this by creating a language where the empty program prints Hello, World!, then congrats, they just paved the way for a very boring answer.

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

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 "Hello, World!" program. This is about finding the shortest "Hello, World!" program in every language. Therefore, I will not mark any answer as "accepted".

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

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

For inspiration, check the Hello World Collection.

The Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

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 snippet:

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

/* Configuration */

var QUESTION_ID = 55422; // 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 = 8478; // 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,<]*(?:<(?:[^\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;
  display: block !important;
}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 500px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Sesos, <s>24</s> 21 bytes

```<code>0000000: 2845ee adaa55 ddcabd 123596 b32b71 5f398a 23b577  (E...U....5..+q_9.#.w
</code>```

Try it online! Check Debug to see the generated binary code.

I tried several less straightforward approaches – including a port of @primo's brainfuck answer – but they all turned out longer.

How it works

The binary file above has been generated by assembling the following SASM code.

add 72  ; Set cell 0 to 72.
put     ; Print 'H'.
fwd 1   ; Advance to cell 1.
add 101 ; Set cell 1 to 101.
put     ; Print 'e'.
add 7   ; Set cell 1 to 108.
put     ; Print 'l'.
put     ; Print 'l'.
add 3   ; Set cell 1 to 111.
put     ; Print 'o'.
fwd 1   ; Advance to cell 2.
add 44  ; Set cell 2 to 44.
put     ; Print ','.
sub 12  ; Set cell 2 to 32.
put     ; Print ' '.
rwd 2   ; Retrocede to cell 0.
add 15  ; Set cell 0 to 87.
put     ; Print 'W'.
fwd 1   ; Advance to cell 1.
put     ; Print 'o'.
add 3   ; Set cell 1 to 114.
put     ; Print 'r'.
sub 6   ; Set cell 1 to 108.
put     ; Print 'l'.
sub 8   ; Set cell 1 to 100.
put     ; Print 'd'.
fwd 1   ; Advance to cell 2.
add 1   ; Set cell 2 to 33.
put     ; Print '!'.
```

ContentLicense: CC BY-SA 4.0

Title: "Hello, World!"

Body:
Sesos, <s>24</s> 21 bytes

0000000: 2845ee adaa55 ddcabd 123596 b32b71 5f398a 23b577  (E...U....5..+q_9.#.w

Try it online! Check Debug to see the generated binary code.

I tried several less straightforward approaches – including a port of @primo's brainfuck answer – but they all turned out longer.

How it works

The binary file above has been generated by assembling the following SASM code.

add 72  ; Set cell 0 to 72.
put     ; Print 'H'.
fwd 1   ; Advance to cell 1.
add 101 ; Set cell 1 to 101.
put     ; Print 'e'.
add 7   ; Set cell 1 to 108.
put     ; Print 'l'.
put     ; Print 'l'.
add 3   ; Set cell 1 to 111.
put     ; Print 'o'.
fwd 1   ; Advance to cell 2.
add 44  ; Set cell 2 to 44.
put     ; Print ','.
sub 12  ; Set cell 2 to 32.
put     ; Print ' '.
rwd 2   ; Retrocede to cell 0.
add 15  ; Set cell 0 to 87.
put     ; Print 'W'.
fwd 1   ; Advance to cell 1.
put     ; Print 'o'.
add 3   ; Set cell 1 to 114.
put     ; Print 'r'.
sub 6   ; Set cell 1 to 108.
put     ; Print 'l'.
sub 8   ; Set cell 1 to 100.
put     ; Print 'd'.
fwd 1   ; Advance to cell 2.
add 1   ; Set cell 2 to 33.
put     ; Print '!'.


问:
Is it a pangram?
Write a function or program that takes as its input a string and prints a truthy value if the string is a pangram (a sequence of letters containing at least one of each letter in the English alphabet) and a falsey value otherwise.

Case of letters should be ignored; If the string is abcdefghijklmnopqrstuvwXYZ, then the function should still return a truthy value. Note that the string can contain any other characters in it, so 123abcdefghijklm NOPQRSTUVWXYZ321 would return a truthy value. An empty input should return a falsey value.

Test cases

```<code>AbCdEfGhIjKlMnOpQrStUvWxYz

==> True

ACEGIKMOQSUWY
BDFHJLNPRTVXZ

==> True

public static void main(String[] args)

==> False

The quick brown fox jumped over the lazy dogs. BOING BOING BOING

==> True
</code>```

This is code golf. Standard rules apply. Shortest code in bytes wins.

答:
C++, 121 bytes

```<code>int P(char *s){int c;bitset<26> a;while(c=*s){c=tolower(c)-'a';if(c>=0&&c<26)a.set(c);if(a.all())return 1;s++;}return 0;}
</code>```

Title: Is it a pangram?

Body:
C++, 121 bytes

int P(char *s){int c;bitset<26> a;while(c=*s){c=tolower(c)-'a';if(c>=0&&c<26)a.set(c);if(a.all())return 1;s++;}return 0;}


答:
Node REPL, <s>8</s> 12 bytes

```<code>path.resolve
</code>```

Luckily you don't have to require() standard modules in the REPL.

Test Suite

https://repl.it/Cclo/1

(If the output at the end is true, it matched)

Title: Directory calculation

Body:
For this challenge, you will be given an absolute path, and a "new" path (which can be absolute or relative), and you need to return the final path.

For example, if your current directory was /var/tmp/test:

my_dir or my_dir/  should return /var/tmp/test/my_dir

../../my_dir should return /var/my_dir

/my_dir/./ should return /my_dir

../../../../../ should return /

To be more pedantic:

A directory is a non-empty string consisting of alphanumeric characters and the symbols -,_, or .

A path is a list of 0 or more directories, separated using /.  An absolute path starts with a /, a relative path does not.  Paths can include an ending /.

You need to "resolve" the second path, given the first path.

The process of resolving is:

Test if the second path is relative.  If so, then insert the absolute path's directories to the beginning of the second path.

If any of the directories is .., then remove it and the preceding directory.  If it is the first directory, then simply remove it.

If any of the directories is ., then remove it.

Output the final absolute path.  You should not output an ending /.

You do not need to handle incorrect input.  The commands should work, whether or not the directories passed actually exist on your machine.  You can assume that everything is a directory, even if it has an extension.

Test cases

```<code>Absolute      New          Output
"/a/b/c"      "d"       -> "/a/b/c/d"
"/a/b/c/"     "d"       -> "/a/b/c/d"
"/a/b/c/"     "d/"      -> "/a/b/c/d"
"/a/b/c"      "/d"      -> "/d"
"/a/b/c"      "/d/"     -> "/d"
"/../a/b/c/"  "d"       -> "/a/b/c/d"
"/a/../b/c/"  "d"       -> "/b/c/d"
"/a/b/../c"   "d"       -> "/a/c/d"
"/a/b/c/.."   "d"       -> "/a/b/d"
"/a/b/c/"     ".."      -> "/a/b"
"/a/b/c"      "../d"    -> "/a/b/d"
"/a/b/c"      "/../d"   -> "/d"
"/a/b/c"      ""        -> "/a/b/c"
"/a/b/c"      "."       -> "/a/b/c"
"/a/b/c"      "./d"     -> "/a/b/c/d"
"/a/b/c"      "/./d"    -> "/d"
"/a/b/c"      "d.txt"   -> "/a/b/c/d.txt"
"/a/b/c"      "d."      -> "/a/b/c/d."
"/a/b/c"      ".txt"    -> "/a/b/c/.txt"
"/a/b/c"      ".txt/d"  -> "/a/b/c/.txt/d"
"/a/b/."      "./././." -> "/a/b"
"/direc"      "tory"    -> "/direc/tory"
"/a-_.b/"     "__._-."  -> "/a-_.b/__._-."
"/a/b"        "../.."   -> "/"
"/a/b"        "../../.."-> "/"
"/a"          "../../.."-> "/"
"/"           ""        -> "/"
"/"           "a"       -> "/a"
"/.."         "a"       -> "/a"
"/."          ""        -> "/"
</code>```

This is a code-golf, so make your submissions as short as possible in your favorite language!

Body:
Node REPL, <s>8</s> 12 bytes

path.resolve

Luckily you don't have to require() standard modules in the REPL.

Test Suite

https://repl.it/Cclo/1

(If the output at the end is true, it matched)


问:
Shortest code to produce infinite output
Write the shortest code you can that produces an infinite output.

That's all. You code will only be disqualified if it stops producing output at some point. As always in code golf, the shortest code wins.

Here's a list of answers that I think are really clever, so they can get credit:

The comma is both code and data

Infinite errors (that counts)

Infinite warnings (that also counts)

What's Marbelous?

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Sesos, 2 bytes

```<code>0000000: 2c06                                              ,.
</code>```

Prints an infinite amount of ones.

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

set numout ; Switch to numeric output

add 1      ; Set the current cell to 1.
jmp        ; Jump to the corresponding exit marker.
    put    ; Print the integer in the current cell to STDOUT.
           ; (implicit jnz)
           ;     If the integer in the current cell is non-zero,
           ;     jump to the previous instruction.
```

Body:
Sesos, 2 bytes

0000000: 2c06                                              ,.

Prints an infinite amount of ones.

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

set numout ; Switch to numeric output

add 1      ; Set the current cell to 1.
jmp        ; Jump to the corresponding exit marker.
    put    ; Print the integer in the current cell to STDOUT.
           ; (implicit jnz)
           ;     If the integer in the current cell is non-zero,
           ;     jump to the previous instruction.


问:
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

```

答:
Sesos, 2 bytes

```<code>0000000: 080a                                              ..
</code>```

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

nop       ; Set an entry marker.
    add 1 ; Increment the current cell.
          ; (implicit jnz)
          ;     If the integer in the current cell is non-zero,
          ;     jump to the previous instruction.
```

Body:
Sesos, 2 bytes

0000000: 080a                                              ..

Try it online! Check Debug to see the generated binary code.

How it works

The binary file above has been generated by assembling the following SASM code.

nop       ; Set an entry marker.
    add 1 ; Increment the current cell.
          ; (implicit jnz)
          ;     If the integer in the current cell is non-zero,
          ;     jump to the previous instruction.


问:
Stock Time Machine

Stock Time Machine

You've gained access to a dataset, tomorrowStocks, which contains the stock prices from your favorite business on the NASDAQ. This dataset is a container indexed by minutes past opening. Each index contains the price of the stock at that time.

```<code>// Assume the stock market opens at 9:30AM EDT
// tomorrowStocks[] contains the prices of your target stock.
// If the stock is $22 @ 10:30AM EDT
tomorrowStocks[60] == 22
</code>```

Output

Your task is to determine the best possible outcome of 1 purchase and 1 sale of 1 stock from the given dataset.

Gotchas

You must buy and sell exactly 1 stock.

You may not buy and sell in the same time slot.

You must buy before you sell.

Test Data

```<code>[1,2,3,4,5]    # 4
[1,99,2,105]   # 104
[99,1,99,100]  # 99
[99,1,1,2,1,3] # 2
[5,4,3,3,1]    # 0
[5,4,3,1]      # -1
[5,2,1]        # -1
[5,4,1]        # -1
[55,45,20,1]   # -10
[5,1]          # -4
[10,7,5,1]     # -2
[7]            # Invalid input -- assume size >= 2
</code>```

This is a code-golf; submit the shortest answer in your favorite language!

答:
VBA, 154

Takes in the input in column A starting in A1, outputs in C1.  Must be run with the last cell in A selected. Note that Excel auto-adds the spaces between terms in VBA, otherwise this could be golfed further.

```<code>Sub s
i = Selection.Row
r = "B1:B" + i-1
Range(r).FormulaArray = "MAX(A2:A$" + i + "-A1)"
Range(r).FillDown
Range("C1").Formula = "MAX(" + r + ")"
End Sub
</code>```

Title: Stock Time Machine

Body:
VBA, 154

Takes in the input in column A starting in A1, outputs in C1.  Must be run with the last cell in A selected. Note that Excel auto-adds the spaces between terms in VBA, otherwise this could be golfed further.

Sub s
i = Selection.Row
r = "B1:B" + i-1
Range(r).FormulaArray = "MAX(A2:A$" + i + "-A1)"
Range(r).FillDown
Range("C1").Formula = "MAX(" + r + ")"
End Sub


问:
Recognize mod-folds

Task

Define a mod-fold as a function of the form f(x) = x % a1 % a2 % … % ak, where the ai are positive integers and k ≥ 0. (Here, % is the left-associative modulo operator.)

Given a list of n integers y0, …, yn−1,  determine if there exists a mod-fold f so that each yi = f(i).

You may choose and fix any two outputs Y and N for your function/program. If there exists such an f, you must always return/print exactly Y; if not, you must always return/print exactly N. (These could be true/false, or 1/0, or false/true, etc.) Mention these in your answer.

The shortest submission in bytes wins.

Example

Define f(x) = x % 7 % 3. Its values start:

```<code>|   x  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ...
| f(x) | 0 | 1 | 2 | 0 | 1 | 2 | 0 | 0 | 1 | 2 | ...
</code>```

Thus, given 0 1 2 0 1 2 0 0 1 2 as input to our solution, we would print Y, as this f generates that sequence. However, given 0 1 0 1 2 as input, we would print N, as no f generates that sequence.

Test cases

The formulas given when the output is Y are just for reference; you must at no point print them.

```<code>0 1 2 3 4 5              Y    (x)
1                        N
0 0 0                    Y    (x%1)
0 1 2 0 1 2 0 0 1 2      Y    (x%7%3)
0 0 1                    N
0 1 2 3 4 5 6 0 0 1 2    Y    (x%8%7)
0 1 2 0 1 2 0 1 2 3      N
0 2 1 0 2 1 0 2 1        N
0 1 0 0 0 1 0 0 0 0 1    Y    (x%9%4%3%2)
</code>```

答:
Jelly, <s>19</s> <s>15</s> 14 bytes

```<code>LṗLUZ’1¦%/sLe@
</code>```

Returns 1 for truthy, 0 for falsy. Try it online!

The algorithm is O(nn), where n is the length of the list, making it too slow and memory-intensive for most of the test cases.

A modified version – which replaces the second L with a 5 – can be used to verify all test cases. Note that this modified version won't work for arbitrarily long lists.

How it works

```<code>LṗLUZ’1¦%/sLe@  Main link. Argument: A (array of integers)

L L             Yield the length l of A.
 ṗ              Take the l-th Cartesian power of [1, ..., l], i.e., construct
                all arrays of length l that consist of elements of [1, ..., l].
   U            Upend/reverse each array. This way, the first l arrays start
                with [1, ..., l], as do the next l arrays, etc.
    Z           Zip/transpose the array of arrays.
     ’1¦        Decrement the first array to map [1, ..., l] to [0, ..., l - 1].
        %/      Reduce the array's columns by modulus/residue.
          sL    Split the result into chunks of length l.
            e@  Verify if A belongs to the resulting array.
</code>```

Title: Recognize mod-folds

Body:
Jelly, <s>19</s> <s>15</s> 14 bytes

LṗLUZ’1¦%/sLe@

Returns 1 for truthy, 0 for falsy. Try it online!

The algorithm is O(nn), where n is the length of the list, making it too slow and memory-intensive for most of the test cases.

A modified version – which replaces the second L with a 5 – can be used to verify all test cases. Note that this modified version won't work for arbitrarily long lists.

How it works

LṗLUZ’1¦%/sLe@  Main link. Argument: A (array of integers)

L L             Yield the length l of A.
 ṗ              Take the l-th Cartesian power of [1, ..., l], i.e., construct
                all arrays of length l that consist of elements of [1, ..., l].
   U            Upend/reverse each array. This way, the first l arrays start
                with [1, ..., l], as do the next l arrays, etc.
    Z           Zip/transpose the array of arrays.
     ’1¦        Decrement the first array to map [1, ..., l] to [0, ..., l - 1].
        %/      Reduce the array's columns by modulus/residue.
          sL    Split the result into chunks of length l.
            e@  Verify if A belongs to the resulting array.


答:
JavaScript 210 bytes

```<code>(s,p)=>{var c=i=>!("aeiou".indexOf(s[i])+1),r=["z","gn","pn","ps","x"].some(t=>!s.indexOf(t))||(c(1)?s[0]=="s":s[0]=="i")?2:c(0)?1:0;return (p&1?(p&2?"le ":r&1?"i ":"gli "):!r?"l'":p&2?"la ":r&1?"il ":"lo ")+s}
</code>```

An anonymous function taking two parameters s and p where

```<code>s  is the input string
p  is plurality (bit 0, set=plural) and gender (bit 1, set=f) combined as
    0 = masculine singular
    1 = masculine plural
    2 = feminine singular
    3 = feminine plural
</code>```

After assigning the function to a variable and some unpacking), it can be tested as

```<code>var f=(s,p)=>{
    var c = i=>!("aeiou".indexOf(s[i])+1),
        r = ["z","gn","pn","ps","x"].some(t=>!s.indexOf(t))
             || ( c(1)? s[0]=="s":s[0]=="i" )
             ?   2 : c(0) ? 1 : 0;

     return (p&1?(p&2?"le ":r&1?"i ":"gli "):!r?"l'":p&2?"la ":r&1?"il ":"lo ")+s;
}

console.log("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
 f("macchina",2),
 f("zio",0),
 f("libri",1),
 f("ieri", 0),
 f("aquile",3),
 f("spagnoli",1),
 f("golf",0),
 f("ombra",2),
 f("impossibili",1))
</code>```

where

c is a function to test s for a consonant at position i.

r evaluates to 0 for starting with a vowel, 1 for starting with a type A consonant and 2 for starting with a type B consonant (tested in reverse order).

Bit bashing in the return statement puts it together.

Title: I programming puzzles, il code golf

Body:
Background

The Italian definite article (corresponding to English the) has seven different forms: l', il, lo, gli, i, la, le. Which one to use depends on three variables:

Gender: masculine / feminine.

Number: singular / plural.

Initial letter of the subsequent word: vowel / consonant type A / consonant type B.

Vowel is any of these: aeiou.

Consonant type B is any of these cases: s- followed by another consonant, z-, gn-, pn-, ps-, x-, i- followed by vowel (this i acts as a semivowel).

Consonant type A is a consonant that is not type B.

The table shows the article form to be used in each of the twelve combinations of the three above variables. Note that the l' form is attached to the following word with a single quote and without a space.

The challenge

Input a word and one or two strings, numbers or Booleans indicating gender and number. (The initial letters will have to be obtained from the input word).

The input word will be a sequence of lowercase ASCII letters. Accented vowels will be replaced by their non-accented versions (for example, realtà will be input as realta).

The gender and number inputs can be separate numbers, Booleans or strings, or a combined number of string (for example, 1 for masculine singular, 2 for feminine singular, etc).

Any reasonable format and separator can be used, as long as it is specified in the answer.

Output the word preceded by the appropriate form of the article, with space or single quote as needed. The output should also be lowercase. Trailing or leading blank space is allowed.

Code golf, shortest wins.

Test cases

In the following I use the input letters m, f to specify gender, and s, p for number (this is just one possible input format).

```<code>Input               Output              Comment

macchina f s        la macchina         Initial letter is cons. A
zio m s             lo zio              Initial letter is cons. B
libri m p           i libri             Initial letter is cons. A
ieri m s            lo ieri             Initial letter is cons. B
aquile f p          le aquile           Initial letter is vowel
spagnoli m p        gli spagnoli        Initial letter is cons. B
golf m s            il golf             Initial letter is cons. A
ombra f s           l'ombra             Initial letter is vowel
impossibili m p     gli impossibili     Initial letter is vowel
</code>```

Body:
JavaScript 210 bytes

(s,p)=>{var c=i=>!("aeiou".indexOf(s[i])+1),r=["z","gn","pn","ps","x"].some(t=>!s.indexOf(t))||(c(1)?s[0]=="s":s[0]=="i")?2:c(0)?1:0;return (p&1?(p&2?"le ":r&1?"i ":"gli "):!r?"l'":p&2?"la ":r&1?"il ":"lo ")+s}

An anonymous function taking two parameters s and p where

s  is the input string
p  is plurality (bit 0, set=plural) and gender (bit 1, set=f) combined as
    0 = masculine singular
    1 = masculine plural
    2 = feminine singular
    3 = feminine plural

After assigning the function to a variable and some unpacking), it can be tested as

var f=(s,p)=>{
    var c = i=>!("aeiou".indexOf(s[i])+1),
        r = ["z","gn","pn","ps","x"].some(t=>!s.indexOf(t))
             || ( c(1)? s[0]=="s":s[0]=="i" )
             ?   2 : c(0) ? 1 : 0;

     return (p&1?(p&2?"le ":r&1?"i ":"gli "):!r?"l'":p&2?"la ":r&1?"il ":"lo ")+s;
}

console.log("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
 f("macchina",2),
 f("zio",0),
 f("libri",1),
 f("ieri", 0),
 f("aquile",3),
 f("spagnoli",1),
 f("golf",0),
 f("ombra",2),
 f("impossibili",1))

where

c is a function to test s for a consonant at position i.

r evaluates to 0 for starting with a vowel, 1 for starting with a type A consonant and 2 for starting with a type B consonant (tested in reverse order).

Bit bashing in the return statement puts it together.


Title: Display a cribbage score in ASCII

Body:
Cribbage is an interesting game, because you need a specific board to score your game.
A cribbage board looks like this:

Notice how the first column is on the left as it goes up, then on the right as it goes down, then back on the left as it goes up again.

And here is what a poorly <s>drawn</s> rendered ASCII art of a cribbage board looks like:

```<code>                     * * *
   -----------      -------
  /     *     \     |*|*|*|
 /*     *     *\    |*|*|*|
/   *   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 * * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------
</code>```

Here is your challenge:

Step 1: Draw this ASCII art of a cribbage board. Trailing whitespace is OK, provided that there is no visible difference.

Step 2: Given three integers as input, display each peg in the correct hole. The pegs can be 0-indexed or 1-indexed. The inputs will be in [0-121] inclusive. You can take these inputs in any reasonable manner, for example, 3 separate inputs, an array, command line arguments, etc. Here's an example for the input (0, 37, 100) (1-indexed):

```<code>                     * * *
   -----------      -------
  /     *     \     |*|*|*|
 /*     *     *\    |*|*|*|
/   2   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|3|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 1 * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------
</code>```

Step 3: Output the whole thing.

Test IO:

Since each of these is pretty vertically tall, I will only include 2, but you can see more at this github gist.

```<code>#Input: (56, 56, 56)
#Output:
                     * * *
   -----------      -------
  /     *     \     |*|*|*|
 /*     *     *\    |*|*|*|
/   *   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |3|2|1|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 * * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------

#Input: (120, 89, 23)
#Output:
                     * * *
   -----------      -------
  /     *     \     |1|*|*|
 /*     *     *\    |*|*|*|
/   *   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|3|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|2|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 * * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------
</code>```

Standard loopholes apply, and the shortest answer in bytes wins!

Body:
Java, <s>1059</s> 1035 bytes

class C{static int[]i=new int[3];String d="-------",l=d+"----";<T>void p(String s,T...o){System.out.format(s+"\n",o);}C(){p("%26s\n%14s%13s\n  /%6s     \\%15s\n /%s%6s%6s\\%14s\n/%4s%4s%4s   \\%13s\n|%6s%4s     |%13s\n|%s%10s|%13s",o(121,0),l,d,s(38,0),t(120,0),s(37,0),s(38,1),s(39,0),t(119,0),s(37,1),s(38,2),s(39,1),t(118,0),s(37,2),s(39,2),t(117,0),o(36,0),o(40,2),t(116,0));for(int j=0;j<7;)g(j++*5);d();p(" %s    |%s%10s|\n%11s%6s%4s     |\n%11s%4s%4s%4s   /\n%12s%s%6s%6s/\n%13s%6s     /\n%24s",o(0,0),o(76,2),o(80,0),"|",s(77,0),s(79,0),"\\",s(77,1),s(78,0),s(79, 1),"\\",s(77,2),s(78,1),s(79,2),"\\",s(78,2),l);}String s(int r,int c){return r==i[c]?c+"":"*";}String t(int r,int d){return l.format("|%s|%s|%s|   ",s(r,d),s(r,1),s(r,2-d));}void r(int r){p(t(35-r,0)+t(41+r,2)+t(115-r,0));}void d(){p(d+"%10s%10s",d,d);}void g(int r){d();for(int j=0;j<5;)r(r+j++);}String o(int r,int d){return l.format("%s %s %s",s(r,d),s(r,1),s(r,2-d));}public static void main(String[]a){for(int j=0;j<3;)i[j]=Integer.decode(a[j++]);new C();}}

Ungolfed:

class Crib {

    static int[] input = new int[3];
    String divider = "-------", longDivider = divider + "----";

    <T> void p(String s, T...o) {
        System.out.format(s+"\n",o);
    }

    Crib() {

        p("%26s", troika(121,0));
        p("%14s%13s", longDivider, divider);
        p("  /%6s     \\%15s", star(38,0), trio(120,0));
        p(" /%s%6s%6s\\%14s", star(37,0), star(38,1), star(39,0), trio(119,0));
        p("/%4s%4s%4s   \\%13s", star(37,1), star(38,2), star(39,1), trio(118,0));
        p("|%6s%4s     |%13s", star(37,2), star(39,2), trio(117,0));
        p("|%s%10s|%13s", troika(36,0), troika(40,2), trio(116,0));
        for(int i = 0; i < 7;)
            group(i++*5);
        printDivider();
        p(" %s    |%s%10s|", troika(0,0), troika(76,2), troika(80,0));
        p("%11s%6s%4s     |", "|", star(77,0), star(79,0));
        p("%11s%4s%4s%4s   /", "\\", star(77,1), star(78,0), star(79, 1));
        p("%12s%s%6s%6s/", "\\", star(77,2), star(78,1), star(79,2));
        p("%13s%6s     /", "\\", star(78,2));
        p("%24s", longDivider);
    }

    String star(int row, int cell) {
        return row == input[cell] ? cell+"" : "*";
    }

    String trio(int row, int diff) {
        return longDivider.format("|%s|%s|%s|   ", star(row, diff), star(row, 1), star(row, 2-diff));
    }

    void printRow(int row) {
        p(trio(35-row, 0) + trio(41+row, 2) + trio(115-row, 0));
    }

    void printDivider() {
        p(divider + "%10s%10s", divider, divider);
    }

    void group(int row) {
        printDivider();
        for(int i = 0; i < 5;)
            printRow(row+i++);
    }

    String troika(int row, int diff) {
        return longDivider.format("%s %s %s", star(row, diff), star(row, 1), star(row, 2-diff));
    }

    public static void main(String[] args) {
        for(int i = 0; i < 3;)
            input[i] = Integer.decode(args[i++]);
        new Crib();
    }
}

Abuses formats (printfs) like mad, which is probably why it's not as small as it could be.


答:
JavaScript (ES6), <s>98</s> bytes

```<code>a=>a.every((n,i)=>n?n<(l+=p==i)&&n==p++:p=1,l=p=1)
</code>```

Saved 48 bytes by switching to @Feersum's discovery. Any given value n in the array is either zero, in which case the next prediction p is 1, or it equals the next prediction, in which case p is incremented. We also measure the length l of the initial sequence by comparing p to i, as n must always be less than l at all times.

Title: Recognize mod-folds

Body:
Task

Define a mod-fold as a function of the form f(x) = x % a1 % a2 % … % ak, where the ai are positive integers and k ≥ 0. (Here, % is the left-associative modulo operator.)

Given a list of n integers y0, …, yn−1,  determine if there exists a mod-fold f so that each yi = f(i).

You may choose and fix any two outputs Y and N for your function/program. If there exists such an f, you must always return/print exactly Y; if not, you must always return/print exactly N. (These could be true/false, or 1/0, or false/true, etc.) Mention these in your answer.

The shortest submission in bytes wins.

Example

Define f(x) = x % 7 % 3. Its values start:

```<code>|   x  | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ...
| f(x) | 0 | 1 | 2 | 0 | 1 | 2 | 0 | 0 | 1 | 2 | ...
</code>```

Thus, given 0 1 2 0 1 2 0 0 1 2 as input to our solution, we would print Y, as this f generates that sequence. However, given 0 1 0 1 2 as input, we would print N, as no f generates that sequence.

Test cases

The formulas given when the output is Y are just for reference; you must at no point print them.

```<code>0 1 2 3 4 5              Y    (x)
1                        N
0 0 0                    Y    (x%1)
0 1 2 0 1 2 0 0 1 2      Y    (x%7%3)
0 0 1                    N
0 1 2 3 4 5 6 0 0 1 2    Y    (x%8%7)
0 1 2 0 1 2 0 1 2 3      N
0 2 1 0 2 1 0 2 1        N
0 1 0 0 0 1 0 0 0 0 1    Y    (x%9%4%3%2)
</code>```

Body:
JavaScript (ES6), <s>98</s> bytes

a=>a.every((n,i)=>n?n<(l+=p==i)&&n==p++:p=1,l=p=1)

Saved 48 bytes by switching to @Feersum's discovery. Any given value n in the array is either zero, in which case the next prediction p is 1, or it equals the next prediction, in which case p is incremented. We also measure the length l of the initial sequence by comparing p to i, as n must always be less than l at all times.


答:
Pyth, 14 bytes

```<code>}Qm%M+RdUQy_Sl
</code>```

Returns True/False. Try it online: Demonstration or Test Suite

Explanation:

```<code>}Qm%M+RdUQy_SlQ   implicit Q (=input) at the end
             lQ   length of input list
            S     create the list [1, 2, ..., len]
           _      reverse => [len, ..., 2, 1]
          y       generate all subsets (these are all possible mod-folds)
  m               map each subset d to:
        UQ           take the range [0, 1, ..., len-1]
     +Rd             transform each number into a list by prepending it to d
                     e.g. if mod-fold = [7,3], than it creates:
                        [[0,7,3], [1,7,3], [2,7,3], [3,7,3], ...]
   %M                fold each list by the modulo operator
                  this gives all possible truthy sequences of length len
}Q                so checking if Q appears in the list returns True or False
</code>```

Pyth, 11 bytes

```<code>q%M.e+k_tx0
</code>```

Based on @ferrsum's idea. I actually thought about using the zero-indices for the subset generation, but didn't realize, that all zero-indices has to be the solution already.

Title: Recognize mod-folds

Body:
Pyth, 14 bytes

}Qm%M+RdUQy_Sl

Returns True/False. Try it online: Demonstration or Test Suite

Explanation:

}Qm%M+RdUQy_SlQ   implicit Q (=input) at the end
             lQ   length of input list
            S     create the list [1, 2, ..., len]
           _      reverse => [len, ..., 2, 1]
          y       generate all subsets (these are all possible mod-folds)
  m               map each subset d to:
        UQ           take the range [0, 1, ..., len-1]
     +Rd             transform each number into a list by prepending it to d
                     e.g. if mod-fold = [7,3], than it creates:
                        [[0,7,3], [1,7,3], [2,7,3], [3,7,3], ...]
   %M                fold each list by the modulo operator
                  this gives all possible truthy sequences of length len
}Q                so checking if Q appears in the list returns True or False

Pyth, 11 bytes

q%M.e+k_tx0

Based on @ferrsum's idea. I actually thought about using the zero-indices for the subset generation, but didn't realize, that all zero-indices has to be the solution already.