问:
Determine the "Luck" of a string
Given a string, return that string's "luck".

A string's luck, as I completely just made up for the purpose of this challenge, is an integer, determined as so:

The base luck for a string is 1.

For each consecutive letter it shares with the word "lucky" (case insensitive), multiply the luck by 2. For instance, if your string was "lumberjack" or "smack" you'd multiply by 4. (More specifically, 2^number of consecutive characters shared.)

The shared letters have to be in the same consecutive order it appears in "lucky" but can start anywhere in the word for the same value ("luc" has the same 8* multiplier as "cky").

If the word has multiple occurrences where it shares consecutive characters with lucky, use the longest consecutive string of the characters.

For ANY letter it shares with the word "omen" subtract 2 from the luck.

It can match a character any amount of times, in any order. For instance the string "nnnnnomemenn" loses 24 luck (12 matching letters)

Example:

```<code>luck("lucky")
>>32
</code>```

2^5 (5 consecutive letters) = 32

```<code>luck("firetruck")
>>6
</code>```

2^3 - 2 (3 consecutive letters from uck, e shared with omen)

```<code>luck("memes")
>>-7
</code>```

1 - 8 (base amount, 4 shared with "omen")

This is code golf, so the answer with the fewest bytes wins.

You can input and output any way you'd like - write a function, use standard input, etc.

For functions, assume whatever data type would make sense for that language. (For example, in JavaScript, you'd be passed a String and return a Number)

Edit: You can assume any input is lowercase.

答:
Scala, 155 bytes

```<code>def f(w:String)=(1::List.fill((for(a<-1 to 5;s<-"lucky".sliding(a))yield if(w.contains(s)) a else 0).max){2}).product-2*w.filter("omen".contains(_)).length
</code>```

Title: Determine the "Luck" of a string

Body:
Scala, 155 bytes

def f(w:String)=(1::List.fill((for(a<-1 to 5;s<-"lucky".sliding(a))yield if(w.contains(s)) a else 0).max){2}).product-2*w.filter("omen".contains(_)).length


问:
Convert n strings of m length to m strings of n length
Write a program that, given any 'n' number of strings of 'm' length, returns 'm' number of 'n'-length strings, with this condition:

Every new string should contains the letters at the same index of the others strings

For example, the first output string must contain the first letter of all the input strings, the second output string must contain the second letter of all the input strings, and so on.

Examples (the numbers under the letters are the indexes of the strings):

```<code>input: "car", "dog", "man", "yay"
        012    012    012    012
output: "cdmy", "aoaa", "rgny"
         0000    1111    2222

input: "money", "taken", "trust"
        01234    01234    01234
output: "mtt", "oar", "nku", "ees", "ynt"
         000    111    222    333    444
</code>```

Assume that the input is correct everytime

Shortest bytes' code wins!

Edit:

Since there are many programming languages, and there could be many possible solutions for each of them, I will post the shortest solution for each programming language and the user who provided it. Keep coding!

Re-Edit:

Thanks to user Dennis I inserted a snippet for the leaderboards.

var QUESTION_ID=85255,OVERRIDE_USER=56179;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

```

答:
Clojure, 68 bytes

```<code>#(map(fn[g](reduce(fn[a b](str a(nth b g)))""%))(range(count(% 0))))
</code>```

Maps a function which is just reduce (goes on elements of the list one by one and joins nth character of the string) on the range from 0 to length of the first string.

See it online: https://ideone.com/pwhZ8e

ContentLicense: CC BY-SA 3.0

Body:
Clojure, 68 bytes

#(map(fn[g](reduce(fn[a b](str a(nth b g)))""%))(range(count(% 0))))

Maps a function which is just reduce (goes on elements of the list one by one and joins nth character of the string) on the range from 0 to length of the first string.

See it online: https://ideone.com/pwhZ8e


问:
ASCII art reflection
In this challenge, you will be given a text block, and you need to perform reflection on the text.

Input:

A string to be reflected. The text may not be supplied as an array whose elements are the lines of text. For example, "ab\ncd" and ['a','b','\n','c','d'] are allowed, but ['ab','cd'] or [['a','b'],['c','d']] are not. You can assume that all of the lines have the same number of characters (padded with whitespace where needed).

A boolean where True indicates Y reflection and False indicates X reflection

The two inputs can be passed in any order.

Output:

The reflected string. The characters do not change, only their position. The resulting image block should be aligned to the top left (the first row and column must each contain a non-whitespace character). Trailing whitespace (on any of the lines) is allowed.

Test cases:

```<code>False
  o /
--|/
  |
 / \

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

```<code>True
  o /
--|/
  |
 / \

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

```<code>True
text

text
</code>```

```<code>False
text

txet
</code>```

```<code>True
P
P
C
G

G
C
P
P
</code>```

```<code>False
P
P
C
G

P
P
C
G
</code>```

```<code>True
abcde
fghij
kl mn
opqrs
tuvwx

tuvwx
opqrs
kl mn
fghij
abcde
</code>```

This is a code-golf, so answer with the shortest answer in your favorite language!

答:
JavaScript (ES 6) 83 bytes

```<code>(c,b)=>(p=c.split`
`)&&(b?p.reverse():p.map(a=>a.split``.reverse().join``)).join`
`
</code>```

```<code>f=(c,b)=>(p=c.split`
`)&&(b?p.reverse():p.map(a=>a.split``.reverse().join``)).join`
`

f("abcde\nfghij\nkl mn\nopqrs\ntuvwx",1)

c="
  o /
--|/
  |
 / \
";

f(c,1)
" / \
   |
 --|/
   o / "

f(c,0)
"/ o
  /|--
   |
  \ / "
</code>```

Title: ASCII art reflection

Body:
JavaScript (ES 6) 83 bytes

(c,b)=>(p=c.split`
`)&&(b?p.reverse():p.map(a=>a.split``.reverse().join``)).join`
`

f=(c,b)=>(p=c.split`
`)&&(b?p.reverse():p.map(a=>a.split``.reverse().join``)).join`
`

f("abcde\nfghij\nkl mn\nopqrs\ntuvwx",1)

c="
  o /
--|/
  |
 / \
";

f(c,1)
" / \
   |
 --|/
   o / "

f(c,0)
"/ o
  /|--
   |
  \ / "


答:
Jelly, 8 bytes

```<code>ṣ⁷ṚU⁴?j⁷
</code>```

Try it here.

```<code>ṣ⁷         Split over newlines.
  ṚU⁴?     If ⁴ (2nd argument), then Ṛ (reverse rank ∞), else U (reverse rank 1).
      j⁷   Join with newlines.
</code>```

Title: ASCII art reflection

Body:
In this challenge, you will be given a text block, and you need to perform reflection on the text.

Input:

A string to be reflected. The text may not be supplied as an array whose elements are the lines of text. For example, "ab\ncd" and ['a','b','\n','c','d'] are allowed, but ['ab','cd'] or [['a','b'],['c','d']] are not. You can assume that all of the lines have the same number of characters (padded with whitespace where needed).

A boolean where True indicates Y reflection and False indicates X reflection

The two inputs can be passed in any order.

Output:

The reflected string. The characters do not change, only their position. The resulting image block should be aligned to the top left (the first row and column must each contain a non-whitespace character). Trailing whitespace (on any of the lines) is allowed.

Test cases:

```<code>False
  o /
--|/
  |
 / \

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

```<code>True
  o /
--|/
  |
 / \

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

```<code>True
text

text
</code>```

```<code>False
text

txet
</code>```

```<code>True
P
P
C
G

G
C
P
P
</code>```

```<code>False
P
P
C
G

P
P
C
G
</code>```

```<code>True
abcde
fghij
kl mn
opqrs
tuvwx

tuvwx
opqrs
kl mn
fghij
abcde
</code>```

This is a code-golf, so answer with the shortest answer in your favorite language!

Body:
Jelly, 8 bytes

ṣ⁷ṚU⁴?j⁷

Try it here.

ṣ⁷         Split over newlines.
  ṚU⁴?     If ⁴ (2nd argument), then Ṛ (reverse rank ∞), else U (reverse rank 1).
      j⁷   Join with newlines.


问:
Shortest simple regex matching a binary word

Task

Define a simple regex as a non-empty regular expression consisting only of

characters 0 and 1,

grouping parentheses ( and ),

one-or-more repetition quantifier +.

Given a non-empty string of 0s and 1s, your program should find the shortest simple regex matching the full input string. (That is, when matching a simple regex, pretend it’s bookended by ^ and $.) If there are multiple shortest regexes, print any or all of them.)

code-golf, so the shortest submission (in bytes) wins.

Test cases

```<code>1 -> 1
00 -> 00 or 0+
010 -> 010
1110 -> 1+0
01010 -> 01010
0101010 -> 0(10)+ or (01)+0
011111 -> 01+
10110110 -> (1+0)+
01100110 -> (0110)+ or (01+0)+
010010010 -> (010)+
111100111 -> 1+001+ or 1+0+1+
00000101010 -> 0+(10)+ or (0+1)+0
1010110001 -> 1(0+1+)+ or (1+0+)+1
</code>```

答:
Python 3, 186 bytes

I'm investigating whether there is an approach to this problem besides brute-forcing, but here is a Python brute-force solution for now.

import re,itertools
def a(b):
 for z in range(10):
  for i in itertools.combinations("01()+"*4,z):
   j=''.join(i)
   try:
    if re.fullmatch(j,b)and len(j)<=len(b):return j
   except:1
```


问:
given prime factors of a number, what is the fastest way to calculate it's proper divisors?
Given prime factors of a number, what is the fastest way to calculate divisors?

```<code>clc; clear;
sms=0;
count = 1;
x=0;
for i=11:28123
    fac = factor(i);
    sm = 1;
    for j = 1:length(fac)-1
        sm = sm + sum(prod(unique(combntns(fac,j), 'rows'),2));
    end
    if sm>i
        x(count) = i;
        count = count + 1;
    end
end
sum1=0;
count = 1;
for i=1:length(x)
    for j=i:length(x)
        smss = x(i) + x(j);
        if smss <= 28123
            sum1(count) = smss;
            count = count + 1;
        end
    end
end
sum1 = unique(sum1);
disp(28123*28124/2-sum(sum1));
</code>```

currently I'm using this prod(unique(combntns(fac,j), 'rows'),2) code which is awfully slow and I'm using Matlab.

答:
Haskell (with Data.List)

```<code>f :: [Int] -> [Int]
f [] = [1]
f (x:xs) = a ++ map (x*) a
    where a=f xs
factorsfromlist1 = nub . sort . f
-- may have better performance
factorsfromlist2 = map head . group . sort . f
</code>```

On the list [2, 2, 3, 5, 5, 11, 11, 11, 17, 31, 37, 47, 67, 103, 331, 617, 1093, 1597, 2309]:

```<code>$ ghc -O test.hs
$ ./test
Prime factors of 2078661171193247994962581628700
Method 1: 1.077712s
Method 2: 0.863675s
</code>```

Body:
Haskell (with Data.List)

f :: [Int] -> [Int]
f [] = [1]
f (x:xs) = a ++ map (x*) a
    where a=f xs
factorsfromlist1 = nub . sort . f
-- may have better performance
factorsfromlist2 = map head . group . sort . f

On the list [2, 2, 3, 5, 5, 11, 11, 11, 17, 31, 37, 47, 67, 103, 331, 617, 1093, 1597, 2309]:

$ ghc -O test.hs
$ ./test
Prime factors of 2078661171193247994962581628700
Method 1: 1.077712s
Method 2: 0.863675s


问:
Post-determined Array Sorting
Input:

An array containing three integers: 0, 1 and 2 in any order (i.e. [2, 0, 1])

And a string of length >= 2 only containing alphabetic letters (both lower- and uppercase) and digits (i.e. a1B2c3)

Output:

Based on the array we sort and output the string.

How does this work?

The array indicates the order precedence of a-z, A-Z and 0-9, the first being 0; second being 1; and third being 2.

The individual characters of the string can then be ordered based on that.

Example:

Array: [2, 0, 1]

String: a1B2c3

Based on the array, we know our order precedence is 0-9a-zA-Z.

Based on that, we can convert and output the string: 123acB.

Challenge rules:

For the array you can choose to use 0-indexed or 1-indexed input, so [3, 1, 2] is also a valid input if you prefer to use 1-indexed arrays.

The string (both input and output) only contains valid characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.

If your language doesn't support arrays (or if you choose to), you are free to use strings instead of arrays for the first parameter (i.e. 012, [0,1,2], etc.).

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>[2, 0, 1]  &  a1B2c3             ->   123acB
[2, 1, 0]  &  aAaA909UuHWw9gh2   ->   02999AAHUWaaghuw
[2, 1, 0]  &  6Bx43              ->   346Bx
[1, 0, 2]  &  jfjf33g            ->   ffgjj33
[0, 2, 1]  &  AbC13              ->   b13AC
[1, 2, 0]  &  Qfl0l              ->   Q0fll
[0, 1, 2]  &  9870abcABC         ->   abcABC0789
[0, 2, 1]  &  test123            ->   estt123
[2, 0, 1]  &  WHAT               ->   AHTW
[2, 0, 1]  &  WhAt               ->   htAW
[1, 0, 2]  &  102BACbac          ->   ABCabc012
</code>```

答:
Ruby, 56 bytes

Ported from @Dennis answer.

```<code>->a,s{s.chars.sort_by{|c|a.index(3-c.ord/32).to_s+c}*''}
</code>```

An alternate 58 bytes solution that I like better, inspired by @Neil and modified slightly from his answer.

```<code>->a,s{a.map{|i|s.scan([/[a-z]/,/[A-Z]/,/\d/][i]).sort}*''}
</code>```

Try either version online! (commented-out version is the alternate solution)

Title: Post-determined Array Sorting

Body:
Ruby, 56 bytes

Ported from @Dennis answer.

->a,s{s.chars.sort_by{|c|a.index(3-c.ord/32).to_s+c}*''}

An alternate 58 bytes solution that I like better, inspired by @Neil and modified slightly from his answer.

->a,s{a.map{|i|s.scan([/[a-z]/,/[A-Z]/,/\d/][i]).sort}*''}

Try either version online! (commented-out version is the alternate solution)


问:
Unzip some numbers
Your task is to create a program or function that generates a zipper with a length of 10 lines. Each line of the zipper is represented by two dashes --:

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

The program/function will take a percentage (divisible by 10) as input, and the output will be the zipper "unzipped" (dashes separated) from the top by the percentage, revealing the 1-indexed, lowest level repeated 2 times, with all prior levels repeated 4, 6, 8, ...etc. times, while keeping the bottom of the zipper centered.

Examples

```<code>>>10%
-11-
 --
 --
 --
 --
 --
 --
 --
 --
 --

>>50%
-1111111111-
 -22222222-
  -333333-
   -4444-
    -55-
     --
     --
     --
     --
     --

>>100%
-11111111111111111111-
 -222222222222222222-
  -3333333333333333-
   -44444444444444-
    -555555555555-
     -6666666666-
      -77777777-
       -888888-
        -9999-
         -10-
</code>```

The input (percentage) can be formatted however you like (50%, .5, 50, 5 [zero implied], etc), and it will always be in the range of 0 to 100 and divisible by 10. The spacing in the examples must be preserved in your output.

答:
Python 2.7, 113 108 77 bytes

    n=input()

    for x in range(0,10):

        v=str(x+1)*(n-x)2

        if xn>89:v='10'

        print' '*min(x,n)+'-'+v+'-'

First time playing golf. Gonna keep going, try to get it <100.

Assumes input is 1-10.

Edit:
Used some tricks from @LeakyNun 's answer (thanks), then crunched it a bit further and got... basically the same answer :/  Didn't know about the `int` string conversion, and 2 - boolean let me get rid of the if statement, which let me get rid of the whole v variable.  Very cool.

My version:

```<code>n=input()
for x in range(10):print' '*min(x,n)+'-'+`x+1`*(n-x)*(2-(x>8))+'-'
</code>```

Title: Unzip some numbers

Body:
Python 2.7, 113 108 77 bytes

    n=input()

    for x in range(0,10):

        v=str(x+1)*(n-x)2

        if xn>89:v='10'

        print' '*min(x,n)+'-'+v+'-'

First time playing golf. Gonna keep going, try to get it <100.

Assumes input is 1-10.

Edit:
Used some tricks from @LeakyNun 's answer (thanks), then crunched it a bit further and got... basically the same answer :/  Didn't know about the `int` string conversion, and 2 - boolean let me get rid of the if statement, which let me get rid of the whole v variable.  Very cool.

My version:

n=input()
for x in range(10):print' '*min(x,n)+'-'+`x+1`*(n-x)*(2-(x>8))+'-'


问:
Return the nth digit of the sequence of aliquot series

0. DEFINITIONS

A sequence is a list of numbers.

A series is the sum of a list of numbers.

The set of natural numbers contains all "non-negative integers greater than zero".

A divisor (in this context) of a natural number j is a natural number i, such that j÷i is also a natural number.

1. PREAMBLE

A couple of other questions on this site mention the concept of the aliquot, or the sequence of divisors of a natural number a which are less than a. Determining amicable numbers involves computing the sum of these divisors, called an aliquot sum or aliquot series. Every natural number has its own aliquot sum, although the value of a number's aliquot sum is not necessarily unique to that number. (Exempli gratia, every prime number has an aliquot sum of 1.)

2. CHALLENGE

Given a natural number n, return the nth digit of the sequence of aliquot sums. The first several series in the sequence, starting with the series for 1, are:

```<code>{0, 1, 1, 3, 1, 6, 1, 7, 4, 8, 1, 16, 1, 10, 9, 15, 1, 21, 1, 22, 11, 14, 1, 36, 6, 16, 13}
</code>```

Concatenated, these look like:

```<code>0113161748116110915121122111413661613
</code>```

Input may be zero-indexed or one-indexed, according to your preference. Solutions must be programs or functions capable of returning the 10,000th digit (input up to 9999 or 10000). The shortest working solution wins.

3. TEST CASES

Correct input-output pairs should include, but are not limited to, the following:

```<code>   0 or     1    ->    0
   4 or     5    ->    1
  12 or    13    ->    6
9999 or 10000    ->    7
</code>```

The number preceding the "or" is 0-indexed; the number following is 1-indexed.

Additional test cases may be provided upon request.

4. REFERENCES

OEIS has a list of numbers and their aliquot sums.

答:
Octave, 71 bytes

This one is Octave only. It won't work in MATLAB. A virtual function is created which works on 1-indexed numbers. It can probably be simplified a bit further. Will have a look this evening.

```<code>@(x)c((c=num2str(arrayfun(@(n)sum(b(~rem(n,b=(1:n-1)))),1:x)))~=' ')(x)
</code>```

You can try online here.

Simply run the command above, prefixed with a= or whatever (just so that you can use it multiple times), and then do a(10000) or whatever. It takes about 7 seconds to calculated that the 10000th digit is a 7.

Body:
Octave, 71 bytes

This one is Octave only. It won't work in MATLAB. A virtual function is created which works on 1-indexed numbers. It can probably be simplified a bit further. Will have a look this evening.

@(x)c((c=num2str(arrayfun(@(n)sum(b(~rem(n,b=(1:n-1)))),1:x)))~=' ')(x)

You can try online here.

Simply run the command above, prefixed with a= or whatever (just so that you can use it multiple times), and then do a(10000) or whatever. It takes about 7 seconds to calculated that the 10000th digit is a 7.


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

Input

Well, obviously this challenge has no input.

Output

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

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

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

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

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

Boilerplate

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

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

Standard loopholes are disallowed.

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

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

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

答:
Scala, 219 bytes

Inspired by Titus' bash solution, not very Scala-like. Also, the colors are off and the "pixels" are not square.

```<code>object O{def main(a:Array[String])={val e="\u001B[";val(b,r,w,n,s)=(e+"44m",e+"41m",e+"47m",e+"0m\n"," "*7);val(x,y,z)=(s"$b$s$w $r  $w $b$s$s$n",s"$w$s $r  $w $s$s$n",s"$r${s*3}    $n");print(s"${x*7}$y$z$z$y${x*7}")}}`
</code>```

ungolfed:

```<code>object O{
  def main(a:Array[String])={
    val e="\u001B["; // escape sequence for color codes
    val(b,r,w,n,s)=(
      e+"44m", // blue background
      e+"41m", // red background
      e+"47m", // white background
      e+"0m\n",// color off + newline
      " "*7);  // seven spaces
    val(x,y,z)=(
      s"$b$s$w $r  $w $b$s$s$n", // 7*blue,white,red,red,white,14*blue
      s"$w$s $r  $w $s$s$n",     // 8*white,2*red,15*white
      s"$r${s*3}    $n");        // 3*7+4=25*red
    print(s"${x*7}$y$z$z$y${x*7}") // print the individual lines
  }
}
</code>```

Idea: The program uses (bash) color escape sequences to set the background color on the console. It then draws a number of space characters in the respective background color. The image consists of 18 lines of 25 spaces; the first seven and the last seven lines represented by variable x, the two (completely red) middle lines by z, and y represents the two white-and-red lines above/below.
To save bytes, variable s represents seven consecutive spaces; for smaller cases, the spaces are used literally (i.e. the four consecutive spaces in variable z are necessary).

Title: Draw the national flag of Iceland

Body:
Scala, 219 bytes

Inspired by Titus' bash solution, not very Scala-like. Also, the colors are off and the "pixels" are not square.

object O{def main(a:Array[String])={val e="\u001B[";val(b,r,w,n,s)=(e+"44m",e+"41m",e+"47m",e+"0m\n"," "*7);val(x,y,z)=(s"$b$s$w $r  $w $b$s$s$n",s"$w$s $r  $w $s$s$n",s"$r${s*3}    $n");print(s"${x*7}$y$z$z$y${x*7}")}}`

ungolfed:

object O{
  def main(a:Array[String])={
    val e="\u001B["; // escape sequence for color codes
    val(b,r,w,n,s)=(
      e+"44m", // blue background
      e+"41m", // red background
      e+"47m", // white background
      e+"0m\n",// color off + newline
      " "*7);  // seven spaces
    val(x,y,z)=(
      s"$b$s$w $r  $w $b$s$s$n", // 7*blue,white,red,red,white,14*blue
      s"$w$s $r  $w $s$s$n",     // 8*white,2*red,15*white
      s"$r${s*3}    $n");        // 3*7+4=25*red
    print(s"${x*7}$y$z$z$y${x*7}") // print the individual lines
  }
}

Idea: The program uses (bash) color escape sequences to set the background color on the console. It then draws a number of space characters in the respective background color. The image consists of 18 lines of 25 spaces; the first seven and the last seven lines represented by variable x, the two (completely red) middle lines by z, and y represents the two white-and-red lines above/below.
To save bytes, variable s represents seven consecutive spaces; for smaller cases, the spaces are used literally (i.e. the four consecutive spaces in variable z are necessary).


答:
Pyth, 10 bytes

```<code>j?Q_.z_M.z
</code>```

Test suite.

```<code>j?Q_.z_M.z  first line evaluated as Q, all other lines as .z
 ?Q         if Q:
   _.z         yield reverse(.z)
      _M.z  else: yield map(reverse, .z)
j           join by newlines
</code>```

Title: ASCII art reflection

Body:
Pyth, 10 bytes

j?Q_.z_M.z

Test suite.

j?Q_.z_M.z  first line evaluated as Q, all other lines as .z
 ?Q         if Q:
   _.z         yield reverse(.z)
      _M.z  else: yield map(reverse, .z)
j           join by newlines


答:
32-bit x86 machine code, 70 bytes

In hex:

```<code>fc31c031c95189e3ac84c0740a34cf0404880c0341ebf189fe9160ac88c2c0e805d788c652ac88c2c0e805d788c658740e6639d076029241aa92aa4e4febdc85c96175d658c3
</code>```

This procedure expects character class sorting order to be a 3-char (0..2) NULL-terminated string in ESI and the string to sort in EDI. Sorting is done in-place using extremely sub-optimal (performance-wise) version of bubble sort.

```<code>0:  fc                  cld
1:  31 c0               xor eax, eax
3:  31 c9               xor ecx, ecx
5:  51                  push ecx        ;Allocate 4 bytes on the stack
6:  89 e3               mov ebx, esp    ;char EBX[4]
_loop0:                                 ;Parsing class order string
8:  ac                  lodsb
9:  84 c0               test al,al      ;Break on NULL
b:  74 0a               jz _break0
d:  34 cf               xor al, 0xCF    ;AL=~atoi(AL)
f:  04 04               add al, 4       ;'0'->3, '1'->2, '2'->1
11: 88 0c 03            mov [ebx+eax], cl    ;EBX[AL]=CL
14: 41                  inc ecx
15: eb f1               jmp _loop0
_break0:
17: 89 fe               mov esi,edi
19: 91                  xchg eax,ecx    ;ECX=0
_bsort:
1a: 60                  pusha
_cx2b:
1b: ac                  lodsb           ;Get the first char to compare
1c: 88 c2               mov dl,al       ;Save to DL
1e: c0 e8 05            shr al,5        ;Char class: [0-9]->1, [A-Z]->2, [a-z]->3
21: d7                  xlat            ;AL=EBX[AL] - priority for the char class
22: 88 c6               mov dh,al       ;... goes to DH
24: 52                  push edx        ;First "comparable char" in DX goes to the stack
25: ac                  lodsb           ;Get the second char to compare
26: 88 c2               mov dl,al       ;\
28: c0 e8 05            shr al,5        ; > Same as the above
2b: d7                  xlat            ;/
2c: 88 c6               mov dh, al      ;Second "comparable char" in DX
2e: 58                  pop eax         ;The first one goes to AX
2f: 74 0e               jz _endpass     ;ZF is set by the last 'shr', and only on AL==0
31: 66 39 d0            cmp ax,dx       ;Upper halves of 32-bit regs may contain trash
34: 76 02               jbe _sorted
36: 92                  xchg eax,edx    ;Now AX<=DX
37: 41                  inc ecx         ;Swap counter
_sorted:
38: aa                  stosb           ;Store AL in-place
39: 92                  xchg eax,edx    ;AL=DL
3a: aa                  stosb           ;Store the second char
3b: 4e                  dec esi         ;Move pointers...
3c: 4f                  dec edi         ;...back one byte
3d: eb dc               jmp _cx2b       ;Repeat with the next two chars
_endpass:
3f: 85 c9               test ecx,ecx    ;Full pass completed, checking # of swaps made
41: 61                  popa            ;Restores ECX(0), ESI, EDI. Doesn't affect flags
42: 75 d6               jnz _bsort      ;If there were changes, repeat
_end:
44: 58                  pop eax         ;Deallocate EBX[]
45: c3                  ret
</code>```

Title: Post-determined Array Sorting

Body:
Input:

An array containing three integers: 0, 1 and 2 in any order (i.e. [2, 0, 1])

And a string of length >= 2 only containing alphabetic letters (both lower- and uppercase) and digits (i.e. a1B2c3)

Output:

Based on the array we sort and output the string.

How does this work?

The array indicates the order precedence of a-z, A-Z and 0-9, the first being 0; second being 1; and third being 2.

The individual characters of the string can then be ordered based on that.

Example:

Array: [2, 0, 1]

String: a1B2c3

Based on the array, we know our order precedence is 0-9a-zA-Z.

Based on that, we can convert and output the string: 123acB.

Challenge rules:

For the array you can choose to use 0-indexed or 1-indexed input, so [3, 1, 2] is also a valid input if you prefer to use 1-indexed arrays.

The string (both input and output) only contains valid characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.

If your language doesn't support arrays (or if you choose to), you are free to use strings instead of arrays for the first parameter (i.e. 012, [0,1,2], etc.).

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>[2, 0, 1]  &  a1B2c3             ->   123acB
[2, 1, 0]  &  aAaA909UuHWw9gh2   ->   02999AAHUWaaghuw
[2, 1, 0]  &  6Bx43              ->   346Bx
[1, 0, 2]  &  jfjf33g            ->   ffgjj33
[0, 2, 1]  &  AbC13              ->   b13AC
[1, 2, 0]  &  Qfl0l              ->   Q0fll
[0, 1, 2]  &  9870abcABC         ->   abcABC0789
[0, 2, 1]  &  test123            ->   estt123
[2, 0, 1]  &  WHAT               ->   AHTW
[2, 0, 1]  &  WhAt               ->   htAW
[1, 0, 2]  &  102BACbac          ->   ABCabc012
</code>```

Body:
32-bit x86 machine code, 70 bytes

In hex:

fc31c031c95189e3ac84c0740a34cf0404880c0341ebf189fe9160ac88c2c0e805d788c652ac88c2c0e805d788c658740e6639d076029241aa92aa4e4febdc85c96175d658c3

This procedure expects character class sorting order to be a 3-char (0..2) NULL-terminated string in ESI and the string to sort in EDI. Sorting is done in-place using extremely sub-optimal (performance-wise) version of bubble sort.

0:  fc                  cld
1:  31 c0               xor eax, eax
3:  31 c9               xor ecx, ecx
5:  51                  push ecx        ;Allocate 4 bytes on the stack
6:  89 e3               mov ebx, esp    ;char EBX[4]
_loop0:                                 ;Parsing class order string
8:  ac                  lodsb
9:  84 c0               test al,al      ;Break on NULL
b:  74 0a               jz _break0
d:  34 cf               xor al, 0xCF    ;AL=~atoi(AL)
f:  04 04               add al, 4       ;'0'->3, '1'->2, '2'->1
11: 88 0c 03            mov [ebx+eax], cl    ;EBX[AL]=CL
14: 41                  inc ecx
15: eb f1               jmp _loop0
_break0:
17: 89 fe               mov esi,edi
19: 91                  xchg eax,ecx    ;ECX=0
_bsort:
1a: 60                  pusha
_cx2b:
1b: ac                  lodsb           ;Get the first char to compare
1c: 88 c2               mov dl,al       ;Save to DL
1e: c0 e8 05            shr al,5        ;Char class: [0-9]->1, [A-Z]->2, [a-z]->3
21: d7                  xlat            ;AL=EBX[AL] - priority for the char class
22: 88 c6               mov dh,al       ;... goes to DH
24: 52                  push edx        ;First "comparable char" in DX goes to the stack
25: ac                  lodsb           ;Get the second char to compare
26: 88 c2               mov dl,al       ;\
28: c0 e8 05            shr al,5        ; > Same as the above
2b: d7                  xlat            ;/
2c: 88 c6               mov dh, al      ;Second "comparable char" in DX
2e: 58                  pop eax         ;The first one goes to AX
2f: 74 0e               jz _endpass     ;ZF is set by the last 'shr', and only on AL==0
31: 66 39 d0            cmp ax,dx       ;Upper halves of 32-bit regs may contain trash
34: 76 02               jbe _sorted
36: 92                  xchg eax,edx    ;Now AX<=DX
37: 41                  inc ecx         ;Swap counter
_sorted:
38: aa                  stosb           ;Store AL in-place
39: 92                  xchg eax,edx    ;AL=DL
3a: aa                  stosb           ;Store the second char
3b: 4e                  dec esi         ;Move pointers...
3c: 4f                  dec edi         ;...back one byte
3d: eb dc               jmp _cx2b       ;Repeat with the next two chars
_endpass:
3f: 85 c9               test ecx,ecx    ;Full pass completed, checking # of swaps made
41: 61                  popa            ;Restores ECX(0), ESI, EDI. Doesn't affect flags
42: 75 d6               jnz _bsort      ;If there were changes, repeat
_end:
44: 58                  pop eax         ;Deallocate EBX[]
45: c3                  ret


答:
Emacs Lisp, 183 bytes

```<code>(lambda(s p)(let(l u n)(apply'concat(mapcar(lambda(l)(sort l'<))(dolist(e(string-to-list s)(mapcar(lambda(i)(nth i(list l u n)))p))(push e(cond((< ?` e)l)((< ?@ e)u)((< ?/ e)n))))))))
</code>```

Slightly shorter than Java...

Title: Post-determined Array Sorting

Body:
Emacs Lisp, 183 bytes

(lambda(s p)(let(l u n)(apply'concat(mapcar(lambda(l)(sort l'<))(dolist(e(string-to-list s)(mapcar(lambda(i)(nth i(list l u n)))p))(push e(cond((< ?` e)l)((< ?@ e)u)((< ?/ e)n))))))))

Slightly shorter than Java...


答:
Haskell, 41 bytes

```<code>f l=zipWith($)[map(!!n)|n<-[0..]]$l<$l!!0
</code>```

Or with a bit more air:

```<code>f l = zipWith ($) [map (!! n) | n <- [0..]] $
                  l <$ (l !! 0)
</code>```

The second list is the list of words repeated “the length of a word” time. On each list of words, we select the n-th letter of each word, giving the result.

Title: Convert n strings of m length to m strings of n length

Body:
Write a program that, given any 'n' number of strings of 'm' length, returns 'm' number of 'n'-length strings, with this condition:

Every new string should contains the letters at the same index of the others strings

For example, the first output string must contain the first letter of all the input strings, the second output string must contain the second letter of all the input strings, and so on.

Examples (the numbers under the letters are the indexes of the strings):

```<code>input: "car", "dog", "man", "yay"
        012    012    012    012
output: "cdmy", "aoaa", "rgny"
         0000    1111    2222

input: "money", "taken", "trust"
        01234    01234    01234
output: "mtt", "oar", "nku", "ees", "ynt"
         000    111    222    333    444
</code>```

Assume that the input is correct everytime

Shortest bytes' code wins!

Edit:

Since there are many programming languages, and there could be many possible solutions for each of them, I will post the shortest solution for each programming language and the user who provided it. Keep coding!

Re-Edit:

Thanks to user Dennis I inserted a snippet for the leaderboards.

var QUESTION_ID=85255,OVERRIDE_USER=56179;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:
Haskell, 41 bytes

f l=zipWith($)[map(!!n)|n<-[0..]]$l<$l!!0

Or with a bit more air:

f l = zipWith ($) [map (!! n) | n <- [0..]] $
                  l <$ (l !! 0)

The second list is the list of words repeated “the length of a word” time. On each list of words, we select the n-th letter of each word, giving the result.


答:
Bash + common linux utils, 16

(($1))&&tac||rev
```

Boolean value (zero or non-zero) passed as a command-line parameter.  I/O of text block via STDIN/STDOUT.  Assumes that all lines are the same length, as indicated in the comments.

Title: ASCII art reflection

Body:
Bash + common linux utils, 16

(($1))&&tac||rev

Boolean value (zero or non-zero) passed as a command-line parameter.  I/O of text block via STDIN/STDOUT.  Assumes that all lines are the same length, as indicated in the comments.


问:
Find an unknown very large number
Let's suppose there is a finite unknown number n (n can be very large, does not necessarily fit 64-bits; think of BigInteger in Java or long in Python) and a function cmp(x) that returns true if x <= n.

Write a program to determine n in minimum number of calls to cmp.

答:
A solution in pseudocode (assuming x is nowhere near 0):

```<code>x=0
#Step 1: get upper and lower bounds on the number of digits
#double the number of digits until we go past the number
while cmp(2**(2**x)): x++
mindgt=2**(x-1)
maxdgt=2**x
#Step 2: find bounds on log(number)
while(maxdgt-mindgt!=1):
    n=(mindgt+maxdgt)/2
    if cmp(2**n):
        mindgt=n
    else:
        maxdgt=n
min=2**mindgt
max=2**maxdgt
#Step 3: straightforward binary search
while(max!=min):
    n=(max+min)/2
    if(cmp(n)):
        mindgt=n
    else:
        maxdgt=n-1
print max
</code>```

For a value on the order of 1e40, this method takes 9 calls on step #1, 7 calls on step #2 and about 133 calls in step #3 for a total of 149.

ContentLicense: CC BY-SA 2.5

Title: Find an unknown very large number

Body:
A solution in pseudocode (assuming x is nowhere near 0):

x=0
#Step 1: get upper and lower bounds on the number of digits
#double the number of digits until we go past the number
while cmp(2**(2**x)): x++
mindgt=2**(x-1)
maxdgt=2**x
#Step 2: find bounds on log(number)
while(maxdgt-mindgt!=1):
    n=(mindgt+maxdgt)/2
    if cmp(2**n):
        mindgt=n
    else:
        maxdgt=n
min=2**mindgt
max=2**maxdgt
#Step 3: straightforward binary search
while(max!=min):
    n=(max+min)/2
    if(cmp(n)):
        mindgt=n
    else:
        maxdgt=n-1
print max

For a value on the order of 1e40, this method takes 9 calls on step #1, 7 calls on step #2 and about 133 calls in step #3 for a total of 149.


答:
Python 3.5, 61 bytes:

```<code>lambda f,j:[print(r[::-1])for r in j[::[1,-1][f]].split('\n')]
</code>```

A simple anonymous lambda function that assumes rectangular input. Call it by by first naming the function, and then calling it wrapped inside print(). In other words, if the function were named H, call it like print(H(<Bool value>, <String>)), where <Bool Value> is any true or false value (i.e. 0/1, true/false, etc.) and <String> is the input string.

See it in Action! (repl.it)

Here is another version with the same length that also assumes rectangular input, but this time a named function, i.e. you don't have to name it first nor wrap it inside print():

```<code>def J(f,j):[print(r[::-1])for r in j[::[1,-1][f]].split('\n')]
</code>```

Simply call this one likeJ(<Bool Value>,<String>).

See this in Action! (repl.it)

However, I'm not the one to stop there. Although we are allowed to assume rectangular input, I also created a version that does not assume that type of input. Therefore, it will space-pad all of the lines to the same length based on the line with the maximum length if and only if the <Bool> input is False, as only a X-reflection will result in the string being "flipped". Now, without further ado, here is the non-rectangular assuming version with a length of <s>134</s> 129 bytes in the form of a normal function:

```<code>def J(f,j):print('\n'.join([' '*((max([len(i)for i in j.split('\n')])-len(r))*(not f))+r[::-1]for r in j[::[1,-1][f]].split('\n')]))
</code>```

See this Last One in Action! (repl.it)

Title: ASCII art reflection

Body:
Python 3.5, 61 bytes:

lambda f,j:[print(r[::-1])for r in j[::[1,-1][f]].split('\n')]

A simple anonymous lambda function that assumes rectangular input. Call it by by first naming the function, and then calling it wrapped inside print(). In other words, if the function were named H, call it like print(H(<Bool value>, <String>)), where <Bool Value> is any true or false value (i.e. 0/1, true/false, etc.) and <String> is the input string.

See it in Action! (repl.it)

Here is another version with the same length that also assumes rectangular input, but this time a named function, i.e. you don't have to name it first nor wrap it inside print():

def J(f,j):[print(r[::-1])for r in j[::[1,-1][f]].split('\n')]

Simply call this one likeJ(<Bool Value>,<String>).

See this in Action! (repl.it)

However, I'm not the one to stop there. Although we are allowed to assume rectangular input, I also created a version that does not assume that type of input. Therefore, it will space-pad all of the lines to the same length based on the line with the maximum length if and only if the <Bool> input is False, as only a X-reflection will result in the string being "flipped". Now, without further ado, here is the non-rectangular assuming version with a length of <s>134</s> 129 bytes in the form of a normal function:

def J(f,j):print('\n'.join([' '*((max([len(i)for i in j.split('\n')])-len(r))*(not f))+r[::-1]for r in j[::[1,-1][f]].split('\n')]))

See this Last One in Action! (repl.it)


答:
Brainfuck, <s>143</s> <s>140</s> 131 bytes

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

Beat<s>s</s> C#.

The challenge was easy enough for Brainfuck, and I apparently was tired enough to just have to do it.

Takes the boolean as a 0x00 (falsy) or any other (truthy) byte in the start of the input, then a rectangle-padded string.

Outputs a trailing newline for the Y flip, and none for the X flip.

Requires an interpreter that supports memory locations to the left of the start (unsure if still required) and gives EOF as 0x00. One such interpreter is here. Obviously doesn't support null bytes in the input because of that.

The code has a lot of blocks with 10 +'s or -'s; those can probably be reduced.

Commented version

```<code>, get mode
[ check truthy input
    ,[ loop thru input
        ---------- subtract newline
        >+ set flag
        < go back to char
        [ was not newline
            > move to flag
            - reset flag
        ]
        > move to flag or one past flag
        [ hit flag; was newline
            - reset flag
            > skip a cell
        ]
        < go to next position
        , read next input
    ]
    < find end of line
    [ loop thru lines
        [<]> find start of line
        [ loop thru line
            ++++++++++ add newline back
            . print this cell
            > go to next cell
        ]
        ++++++++++ change to newline
        . print newline
        <[<]< find end of previous line
    ]
]
,[ loop thru any input left
    ---------- subtract newline
    >+ set flag
    < go back to char
    [ was not newline
        ++++++++++ add newline back
        > move to flag
        - reset flag
    ]
    > move to flag or one past flag
    [ hit flag; was newline
        - clear flag
        < go back to char
        < go back to line chars
        [ loop thru line
            . print this cell
            < go to previous cell
        ]
        ++++++++++. print newline
        [>]>> find empty cell
    ]
    < go to next position
    , read next input
]
< go to line
[ loop thru line
    . print this cell
    < go to previous cell
]
</code>```

Title: ASCII art reflection

Body:
Brainfuck, <s>143</s> <s>140</s> 131 bytes

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

Beat<s>s</s> C#.

The challenge was easy enough for Brainfuck, and I apparently was tired enough to just have to do it.

Takes the boolean as a 0x00 (falsy) or any other (truthy) byte in the start of the input, then a rectangle-padded string.

Outputs a trailing newline for the Y flip, and none for the X flip.

Requires an interpreter that supports memory locations to the left of the start (unsure if still required) and gives EOF as 0x00. One such interpreter is here. Obviously doesn't support null bytes in the input because of that.

The code has a lot of blocks with 10 +'s or -'s; those can probably be reduced.

Commented version

, get mode
[ check truthy input
    ,[ loop thru input
        ---------- subtract newline
        >+ set flag
        < go back to char
        [ was not newline
            > move to flag
            - reset flag
        ]
        > move to flag or one past flag
        [ hit flag; was newline
            - reset flag
            > skip a cell
        ]
        < go to next position
        , read next input
    ]
    < find end of line
    [ loop thru lines
        [<]> find start of line
        [ loop thru line
            ++++++++++ add newline back
            . print this cell
            > go to next cell
        ]
        ++++++++++ change to newline
        . print newline
        <[<]< find end of previous line
    ]
]
,[ loop thru any input left
    ---------- subtract newline
    >+ set flag
    < go back to char
    [ was not newline
        ++++++++++ add newline back
        > move to flag
        - reset flag
    ]
    > move to flag or one past flag
    [ hit flag; was newline
        - clear flag
        < go back to char
        < go back to line chars
        [ loop thru line
            . print this cell
            < go to previous cell
        ]
        ++++++++++. print newline
        [>]>> find empty cell
    ]
    < go to next position
    , read next input
]
< go to line
[ loop thru line
    . print this cell
    < go to previous cell
]


答:
C (Ansi), 193 Bytes

Golfed:

```<code>i,y,x;main(g,o,p)char**o;{p=(o[1][0]=='t');while(o[2][++i]!='\n');p?y=(strlen(o[2])-1)/i:(x=i);do do printf("%c",o[2][x+y*i]);while(p?++x<i:x-->0);while(p?x=0,y--:++y<(x=i-1,strlen(o[2])/i));}
</code>```

Ungolfed:

```<code>i,y,x;
main(g,o,p)char**o;{
    p=(o[1][0]=='t');
    while(o[2][++i]!='\n');
    p?y=(strlen(o[2])-1)/i:(x=i);
    do{
        do{
            printf("%c",o[2][x+y*i]);
        }while(p?++x<i:x-->0);
    }while(p?x=0,y--:++y<(x=i-1,strlen(o[2])/i));
}
</code>```

Usage:

Compilation Arguments:

```<code>gcc -O3 -ansi
</code>```

Example Input:

Input is a t or not t for true of false followed by a newspace lead and trailed string.

```<code>./reverseString t "
truck
ducky
quack
moose
"
</code>```

Example Output:

```<code>moose
quack
ducky
truck
</code>```

Title: ASCII art reflection

Body:
In this challenge, you will be given a text block, and you need to perform reflection on the text.

Input:

A string to be reflected. The text may not be supplied as an array whose elements are the lines of text. For example, "ab\ncd" and ['a','b','\n','c','d'] are allowed, but ['ab','cd'] or [['a','b'],['c','d']] are not. You can assume that all of the lines have the same number of characters (padded with whitespace where needed).

A boolean where True indicates Y reflection and False indicates X reflection

The two inputs can be passed in any order.

Output:

The reflected string. The characters do not change, only their position. The resulting image block should be aligned to the top left (the first row and column must each contain a non-whitespace character). Trailing whitespace (on any of the lines) is allowed.

Test cases:

```<code>False
  o /
--|/
  |
 / \

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

```<code>True
  o /
--|/
  |
 / \

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

```<code>True
text

text
</code>```

```<code>False
text

txet
</code>```

```<code>True
P
P
C
G

G
C
P
P
</code>```

```<code>False
P
P
C
G

P
P
C
G
</code>```

```<code>True
abcde
fghij
kl mn
opqrs
tuvwx

tuvwx
opqrs
kl mn
fghij
abcde
</code>```

This is a code-golf, so answer with the shortest answer in your favorite language!

Body:
C (Ansi), 193 Bytes

Golfed:

i,y,x;main(g,o,p)char**o;{p=(o[1][0]=='t');while(o[2][++i]!='\n');p?y=(strlen(o[2])-1)/i:(x=i);do do printf("%c",o[2][x+y*i]);while(p?++x<i:x-->0);while(p?x=0,y--:++y<(x=i-1,strlen(o[2])/i));}

Ungolfed:

i,y,x;
main(g,o,p)char**o;{
    p=(o[1][0]=='t');
    while(o[2][++i]!='\n');
    p?y=(strlen(o[2])-1)/i:(x=i);
    do{
        do{
            printf("%c",o[2][x+y*i]);
        }while(p?++x<i:x-->0);
    }while(p?x=0,y--:++y<(x=i-1,strlen(o[2])/i));
}

Usage:

Compilation Arguments:

gcc -O3 -ansi

Example Input:

Input is a t or not t for true of false followed by a newspace lead and trailed string.

./reverseString t "
truck
ducky
quack
moose
"

Example Output:

moose
quack
ducky
truck


答:
x86 machine code, 19 bytes

In hex:

```<code>fc89d35651a401dee2fb91aa595e464a75f1c3
</code>```

Input: ECX: # of strings (n), EDX: individual string length (m), ESI: array of input strings, EDI: output buffer receiving array of strings. Array is presumed to be defined as char src[n][m+1] for input and char dst[m][n+1] for output, and all strings are NULL-terminated.

```<code>0:  fc                  cld
1:  89 d3               mov ebx,edx   ;EDX is the counter for the outer loop
_outer:
3:  56                  push esi
4:  51                  push ecx
_inner:
5:  a4                  movsb         ;[EDI++]=[ESI++]
6:  01 de               add esi,ebx   ;Same char, next string
8:  e2 fb               loop _inner   ;--ECX==0 => break
a:  91                  xchg eax,ecx  ;EAX=0
b:  aa                  stosb         ;NULL-terminate just completed string
c:  59                  pop ecx
d:  5e                  pop esi       ;First string,
e:  46                  inc esi       ;...next char
f:  4a                  dec edx
10: 75 f1               jnz _outer
12: c3                  ret
</code>```

Body:
x86 machine code, 19 bytes

In hex:

fc89d35651a401dee2fb91aa595e464a75f1c3

Input: ECX: # of strings (n), EDX: individual string length (m), ESI: array of input strings, EDI: output buffer receiving array of strings. Array is presumed to be defined as char src[n][m+1] for input and char dst[m][n+1] for output, and all strings are NULL-terminated.

0:  fc                  cld
1:  89 d3               mov ebx,edx   ;EDX is the counter for the outer loop
_outer:
3:  56                  push esi
4:  51                  push ecx
_inner:
5:  a4                  movsb         ;[EDI++]=[ESI++]
6:  01 de               add esi,ebx   ;Same char, next string
8:  e2 fb               loop _inner   ;--ECX==0 => break
a:  91                  xchg eax,ecx  ;EAX=0
b:  aa                  stosb         ;NULL-terminate just completed string
c:  59                  pop ecx
d:  5e                  pop esi       ;First string,
e:  46                  inc esi       ;...next char
f:  4a                  dec edx
10: 75 f1               jnz _outer
12: c3                  ret


问:
Big big numbers
Whilst trying to golf several of my answers, I've needed to write large integers in as few characters as possible.

Now I know the best way to do that: I'll be getting you to be writing this program.

The challenge

Write a program that when given a positive integer, outputs a program that prints it to stdout or equivalent.

The output programs don't have to be in the same language as the creator.

The output must be at most 128 bytes.

You may accept input from stdin or equivalent (not function input)

You may output the resulting program to stdout or equivalent.

The number output must be in decimal (base 10)

Scoring

Your score is equal to the smallest positive integer your program can not encode.

The entry with the largest score wins.

答:
CJam, 233114 ≈ 7.561⋅10269

```<code>ri233b{Kms/m]_34=+c}%s`"{iKms*}%233b"
</code>```

The output program "…"{iKms*}%233b decodes the 8-bit characters of a string to base 233 digits with n ↦ ⌊n ⋅ sin 20⌋ = ⌊n ⋅ 0.913⌋.  This transformation happens to be surjective without requiring the critical codepoints 34 (double quote) and 92 (backslash) as input.

Title: Big big numbers

Body:
CJam, 233114 ≈ 7.561⋅10269

ri233b{Kms/m]_34=+c}%s`"{iKms*}%233b"

The output program "…"{iKms*}%233b decodes the 8-bit characters of a string to base 233 digits with n ↦ ⌊n ⋅ sin 20⌋ = ⌊n ⋅ 0.913⌋.  This transformation happens to be surjective without requiring the critical codepoints 34 (double quote) and 92 (backslash) as input.


问:
Runs of Digits in Pi
Your goal is to output the strictly increasing sequence of consecutive, identical digits of pi (π). Each term in the sequence must be one digit longer than the previous. So 3 (0th digit of pi) is the first time a run of digits occurs (length 1). The next to occur is 33 (digits 24 and 25 of pi). Of course, this sequence requires the digits of pi to be in base 10.

The ones known so far, and the first six all occur within the first 800 digits:

```<code>3
33
111
9999
99999
999999
3333333
44444444
777777777
6666666666
... (not in first 2 billion digits)
</code>```

Note that the consecutive nines all occur together, in the same run, so if the next larger run you found happened to be 1000 consecutive 0s, this would fill in multiple terms of the sequence.

I have not found any more terms with my program. I know there are no more terms within the first 50000 digits or more. My program was taking too long with 500000 digits, so I gave up.

Reference Implementation

You may:

Output the sequence forever

Take an integer n and find the first n numbers in the sequence

Take an integer n and find the numbers in the sequence contained in the first n digits of pi.

Make sure to specify which one your code does. The number n may be zero or one indexed.

Inspired by this mathoverflow question.

答:
Mathematica, 85 bytes

```<code>FromDigits/@DeleteDuplicatesBy[Join@@Subsets/@Split@RealDigits[Pi,10,#][[1]],Length]&
</code>```

Anonymous function. Takes n as input, and returns the elements of the sequence in the first n digits of π. Output is in the form of {0, 3, 33, 111, ...}.

Title: Runs of Digits in Pi

Body:
Mathematica, 85 bytes

FromDigits/@DeleteDuplicatesBy[Join@@Subsets/@Split@RealDigits[Pi,10,#][[1]],Length]&

Anonymous function. Takes n as input, and returns the elements of the sequence in the first n digits of π. Output is in the form of {0, 3, 33, 111, ...}.


答:
Python 2, 298 bytes

Note, the code for generating pi is taken from the OP's implementation.

def p():
 q,r,t,j=1,180,60,2
 while 1:
  u,y=3*(3*j+1)*(3*j+2),(q*(27*j-12)+5*r)//(5*t)
  yield y
  q,r,t,j=10*q*j*(2*j-1),10*u*(q*(5*j-2)+r-y*t),t*u,j+1
p=p()
c=r=0
d=[0]
while 1:
 t=p.next()
 if t==d[len(d)-1]:d.append(t)
 else:d=[t]
 if len(d)>r:r=len(d);print"".join([`int(x)`for x in d])
 c+=1
```

My first attempt at golfing in Python. Outputs the sequence forever.

Title: Runs of Digits in Pi

Body:
Your goal is to output the strictly increasing sequence of consecutive, identical digits of pi (π). Each term in the sequence must be one digit longer than the previous. So 3 (0th digit of pi) is the first time a run of digits occurs (length 1). The next to occur is 33 (digits 24 and 25 of pi). Of course, this sequence requires the digits of pi to be in base 10.

The ones known so far, and the first six all occur within the first 800 digits:

```<code>3
33
111
9999
99999
999999
3333333
44444444
777777777
6666666666
... (not in first 2 billion digits)
</code>```

Note that the consecutive nines all occur together, in the same run, so if the next larger run you found happened to be 1000 consecutive 0s, this would fill in multiple terms of the sequence.

I have not found any more terms with my program. I know there are no more terms within the first 50000 digits or more. My program was taking too long with 500000 digits, so I gave up.

Reference Implementation

You may:

Output the sequence forever

Take an integer n and find the first n numbers in the sequence

Take an integer n and find the numbers in the sequence contained in the first n digits of pi.

Make sure to specify which one your code does. The number n may be zero or one indexed.

Inspired by this mathoverflow question.

Body:
Python 2, 298 bytes

Note, the code for generating pi is taken from the OP's implementation.

def p():
 q,r,t,j=1,180,60,2
 while 1:
  u,y=3*(3*j+1)*(3*j+2),(q*(27*j-12)+5*r)//(5*t)
  yield y
  q,r,t,j=10*q*j*(2*j-1),10*u*(q*(5*j-2)+r-y*t),t*u,j+1
p=p()
c=r=0
d=[0]
while 1:
 t=p.next()
 if t==d[len(d)-1]:d.append(t)
 else:d=[t]
 if len(d)>r:r=len(d);print"".join([`int(x)`for x in d])
 c+=1

My first attempt at golfing in Python. Outputs the sequence forever.


Title: Post-determined Array Sorting

Body:
J, 40 bytes

;@:{[:(<@/:~@}./.~2-64 96 I.3&u:)'aA0'&,


答:
Julia, 59 bytes

```<code>x\y=(y=split(y,'
');! =reverse;join(x?!y:[!a for a=y],'
'))
</code>```

Try it online!

Title: ASCII art reflection

Body:
Julia, 59 bytes

x\y=(y=split(y,'
');! =reverse;join(x?!y:[!a for a=y],'
'))

Try it online!


问:
Fast line drawing algorithm
The task is to find a way to draw a horizontal line in an array of 16-bit integers.

We're assuming a 256x192 pixel array with 16 pixels per word. A line is a contiguous run of set (1) bits. Lines can start in the middle of any word, overlap any other words, and end in any word; they may also start and end in the same word. They may not wrap on to the next line. Hint: the middle words are easy - just write 0xffff, but the edges will be tricky, as will handling the case for the start and end in the same word. A function/procedure/routine must take an x0 and x1 coordinate indicating the horizontal start and stop points, as well as a y coordinate.

I exclude myself from this because I designed a nearly identical algorithm myself for an embedded processor but I'm curious how others would go about it. Bonus points for using relatively fast operations (for example, a 64 bit multiply or floating point operation wouldn't be fast on an embedded machine but a simple bit shift would be.)

答:
Here is a C version of my Python answer using the switch statement instead of the while loop and reduced indexing by incrementing a pointer instead of the array index

The size of the lookup table can be substantially reduced by using T[x1 & 0xf] and U[x2 & 0xf] for a couple of extra instructions

```<code>#include <stdio.h>
#include <math.h>

unsigned short T[] = {0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001};

unsigned short U[] = {0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff};

unsigned short buf[192*16];

void clear(){
    int i;
    for (i=0; i<192*16; i++) buf[i]==0;
}

void render(){
    int x,y;
    for (y=0; y<192; y++){
        for (x=0; x<256; x++) printf("%d", (buf[(y<<4)+(x>>4)]>>(15-(x&15)))&1);
        printf("\n");
    }
}

void drawline(int x1, int x2, int y){
    int y_ = y<<4;
    int x1_ = y_+(x1>>4);
    int x2_ = y_+(x2>>4);
    unsigned short *p = buf+x1_;

    if (x1_==x2_){
        *p|=T[x1]&U[x2];
        return;
        }

    *p++|=T[x1];
    switch (x2_-x1_){
    case 14: *p++ = 0xffff;
    case 13: *p++ = 0xffff;
    case 12: *p++ = 0xffff;
    case 11: *p++ = 0xffff;
    case 10: *p++ = 0xffff;
    case 9: *p++ = 0xffff;
    case 8: *p++ = 0xffff;
    case 7: *p++ = 0xffff;
    case 6: *p++ = 0xffff;
    case 5: *p++ = 0xffff;
    case 4: *p++ = 0xffff;
    case 3: *p++ = 0xffff;
    case 2: *p++ = 0xffff;
    case 1: *p++ = U[x2];
    }
}

int main(){
    int x,y;
    clear();

    for (y=0; y<192; y++){
        drawline(y/2,y,y);
    }

    for (x=10; x<200; x+=6){
        drawline(x,x+2,0);
        drawline(x+3,x+5,1);
    }

    for (y=-49; y<50; y++){
        x = sqrt(2500-y*y);
        drawline(200-x, 200+x, y+60);
    }
    render();
    return 0;
    }
</code>```

Title: Fast line drawing algorithm

Body:
Here is a C version of my Python answer using the switch statement instead of the while loop and reduced indexing by incrementing a pointer instead of the array index

The size of the lookup table can be substantially reduced by using T[x1 & 0xf] and U[x2 & 0xf] for a couple of extra instructions

#include <stdio.h>
#include <math.h>

unsigned short T[] = {0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001,
                      0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff,
                      0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001};

unsigned short U[] = {0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff,
                      0x8000, 0xc000, 0xe000, 0xf000, 0xf800, 0xfc00, 0xfe00, 0xff00,
                      0xff80, 0xffc0, 0xffe0, 0xfff0, 0xfff8, 0xfffc, 0xfffe, 0xffff};

unsigned short buf[192*16];

void clear(){
    int i;
    for (i=0; i<192*16; i++) buf[i]==0;
}

void render(){
    int x,y;
    for (y=0; y<192; y++){
        for (x=0; x<256; x++) printf("%d", (buf[(y<<4)+(x>>4)]>>(15-(x&15)))&1);
        printf("\n");
    }
}

void drawline(int x1, int x2, int y){
    int y_ = y<<4;
    int x1_ = y_+(x1>>4);
    int x2_ = y_+(x2>>4);
    unsigned short *p = buf+x1_;

    if (x1_==x2_){
        *p|=T[x1]&U[x2];
        return;
        }

    *p++|=T[x1];
    switch (x2_-x1_){
    case 14: *p++ = 0xffff;
    case 13: *p++ = 0xffff;
    case 12: *p++ = 0xffff;
    case 11: *p++ = 0xffff;
    case 10: *p++ = 0xffff;
    case 9: *p++ = 0xffff;
    case 8: *p++ = 0xffff;
    case 7: *p++ = 0xffff;
    case 6: *p++ = 0xffff;
    case 5: *p++ = 0xffff;
    case 4: *p++ = 0xffff;
    case 3: *p++ = 0xffff;
    case 2: *p++ = 0xffff;
    case 1: *p++ = U[x2];
    }
}

int main(){
    int x,y;
    clear();

    for (y=0; y<192; y++){
        drawline(y/2,y,y);
    }

    for (x=10; x<200; x+=6){
        drawline(x,x+2,0);
        drawline(x+3,x+5,1);
    }

    for (y=-49; y<50; y++){
        x = sqrt(2500-y*y);
        drawline(200-x, 200+x, y+60);
    }
    render();
    return 0;
    }


答:
J, 29 bytes

```<code>}:@,@(,.&LF@{|."1,:|.)>@cutLF
</code>```

LHS input is the boolean where 0 is false and 1 is true. RHS is the string input.

Title: ASCII art reflection

Body:
J, 29 bytes

}:@,@(,.&LF@{|."1,:|.)>@cutLF

LHS input is the boolean where 0 is false and 1 is true. RHS is the string input.


答:
JavaScript (ES6), 65

Note: 'natural' ASCII order is 0-9, A-Z, a-z, that is just the opposite of the OP 0,1,2. So

order the string adding invalid chars to separate runs

split it in 3 segmenents - invalid chars mark each

get segments one by one in the requested order

reassemble

s=>w=>w.map(w=>[...'^@'+s].sort().join``.split(/\W/)[2-w]).join``
```
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>F=s=>w=>w.map(w=>[...'^@'+s].sort().join``.split(/\W/)[2-w]).join``

;[['201','a1B2c3','123acB']
,['210','aAaA909UuHWw9gh2','02999AAHUWaaghuw']
,['210','6Bx43','346Bx']
,['102','jfjf33g','ffgjj33']
,['021','AbC13','b13AC']
,['120','Qfl0l','Q0fll']
,['012','9870abcABC','abcABC0789']
,['021','test123','estt123']
,['201','WHAT','AHTW']
,['201','WhAt','htAW']
,['102','102BACbac','ABCabc012']]
.forEach(t=>{
  var w=t[0],s=t[1],k=t[2], r=F(s)([...w])
  console.log(w,s,r,(r==k?'OK':'KO (expected '+k+')'))
})</code>```

Title: Post-determined Array Sorting

Body:
Input:

An array containing three integers: 0, 1 and 2 in any order (i.e. [2, 0, 1])

And a string of length >= 2 only containing alphabetic letters (both lower- and uppercase) and digits (i.e. a1B2c3)

Output:

Based on the array we sort and output the string.

How does this work?

The array indicates the order precedence of a-z, A-Z and 0-9, the first being 0; second being 1; and third being 2.

The individual characters of the string can then be ordered based on that.

Example:

Array: [2, 0, 1]

String: a1B2c3

Based on the array, we know our order precedence is 0-9a-zA-Z.

Based on that, we can convert and output the string: 123acB.

Challenge rules:

For the array you can choose to use 0-indexed or 1-indexed input, so [3, 1, 2] is also a valid input if you prefer to use 1-indexed arrays.

The string (both input and output) only contains valid characters: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.

If your language doesn't support arrays (or if you choose to), you are free to use strings instead of arrays for the first parameter (i.e. 012, [0,1,2], etc.).

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

Test cases:

```<code>[2, 0, 1]  &  a1B2c3             ->   123acB
[2, 1, 0]  &  aAaA909UuHWw9gh2   ->   02999AAHUWaaghuw
[2, 1, 0]  &  6Bx43              ->   346Bx
[1, 0, 2]  &  jfjf33g            ->   ffgjj33
[0, 2, 1]  &  AbC13              ->   b13AC
[1, 2, 0]  &  Qfl0l              ->   Q0fll
[0, 1, 2]  &  9870abcABC         ->   abcABC0789
[0, 2, 1]  &  test123            ->   estt123
[2, 0, 1]  &  WHAT               ->   AHTW
[2, 0, 1]  &  WhAt               ->   htAW
[1, 0, 2]  &  102BACbac          ->   ABCabc012
</code>```

Body:
JavaScript (ES6), 65

Note: 'natural' ASCII order is 0-9, A-Z, a-z, that is just the opposite of the OP 0,1,2. So

order the string adding invalid chars to separate runs

split it in 3 segmenents - invalid chars mark each

get segments one by one in the requested order

reassemble

s=>w=>w.map(w=>[...'^@'+s].sort().join``.split(/\W/)[2-w]).join``

F=s=>w=>w.map(w=>[...'^@'+s].sort().join``.split(/\W/)[2-w]).join``

;[['201','a1B2c3','123acB']
,['210','aAaA909UuHWw9gh2','02999AAHUWaaghuw']
,['210','6Bx43','346Bx']
,['102','jfjf33g','ffgjj33']
,['021','AbC13','b13AC']
,['120','Qfl0l','Q0fll']
,['012','9870abcABC','abcABC0789']
,['021','test123','estt123']
,['201','WHAT','AHTW']
,['201','WhAt','htAW']
,['102','102BACbac','ABCabc012']]
.forEach(t=>{
  var w=t[0],s=t[1],k=t[2], r=F(s)([...w])
  console.log(w,s,r,(r==k?'OK':'KO (expected '+k+')'))
})


问:
Is case sensitivity important? Part II: reality check
In this question Tom learned that, in general, there are many motivations to choose to include case sensitivity in his programming language, because the possible combinations for a variable name are much more than what's possible with a case insensitive programming language for a name of the same length.

But, as a more meticulous person than him pointed out, even with case sensitivity, many combinations like A_18__cDfG are wasted anyway because no one will ever use them, so Tom decided to be an even more meticulous person and to redo the calculation of the difference of possibilities of variable names between a case sensitive programming language and a case insensitive programming language only counting the variable names that are likely to be used.

The Challenge

Write a function (or a full program if your language doesn't support them) that takes an input n and returns (or outputs) the difference between the number of possible, valid combinations for a variable name of length n with case sensitivity and a variable name of the same length without case sensitivity.

Valid names

You must only count names in which:

The first character is either an alphabet letter or an underscore, but never a digit;

If there are digits, they must appear at the end of the name, so that x1 and arraysize12 are valid but iam6feettall isn't;

If underscores are present, they must appear at the beginning of the name, like in __private and _VERSION but unlike in __init__ or some_variable;

For case sensitive names, variables like HeLlObOyS aren't counted. A name must be either all uppercase (HELLOBOYS) or all lowercase (helloboys);

There must be at least one alphabetic character. This means _________a9999999999 is valid but __ or _4 arent't.

Rules

Regexs are, of course, allowed;

Blame Tom's meticulousness.

Testcases

```<code>Input (lenght of the varable name) -> Output (differences in valid combinations)
0 -> 0 (no combinations for both cases: 0 - 0 = 0)
1 -> 26
2 -> 962
3 -> 27898
4 -> 754234
5 -> 19898970
6 -> 520262106
</code>```

Scoring

It's again code golf. Shortes program in bytes wins.

Reference, non-competing Lua implementation

Since the test cases may be wrong, I've been asked to include it, so here it is:

```<code>local case = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789"

local function isvalid(s)  --checks if a string s is valid AND only suitable for case sensitive
    if s:upper() == s then --if the string is all uppercase, it's also valid for case unsensitive
        return false
    end
    return (s:match"^_*[%w]+[%d]*$" --checks if it matchs the underscore-character-digit sequence
            and s:lower() == s)     --checks if it's all lowercase
            and true                --trasforms to boolean value
end

local function each(s, n) --recursive function called for character at position 2..n
    if n == 0 then
        if isvalid(s) then
            return 1
        end
        return 0
    else
        local total = 0
        for i = 1, #case do
            total = total + each(s..case:sub(i, i), n - 1)
        end
        return total
    end
end

local function diff(n) --the actual function
    local total = 0
    if n > 0 then
        for s = 1, #case - 10 do --loops for character at position 1, which can't be a digit
            total = total + each(case:sub(s, s), n - 1)
        end
    end
    print(string.format("%.0f", total)) --prints the result in non-scientific notation
end
</code>```

Body:
Haskell, 41 bytes

d n=sum[26^a*10^k|a<-[1..n],k<-[0..n-a]]

Runtime: O(k*n²), where k depends on the size of the resulting numbers.

Results

ghci> forM_ [0..100] $ \n -> printf "%3d: %d\n" n (d n)
  0: 0
  1: 26
  2: 962
  3: 27898
  4: 754234
  5: 19898970
  6: 520262106
  7: 13555703642
  8: 352737183578
  9: 9174055661914
 10: 238554336098650
 11: 6202701627453786
 12: 161273131202687322
 13: 4193130300158759258
 14: 109021676693016629594
 15: 2834566482907321258330
 16: 73698757444479241605466
 17: 1916167982445349170631002
 18: 49820370432467967325294938
 19: 1295329660133056039346557274
 20: 33678571452348345911899378010
 21: 875642860649945882598272717146
 22: 22766714405787481836443979534682
 23: 591934574839363416636432356790618
 24: 15390298948712337721436130165444954
 25: 400147772695409669646228273190457690
 26: 10403842090369540299690823991840788826
 27: 270499894352496936680850312676749398362
 28: 7032997253193809242590997018484373246298
 29: 182857928583327929196254811369482593292634
 30: 4754306143169415047991513984495436314497370
 31: 123611959722433680136668252485770233065820506
 32: 3213910952783564572442263453518914948600222042
 33: 83561684772375567772387738680380677552494661978
 34: 2172603804081793650970970094578786505253750100314
 35: 56487698906126923814134111347937338025486391497050
 36: 1468680171559302908056375783935259677551535067812186
 37: 38185684460541904498354659271205640505228800652005722
 38: 992827795974089805846110029940235542024837705841037658
 39: 25813522695326337840887749667335012981534669240755867994
 40: 671151590078484812751970380239599226408790289148541456730
 41: 17449941342040605420440118775118468775517436406750966763866
 42: 453698474893055743820331977041969077052342235464414024749402
 43: 11796160347219449368217520291980084892249787010963653532373338
 44: 306700169027705683862544416480371096087383351173943880730595674
 45: 7974204394720347783315043717378537387160856019411429787884376410
 46: 207329314262729042395080025540730860955071145393586063373882675546
 47: 5390562170830955102560969552947891273720738669122126536609838453082
 48: 140154616441604832669474097265534062005628094286064178840744688669018
 49: 3644020027481725649435215417792774501035219340326557538748250794283354
 50: 94744520714524866885604489751501025915804591737379384896343409540256090
 51: 2463357538577646539028605622427915562699808274060752896193817536935547226
 52: 64047296003018810014772635072014693519083904014468464189928144849213116762
 53: 1665229696078489060384377400761270920385070393265068957827020654968429924698
 54: 43295972098040715569996701308681932818900719113780681792391425918068066931034
 55: 1125695274549058604819943122914619142180307585847186615491065962758658629095770
 56: 29268077138275523725318810084668986585576886120915740891656603920614013245378906
 57: 760970005595163616858291951090282540113887928032698152071960590824853233268740442
 58: 19785220145474254038315619617236234931849975017739040842759864250335072953876140378
 59: 514415723782330604996206398937030997116988239350103950800645359397600785689668538714
 60: 13374808818340595729901369261251694813930583111991591609705668233226509316820270895450
 61: 347745029276855488977435629681432954051084049800670270741236262952778131126215932170586
 62: 9041370761198242713413326660606145694217074183706315928161031725661120298170503125324122
 63: 235075639791154310548746496064648676938532817665253103021075713756078016641321970147316058
 64: 6111966634570012074267408926569754489290742148185469567436857446546917321563260112719106394
 65: 158911132498820313930952632379702505610448184741711097642247182499108739249533651819585655130
 66: 4131689444969328162204768444761154034760541692173377427587315633865716109376763836198115922266
 67: 107423925569202532217323979592678893792662972885396702006159095369397507732684748630039902867802
 68: 2793022064799265837650423469698540127498126183909203141049025368493224089938692353269926363451738
 69: 72618573684780911778911010215050932203840169670528170556163548469712715227294890073906974338634074
 70: 1888082915804303706251686265620213126188733300322621323349141149101419484798556030810470221693374810
 71: 49090155810911896362543842906414430169795954697277043295966558765525795493651345689961114652916633946
 72: 1276344051083709305426139915569664073303583711018092014584019416792559571723823876827877869864721371482
 73: 33184945328176441941079637804840154794782065375359281268073393725495437753708309686413713505371644547418
 74: 862808578532587490468070582926132913553222588648230201858797125751770270485304940735645440028551647121754
 75: 22433023041847274752169835156082344641272676193742874137217614158434915921506817348015670329631231714054490
 76: 583258599088029143556415714058169849561978469926203616456546857008196702848066139937296317459300913454305626
 77: 15164723576288757732466808565512704977500329106970182916759107171102003162938608527258593142830712638700835162
 78: 394282812983507701044137022703333218303897445670113644724625675337540971125292710597612310602487417495110603098
 79: 10251353137571200227147562590286692564790222476311843651729156447664954138146499364426808964553561743761764569434
 80: 266535181576851205905836627347454295573434673272996823833846956528177696480697872363985921967281494226694767694170
 81: 6929914720998131353551752311033814573798190393986806308568909758621508997387033570352522860038207738782952848937306
 82: 180177782745951415192345560086879207807641839132545852911680542613048122820951761718054483249882290097245662961258842
 83: 4684622351394736795000984562258859691887576706335081064592582996828140082233634693558305453385828431417276125881618778
 84: 121800181136263156670025598618730354877965883253600996568296046806420531026963390921404830676920428105738068161810977114
 85: 3166804709542842073420665564086989255716001853482514799664586105855822695589937052845414486488820019638078661095974293850
 86: 82336922448113893908937304666261720937504937079434273680168127641140278974227252262869665537598209399478934077384220528986
 87: 2140759983650961241632369921322804747264017252954180004573260207558536142218797447723500192866442333275341174900878622642522
 88: 55659759574924992282441617954392923457753337465697569007793654285410828586577622529699893903416389554047759436311733077594458
 89: 1447153748948049799343482066814216010190475662997025683091523900309570432139907074661086130377715017294130634232993948906344794
 90: 37625997472649294782930533737169616267841256126811556649268510296937720124526472830077128278709479338536285378946731560453853530
 91: 978275934288881664356193877166410022992761548185989361769870156609269612126577182470894224135335351690832308741503909460689080666
 92: 25435174291510923273261040806326660598100689141724612294905512960729898804179895633132138716407608032850528916167990534866804986202
 93: 661314531579284005104787060964493175553506806573728808556432225867866257797566175350324495515486697743002640709256642795425818530138
 94: 17194177821061384132724463585076822564420065859805837911356126761453411591625609447997325772291543030206957547329561601569960170672474
 95: 447048623347595987450836053211997386675210601243840674584148184686677590271154734536819358968469007674269785119457490529707853326373210
 96: 11623264207037495673721737383511932053558364521228746428076741690742506235938911986846192222069083088419903301994783642661293075374592346
 97: 302204869382974887516765171971310233392546366440836296018884172848194051023300600546889886662685049187806374740753263598082508848628289882
 98: 7857326603957347075435894471254066068206494416350632585379877382941934215494704503108025942118700167771854632148473742439034118953224425818
 99: 204290491702891023961333256252605717773371743714005336108765700845379178491751205969697563383975093250957109324749206192303775981672723960154
100: 5311552784275166622994664662567748662107694225453027627716797110868747529674420244101025536872241313413773731332368249888787064412379711852890
(0.72 secs, 632,190,360 bytes)

Ungolfed

difference :: Integer -> Integer
difference n = sum [ 26 ^ alpha * 10 ^ digits
                   | alphas <- [1 .. n]
                   , digits <- [0 .. n - alphas]
                   ]

Explanation

All valid names have the structure, namely [underscore]alpha[alpha][digit]. We have at least one alphabet letter, arbitrary many underscores, and arbitrary many digits (as long as the resulting string has the correct length). The position of those is fixed by Tom's rules.

The number of valid case-insenstive combinations can be calculated as follows (a is the number of alphabet letters, u the number of underscores):

$$
c(n) = \sum_{a=1}^n \sum_{u=0}{n-a} 26^a \cdot 10^{n - a - u}
$$

The number of valid case-sensitive combinations can be calculated similarly, we just add \sum_{\{L,U\}}:

$$
C(n) = \sum_{\{L,U\} \sum_{a=1}^n \sum_{u=0}{n-a} 26^a \cdot 10^{n - a - u} \\
     = 2 \sum_{a=1}^n \sum_{u=0}{n-a} 26^a \cdot 10^{n - a - u}
$$

The difference C(n) - c(n) is… c(n):

So all we have to do is to find out is the count of case-insensitive variants.