问:
Convert YYYYMM to MMMYY
Basing on this SO question.

Challenge is rather simple: given a date period in the format YYYYMM output it in the format MMMYY.

Rules:

The input will be a number or a string exactly 6 characters long, consisting only of digits.

Last two digits will be between 01 and 12.

Output must be in the form MMMYY, where MMM represents uppercase three-letter code for the month (below) and YY represents two last digits of the YYYY part of the input.

List of months with corresponding code:

```<code>MM    MMM
01    JAN
02    FEB
03    MAR
04    APR
05    MAY
06    JUN
07    JUL
08    AUG
09    SEP
10    OCT
11    NOV
12    DEC
</code>```

Examples:

```<code>Input     Output
201604    APR16
200001    JAN00
000112    DEC01
123405    MAY34
</code>```

答:
Ruby 46 + 6 for -rdate = 52

For completeness, if nothing else.

```<code>->d{Date.strptime(d,'%Y%m').strftime('%^b%y')}
</code>```

See the tests on repl.it: https://repl.it/Cj7z

Title: Convert YYYYMM to MMMYY

Body:
Ruby 46 + 6 for -rdate = 52

For completeness, if nothing else.

->d{Date.strptime(d,'%Y%m').strftime('%^b%y')}

See the tests on repl.it: https://repl.it/Cj7z


问:
Is this number Loeschian?
A positive integer \$k\$ is a Loeschian number if

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers.

For example, the first positive Loeschian numbers are: \$1\$ (\$i=1, j=0\$); \$3\$ (\$i=j=1\$); \$4\$ (\$i=2, j=0\$); \$7\$ (\$i=2, j=1\$); \$9\$ (\$i=-3, j=3\$); ... Note that \$i, j\$ for a given \$k\$ are not unique. For example, \$9\$ can also be generated with \$i=3, j=0\$.

Other equivalent characterizations of these numbers are:

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i, j\$ non-negative integers. (For each pair of integers \$i, j\$ there's a pair of non-negative integers that gives the same \$k\$)

There is a set of \$k\$ contiguous hexagons that forms a tesselation on a hexagonal grid so that corresponding cells are the same distance apart (see illustrations for \$k = 4\$ and for \$k = 7\$). (Because of this property, these numbers find application in mobile cellular communication networks.)

See more characterizations in the OEIS page of the sequence.

The challenge

Given a positive integer, output a truthy result if it is a Loeschian number, or a falsy result otherwise.

The program or function should handle (say in less than a minute) inputs up to \$1000\$, or up to data type limitations.

Code golf. Shortest wins.

Test cases

The following numbers should output a truthy result:

```<code>1, 4, 7, 12, 13, 108, 109, 192, 516, 999
</code>```

The following numbers should output a falsy result:

```<code>2, 5, 10, 42, 101, 102, 128, 150, 501, 1000
</code>```

答:
Matlab, <s>53</s> 52 bytes

```<code>n=input('');[a b]=ndgrid(0:n);find((a+b).^2-a.*b==n)
</code>```

Simple search over all possibilities.

Outputs empty array as falsy and a non-empty vector as truthy value.

Considering all-zeros matrix as falsy and not-all-zeros matrix as truthy we can get rid of the find function resulting in <s>47</s> 46 bytes solution:

```<code>n=input('');[a b]=ndgrid(0:n);(a+b).^2-a.*b==n
</code>```

One byte saved thanks to @flawr

ContentLicense: CC BY-SA 4.0

Title: Is this number Loeschian?

Body:
Matlab, <s>53</s> 52 bytes

n=input('');[a b]=ndgrid(0:n);find((a+b).^2-a.*b==n)

Simple search over all possibilities.

Outputs empty array as falsy and a non-empty vector as truthy value.

Considering all-zeros matrix as falsy and not-all-zeros matrix as truthy we can get rid of the find function resulting in <s>47</s> 46 bytes solution:

n=input('');[a b]=ndgrid(0:n);(a+b).^2-a.*b==n

One byte saved thanks to @flawr

ContentLicense: CC BY-SA 3.0


问:
Output a shuffled deck using random input

Input/Output:

Input: A uniformly random, infinitely long, string of '0's and '1's, taken from stdin.  The string is assumed to be truly random, not pseudo-random.  It is uniform in that each character is equally likely to be a '0' or '1'.

Careful! The input is infinitely long, so you can't store it all in memory using a function like raw_input() in python.  If I'm not mistaken, golfscript will fail with infinite input, since it pushes the entire input onto the stack prior to running.

Output: A uniformly random shuffled standard deck, without jokers.  It is uniform in that all orderings are equally likely.

Each card in the output is it's rank, A, 2-9, T, J, Q or K concatenated with it's suit, c, d, h or s.  For example, the 10 of spades is Ts

The cards of the deck should be separated by spaces.

You may not use built-in random libraries or functions because they are not truly random, only pseudo-random.

Example input

You may use the following python script to pipe input into your program:

```<code>import sys, random
try:
    while True:
        sys.stdout.write(str(random.randint(0,1)))
except IOError:
    pass
</code>```

If you save the script as rand.py, test your program with python rand.py | your_program

In python 3 it runs as expected, but in python 2.7 I get an error message after my program's output, but only after everything's done, so just ignore the error message.

Example output:

Here's how the deck should be printed if it happened to be shuffled into a sorted order:

```<code>Ac 2c 3c 4c 5c 6c 7c 8c 9c Tc Jc Qc Kc Ad 2d 3d 4d 5d 6d 7d 8d 9d Td Jd Qd Kd Ah 2h 3h 4h 5h 6h 7h 8h 9h Th Jh Qh Kh As 2s 3s 4s 5s 6s 7s 8s 9s Ts Js Qs Ks
</code>```

Scoring:

This is a code golf.  Shortest code wins.

Example program:

Here is a python 2.7 solution, not golfed.

```<code>import sys
def next():
    return int(sys.stdin.read(1))==1
def roll(n):
    if n==1:
        return 0
    if n%2==0:
        r=roll(n/2)
        if next():
            r+=n/2
        return r
    else:
        r=n
        while(r==n):
            r=roll(n+1)
        return r
deck = [rank+suit for suit in 'cdhs' for rank in 'A23456789TJQK']
while len(deck)>0:
    print deck.pop(roll(len(deck))),
</code>```

答:
Perl, 80 chars

here is another implementation that does not suffer from the bias and is two characters shorter:

```<code>$/=1x9;$_=A23456789TJQK;s/./$&s$&c$&d$&h/g;%h=map{<>.$_,"$_ "}/../g;say values%h
</code>```

old implementation (82 chars):

```<code>$/=1x9;$_=A23456789TJQK;s/./$&s$&c$&d$&h/g;say map/..$/&&$&.$",sort map<>.$_,/../g
</code>```

old implementation description:

```<code># set input record separator (how internal readline() delimits lines) to "11111111"
$/ = 1x9;

# constructs a string representation of all 52 cards: "AsAc(...)KdKh"
$_ = A23456789TJQK; s/./$&s$&c$&d$&h/g;

# for each pair of characters (each card) in the string $_
foreach $card (/../g)
{
    # read from STDIN until $/ is found (this may NEVER occur!), which
    # results in a random string of 1s and 0s
    $weight = <>;

    # append the card identifier onto the random string
    $card = $weight . $card;

    # add this new card identifier to a new list
    push @cards, $card;
}

# sort the cards with their random string prefix
sort @cards;

# for each card in the "randomly sorted" list
foreach $card (@cards)
{
    # capture the final two characters from the card (the rank and suit),
    # and append a space onto them
    $card =~ /..$/;
    $card = $card . $";

    print $card;
}
</code>```

Body:
Perl, 80 chars

here is another implementation that does not suffer from the bias and is two characters shorter:

$/=1x9;$_=A23456789TJQK;s/./$&s$&c$&d$&h/g;%h=map{<>.$_,"$_ "}/../g;say values%h

old implementation (82 chars):

$/=1x9;$_=A23456789TJQK;s/./$&s$&c$&d$&h/g;say map/..$/&&$&.$",sort map<>.$_,/../g

old implementation description:

# set input record separator (how internal readline() delimits lines) to "11111111"
$/ = 1x9;

# constructs a string representation of all 52 cards: "AsAc(...)KdKh"
$_ = A23456789TJQK; s/./$&s$&c$&d$&h/g;

# for each pair of characters (each card) in the string $_
foreach $card (/../g)
{
    # read from STDIN until $/ is found (this may NEVER occur!), which
    # results in a random string of 1s and 0s
    $weight = <>;

    # append the card identifier onto the random string
    $card = $weight . $card;

    # add this new card identifier to a new list
    push @cards, $card;
}

# sort the cards with their random string prefix
sort @cards;

# for each card in the "randomly sorted" list
foreach $card (@cards)
{
    # capture the final two characters from the card (the rank and suit),
    # and append a space onto them
    $card =~ /..$/;
    $card = $card . $";

    print $card;
}


问:
Turtles All the Way Down
Write a program or function that takes in a positive integer and prints or returns a stack of that many ASCII-art turtles, where each turtle is larger than the one above it.

Specifically, if the input is 1, the output should be:

```<code> __
/,,\o
</code>```

If the input is 2:

```<code>  __
o/,,\
 ____
/,__,\o
</code>```

If the input is 3:

```<code>   __
  /,,\o
  ____
o/,__,\
 ______
/,____,\o
</code>```

If the input is 4:

```<code>    __
  o/,,\
   ____
  /,__,\o
  ______
o/,____,\
 ________
/,______,\o
</code>```

If the input is 5:

```<code>     __
    /,,\o
    ____
  o/,__,\
   ______
  /,____,\o
  ________
o/,______,\
 __________
/,________,\o
</code>```

And so on in the same pattern for larger inputs.

Note that:

The head (the o) of the bottom turtle is always on the right. The heads of the turtles above then alternate back and forth.

No lines may have trailing spaces.

Superfluous leading spaces are not allowed. (i.e. the back of the bottom turtle should be at the start of the line.)

A single optional trailing newline is allowed.

The shortest code in bytes wins.

答:
05AB1E, 45 bytes

```<code>Lvð¹y-©>×„__y×UXJ,„/,X¨¨„,\J'o®ÉiìëJ}ð®®É-×ì,
</code>```

Try it online

Title: Turtles All the Way Down

Body:
05AB1E, 45 bytes

Lvð¹y-©>×„__y×UXJ,„/,X¨¨„,\J'o®ÉiìëJ}ð®®É-×ì,

Try it online


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

答:
Jelly, 8 bytes

```<code>”*x³s⁵j⁷
</code>```

Try it online!

How it works

```<code>”*x³s⁵j⁷  Main link. No arguments.

”*        Yield '*'.
  x³      Repeat the character 100 times.
    s⁵    Split into chunks of length 10.
      j⁷  Join, separating by linefeeds.
</code>```

Title: Print a 10 by 10 grid of asterisks

Body:
Jelly, 8 bytes

”*x³s⁵j⁷

Try it online!

How it works

”*x³s⁵j⁷  Main link. No arguments.

”*        Yield '*'.
  x³      Repeat the character 100 times.
    s⁵    Split into chunks of length 10.
      j⁷  Join, separating by linefeeds.


问:
I misspelled my domayn name
According to Alexa rankings, the top 10 websites are:

```<code>google.com
youtube.com
facebook.com
baidu.com
yahoo.com
wikipedia.org
amazon.com
twitter.com
qq.com
google.co.in
</code>```

Being the top 10 visited websites, these are probably also the top 10 misspelled websites [Citation Needed].

Your task

Your goal is to write a program or function that accepts a string containing a misspelled domain name, and outputs all domain names on the top 10 list that are spelled similarly.

Rules

Each input may be up to three characters off from a correct website. A changed character may a substitution (cat -> cot), addition (cat -> cant), or removal (cat -> at).

Moving a letter counts as two characters changed (the deletion of one character and the addition of another)

The input will only include the characters a-z, period, and dash

The name of a website does not include the http(s):// or the www. The websites are exactly as listed above.

The program must print out all websites that match the input.

Case doesn't matter. The test cases will be presented as lower case, but if your program requires upper case, that's fine too.

As always, no standard loopholes.

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

Some test cases

(Input followed by outputs)

```<code>yahoo.com
yahoo.com (no change for correct spelling)

goggle.com
google.com

wikipedia.organ
wikipedia.org

bidua.cm
baidu.com

.om
qq.com

google.co.i
google.com and google.co.in

google.com
google.com and google.co.in

twipper.com
twitter.com

yahoo.org
yahoo.com

amazing.com
amazon.com

factbook.co
facebook.com

ki-pedia.org
wikipedia.org

google.co.india
google.co.in

goo.com
google.com

aol.com
qq.com

qqzon.com
qq.com and amazon.com
</code>```

Leaderboards

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

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

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

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

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

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

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

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

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

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Python, <s>216</s> <s>200</s> <s>193</s> 183 bytes

```<code>import editdistance as e
i=raw_input()
print[n for n in"googlexyoutubexfacebookxbaiduxyahooxamazonxtwitterxqqxgoogle.co.in wikipedia.org".replace('x','.com ').split()if e.eval(i,n)<4]
</code>```

The module editdistance calculates the Levenshtein distance, which is the straightforward implementation of what the challenge was asking for.

EDIT: Saved 3 bytes thanks to @shooqie

EDIT 2: Saved another 10 bytes thanks to @shooqie and @Frank

Title: I misspelled my domayn name

Body:
Python, <s>216</s> <s>200</s> <s>193</s> 183 bytes

import editdistance as e
i=raw_input()
print[n for n in"googlexyoutubexfacebookxbaiduxyahooxamazonxtwitterxqqxgoogle.co.in wikipedia.org".replace('x','.com ').split()if e.eval(i,n)<4]

The module editdistance calculates the Levenshtein distance, which is the straightforward implementation of what the challenge was asking for.

EDIT: Saved 3 bytes thanks to @shooqie

EDIT 2: Saved another 10 bytes thanks to @shooqie and @Frank


Title: Print a 10 by 10 grid of asterisks

Body:
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.

Body:
Befunge, 39 bytes

52*>52* v
,1-:!#v_>67*
#@_v  >$52*,1-:!

Try it here!


答:
Perl 6, <s> 52 51 </s> 50 bytes

->\k{?first ->(\i,\j){k==i*i+j*j+i*j},(0..k X 0..k)}
->\k{?grep ->(\i,\j){k==i*i+j*j+i*j},(0..k X 0..k)}

{?grep ->(\i,\j){$_==i*i+j*j+i*j},(0..$_ X 0..$_)}
```

<h3>Explanation:</h3>

<pre class="lang-perl6 prettyprint-override"><code>{
  # Turn the following into a Bool
  # ( Technically not necessary as a list of 1 or more values is truthy )
  ?

  # find all where the code block returns a truthy value
  grep

  # pointy block that takes one value (list of 2 values)
  # and gives each of the values in it a name
  ->
    $ ( \i, \j )
  {
    # return true if the definition matches
    $_ == i*i + j*j + i*j
  },

  # a list of 2 element lists (possible i and j values)
  ( 0..$_ X 0..$_ )
}
</code>```

Test:

use v6.c;
use Test;

my @true = 0, 1, 4, 7, 12, 13, 108, 109, 192, 516, 999;
my @false = 2, 5, 10, 42, 101, 102, 128, 150, 501, 1000;

plan (@true + @false) * 2;

my &is-loeschian = {?grep ->(\i,\j){$_==i*i+j*j+i*j},(0..$_ X 0..$_)}

for |(@true X True), |(@false X False) -> ( $input, $expected ) {
  my ($result,$seconds) = $input.&time-it;
  is $result, $expected, ~$input;
  cmp-ok $seconds, &[<], 60, "in $seconds seconds"
}

sub time-it ( $input ) {
  my $start = now;
  my $result = $input.&is-loeschian;
  my $finish = now;
  return ( $result, $finish - $start )
}
```

<pre class="lang-perl6 prettyprint-override"><code>1..42
ok 1 - 0
ok 2 - in 0.00111763 seconds
ok 3 - 1
ok 4 - in 0.00076766 seconds
...
ok 19 - 516
ok 20 - in 0.19629727 seconds
ok 21 - 999
ok 22 - in 0.1126715 seconds
ok 23 - 2
ok 24 - in 0.0013301 seconds
ok 25 - 5
ok 26 - in 0.00186610 seconds
...
ok 37 - 150
ok 38 - in 0.83877554 seconds
ok 39 - 501
ok 40 - in 9.2968558 seconds
ok 41 - 1000
ok 42 - in 37.31434146 seconds
</code>```

Title: Is this number Loeschian?

Body:
A positive integer \$k\$ is a Loeschian number if

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers.

For example, the first positive Loeschian numbers are: \$1\$ (\$i=1, j=0\$); \$3\$ (\$i=j=1\$); \$4\$ (\$i=2, j=0\$); \$7\$ (\$i=2, j=1\$); \$9\$ (\$i=-3, j=3\$); ... Note that \$i, j\$ for a given \$k\$ are not unique. For example, \$9\$ can also be generated with \$i=3, j=0\$.

Other equivalent characterizations of these numbers are:

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i, j\$ non-negative integers. (For each pair of integers \$i, j\$ there's a pair of non-negative integers that gives the same \$k\$)

There is a set of \$k\$ contiguous hexagons that forms a tesselation on a hexagonal grid so that corresponding cells are the same distance apart (see illustrations for \$k = 4\$ and for \$k = 7\$). (Because of this property, these numbers find application in mobile cellular communication networks.)

See more characterizations in the OEIS page of the sequence.

The challenge

Given a positive integer, output a truthy result if it is a Loeschian number, or a falsy result otherwise.

The program or function should handle (say in less than a minute) inputs up to \$1000\$, or up to data type limitations.

Code golf. Shortest wins.

Test cases

The following numbers should output a truthy result:

```<code>1, 4, 7, 12, 13, 108, 109, 192, 516, 999
</code>```

The following numbers should output a falsy result:

```<code>2, 5, 10, 42, 101, 102, 128, 150, 501, 1000
</code>```

Body:
Perl 6, <s> 52 51 </s> 50 bytes

->\k{?first ->(\i,\j){k==i*i+j*j+i*j},(0..k X 0..k)}
->\k{?grep ->(\i,\j){k==i*i+j*j+i*j},(0..k X 0..k)}

{?grep ->(\i,\j){$_==i*i+j*j+i*j},(0..$_ X 0..$_)}

Explanation:

{
  # Turn the following into a Bool
  # ( Technically not necessary as a list of 1 or more values is truthy )
  ?

  # find all where the code block returns a truthy value
  grep

  # pointy block that takes one value (list of 2 values)
  # and gives each of the values in it a name
  ->
    $ ( \i, \j )
  {
    # return true if the definition matches
    $_ == i*i + j*j + i*j
  },

  # a list of 2 element lists (possible i and j values)
  ( 0..$_ X 0..$_ )
}

Test:

use v6.c;
use Test;

my @true = 0, 1, 4, 7, 12, 13, 108, 109, 192, 516, 999;
my @false = 2, 5, 10, 42, 101, 102, 128, 150, 501, 1000;

plan (@true + @false) * 2;

my &is-loeschian = {?grep ->(\i,\j){$_==i*i+j*j+i*j},(0..$_ X 0..$_)}

for |(@true X True), |(@false X False) -> ( $input, $expected ) {
  my ($result,$seconds) = $input.&time-it;
  is $result, $expected, ~$input;
  cmp-ok $seconds, &[<], 60, "in $seconds seconds"
}

sub time-it ( $input ) {
  my $start = now;
  my $result = $input.&is-loeschian;
  my $finish = now;
  return ( $result, $finish - $start )
}

1..42
ok 1 - 0
ok 2 - in 0.00111763 seconds
ok 3 - 1
ok 4 - in 0.00076766 seconds
...
ok 19 - 516
ok 20 - in 0.19629727 seconds
ok 21 - 999
ok 22 - in 0.1126715 seconds
ok 23 - 2
ok 24 - in 0.0013301 seconds
ok 25 - 5
ok 26 - in 0.00186610 seconds
...
ok 37 - 150
ok 38 - in 0.83877554 seconds
ok 39 - 501
ok 40 - in 9.2968558 seconds
ok 41 - 1000
ok 42 - in 37.31434146 seconds


答:
Jelly, <s>11</s> 9 bytes

```<code>ÆF‘%3,2ḄȦ
</code>```

Try it online! or verify all test cases.

Background

In Elementary results on the binary quadratic form a² + ab + b², the author proves the following theorem about Löschian numbers.

Theorem 16. The necessary and sufficient condition of any non-negative integer to be in the form a² + ab + b² is that, in its prime factorization, all primes other than 3 that are not in the form (6k + 1) have even exponents.

As noted on the relevant OEIS page, since all integers are are congruent to 0, 1 or 2 modulo 3, the number 3 is the only prime that is congruent to 0, and all numbers of the form (6k + 1) are congruent to 1, the theorem can be stated alternatively as follows.

A non-negative integer n is a Löschian number if and only if all prime factors of n that are congruent to 2 modulo 3 have even exponents.

How it works

```<code>ÆF‘%3,2ḄȦ  Main link. Argument: n (integer)

ÆF         Yield the prime factorization of n, as prime-exponent pairs.
  ‘        Increment all primes and exponents, turning primes of the form 3k - 2
           into multiples of 3 and odd exponents into multiples of 2.
   %3,2    Reduce all incremented primes/exponents modulo 3/2.
           n is Löschian if and only if this does not result in a [0, 0] pair.
           Due to Jelly's form of vectorization, this yields [3, 2] if n = 1.
       Ḅ   Unbinary; convert each pair from base 2 to integer.
           Note that [x, y] = [0, 0] if and only if 2x + y = 0.
        Ȧ  All; return 1 if the result contains no zeroes, 0 otherwise.
</code>```

Title: Is this number Loeschian?

Body:
Jelly, <s>11</s> 9 bytes

ÆF‘%3,2ḄȦ

Try it online! or verify all test cases.

Background

In Elementary results on the binary quadratic form a² + ab + b², the author proves the following theorem about Löschian numbers.

Theorem 16. The necessary and sufficient condition of any non-negative integer to be in the form a² + ab + b² is that, in its prime factorization, all primes other than 3 that are not in the form (6k + 1) have even exponents.

As noted on the relevant OEIS page, since all integers are are congruent to 0, 1 or 2 modulo 3, the number 3 is the only prime that is congruent to 0, and all numbers of the form (6k + 1) are congruent to 1, the theorem can be stated alternatively as follows.

A non-negative integer n is a Löschian number if and only if all prime factors of n that are congruent to 2 modulo 3 have even exponents.

How it works

ÆF‘%3,2ḄȦ  Main link. Argument: n (integer)

ÆF         Yield the prime factorization of n, as prime-exponent pairs.
  ‘        Increment all primes and exponents, turning primes of the form 3k - 2
           into multiples of 3 and odd exponents into multiples of 2.
   %3,2    Reduce all incremented primes/exponents modulo 3/2.
           n is Löschian if and only if this does not result in a [0, 0] pair.
           Due to Jelly's form of vectorization, this yields [3, 2] if n = 1.
       Ḅ   Unbinary; convert each pair from base 2 to integer.
           Note that [x, y] = [0, 0] if and only if 2x + y = 0.
        Ȧ  All; return 1 if the result contains no zeroes, 0 otherwise.


答:
dc, <s>22</s> 18 bytes

```<code>[**********]ddddff
</code>```

Invoked in bash as

```<code>echo [**********]ddddff | dc
</code>```

Explanation:

```<code>[**********] # This is dc's way of making a string, which is then pushed onto the stack
dddd         # d is for duplicate, so we duplicate it 4 times on the stack
ff           # print the whole stack twice, which contains 5 repetitions of 10 *'s (x2)
</code>```

Thanks to LeakyNun for saving <s>5</s> 4 bytes; Edited from 5 since I can't count.

Title: Print a 10 by 10 grid of asterisks

Body:
dc, <s>22</s> 18 bytes

[**********]ddddff

Invoked in bash as

echo [**********]ddddff | dc

Explanation:

[**********] # This is dc's way of making a string, which is then pushed onto the stack
dddd         # d is for duplicate, so we duplicate it 4 times on the stack
ff           # print the whole stack twice, which contains 5 repetitions of 10 *'s (x2)

Thanks to LeakyNun for saving <s>5</s> 4 bytes; Edited from 5 since I can't count.


问:
Alphabet triangle
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

答:
R, 95 bytes

```<code>L=LETTERS;cat("A\n");for(i in 2:50)cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n');cat("A\n")
</code>```

Ungolfed:

```<code>L=LETTERS; #Took idea from @Frederic, I apologize if I shouldn't (first time posting)
cat("A\n")
for(i in 2:50)
{
    cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n')
}
cat("A\n")
</code>```

Basically, the formula in the cat function in the for loop is a transformation on the absolute value function, mapping n -> n for Letters 2 through 26 and then mapping Letters 27 -> 25, 28 -> 24, ..., 50 -> 2. I don't think it would work if I included the 'A' in this formula, which is why I printed it out separately.

Title: Alphabet triangle

Body:
R, 95 bytes

L=LETTERS;cat("A\n");for(i in 2:50)cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n');cat("A\n")

Ungolfed:

L=LETTERS; #Took idea from @Frederic, I apologize if I shouldn't (first time posting)
cat("A\n")
for(i in 2:50)
{
    cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n')
}
cat("A\n")

Basically, the formula in the cat function in the for loop is a transformation on the absolute value function, mapping n -> n for Letters 2 through 26 and then mapping Letters 27 -> 25, 28 -> 24, ..., 50 -> 2. I don't think it would work if I included the 'A' in this formula, which is why I printed it out separately.


答:
C, 47 bytes

```<code>main(i){while(i<111)putchar(10|!!(i++%11)<<5);}
</code>```

Try it online.

Not as compact as the other C answer (putchar is such a long name!), but I don't use the asterisk character in my program. It treats the output as a 11 by 10 grid, where the 11th character is the newline. It then computes the ASCII for '*' (10 + 32 = 42) or '\n' (10) for each position.

I could save one byte with this approach if I were to change the character expression to: 42-!(i++%11)*32, but that would require an asterisk.

Title: Print a 10 by 10 grid of asterisks

Body:
C, 47 bytes

main(i){while(i<111)putchar(10|!!(i++%11)<<5);}

Try it online.

Not as compact as the other C answer (putchar is such a long name!), but I don't use the asterisk character in my program. It treats the output as a 11 by 10 grid, where the 11th character is the newline. It then computes the ASCII for '*' (10 + 32 = 42) or '\n' (10) for each position.

I could save one byte with this approach if I were to change the character expression to: 42-!(i++%11)*32, but that would require an asterisk.


问:
Hello World in 1024 characters
In exactly 1024 characters, no more, no less:

Must print Hello World.

Must not use unnecessary whitespace.

Must not use comments.

Judging should favor creativity and/or humor over simple obfuscation when voting up answers.

The earliest I will select an answer is the 11th (Sunday) of November (2012). I'm seeing some awesome entries so far, can't wait to see what else people come up with.

答:
Javascript

Lipsum Test with a regex:

```<code>"Hello World|Ta what. Soft lad mardy bum that's champion. Tha knows chuffin' nora tha knows tha knows mardy bum shurrup. Where's tha bin. Any rooad ne'ermind. Is that thine cack-handed ah'll gi' thee a thick ear. Ah'll gi' thee a thick ear. Gerritetten tintintin ah'll learn thi shurrup chuffin' nora. Sup wi' 'im. Nah then soft southern pansy tintintin breadcake t'foot o' our stairs how much. Shu' thi gob be reet th'art nesh thee ah'll gi' thee a thick ear that's champion. Shu' thi gob t'foot o' our stairs tha daft apeth where's tha bin ah'll gi' thi summat to rooer abaht. Wacken thi sen up eeh eeh. Shu' thi gob tha what that's champion soft southern pansy ah'll learn thi a pint 'o mild. Appens as maybe gi' o'er nobbut a lad nobbut a lad.Big girl's blouse a pint 'o mild. Big girl's blouse ah'll learn thi. A pint 'o mild. How much ah'll gi' thi summat to rooer abaht michael palin nay lad. Gerritetten a pint 'o mild be reet nay lad. Nay lad how much ee by gum. 1234567I love feet so much.".match(/Hello World/)[0]
</code>```

The regex: .match(/Hello World/)[0]

Title: Hello World in 1024 characters

Body:
Javascript

Lipsum Test with a regex:

"Hello World|Ta what. Soft lad mardy bum that's champion. Tha knows chuffin' nora tha knows tha knows mardy bum shurrup. Where's tha bin. Any rooad ne'ermind. Is that thine cack-handed ah'll gi' thee a thick ear. Ah'll gi' thee a thick ear. Gerritetten tintintin ah'll learn thi shurrup chuffin' nora. Sup wi' 'im. Nah then soft southern pansy tintintin breadcake t'foot o' our stairs how much. Shu' thi gob be reet th'art nesh thee ah'll gi' thee a thick ear that's champion. Shu' thi gob t'foot o' our stairs tha daft apeth where's tha bin ah'll gi' thi summat to rooer abaht. Wacken thi sen up eeh eeh. Shu' thi gob tha what that's champion soft southern pansy ah'll learn thi a pint 'o mild. Appens as maybe gi' o'er nobbut a lad nobbut a lad.Big girl's blouse a pint 'o mild. Big girl's blouse ah'll learn thi. A pint 'o mild. How much ah'll gi' thi summat to rooer abaht michael palin nay lad. Gerritetten a pint 'o mild be reet nay lad. Nay lad how much ee by gum. 1234567I love feet so much.".match(/Hello World/)[0]

The regex: .match(/Hello World/)[0]


问:
Array Escape - get out of there
One day you awake only to find yourself caught in an array. You try to just walk out of there, taking one index at the time, but it seems there are other rules:

The array is completely filled with natural numbers.

If you find yourself on an index n, you go to the index array[n], except:

If you find yourself on an index n which is a prime number, you take array[n] steps back

Example:
You start on index 4, in this array (start index is 0):

```<code>array = [1,4,5,6,8,10,14,15,2,2,4,5,7];
-----------------^ you are here
</code>```

As the value of the field you are on is 8, you go to the index 8 as the first step. The field you land on contains the value 2. You then go to index 2 as your second step. As2is a prime number, you take 5 steps back, which is your third step. As there is no index -3, you successfully escaped the array in a total of 3 steps.

Your task is:

To write a program or function, which accepts an array and a start index as parameter, and outputs the amount of steps to escape the array. If you can't escape the array (e.g. [2,0,2] with start-index 2 => you constantly go from index 2 to 0), output a falsy value. You may use one-based indexing or zero-based indexing, but please specify which you use.

Test cases

Input: [2,5,6,8,1,2,3], 3

Output: 1

Input: [2, 0, 2], 2

Output: false

Input: [14,1,2,5,1,3,51,5,12,3,4,41,15,4,12,243,51,2,14,51,12,11], 5;

Output: 6

The shortest answer wins.

答:
Java, <s>163</s> 160 bytes

```<code>boolean p(int n){for(int i=2;i<n;)if(n%i++==0)return 0>1;return 1>0;}
int f(int[]a,int n){return n<0||n>=a.length?1:p(n)?n<a[n]?1:1+f(a,a[n-a[n]]):1+f(a,a[n]);}
</code>```

p(n) is for prime testing, f(a,n) is for the escape function. Usage:

```<code>public static void main(String[] args) {
    int[] array = {14,1,2,5,1,3,51,5,12,3,4,41,15,4,12,243,51,2,14,51,12,11};
    System.out.println(f(array, 5));
}
</code>```

Ungolfed version:

```<code>static boolean isPrime(int n) {
    for (int i = 2; i < n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

static int escape(int[] array, int n) {
    if (n < 0 || n >= array.length) {
        return 1;
    } else if (isPrime(n)) {
        if (n < array[n]) {
            return 1;
        } else {
            return 1 + escape(array, array[n - array[n]]);
        }
    } else {
        return 1 + escape(array, array[n]);
    }
}
</code>```

Title: Array Escape - get out of there

Body:
Java, <s>163</s> 160 bytes

boolean p(int n){for(int i=2;i<n;)if(n%i++==0)return 0>1;return 1>0;}
int f(int[]a,int n){return n<0||n>=a.length?1:p(n)?n<a[n]?1:1+f(a,a[n-a[n]]):1+f(a,a[n]);}

p(n) is for prime testing, f(a,n) is for the escape function. Usage:

public static void main(String[] args) {
    int[] array = {14,1,2,5,1,3,51,5,12,3,4,41,15,4,12,243,51,2,14,51,12,11};
    System.out.println(f(array, 5));
}

Ungolfed version:

static boolean isPrime(int n) {
    for (int i = 2; i < n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

static int escape(int[] array, int n) {
    if (n < 0 || n >= array.length) {
        return 1;
    } else if (isPrime(n)) {
        if (n < array[n]) {
            return 1;
        } else {
            return 1 + escape(array, array[n - array[n]]);
        }
    } else {
        return 1 + escape(array, array[n]);
    }
}


问:
Smallest sum (and largest difference) of two 3-digit integers
Given six unique non-negative integers, print the two 3-digit integers comprised of those numbers that sum to the smallest amount.

Additionally,

If there is more than one set of numbers that meets the smallest-sum requirement, print the two that have the greatest difference. For example, 269 + 157 = 267 + 159 = 426; however, 269 - 157 > 267 - 159, so the first set should be printed.

Print the numbers on the same line largest -> smallest, separated by a single space.

Zero (0) cannot be used as a leading number.

Inputs will always be digits.

Testcases

```<code>input        | output
2 6 5 1 9 7  | 269 157
1 9 5 0 8 3  | 359 108
1 2 3 4 5 6  | 246 135
</code>```

Scoring

As this is code golf, shortest entry wins.

答:
Python3 97 bytes

```<code>def x(*s):d=sorted(s);i=(0,1)[not d[0]];print(d[1+i],d[3],d[5],' ',d[0+i],d[(2+i)%3],d[4],sep='')
</code>```

The approach is based on the narrative of @Dennis answer.

First try on Ideone with the code (I hope I did save it): Try it!

Body:
Python3 97 bytes

def x(*s):d=sorted(s);i=(0,1)[not d[0]];print(d[1+i],d[3],d[5],' ',d[0+i],d[(2+i)%3],d[4],sep='')

The approach is based on the narrative of @Dennis answer.

First try on Ideone with the code (I hope I did save it): Try it!


问:
A newly discovered number: bleen!
"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7."  --George Carlin

In this challenge, you will print all Integers, inclusive, within the given input range.  Print numbers ascending or descending according to their input order.  That is, for input [n1, n2], print ascending if n1 < n2, descending if n1 > n2.

Since bleen is now an Integer number it may be used as input.  It must also be included in the output, between 6 and 7 where applicable.  Also note that -bleen exists between -7 and -6.

Input

Two Integers [n1, n2] in the range [-10, 10], inclusive, via your programming language's input of choice.

(Input may also contain bleen and -bleen!)

Output

Print all Integers starting at n1 and ending with n2, including the newly discovered bleen between 6 and 7.  Output can be a range of character separated numbers in some form your language supports - that is, comma or space separated.  One trailing space of output is okay.

Examples

```<code>Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

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

Additional notes

You may write a program or function and use any standard method of receiving input and providing output.

You may use any programming language, but standard loopholes are not allowed.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

答:
Python 2, 100 bytes

The first four lines generate the list [-10, -9, -8, -7, 'bleen', -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 'bleen', 7, 8, 9, 10]. The next line gets input and stores it in s and e. The last two lines use .index() and list slicing notation to get the correct range.

```<code>a=range(-10,11)
b="bleen"
c=a.insert
c(17,b)
c(4,b)
s,e=eval(input())
d=a.index
print a[d(s):d(e)+1]
</code>```

Works in the same way as Leaky Nun's answer but developed independently. Stole an input method from orlp.

Ungolfed:

```<code>array = range(-10, 11)
array.insert(17, "bleen")
array.insert(4, "bleen")
start, end = eval(input())
print array[array.index(start):array.index(end) + 1]
</code>```

Title: A newly discovered number: bleen!

Body:
Python 2, 100 bytes

The first four lines generate the list [-10, -9, -8, -7, 'bleen', -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 'bleen', 7, 8, 9, 10]. The next line gets input and stores it in s and e. The last two lines use .index() and list slicing notation to get the correct range.

a=range(-10,11)
b="bleen"
c=a.insert
c(17,b)
c(4,b)
s,e=eval(input())
d=a.index
print a[d(s):d(e)+1]

Works in the same way as Leaky Nun's answer but developed independently. Stole an input method from orlp.

Ungolfed:

array = range(-10, 11)
array.insert(17, "bleen")
array.insert(4, "bleen")
start, end = eval(input())
print array[array.index(start):array.index(end) + 1]


答:
Perl, 54 + 1 (-n flag) = 55 bytes

```<code>for$i(0..$_){for$j(0..$_){$i*$i+$j*$j+$i*$j-$_?1:say}}
</code>```

Needs -n and -M5.010 flags to run :

```<code>perl -nE 'for$i(0..$_){for$j(0..$_){$i*$i+$j*$j+$i*$j-$_?1:say}}'
</code>```

Outputs some stuffs if the number is a Loeschian number, and nothing otherwise.

This implementation is quite boring, so here is another one, for 87 bytes, regex-based, just for the eyes :

```<code>perl -pE '$_=(1 x$_)=~/^(.*)(??{$1x(-1+length$1)})(.*)(??{$2x(-1+length$2)})(??{$1x length$2})$/'
</code>```

Carefull with this one, as the backtracking will use a lot of memory, so don't try to test numbers too big! (especially numbers that aren't Loeschians)

Title: Is this number Loeschian?

Body:
Perl, 54 + 1 (-n flag) = 55 bytes

for$i(0..$_){for$j(0..$_){$i*$i+$j*$j+$i*$j-$_?1:say}}

Needs -n and -M5.010 flags to run :

perl -nE 'for$i(0..$_){for$j(0..$_){$i*$i+$j*$j+$i*$j-$_?1:say}}'

Outputs some stuffs if the number is a Loeschian number, and nothing otherwise.

This implementation is quite boring, so here is another one, for 87 bytes, regex-based, just for the eyes :

perl -pE '$_=(1 x$_)=~/^(.*)(??{$1x(-1+length$1)})(.*)(??{$2x(-1+length$2)})(??{$1x length$2})$/'

Carefull with this one, as the backtracking will use a lot of memory, so don't try to test numbers too big! (especially numbers that aren't Loeschians)


答:
Python, 109 bytes

```<code>z="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def a(x):v=z[:x]+z[x-26::-1]+"\n";return v+a(x+1)+v if x<25 else v
print a(0)
</code>```

Build up a string with a recursive call in the middle to build the triangle out.
Might come back to try and get it <100.

Title: Alphabet triangle

Body:
You are to print this exact text:

```<code>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
</code>```

Specs

Extra trailing newlines are allowed at the end of the output.

Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.

You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.

You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

Body:
Python, 109 bytes

z="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def a(x):v=z[:x]+z[x-26::-1]+"\n";return v+a(x+1)+v if x<25 else v
print a(0)

Build up a string with a recursive call in the middle to build the triangle out.
Might come back to try and get it <100.


答:
DOG, 22 bytes

```<code>10 bark "**********\n"
</code>```

Prints out ********** and a newline 10 times.

Try it online! (you'll have to manually copy the code since I don't have permalink functionality yet ;_;)

Title: Print a 10 by 10 grid of asterisks

Body:
DOG, 22 bytes

10 bark "**********\n"

Prints out ********** and a newline 10 times.

Try it online! (you'll have to manually copy the code since I don't have permalink functionality yet ;_;)


答:
VBA, <s>68</s> 67 bytes

```<code>Function L(N):For a=0To N:For b=0To a:L=L+(N=a^2+a*b+b^2):Next b,a
</code>```

Naive search, starting to slow down slightly for n=1000. Excel recognizes zero return as falsy, all other returns as truthy.

Note that investigation of negative i and j is not needed, since given i>j>=0 :

(-i)2 + (-i)(-j) + (-j)2 = i2 + ij + j2

(the same result as for i and j)

(-i)2 + (-i)j + j2 = i2 - ij + j2

i2 + i(-j) + (-j)2 = i2 - ij + j2

(if one is negative, it doesn't matter which one), and then

(i-j)2 + (i-j)j + j2 = (i2 - 2ij + j2) + (ij - j2) + j2 = i2 - ij + j2

And since both (i-j) and j are non-negative, any generation of Loeschian numbers involving a negative number can be achieved using non-negative numbers.

Saved a byte, Next:Next -> Next b,a thanks to Taylor Scott.

Title: Is this number Loeschian?

Body:
VBA, <s>68</s> 67 bytes

Function L(N):For a=0To N:For b=0To a:L=L+(N=a^2+a*b+b^2):Next b,a

Naive search, starting to slow down slightly for n=1000. Excel recognizes zero return as falsy, all other returns as truthy.

Note that investigation of negative i and j is not needed, since given i>j>=0 :

(-i)2 + (-i)(-j) + (-j)2 = i2 + ij + j2

(the same result as for i and j)

(-i)2 + (-i)j + j2 = i2 - ij + j2

i2 + i(-j) + (-j)2 = i2 - ij + j2

(if one is negative, it doesn't matter which one), and then

(i-j)2 + (i-j)j + j2 = (i2 - 2ij + j2) + (ij - j2) + j2 = i2 - ij + j2

And since both (i-j) and j are non-negative, any generation of Loeschian numbers involving a negative number can be achieved using non-negative numbers.

Saved a byte, Next:Next -> Next b,a thanks to Taylor Scott.


答:
Notepad++, ??? keystrokes

I have no idea how to score this, but I decided to give it a shot since there's an answer on Notepad.

Here's the sequence:

* * * * *  CTRL (hold) A D → D D D D D D D D D

Title: Print a 10 by 10 grid of asterisks

Body:
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.


Title: Hello World in 1024 characters

Body:
In exactly 1024 characters, no more, no less:

Must print Hello World.

Must not use unnecessary whitespace.

Must not use comments.

Judging should favor creativity and/or humor over simple obfuscation when voting up answers.

The earliest I will select an answer is the 11th (Sunday) of November (2012). I'm seeing some awesome entries so far, can't wait to see what else people come up with.


答:
Jellyfish, <s>56</s> <s>43</s> <s>41</s> <s>29</s> 28 bytes

2 bytes thanks to Zgarb

```<code>p
n    <
+`/
`1*
/
+
&*r&;>i
</code>```

Try it online!

A fork of my Jelly answer.

Title: Is this number Loeschian?

Body:
A positive integer \$k\$ is a Loeschian number if

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers.

For example, the first positive Loeschian numbers are: \$1\$ (\$i=1, j=0\$); \$3\$ (\$i=j=1\$); \$4\$ (\$i=2, j=0\$); \$7\$ (\$i=2, j=1\$); \$9\$ (\$i=-3, j=3\$); ... Note that \$i, j\$ for a given \$k\$ are not unique. For example, \$9\$ can also be generated with \$i=3, j=0\$.

Other equivalent characterizations of these numbers are:

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i, j\$ non-negative integers. (For each pair of integers \$i, j\$ there's a pair of non-negative integers that gives the same \$k\$)

There is a set of \$k\$ contiguous hexagons that forms a tesselation on a hexagonal grid so that corresponding cells are the same distance apart (see illustrations for \$k = 4\$ and for \$k = 7\$). (Because of this property, these numbers find application in mobile cellular communication networks.)

See more characterizations in the OEIS page of the sequence.

The challenge

Given a positive integer, output a truthy result if it is a Loeschian number, or a falsy result otherwise.

The program or function should handle (say in less than a minute) inputs up to \$1000\$, or up to data type limitations.

Code golf. Shortest wins.

Test cases

The following numbers should output a truthy result:

```<code>1, 4, 7, 12, 13, 108, 109, 192, 516, 999
</code>```

The following numbers should output a falsy result:

```<code>2, 5, 10, 42, 101, 102, 128, 150, 501, 1000
</code>```

Body:
Jellyfish, <s>56</s> <s>43</s> <s>41</s> <s>29</s> 28 bytes

2 bytes thanks to Zgarb

p
n    <
+`/
`1*
/
+
&*r&;>i

Try it online!

A fork of my Jelly answer.


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

0. DEFINITIONS

A sequence is a list of numbers.

A series is the sum of a list of numbers.

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

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

1. PREAMBLE

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

2. CHALLENGE

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

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

Concatenated, these look like:

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

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

3. TEST CASES

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

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

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

Additional test cases may be provided upon request.

4. REFERENCES

OEIS has a list of numbers and their aliquot sums.

答:
Java 8, 220 bytes

```<code>import java.util.stream.IntStream;
char a(int n){return IntStream.range(1,n+2).map(i->IntStream.range(1,i).filter(k->i%k==0).sum()).mapToObj(Integer::toString).collect(java.util.stream.Collectors.joining("")).charAt(n);}
</code>```

Well, it's fast at least. It averages 0.3 seconds to get the 9999/10000th element on my machine. It generates only as many aliquot sums as the index you specified. This means the string will be slightly longer than your index in most cases, since some aliquot sums have 2 or more digits, but for the most part, it only generates as long of a string as we need.

Usage:

```<code>public static void main(String[] args) {
    System.out.println(a(0));
    System.out.println(a(4));
    System.out.println(a(12));
    System.out.println(a(9999));
}
</code>```

Ungolfed:

```<code>public static void main(String[] args) {
    System.out.println(all(0));
    System.out.println(all(4));
    System.out.println(all(12));
    System.out.println(all(9999));
}

static int aliquotSum(int n) {
    return IntStream.range(1, n).filter(k -> n % k == 0).sum();
}

static IntStream sums(int n) {
    return IntStream.range(1, n + 2).map(i -> aliquotSum(i));
}

static String arraycat(IntStream a) {
    return a.mapToObj(Integer::toString).collect(java.util.stream.Collectors.joining(""));
}

static char all(int index) {
    return arraycat(sums(index)).charAt(index);
}
</code>```

Body:
Java 8, 220 bytes

import java.util.stream.IntStream;
char a(int n){return IntStream.range(1,n+2).map(i->IntStream.range(1,i).filter(k->i%k==0).sum()).mapToObj(Integer::toString).collect(java.util.stream.Collectors.joining("")).charAt(n);}

Well, it's fast at least. It averages 0.3 seconds to get the 9999/10000th element on my machine. It generates only as many aliquot sums as the index you specified. This means the string will be slightly longer than your index in most cases, since some aliquot sums have 2 or more digits, but for the most part, it only generates as long of a string as we need.

Usage:

public static void main(String[] args) {
    System.out.println(a(0));
    System.out.println(a(4));
    System.out.println(a(12));
    System.out.println(a(9999));
}

Ungolfed:

public static void main(String[] args) {
    System.out.println(all(0));
    System.out.println(all(4));
    System.out.println(all(12));
    System.out.println(all(9999));
}

static int aliquotSum(int n) {
    return IntStream.range(1, n).filter(k -> n % k == 0).sum();
}

static IntStream sums(int n) {
    return IntStream.range(1, n + 2).map(i -> aliquotSum(i));
}

static String arraycat(IntStream a) {
    return a.mapToObj(Integer::toString).collect(java.util.stream.Collectors.joining(""));
}

static char all(int index) {
    return arraycat(sums(index)).charAt(index);
}


答:
EXCEL, 26 bytes.

```<code>=REPT("**********[ae]",10)
</code>```

Can go into any cell.

Title: Print a 10 by 10 grid of asterisks

Body:
EXCEL, 26 bytes.

=REPT("**********[ae]",10)

Can go into any cell.


答:
Dyalog APL, 19 bytes

⊢∊(∘.(×-⍨2*⍨+)⍨0,⍳)
```

Checks if k ∊ (i + j)² – ij, for any 0 ≤ i, j ≤ k.

    ⊢ is k

∊ a member of

    ∘. all combinations of

        × i times j

        -⍨ subtracted from

        2*⍨ the square of

        + i plus j

    ⍨ for all i and j in

    0, zero prepended to

    ⍳ the integers 1 through k

1000 takes 3.3 seconds on my M540 and even less on TryAPL.

Title: Is this number Loeschian?

Body:
Dyalog APL, 19 bytes

⊢∊(∘.(×-⍨2*⍨+)⍨0,⍳)

Checks if k ∊ (i + j)² – ij, for any 0 ≤ i, j ≤ k.

    ⊢ is k

∊ a member of

    ∘. all combinations of

        × i times j

        -⍨ subtracted from

        2*⍨ the square of

        + i plus j

    ⍨ for all i and j in

    0, zero prepended to

    ⍳ the integers 1 through k

1000 takes 3.3 seconds on my M540 and even less on TryAPL.


Title: Print a 10 by 10 grid of asterisks

Body:
Swift 2, 45 Bytes

func a(){for _ in 0...9{print("**********")}}


答:
Python 2.7, <s>255</s> <s>238</s> 236 bytes

Even though this loses to both of the other Python 2 solutions, I liked my recursive approach:

```<code>def r(s,p):
 for(a,b)in p:s=a.join(s.split(b))
 return s
def t(w):
 i='_'*2*w;s='\n __%s\n/,%s,\o'%(i,i)
 if w:s=r(t(w-1),[('\n ','\n'),('Z/',' /'),('\\Z\n','\\\n'),(' /','o/'),('\\','\\o'),('o','Z')])+s
 return s
print t(input()-1)[1:]
</code>```

edit1: dropped a few bytes by eliminating some replacements

edit2: shaved 2 bytes by saving the underscores as a variable

Title: Turtles All the Way Down

Body:
Write a program or function that takes in a positive integer and prints or returns a stack of that many ASCII-art turtles, where each turtle is larger than the one above it.

Specifically, if the input is 1, the output should be:

```<code> __
/,,\o
</code>```

If the input is 2:

```<code>  __
o/,,\
 ____
/,__,\o
</code>```

If the input is 3:

```<code>   __
  /,,\o
  ____
o/,__,\
 ______
/,____,\o
</code>```

If the input is 4:

```<code>    __
  o/,,\
   ____
  /,__,\o
  ______
o/,____,\
 ________
/,______,\o
</code>```

If the input is 5:

```<code>     __
    /,,\o
    ____
  o/,__,\
   ______
  /,____,\o
  ________
o/,______,\
 __________
/,________,\o
</code>```

And so on in the same pattern for larger inputs.

Note that:

The head (the o) of the bottom turtle is always on the right. The heads of the turtles above then alternate back and forth.

No lines may have trailing spaces.

Superfluous leading spaces are not allowed. (i.e. the back of the bottom turtle should be at the start of the line.)

A single optional trailing newline is allowed.

The shortest code in bytes wins.

Body:
Python 2.7, <s>255</s> <s>238</s> 236 bytes

Even though this loses to both of the other Python 2 solutions, I liked my recursive approach:

def r(s,p):
 for(a,b)in p:s=a.join(s.split(b))
 return s
def t(w):
 i='_'*2*w;s='\n __%s\n/,%s,\o'%(i,i)
 if w:s=r(t(w-1),[('\n ','\n'),('Z/',' /'),('\\Z\n','\\\n'),(' /','o/'),('\\','\\o'),('o','Z')])+s
 return s
print t(input()-1)[1:]

edit1: dropped a few bytes by eliminating some replacements

edit2: shaved 2 bytes by saving the underscores as a variable


答:
Wolfram, 22 bytes

```<code>Grid[Table["*",10,10]]
</code>```

Title: Print a 10 by 10 grid of asterisks

Body:
Wolfram, 22 bytes

Grid[Table["*",10,10]]


Title: Generating Binary shapes

Body:
How could we generate shapes or images using binary?

I got to messing around trying to create something that looked matrix like and got to thinking, wouldn't a great CodeGolf be to see who can make the best shortest code to generate a binary image?

Please advise me of any rules I should add.

Rules:

Create a binary image art of a Meme using 40 chars wide by 20 chars tall.

Shortest code out of top 3 voted images wins.

Example Output:

```<code>00000000000000000000000000000000000000000
00000000000000000000000000000000000000000
00000000000000000000000000000000000000000
00000000000000000000000000000000000000000
00000000000000000000000000000000000000000
00000000000000000000000000000000000000000
00000000000000000000000000000000000000000
00000000000000000000000000000000000000000
00000000001111000000000000011110000000000
00000000111111110000000001111111100000000
00000011110000111100001111000001111000000
00000011110000111100001111000001111000000
00000011110000111100001111000001111000000
00000011110000001111111100000001111000000
00000011110000000011110000000001111000000
00000011110000000000000000000001111000000
00000011110000000000000000000001111000000
00001111000000000000000000000000011110000
00111100000000000000000000000000000111100
11110000000000000000000000000000000001111
</code>```

Body:
I could make no sense out of that knowyourmeme site. So here's a riff on your first reference: something matrix like.

Postscript (287) (310)

Edit: Better output (more 'ones', less apparent waves).

Run with gs -dNODISPLAY -q -- matrix.ps 60. Replace 60 with the number of columns to generate.

%!
<<
0{(1)print}
1{(0)print}
10{()=}
/#{load exec}
/rho ARGUMENTS 0 get cvi
/enn 0
/set{[rho{rand rand 30 mod 2 idiv 3 mul neg bitshift}repeat]}
/lin{[exch{dup 2 idiv exch 2 mod #}forall]10 #}
/zer{/enn enn 1 add def enn 6 mod 0 eq{dup 0 exch{add}forall rho 1.1 exp lt{pop set}if}if}
>>begin
set{lin zer}loop

It generates infinite output like this, mostly ones with vertical zero "signals":

011001110110110001100101111110011111001101101111110111011101
010011111101100011110110110111010101001101111111111110011101
111111110111110001111100010110110011011101111111110110011101
110110111111110011111011110110111110111111101111110111111101
010101111111110101101100011100100110001101101111111110011101
110101111111101101101010011110101111001101111111110111111111
011111111111101001100111011100000011111101101111110111011011
010111111111111101101100111110100001101111111111111110011101
010100111111101001111011011111011001111111111111111110111001
011111111111101011110100011101001101101111111111110110111111
111100111111111101111100011111110001101111101111111111011011
111100111111101011110001011101111101101111111111111111111101
111101111111111001111001011111010101111101101111111110111111
011110111111111001100101011111011101111111101111111111111101
011101111111111101110001111111011101111111111111111111011101
111101111111111111110111111111111111111111111111110110011111
011101111111101011100111011111110101111111101111111111111111
011100111111111101111011111111111111111101101111110111011101
011111111111101111110111111111010111111111111111111111111111
011100111111111011110101111111111101111111111111111111011111
011101111111111111110101111111110111111111111111111111011111
111111111111111101111111111111111111111111111111111111011111
111111111111101101111101111111111111111111111111111111011111
111111111111101111111111111111111111111111111111111111011111
111111111111101111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111011111
010011010111011111001101111111011001011011011011111010111111
110011011111001111001111011100111011111011110011111101100110
110101111111111011111011111000110101110011011010111111110110
010111111111001111111001111000110001111111011111111110101110
010001111111111111110001011100110001100011110111101010111101
011011111011001011111001011100111111110111110110111011100110
011001011111101111110111011100110111100111111110111111111100
011101111011101111110001111110111111111111110111111010111111
011101111011101011111101111110110011011111010111101110101111
111101111011111011110001011101110001111011011111111000111100
111101011111011111111011111110111001101111111111111101111111
111101111111001111111111111110110011000011111111111100100111
11010101111110^C
Command terminated


答:
Actually, 7 bytes

```<code>9u;'**n
</code>```

Try it online!

Explanation:

```<code>9u;'**n
9u;      push two copies of 10
   '*    push "*"
     *   multiply by one of the copies, yielding "**********"
      n  push 10 total copies of the string
</code>```

Title: Print a 10 by 10 grid of asterisks

Body:
Actually, 7 bytes

9u;'**n

Try it online!

Explanation:

9u;'**n
9u;      push two copies of 10
   '*    push "*"
     *   multiply by one of the copies, yielding "**********"
      n  push 10 total copies of the string


问:
Wait, but what's e^N?
Objective:

The objective is to calculate e^N for some real or imaginary N (e.g. 2, -3i, 0.7, 2.5i, but not 3+2i). This is code golf, so, shortest code (in bytes) wins.

So, for example:

N = 3, e^N = 20.0855392

N = -2i, e^N = -0.416146837 - 0.9092974268i

The letter i shouldn't be capitalized (since in math it is lowercase)

If your language supports raising numbers to complex numbers, you can't use that. You may use built-in real exponentiation.

For any answer where b (in a + bi) is negative, it is OK to have both the plus and minus sign (e.g. 2 + -3i), since that is understood to be (2 - 3i)

Bonus (-15 bytes): Solve this for N is a any complex number (e.g. 5 + 7i). If you are going for the bonus, you can assume that both components will always be given (even for the standard objective)

答:
APL (Dyalog Extended), <s>20</s> 16 - 15 = 1 byte (SBCS)

'+i',⍨¨*⍤⊣×2 1○⊢
```

'+i',⍨¨ append "+" and "i" to the ends of

  * e to the power of

   ⊣ the left argument (the real part)

 × times

  2 1○ the cosine and sine of

   ⊢ the right argument (the imaginary part)

TryAPL online!

Title: Wait, but what's e^N?

Body:
APL (Dyalog Extended), <s>20</s> 16 - 15 = 1 byte (SBCS)

'+i',⍨¨*⍤⊣×2 1○⊢

'+i',⍨¨ append "+" and "i" to the ends of

  * e to the power of

   ⊣ the left argument (the real part)

 × times

  2 1○ the cosine and sine of

   ⊢ the right argument (the imaginary part)

TryAPL online!


问:
Collatz Paths: Forwards and Backwards along the Collatz Conjecture
The Collatz conjecture is a very well-known conjecture. Take a positive integer; if it's even, divide by 2, else, multiply by 3 and add 1. Repeat until you reach 1 or something else happens. The conjecture is that this process always reaches 1.

You can also reverse the process. Start at 1, multiply by 2, and to branch to multiply by 3 and add 1 numbers, when you reach an even number that is 1 (mod 3), subtract 1 and divide by 3.

A Collatz path combines the two, trying to get from one number to another with those four operations.

For example, to get to 20 from 1:

```<code>1     *2
2     *2
4     *2
8     *2
16    *2
5     (-1)/3
10    *2
20    *2
</code>```

You can also get to 3 from 10 by subtracting 1 and dividing by 3.

With these tools, you can traverse a Collatz path from one number to another. For example, the path from 20 to 3 is (divide by 2), (subtract 1, divide by 3).

In short, the available operations are:

```<code>n * 2       always
n // 2      if n % 2 == 0
n * 3 + 1   if n % 2 == 1
(n-1) // 3  if n % 6 == 4
</code>```

Note: not all Collatz paths are short. a(7,3) could run

```<code>7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 2, 4, 8, 16, 5, 10, 3
</code>```

but a shorter path is

```<code>7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 3
</code>```

The Challenge

Find the length of the shortest Collatz path between any two positive integers, p and q.

Input is any two positive integers less than 2^20 to avoid integer overflow. The input method is left to the discretion of the golfer. The integers may be the same, in which case, the length of the Collatz path is 0.

Output should be one integer, denoting the length of the shortest Collatz path between p and q.

Test Cases

```<code>a(2,1)
1

a(4,1)
1         # 4 -> 1

a(3,1)
6         # 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 1

a(11,12)
11        # 11 -> 34 -> 17 -> 52 -> 26 -> 13
          # -> 40 -> 20 -> 10 -> 3 -> 6 -> 12

a(15,9)
20        # 46 -> 23 -> 70 -> 35 -> 106 -> 53 -> 160 -> 80 -> 40 -> 13
          # -> 26 -> 52 -> 17 -> 34 -> 11 -> 22 ->  7 -> 14 -> 28 -> 9
</code>```

Many thanks to orlp for their help in clarifying this challenge.

As always, if the problem is unclear, please let me know. Good luck and good golfing!

答:
JavaScript (ES6), 135 bytes

```<code>f=(x,y,a=[(s=[],s[0]=s[x]=1,x)],z=a.shift())=>z-y?[z*2,z/2,z%2?z*3+1:~-z/3].map(e=>e%1||s[e]?0:s[a.push(e),e]=-~s[z])&&f(x,y,a):~-s[y]
</code>```

Performs a breadth-first search. x is the starting number, y the destination, a an array of trial values, s an array of the number of inclusive steps on the chain from x, z the current value. If z and y are not equal, compute z*2, z/2 and either z*3+1 or (z-1)/3, depending on whether z is odd or even, then filter out fractions and previously seen values and add them to the search list.

Body:
JavaScript (ES6), 135 bytes

f=(x,y,a=[(s=[],s[0]=s[x]=1,x)],z=a.shift())=>z-y?[z*2,z/2,z%2?z*3+1:~-z/3].map(e=>e%1||s[e]?0:s[a.push(e),e]=-~s[z])&&f(x,y,a):~-s[y]

Performs a breadth-first search. x is the starting number, y the destination, a an array of trial values, s an array of the number of inclusive steps on the chain from x, z the current value. If z and y are not equal, compute z*2, z/2 and either z*3+1 or (z-1)/3, depending on whether z is odd or even, then filter out fractions and previously seen values and add them to the search list.


答:
Python, (94 - 15) = 79 bytes

```<code>from math import *
import cmath
n=input()
print `e**(n[0])*(cos(n[1])+1j*sin(n[1]))`[1:-2]+'i'
</code>```

Pretty straightforward implementation. Since python uses "j" instead of "i" for imaginary numbers, replacing the characters in the final string eats up quite a few (12) bytes. This can definitely still be golfed.

Takes input in the form of [a,b] for a + bi.

Title: Wait, but what's e^N?

Body:
Objective:

The objective is to calculate e^N for some real or imaginary N (e.g. 2, -3i, 0.7, 2.5i, but not 3+2i). This is code golf, so, shortest code (in bytes) wins.

So, for example:

N = 3, e^N = 20.0855392

N = -2i, e^N = -0.416146837 - 0.9092974268i

The letter i shouldn't be capitalized (since in math it is lowercase)

If your language supports raising numbers to complex numbers, you can't use that. You may use built-in real exponentiation.

For any answer where b (in a + bi) is negative, it is OK to have both the plus and minus sign (e.g. 2 + -3i), since that is understood to be (2 - 3i)

Bonus (-15 bytes): Solve this for N is a any complex number (e.g. 5 + 7i). If you are going for the bonus, you can assume that both components will always be given (even for the standard objective)

Body:
Python, (94 - 15) = 79 bytes

from math import *
import cmath
n=input()
print `e**(n[0])*(cos(n[1])+1j*sin(n[1]))`[1:-2]+'i'

Pretty straightforward implementation. Since python uses "j" instead of "i" for imaginary numbers, replacing the characters in the final string eats up quite a few (12) bytes. This can definitely still be golfed.

Takes input in the form of [a,b] for a + bi.


答:
JavaScript (ES6), 178 bytes

```<code> (s,e)=>{q='bleen';t=[];for(i=-10;i<11;i++)t.push(i);t.splice(4,0,'-'+q);t.splice(18,0,q);s=t.indexOf(s);e=t.indexOf(e);s>e&&t.reverse()&&(e=22-e)&&(s=22-s);return t.slice(s,e+1)}
</code>```

Try it

EDIT: Fix for reverse ordering.Thanks Patrick, missed this condition

Title: A newly discovered number: bleen!

Body:
"The Nobel Prize in mathematics was awarded to a California professor who has discovered a new number! The number is bleen, which he claims belongs between 6 and 7."  --George Carlin

In this challenge, you will print all Integers, inclusive, within the given input range.  Print numbers ascending or descending according to their input order.  That is, for input [n1, n2], print ascending if n1 < n2, descending if n1 > n2.

Since bleen is now an Integer number it may be used as input.  It must also be included in the output, between 6 and 7 where applicable.  Also note that -bleen exists between -7 and -6.

Input

Two Integers [n1, n2] in the range [-10, 10], inclusive, via your programming language's input of choice.

(Input may also contain bleen and -bleen!)

Output

Print all Integers starting at n1 and ending with n2, including the newly discovered bleen between 6 and 7.  Output can be a range of character separated numbers in some form your language supports - that is, comma or space separated.  One trailing space of output is okay.

Examples

```<code>Input:  1 10
Output: 1 2 3 4 5 6 bleen 7 8 9 10

Input:  -9 -4
Output: -9 -8 -7 -bleen -6 -5 -4

Input:  -8 bleen
Output: -8 -7 -bleen -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 bleen

Input:  9 1
Output: 9 8 7 bleen 6 5 4 3 2 1

Input:  2 -bleen
Output: 2 1 0 -1 -2 -3 -4 -5 -6 -bleen

Input:  -bleen 0
Output: -bleen -6 -5 -4 -3 -2 -1 0

Input:  bleen bleen
Output: bleen

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

Additional notes

You may write a program or function and use any standard method of receiving input and providing output.

You may use any programming language, but standard loopholes are not allowed.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

Body:
JavaScript (ES6), 178 bytes

 (s,e)=>{q='bleen';t=[];for(i=-10;i<11;i++)t.push(i);t.splice(4,0,'-'+q);t.splice(18,0,q);s=t.indexOf(s);e=t.indexOf(e);s>e&&t.reverse()&&(e=22-e)&&(s=22-s);return t.slice(s,e+1)}

Try it

EDIT: Fix for reverse ordering.Thanks Patrick, missed this condition


问:
Compounding english
A compound word is a word that contains 2 or more words in it.  We can do better than that, though.  We need you to create 1 (nonsensical) word that contains every word.

However, we want this word to be as short as possible.  We can use overlapping letters to achieve this.

For example, if your word list was ["cat", "atom", "a"], you would want to return "catom".

Input/Output

Your program will need to take a list of words as input, and return a compound word as output.

The word list you will be using is the top 10000 words in English, according to Google  (If this list turns out to be too easy, I may change it to a longer one).   For reference, simply appending each word gives you a score of 65888.

Your score is the number of letters in your final word, lower is better.  Tie breaker goes to the first poster.

答:
PHP 46612 characters

This is just a start. I hope to improve it. All I've done so far is remove any word that is a sub-string of another word. I'm working on 3 copies of the array, but the memory doesn't seem to be an issue.

```<code><?php
set_time_limit(3000);

$words=file('https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt');
$words = array_map('trim', $words);

usort($words, function ($a, $b)
{
    if (strlen($a) == strlen($b) ){
        return 0;
    }
    return ( strlen($a) < strlen($b) )? -1 : 1;
});

$final_array=$words;
$comparison_array=$words;

  foreach($words as $key => $word){
    echo $word."<br>\n";
      foreach($comparison_array as $nestedKey => $nestedWord){
          if (strlen($nestedWord) <= strlen($word)) {
            unset($comparison_array[$nestedKey]);
            continue;
          }
          if( strpos($nestedWord,$word) !== FALSE ){
              unset($final_array[$key]);
              $restart=true;
              break;
          }
      }
  }

sort($final_array);
$compound='';
$compound = implode($final_array);
echo $compound;
echo "  <br><br>\n\n". strlen($compound);
</code>```

Title: Compounding english

Body:
PHP 46612 characters

This is just a start. I hope to improve it. All I've done so far is remove any word that is a sub-string of another word. I'm working on 3 copies of the array, but the memory doesn't seem to be an issue.

<?php
set_time_limit(3000);

$words=file('https://raw.githubusercontent.com/first20hours/google-10000-english/master/google-10000-english.txt');
$words = array_map('trim', $words);

usort($words, function ($a, $b)
{
    if (strlen($a) == strlen($b) ){
        return 0;
    }
    return ( strlen($a) < strlen($b) )? -1 : 1;
});

$final_array=$words;
$comparison_array=$words;

  foreach($words as $key => $word){
    echo $word."<br>\n";
      foreach($comparison_array as $nestedKey => $nestedWord){
          if (strlen($nestedWord) <= strlen($word)) {
            unset($comparison_array[$nestedKey]);
            continue;
          }
          if( strpos($nestedWord,$word) !== FALSE ){
              unset($final_array[$key]);
              $restart=true;
              break;
          }
      }
  }

sort($final_array);
$compound='';
$compound = implode($final_array);
echo $compound;
echo "  <br><br>\n\n". strlen($compound);


答:
Python 2, 49 bytes

lambda n:0in[(n-3*i*i+0j)**.5%1for i in range(n)]
```

Try it online!

Uses the equivalent quadratic form given on OEIS of n == 3*i*i+j*j.  Check whether n-3*i*i is a perfect square for any i by taking its square root and checking if it's an integer, i.e. equals 0 modulo 1. Note that Python computes square roots of perfect squares exactly, without floating point error. The +0j makes it a complex number to avoid an error on the square root of a negative.

Title: Is this number Loeschian?

Body:
A positive integer \$k\$ is a Loeschian number if

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i\$, \$j\$ integers.

For example, the first positive Loeschian numbers are: \$1\$ (\$i=1, j=0\$); \$3\$ (\$i=j=1\$); \$4\$ (\$i=2, j=0\$); \$7\$ (\$i=2, j=1\$); \$9\$ (\$i=-3, j=3\$); ... Note that \$i, j\$ for a given \$k\$ are not unique. For example, \$9\$ can also be generated with \$i=3, j=0\$.

Other equivalent characterizations of these numbers are:

\$k\$ can be expressed as \$i^2 + j^2 + i\times j\$ for \$i, j\$ non-negative integers. (For each pair of integers \$i, j\$ there's a pair of non-negative integers that gives the same \$k\$)

There is a set of \$k\$ contiguous hexagons that forms a tesselation on a hexagonal grid so that corresponding cells are the same distance apart (see illustrations for \$k = 4\$ and for \$k = 7\$). (Because of this property, these numbers find application in mobile cellular communication networks.)

See more characterizations in the OEIS page of the sequence.

The challenge

Given a positive integer, output a truthy result if it is a Loeschian number, or a falsy result otherwise.

The program or function should handle (say in less than a minute) inputs up to \$1000\$, or up to data type limitations.

Code golf. Shortest wins.

Test cases

The following numbers should output a truthy result:

```<code>1, 4, 7, 12, 13, 108, 109, 192, 516, 999
</code>```

The following numbers should output a falsy result:

```<code>2, 5, 10, 42, 101, 102, 128, 150, 501, 1000
</code>```

Body:
Python 2, 49 bytes

lambda n:0in[(n-3*i*i+0j)**.5%1for i in range(n)]

Try it online!

Uses the equivalent quadratic form given on OEIS of n == 3*i*i+j*j.  Check whether n-3*i*i is a perfect square for any i by taking its square root and checking if it's an integer, i.e. equals 0 modulo 1. Note that Python computes square roots of perfect squares exactly, without floating point error. The +0j makes it a complex number to avoid an error on the square root of a negative.


答:
R, 150 bytes

```<code>a=function(x,y=1){d=x-y;t=d%%2;cat(rep(" ",d+1),rep("_",2*y),"\n",rep(" ",d-t),"o"[t],"/,",rep("_",2*y-2),",\\","o"[!t],"\n",sep="");if(y<x)a(x,y+1)}
</code>```

more cleanly (adds a byte)

```<code>a=function(x,y=1){
     d=x-y
     t=d%%2
     cat(rep(" ",d+1),rep("_",2*y),"\n",rep(" ",d-t),"o"[t],"/,",rep("_",2*y-2),",\\","o"[!t],"\n",sep="")
     if(y<x)a(x,y+1)
}
</code>```

Basic structure recursively calls itself --telling itself both the final number to be called and the current level. Starts with a default for y=1, so it only needs one variable for initial call. Quickly defines two values that are frequently used. Then it just repeats everything the necessary number of times.

```<code>"o"[t],"o"[!t]
</code>```

Each of these implicitly test whether to add the head to right or left and place it appropriately.

Title: Turtles All the Way Down

Body:
R, 150 bytes

a=function(x,y=1){d=x-y;t=d%%2;cat(rep(" ",d+1),rep("_",2*y),"\n",rep(" ",d-t),"o"[t],"/,",rep("_",2*y-2),",\\","o"[!t],"\n",sep="");if(y<x)a(x,y+1)}

more cleanly (adds a byte)

a=function(x,y=1){
     d=x-y
     t=d%%2
     cat(rep(" ",d+1),rep("_",2*y),"\n",rep(" ",d-t),"o"[t],"/,",rep("_",2*y-2),",\\","o"[!t],"\n",sep="")
     if(y<x)a(x,y+1)
}

Basic structure recursively calls itself --telling itself both the final number to be called and the current level. Starts with a default for y=1, so it only needs one variable for initial call. Quickly defines two values that are frequently used. Then it just repeats everything the necessary number of times.

"o"[t],"o"[!t]

Each of these implicitly test whether to add the head to right or left and place it appropriately.


答:
tinyAll, 17 bytes

The current version (untouched for a LONG time), is extremelly broken, but works enough for this challenge.

```<code>P'*Ra_P"
[:;]"R9_
</code>```

Basically:

Pass * to the R(repeat) function

Repeat it a (10) times

Output it (_)

Pass the output (;), through string interpolation, prefixed by a newline

To the R function

And repeat 9 more times

And display the result

A boring alternative, with the same byte count:

```<code>P"**********
"Ra_
</code>```

Translating:

Pass "**********
 (newline)

To the R function, to repeat a (10) times

And output the result (_)

Try it:

// Commit https://github.com/ismael-miguel/tinyall/commit/2589837678f4b6556d1bd22f163255e2e058808e#diff-65af36bb0dc600cbc7a54816dcda57fd
(function(window, undefined) {
 var funcs = {
  //echo
  '_':function(value, data){
   var tmp = data.out + (value === undefined ? data.last : value);
   data.vars[';'] = data.out = tmp;
   return tmp;
  },
  //array
  A:function(value, data){
   var split_value = (value || '').split(/(\-?\d+(?:\.\d*)?(?:[eE][\-+]?\d+)?|'(?:\\'|[^']*)*'),?/);
   var final_value = [];
   for(var i = 0, l = split_value.length; i<l; i++)
   {
    if(split_value[i][0] == '\'')
    {
     final_value[final_value.length] = split_value[i].replace(/^'(.*)'$/,'$1').replace(/\\'/g,'\'');
    }
    else if(split_value[i]/1 || split_value[i] == '0')
    {
     final_value[final_value.length] = +split_value[i];
    }
   }

   return final_value;
  },
  //comparison functions
  C:function(value, data){

  },
  D:function(value, data){

   var debug = {
    value: value,
    type: typeof value,
    memory: data
   }

   if(console && console.log)
   {
    console.log(debug);
   }

   return value;
  },
  //eval
  E:function(value, data){
   run_code(value, data);
  },
  //flip the value around
  F:function(value, data){
   if(('object' === typeof value) && value.reverse)
   {
    return value.reverse();
   }
   else
   {
    return value.toString().split('').reverse().join('');
   }
  },
  //hello worlds
  H:function(value) {
   return 'hH'[value&1]
    +'ello'
    +(value&2?',':'')
    +' '
    +('wW'[+!!(value&4)])
    +'orld'
    +(value&8?'!':'')
    +(value&16?'\n':'');
  },
  //math functions
  M:function(value, data){

  },
  //not (inverts values/casing)
  N:function(value) {
   switch(typeof value)
   {
    case 'boolean':
     return !value;
    case 'number':
     return -value;
    case 'string':
     var tmp = '';
     for(var i = 0, l = value.length; i < l; i++)
     {
      if(value[i] >= 'a' && value[i] <= 'z')
      {
       tmp += String.fromCharCode(value.charCodeAt(i) - 32);
      }
      else if(value[i] >= 'A' && value[i] <= 'Z')
      {
       tmp += String.fromCharCode(value.charCodeAt(i) + 32);
      }
      else
      {
       tmp += value[i];
      }
     }
     return tmp;
    default:
     return 0;
   }
  },
  //passthrough
  P:function(value) {
   return value;
  },
  //repeat
  R:function(value, data){
   var tmp = '';

   if(value > 0)
   {
    while(value--)
    {
     tmp += data.last;
    }
   }

   return tmp;
  },
  //string functions
  S:function(value, data){
   var methods = {
    t:function(value){
     return value.replace(/^\s+/,'').replace(/\s+$/,'');
    },
    u:function(value){
     return value.toUpperCase();
    },
    T:function(value ){

    },
    R:function(value){

    }
   };

   var tmp = data.last.toString();
   for(var i = 0, l = value.length; i < l; i++)
   {
    tmp = value[i] in methods ? methods[value[i]](tmp, value, i) : '';
   }

   return tmp;
  },
  //clears output
  Z:function(value, data) {
   return data.vars[';'] = data.out = 0;
  }
 };

 var expand_string = function(value, data){

  return value.replace(
   /\[:(?:([A-Z_])(.)?|([^A-Z_'"]))\]/g,
   function(_, func, arg, value){
    if(func)
    {
     return funcs[func](get_value(arg, data, true), data);
    }
    else
    {
     return get_value(value, data, true);
    }
   }
  );

 };

 var get_value = function(value, data, recursion) {

  if(value === null || value === undefined || value === ' ')
  {
   return undefined;
  }

  var x = (value || '').toString();

  if(/^\-?\d+(?:\.\d*)?(?:[eE][\-+]?\d+)?$/.test(x))
  {
   //returns a number
   return +x;
  }
  else if(/^[a-z]$/.test(x))
  {
   //returns a number between 10-43
   return (x in data.vars) ? data.vars[x] : x.charCodeAt(0) - 87;
  }
  else if(x[0] == '\'')
  {
   return x[1];
  }
  else if(x[0] == '"' && x.length >= 2)
  {
   var sub = x.substr(1, x.length - 2);

   return recursion ? sub : expand_string(sub, data);
  }
  else
  {
   return data.vars[x];
  }
 };

 var run_code = function(code, memory){

  if(!code || /^[a-z\d]$/.test(code))
  {
   memory.out = funcs.H(get_value(code, memory));
  }
  else
  {
   code.toString().replace(
    // /(?:([^A-Z_:'"])=)?([A-Z_])(?::('.|"[^"]*"|-?\d+|.))?/g,
    /(?:([^A-Z_'"])=)?([A-Z_])(?:('.|"[^"]*"|-?\d+|[^A-Z_'"]))?/g,
    function(_, name, func, value){

     memory.vars[name || ':'] = memory.last = (funcs[func] || noop)( value ? get_value(value, memory) : memory.last, memory);

     return '';
    }
   );
  }
 }

 var noop = function(){};

 window.tinyAll=function(code, input) {
  var data = {
   out: '',
   last: 0,
   input: input || 0,
   vars: {
    //version
    '|':'0.3',
    //input
    ':':input || 0,
    //output
    ';':0,
    //code
    '.':(code || '').toString()
   }
  };

  run_code(data.vars['.'], data);

  return data.out || 0;
 };
})(Function('return this')());

//RUN THE CODE!!!
//\n instead of a real newline, but works the same
console.log(tinyAll('P\'*Ra_P"\n[:;]"R9_'));
console.log(tinyAll('P"**********\n"Ra_'));```

Title: Print a 10 by 10 grid of asterisks

Body:
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.

Body:
tinyAll, 17 bytes

The current version (untouched for a LONG time), is extremelly broken, but works enough for this challenge.

P'*Ra_P"
[:;]"R9_

Basically:

Pass * to the R(repeat) function

Repeat it a (10) times

Output it (_)

Pass the output (;), through string interpolation, prefixed by a newline

To the R function

And repeat 9 more times

And display the result

A boring alternative, with the same byte count:

P"**********
"Ra_

Translating:

Pass "**********
 (newline)

To the R function, to repeat a (10) times

And output the result (_)

Try it:

// Commit https://github.com/ismael-miguel/tinyall/commit/2589837678f4b6556d1bd22f163255e2e058808e#diff-65af36bb0dc600cbc7a54816dcda57fd
(function(window, undefined) {
 var funcs = {
  //echo
  '_':function(value, data){
   var tmp = data.out + (value === undefined ? data.last : value);
   data.vars[';'] = data.out = tmp;
   return tmp;
  },
  //array
  A:function(value, data){
   var split_value = (value || '').split(/(\-?\d+(?:\.\d*)?(?:[eE][\-+]?\d+)?|'(?:\\'|[^']*)*'),?/);
   var final_value = [];
   for(var i = 0, l = split_value.length; i<l; i++)
   {
    if(split_value[i][0] == '\'')
    {
     final_value[final_value.length] = split_value[i].replace(/^'(.*)'$/,'$1').replace(/\\'/g,'\'');
    }
    else if(split_value[i]/1 || split_value[i] == '0')
    {
     final_value[final_value.length] = +split_value[i];
    }
   }

   return final_value;
  },
  //comparison functions
  C:function(value, data){

  },
  D:function(value, data){

   var debug = {
    value: value,
    type: typeof value,
    memory: data
   }

   if(console && console.log)
   {
    console.log(debug);
   }

   return value;
  },
  //eval
  E:function(value, data){
   run_code(value, data);
  },
  //flip the value around
  F:function(value, data){
   if(('object' === typeof value) && value.reverse)
   {
    return value.reverse();
   }
   else
   {
    return value.toString().split('').reverse().join('');
   }
  },
  //hello worlds
  H:function(value) {
   return 'hH'[value&1]
    +'ello'
    +(value&2?',':'')
    +' '
    +('wW'[+!!(value&4)])
    +'orld'
    +(value&8?'!':'')
    +(value&16?'\n':'');
  },
  //math functions
  M:function(value, data){

  },
  //not (inverts values/casing)
  N:function(value) {
   switch(typeof value)
   {
    case 'boolean':
     return !value;
    case 'number':
     return -value;
    case 'string':
     var tmp = '';
     for(var i = 0, l = value.length; i < l; i++)
     {
      if(value[i] >= 'a' && value[i] <= 'z')
      {
       tmp += String.fromCharCode(value.charCodeAt(i) - 32);
      }
      else if(value[i] >= 'A' && value[i] <= 'Z')
      {
       tmp += String.fromCharCode(value.charCodeAt(i) + 32);
      }
      else
      {
       tmp += value[i];
      }
     }
     return tmp;
    default:
     return 0;
   }
  },
  //passthrough
  P:function(value) {
   return value;
  },
  //repeat
  R:function(value, data){
   var tmp = '';

   if(value > 0)
   {
    while(value--)
    {
     tmp += data.last;
    }
   }

   return tmp;
  },
  //string functions
  S:function(value, data){
   var methods = {
    t:function(value){
     return value.replace(/^\s+/,'').replace(/\s+$/,'');
    },
    u:function(value){
     return value.toUpperCase();
    },
    T:function(value ){

    },
    R:function(value){

    }
   };

   var tmp = data.last.toString();
   for(var i = 0, l = value.length; i < l; i++)
   {
    tmp = value[i] in methods ? methods[value[i]](tmp, value, i) : '';
   }

   return tmp;
  },
  //clears output
  Z:function(value, data) {
   return data.vars[';'] = data.out = 0;
  }
 };

 var expand_string = function(value, data){

  return value.replace(
   /\[:(?:([A-Z_])(.)?|([^A-Z_'"]))\]/g,
   function(_, func, arg, value){
    if(func)
    {
     return funcs[func](get_value(arg, data, true), data);
    }
    else
    {
     return get_value(value, data, true);
    }
   }
  );

 };

 var get_value = function(value, data, recursion) {

  if(value === null || value === undefined || value === ' ')
  {
   return undefined;
  }

  var x = (value || '').toString();

  if(/^\-?\d+(?:\.\d*)?(?:[eE][\-+]?\d+)?$/.test(x))
  {
   //returns a number
   return +x;
  }
  else if(/^[a-z]$/.test(x))
  {
   //returns a number between 10-43
   return (x in data.vars) ? data.vars[x] : x.charCodeAt(0) - 87;
  }
  else if(x[0] == '\'')
  {
   return x[1];
  }
  else if(x[0] == '"' && x.length >= 2)
  {
   var sub = x.substr(1, x.length - 2);

   return recursion ? sub : expand_string(sub, data);
  }
  else
  {
   return data.vars[x];
  }
 };

 var run_code = function(code, memory){

  if(!code || /^[a-z\d]$/.test(code))
  {
   memory.out = funcs.H(get_value(code, memory));
  }
  else
  {
   code.toString().replace(
    // /(?:([^A-Z_:'"])=)?([A-Z_])(?::('.|"[^"]*"|-?\d+|.))?/g,
    /(?:([^A-Z_'"])=)?([A-Z_])(?:('.|"[^"]*"|-?\d+|[^A-Z_'"]))?/g,
    function(_, name, func, value){

     memory.vars[name || ':'] = memory.last = (funcs[func] || noop)( value ? get_value(value, memory) : memory.last, memory);

     return '';
    }
   );
  }
 }

 var noop = function(){};

 window.tinyAll=function(code, input) {
  var data = {
   out: '',
   last: 0,
   input: input || 0,
   vars: {
    //version
    '|':'0.3',
    //input
    ':':input || 0,
    //output
    ';':0,
    //code
    '.':(code || '').toString()
   }
  };

  run_code(data.vars['.'], data);

  return data.out || 0;
 };
})(Function('return this')());

//RUN THE CODE!!!
//\n instead of a real newline, but works the same
console.log(tinyAll('P\'*Ra_P"\n[:;]"R9_'));
console.log(tinyAll('P"**********\n"Ra_'));


问:
Calculating areas.
The smallest code that gives the area between the curve p(x) = a0 + a1*x + a2*x2 + ..., the line y = 0, the line x = 0 and the line x = C

(i.e. something like this:

)

You can assume that p(x) >= 0 for x < C (bonus points if your code works for negative values of p(x)).

Input

C, a0, a1, ...

Output

a real number - the area

Example 1:

```<code>input: 2, 0, 1
output: 2.0
</code>```

Examlpe 2:

```<code>input: 3.0, 0, 0.0, 2
output: 18
</code>```

UPDATE:

C > 0 is also assumed

the area is between the curve, y=0, x=C and x = 0

the input can be a list of any form; not necessarily comma separated.

the output can be a real of any form (thus, '18' is a valid output, as is '18.0')

ContentLicense: CC BY-SA 2.5

Title: Calculating areas.

Body:
J, 26 characters

f=:3 :'((1}.y)&p.d._1)0{y'

e.g.

   f 2 0 1
2
   f 3 0 0 2
18


答:
Swift 2.2, 342 Bytes

func a(x:String,y:String){var k="bleen",a=Int(x) ?? (x==k ?(x==y ? -9:6):-6),b=Int(y) ?? (y==k ?6:-6),t=0,s=[Any](),f=Int(x)==nil ?x:"";if a>b{t=a;a=b;b=t};for i in a...b{if i==7 && a != 7{s.append(k)};s.append(i);if -i==7 && b != -7{s.append("-"+k)}};for v in t==0 ?s:s.reverse(){f+=" \(v)"};if Int(y)==nil&&b>0{f+=" \(y)"};print(x==y ?x:f)}
```
<p>Test this using IBM's Swift Sandbox</p>
<p><strong>Ungolfed</strong></p>
<pre class="lang-swift prettyprint-override"><code>func bleen(x: String, y: String){
    var k = "bleen",
        a = Int(x) ?? (x == k ? (x == y ? -9 : 6) : -6),
        b = Int(y) ?? (y == k ? 6: -6),
        t = 0,
        s = [Any](),
        f = Int(x) == nil ? x : ""

    if a > b{
        t = a
        a = b
        b = t
    }

    for i in a...b{
        if i == 7 && a != 7{s.append(k)}
        s.append(i)
        if -i == 7 && b != -7{s.append("-" + k)}
    }

    if Int(y) == nil && b > 0{s.append(y)}

    for v in t == 0 ? s : s.reverse(){
        f+="\(v) "
    }

    print(x == y ? x : f)
}
</code>```

Title: A newly discovered number: bleen!

Body:
Swift 2.2, 342 Bytes

func a(x:String,y:String){var k="bleen",a=Int(x) ?? (x==k ?(x==y ? -9:6):-6),b=Int(y) ?? (y==k ?6:-6),t=0,s=[Any](),f=Int(x)==nil ?x:"";if a>b{t=a;a=b;b=t};for i in a...b{if i==7 && a != 7{s.append(k)};s.append(i);if -i==7 && b != -7{s.append("-"+k)}};for v in t==0 ?s:s.reverse(){f+=" \(v)"};if Int(y)==nil&&b>0{f+=" \(y)"};print(x==y ?x:f)}

Test this using IBM's Swift Sandbox

Ungolfed

func bleen(x: String, y: String){
    var k = "bleen",
        a = Int(x) ?? (x == k ? (x == y ? -9 : 6) : -6),
        b = Int(y) ?? (y == k ? 6: -6),
        t = 0,
        s = [Any](),
        f = Int(x) == nil ? x : ""

    if a > b{
        t = a
        a = b
        b = t
    }

    for i in a...b{
        if i == 7 && a != 7{s.append(k)}
        s.append(i)
        if -i == 7 && b != -7{s.append("-" + k)}
    }

    if Int(y) == nil && b > 0{s.append(y)}

    for v in t == 0 ? s : s.reverse(){
        f+="\(v) "
    }

    print(x == y ? x : f)
}