答:
Javascript, 32 bytes

Uppercase A:

```<code>String.fromCodePoint(33*2-(3-2))
</code>```

Title: The Letter A without A

Body:
Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of printing) is allowed.

Both the lowercase and uppercase versions of the letter "A" are acceptable (that is, unicode U+0061 or unicode U+0041. Other character encodings that aren't Unicode are allowed, but either way, the resulting output of your code must be the latin letter "A", and not any lookalikes or homoglyphs)

You must not use any of the below characters in your code, regardless of the character encoding that you pick:

"A", whether uppercase or lowercase.

"U", whether lowercase or uppercase.

X, whether uppercase or lowercase.

+

&

#

0

1

4

5

6

7

9

Cheating, loopholes, etc, are not allowed.

Since this is code-golf, the shortest solution, in bytes, that follows all the rules, is the winner.

Validity Checker

This Stack Snippet checks to make sure your code doesn't use the restricted characters. It might not work properly for some character encodings.

var t = prompt("Input your code.");

if (/[AaUuXx+&#0145679]/.test(t)) {
  alert("Contains a disallowed character!");
} else {
  alert("No disallowed characters");
}```
</div>
</div>
</p>

<p><em>This Stack Snippet that makes sure you don't have a disallowed character is also available on JSFiddle.</em></p>

<h3>Leaderboard</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var QUESTION_ID=90349,OVERRIDE_USER=58717;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="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});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;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>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;</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}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table></code>```

Body:
Javascript, 32 bytes

Uppercase A:

String.fromCodePoint(33*2-(3-2))


问:
Pokemon GO Evolution Cost Calculator
Tired of always wondering how many more Pokémon you need to catch to get those high-tier evolutions? Wonder no more! Now you will write a complete program or function to calculate it for you!

The Challenge:

As input, your program will receive a list of the costs in candy to evolve a Pokémon to the next tier. (This list may be separated by any delimiter of your choosing, or as function arguments). Your program will then return or print the number of Pokémon that must be caught, including the one that will be evolved, to evolve through all the tiers given.

How do you calculate this? Like so:

1. Add up all the candy costs: 12 + 50 = 62

2. Subtract 3 candies from the total, this being from the one Pokémon you keep for evolving: 62 - 3 = 59

3. Divide this number by 4 (3 for catching, 1 for giving it to the Professor), always taking the ceil() of the result: ceil(59/4) = 15

4. Finally, add 1 to this total to get the total number of Pokémon you must catch, 16!

Example Input -> Output:

```<code>[4] -> 2
[50] -> 13
[12, 50] -> 16
[25, 100] -> 32
[19, 35, 5, 200] -> 65
</code>```

Winning:

The app has already taken up most of the space on your phone, so your program needs to be as short as possible. The complete program or function with the smallest byte count will be accepted in two weeks! (with any ties being settled by the earliest submitted entry!)

答:
Brachylog, 5 bytes

```<code>+:4/+
</code>```

Try it online!

Explanation

A very original answer…

```<code>+        Sum
 :4/     Integer division by 4
    +    Increment
</code>```

ContentLicense: CC BY-SA 3.0

Title: Pokemon GO Evolution Cost Calculator

Body:
Brachylog, 5 bytes

+:4/+

Try it online!

Explanation

A very original answer…

+        Sum
 :4/     Integer division by 4
    +    Increment


问:
How can I get a repdigit?
In honor of how much rep I had several hours ago, when I first thought of this challenge:

Numbers like this that are made up of a single digit repeating are called repdigits. Repdigits are fun! Every body would be more happy if the amount of rep they had was a repdigit¹, but I am impatient, so you need to help me find out the fastest way to get to a repdigit.

Here is your challenge:

Given a positive integers representing reputation, output the minimum amount of rep they need to gain to get to a repdigit. For example, at the time of writing this challenge, user Martin Ender had 102,856 rep. The nearest rep-digit is 111,111, so he would need to gain: 8255 rep to be at a repdigit.

Since people dislike losing rep, we will only consider non-negative changes. This means that, for example, if someone is at 12 rep, rather than losing 1 rep, the solution is to gain 10 rep. This allows '0' to be a valid output, since anyone who has 111 rep is already at a repdigit.

Input and output can be in any reasonable format, and since it is impossible to have less than 1 rep on any Stack Exchange site, you can assume no inputs will be less than 1.

One cornercase to note:

If a user has less than 10 rep, they are already at a repdigit, and so they also need '0'.

Test IO:

```<code>#Input      #Ouput
8           0
100         11
113         109
87654321    1234567
42          2
20000       2222
11132       11090
</code>```

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

答:
Python 2, 52 bytes

```<code>a=b=input()
while len(set(str(a)))!=1:a+=1
print a-b
</code>```

Python 2 has several tricks that make this shorter. For example, input is numeric, so we don't need to cast to int. (-5 bytes) We also don't need to put parenthesis around the a-b (-1 byte)

Use this script to verify all test cases:

```<code>def f(i):
    a=b=i
    while len(set(str(a)))!=1:a+=1
    return a-b

inputs = [8, 100, 113, 87654321, 42, 20000, 11132]
outputs = [0, 11, 109, 1234567, 2, 2222, 11090]

for i in range(len(inputs)):
    print(f(inputs[i]) == outputs[i])
</code>```

You may also try it online!

Title: How can I get a repdigit?

Body:
Python 2, 52 bytes

a=b=input()
while len(set(str(a)))!=1:a+=1
print a-b

Python 2 has several tricks that make this shorter. For example, input is numeric, so we don't need to cast to int. (-5 bytes) We also don't need to put parenthesis around the a-b (-1 byte)

Use this script to verify all test cases:

def f(i):
    a=b=i
    while len(set(str(a)))!=1:a+=1
    return a-b

inputs = [8, 100, 113, 87654321, 42, 20000, 11132]
outputs = [0, 11, 109, 1234567, 2, 2222, 11090]

for i in range(len(inputs)):
    print(f(inputs[i]) == outputs[i])

You may also try it online!


答:
Jelly, 6 bytes

```<code>DE$1#_
</code>```

Output is a singleton array.

Try it online! or verify most test cases. Test case 87654321 is too slow for TIO.

How it works

```<code>DE$1#_  Main link. Argument: n

   1#   Call the link to the left with argument k = n, n + 1, n + 2, etc. until one
        match is found, then return the matching k.
  $       Combine the two links to the left into a monadic chain.
D           Convert k to base 10.
 E          Test if all decimal digits are equal.
     _  Subtract n from the result.
</code>```

Title: How can I get a repdigit?

Body:
In honor of how much rep I had several hours ago, when I first thought of this challenge:

Numbers like this that are made up of a single digit repeating are called repdigits. Repdigits are fun! Every body would be more happy if the amount of rep they had was a repdigit¹, but I am impatient, so you need to help me find out the fastest way to get to a repdigit.

Here is your challenge:

Given a positive integers representing reputation, output the minimum amount of rep they need to gain to get to a repdigit. For example, at the time of writing this challenge, user Martin Ender had 102,856 rep. The nearest rep-digit is 111,111, so he would need to gain: 8255 rep to be at a repdigit.

Since people dislike losing rep, we will only consider non-negative changes. This means that, for example, if someone is at 12 rep, rather than losing 1 rep, the solution is to gain 10 rep. This allows '0' to be a valid output, since anyone who has 111 rep is already at a repdigit.

Input and output can be in any reasonable format, and since it is impossible to have less than 1 rep on any Stack Exchange site, you can assume no inputs will be less than 1.

One cornercase to note:

If a user has less than 10 rep, they are already at a repdigit, and so they also need '0'.

Test IO:

```<code>#Input      #Ouput
8           0
100         11
113         109
87654321    1234567
42          2
20000       2222
11132       11090
</code>```

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

Body:
Jelly, 6 bytes

DE$1#_

Output is a singleton array.

Try it online! or verify most test cases. Test case 87654321 is too slow for TIO.

How it works

DE$1#_  Main link. Argument: n

   1#   Call the link to the left with argument k = n, n + 1, n + 2, etc. until one
        match is found, then return the matching k.
  $       Combine the two links to the left into a monadic chain.
D           Convert k to base 10.
 E          Test if all decimal digits are equal.
     _  Subtract n from the result.


答:
Brachylog, 9 bytes

```<code>:.#++#==,
</code>```

Try it online!

This is pretty efficent as it makes use of constraints arithmetic.

Explanation

```<code>:.            The list [Input, Output].
  #+          Both elements must be positive or zero.
    +         The sum of those two elements…
     #=       …must result in an integer where all digits are the same.
       =,     Assign a value that matches those constraints.
</code>```

Title: How can I get a repdigit?

Body:
Brachylog, 9 bytes

:.#++#==,

Try it online!

This is pretty efficent as it makes use of constraints arithmetic.

Explanation

:.            The list [Input, Output].
  #+          Both elements must be positive or zero.
    +         The sum of those two elements…
     #=       …must result in an integer where all digits are the same.
       =,     Assign a value that matches those constraints.


答:
Perl 6, 23 bytes

```<code>{($_...{[==] .comb})-1}
</code>```

A lambda that takes the input number as argument, and returns the result.

Explanation:

Uses the ... sequence operator to increment the input number until it reaches a repdigit (tested by splitting its string representation into characters and seeing if they're all equal).

Subtracts one from the length of the sequence.

Title: How can I get a repdigit?

Body:
Perl 6, 23 bytes

{($_...{[==] .comb})-1}

A lambda that takes the input number as argument, and returns the result.

Explanation:

Uses the ... sequence operator to increment the input number until it reaches a repdigit (tested by splitting its string representation into characters and seeing if they're all equal).

Subtracts one from the length of the sequence.


答:
Pyth, <s>9</s> <s>8</s> 7 bytes

1 byte thanks to @FryAmTheEggman.

```<code>-f@F`TQ
</code>```

Try it online.

Very inefficient, loops through all numbers from the input to the next repdigit.

Title: How can I get a repdigit?

Body:
Pyth, <s>9</s> <s>8</s> 7 bytes

1 byte thanks to @FryAmTheEggman.

-f@F`TQ

Try it online.

Very inefficient, loops through all numbers from the input to the next repdigit.


答:
Python 2, 37 bytes

f=lambda n:1-len(set(`n`))and-~f(n+1)
```

Test it on Ideone. Note that this approach is too inefficient for test case 87654321.

How it works

If n is already a repdigit, 1-len(set(`n`)) will return 0 since the length of the set of n's digits in base 10 will be 1. In this case, f returns 0.

If n is not a repdigit, f(n+1) recursively calls f with the next possible value of n. -~ increments the return value of f (0 when a repdigit is found) by 1 each time f is called recursively, so the final return value equals the number of times f has been called, i.e., the number of times n had to be incremented to get a repdigit.

Title: How can I get a repdigit?

Body:
Python 2, 37 bytes

f=lambda n:1-len(set(`n`))and-~f(n+1)

Test it on Ideone. Note that this approach is too inefficient for test case 87654321.

How it works

If n is already a repdigit, 1-len(set(`n`)) will return 0 since the length of the set of n's digits in base 10 will be 1. In this case, f returns 0.

If n is not a repdigit, f(n+1) recursively calls f with the next possible value of n. -~ increments the return value of f (0 when a repdigit is found) by 1 each time f is called recursively, so the final return value equals the number of times f has been called, i.e., the number of times n had to be incremented to get a repdigit.


答:
Haskell, 39 bytes

```<code>until(((==).head>>=all).show)(+1)>>=(-)
</code>```

Try it online

Title: How can I get a repdigit?

Body:
Haskell, 39 bytes

until(((==).head>>=all).show)(+1)>>=(-)

Try it online


问:
The Luhn algorithm for verifying credit card numbers, etc

Challenge

Write the shortest program or function to calculate the Luhn Algorithm for verifying (credit card) numbers.

Luhn algorithm explained

From RosettaCode, this algorithm for the purposes of this challenge is specified as such, with the example input of 49927398716:

```<code>Reverse the digits, make an array:
    6, 1, 7, 8, 9, 3, 7, 2, 9, 9, 4
Double the numbers in odd indexes:
    6, 2, 7, 16, 9, 6, 7, 4, 9, 18, 4
Sum the digits in each number:
    6, 2, 7, 7, 9, 6, 7, 4, 9, 9, 4
Sum all of the numbers:
    6 + 2 + 7 + 7 + 9 + 6 + 7 + 4 + 9 + 9 + 4 = 70
If the sum modulo 10 is 0, then the number is valid:
    70 % 10 = 0 => valid
</code>```

IO Rules

Input: A string or number (your choice), in your language's input/output format of choice

Output: A truthy or falsy value, respectively, indicating whether or not the input is valid according to the test above.

Notes / Tips

Try not to accidentally post your own credit card or account numbers, if you use them to test :)

If the input is invalid and impossible to process with the specified algorithm (i.e, too short to work with), you can do whatever you want, including blow up my computer.

However, the previous bullet does not mean that your language can do whatever it wants with Numbers that are too large for it to handle. If your language isn't capable of handling a test case, then consider taking a string as input.

Examples

The following examples were validated with this Python script; if you think one is wrong or have a question, just ping @cat.

```<code>49927398716      True
49927398717      False
1234567812345670 True
1234567812345678 False
79927398710      False
79927398711      False
79927398712      False
79927398713      True
79927398714      False
79927398715      False
79927398716      False
79927398717      False
79927398718      False
79927398719      False
374652346956782346957823694857692364857368475368 True
374652346956782346957823694857692364857387456834 False
8 False **
0 True  **
</code>```

** according to the Python implementation, but you may do anything because these are too short to be eligible by a strict adherence to the specification.

If any of the above invalidates existing answers (though I believe that should not be possible), then those answers are stil valid. However, new answers, in order to be valid, should follow the specification above.

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Windows PowerShell, 82

filter f{!((''+($_[($_.length)..0]|%{+"$_"*($i++%2+1)})-replace'.','+$&'|iex)%10)}

History:

2011-02-13 03:08 (84) First attempt.

2011-02-13 12:13 (82) I don't need to join, as spaces do not hurt. +1 + +3 can still be evaluated.

ContentLicense: CC BY-SA 2.5


答:
Python 2, <s>41</s> 40 bytes

def f(n):r=10**len(`n`)/9;print-n/r*-r-n
```

Not the shortest approach, but very efficient. Test it on Ideone.

How it works

For input 10**len(`n`) rounds n up to the nearest power of 10. Afterwards, we divide the result by 9. This returns the repdigit 1…1 that has as many digits as n. We save the result in r. For example, if n = 87654321, then r = 11111111.

The desired repdigit will be a multiple or r. To decide which, we perform ceiling division of n by r. Since Python 2's division operator / floors, this can be achieved with -n/r, which will yield the correct absolute value, with negative sign. For example, if n = 87654321, this will return -8.

Finally, we multiply the computed quotient by -r to repeat the quotient once for each digit in n. For example, if n = 87654321, this returns 88888888, which is the desired repdigit.

Finally, to calculate the required increment, we subtract n from the previous result. For our example n = 87654321, this returns 1234567, as desired.

Title: How can I get a repdigit?

Body:
Python 2, <s>41</s> 40 bytes

def f(n):r=10**len(`n`)/9;print-n/r*-r-n

Not the shortest approach, but very efficient. Test it on Ideone.

How it works

For input 10**len(`n`) rounds n up to the nearest power of 10. Afterwards, we divide the result by 9. This returns the repdigit 1…1 that has as many digits as n. We save the result in r. For example, if n = 87654321, then r = 11111111.

The desired repdigit will be a multiple or r. To decide which, we perform ceiling division of n by r. Since Python 2's division operator / floors, this can be achieved with -n/r, which will yield the correct absolute value, with negative sign. For example, if n = 87654321, this will return -8.

Finally, we multiply the computed quotient by -r to repeat the quotient once for each digit in n. For example, if n = 87654321, this returns 88888888, which is the desired repdigit.

Finally, to calculate the required increment, we subtract n from the previous result. For our example n = 87654321, this returns 1234567, as desired.


答:
05AB1E, <s>10</s> 6 bytes

```<code>∞.Δ+Ë
</code>```

Try it online!

Explanation

```<code>∞<      # from the infinite list of non-negative integers
  .Δ    # find the first number where
     Ë  # all digits are equal
    +   # after adding the input
</code>```

Title: How can I get a repdigit?

Body:
05AB1E, <s>10</s> 6 bytes

∞.Δ+Ë

Try it online!

Explanation

∞<      # from the infinite list of non-negative integers
  .Δ    # find the first number where
     Ë  # all digits are equal
    +   # after adding the input

ContentLicense: CC BY-SA 4.0


答:
Pyke, <s>13</s> 11 bytes

```<code>o+`}ltIr)ot
</code>```

Try it here!

```<code>            - o = 0
o+          -     o++ + input
  `         -    str(^)
   }        -   deduplicate(^)
    lt      -  len(^)-1
      I )   - if ^:
       r    -  goto_start()
         ot - o++ -1
</code>```

Title: How can I get a repdigit?

Body:
Pyke, <s>13</s> 11 bytes

o+`}ltIr)ot

Try it here!

            - o = 0
o+          -     o++ + input
  `         -    str(^)
   }        -   deduplicate(^)
    lt      -  len(^)-1
      I )   - if ^:
       r    -  goto_start()
         ot - o++ -1


答:
Java 7, <s>116</s> 76 bytes

```<code>int c(int i){int r=(int)Math.pow(10,(i+"").length())/9;return(-i/r-1)*-r-i;}
</code>```

Used @Dennis' amazing approach to lower the byte-count by a whopping 40 bytes.

Ungolfed & test cases:

Try it here.

```<code>class Main{
  static int c(int i){
    int r = (int)Math.pow(10, (i+"").length()) / 9;
    return (-i / r - 1) * -r - i;
  }

  public static void main(String[] a){
    System.out.println(c(8));
    System.out.println(c(100));
    System.out.println(c(113));
    System.out.println(c(87654321));
    System.out.println(c(42));
    System.out.println(c(20000));
    System.out.println(c(11132));
  }
}
</code>```

Output:

```<code>0
11
109
1234567
2
2222
11090
</code>```

Title: How can I get a repdigit?

Body:
Java 7, <s>116</s> 76 bytes

int c(int i){int r=(int)Math.pow(10,(i+"").length())/9;return(-i/r-1)*-r-i;}

Used @Dennis' amazing approach to lower the byte-count by a whopping 40 bytes.

Ungolfed & test cases:

Try it here.

class Main{
  static int c(int i){
    int r = (int)Math.pow(10, (i+"").length()) / 9;
    return (-i / r - 1) * -r - i;
  }

  public static void main(String[] a){
    System.out.println(c(8));
    System.out.println(c(100));
    System.out.println(c(113));
    System.out.println(c(87654321));
    System.out.println(c(42));
    System.out.println(c(20000));
    System.out.println(c(11132));
  }
}

Output:

0
11
109
1234567
2
2222
11090


问:
Create an unlimited counterstring
A counterstring is some sort of self-describing test data that is used in software testing. Not sure it was actually invented by James Bach, but I know it from there.

The idea is as follows: the test data contains many asterisk (*). The number in front of the asterisk tells you how long the test data is at that point. If you need to know a position in the test data that is not an asterisk, find the last asterisk, look at the number before and add the number of digits that follow.

The sequence starts like this:

```<code>2*4*6*8*11*14*17*20*23*
             ^
</code>```

As you can see, the marked asterisk is at position 14.

If a file happens to be truncated as follows

```<code>[...]2045*20
</code>```

then you can derive that there is a limit of 2047 characters somewhere (2045 where the asterisk is plus 2 for 2 and 0).

It's your task to create the shortest (this is code-golf) program that outputs (std::out or file or whatever) an arbitrary long test string of that format. The length in characters is given as argument. The program shall support up to 2 GB test data (input value 2147483647 characters).

"Dangerous" positions in the 2 GB file:

```<code>8*11*
98*102*
998*1003*
9998*10004*
99998*100005*
999995*1000003*
9999995*10000004*
99999995*100000005*
999999995*1000000006*
</code>```

This should answer @Leaky Nun's question if there is a decision to make between 995*999* and 995*1000* or similar: no.

The end of the 2 GB file with input value 2147483647 is:

```<code>2147483640*2147483
</code>```

答:
Pyth, <s>25</s> <s>17</s> <s>15</s> 14 bytes

```<code><uu++GlN\*k)Qk
</code>```

Try it online.

Length is taken via STDIN.

Title: Create an unlimited counterstring

Body:
Pyth, <s>25</s> <s>17</s> <s>15</s> 14 bytes

<uu++GlN\*k)Qk

Try it online.

Length is taken via STDIN.


答:
Pyke, 4 bytes

```<code>seeh
</code>```

Try it here!

```<code>((sum(input)/2)/2)+1
</code>```

Title: Pokemon GO Evolution Cost Calculator

Body:
Tired of always wondering how many more Pokémon you need to catch to get those high-tier evolutions? Wonder no more! Now you will write a complete program or function to calculate it for you!

The Challenge:

As input, your program will receive a list of the costs in candy to evolve a Pokémon to the next tier. (This list may be separated by any delimiter of your choosing, or as function arguments). Your program will then return or print the number of Pokémon that must be caught, including the one that will be evolved, to evolve through all the tiers given.

How do you calculate this? Like so:

1. Add up all the candy costs: 12 + 50 = 62

2. Subtract 3 candies from the total, this being from the one Pokémon you keep for evolving: 62 - 3 = 59

3. Divide this number by 4 (3 for catching, 1 for giving it to the Professor), always taking the ceil() of the result: ceil(59/4) = 15

4. Finally, add 1 to this total to get the total number of Pokémon you must catch, 16!

Example Input -> Output:

```<code>[4] -> 2
[50] -> 13
[12, 50] -> 16
[25, 100] -> 32
[19, 35, 5, 200] -> 65
</code>```

Winning:

The app has already taken up most of the space on your phone, so your program needs to be as short as possible. The complete program or function with the smallest byte count will be accepted in two weeks! (with any ties being settled by the earliest submitted entry!)

Body:
Pyke, 4 bytes

seeh

Try it here!

((sum(input)/2)/2)+1


问:
Find the minimum and maximum integers in an array, without using builtins

Challenge

Given an array of integers, received from stdin, function arguments, program arguments, or some other method:

Output only the minimum and maximum numbers in the array, through a return value, stdout, or other fitting methods.

Example session

```<code>> minmax( {0, 15, 2, 3, 7, 18, -2, 9, 6, -5, 3, 8, 9, -14} )
-14 18
</code>```

Reference implementation

```<code>// C++14

void minmax(std::vector<int> v) {
    int min = v[0]; int max = v[0];
    for(auto it : v) {
        if (*it < min)
            min = *it;
        if (*it > max)
            max = *it;
    }
    std::cout << min << ' ' << max << std::endl;
}
</code>```

Rules

You may not use a built-in function to calculate the values.

Standard loopholes disallowed.

Creative implementations encouraged.

This is code-golf, shortest answer wins but will not be selected.

Clarifications

If the array contains 1 element you need to output it twice.

If the minimum and maximum values are the same, you need to output them both.

答:
Pyke, <s>5</s> 4 bytes

```<code>S'he
</code>```

Try it here!

```<code>S    - sorted(input)
 'he - ^[0], ^[-1]
</code>```

Body:
Pyke, <s>5</s> 4 bytes

S'he

Try it here!

S    - sorted(input)
 'he - ^[0], ^[-1]


答:
Python 2, 34 bytes

```<code>x=sorted(input());print x[0],x[-1]
</code>```

Title: Find the minimum and maximum integers in an array, without using builtins

Body:
Challenge

Given an array of integers, received from stdin, function arguments, program arguments, or some other method:

Output only the minimum and maximum numbers in the array, through a return value, stdout, or other fitting methods.

Example session

```<code>> minmax( {0, 15, 2, 3, 7, 18, -2, 9, 6, -5, 3, 8, 9, -14} )
-14 18
</code>```

Reference implementation

```<code>// C++14

void minmax(std::vector<int> v) {
    int min = v[0]; int max = v[0];
    for(auto it : v) {
        if (*it < min)
            min = *it;
        if (*it > max)
            max = *it;
    }
    std::cout << min << ' ' << max << std::endl;
}
</code>```

Rules

You may not use a built-in function to calculate the values.

Standard loopholes disallowed.

Creative implementations encouraged.

This is code-golf, shortest answer wins but will not be selected.

Clarifications

If the array contains 1 element you need to output it twice.

If the minimum and maximum values are the same, you need to output them both.

Body:
Python 2, 34 bytes

x=sorted(input());print x[0],x[-1]


答:
Pyth, 5 bytes

```<code>h/sQ4
</code>```

Try it here!

Sum input with sQ, divide by 4 with /4 and finally increment h.

Title: Pokemon GO Evolution Cost Calculator

Body:
Pyth, 5 bytes

h/sQ4

Try it here!

Sum input with sQ, divide by 4 with /4 and finally increment h.


答:
CJam, 7 bytes

```<code>{:+4/)}
</code>```

Try it here!

Defines an unnamed block that expects the input on the stack and leaves the result there.

:+ sums the list, 4/ divides the result by 4 and ) increments that.

Title: Pokemon GO Evolution Cost Calculator

Body:
CJam, 7 bytes

{:+4/)}

Try it here!

Defines an unnamed block that expects the input on the stack and leaves the result there.

:+ sums the list, 4/ divides the result by 4 and ) increments that.


问:
Secret Santa Challenge

Possible Duplicate:

  Holiday Gift Exchange

Background:
Secret Santa is a Western Christmas tradition in which members of a group or community are randomly assigned a person to whom they anonymously give a gift.

http://en.wikipedia.org/wiki/Secret_Santa

Ok, me and my work colleges did this today during our lunch hour - we made a secret algorithm santa pick random gifters and receivers.

Think of this question as a Christmas Programming Challenge to see who can come up with some of the most elegant solutions for this problem.

Input:
The input should be an array ['Oliver', 'Paul', 'Rowan', 'Darren', 'Nick', 'Atif', 'Kevin']

Output
A representation of something similar to key value pairs for the gifter and receiver. e.g.

```<code>Oliver -> Darren,
Paul -> Nick,
Rowan -> Kevin
Kevin -> Atif,
Darren -> Paul,
Nick -> Oliver,
Atif -> Rowan
</code>```

Deadline: 15th December (for those late christmas shoppers)

Remember: you cannot have a person choosing themselves and the program must not spiral off into an infinite loop when gifter == receiver when there is only one person left.

Rules:

Must not have duplicates

Must be random (we all have different views on what is random - but you get my gist)

No Language constraints

Have fun

Here is mine (not golfed) in ruby:

```<code>require 'pp'

def move(array, from, to)
  array.insert(to, array.delete_at(from))
end

gifters = ['Oliver', 'Paul', 'Rowan', 'Darren', 'Nick', 'Atif', 'Kevin'].shuffle!
recievers = gifters.dup

move recievers, recievers.count - 1, 0

pp Hash[gifters.zip recievers]
</code>```

which spits out:

```<code>{"Nick"=>"Darren",
 "Paul"=>"Nick",
 "Kevin"=>"Paul",
 "Rowan"=>"Kevin",
 "Atif"=>"Rowan",
 "Oliver"=>"Atif",
 "Darren"=>"Oliver"}
</code>```

答:
Ruby - 161 42 chars

#!/usr/bin/env ruby
require 'csv'

gifters = CSV.read(ARGV[0]).first

receivers = gifters.shuffle!.dup
puts Hash[gifters.zip(receivers << receivers.shift)]
```

<p>Usage</p>

```./secret_santa path_to_some_csv
=> {"Edward"=>"Alan", "Alan"=>"Charlie", "Charlie"=>"Dave", "Dave"=>"Brett", "Brett"=>"Edward"}
```

<h2>Update</h2>

```r=ARGV.shuffle!.dup;p ARGV.zip(r<<r.shift)
```

Title: Secret Santa Challenge

Body:
Ruby - 161 42 chars

#!/usr/bin/env ruby
require 'csv'

gifters = CSV.read(ARGV[0]).first

receivers = gifters.shuffle!.dup
puts Hash[gifters.zip(receivers << receivers.shift)]

Usage

./secret_santa path_to_some_csv
=> {"Edward"=>"Alan", "Alan"=>"Charlie", "Charlie"=>"Dave", "Dave"=>"Brett", "Brett"=>"Edward"}

Update

r=ARGV.shuffle!.dup;p ARGV.zip(r<<r.shift)


答:
APL (Dyalog), <s>11</s> <s>10</s> 5 bytes

-5 thanks to Erik the Outgolfer.

According to the original poster, using a function that picks the largest of exactly two elements (in contrast to the largest of a whole array) [is] allowed. Therefore, the obvious solution is:

⌊/,⌈/
```
<p><code>⌊/</code> minimum-reduction</p>
<p><code>,</code> followed by</p>
<p><code>⌈/</code> maximum-reduction</p>
<hr />
<p>More in the spirit of the challenge:</p>
<pre class="lang-apl prettyprint-override"><code>(⊃,⊢/)⍋⊃¨⊂
</code>```

(

 ⊃ first

 , followed by

 ⊢/ the last (lit. right-reduction)

) of

⍋ the indices of the elements in ascending order

⊃¨ each picks from

⊂ the entire argument

TryAPL online!

Body:
APL (Dyalog), <s>11</s> <s>10</s> 5 bytes

-5 thanks to Erik the Outgolfer.

According to the original poster, using a function that picks the largest of exactly two elements (in contrast to the largest of a whole array) [is] allowed. Therefore, the obvious solution is:

⌊/,⌈/

⌊/ minimum-reduction

, followed by

⌈/ maximum-reduction

More in the spirit of the challenge:

(⊃,⊢/)⍋⊃¨⊂

(

 ⊃ first

 , followed by

 ⊢/ the last (lit. right-reduction)

) of

⍋ the indices of the elements in ascending order

⊃¨ each picks from

⊂ the entire argument

TryAPL online!


答:
Actually, 15 bytes

```<code>;D;WXu;$╔l1<WX-
</code>```

Try it online!

Explanation:

```<code>;D;WXu;$╔l1<WX-
;                dupe
 D;              decrement, dupe
   WXu;$╔l1<W    while top of stack is truthy:
    X              discard
     u             increment
      ;            dupe
       $╔l1<       1 if len(str(TOS)) > 1 else 0 (check if the string representation of the TOS contains only one unique digit)
                 after the loop, the stack will be [1 repdigit input]
             X   discard
              -  subtract input from repdigit
</code>```

Title: How can I get a repdigit?

Body:
In honor of how much rep I had several hours ago, when I first thought of this challenge:

Numbers like this that are made up of a single digit repeating are called repdigits. Repdigits are fun! Every body would be more happy if the amount of rep they had was a repdigit¹, but I am impatient, so you need to help me find out the fastest way to get to a repdigit.

Here is your challenge:

Given a positive integers representing reputation, output the minimum amount of rep they need to gain to get to a repdigit. For example, at the time of writing this challenge, user Martin Ender had 102,856 rep. The nearest rep-digit is 111,111, so he would need to gain: 8255 rep to be at a repdigit.

Since people dislike losing rep, we will only consider non-negative changes. This means that, for example, if someone is at 12 rep, rather than losing 1 rep, the solution is to gain 10 rep. This allows '0' to be a valid output, since anyone who has 111 rep is already at a repdigit.

Input and output can be in any reasonable format, and since it is impossible to have less than 1 rep on any Stack Exchange site, you can assume no inputs will be less than 1.

One cornercase to note:

If a user has less than 10 rep, they are already at a repdigit, and so they also need '0'.

Test IO:

```<code>#Input      #Ouput
8           0
100         11
113         109
87654321    1234567
42          2
20000       2222
11132       11090
</code>```

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

Body:
Actually, 15 bytes

;D;WXu;$╔l1<WX-

Try it online!

Explanation:

;D;WXu;$╔l1<WX-
;                dupe
 D;              decrement, dupe
   WXu;$╔l1<W    while top of stack is truthy:
    X              discard
     u             increment
      ;            dupe
       $╔l1<       1 if len(str(TOS)) > 1 else 0 (check if the string representation of the TOS contains only one unique digit)
                 after the loop, the stack will be [1 repdigit input]
             X   discard
              -  subtract input from repdigit


问:
Text animation format Code Golf
Working with old files from DOS, I found an ancient text animation format, that specify how much time each frame must be shown in the screen. It's very simple:

F1W5F2W3

This example above indicates that Frame 1 must be shown for 5 units of time, and frame 2 for 3 units more. Now I want to convert it to:

1, 1, 1, 1, 1, 2, 2, 2

In the converted example below, frame 1 is repeated 5 times, and frame 2 three times.

Rules: The only allowed letters are F and W (and the lowercase counterparts, f and w). Numbers can go up to 255. Total input String with no more than 255 chars.

Other examples:

Input: F10W3F11W3F10W3F12W3

Output: 10, 10, 10, 11, 11, 11, 10, 10, 10, 12, 12, 12

Input: f1w0f2w10

Output: 2, 2, 2, 2, 2, 2, 2, 2, 2, 2

Short code wins.

Edited - Accepted formats:
Any answer containing the output and ignoring spaces. Ex: 1, 1, 2, 2 or [1,1,2,2] or (1,1,2,2). But NOT 1 1 2 2 or [1; 1; 2; 2] or [1 1 2 2].

答:
Clojure, 86 bytes

```<code>(fn[a](mapcat #(repeat(read-string(last %))(first %))(partition 2 (re-seq #"\d+" a))))
</code>```

Depending on requirements, I could also drop "cat" from "mapcat".

Title: Text animation format Code Golf

Body:
Clojure, 86 bytes

(fn[a](mapcat #(repeat(read-string(last %))(first %))(partition 2 (re-seq #"\d+" a))))

Depending on requirements, I could also drop "cat" from "mapcat".


答:
JavaScript (ES6), 42 bytes

```<code>f=(n,p=1)=>n<p?-~(n*9/p)*~-p/9-n:f(n,p*10)
</code>```

Explanation: Recursively computes p as the next power of 10 after n. The digit to be repeated is then computed as 1+floor(9n/p), and the repunit is simply (p-1)/9, from which the result follows.

Title: How can I get a repdigit?

Body:
JavaScript (ES6), 42 bytes

f=(n,p=1)=>n<p?-~(n*9/p)*~-p/9-n:f(n,p*10)

Explanation: Recursively computes p as the next power of 10 after n. The digit to be repeated is then computed as 1+floor(9n/p), and the repunit is simply (p-1)/9, from which the result follows.


答:
R, 22 bytes

```<code>floor(sum(scan())/4+1)
</code>```

Title: Pokemon GO Evolution Cost Calculator

Body:
R, 22 bytes

floor(sum(scan())/4+1)


答:
R, <s>102</s> <s>98</s> 91 bytes

```<code>a=scan(,'');i=0;while(length(unique(strsplit(a,"")[[1]]))!=1){a=paste(strtoi(a)+1);i=i+1};i
</code>```

Ungolfed :

```<code>a=scan(,'') #Asks for input
i=0         #Initialize i to 0, surprisingly

while(length(unique(strsplit(a,"")[[1]]))!=1)
    #Splits the input into its digits,
    #compute the length of the vector created by the function `unique`, which gives all the digits once.
    #as long as the this length is different from one :
{
a=paste(strtoi(a)+1) #Increases by one the value of the input (while messing around with its format)
i=i+1                           #Increases by one the value of the counter
}

i #Outputs the counter
</code>```

Messing around with the format (<s>as.numeric and as.character</s>) adds some bytes, but R is not really flexible !

Title: How can I get a repdigit?

Body:
R, <s>102</s> <s>98</s> 91 bytes

a=scan(,'');i=0;while(length(unique(strsplit(a,"")[[1]]))!=1){a=paste(strtoi(a)+1);i=i+1};i

Ungolfed :

a=scan(,'') #Asks for input
i=0         #Initialize i to 0, surprisingly

while(length(unique(strsplit(a,"")[[1]]))!=1)
    #Splits the input into its digits,
    #compute the length of the vector created by the function `unique`, which gives all the digits once.
    #as long as the this length is different from one :
{
a=paste(strtoi(a)+1) #Increases by one the value of the input (while messing around with its format)
i=i+1                           #Increases by one the value of the counter
}

i #Outputs the counter

Messing around with the format (<s>as.numeric and as.character</s>) adds some bytes, but R is not really flexible !


问:
Exponentially Slimy Programming: Stacking Minecraft Slimes
Slimes are cube shaped enemies in Minecraft that break into multiple smaller versions of themselves when killed. For the purposes of this challenge we'll depict them as an 8×8 pixel image with 3 colors:

 ← True 8×8 version.

The precise RGB colors are:

0, 0, 0 for the eyes and mouth

110, 170, 90 for the central, darker green

116, 196, 96 for the outer, lighter green

Challenge

Write a program or function that takes in a positive integer N and outputs an image of N sizes of slimes packed into a rectangle. Going from left to right, the image should follow the pattern of having:

A stack of 2(N-1) 8×8 slimes.

A stack of 2(N-2) 16×16 slimes.

A stack of 2(N-3) 32×32 slimes.

And so on until the stack only contains one slime.

The slime images larger than the 8×8 version () are generated by nearest-neighbor upsampling (i.e. just doubling all the pixels). Note that you must use the exact slime design and colors given here.

The final image will contain 2N-1 slimes and be 2(N+3)-8 pixels wide and 2(N+2) pixels tall.

The image may be output in any common image file format, saved to a file or printed/returned as a raw data stream, or directly displayed during runtime.

The shortest code in bytes wins.

Examples

Your program should produce these exact results.

N = 1:

N = 2:

N = 3:

N = 4:

N = 5:

N = 6:

Larger N should work just as well.

答:
R, <s>378</s> <s>356</s> <s>346</s> 334 bytes

```<code>f=function(n){r=rep;k=r(0,4);m=r(1,6);L=c();for(i in 1:n)L=cbind(L,r(max(L,0)+2^(n-i):1,e=2^(i-1)));png(w=sum(w<-4*2^(1:n)),h=sum(h<-r(8,2^(n-1))));layout(L,w,h);for(i in 1:max(L)){par(mar=k);image(matrix(c(0,0,0,1,k,0,m,0,0,1,1,1,2,r(1,10),0,0,r(r(c(2,1,2,0),e=2),2),m,k,1,k),nr=8),col=c("#74C460","#6EAA5A",1),ax=F,an=F)};dev.off()}
</code>```

Saves as a png file. Indented, with linefeeds:

f=function(n){
    r=rep
    k=r(0,4)
    m=r(1,6)
    L=c()
    for(i in 1:n)L=cbind(L,r(max(L,0)+2^(n-i):1,e=2^(i-1)))
    png(w=sum(w<-4*2^(1:n)),h=sum(h<-r(8,2^(n-1))))
    layout(L,w,h)
    for(i in 1:max(L)){
        par(mar=k)
        image(matrix(c(0,0,0,1,k,0,m,0,
                       0,1,1,1,2,r(1,10),0,
                       0,r(r(c(2,1,2,0),e=2),2),
                       m,k,1,k),
                     nr=8),
              col=c("#74C460","#6EAA5A",1),ax=F,an=F)
    }
    dev.off()
}
```
<p>N=2: <img src="https://i.stack.imgur.com/byebW.png" alt="N=2" /><br />
N=3: <img src="https://i.stack.imgur.com/SiGka.png" alt="N=3" /><br />
N=4: <img src="https://i.stack.imgur.com/gntye.png" alt="N=4" /></p>
<p>Some explanations:</p>
<p>Here's the matrix that's being plotted (0 represent lightgreen, 1 darkgreen and 2 black; the matrix is tilted because columns are the y-axis and rows the x-axis):</p>
```     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    0    0    0    1    0    0    0    0
[2,]    0    1    1    1    2    2    1    0
[3,]    0    1    1    1    2    2    1    0
[4,]    1    1    1    1    1    1    1    1
[5,]    0    1    2    1    1    1    1    0
[6,]    0    1    1    1    2    2    1    0
[7,]    0    1    1    1    2    2    1    0
[8,]    0    0    1    0    0    0    0    0
```
<p>Each call to <code>image</code> plot that matrix (with each integer corresponding to a color).
For N=4, here is L (the layout matrix, each unique number represents one single plot), w (the widths of the matrix columns) and h (the heights of the matrix rows):</p>
```> L
     [,1] [,2] [,3] [,4]
[1,]    8   12   14   15
[2,]    7   12   14   15
[3,]    6   11   14   15
[4,]    5   11   14   15
[5,]    4   10   13   15
[6,]    3   10   13   15
[7,]    2    9   13   15
[8,]    1    9   13   15
> w
[1]  8 16 32 64
> h
[1] 8 8 8 8 8 8 8 8
```

Body:
R, <s>378</s> <s>356</s> <s>346</s> 334 bytes

f=function(n){r=rep;k=r(0,4);m=r(1,6);L=c();for(i in 1:n)L=cbind(L,r(max(L,0)+2^(n-i):1,e=2^(i-1)));png(w=sum(w<-4*2^(1:n)),h=sum(h<-r(8,2^(n-1))));layout(L,w,h);for(i in 1:max(L)){par(mar=k);image(matrix(c(0,0,0,1,k,0,m,0,0,1,1,1,2,r(1,10),0,0,r(r(c(2,1,2,0),e=2),2),m,k,1,k),nr=8),col=c("#74C460","#6EAA5A",1),ax=F,an=F)};dev.off()}

Saves as a png file. Indented, with linefeeds:

f=function(n){
    r=rep
    k=r(0,4)
    m=r(1,6)
    L=c()
    for(i in 1:n)L=cbind(L,r(max(L,0)+2^(n-i):1,e=2^(i-1)))
    png(w=sum(w<-4*2^(1:n)),h=sum(h<-r(8,2^(n-1))))
    layout(L,w,h)
    for(i in 1:max(L)){
        par(mar=k)
        image(matrix(c(0,0,0,1,k,0,m,0,
                       0,1,1,1,2,r(1,10),0,
                       0,r(r(c(2,1,2,0),e=2),2),
                       m,k,1,k),
                     nr=8),
              col=c("#74C460","#6EAA5A",1),ax=F,an=F)
    }
    dev.off()
}

N=2:

N=3:

N=4:

Some explanations:

Here's the matrix that's being plotted (0 represent lightgreen, 1 darkgreen and 2 black; the matrix is tilted because columns are the y-axis and rows the x-axis):

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    0    0    0    1    0    0    0    0
[2,]    0    1    1    1    2    2    1    0
[3,]    0    1    1    1    2    2    1    0
[4,]    1    1    1    1    1    1    1    1
[5,]    0    1    2    1    1    1    1    0
[6,]    0    1    1    1    2    2    1    0
[7,]    0    1    1    1    2    2    1    0
[8,]    0    0    1    0    0    0    0    0

Each call to image plot that matrix (with each integer corresponding to a color).
For N=4, here is L (the layout matrix, each unique number represents one single plot), w (the widths of the matrix columns) and h (the heights of the matrix rows):

> L
     [,1] [,2] [,3] [,4]
[1,]    8   12   14   15
[2,]    7   12   14   15
[3,]    6   11   14   15
[4,]    5   11   14   15
[5,]    4   10   13   15
[6,]    3   10   13   15
[7,]    2    9   13   15
[8,]    1    9   13   15
> w
[1]  8 16 32 64
> h
[1] 8 8 8 8 8 8 8 8


问:
How does math work in Anastasiya's world?

Background:

Standard operation math like basic addition and multiplication in the real world work like these:

```<code>12 + 123 = 135
</code>```

and

```<code>12 * 123 = 1476
</code>```

That's not interesting and boring! Many schools are already interpreting this as practice, practice, practice of formal algorithms. That implies a pretty rigid and boring mathematical diet and is not what is intended in this challenge. Get ready to play some fun on our beloved site.

Consider the process of adding two positive integer numbers, then adding again all the digits of its result. Repeating with the addition until only a single digit is obtained. For example:

The result of 12 + 123 is 135.

Adding all the digits of 135 we obtain 1 + 3 + 5 = 9.

The number of steps required to obtain a single digit value 9 in this repeated addition is 2.

As with the previous process of the addition, the multiplication of two positive integer numbers follows the same process. Multiply all the digits of its result and then repeating this process until only a single digit remains. Take the above example:

The result of 12 * 123 is 1476.

Multiply all the digits of 1476 we obtain 1 * 4 * 7 * 6 = 168.

Multiply again all the digits of 168 we obtain 1 * 6 * 8 = 48.

Multiply again all the digits of 48 we obtain 4 * 8 = 32.

Multiply once again all the digits of 32 we obtain 3 * 2 = 6.

The number of steps required to obtain a single digit value 6 this repeated multiplication is 5.

For this challenge's sake and avoiding any misuse of math notations, I introduce these two dummy notations: (+) and (*), but you may use any notation you like, which work like the followings:

The operation of repeated addition process to obtain a single value is 12 (+) 123 = 9.

The operation of repeated multiplication process to obtain a single value is 12 (*) 123  = 6.

Challenge:

The challenge is to write either a program or a function which can perform both of operations as explained in the background section: (+) and (*).

Input:

The inputs of the program or the function are two positive integers and one operation either (+) and (*). The format of the input is an arbitrary choice of the programmer. You may format the input, for example, a (+) b or F(a, (+), b) or any format you wish.

Output:

The output of the program or the function must contain the result of operation and the number of steps required with freestyle format as you wish.

Test Cases (ignore the input and output format):

```<code>    81 (+) 31       -->   (4 ; 2)
    351 (+) 14568   -->   (6 ; 3)
    21 (*) 111      -->   (8 ; 3)
    136 (*) 2356    -->   (0 ; 2)
</code>```

General rules:

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

Don't let esolangs discourage you from posting an answer with regular languages. Enjoy this challenge by providing an answer as short as possible with your programming language. If you post a clever answer and a clear explanation, your answer will be appreciated (hence the upvotes) regardless of the programming language you use.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/ method with the proper parameters, full programs, etc. The choice is yours.

If possible, your program can properly handle large numbers. If not, that will just be fine.

Let the game begin!!

答:
Haskell, 108 bytes

```<code>f=map(read.pure).show
g h=(\x->(h.f$last x,length x+1)).takeWhile(>10).iterate(h.f)
(a#b)o=g(foldr1 o)$o a b
</code>```

Defines the function # which first takes a and b and then the operator o. Fun fact: this works with any operator (actually, any function) you want!

Body:
Haskell, 108 bytes

f=map(read.pure).show
g h=(\x->(h.f$last x,length x+1)).takeWhile(>10).iterate(h.f)
(a#b)o=g(foldr1 o)$o a b

Defines the function # which first takes a and b and then the operator o. Fun fact: this works with any operator (actually, any function) you want!


答:
k (<s>29</s> 20 chars)

```<code>{i!(1_i),*i:(-#x)?x}
</code>```

<s>
    {i!@[i:(-:#x)?x;,/|2 0N#!#x]}</s>

Example

```<code>k){i!(1_i),*i:(-#x)?x}`person1`person2`person3`person4`person5
person2| person1
person5| person3
person4| person2
person1| person5
person3| person4
</code>```

Explanation - as above, shuffles list and maps to rotation of itself.

Title: Secret Santa Challenge

Body:
Possible Duplicate:

  Holiday Gift Exchange

Background:
Secret Santa is a Western Christmas tradition in which members of a group or community are randomly assigned a person to whom they anonymously give a gift.

http://en.wikipedia.org/wiki/Secret_Santa

Ok, me and my work colleges did this today during our lunch hour - we made a secret algorithm santa pick random gifters and receivers.

Think of this question as a Christmas Programming Challenge to see who can come up with some of the most elegant solutions for this problem.

Input:
The input should be an array ['Oliver', 'Paul', 'Rowan', 'Darren', 'Nick', 'Atif', 'Kevin']

Output
A representation of something similar to key value pairs for the gifter and receiver. e.g.

```<code>Oliver -> Darren,
Paul -> Nick,
Rowan -> Kevin
Kevin -> Atif,
Darren -> Paul,
Nick -> Oliver,
Atif -> Rowan
</code>```

Deadline: 15th December (for those late christmas shoppers)

Remember: you cannot have a person choosing themselves and the program must not spiral off into an infinite loop when gifter == receiver when there is only one person left.

Rules:

Must not have duplicates

Must be random (we all have different views on what is random - but you get my gist)

No Language constraints

Have fun

Here is mine (not golfed) in ruby:

```<code>require 'pp'

def move(array, from, to)
  array.insert(to, array.delete_at(from))
end

gifters = ['Oliver', 'Paul', 'Rowan', 'Darren', 'Nick', 'Atif', 'Kevin'].shuffle!
recievers = gifters.dup

move recievers, recievers.count - 1, 0

pp Hash[gifters.zip recievers]
</code>```

which spits out:

```<code>{"Nick"=>"Darren",
 "Paul"=>"Nick",
 "Kevin"=>"Paul",
 "Rowan"=>"Kevin",
 "Atif"=>"Rowan",
 "Oliver"=>"Atif",
 "Darren"=>"Oliver"}
</code>```

Body:
k (<s>29</s> 20 chars)

{i!(1_i),*i:(-#x)?x}

<s>
    {i!@[i:(-:#x)?x;,/|2 0N#!#x]}</s>

Example

k){i!(1_i),*i:(-#x)?x}`person1`person2`person3`person4`person5
person2| person1
person5| person3
person4| person2
person1| person5
person3| person4

Explanation - as above, shuffles list and maps to rotation of itself.


答:
Dyalog APL, <s>33</s> <s>32</s> <s>30</s> 29 bytes

This extends APL to include the prefix notation +/A n₁ n₂ and ×/A n₁ n₂. (In fact, you can use any operation to the left of the /A.) Returns a list of {result, repetition count}.

A←{(⊃,≢)⍺⍺{∪⍵,⍨⍺⍺⍎¨⍕⊃⍵}⍣≡⍺⍺⍵}
```

A←{ define a higher-order function in terms of left-hand function ⍺⍺, and right-hand argument ⍵

(⊃,≢) the first element of, followed by the count of

⍺⍺{ the supplied function (+/ for sum or ×/ for product) fed to the higher-order function

∪ the unique elements of

⍵,⍨ the argument appended to

⍺⍺ the fed function applied to

⍎¨ the evaluation of each character of

⍕ the character representation of

⊃⍵ the first element of the argument

}⍣≡ applied repeatedly until the result is identical to the argument, beginning with

⍺⍺⍵ the originally fed function (+/ or ×/) applied to the original argument

} [end of higher-order function definition]

TryAPL online! (⍎ has been emulated with e for security reasons.)

Thanks to @ngn for saving a byte.

0 bytes (in jest)

Dyalog APL actually already has full support for Anastasiyan math; instead of (+) and (×), it uses +{n←0⋄n,⍺⍺{n+←1⋄⍺⍺/⍎¨⍕⍵}⍣=⍵⍺⍺⍨⍺} and ×{n←0⋄n,⍺⍺{n+←1⋄⍺⍺/⍎¨⍕⍵}⍣=⍵⍺⍺⍨⍺}.

Try 81 +{(⊃,≢)⍺⍺{∪⍵,⍨⍺⍺e¨⍕⊃⍵}⍣≡⍺⍺/⍺⍵} 31 and 21 ×{n←0⋄n,⍺⍺{n+←1⋄⍺⍺/e¨⍕⍵}⍣=⍵⍺⍺⍨⍺} 111.

Title: How does math work in Anastasiya's world?

Body:
Background:

Standard operation math like basic addition and multiplication in the real world work like these:

```<code>12 + 123 = 135
</code>```

and

```<code>12 * 123 = 1476
</code>```

That's not interesting and boring! Many schools are already interpreting this as practice, practice, practice of formal algorithms. That implies a pretty rigid and boring mathematical diet and is not what is intended in this challenge. Get ready to play some fun on our beloved site.

Consider the process of adding two positive integer numbers, then adding again all the digits of its result. Repeating with the addition until only a single digit is obtained. For example:

The result of 12 + 123 is 135.

Adding all the digits of 135 we obtain 1 + 3 + 5 = 9.

The number of steps required to obtain a single digit value 9 in this repeated addition is 2.

As with the previous process of the addition, the multiplication of two positive integer numbers follows the same process. Multiply all the digits of its result and then repeating this process until only a single digit remains. Take the above example:

The result of 12 * 123 is 1476.

Multiply all the digits of 1476 we obtain 1 * 4 * 7 * 6 = 168.

Multiply again all the digits of 168 we obtain 1 * 6 * 8 = 48.

Multiply again all the digits of 48 we obtain 4 * 8 = 32.

Multiply once again all the digits of 32 we obtain 3 * 2 = 6.

The number of steps required to obtain a single digit value 6 this repeated multiplication is 5.

For this challenge's sake and avoiding any misuse of math notations, I introduce these two dummy notations: (+) and (*), but you may use any notation you like, which work like the followings:

The operation of repeated addition process to obtain a single value is 12 (+) 123 = 9.

The operation of repeated multiplication process to obtain a single value is 12 (*) 123  = 6.

Challenge:

The challenge is to write either a program or a function which can perform both of operations as explained in the background section: (+) and (*).

Input:

The inputs of the program or the function are two positive integers and one operation either (+) and (*). The format of the input is an arbitrary choice of the programmer. You may format the input, for example, a (+) b or F(a, (+), b) or any format you wish.

Output:

The output of the program or the function must contain the result of operation and the number of steps required with freestyle format as you wish.

Test Cases (ignore the input and output format):

```<code>    81 (+) 31       -->   (4 ; 2)
    351 (+) 14568   -->   (6 ; 3)
    21 (*) 111      -->   (8 ; 3)
    136 (*) 2356    -->   (0 ; 2)
</code>```

General rules:

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

Don't let esolangs discourage you from posting an answer with regular languages. Enjoy this challenge by providing an answer as short as possible with your programming language. If you post a clever answer and a clear explanation, your answer will be appreciated (hence the upvotes) regardless of the programming language you use.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/ method with the proper parameters, full programs, etc. The choice is yours.

If possible, your program can properly handle large numbers. If not, that will just be fine.

Let the game begin!!

Body:
Dyalog APL, <s>33</s> <s>32</s> <s>30</s> 29 bytes

This extends APL to include the prefix notation +/A n₁ n₂ and ×/A n₁ n₂. (In fact, you can use any operation to the left of the /A.) Returns a list of {result, repetition count}.

A←{(⊃,≢)⍺⍺{∪⍵,⍨⍺⍺⍎¨⍕⊃⍵}⍣≡⍺⍺⍵}

A←{ define a higher-order function in terms of left-hand function ⍺⍺, and right-hand argument ⍵

(⊃,≢) the first element of, followed by the count of

⍺⍺{ the supplied function (+/ for sum or ×/ for product) fed to the higher-order function

∪ the unique elements of

⍵,⍨ the argument appended to

⍺⍺ the fed function applied to

⍎¨ the evaluation of each character of

⍕ the character representation of

⊃⍵ the first element of the argument

}⍣≡ applied repeatedly until the result is identical to the argument, beginning with

⍺⍺⍵ the originally fed function (+/ or ×/) applied to the original argument

} [end of higher-order function definition]

TryAPL online! (⍎ has been emulated with e for security reasons.)

Thanks to @ngn for saving a byte.

0 bytes (in jest)

Dyalog APL actually already has full support for Anastasiyan math; instead of (+) and (×), it uses +{n←0⋄n,⍺⍺{n+←1⋄⍺⍺/⍎¨⍕⍵}⍣=⍵⍺⍺⍨⍺} and ×{n←0⋄n,⍺⍺{n+←1⋄⍺⍺/⍎¨⍕⍵}⍣=⍵⍺⍺⍨⍺}.

Try 81 +{(⊃,≢)⍺⍺{∪⍵,⍨⍺⍺e¨⍕⊃⍵}⍣≡⍺⍺/⍺⍵} 31 and 21 ×{n←0⋄n,⍺⍺{n+←1⋄⍺⍺/e¨⍕⍵}⍣=⍵⍺⍺⍨⍺} 111.


答:
Pyke, 16 bytes

```<code>RE`DltImbRoKr)oh
</code>```

Try it here!

```<code>RE               - evaluate the input as Pyke code
                 -  (`B` is product and `s` is sum, the second line is a tuple)
  `              - i = str(^)
    ltI      )   - if len(i) != 1:
       mb        -   map(i, int)
         R       -   get the `B` or `s` from input
          oK     -   o++
            r    -   goto_start()
              oh - o++ + 1
</code>```

Takes multiply as B and add as s. The two numerical inputs are separated by commas.

Body:
Pyke, 16 bytes

RE`DltImbRoKr)oh

Try it here!

RE               - evaluate the input as Pyke code
                 -  (`B` is product and `s` is sum, the second line is a tuple)
  `              - i = str(^)
    ltI      )   - if len(i) != 1:
       mb        -   map(i, int)
         R       -   get the `B` or `s` from input
          oK     -   o++
            r    -   goto_start()
              oh - o++ + 1

Takes multiply as B and add as s. The two numerical inputs are separated by commas.


答:
05AB1E, <s>20</s> 15 bytes

```<code>[¼¹iOëP}Dg#S]¾‚
</code>```

Explanation

```<code>[       Dg# ]    # loop until number is single digit
 ¼               # increase counter
  ¹iO            # if operation is addition, sum list
     ëP}         # else take product of list
           S     # split into a list of digits
             ¾‚  # pair final number with counter and output
</code>```

Operator is 1 for addition, 0 for multiplication.

Try it online

Body:
05AB1E, <s>20</s> 15 bytes

[¼¹iOëP}Dg#S]¾‚

Explanation

[       Dg# ]    # loop until number is single digit
 ¼               # increase counter
  ¹iO            # if operation is addition, sum list
     ëP}         # else take product of list
           S     # split into a list of digits
             ¾‚  # pair final number with counter and output

Operator is 1 for addition, 0 for multiplication.

Try it online


问:
Alphabet triangle strikes again

Task

Your task is to print this exact text:

```<code>A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
</code>```

Specs

You may do it in all-lowercase instead of all-uppercase.

Trailing newlines at the end of the triangle is allowed.

Trailing spaces after each line is allowed.

You must print to STDOUT instead of outputting an array of strings.

Scoring

This is code-golf. Program with lowest byte-count wins.

答:
Python 3, 83 bytes

```<code>[print("".join([chr((i%26)+97)for i in range(j*j,(j+1)*(j+1))]))for j in range(26)]
</code>```

My first golfing experience.

Title: Alphabet triangle strikes again

Body:
Python 3, 83 bytes

[print("".join([chr((i%26)+97)for i in range(j*j,(j+1)*(j+1))]))for j in range(26)]

My first golfing experience.


答:
R, <s>175</s> <s>167</s> <s>164</s> <s>140</s> <s>134</s> <s>127</s> <s>126</s> 119 bytes

```<code>function(G,S,D){i=1;O=switch(S,"+"=sum,prod);x=O(G,D);while(x>9){i=i+1;x=O(strtoi(strsplit(paste(x),"")[[1]]))};c(x,i)}
</code>```

Ungolfed :

```<code>f=function(G,S,D) #The function takes : the left operand, the operation symbol (between quote marks)
                  #and then the right operand
i=1               #That's the counter

O=switch(S,"+"=sum,prod)     #`O` takes the value `sum` if `S` matches `+`, `prod`
                             #(which is the next agument) if not.

x=O(G,D)                     #Does the first operation

while(nchar(x)>1)                 #While the number of character of the result
                                  #of the operation is not of length 1, i.e., an integer :

    i=i+1                                    #Increase the counter
    x=O(strtoi(strsplit(paste(x),"")[[1]]))  #Apply the operation `O` to the first operation and
                                             #the eventual subsequent ones

c(x,i)                                 #Outputs the result and the counter
</code>```

<s>ifelse is back ! Yeah !</s>

Nop

Usage :

```<code>Special addition
> f(31,"+",81)
[1] 4 2

Special multiplication
> f(136,"*",2356)
[1] 0 2
</code>```

Thanks a lot to @plannapus for golfing out 24 bytes !

-7 bytes thanks to a good idea from @Vlo !

Body:
R, <s>175</s> <s>167</s> <s>164</s> <s>140</s> <s>134</s> <s>127</s> <s>126</s> 119 bytes

function(G,S,D){i=1;O=switch(S,"+"=sum,prod);x=O(G,D);while(x>9){i=i+1;x=O(strtoi(strsplit(paste(x),"")[[1]]))};c(x,i)}

Ungolfed :

f=function(G,S,D) #The function takes : the left operand, the operation symbol (between quote marks)
                  #and then the right operand
i=1               #That's the counter

O=switch(S,"+"=sum,prod)     #`O` takes the value `sum` if `S` matches `+`, `prod`
                             #(which is the next agument) if not.

x=O(G,D)                     #Does the first operation

while(nchar(x)>1)                 #While the number of character of the result
                                  #of the operation is not of length 1, i.e., an integer :

    i=i+1                                    #Increase the counter
    x=O(strtoi(strsplit(paste(x),"")[[1]]))  #Apply the operation `O` to the first operation and
                                             #the eventual subsequent ones

c(x,i)                                 #Outputs the result and the counter

<s>ifelse is back ! Yeah !</s>

Nop

Usage :

Special addition
> f(31,"+",81)
[1] 4 2

Special multiplication
> f(136,"*",2356)
[1] 0 2

Thanks a lot to @plannapus for golfing out 24 bytes !

-7 bytes thanks to a good idea from @Vlo !


答:
JavaScript (ES6), 59

Recursive function, the input format is tailored to simplify the recursive call:

operator : '+' or '*'

operands : array of two values

f=(o,v,s=1,t=eval(v.join(o)))=>t>9?f(o,[...t+''],s+1):[t,s]
```
<p><strong>Test</strong></p>
<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=(o,v,s=1,t=eval(v.join(o)))=>t>9?f(o,[...t+''],s+1):[t,s]

;[
  [81,'+',31,     /* -> */ 4, 2]
, [351,'+',14568, /* -> */ 6, 3]
, [21,'*',111,    /* -> */ 8, 3]
, [136,'*',2356,  /* -> */ 0, 2]
].forEach(t=>{
  var [a,o,b,k1,k2] = t,
      [r,s]=f(o,[a,b]);
  console.log(k1==r && k2==s ? 'OK':'KO',a,o,b,'->',r,s)
})
  </code>```

Body:
JavaScript (ES6), 59

Recursive function, the input format is tailored to simplify the recursive call:

operator : '+' or '*'

operands : array of two values

f=(o,v,s=1,t=eval(v.join(o)))=>t>9?f(o,[...t+''],s+1):[t,s]

Test

f=(o,v,s=1,t=eval(v.join(o)))=>t>9?f(o,[...t+''],s+1):[t,s]

;[
  [81,'+',31,     /* -> */ 4, 2]
, [351,'+',14568, /* -> */ 6, 3]
, [21,'*',111,    /* -> */ 8, 3]
, [136,'*',2356,  /* -> */ 0, 2]
].forEach(t=>{
  var [a,o,b,k1,k2] = t,
      [r,s]=f(o,[a,b]);
  console.log(k1==r && k2==s ? 'OK':'KO',a,o,b,'->',r,s)
})


答:
Python, <s>160</s> <s>146</s> 129 bytes

def r(s):
 n=str(eval(s));c=0
 while n[1:]:exec("n=str(reduce(lambda a,b:a%sb,map(int,list(n))))"%"*+"["+"in s]);c+=1
 return n,c
```

Will post an explanation soon.

Input is in the form 12+12 or 5*35 (with normal + and * signs), and assumes that those are the only two operators.

It can handle number inputs as large as your computer's memory allows.

I'm almost certainly confident that this can be further.

EDIT: <s>16</s> 31 bytes saved thanks to @Copper.

Body:
Python, <s>160</s> <s>146</s> 129 bytes

def r(s):
 n=str(eval(s));c=0
 while n[1:]:exec("n=str(reduce(lambda a,b:a%sb,map(int,list(n))))"%"*+"["+"in s]);c+=1
 return n,c

Will post an explanation soon.

Input is in the form 12+12 or 5*35 (with normal + and * signs), and assumes that those are the only two operators.

It can handle number inputs as large as your computer's memory allows.

I'm almost certainly confident that this can be further.

EDIT: <s>16</s> 31 bytes saved thanks to @Copper.


答:
Jelly, 17 bytes

```<code>+×⁵?µDSP⁵?$ÐĿµL;Ṫ
</code>```

Try it online!

Given arguments like x y 1, this computes the Anastasiya sum x (+) y.

Given arguments like x y 0, this computes the Anastasiya product x (*) y.

Output is given as [number of steps, result].

Body:
Jelly, 17 bytes

+×⁵?µDSP⁵?$ÐĿµL;Ṫ

Try it online!

Given arguments like x y 1, this computes the Anastasiya sum x (+) y.

Given arguments like x y 0, this computes the Anastasiya product x (*) y.

Output is given as [number of steps, result].


问:
Given a list of Tetris moves, return the number of completed lines

Description

We consider a slightly simplified version of Tetris where each move consists of:

rotating the piece clockwise, 0 to 3 times

positioning the piece at a given column

fast drop

The goal is to determine the number of completed lines, given a list of such Tetris moves.

Completed rows are removed as pieces are dropped, following standard Tetris rules.

Playfield

The playfield is 10-column wide. There's no Game Over and it is assumed that there's always enough space and time to perform the above actions, no matter the configuration of the playfield. The height of the playfield doesn't really matter here, but you can use the standard 22 rows as an upper limit.

Shapes of Tetrominoes

Input / Output

Input

A comma separated list of Tetris moves encoded with 3 characters. The first two character describe the Tetromino shape to use and the last one describes the position where it's dropped.

Tetromino: I, O, T, L, J, Z or S, in the same order as above.

Number of clockwise rotations: 0 to 3

Column: 0 to 9. This is the column in which the top-left corner of the piece (marked with an x on the above picture) is located after the rotation 1

It is assumed that all moves in the provided list are valid. There's no need to check for invalid entries such as I07 (horizontal I shape put too far on the right).

1 You are free to either implement a real rotation algorithm or to hardcode all the different shapes, as long as the x is located in the column given by the third character of the move.

Output

Number of completed lines.

Example

O00,T24 will generate the first position and O00,T24,S02,T01,L00,Z03,O07,L06,I05 will generate the second position.

Therefore, the following sequence will generate a Tetris and should return 4:

```<code>O00,T24,S02,T01,L00,Z03,O07,L06,I05,I19
</code>```

Test cases

```<code>1) "O00,T24,S02,T01,L00,Z03,O07,L06,I05,I19" -> 4
2) "S00,J03,L27,Z16,Z18,I10,T22,I01,I05,O01,L27,O05,S13" -> 5
3) "I01,T30,J18,L15,J37,I01,S15,L07,O03,O03,L00,Z00,T38,T01,S06,L18,L14" -> 4
4) "S14,T00,I13,I06,I05,I19,L20,J26,O07,Z14,Z10,Z12,O01,L27,L04,I03,S07,I01,T25,J23,J27,O01,
    I10,I10" -> 8
5) "O00,T24,L32,T16,L04,Z11,O06,L03,I18,J30,L23,Z07,I19,T05,T18,L30,I01,I01,I05,T02" -> 8
</code>```

Test page

You can use this JSFiddle to test a move list.

Body:
PHP, <s>454</s> <s>435</s> <s>427</s> <s>420</s> 414 bytes

bit fields for pieces and map; but no special case for the I shape as Dave´s golfing.

<?$t=[I=>[15,4369],O=>[51],T=>[114,562,39,305],L=>[113,802,71,275],J=>[116,547,23,785],Z=>[54,561],S=>[99,306]];foreach($argv as$z=>$m)if($z){$s=$t[$m[0]][$m[1]%count($t[$m[0]])];for($d=$i=0;$i<4;$i++)for($k=0;$k<4;$k++)if($s>>4*$k&1<<$i){for($y=0;$y++<count($f);)if($f[$y-1]&1<<$m[2]+$i)$d=max($d,$y-$k);$k=3;}for($k=$d;$s;$k++,$s>>=4)if(1022<$f[$k]|=$s%16<<$m[2]){$c++;unset($f[$k]);}$f=array_values($f);}echo$c;

takes arguments from command line, prints result

ungolfed as function

takes arguments as array, returns result

function t($a)
{
    // bitwise description of the stones and rotations
    $t=[I=>[15,4369],O=>[51],T=>[114,562,39,305],L=>[113,802,71,275],J=>[116,547,23,785],Z=>[54,561],S=>[99,306]];
    foreach($a as$m)
    {
        $s=$t[$m[0]][$m[1]%count($t[$m[0]])];   // $s=stone
        // find dropping space
        for($d=$i=0;$i<4;$i++)
            // a) lowest pixel of stone in column i
            for($k=0;$k<4;$k++)
                if($s>>4*$k&1<<$i)
                {
                    // b) top pixel of field in column x+i
                    for($y=0;$y++<count($f);)
                        if($f[$y-1]&1<<$m[2]+$i)$d=max($d,$y-$k);
                    $k=3; // one byte shorter than `break;`
                }
        // do drop
        for($k=$d;$s;$k++,$s>>=4)
            if(1022<$f[$k]|=$s%16<<$m[2])   // add block pixels to line pixels ... if full,
            {$c++;unset($f[$k]);}           // tetris
        $f=array_values($f);
    }
    return$c;
}

tests (on function)

$data=[
    "O00,T24,S02,T01,L00,Z03,O07,L06,I05,I19"=>4,
    "S00,J03,L27,Z16,Z18,I10,T22,I01,I05,O01,L27,O05,S13" => 5,
    "I01,T30,J18,L15,J37,I01,S15,L07,O03,O03,L00,Z00,T38,T01,S06,L18,L14" => 4,
    "S14,T00,I13,I06,I05,I19,L20,J26,O07,Z14,Z10,Z12,O01,L27,L04,I03,S07,I01,T25,J23,J27,O01,I10,I10" => 8,
    // additional example for the two last tetrominoes:
    'O00,T24,L32,T16,L04,Z11,O06,L03,I18,J30,L23,Z07,I19,T05,T18,L30,I01,I01,I05,T02' => 8,
];
function out($a){if(is_object($a)){foreach($a as$v)$r[]=$v;return'{'.implode(',',$r).'}';}if(!is_array($a))return$a;$r=[];foreach($a as$v)$r[]=out($v);return'['.join(',',$r).']';}
function cmp($a,$b){if(is_numeric($a)&&is_numeric($b))return 1e-2<abs($a-$b);if(is_array($a)&&is_array($b)&&count($a)==count($b)){foreach($a as $v){$w = array_shift($b);if(cmp($v,$w))return true;}return false;}return strcmp($a,$b);}
function test($x,$e,$y){static $h='<table border=1><tr><th>input</th><th>output</th><th>expected</th><th>ok?</th></tr>';echo"$h<tr><td>",out($x),'</td><td>',out($y),'</td><td>',out($e),'</td><td>',cmp($e,$y)?'N':'Y',"</td></tr>";$h='';}
foreach($data as $v=>$e)
{
    $x=explode(',',$v);
    test($x,$e,t($x));
}


答:
```<code>    NSMutableArray *people =
    [NSMutableArray arrayWithArray:@[@"Oliver", @"Paul", @"Rowan", @"Darren", @"Nick", @"Atif", @"Kevin"]];
    [people sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
         return (arc4random_uniform(3)-1);
    }];

    for (int i = 0;  i < [people count]; i++)
        NSLog(@"%@ gifts %@", people[i], people[(i+1)%[people count]]);
</code>```

Title: Secret Santa Challenge


答:
Octave, 85 bytes <s>MATLAB, 123, 114, 105, 94 bytes  </s>

Decided to translate this to Octace, to take advantage of  the direct indexing, and incrementing capabilitites. Takes the input on the form: f(a,operator), where a = [number1, number2],  and operator==1 gives the product, and operator==2 gives the sum.

```<code>function[x,i]=f(a,o)
g={@prod,@sum}{o};x=g(a);i=1;while(x=g(num2str(x)-48))>9;i++;end
</code>```

Explanations:

g={@prod,@sum}{o} : Chooses the appropriate function, product or sum and assigns it to g

x=g(a) takes the sum or product of the inputs

i=1; ... i++ : Incrementer to count the number of steps

```<code>while(x=g(num2str(x)-48))>9;
          num2str(x)-48)     % turns a number 123 into an array [1 2 3].
        g(num2str(x)-48))    % Takes the sum or product of the array
      x=g(num2str(x)-48))    % Assign that value to the variable x
      x=g(num2str(x)-48))>9  % Checks if x > 9, continue looping if yes
</code>```

Removed two newlines, a space, and placed both input numbers in a vector instead of separate arguments. This saved 9 bytes, thanks to pajonk!
Removed k=@(x)... to save another 11 bytes thanks to beaker =) Finally, translated the whole thing to Octave to save another 9 bytes...

Body:
Octave, 85 bytes <s>MATLAB, 123, 114, 105, 94 bytes  </s>

Decided to translate this to Octace, to take advantage of  the direct indexing, and incrementing capabilitites. Takes the input on the form: f(a,operator), where a = [number1, number2],  and operator==1 gives the product, and operator==2 gives the sum.

function[x,i]=f(a,o)
g={@prod,@sum}{o};x=g(a);i=1;while(x=g(num2str(x)-48))>9;i++;end

Explanations:

g={@prod,@sum}{o} : Chooses the appropriate function, product or sum and assigns it to g

x=g(a) takes the sum or product of the inputs

i=1; ... i++ : Incrementer to count the number of steps

while(x=g(num2str(x)-48))>9;
          num2str(x)-48)     % turns a number 123 into an array [1 2 3].
        g(num2str(x)-48))    % Takes the sum or product of the array
      x=g(num2str(x)-48))    % Assign that value to the variable x
      x=g(num2str(x)-48))>9  % Checks if x > 9, continue looping if yes

Removed two newlines, a space, and placed both input numbers in a vector instead of separate arguments. This saved 9 bytes, thanks to pajonk!
Removed k=@(x)... to save another 11 bytes thanks to beaker =) Finally, translated the whole thing to Octave to save another 9 bytes...


答:
Jellyfish, 20 bytes

```<code>p
<
)\&&&~j<i
->N>u0
</code>```

Try it online!
TIO can't handle the longer test cases, but given enough time and memory, they should work too.

Explanation

i is input, and < decrements it. This value is fed to the function on the left.

\> increments the value (at least once) until the function to the right gives a truthy value.

The test function is a composition (by &s) of four functions.

0~j converts to string.

u removes duplicate digits.

> removes the head of the resulting string.

N is logical negation: it gives 1 for an empty string, and 0 for non-empty. Thus the function tests for a rep-digit, and the result of \ is the next rep-digit counting from <i.

)- subtracts the result from the function input, that is, <i.

This difference is off by one, so < decrements it. Finally, p prints the result.

Title: How can I get a repdigit?

Body:
In honor of how much rep I had several hours ago, when I first thought of this challenge:

Numbers like this that are made up of a single digit repeating are called repdigits. Repdigits are fun! Every body would be more happy if the amount of rep they had was a repdigit¹, but I am impatient, so you need to help me find out the fastest way to get to a repdigit.

Here is your challenge:

Given a positive integers representing reputation, output the minimum amount of rep they need to gain to get to a repdigit. For example, at the time of writing this challenge, user Martin Ender had 102,856 rep. The nearest rep-digit is 111,111, so he would need to gain: 8255 rep to be at a repdigit.

Since people dislike losing rep, we will only consider non-negative changes. This means that, for example, if someone is at 12 rep, rather than losing 1 rep, the solution is to gain 10 rep. This allows '0' to be a valid output, since anyone who has 111 rep is already at a repdigit.

Input and output can be in any reasonable format, and since it is impossible to have less than 1 rep on any Stack Exchange site, you can assume no inputs will be less than 1.

One cornercase to note:

If a user has less than 10 rep, they are already at a repdigit, and so they also need '0'.

Test IO:

```<code>#Input      #Ouput
8           0
100         11
113         109
87654321    1234567
42          2
20000       2222
11132       11090
</code>```

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

Body:
Jellyfish, 20 bytes

p
<
)\&&&~j<i
->N>u0

Try it online!
TIO can't handle the longer test cases, but given enough time and memory, they should work too.

Explanation

i is input, and < decrements it. This value is fed to the function on the left.

\> increments the value (at least once) until the function to the right gives a truthy value.

The test function is a composition (by &s) of four functions.

0~j converts to string.

u removes duplicate digits.

> removes the head of the resulting string.

N is logical negation: it gives 1 for an empty string, and 0 for non-empty. Thus the function tests for a rep-digit, and the result of \ is the next rep-digit counting from <i.

)- subtracts the result from the function input, that is, <i.

This difference is off by one, so < decrements it. Finally, p prints the result.


答:
dc, 45 bytes

```<code>[dsa]dsAx[dsz]dsZx[dla>Adlz<Zs.z0<f]dsfxlzlaf
</code>```

This is a fairly straightforward equivalent of the C++ reference code:

```<code>#Test data
0 15 2 3 7 18 _2 9 6 _5 3 8 9 _14

# Uses two variables: a for min, and z for max

# Functions A and Z simply store a copy to a and z respectively.  Call
# them both, to initialize the variables.
[dsa]dsAx
[dsz]dsZx

# Function f is the main work - define and call it
[
    dla>A                       # copy into a if lower
    dlz<Z                       # copy into z if higher
    s.                          # discard value
    z0<f                        # recurse until end of input
]dsfx

# print the result
lzlaf
</code>```

Body:
Challenge

Given an array of integers, received from stdin, function arguments, program arguments, or some other method:

Output only the minimum and maximum numbers in the array, through a return value, stdout, or other fitting methods.

Example session

```<code>> minmax( {0, 15, 2, 3, 7, 18, -2, 9, 6, -5, 3, 8, 9, -14} )
-14 18
</code>```

Reference implementation

```<code>// C++14

void minmax(std::vector<int> v) {
    int min = v[0]; int max = v[0];
    for(auto it : v) {
        if (*it < min)
            min = *it;
        if (*it > max)
            max = *it;
    }
    std::cout << min << ' ' << max << std::endl;
}
</code>```

Rules

You may not use a built-in function to calculate the values.

Standard loopholes disallowed.

Creative implementations encouraged.

This is code-golf, shortest answer wins but will not be selected.

Clarifications

If the array contains 1 element you need to output it twice.

If the minimum and maximum values are the same, you need to output them both.

Body:
dc, 45 bytes

[dsa]dsAx[dsz]dsZx[dla>Adlz<Zs.z0<f]dsfxlzlaf

This is a fairly straightforward equivalent of the C++ reference code:

#Test data
0 15 2 3 7 18 _2 9 6 _5 3 8 9 _14

# Uses two variables: a for min, and z for max

# Functions A and Z simply store a copy to a and z respectively.  Call
# them both, to initialize the variables.
[dsa]dsAx
[dsz]dsZx

# Function f is the main work - define and call it
[
    dla>A                       # copy into a if lower
    dlz<Z                       # copy into z if higher
    s.                          # discard value
    z0<f                        # recurse until end of input
]dsfx

# print the result
lzlaf


答:
Java, <s>164</S> <s>159</s> 146 bytes

```<code>int[]p(int t,int m,String[]d){int r=m;for(String i:d){int x=Integer.decode(i);r=m<1?r+x:r*x;}return r>9?p(++t,m,(r+"").split("")):new int[]{r,t};}
</code>```

First argument is just the counter, always 0

Second argument is method, 0 for ADD and 1 for MULTIPLY.

Third argument is an array of Strings, which contains the values to add/multiply.

Ungolfed

```<code>public static int[] p(int t, int m, String[] d) {
    int r = m;
    for (String i : d) {
        int x = Integer.decode(i);
        r = m < 1 ? r + x : r * x;
    }
    return (r + "").length() > 1 ? p(++t, m, (r + "").split("")) : new int[]{r, t};
}
</code>```

thanks to @Kevin Cruijssen for cutting a few bytes.

thanks to @milk for shaving 5 bytes.

Test Program

```<code>public static final int ADD = 0;
public static final int MULTIPLY = 1;

public static void main(String[] args) {
    System.out.println(Arrays.toString(p(0, ADD, new String[]{"12", "123"}))); //9
    System.out.println(Arrays.toString(p(0, MULTIPLY, new String[]{"12", "123"}))); //6
}

public static int[] p(int t, int m, String[] d) {
    int r = m;
    for (String i : d) {
        int x = Integer.decode(i);
        r = m < 1 ? r + x : r * x;
    }
    return (r + "").length() > 1 ? p(++t, m, (r + "").split("")) : new int[]{r, t};
}
</code>```

Body:
Java, <s>164</S> <s>159</s> 146 bytes

int[]p(int t,int m,String[]d){int r=m;for(String i:d){int x=Integer.decode(i);r=m<1?r+x:r*x;}return r>9?p(++t,m,(r+"").split("")):new int[]{r,t};}

First argument is just the counter, always 0

Second argument is method, 0 for ADD and 1 for MULTIPLY.

Third argument is an array of Strings, which contains the values to add/multiply.

Ungolfed

public static int[] p(int t, int m, String[] d) {
    int r = m;
    for (String i : d) {
        int x = Integer.decode(i);
        r = m < 1 ? r + x : r * x;
    }
    return (r + "").length() > 1 ? p(++t, m, (r + "").split("")) : new int[]{r, t};
}

thanks to @Kevin Cruijssen for cutting a few bytes.

thanks to @milk for shaving 5 bytes.

Test Program

public static final int ADD = 0;
public static final int MULTIPLY = 1;

public static void main(String[] args) {
    System.out.println(Arrays.toString(p(0, ADD, new String[]{"12", "123"}))); //9
    System.out.println(Arrays.toString(p(0, MULTIPLY, new String[]{"12", "123"}))); //6
}

public static int[] p(int t, int m, String[] d) {
    int r = m;
    for (String i : d) {
        int x = Integer.decode(i);
        r = m < 1 ? r + x : r * x;
    }
    return (r + "").length() > 1 ? p(++t, m, (r + "").split("")) : new int[]{r, t};
}


答:
C#, 60 bytes

```<code>n=>{System.Array.Sort(n);return new[]{n[0],n[n.Length-1]};};
</code>```

A naïve method at 93 bytes:

```<code>n=>{var r=new[]{n[0],n[0]};foreach(int i in n){if(i<r[0])r[0]=i;if(i>r[1])r[1]=i;}return r;};
</code>```

Body:
C#, 60 bytes

n=>{System.Array.Sort(n);return new[]{n[0],n[n.Length-1]};};

A naïve method at 93 bytes:

n=>{var r=new[]{n[0],n[0]};foreach(int i in n){if(i<r[0])r[0]=i;if(i>r[1])r[1]=i;}return r;};


答:
Java 7, <s>203</s> <s>195</s> 192 bytes

```<code>int c=1;String c(long a,long b,int o){return p(((o<1?a+b:a*b)+"",o)+","+c;}long p(String n,int o){long x=o,q;for(String s:n.split("")){q=new Long(s);x=o<1?x+q:x*q}c++;return x<10?x:p(x+"",o);}
</code>```

It uses long (maximum value of 263-1). If it would use int instead (maximum value of 231-1) it would only be 1 byte less (191 bytes):

```<code>int c=1;String c(int a,int b,int o){return p(((o<1?a+b:a*b)+"",o)+","+c;}int p(String n,int o){int x=o,q;for(String s:n.split("")){q=new Integer(s);x=o<1?x+q:x*q}c++;return x<10?x:p(x+"",o);}
</code>```

It can most likely be golfed a bit more. Having to print the steps as well as the answer for both operators takes some bytes, though..

Uses 0 (for (+)) and 1 (for (*)).

Ungolfed & test code:

Try it here.

```<code>class Main{
  static int c = 1;
  static String c(long a, long b, int o){
    return p((o < 1 ? a+b : a*b) + "", o) + "," + c;
  }

  static long p(String n, int o){
    long x = o,
         q;
    for(String s : n.split("")){
      q = new Long(s);
      x = o < 1
           ? x + q
           : x * q;
    }
    c++;
    return x < 10
            ? x
            : p(x+"", o);
  }

  public static void main(String[] a){
    System.out.println(c(81, 31, true));
    c = 1;
    System.out.println(c(351, 14568, true));
    c = 1;
    System.out.println(c(21, 111, false));
    c = 1;
    System.out.println(c(136, 2356, false));
  }
}
</code>```

Output:

```<code>4,2
6,3
8,3
0,2
</code>```

Body:
Background:

Standard operation math like basic addition and multiplication in the real world work like these:

```<code>12 + 123 = 135
</code>```

and

```<code>12 * 123 = 1476
</code>```

That's not interesting and boring! Many schools are already interpreting this as practice, practice, practice of formal algorithms. That implies a pretty rigid and boring mathematical diet and is not what is intended in this challenge. Get ready to play some fun on our beloved site.

Consider the process of adding two positive integer numbers, then adding again all the digits of its result. Repeating with the addition until only a single digit is obtained. For example:

The result of 12 + 123 is 135.

Adding all the digits of 135 we obtain 1 + 3 + 5 = 9.

The number of steps required to obtain a single digit value 9 in this repeated addition is 2.

As with the previous process of the addition, the multiplication of two positive integer numbers follows the same process. Multiply all the digits of its result and then repeating this process until only a single digit remains. Take the above example:

The result of 12 * 123 is 1476.

Multiply all the digits of 1476 we obtain 1 * 4 * 7 * 6 = 168.

Multiply again all the digits of 168 we obtain 1 * 6 * 8 = 48.

Multiply again all the digits of 48 we obtain 4 * 8 = 32.

Multiply once again all the digits of 32 we obtain 3 * 2 = 6.

The number of steps required to obtain a single digit value 6 this repeated multiplication is 5.

For this challenge's sake and avoiding any misuse of math notations, I introduce these two dummy notations: (+) and (*), but you may use any notation you like, which work like the followings:

The operation of repeated addition process to obtain a single value is 12 (+) 123 = 9.

The operation of repeated multiplication process to obtain a single value is 12 (*) 123  = 6.

Challenge:

The challenge is to write either a program or a function which can perform both of operations as explained in the background section: (+) and (*).

Input:

The inputs of the program or the function are two positive integers and one operation either (+) and (*). The format of the input is an arbitrary choice of the programmer. You may format the input, for example, a (+) b or F(a, (+), b) or any format you wish.

Output:

The output of the program or the function must contain the result of operation and the number of steps required with freestyle format as you wish.

Test Cases (ignore the input and output format):

```<code>    81 (+) 31       -->   (4 ; 2)
    351 (+) 14568   -->   (6 ; 3)
    21 (*) 111      -->   (8 ; 3)
    136 (*) 2356    -->   (0 ; 2)
</code>```

General rules:

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

Don't let esolangs discourage you from posting an answer with regular languages. Enjoy this challenge by providing an answer as short as possible with your programming language. If you post a clever answer and a clear explanation, your answer will be appreciated (hence the upvotes) regardless of the programming language you use.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/ method with the proper parameters, full programs, etc. The choice is yours.

If possible, your program can properly handle large numbers. If not, that will just be fine.

Let the game begin!!

Body:
Java 7, <s>203</s> <s>195</s> 192 bytes

int c=1;String c(long a,long b,int o){return p(((o<1?a+b:a*b)+"",o)+","+c;}long p(String n,int o){long x=o,q;for(String s:n.split("")){q=new Long(s);x=o<1?x+q:x*q}c++;return x<10?x:p(x+"",o);}

It uses long (maximum value of 263-1). If it would use int instead (maximum value of 231-1) it would only be 1 byte less (191 bytes):

int c=1;String c(int a,int b,int o){return p(((o<1?a+b:a*b)+"",o)+","+c;}int p(String n,int o){int x=o,q;for(String s:n.split("")){q=new Integer(s);x=o<1?x+q:x*q}c++;return x<10?x:p(x+"",o);}

It can most likely be golfed a bit more. Having to print the steps as well as the answer for both operators takes some bytes, though..

Uses 0 (for (+)) and 1 (for (*)).

Ungolfed & test code:

Try it here.

class Main{
  static int c = 1;
  static String c(long a, long b, int o){
    return p((o < 1 ? a+b : a*b) + "", o) + "," + c;
  }

  static long p(String n, int o){
    long x = o,
         q;
    for(String s : n.split("")){
      q = new Long(s);
      x = o < 1
           ? x + q
           : x * q;
    }
    c++;
    return x < 10
            ? x
            : p(x+"", o);
  }

  public static void main(String[] a){
    System.out.println(c(81, 31, true));
    c = 1;
    System.out.println(c(351, 14568, true));
    c = 1;
    System.out.println(c(21, 111, false));
    c = 1;
    System.out.println(c(136, 2356, false));
  }
}

Output:

4,2
6,3
8,3
0,2


答:
Excel, <s>85</s> 79 bytes

Put the following formula in any cell except cell N since it's a name for reference cell of input:

```<code>=IF(1*(REPT(LEFT(N),LEN(N)))<N,REPT(LEFT(N)+1,LEN(N))-N,REPT(LEFT(N),LEN(N))-N)
</code>```

Explanation:

N is the input and also name of reference cell.

LEFT(N) take the first digit of input value.

LEN(N) return the length of input value.

REPT(LEFT(N),LEN(N)) repeat the first digit of input value LEN(N) times and multiply it by 1 to convert text format to number format so we can use it for number comparison.

The syntax for the IF function in Microsoft Excel is: IF( condition, [value_if_true], [value_if_false]), hence makes the whole formula is self-explanatory.

Title: How can I get a repdigit?

Body:
Excel, <s>85</s> 79 bytes

Put the following formula in any cell except cell N since it's a name for reference cell of input:

=IF(1*(REPT(LEFT(N),LEN(N)))<N,REPT(LEFT(N)+1,LEN(N))-N,REPT(LEFT(N),LEN(N))-N)

Explanation:

N is the input and also name of reference cell.

LEFT(N) take the first digit of input value.

LEN(N) return the length of input value.

REPT(LEFT(N),LEN(N)) repeat the first digit of input value LEN(N) times and multiply it by 1 to convert text format to number format so we can use it for number comparison.

The syntax for the IF function in Microsoft Excel is: IF( condition, [value_if_true], [value_if_false]), hence makes the whole formula is self-explanatory.


答:
PHP, 44 bytes

```<code>function a($a){sort($a);echo $a[0].end($a);}
</code>```

Body:
PHP, 44 bytes

function a($a){sort($a);echo $a[0].end($a);}


答:
R, 81 73 65 63 bytes

A simple for loop approach. Repeat the alphabet 26 times and loop through a sliding index range that is calculated using (i^2-2*i+2):i^2.

```<code>for(i in 1:26)cat(rep(LETTERS,26)[(i^2-2*i+2):i^2],"\n",sep="")
</code>```

Title: Alphabet triangle strikes again

Body:
Task

Your task is to print this exact text:

```<code>A
BCD
EFGHI
JKLMNOP
QRSTUVWXY
ZABCDEFGHIJ
KLMNOPQRSTUVW
XYZABCDEFGHIJKL
MNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
</code>```

Specs

You may do it in all-lowercase instead of all-uppercase.

Trailing newlines at the end of the triangle is allowed.

Trailing spaces after each line is allowed.

You must print to STDOUT instead of outputting an array of strings.

Scoring

This is code-golf. Program with lowest byte-count wins.

Body:
R, 81 73 65 63 bytes

A simple for loop approach. Repeat the alphabet 26 times and loop through a sliding index range that is calculated using (i^2-2*i+2):i^2.

for(i in 1:26)cat(rep(LETTERS,26)[(i^2-2*i+2):i^2],"\n",sep="")


答:
MATL, 10 bytes

```<code>q`QtVda}G-
</code>```

Try it online!

This keeps incrementing the input until all digits are equal, so it's slow. The test case for input 87654321 times out in the online compiler.

```<code>q      % Take input implicitly. Subtract 1
`      % Do...while loop
  Q    %   Increment top of the stack
  tV   %   Duplicate and convert to string (i.e. digits of the number)
  d    %   Difference between consecutive digits
  a    %   True if any such difference is nonzero. This is the loop condition
}      % Finally (execute on loop exit)
  G-   %   Subtract input. This is the final result, to be (implicitly) displayed
       % End loop implicitly. If loop condition (top of the stack) is truthy: proceeds
       % with next iteration. Else: executes the "finally" block and exits loop
       % Display implicitly
</code>```

Title: How can I get a repdigit?

Body:
MATL, 10 bytes

q`QtVda}G-

Try it online!

This keeps incrementing the input until all digits are equal, so it's slow. The test case for input 87654321 times out in the online compiler.

q      % Take input implicitly. Subtract 1
`      % Do...while loop
  Q    %   Increment top of the stack
  tV   %   Duplicate and convert to string (i.e. digits of the number)
  d    %   Difference between consecutive digits
  a    %   True if any such difference is nonzero. This is the loop condition
}      % Finally (execute on loop exit)
  G-   %   Subtract input. This is the final result, to be (implicitly) displayed
       % End loop implicitly. If loop condition (top of the stack) is truthy: proceeds
       % with next iteration. Else: executes the "finally" block and exits loop
       % Display implicitly