问:
Sylvester's sequence
Sylvester's sequence, OEIS A000058, is an integer sequence defined as follows:

Each member is the product of all previous members plus one.  The first member of the sequence is 2.

Task

Create a program to calculate the nth term of Sylvester's Sequence.  Standard input, output and loopholes apply.

Standard sequence rules apply.

This is code-golf, so the goal is to minimize the size of your source code as measured in bytes.

Test Cases

You may use either zero or one indexing. (Here I use zero indexing)

```<code>>>0
2
>>1
3
>>2
7
>>3
43
>>4
1807
</code>```

答:
Python 3, <s>71 69 68 63</s> 57 bytes

Python 3, <s>71 69</s> 68 bytes

```<code>l=[2]
for _ in range(int(input())):
    n=1
    for i in l:n*=i
    l+=[n+1]
print(l[-1])
</code>```

Also 68 bytes:

```<code>l=[2]
a=int(input())
while len(l)<a:
    n=1
    for i in l:n*=i
    l+=[n+1]
print(l[-1])
</code>```

EDIT:

Thanks @WheatWizard for pointing out about using n instead of no, and removing the space between for i in l and n*=i.

Also thanks for pointing out about moving int(input()) into the range function.

EDIT 2:

Thanks @WheatWizard for pointing out the iteration tip, it has allowed me to write these two, shorter, programs:

Python 3, 63 bytes

```<code>l=[2]
for _ in"a"*int(input()):
    n=1
    for i in l:n*=i
    l+=[n+1]
print(l[-2])
</code>```

Python 3, 57 bytes

```<code>l=[2]
for _ in"a"*int(input()):
    b=l[-1]
    l+=[(b-1)*b+1]
print(b)
</code>```

The second code (57 bytes) does not follow the instructions for making the sequence (i.e: product of the sequence+1) instead it works on the fact that the last number will always be the product of the rest+1 meaning that instead of iterating through the sequence, I can multiply the last number by itself-1 and then add 1 back on.

Title: Sylvester's sequence

Body:
Python 3, <s>71 69 68 63</s> 57 bytes

Python 3, <s>71 69</s> 68 bytes

l=[2]
for _ in range(int(input())):
    n=1
    for i in l:n*=i
    l+=[n+1]
print(l[-1])

Also 68 bytes:

l=[2]
a=int(input())
while len(l)<a:
    n=1
    for i in l:n*=i
    l+=[n+1]
print(l[-1])

EDIT:

Thanks @WheatWizard for pointing out about using n instead of no, and removing the space between for i in l and n*=i.

Also thanks for pointing out about moving int(input()) into the range function.

EDIT 2:

Thanks @WheatWizard for pointing out the iteration tip, it has allowed me to write these two, shorter, programs:

Python 3, 63 bytes

l=[2]
for _ in"a"*int(input()):
    n=1
    for i in l:n*=i
    l+=[n+1]
print(l[-2])

Python 3, 57 bytes

l=[2]
for _ in"a"*int(input()):
    b=l[-1]
    l+=[(b-1)*b+1]
print(b)

The second code (57 bytes) does not follow the instructions for making the sequence (i.e: product of the sequence+1) instead it works on the fact that the last number will always be the product of the rest+1 meaning that instead of iterating through the sequence, I can multiply the last number by itself-1 and then add 1 back on.


问:
Draw a random hexa-glyph

The above image is called a hexa-glyph.  Hexa-glyphs are some cool patterns I made up while doodling during my DiffEq class.  Here's how you make one:

Consider the following set of points, shaped like a regular hexagram.  The inner hexagon is what will contain the final glyph, while the outer 6 points form a star and are where we will start drawing our lines.

From the outer six points, randomly select a pair.  For efficiency, there should be at least one other point between the two selected points (otherwise, it would have no effect on the final figure).  Then, from each of the two points, cast a ray towards the other.  This ray is blocked by previous lines.

Repeat this process until all 9 edges have been formed, as shown in the next few images.

Here is an example of rays being blocked.  The ends of the ray segment are still visible, but the middle portion is occluded by the first two segments we drew.

These two rays are also "blocked," but this doesn't cause any visible difference because they are blocked by the same other line.

Fast-forwarding until all 9 lines are drawn.  If you want a more detailed explanation of these skipped steps, I can expound.

Finally, remove the points of the star.  To make it look prettier, the thick dots are also removed.

The challenge

You challenge is to output a visual representation of a random hexa-glyph.  This is code-golf, fewest bytes wins.

All possible hexa-glyphs should appear with some positive probability. Different hexa-glyphs are generated by changing the order in which the 9 edges are drawn.

Furthermore, all images output by your program must be valid hexa-glyphs. Certain patterns (like a complete outline of the inner hexagon) cannot possibly appear as a hexa-glyph, and so you program mustn't output these.

The output should be a graphical image (printed to screen or file).

The hexagon must be regular, but can appear in any orientation.

Reflections / rotations are not considered unique.  (This might make requirement 1 easier to follow).

答:
Python, <s>604</s> <s>591</s> <s>574</s> <s>561</s> <s>538</s> <s>531</s> <s>536</s> <s>534</s> <s>528</s> <s>493</s> <s>483</s> <s>452</s> <s>431</s> <s>420</s> <s>419</s> <s>415</s> <s>388</s> <s>385</s> 384 bytes

I have adapted Level River St's idea of checking if a line will be blocked by checking if both endpoints of the line have already been visited before. This saves 27 bytes. Golfing suggestions welcome.

Edit: Bug fixing and golfing g(p,q) for 3 bytes. Golfed L for one byte.

from turtle import*
from random import*
R=range
G=goto
*L,=R(9)
shuffle(L)
a=[0]*13
ht()
T=12
c=[(j.imag,j.real)for j in(1j**(i/3)*T*.75**(i%2/2)for i in R(T))]+[(0,0)]
def g(p,q):pu();G(c[p]);a[p]*a[q]or pd();G(c[q])
for m in L:
 p=2*m;x,y,z=R(p,p+3)
 if m<6:
  if a[x]*a[z%T]<1:g(x,y);g(y,z%T);a[x]=a[y]=a[z%T]=1
 else:
  if a[p-11]*a[p-5]<1:g(p-11,T);g(p-5,T);a[p-11]=a[p-5]=a[T]=1
```

<p><strong>Ungolfing:</strong></p>

<pre class="lang-python prettyprint-override"><code>from turtle import*
from random import*

def draw_line(points, p_1, p_2):
    penup()
    goto(points[p_1])
    if not (a[p] and a[q]):
        pendown()
    goto(points[p_2])

def draw_glyph():
    ht()
    nine_lines = list(range(9))
    shuffle(nine_lines)
    size = 12
    center = [0,0]

    points = []
    for i in range(12):      # put in a point of a dodecagon
                             # if i is even, keep as hexagon point
                             # else, convert to hexagon midpoint
        d = 1j**(i/3) * 12   # dodecagon point
        if i%2:
            d *= .75**.5     # divide by sqrt(3/4) to get midpoint
        points += (d.imag, d.real)
    points.append(center)

    a = [0]*13
    for m in nine_lines:
        p = 2*m
        if m<6:
            x, y, z = p, p+1, p+2
            if not (a[x] and a[z%12]):
                draw_line(points, x, y)
                draw_line(points, y, z%12)
                a[x] = a[y] = a[z%12] = 1
        else:
            if not (a[p-11] and a[p-5]):
                draw_line(p-11, 12)
                draw_line(p-5, 12)
                a[p-11] = a[p-5] = a[12] = 1
</code>```

The hexa-glyphs themselves are quite small as we use a 12-pixel hexagon as a base (for golfing reasons). Here are some example hexa-glyphs (apologies for the poor cropping):

ContentLicense: CC BY-SA 3.0

Title: Draw a random hexa-glyph

Body:
Python, <s>604</s> <s>591</s> <s>574</s> <s>561</s> <s>538</s> <s>531</s> <s>536</s> <s>534</s> <s>528</s> <s>493</s> <s>483</s> <s>452</s> <s>431</s> <s>420</s> <s>419</s> <s>415</s> <s>388</s> <s>385</s> 384 bytes

I have adapted Level River St's idea of checking if a line will be blocked by checking if both endpoints of the line have already been visited before. This saves 27 bytes. Golfing suggestions welcome.

Edit: Bug fixing and golfing g(p,q) for 3 bytes. Golfed L for one byte.

from turtle import*
from random import*
R=range
G=goto
*L,=R(9)
shuffle(L)
a=[0]*13
ht()
T=12
c=[(j.imag,j.real)for j in(1j**(i/3)*T*.75**(i%2/2)for i in R(T))]+[(0,0)]
def g(p,q):pu();G(c[p]);a[p]*a[q]or pd();G(c[q])
for m in L:
 p=2*m;x,y,z=R(p,p+3)
 if m<6:
  if a[x]*a[z%T]<1:g(x,y);g(y,z%T);a[x]=a[y]=a[z%T]=1
 else:
  if a[p-11]*a[p-5]<1:g(p-11,T);g(p-5,T);a[p-11]=a[p-5]=a[T]=1

Ungolfing:

from turtle import*
from random import*

def draw_line(points, p_1, p_2):
    penup()
    goto(points[p_1])
    if not (a[p] and a[q]):
        pendown()
    goto(points[p_2])

def draw_glyph():
    ht()
    nine_lines = list(range(9))
    shuffle(nine_lines)
    size = 12
    center = [0,0]

    points = []
    for i in range(12):      # put in a point of a dodecagon
                             # if i is even, keep as hexagon point
                             # else, convert to hexagon midpoint
        d = 1j**(i/3) * 12   # dodecagon point
        if i%2:
            d *= .75**.5     # divide by sqrt(3/4) to get midpoint
        points += (d.imag, d.real)
    points.append(center)

    a = [0]*13
    for m in nine_lines:
        p = 2*m
        if m<6:
            x, y, z = p, p+1, p+2
            if not (a[x] and a[z%12]):
                draw_line(points, x, y)
                draw_line(points, y, z%12)
                a[x] = a[y] = a[z%12] = 1
        else:
            if not (a[p-11] and a[p-5]):
                draw_line(p-11, 12)
                draw_line(p-5, 12)
                a[p-11] = a[p-5] = a[12] = 1

The hexa-glyphs themselves are quite small as we use a 12-pixel hexagon as a base (for golfing reasons). Here are some example hexa-glyphs (apologies for the poor cropping):


问:
Find the right path
Given a list of paths, output the correct path.

Example of path:

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

- and | are horizontal and vertical paths.

/ and \ are 90° turns.

+ is treated as a - or a | depending of the current direction.

Paths may go in any direction and a character may be used in multiple paths.

Input will be like this:

```<code>       /--\
A------+--+--#
B------/  \--:
C------------#
D------------#
</code>```

A, B, C and D are path starts

# is a wall (the path is bad)

: is the end (the path is correct)

So here the output will be B.

You can assume:

: and # will always be reached from the left.

The character at the right of the start of a path will always be -.

Paths will always be well formed.

# and : will always be in the same column.

There will always be only one : and 4 paths.

Test cases

```<code>A------#
B------#
C------#
D------:
=>
D
</code>```

```<code>A-\ /---:
B-+-/ /-#
C-+---+-#
D-+---/
  \-----#
=>
B
</code>```

```<code>  /-\
A-+\\---#
B-/\-\/-#
C----++-#
D----+/
     \--:
=>
A
</code>```

```<code>A-\
B-+\
C-++\/----#
D-+++//---:
  \++-//--#
   \+--//-#
    \---/
=>
A
</code>```

```<code>  /-\
A-+-/-\
B-+-+-\--#
C-+-/ |/-#
D-\---++-#
  \---+/
      \--:
=>
B
</code>```

Since this is code-golf, the shortest answer win.

答:
Python, 221 bytes

```<code>def P(s,c=""):
 l=s.split("\n")
 v=[0,-1]
 p=[(i,l[i].index(":"))for i in range(len(l))if":"in l[i]][0]
 while c in"-:|+/\\":
    p=map(sum,zip(p,v))
    c=l[p[0]][p[1]]
    v=v[::1-(c=="\\")*2]
    if"/"==c:v=[-v[1],-v[0]]
 return c
</code>```

The first indention is just one space, in the while loop it's a tab.

Title: Find the right path

Body:
Python, 221 bytes

def P(s,c=""):
 l=s.split("\n")
 v=[0,-1]
 p=[(i,l[i].index(":"))for i in range(len(l))if":"in l[i]][0]
 while c in"-:|+/\\":
    p=map(sum,zip(p,v))
    c=l[p[0]][p[1]]
    v=v[::1-(c=="\\")*2]
    if"/"==c:v=[-v[1],-v[0]]
 return c

The first indention is just one space, in the while loop it's a tab.


问:
Visible Buildings
This puzzle is derived from CodinGame SamSi's "Heart of the City" puzzle.

Description

You decide to take a walk in an n * n tile city and go to the center tile. All of the buildings are infinitely small, but you have super vision and can see everything close up and far away.

Constraints

n is always odd

You can see any building that is not directly obstructed by another one

Task

Mark each building visible with *. The building is visible iff it is not blocked by another building on the exact same line of vision.

In other words, if @ is the origin, the building is visible iff the x-coordinate and the y-coordinate are co-prime to each other.

Example input and output

Input:

```<code>7
</code>```

Output:

```<code> ** **
* * * *
*******
  *@*
*******
* * * *
 ** **
</code>```

* is a visible building,
 is an invisible building, and
@ is where you are.

Scoring

Remember, this is code-golf, so the answer with the least bytes wins.

var QUESTION_ID=91394,OVERRIDE_USER=59057;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}*{font-family:"Helvetica",sans-serif}</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

```

答:
Excel-VBA, (47*n^2) bytes and 121 bytes

Instruction:

Excel turns out to be very handy for this challenge and there are combination of Excel formulas to get the exact pattern as the OP's shown for a given input. Luckily enough for me, Excel has a GCD function - a built-in formula to return greatest common divisor of positive integers so I don't have to create one using Euclidean algorithm.  Why do I need a GCD function here? It's because two numbers are called coprime, if their greatest common divisor equals 1. The numbers here is the coordinate of the position, x and y, relative to the origin, @. Here is the Excel formula

```<code>=IF(GCD(ABS(COLUMN()-m),ABS(m-ROW()))=1,"*","")
</code>```

where m is the name of a reference cell and it's equal to the smallest integer greater than or equal to n/2, ceiling(n/2), where n is the name of a reference cell for the input. Paste this formula in cell A1, then drag all over range with the size n x n. The length of the formula is 47 bytes but you have to replicate it n x n times, so it's equal to (47*n^2) bytes.

To automate the process and to reduce the use of characters, we can use VBA since it's integrated with Excel. First thing first, set a worksheet Excel like the following:

Then put the following code in the Immediate Window

```<code>n=[A1]:m=Int(n/2)+1:Range("A1",Cells(n,n))="=IF(GCD(ABS(COLUMN()-"&m &"),ABS("&m &"-ROW()))=1,""*"","""")":Cells(m,m)="@"
</code>```

Ungolfed the code:

```<code>Sub A()
    n = [A1]
    m = Int(n / 2) + 1
    Range("A1", Cells(n, n)) = "=IF(GCD(ABS(COLUMN()-" & m & "),ABS(" & m & "-ROW()))=1,""*"" ,"""")"
    Cells(m, m) = "@"
End Sub
</code>```

Explanation:

n = [A1] : Set n as the input and assign the value of cell A1 to n.

m = Int(n / 2) + 1 : Custom way to return the same output as the ceiling function for argument n/2.

Range("A1", Cells(n, n)) = "=IF(GCD(ABS(COLUMN()-" & m & "),ABS(" & m & "-ROW()))=1,""*"" ,"""")" :  Paste the formula above to every cell in the range with size n x n start from cell A1.

Cells(m, m) = "@"  :  Assign the center of the range with a character @.

Output:

Figure below is the example output for the input n = 11

I set the font color to red to make it look more attractive. Even better

Title: Visible Buildings

Body:
Excel-VBA, (47*n^2) bytes and 121 bytes

Instruction:

Excel turns out to be very handy for this challenge and there are combination of Excel formulas to get the exact pattern as the OP's shown for a given input. Luckily enough for me, Excel has a GCD function - a built-in formula to return greatest common divisor of positive integers so I don't have to create one using Euclidean algorithm.  Why do I need a GCD function here? It's because two numbers are called coprime, if their greatest common divisor equals 1. The numbers here is the coordinate of the position, x and y, relative to the origin, @. Here is the Excel formula

=IF(GCD(ABS(COLUMN()-m),ABS(m-ROW()))=1,"*","")

where m is the name of a reference cell and it's equal to the smallest integer greater than or equal to n/2, ceiling(n/2), where n is the name of a reference cell for the input. Paste this formula in cell A1, then drag all over range with the size n x n. The length of the formula is 47 bytes but you have to replicate it n x n times, so it's equal to (47*n^2) bytes.

To automate the process and to reduce the use of characters, we can use VBA since it's integrated with Excel. First thing first, set a worksheet Excel like the following:

Then put the following code in the Immediate Window

n=[A1]:m=Int(n/2)+1:Range("A1",Cells(n,n))="=IF(GCD(ABS(COLUMN()-"&m &"),ABS("&m &"-ROW()))=1,""*"","""")":Cells(m,m)="@"

Ungolfed the code:

Sub A()
    n = [A1]
    m = Int(n / 2) + 1
    Range("A1", Cells(n, n)) = "=IF(GCD(ABS(COLUMN()-" & m & "),ABS(" & m & "-ROW()))=1,""*"" ,"""")"
    Cells(m, m) = "@"
End Sub

Explanation:

n = [A1] : Set n as the input and assign the value of cell A1 to n.

m = Int(n / 2) + 1 : Custom way to return the same output as the ceiling function for argument n/2.

Range("A1", Cells(n, n)) = "=IF(GCD(ABS(COLUMN()-" & m & "),ABS(" & m & "-ROW()))=1,""*"" ,"""")" :  Paste the formula above to every cell in the range with size n x n start from cell A1.

Cells(m, m) = "@"  :  Assign the center of the range with a character @.

Output:

Figure below is the example output for the input n = 11

I set the font color to red to make it look more attractive. Even better


问:
Mathematical Combination
Write a program that takes an input such as:

```<code>n,k
</code>```

which then computes:

$$\binom n k = \frac {n!} {k!(n-k)!}$$

and then prints the result.

A numerical example:

Input:

```<code>5,2
</code>```

Internal computation:

$$\frac {5!} {3!\times2!}$$

Printed Output:

```<code>10
</code>```

I'd like to see an answer that beats my python solution of 65 characters, but all languages are obviously welcome.

Here's my solution:

```<code>n,k=input();f=lambda x:+(x<2)or x*f(x-1);print f(n)/(f(k)*f(n-k))
</code>```

Edit:

I admit that this question is from the codegolf website mathematical combination puzzle.  I know that my answer may look like not much progress can be made on it, but the leaders of this puzzle have solved it in nearly half as many characters.

答:
Python (52)

```<code> f=lambda n,k:k<1or f(n-1,k-1)*n/k;print+f(*input())
</code>```

Improved from the other two by using print+ to convert the result of f from boolean to int in case k==0.

Still have no idea how to shrink it to 39, I wonder whether they are using lambda at all.

ContentLicense: CC BY-SA 4.0

Title: Mathematical Combination

Body:
Python (52)

 f=lambda n,k:k<1or f(n-1,k-1)*n/k;print+f(*input())

Improved from the other two by using print+ to convert the result of f from boolean to int in case k==0.

Still have no idea how to shrink it to 39, I wonder whether they are using lambda at all.


问:
Excessive Integers
For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where p1,...,pk are primes and e1,...,ek are positive integers, we can define two functions:

Ω(n) = e1+e2+...+ek the number of prime divisors (counted with multiplicity) (A001222)

ω(n) = k the number of distinct prime divisors. (A001221)

With those two functions we define the excess e(n) = Ω(n) - ω(n) (A046660). This can be considered as a measure of how close a number is to being squarefree.

Challenge

For a given positive integer n return e(n).

Examples

For n = 12 = 2^2 * 3 we have Ω(12) = 2+1 and ω(12) = 2 and therefore e(12) = Ω(12) - ω(12) = 1. For any squarefree number n we obivously have e(n) = 0. The first few terms are

```<code>1       0
2       0
3       0
4       1
5       0
6       0
7       0
8       2
9       1
10      0
11      0
12      1
13      0
14      0
15      0
</code>```

Some more details in the OEIS wiki.

答:
Pyth, 7 bytes

```<code>-lPQl{P
</code>```

Try it online.

Title: Excessive Integers

Body:
Pyth, 7 bytes

-lPQl{P

Try it online.


答:
MATL, <s>7</s> 5 bytes

```<code>Yfd~s
</code>```

Try it online! Or verify all test cases.

Explanation

```<code>Yf    % Implicit input. Obtain prime factors, sorted and with repetitions
d     % Consecutive differences
~     % Logical negate: zeros become 1, nonzeros become 0
s     % Sum. Implicit display
</code>```

Title: Excessive Integers

Body:
For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where p1,...,pk are primes and e1,...,ek are positive integers, we can define two functions:

Ω(n) = e1+e2+...+ek the number of prime divisors (counted with multiplicity) (A001222)

ω(n) = k the number of distinct prime divisors. (A001221)

With those two functions we define the excess e(n) = Ω(n) - ω(n) (A046660). This can be considered as a measure of how close a number is to being squarefree.

Challenge

For a given positive integer n return e(n).

Examples

For n = 12 = 2^2 * 3 we have Ω(12) = 2+1 and ω(12) = 2 and therefore e(12) = Ω(12) - ω(12) = 1. For any squarefree number n we obivously have e(n) = 0. The first few terms are

```<code>1       0
2       0
3       0
4       1
5       0
6       0
7       0
8       2
9       1
10      0
11      0
12      1
13      0
14      0
15      0
</code>```

Some more details in the OEIS wiki.

Body:
MATL, <s>7</s> 5 bytes

Yfd~s

Try it online! Or verify all test cases.

Explanation

Yf    % Implicit input. Obtain prime factors, sorted and with repetitions
d     % Consecutive differences
~     % Logical negate: zeros become 1, nonzeros become 0
s     % Sum. Implicit display


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

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

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

"A", whether uppercase or lowercase.

"U", whether lowercase or uppercase.

X, whether uppercase or lowercase.

+

&

#

0

1

4

5

6

7

9

Cheating, loopholes, etc, are not allowed.

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

Validity Checker

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

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

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

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

<h3>Leaderboard</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var QUESTION_ID=90349,OVERRIDE_USER=58717;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;</code>```

body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table></code>```

答:
Microscript II, 6 bytes

```<code>2s'C-K
</code>```

Basically subtracts 2 from the char code of C, then converts back to a character before printing implicitly.

In the original Microscript, it becomes this 7-byte program:

```<code>2s'C-Ph
</code>```

Title: The Letter A without A

Body:
Microscript II, 6 bytes

2s'C-K

Basically subtracts 2 from the char code of C, then converts back to a character before printing implicitly.

In the original Microscript, it becomes this 7-byte program:

2s'C-Ph


答:
Jelly, 5 bytes

```<code>ÆfI¬S
</code>```

Try it online!

Verify all testcases.

Port of Luis Mendo's answer in MATL.

```<code>ÆfI¬S

Æf     Implicit input. Obtain prime factors, sorted and with repetitions
  I    Consecutive differences
   ¬   Logical negate: zeros become 1, nonzeros become 0
    S  Sum. Implicit display
</code>```

Title: Excessive Integers

Body:
Jelly, 5 bytes

ÆfI¬S

Try it online!

Verify all testcases.

Port of Luis Mendo's answer in MATL.

ÆfI¬S

Æf     Implicit input. Obtain prime factors, sorted and with repetitions
  I    Consecutive differences
   ¬   Logical negate: zeros become 1, nonzeros become 0
    S  Sum. Implicit display


答:
Brachylog, 11 bytes

```<code>$pPd:Pr:la-
</code>```

Try it online!

Explanation

```<code>$pP            P is the list of prime factors of the Input
  Pd           Remove all duplicates in P
    :Pr        Construct the list [P, P minus duplicates]
       :la     Apply "length" to the two elements of that list
          -    Output is the subtraction of the first element by the second one
</code>```

Title: Excessive Integers

Body:
Brachylog, 11 bytes

$pPd:Pr:la-

Try it online!

Explanation

$pP            P is the list of prime factors of the Input
  Pd           Remove all duplicates in P
    :Pr        Construct the list [P, P minus duplicates]
       :la     Apply "length" to the two elements of that list
          -    Output is the subtraction of the first element by the second one


答:
Mathematica, 23 bytes

```<code>PrimeOmega@#-PrimeNu@#&
</code>```

Very boring. FactorInteger already takes up 13 bytes, and I can't see much that can be done with the remaining 10.

Title: Excessive Integers

Body:
Mathematica, 23 bytes

PrimeOmega@#-PrimeNu@#&

Very boring. FactorInteger already takes up 13 bytes, and I can't see much that can be done with the remaining 10.


问:
The Burnt Pancake Problem
This challenge is related to Flipping Pancakes.

You may have heard of pancake sorting, where a stack of pancakes is sorted by size by inserting spatula into the stack and flipping all of the pancakes above the spatula, until the pancakes are sorted smallest to largest on the plate. The burnt pancake problem is slightly different. All pancakes now have one side that is burnt, and the burnt side of each pancake must face the plate once the sorting is completed.

For example, given the following stack (size of pancake on the left. 0 meaning burnt-side down and 1 meaning burnt-side up on the right):

```<code>1 0
3 1
2 1
</code>```

You may flip the whole stack to get 20 30 11, flip the top two to get 31 21 11 and flip the whole stack again to get 10 20 30, a sorted stack of burnt pancakes. This sequence of moves, flip 3, flip 2, flip 3, could be represented as 3 2 3.

The Challenge

Given an array of pancakes sizes (not necessarily unique) and their orientations, output any valid burnt pancake sorting sequence, that is, a sequence of flips that leads to the stack of pancakes being sorted from smallest to largest with burnt sides down.

Input and output may be any sane format with separators, but please specify which formats you use and state which end of your input format is the top of the stack (TOS).

Flipping zero pancakes is allowed.

Mixing separators in the input/output is allowed.

Test cases

For all of the following test cases, input is a list and output is a space-separated string, and TOS is on the left.

```<code>[[1, 0], [3, 1], [2, 1]]
"3 2 3"

[[5, 1], [3, 0], [4, 1], [2, 1], [1, 0]]
"5 3 4 1 3 2 1"

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

As always, if anything is unclear or incorrect, please let me know in the comments. Good luck and good golfing!

答:
Ruby, <s>101</s> <s>95</s> 93 bytes

Not very golfy, I just wanted to make a bogo-sort variant. It's an anonymous function that takes an array of arrays and prints random flips to stdout until the pancakes are sorted.

->a{(p r=-~rand(a.size)
a[0,r]=a[0,r].reverse.map{|x,b|[x,1-b]})while a!=a.sort||a.rassoc(1)}
```

You can for example assign it to f and say f.call [[1, 0], [3, 1], [2, 1]]

-5 bytes from @Jordan with the brilliant use of rassoc

-2 bytes from @Sherlock9

Title: The Burnt Pancake Problem

Body:
Ruby, <s>101</s> <s>95</s> 93 bytes

Not very golfy, I just wanted to make a bogo-sort variant. It's an anonymous function that takes an array of arrays and prints random flips to stdout until the pancakes are sorted.

->a{(p r=-~rand(a.size)
a[0,r]=a[0,r].reverse.map{|x,b|[x,1-b]})while a!=a.sort||a.rassoc(1)}

You can for example assign it to f and say f.call [[1, 0], [3, 1], [2, 1]]

-5 bytes from @Jordan with the brilliant use of rassoc

-2 bytes from @Sherlock9


Title: Excessive Integers

Body:
C, 74 bytes

f(n,e,r,i){r=0;for(i=2;n>1;i++,r+=e?e-1:e)for(e=0;n%i<1;e++)n/=i;return r;}

Ideone it!


问:
Pseudosort a list in 2*n comparisons
Write a program that takes a list of n space-separated integers, and outputs a permutation of that list using a maximum of 2*n comparisons.

It should loop this until an empty line is input.  Alternatively, it can accept inputs until an empty line is given, then output all the permutations.

Though your program only has to work on integers, it should be possible to implement your algorithm for any comparable data structures.  For example, using sign(a-b) to get extra comparisons is illegal, because the same algorithm can't be applied to data structures without numerical values.

Example session:

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

or

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

note: > shouldn't actually be printed, it's just being used to notate input vs output.

Scoring

Scoring is based mostly on how well sorted the permutations are, but also favours concise code.

Run your program with this file as input.  Use your program's output as input to this python script.  This script works under both python 2.7 and 3.3.  Other versions weren't tested.

```<code>import sys
def score(l):
    n = len(l)
    w = n**2 // 2
    s = sum(abs(l[i]-i)for i in range(n))
    return float(s)/w
s = 0.0
for i in range(40000):
    s += score([int(n) for n in sys.stdin.readline().split()])
print (int(s))
</code>```

Your score is the output of the above script plus the length of your program

Explanation of Scoring

In the input file, there are 1000 lists for each length n in the range 10 <= n < 50.  In total, there are 40000 lists.  No two elements of a list will be equal.

To score a list, we define the unsortedness of a list as the sum of distances of each element from where it should be.  For example, for the list [0,1,4,3,2], the unsortedness is 4, because 4 and 2 are each 2 positions from where they should be, and the rest of the numbers are correct.

The worst case unsortedness of a list of length n is n^2 / 2, using integer division.

The score of a list is its unsortednes divided by the maximum unsortedness.  This is a number between 0.0 (sorted) and 1.0 (reversed).

Your total score is the sum of all scores in the input rounded down to an integer, plus the length of your program.  Because there are 40000 cases, a better pseudo-sort is likely better than shorter code, but if there is some optimal solution, then the shortest implementation of that solution will win.

答:
Ruby, 10140 (9988 + 152)

```<code>def q a
  p=a.pop
  l,m=a.partition{|x|x<p}
  [l,p,m]
end
while a=gets
  a=a.split.map(&:to_i)
  l,p,m=q a
  puts (q(l)+[p]+q(m)).flatten.join(" ")
end
</code>```

This simply performs two rounds of quicksort. It removes the last element, then divides the remaining array into those less than and those greater than that element (n-1 comparisons).  Then it does the same thing to those two (n-3 comparisons) and joins the result in order. Total comparisons are 2*n - 4 (worst case 2*n - 2), so there's definitely room for improvement.

Title: Pseudosort a list in 2*n comparisons

Body:
Ruby, 10140 (9988 + 152)

def q a
  p=a.pop
  l,m=a.partition{|x|x<p}
  [l,p,m]
end
while a=gets
  a=a.split.map(&:to_i)
  l,p,m=q a
  puts (q(l)+[p]+q(m)).flatten.join(" ")
end

This simply performs two rounds of quicksort. It removes the last element, then divides the remaining array into those less than and those greater than that element (n-1 comparisons).  Then it does the same thing to those two (n-3 comparisons) and joins the result in order. Total comparisons are 2*n - 4 (worst case 2*n - 2), so there's definitely room for improvement.


答:
Python 2, <s>100</s> <s>99</s> <s>98</s> 96 bytes

n=input()
i=2
f=[]
while i<n:
 if n%i:i+=1
 else:n/=i;f+=i,
if-~n:f+=n,
print len(f)-len(set(f))
```

Most of the code is taken up by a golfed version of this SO answer, which stores the prime factors of the input in f. Then we simply use set manipulation to calculate the excess factors.

Thanks to Leaky Nun for saving <s>1</s> 3 bytes!

Title: Excessive Integers

Body:
Python 2, <s>100</s> <s>99</s> <s>98</s> 96 bytes

n=input()
i=2
f=[]
while i<n:
 if n%i:i+=1
 else:n/=i;f+=i,
if-~n:f+=n,
print len(f)-len(set(f))

Most of the code is taken up by a golfed version of this SO answer, which stores the prime factors of the input in f. Then we simply use set manipulation to calculate the excess factors.

Thanks to Leaky Nun for saving <s>1</s> 3 bytes!


答:
05AB1E, 6 bytes

```<code>Òg¹fg-
</code>```

Explanation

```<code>Òg      # number of prime factors with duplicates
     -  # minus
  ¹fg   # number of prime factors without duplicates
</code>```

Try it online!

Title: Excessive Integers

Body:
05AB1E, 6 bytes

Òg¹fg-

Explanation

Òg      # number of prime factors with duplicates
     -  # minus
  ¹fg   # number of prime factors without duplicates

Try it online!


问:
Where are Champernowne's zeroes?
Consider the infinite string of all nonnegative decimal integers concatenated together in order (akin to Champernowne's constant):

```<code>0123456789101112131415161718192021222324252627282930...979899100101102103...
</code>```

Write a program or function that takes in a nonnegative integer that indexes (0-based) into this infinite string. Output a truthy value if the digit indexed is 0, otherwise output a falsy value if the digit is 1-9.

The shortest code in bytes wins.

The first 25 truthy-producing inputs are:

```<code>0
11
31
51
71
91
111
131
151
171
191
192
194
197
200
203
206
209
212
215
218
222
252
282
312
</code>```

Kudos if your program is memory effecient, but this is not a requirement.

答:
05AB1E, 5 bytes

Code:

```<code>ÝJ¹è_
</code>```

Explanation:

```<code>Ý      # Get the list [0 .. input].
 J     # Join the list.
  ¹    # Get the first input again.
   è   # Get the character on that index.
    _  # Logical negate (0 -> 1, everything else -> 0).
</code>```

Uses the CP-1252 encoding. Try it online!

Title: Where are Champernowne's zeroes?

Body:
05AB1E, 5 bytes

Code:

ÝJ¹è_

Explanation:

Ý      # Get the list [0 .. input].
 J     # Join the list.
  ¹    # Get the first input again.
   è   # Get the character on that index.
    _  # Logical negate (0 -> 1, everything else -> 0).

Uses the CP-1252 encoding. Try it online!


答:
Python 3, 44 bytes

```<code>lambda n:''.join(map(str,range(n+1)))[n]<'1'
</code>```

An anonymous function that takes input via argument and returns True or False as appropriate.

How it works

```<code>lambda n      Anonymous function with input n
range(n+1)    Yield the range [0, n]...
map(str,...)  ...convert all elements to string...
''.join(..)   ...concatenate...
...[n]        ...yield nth character...
:...<'1'      ...return True if int(character)==0 else return False
</code>```

Try it on Ideone

Title: Where are Champernowne's zeroes?

Body:
Consider the infinite string of all nonnegative decimal integers concatenated together in order (akin to Champernowne's constant):

```<code>0123456789101112131415161718192021222324252627282930...979899100101102103...
</code>```

Write a program or function that takes in a nonnegative integer that indexes (0-based) into this infinite string. Output a truthy value if the digit indexed is 0, otherwise output a falsy value if the digit is 1-9.

The shortest code in bytes wins.

The first 25 truthy-producing inputs are:

```<code>0
11
31
51
71
91
111
131
151
171
191
192
194
197
200
203
206
209
212
215
218
222
252
282
312
</code>```

Kudos if your program is memory effecient, but this is not a requirement.

Body:
Python 3, 44 bytes

lambda n:''.join(map(str,range(n+1)))[n]<'1'

An anonymous function that takes input via argument and returns True or False as appropriate.

How it works

lambda n      Anonymous function with input n
range(n+1)    Yield the range [0, n]...
map(str,...)  ...convert all elements to string...
''.join(..)   ...concatenate...
...[n]        ...yield nth character...
:...<'1'      ...return True if int(character)==0 else return False

Try it on Ideone


答:
MATL, 11 bytes

```<code>Qt:qVXzw)U~
</code>```

Try it Online!

Explanation:

```<code>    % Implicitly grab input as an integer (N)
Qt  % Add 1 and duplicate
:q  % Create an array from [0 ... N]
V   % Convert each entry to a string (places spaces between each number)
Xz  % Remove all whitespace
w)  % Get the N+1 element of the string (since MATL uses 1-based indexing natively)
U~  % Convert the result back to a number and negate which yields TRUE if it was '0' and
    % FALSE otherwise
</code>```

Title: Where are Champernowne's zeroes?

Body:
MATL, 11 bytes

Qt:qVXzw)U~

Try it Online!

Explanation:

    % Implicitly grab input as an integer (N)
Qt  % Add 1 and duplicate
:q  % Create an array from [0 ... N]
V   % Convert each entry to a string (places spaces between each number)
Xz  % Remove all whitespace
w)  % Get the N+1 element of the string (since MATL uses 1-based indexing natively)
U~  % Convert the result back to a number and negate which yields TRUE if it was '0' and
    % FALSE otherwise


答:
Mathematica, <s>42</s> 40 bytes

```<code>(0@@Join@@IntegerDigits@Range@#)[[#]]<1&
</code>```

Anonymous function. Takes a number as input and returns either True or False as output. A longer, yet more efficient(?) solution:

```<code>RealDigits[ChampernowneNumber[],10,1,-#][[1,1]]<1&
</code>```

Title: Where are Champernowne's zeroes?

Body:
Mathematica, <s>42</s> 40 bytes

(0@@Join@@IntegerDigits@Range@#)[[#]]<1&

Anonymous function. Takes a number as input and returns either True or False as output. A longer, yet more efficient(?) solution:

RealDigits[ChampernowneNumber[],10,1,-#][[1,1]]<1&


答:
Kotlin, 22 bytes

```<code>{print("${3<2}"[3-2])}
</code>```

This is a lambda that prints a to the console when invoked. Converts false (3<2) to string via string template and returns the 1-indexed character.

Title: The Letter A without A

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

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

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

"A", whether uppercase or lowercase.

"U", whether lowercase or uppercase.

X, whether uppercase or lowercase.

+

&

#

0

1

4

5

6

7

9

Cheating, loopholes, etc, are not allowed.

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

Validity Checker

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

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

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

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

<h3>Leaderboard</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var QUESTION_ID=90349,OVERRIDE_USER=58717;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;</code>```

body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table></code>```

Body:
Kotlin, 22 bytes

{print("${3<2}"[3-2])}

This is a lambda that prints a to the console when invoked. Converts false (3<2) to string via string template and returns the 1-indexed character.


答:
J, <s>11</s> 10 bytes

Saved 1 byte thanks to Jonah.

```<code>1#.1-~:@q:
</code>```

Title: Excessive Integers

Body:
For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where p1,...,pk are primes and e1,...,ek are positive integers, we can define two functions:

Ω(n) = e1+e2+...+ek the number of prime divisors (counted with multiplicity) (A001222)

ω(n) = k the number of distinct prime divisors. (A001221)

With those two functions we define the excess e(n) = Ω(n) - ω(n) (A046660). This can be considered as a measure of how close a number is to being squarefree.

Challenge

For a given positive integer n return e(n).

Examples

For n = 12 = 2^2 * 3 we have Ω(12) = 2+1 and ω(12) = 2 and therefore e(12) = Ω(12) - ω(12) = 1. For any squarefree number n we obivously have e(n) = 0. The first few terms are

```<code>1       0
2       0
3       0
4       1
5       0
6       0
7       0
8       2
9       1
10      0
11      0
12      1
13      0
14      0
15      0
</code>```

Some more details in the OEIS wiki.

Body:
J, <s>11</s> 10 bytes

Saved 1 byte thanks to Jonah.

1#.1-~:@q:


答:
CJam, 9 bytes

```<code>{_),s=~!}
</code>```

This is an unnamed block (function) which takes in an integer and returns 0 or 1 accordingly.

Explanation:

```<code>{       }        Defines a block
 _               Copy input n
  ),             Increment n and take range
    s            Convert to string - for a list of numbers this concatenates
                 the digits
     =           Index, getting nth digit
      ~          Evaluate the digit character into a number
       !         Logical negation
</code>```

Online interpreter. Note that ~ evaluates a block. Alternative, you can run this test suite which uses , to filter the first 1000 numbers for truthy values.

Title: Where are Champernowne's zeroes?

Body:
CJam, 9 bytes

{_),s=~!}

This is an unnamed block (function) which takes in an integer and returns 0 or 1 accordingly.

Explanation:

{       }        Defines a block
 _               Copy input n
  ),             Increment n and take range
    s            Convert to string - for a list of numbers this concatenates
                 the digits
     =           Index, getting nth digit
      ~          Evaluate the digit character into a number
       !         Logical negation

Online interpreter. Note that ~ evaluates a block. Alternative, you can run this test suite which uses , to filter the first 1000 numbers for truthy values.


问:
Who's that Pokémon?
Input: an integer N between 1 and 151

Output: the Nth Pokemon.

Rules

You may use one data file.

You may not use any already made data decompression algorithms.  This includes libraries and other programs.

Your program may not access files other than itself and your data file.

Scoring

Your score is the sum of the length of your code and data file.

Helpful Stuff

Here's a list of the first 151 pokemon separated by semicolons to help you generate your data file.  Your output should exactly match the Nth entry of this line:

```<code>Bulbasaur;Ivysaur;Venusaur;Charmander;Charmeleon;Charizard;Squirtle;Wartortle;Blastoise;Caterpie;Metapod;Butterfree;Weedle;Kakuna;Beedrill;Pidgey;Pidgeotto;Pidgeot;Rattata;Raticate;Spearow;Fearow;Ekans;Arbok;Pikachu;Raichu;Sandshrew;Sandslash;Nidoran (f);Nidorina;Nidoqueen;Nidoran (m);Nidorino;Nidoking;Clefairy;Clefable;Vulpix;Ninetales;Jigglypuff;Wigglytuff;Zubat;Golbat;Oddish;Gloom;Vileplume;Paras;Parasect;Venonat;Venomoth;Diglett;Dugtrio;Meowth;Persian;Psyduck;Golduck;Mankey;Primeape;Growlith;Arcanine;Poliwag;Poliwhirl;Poliwrath;Abra;Kadabra;Alakazam;Machop;Machoke;Machamp;Bellsprout;Weepinbell;Victreebell;Tentacool;Tentacruel;Geodude;Graveler;Golem;Ponyta;Rapidash;Slowpoke;Slowbro;Magnemite;Magneton;Farfetch'd;Doduo;Dodrio;Seel;Dewgong;Grimer;Muk;Shellder;Cloyster;Gastly;Haunter;Gengar;Onix;Drowsee;Hypno;Krabby;Kingler;Voltorb;Electrode;Exeggute;Exeggutor;Cubone;Marowak;Hitmonlee;Hitmonchan;Lickitung;Koffing;Weezing;Rhyhorn;Rhydon;Chansey;Tangela;Kangaskhan;Horsea;Seadra;Goldeen;Seaking;Staryu;Starmie;Mr. Mime;Scyther;Jynx;Electabuzz;Magmar;Pinsir;Tauros;Magikarp;Gyarados;Lapras;Ditto;Eevee;Vaporeon;Jolteon;Flareon;Porygon;Omanyte;Omastar;Kabuto;Kabutops;Aerodactyl;Snorlax;Articuno;Zapdos;Moltres;Dratini;Dragonair;Dragonite;Mewtwo;Mew
</code>```

答:
J (93 + 787 = 880)

Edit: other capitalisation method that capitalizes 'Mr. Mime' correctly.

Can probably be shortened, I've almost never written J before. It works on a similar principle as the PHP example.

You need the 'p' file in the same directory as you run this, the file can be downloaded from: http://frankenstein.d-n-s.org.uk/p. It is 787 bytes.

```<code>u:p-32*96<p*|.!.1[32=p=.(}.p#~(".1!:1[1)=+/\31=p=.#._5>\,#:a.i.1!:1<'p'){(97+i.26),a.i.'.()'' '
</code>```

The file is encoded in a five-bit format, as follows:

```<code>0-25: A-Z
26: .
27: (
28: )
29: '
30: <space>
31: separator
</code>```

The file also starts with a separator, to make the list 1-based.

The J code works as follows:

(97+i.26),a.i.'.()'' ': a string where the index N is the ASCII character

{: select from this list the values generated by the expression below

1!:1<'p': read the 'p' file

,#:a.i.: get the file as bits

_5>\: group the bits in groups of five

p=.#.: transform each group of bits into a number and assign to p

+/\31=p: a list of the size of p where each value N means the value at that position in p belongs to the N-th pokemon.

(".1!:1[1)=: read a number from the keyboard and see where in p the characters for that pokemon are.

}.p#~: look them up in p, and remove the first item (which is the separator).

p-32*96<p*_1|.(!.1)32=p=.: Assign the output to p again, and subtract 32 from p where p is bigger than 96 and to the right of a space. Which is cumbersome. According to the J documentation there should be a capitalize function but it's not there on my system.

u:: look them up as unicode.

Title: Who's that Pokémon?

Body:
J (93 + 787 = 880)

Edit: other capitalisation method that capitalizes 'Mr. Mime' correctly.

Can probably be shortened, I've almost never written J before. It works on a similar principle as the PHP example.

You need the 'p' file in the same directory as you run this, the file can be downloaded from: http://frankenstein.d-n-s.org.uk/p. It is 787 bytes.

u:p-32*96<p*|.!.1[32=p=.(}.p#~(".1!:1[1)=+/\31=p=.#._5>\,#:a.i.1!:1<'p'){(97+i.26),a.i.'.()'' '

The file is encoded in a five-bit format, as follows:

0-25: A-Z
26: .
27: (
28: )
29: '
30: <space>
31: separator

The file also starts with a separator, to make the list 1-based.

The J code works as follows:

(97+i.26),a.i.'.()'' ': a string where the index N is the ASCII character

{: select from this list the values generated by the expression below

1!:1<'p': read the 'p' file

,#:a.i.: get the file as bits

_5>\: group the bits in groups of five

p=.#.: transform each group of bits into a number and assign to p

+/\31=p: a list of the size of p where each value N means the value at that position in p belongs to the N-th pokemon.

(".1!:1[1)=: read a number from the keyboard and see where in p the characters for that pokemon are.

}.p#~: look them up in p, and remove the first item (which is the separator).

p-32*96<p*_1|.(!.1)32=p=.: Assign the output to p again, and subtract 32 from p where p is bigger than 96 and to the right of a space. Which is cumbersome. According to the J documentation there should be a capitalize function but it's not there on my system.

u:: look them up as unicode.


答:
JavaScript (ES6), 47 bytes

n=>[...Array(n+1)].reduce((a,_,i)=>a+i,'')[n]<1

Title: Where are Champernowne's zeroes?


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

2 bytes thanks to Fatalize.

```<code>y@ec:?m0
</code>```

Try it online!

```<code>y@ec:?m0

y         range from 0 to Input, inclusive,
 @e       the digits of every number in that range,
   c      concatenated
    :?m   the Input-th digit
       0  is zero.
</code>```

Title: Where are Champernowne's zeroes?

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

2 bytes thanks to Fatalize.

y@ec:?m0

Try it online!

y@ec:?m0

y         range from 0 to Input, inclusive,
 @e       the digits of every number in that range,
   c      concatenated
    :?m   the Input-th digit
       0  is zero.


Title: Where are Champernowne's zeroes?

Body:
Haskell, 25 bytes

(<'1').((show=<<[0..])!!)

Usage example: (<'1').((show=<<[0..])!!)  312 -> True


Title: Where are Champernowne's zeroes?

Body:
Javascript (ES6), <s>42</s> 33 bytes

n=>!+(r=i=>i>n?'':i+r(i+1))(0)[n]

Example:

let f =
n=>!+(r=i=>i>n?'':i+r(i+1))(0)[n]

// test all integers in [0, 312]
for(var n = 0, list = []; n <= 312; n++) {
  f(n) && list.push(n);
}
console.log(list.join(','));


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

Thanks to @LeakyNun for -1 byte

```<code>!s@jkUh
</code>```

This is my first attempt at golfing in Pyth.

A full program that prints True or False as appropriate.

Try it online

First 25 truthy inputs

How it works

```<code>!s@jkUh    Program. Input: Q
      hQ   Head. Yield Q+1
     U     Unary range. Yield [0, Q]
   jk      Join. Join on empty string
  @     Q  Index. Yield string[Q]
 s         Integer. Convert to integer
!          Logical negation. 0 -> True, all other digits -> False
           Print. Print result implicitly
</code>```

Title: Where are Champernowne's zeroes?

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

Thanks to @LeakyNun for -1 byte

!s@jkUh

This is my first attempt at golfing in Pyth.

A full program that prints True or False as appropriate.

Try it online

First 25 truthy inputs

How it works

!s@jkUh    Program. Input: Q
      hQ   Head. Yield Q+1
     U     Unary range. Yield [0, Q]
   jk      Join. Join on empty string
  @     Q  Index. Yield string[Q]
 s         Integer. Convert to integer
!          Logical negation. 0 -> True, all other digits -> False
           Print. Print result implicitly


答:
Perl 6, <s>26</s> 25 bytes

```<code>{!+map(|*.comb,0..*)[$_]}
</code>```

A lambda that takes a number as input and returns a True or False.

Memory-efficient.

How it works

0..* – Construct the range from 0 to infinity.

map(|*.comb,  ) – Lazily iterate the range, replacing each number with the characters of its string representation, and returning a new lazy sequence. The | keeps the new sequence flattened.

[$_] – Take the element at the index defined by the (implicitly declared) lambda parameter $_.

+ – Coerce it to a number. (This step is needed because coercing a string directly to a boolean always gives True unless the string is empty.)

! – Coerce it to a boolean and negate it.

(try it online)

EDIT: -1 byte thanks to b2gills.

Title: Where are Champernowne's zeroes?

Body:
Perl 6, <s>26</s> 25 bytes

{!+map(|*.comb,0..*)[$_]}

A lambda that takes a number as input and returns a True or False.

Memory-efficient.

How it works

0..* – Construct the range from 0 to infinity.

map(|*.comb,  ) – Lazily iterate the range, replacing each number with the characters of its string representation, and returning a new lazy sequence. The | keeps the new sequence flattened.

[$_] – Take the element at the index defined by the (implicitly declared) lambda parameter $_.

+ – Coerce it to a number. (This step is needed because coercing a string directly to a boolean always gives True unless the string is empty.)

! – Coerce it to a boolean and negate it.

(try it online)

EDIT: -1 byte thanks to b2gills.


问:
Rube Goldberg Hello World
For this golf, you will need to use more than one language.

The task

A Rube Goldberg machine is a contraption that takes an enormous number of complicated steps in order to execute a very simple task. The goal of this golf is to output Rube Goldberg... but not directly.

The machine

Your "machine" is the source code that, once executed, will give another source code in another language that will output Rube Goldberg upon execution. Got it?

I rephrase: your initial code must give another code, that other code must output Rube Goldberg. Both codes must be written in different languages.

The bonus which is more like the only fun way to do it

There is a bonus if your code outputs a code that will output a code that will ... that will output Rube Goldberg.

NOTE: any sort of output can be used (stdout, stderr, dialog box, ...)

The points

The number of points is equal to the number of bytes used in your code, divided by the number of distinct, extra languages that you used.

NOTE: different languages use different encodings. The number of bytes is counted in the initial language with its own encoding.

Examples

Pyth -> J -> Javascript -> output in 30 bytes = 30/2 = 15 points (J and Javascript are the extra languages)

Java -> C# -> C++ -> PHP -> output in 36 bytes = 36/3 = 12 points (More bytes and more languages can win over fewer bytes and fewer languages (I know there is no way that these languages do it in 36 bytes))

C -> output in 10 bytes = 10/0 = Infinity points (No extra languages)

Python -> Perl -> Ruby -> Python -> Ruby in 44 bytes = 44/2 = 22 points (Perl and Ruby are the extra languages, the second Python is not counted as it is not an extra language, the second Ruby is not counted as it has already been used)

NOTE: Languages that output their input can't be used. That would be an extra language with absolutely no additional bytes.

The answer

Please provide an answer that clearly states which languages you used and shows us the code at each step (i.e.: in each language).

The winner

Of course, like usual, the lowest score wins.

NOTE: As usual, standard loopholes and "cheats" are not allowed.

答:
dc -> Fortran -> Basic -> Vim, 59/3 = 19.(6) points

With this answer I wanted to contribute to the variety of languages already used in other answers.

dc:

```<code>[program P;write(*,*)"PRINT ""echo 'Rube Goldberg'""";end]P
</code>```

Fortran:

program P;write(*,*)"PRINT ""echo 'Rube Goldberg'""";end
```

<p><strong>Basic:</strong></p>

<pre class="lang-basic prettyprint-override"><code>PRINT "echo 'Rube Goldberg'"
</code>```

Vim:

echo 'Rube Goldberg'
```

<p><strong>Final output:</strong></p>

```Rube Goldberg
```

Title: Rube Goldberg Hello World

Body:
dc -> Fortran -> Basic -> Vim, 59/3 = 19.(6) points

With this answer I wanted to contribute to the variety of languages already used in other answers.

dc:

[program P;write(*,*)"PRINT ""echo 'Rube Goldberg'""";end]P

Fortran:

program P;write(*,*)"PRINT ""echo 'Rube Goldberg'""";end

Basic:

PRINT "echo 'Rube Goldberg'"

Vim:

echo 'Rube Goldberg'

Final output:

Rube Goldberg


答:
Brachylog, 11 bytes

```<code>$p@b:la:-a+
</code>```

Try it online!

Verify all testcases. (The wrapper is longer than the function...)

```<code>$p@b:la:-a+

$p            prime factorization
  @b          group blocks of equal elements
    :la       length of each
       :-a    each minus 1
          +   sum
</code>```

Title: Excessive Integers

Body:
Brachylog, 11 bytes

$p@b:la:-a+

Try it online!

Verify all testcases. (The wrapper is longer than the function...)

$p@b:la:-a+

$p            prime factorization
  @b          group blocks of equal elements
    :la       length of each
       :-a    each minus 1
          +   sum


答:
Javascript (ES6), <s>53</s> <s>51</s> 46 bytes

```<code>e=(n,i=2)=>i<n?n%i?e(n,i+1):e(n/=i,i)+!(n%i):0
</code>```

Saved 5 bytes thanks to Neil

Example:

e=(n,i=2)=>i<n?n%i?e(n,i+1):e(n/=i,i)+!(n%i):0

// computing e(n) for n in [1, 30]
for(var n = 1, list = []; n <= 30; n++) {
  list.push(e(n));
}
console.log(list.join(','));```

Title: Excessive Integers

Body:
Javascript (ES6), <s>53</s> <s>51</s> 46 bytes

e=(n,i=2)=>i<n?n%i?e(n,i+1):e(n/=i,i)+!(n%i):0

Saved 5 bytes thanks to Neil

Example:

e=(n,i=2)=>i<n?n%i?e(n,i+1):e(n/=i,i)+!(n%i):0

// computing e(n) for n in [1, 30]
for(var n = 1, list = []; n <= 30; n++) {
  list.push(e(n));
}
console.log(list.join(','));


问:
Play a sound, any sound
Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

The program should run on a reasonable, not too uncommon personal computer.

Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.

Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.

答:
J (2)

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

This prints all the characters from 0 to 255, that includes the bell.

If I have to do it without printing anything else, it's 4 characters:

```<code>7{a.
</code>```

Title: Play a sound, any sound

Body:
J (2)

a.

This prints all the characters from 0 to 255, that includes the bell.

If I have to do it without printing anything else, it's 4 characters:

7{a.


答:
S.I.L.O.S, 113 bytes

```<code>readIO
t=2
lbla
e=0
GOTO b
lblc
i/t
e+1
lblb
m=i
m%t
n=1
n-m
if n c
d=e
d/d
e-d
r+e
A=i
A-1
t+1
if A a
printInt r
</code>```

Try it online!

A port of my answer in C.

Title: Excessive Integers

Body:
S.I.L.O.S, 113 bytes

readIO
t=2
lbla
e=0
GOTO b
lblc
i/t
e+1
lblb
m=i
m%t
n=1
n-m
if n c
d=e
d/d
e-d
r+e
A=i
A-1
t+1
if A a
printInt r

Try it online!

A port of my answer in C.


答:
GolfScript, 12 bytes

```<code>~.),""*\=48=
</code>```

Explanation:

```<code>~             Evaluate the input.
 .            Duplicate it
  )           Increment the duplicate.
   ,          Create an array from 0 to it.
    ""*       Join it with an empty string.
       \=     Get the n-th index of this string, where n is the input
         48=  Is it equal to 0?
</code>```

Try it online or verify all test cases!

Title: Where are Champernowne's zeroes?

Body:
Consider the infinite string of all nonnegative decimal integers concatenated together in order (akin to Champernowne's constant):

```<code>0123456789101112131415161718192021222324252627282930...979899100101102103...
</code>```

Write a program or function that takes in a nonnegative integer that indexes (0-based) into this infinite string. Output a truthy value if the digit indexed is 0, otherwise output a falsy value if the digit is 1-9.

The shortest code in bytes wins.

The first 25 truthy-producing inputs are:

```<code>0
11
31
51
71
91
111
131
151
171
191
192
194
197
200
203
206
209
212
215
218
222
252
282
312
</code>```

Kudos if your program is memory effecient, but this is not a requirement.

Body:
GolfScript, 12 bytes

~.),""*\=48=

Explanation:

~             Evaluate the input.
 .            Duplicate it
  )           Increment the duplicate.
   ,          Create an array from 0 to it.
    ""*       Join it with an empty string.
       \=     Get the n-th index of this string, where n is the input
         48=  Is it equal to 0?

Try it online or verify all test cases!


答:
Javascript (ES5): 61 60 bytes

```<code>function(b){for(s="";s.length<b;)s+=s.length;return 0==s[b]}
</code>```

Ungolfed:

```<code>function a(b){
  for(var s="";s.length<b;)
    s+=s.length;
  }
  return (s[b]==0);
}
</code>```

Old:

```<code>function(n){s="";while(s.length<n)s+=s.length;return s[n]==0}
</code>```

Ungolfed old:

```<code>function a(n){
  var str="";
  while(str.length<n)str+=str.length; //Create String as long as needed
  return str[n]==0 //Check for 0 and return
}
</code>```

Title: Where are Champernowne's zeroes?

Body:
Javascript (ES5): 61 60 bytes

function(b){for(s="";s.length<b;)s+=s.length;return 0==s[b]}

Ungolfed:

function a(b){
  for(var s="";s.length<b;)
    s+=s.length;
  }
  return (s[b]==0);
}

Old:

function(n){s="";while(s.length<n)s+=s.length;return s[n]==0}

Ungolfed old:

function a(n){
  var str="";
  while(str.length<n)str+=str.length; //Create String as long as needed
  return str[n]==0 //Check for 0 and return
}


答:
S.I.L.O.S, 236 bytes

```<code>GOTO s
funcg
if q p
r=p
return
lblp
t=p
t%q
p=q
q=t
GOSUB g
return
lbls
readIO
m=i
m/2
a=i
lbla
a-1
a-m
b=i
lblb
b-1
b-m
p=a
p|
q=b
q|
GOSUB g
r-1
A=r
A|
r/A
r*-1
r+1
p=r
r*r
r*6
p*4
r+p
r+32
printChar r
b+m
if b b
printLine
a+m
if a a
</code>```

Try it online!

Port of my answer in C.

Title: Visible Buildings

Body:
This puzzle is derived from CodinGame SamSi's "Heart of the City" puzzle.

Description

You decide to take a walk in an n * n tile city and go to the center tile. All of the buildings are infinitely small, but you have super vision and can see everything close up and far away.

Constraints

n is always odd

You can see any building that is not directly obstructed by another one

Task

Mark each building visible with *. The building is visible iff it is not blocked by another building on the exact same line of vision.

In other words, if @ is the origin, the building is visible iff the x-coordinate and the y-coordinate are co-prime to each other.

Example input and output

Input:

```<code>7
</code>```

Output:

```<code> ** **
* * * *
*******
  *@*
*******
* * * *
 ** **
</code>```

* is a visible building,
 is an invisible building, and
@ is where you are.

Scoring

Remember, this is code-golf, so the answer with the least bytes wins.

var QUESTION_ID=91394,OVERRIDE_USER=59057;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}*{font-family:"Helvetica",sans-serif}</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:
S.I.L.O.S, 236 bytes

GOTO s
funcg
if q p
r=p
return
lblp
t=p
t%q
p=q
q=t
GOSUB g
return
lbls
readIO
m=i
m/2
a=i
lbla
a-1
a-m
b=i
lblb
b-1
b-m
p=a
p|
q=b
q|
GOSUB g
r-1
A=r
A|
r/A
r*-1
r+1
p=r
r*r
r*6
p*4
r+p
r+32
printChar r
b+m
if b b
printLine
a+m
if a a

Try it online!

Port of my answer in C.


答:
Python 3.5, 40 bytes

lambda n:('%d'*-~n%(*range(n),n))[n]<'1'
```

Test it on repl.it.

How it works

For input n, '%d'*-~n repeats the format string n + 1 times.

(*range(n),n) unpacks the range [0, ..., n - 1] and yields the tuple (0, ..., n).

...%... replaces each occurrence of %d with the corresponding integer in the range, yielding the string 01234567891011...n.

(...)[n]<'1' selects the character at index n and tests if it is less than the character 1.

Title: Where are Champernowne's zeroes?

Body:
Python 3.5, 40 bytes

lambda n:('%d'*-~n%(*range(n),n))[n]<'1'

Test it on repl.it.

How it works

For input n, '%d'*-~n repeats the format string n + 1 times.

(*range(n),n) unpacks the range [0, ..., n - 1] and yields the tuple (0, ..., n).

...%... replaces each occurrence of %d with the corresponding integer in the range, yielding the string 01234567891011...n.

(...)[n]<'1' selects the character at index n and tests if it is less than the character 1.


答:
S.I.L.O.S, 141 bytes

```<code>readIO
i+1
lblL
c=C
p=1
lblc
p*10
c/10
if c c
p/10
lbln
m=C
m/p
m%10
p/10
i-1
if i C
GOTO H
lblC
if p n
C+1
GOTO L
lblH
m/m
m-1
m|
printInt m
</code>```

Try it online!

Uses only 5 integers, maximum memory efficiency \o/

Explanation

We generate as many digits as the input in the Champernowne's constant.

In the main loop, we do the following:

Find the length of the current number by floor_dividing it by 10 repeatedly until it reaches 0, and then count the number of divisions used.

Instead of storing the number of divisions, we store 10 to that number power instead.

Iterate through each digit as such: the 100s digit of 1234 is obtained by (1234/10)%10 where / is floor division.

For each digit generated, take 1 from the input, while checking if the input reached zero.

If the input reaches zero, check if the current digit is 0 and then halts.

Title: Where are Champernowne's zeroes?

Body:
S.I.L.O.S, 141 bytes

readIO
i+1
lblL
c=C
p=1
lblc
p*10
c/10
if c c
p/10
lbln
m=C
m/p
m%10
p/10
i-1
if i C
GOTO H
lblC
if p n
C+1
GOTO L
lblH
m/m
m-1
m|
printInt m

Try it online!

Uses only 5 integers, maximum memory efficiency \o/

Explanation

We generate as many digits as the input in the Champernowne's constant.

In the main loop, we do the following:

Find the length of the current number by floor_dividing it by 10 repeatedly until it reaches 0, and then count the number of divisions used.

Instead of storing the number of divisions, we store 10 to that number power instead.

Iterate through each digit as such: the 100s digit of 1234 is obtained by (1234/10)%10 where / is floor division.

For each digit generated, take 1 from the input, while checking if the input reached zero.

If the input reaches zero, check if the current digit is 0 and then halts.


Title: Where are Champernowne's zeroes?

Body:
C, 154 bytes

s(n,v,k,z){for(k=1;(z=n%10,n/=10)&&!v||k<v;++k); return v?z:k;}
f(n,i,j,c){for(i=0,j=0;;++i){c=s(i,0,0,0);j+=c;if(j>n){c=s(i,j-n,c,0);break;}}return !c;}

the function that calculate the value is f(n,0,0,0) where n is the input index.
it can calculate from index changing "return !c" in "return c" the value of the array in that index...
i don't understand how but it seems to work ok....

main()
{int   i,r;
 char  a[]="0123456789101112131415161718192021222324252627282930313233343536";

 for(i=0; i<1000; ++i)
    if(r=f(i,0,0,0))
        printf("%u|",i);
}
/*
 154
 0|11|31|51|71|91|111|131|151|171|191|192|194|197|200|203|206|209|212|215|218|222
|252|282|312|342|372|402|432|462|491|492|494|497|500|503|506|509|512|515|518|522|552
|582|612|642|672|702|732|762|791|792|794|797|800|803|806|809|812|815|818|822|852
|882|912|942|972|
*/


答:
Jelly, 6 bytes

```<code>RDF⁸ị¬
</code>```

Try it online! or verify all test cases.

How it works

```<code>RDF⁸ị¬  Main link. Argument: n

R       Range; yield [1, ..., n].
 D      Decimal; convert all integers in that range to base 10 arrays.
  F     Flatten the result.
   ⁸ị   Extract the digit at index n (1-based).
        This returns 0 if the array is empty (n = 0).
     ¬  Logical NOT; return 1 if the digit is 0, 0 if not.
</code>```

Title: Where are Champernowne's zeroes?

Body:
Jelly, 6 bytes

RDF⁸ị¬

Try it online! or verify all test cases.

How it works

RDF⁸ị¬  Main link. Argument: n

R       Range; yield [1, ..., n].
 D      Decimal; convert all integers in that range to base 10 arrays.
  F     Flatten the result.
   ⁸ị   Extract the digit at index n (1-based).
        This returns 0 if the array is empty (n = 0).
     ¬  Logical NOT; return 1 if the digit is 0, 0 if not.


答:
CoffeeScript, 56 bytes

```<code>a=(b)->
 s=""
 while s.length<b #loop for building string with required length
  s+=s.length     #add number
 "0"==s[b]        #return, if the number at the position equals zero
</code>```

Title: Where are Champernowne's zeroes?

Body:
CoffeeScript, 56 bytes

a=(b)->
 s=""
 while s.length<b #loop for building string with required length
  s+=s.length     #add number
 "0"==s[b]        #return, if the number at the position equals zero


问:
Find the Factorial!
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

$$n!:=\begin{cases}1 & n=0\\n\cdot(n-1)!&n>0\end{cases}$$

In plain English the factorial of 0 is 1 and the factorial of n, where n is larger than 0 is n times the factorial of one less than n.

Your code should perform input and output using a standard methods.

Requirements:

Does not use any built-in libraries that can calculate the factorial (this includes any form of eval)

Can calculate factorials for numbers up to 125

Can calculate the factorial for the number 0 (equal to 1)

Completes in under a minute for numbers up to 125

The shortest submission wins, in the case of a tie the answer with the most votes at the time wins.

答:
APL (4)

```<code>×/∘⍳
</code>```

Works as an anonymous function:

```<code>    ×/∘⍳ 5
120
</code>```

If you want to give it a name, 6 characters:

```<code>f←×/∘⍳
</code>```

Title: Find the Factorial!

Body:
APL (4)

×/∘⍳

Works as an anonymous function:

    ×/∘⍳ 5
120

If you want to give it a name, 6 characters:

f←×/∘⍳


答:
Groovy, 56 bytes

```<code>def f(n){def s=''<<'';(0..n).each{s<<it};!(s[n] as int)}
</code>```

Nothing fancy, but I'm trying out some new things.

```<code>def f(n) {
  def s = ''<<''           // declare a StringBuffer
  (0..n).each { s << it }
  !(s[n] as int)           // Groovy considers a non-null char truthy, so we have to cast
}
</code>```

Title: Where are Champernowne's zeroes?

Body:
Groovy, 56 bytes

def f(n){def s=''<<'';(0..n).each{s<<it};!(s[n] as int)}

Nothing fancy, but I'm trying out some new things.

def f(n) {
  def s = ''<<''           // declare a StringBuffer
  (0..n).each { s << it }
  !(s[n] as int)           // Groovy considers a non-null char truthy, so we have to cast
}


问:
Steps of Permutation
Write a function which takes a set of integers and prints every permutation of the set, and the swap performed in between each step

Input

a set of integers, for example (0, 1, 2)

Output

the list of permutations and swaps in the format
(set)
(swap)
(set)
...

Test case

```<code>Input:
(3, 1, 5)

Output:
(3, 1, 5)
(3, 1)
(1, 3, 5)
(3, 5)
(1, 5, 3)
(1, 3)
(3, 5, 1)
(3, 5)
(5, 3, 1)
(3, 1)
(5, 1, 3)
</code>```

Rules

You can format the set of numbers however you want.

You can do the swaps in any order

You can repeat permutations and swaps in order to get a new one

Your code doesn't have to actually perform the swaps, the output just needs to show what swap was made between your last output and your current one

Your code only needs to function for sets with 2 or more elements

The set you're given will have no repeating elements (e.g. (0, 1, 1, 2) is invalid)

This is code-golf, so shortest code wins!

答:
JavaScript (ES6), 186 bytes

f=
a=>{console.log(a);d=a.slice().fill(-1);s=[...d.keys()];for(i=l=a.length;i;)s[k=(j=s.indexOf(--i))+d[i]]a[n])),i=l):d[i]*=-1}
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=i><input type=button value=Go! onclick=f(i.value.split`,`)></code>```

Note: I'm not sure how flexible the output format is, may be I could do this for 171 bytes:

```<code>a=>{console.log(a);d=a.slice().fill(-1);s=[...d.keys()];for(i=l=a.length;i;)s[k=(j=s.indexOf(--i))+d[i]]<i?console.log(a[s[j]=s[k]],a[s[k]=i],s.map(n=>a[n],i=l)):d[i]*=-1}
</code>```

Works by performing the Steinhaus–Johnson–Trotter algorithm on the shuffle array of indices and translating back to the input array. Ungolfed:

```<code>function steps(array) {
    console.log(array); // initial row
    var d = a.slice().fill(-1); // direction values
    var s = [...a.keys()]; // initial (identity) shuffle
    var l = a.length;
    for (var i = l; i; ) { // start by trying to move the last element
        var j = s.indexOf(--i);
        var k = j + d[i]; // proposed exchange
        if (s[k] < i) { // only exchange with lower index (within bounds)
            console.log(a[s[k]],a[i]); // show values being exchanged
            s[j] = s[k];
            s[k] = i; // do the exchange on the shuffle
            console.log(s.map(n=>a[n])); // show the shuffled array
            i = l; // start from the last element again
        } else {
            d[i] *= -1; // next time, try moving it the other way
        } // --i above causes previous element to be tried
    } // until no movable elements can be found
}
</code>```

Title: Steps of Permutation

Body:
JavaScript (ES6), 186 bytes

f=
a=>{console.log(a);d=a.slice().fill(-1);s=[...d.keys()];for(i=l=a.length;i;)s[k=(j=s.indexOf(--i))+d[i]]<i?(console.log(a[s[j]=s[k]],a[s[k]=i]),console.log(s.map(n=>a[n])),i=l):d[i]*=-1}
;

<input id=i><input type=button value=Go! onclick=f(i.value.split`,`)>

Note: I'm not sure how flexible the output format is, may be I could do this for 171 bytes:

a=>{console.log(a);d=a.slice().fill(-1);s=[...d.keys()];for(i=l=a.length;i;)s[k=(j=s.indexOf(--i))+d[i]]<i?console.log(a[s[j]=s[k]],a[s[k]=i],s.map(n=>a[n],i=l)):d[i]*=-1}

Works by performing the Steinhaus–Johnson–Trotter algorithm on the shuffle array of indices and translating back to the input array. Ungolfed:

function steps(array) {
    console.log(array); // initial row
    var d = a.slice().fill(-1); // direction values
    var s = [...a.keys()]; // initial (identity) shuffle
    var l = a.length;
    for (var i = l; i; ) { // start by trying to move the last element
        var j = s.indexOf(--i);
        var k = j + d[i]; // proposed exchange
        if (s[k] < i) { // only exchange with lower index (within bounds)
            console.log(a[s[k]],a[i]); // show values being exchanged
            s[j] = s[k];
            s[k] = i; // do the exchange on the shuffle
            console.log(s.map(n=>a[n])); // show the shuffled array
            i = l; // start from the last element again
        } else {
            d[i] *= -1; // next time, try moving it the other way
        } // --i above causes previous element to be tried
    } // until no movable elements can be found
}


问:
"99 Bottles of Beer"
Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible.

Lyrics:

```<code>99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

....

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
</code>```

Rules:

Your program must log to STDOUT or an acceptable alternative, or be returned from a function (with or without a trailing newline).

Your program must be a full, runnable program or function.

Languages specifically written to submit a 0-byte answer to this challenge are allowed, just not particularly interesting.

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

This is different from the output by HQ9+ or 99. Any answers written in these languages will be deleted.

As this is a catalog challenge, this is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
F#, <s>210 201 263</s> 241 bytes

```<code>let B n=sprintf"%d bottle%s of beer"n (if n>1 then"s"else"")
for n=99 downto 1 do printfn"%s on the wall, %s.\n%s on the wall.\n"(B n)(B n)(if n>1 then"Take one down and pass it around, "+B(n-1)else"Go to the store and buy some more, "+B 99)
</code>```

Missed the "Go to the store and buy some more" part ..

Title: "99 Bottles of Beer"

Body:
F#, <s>210 201 263</s> 241 bytes

let B n=sprintf"%d bottle%s of beer"n (if n>1 then"s"else"")
for n=99 downto 1 do printfn"%s on the wall, %s.\n%s on the wall.\n"(B n)(B n)(if n>1 then"Take one down and pass it around, "+B(n-1)else"Go to the store and buy some more, "+B 99)

Missed the "Go to the store and buy some more" part ..


答:
JavaScript (ES6), 45 bytes + Kudos

```<code>f=(n,s='0')=>s[n]?!+s[n]:f(n-s.length,-~s+'')
</code>```

My best non-Kudos version was 34 bytes:

```<code>n=>!+(g=s=>s[n]||g(s+i++))('',i=0)
</code>```

Title: Where are Champernowne's zeroes?

Body:
JavaScript (ES6), 45 bytes + Kudos

f=(n,s='0')=>s[n]?!+s[n]:f(n-s.length,-~s+'')

My best non-Kudos version was 34 bytes:

n=>!+(g=s=>s[n]||g(s+i++))('',i=0)


Title: Visible Buildings

Body:
GolfScript, 98 83 bytes

~:l.2/~):o:i;{o{.abs i abs.!!{{.@\%.}do}*;1={'*'}{' '}if\.i|!{\;'@'\}*)}l*;i):i;n}*

Try it online!

Input = 11

 **** ****
* * * * * *
** ** ** **
* * * * * *
***********
    *@*
***********
* * * * * *
** ** ** **
* * * * * *
 **** ****


问:
Print a 10 by 10 grid of asterisks

Background

This is a standard textbook example to demonstrate for loops.

This is one of the first programs I learnt when I started learning programming ~10 years ago.

Task

You are to print this exact text:

```<code>**********
**********
**********
**********
**********
**********
**********
**********
**********
**********
</code>```

Specs

You may have extra trailing newlines.

You may have extra trailing spaces (U+0020) at the end of each line, including the extra trailing newlines.

Scoring

This is code-golf. Shortest answer in bytes wins.

答:
GolfScript, 27 bytes

```<code>0{"**********\n"\1+.10<}do;
</code>```

Try it online!

Explanation

```<code>0              # Push 0 onto the stack: counter
{
"**********\n" # Push 10 '*' and a newline character
\              # Moves the counter onto the stack
1+             # Increments the counter
.10<           # Check if it's smaller than 10
}do;           # Repeat until counter equals 10
</code>```

Title: Print a 10 by 10 grid of asterisks

Body:
GolfScript, 27 bytes

0{"**********\n"\1+.10<}do;

Try it online!

Explanation

0              # Push 0 onto the stack: counter
{
"**********\n" # Push 10 '*' and a newline character
\              # Moves the counter onto the stack
1+             # Increments the counter
.10<           # Check if it's smaller than 10
}do;           # Repeat until counter equals 10


Title: Find the right path

Body:
Given a list of paths, output the correct path.

Example of path:

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

- and | are horizontal and vertical paths.

/ and \ are 90° turns.

+ is treated as a - or a | depending of the current direction.

Paths may go in any direction and a character may be used in multiple paths.

Input will be like this:

```<code>       /--\
A------+--+--#
B------/  \--:
C------------#
D------------#
</code>```

A, B, C and D are path starts

# is a wall (the path is bad)

: is the end (the path is correct)

So here the output will be B.

You can assume:

: and # will always be reached from the left.

The character at the right of the start of a path will always be -.

Paths will always be well formed.

# and : will always be in the same column.

There will always be only one : and 4 paths.

Test cases

```<code>A------#
B------#
C------#
D------:
=>
D
</code>```

```<code>A-\ /---:
B-+-/ /-#
C-+---+-#
D-+---/
  \-----#
=>
B
</code>```

```<code>  /-\
A-+\\---#
B-/\-\/-#
C----++-#
D----+/
     \--:
=>
A
</code>```

```<code>A-\
B-+\
C-++\/----#
D-+++//---:
  \++-//--#
   \+--//-#
    \---/
=>
A
</code>```

```<code>  /-\
A-+-/-\
B-+-+-\--#
C-+-/ |/-#
D-\---++-#
  \---+/
      \--:
=>
B
</code>```

Since this is code-golf, the shortest answer win.

Body:
Ruby, 140 bytes

->s{(?A..?D).find{|l,c|x=h=1
v=0
y=s[/.*#{l}/m].count$/
(v,h=c==?/?[-h,-v]:c==?\\?[h,v]:[v,h]
y+=v
x+=h)until(c=s.lines[y][x])=~/(:)|#/
$1}}

Try it on repl.it: https://repl.it/CyJv

Ungolfed

->s{
  (?A..?D).find {|l,c|
    x = h = 1
    v = 0
    y = s[/.*#{l}/m].count $/

    ( v, h = c == ?/ ? [-h,-v] : c == ?\\ ? [h,v] : [v,h]
      y += v
      x += h
    ) until (c = s.lines[y][x]) =~ /(:)|#/

    $1
  }
}


答:
Python, (with sympy) 66 bytes

import sympy;lambda n:sum(x-1for x in sympy.factorint(n).values())
```

sympy.factorint returns a dictionary with factors as keys and their multiplicities as values, so the sum of the values is Ω(n) and the number of values is ω(n), so the sum of the decremented values is what we want.

Title: Excessive Integers

Body:
For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where p1,...,pk are primes and e1,...,ek are positive integers, we can define two functions:

Ω(n) = e1+e2+...+ek the number of prime divisors (counted with multiplicity) (A001222)

ω(n) = k the number of distinct prime divisors. (A001221)

With those two functions we define the excess e(n) = Ω(n) - ω(n) (A046660). This can be considered as a measure of how close a number is to being squarefree.

Challenge

For a given positive integer n return e(n).

Examples

For n = 12 = 2^2 * 3 we have Ω(12) = 2+1 and ω(12) = 2 and therefore e(12) = Ω(12) - ω(12) = 1. For any squarefree number n we obivously have e(n) = 0. The first few terms are

```<code>1       0
2       0
3       0
4       1
5       0
6       0
7       0
8       2
9       1
10      0
11      0
12      1
13      0
14      0
15      0
</code>```

Some more details in the OEIS wiki.

Body:
Python, (with sympy) 66 bytes

import sympy;lambda n:sum(x-1for x in sympy.factorint(n).values())

sympy.factorint returns a dictionary with factors as keys and their multiplicities as values, so the sum of the values is Ω(n) and the number of values is ω(n), so the sum of the decremented values is what we want.


问:
Tips for golfing in Ruby
What general tips can you give for golfing in Ruby?

I'm looking for ideas that can be applied to code golf problems in general that are specific to Ruby. (For example, "Remove comments" would not be an answer.)

Please post one tip per answer.

答:
Array#assoc/rassoc

When you have an array of arrays and want to find the sub-array that starts with a particular value, don't use Enumerable#find, use Array#assoc:

```<code>a = [[0,"foo"],[0,"bar"],[1,"baz"],[0,"qux"]]
a.find{|x,|x==1} # => [1,"baz"]
a.assoc(1) # => [1,"baz"]
</code>```

This is also a good replacement for Enumerable#any? in some situations.

Array#rassoc does the same thing, but checks the sub-arrays' last element:

```<code>a = [[123,"good"],[456,"good"]]
a.any?{|*,x|x=="bad"} # => false
a.rassoc("bad") # => nil
</code>```

Title: Tips for golfing in Ruby

Body:
Array#assoc/rassoc

When you have an array of arrays and want to find the sub-array that starts with a particular value, don't use Enumerable#find, use Array#assoc:

a = [[0,"foo"],[0,"bar"],[1,"baz"],[0,"qux"]]
a.find{|x,|x==1} # => [1,"baz"]
a.assoc(1) # => [1,"baz"]

This is also a good replacement for Enumerable#any? in some situations.

Array#rassoc does the same thing, but checks the sub-arrays' last element:

a = [[123,"good"],[456,"good"]]
a.any?{|*,x|x=="bad"} # => false
a.rassoc("bad") # => nil