问:
Count up folks!

Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

答:
PowerShell, <s>32</s> 26 bytes

After reading the question thoroughly, I realized that my original answer does not support up to 2^64-1 since the range operator (..) in PS only supports 32bit integers.

Corrected answer:

<s>for($x=0;$x-le$args[0];$x++){$x}</s>

```<code>while($x++-ne$args[0]){$x}
</code>```

Usage (save as count.ps1):

```<code>PS>count.ps1 8
1
2
3
4
5
6
7
8
</code>```

Old method, supports only up to 2^32-1 taking input from the pipeline:

```<code>%{1..$_}
</code>```

Since expressions are only allowed as the first element in the PowerShell pipeline, I have to wrap it in a foreach (%).

Title: Count up folks!

Body:
PowerShell, <s>32</s> 26 bytes

After reading the question thoroughly, I realized that my original answer does not support up to 2^64-1 since the range operator (..) in PS only supports 32bit integers.

Corrected answer:

<s>for($x=0;$x-le$args[0];$x++){$x}</s>

while($x++-ne$args[0]){$x}

Usage (save as count.ps1):

PS>count.ps1 8
1
2
3
4
5
6
7
8

Old method, supports only up to 2^32-1 taking input from the pipeline:

%{1..$_}

Since expressions are only allowed as the first element in the PowerShell pipeline, I have to wrap it in a foreach (%).


问:
Make an HTML page goto infinite loop?
Write a code using HTML, JavaScript, jQuery to make the page go into infinite loop.

Restrictions:

No looping or control structures of javascript and jQuery allowed. You can only use alert, events, etc.

答:
This reloads the page as soon as it loads:

```<code><html>
<head>
<script>window.location=window.location</script>
</head>
</html>
</code>```

Or you could bring up infinite alert boxes (until the user disables them):

```<code><html>
<body onfocus="alert('')"></body>
</html>
</code>```

ContentLicense: CC BY-SA 3.0

Title: Make an HTML page goto infinite loop?

Body:
This reloads the page as soon as it loads:

<html>
<head>
<script>window.location=window.location</script>
</head>
</html>

Or you could bring up infinite alert boxes (until the user disables them):

<html>
<body onfocus="alert('')"></body>
</html>


答:
Turing Machine Simulator - 1366 Bytes (124 Lines)

```<code>0 * * r 0
0 _ , r 1
1 _ 1 r ,
, _ , l 2
2 * * l 2
2 , * l 3
3 _ * r 4
3 1 0 l 4
3 2 1 l 4
3 3 2 l 4
3 4 3 l 4
3 5 4 l 4
3 6 5 l 4
3 7 6 l 4
3 8 7 l 4
3 9 8 l 4
3 0 9 l 3
4 * * l 4
4 _ * r 5
5 0 _ r 5
5 , * * n
5 * * r 6
6 * * r 6
6 , * r 9
9 * * r 9
9 _ * l z
z * * l m
m * * l m
m , * r 7
7 * * r 7
7 , * * x
7 0 p r p
7 1 q r q
7 2 w r w
7 3 e r e
7 4 r r r
7 5 t r t
7 6 y r y
7 7 u r u
7 8 i r i
7 9 o r o
8 * * l 8
8 , * l m
p * * r p
p . * r P
p _ . r P
P * * r P
P _ 0 l 8
q * * r q
q . * r Q
q _ . r Q
Q * * r Q
Q _ 1 l 8
w * * r w
w . * r W
w _ . r W
W * * r W
W _ 2 l 8
e * * r e
e . * r E
e _ . r E
E * * r E
E _ 3 l 8
r * * r r
r . * r R
r _ . r R
R * * r R
R _ 4 l 8
t * * r t
t . * r T
t _ . r T
T * * r T
T _ 5 l 8
y * * r y
y . * r Y
y _ . r Y
Y * * r Y
Y _ 6 l 8
u * * r u
u . * r U
u _ . r U
U * * r U
U _ 7 l 8
i * * r i
i . * r I
i _ . r I
I * * r I
I _ 8 l 8
o * * r o
o . * r O
o _ . r O
O * * r O
O _ 9 l 8
x * * r x
x _ , l b
b . 1 l c
b 0 1 l c
b 1 2 l c
b 2 3 l c
b 3 4 l c
b 4 5 l c
b 5 6 l c
b 6 7 l c
b 7 8 l c
b 8 9 l c
b 9 0 l b
c * * l c
c _ * r v
v * * r v
v , * * 2
n * * r n
n _ * r halt
n , _ r n
n . _ r n
n p 0 r n
n q 1 r n
n w 2 r n
n e 3 r n
n r 4 r n
n t 5 r n
n y 6 r n
n u 7 r n
n i 8 r n
n o 9 r n
</code>```

You can try it out here - link
Just set the initial input to the upper limit.

Supports arbitrarily large integers

Title: Count up folks!

Body:
Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

Body:
Turing Machine Simulator - 1366 Bytes (124 Lines)

0 * * r 0
0 _ , r 1
1 _ 1 r ,
, _ , l 2
2 * * l 2
2 , * l 3
3 _ * r 4
3 1 0 l 4
3 2 1 l 4
3 3 2 l 4
3 4 3 l 4
3 5 4 l 4
3 6 5 l 4
3 7 6 l 4
3 8 7 l 4
3 9 8 l 4
3 0 9 l 3
4 * * l 4
4 _ * r 5
5 0 _ r 5
5 , * * n
5 * * r 6
6 * * r 6
6 , * r 9
9 * * r 9
9 _ * l z
z * * l m
m * * l m
m , * r 7
7 * * r 7
7 , * * x
7 0 p r p
7 1 q r q
7 2 w r w
7 3 e r e
7 4 r r r
7 5 t r t
7 6 y r y
7 7 u r u
7 8 i r i
7 9 o r o
8 * * l 8
8 , * l m
p * * r p
p . * r P
p _ . r P
P * * r P
P _ 0 l 8
q * * r q
q . * r Q
q _ . r Q
Q * * r Q
Q _ 1 l 8
w * * r w
w . * r W
w _ . r W
W * * r W
W _ 2 l 8
e * * r e
e . * r E
e _ . r E
E * * r E
E _ 3 l 8
r * * r r
r . * r R
r _ . r R
R * * r R
R _ 4 l 8
t * * r t
t . * r T
t _ . r T
T * * r T
T _ 5 l 8
y * * r y
y . * r Y
y _ . r Y
Y * * r Y
Y _ 6 l 8
u * * r u
u . * r U
u _ . r U
U * * r U
U _ 7 l 8
i * * r i
i . * r I
i _ . r I
I * * r I
I _ 8 l 8
o * * r o
o . * r O
o _ . r O
O * * r O
O _ 9 l 8
x * * r x
x _ , l b
b . 1 l c
b 0 1 l c
b 1 2 l c
b 2 3 l c
b 3 4 l c
b 4 5 l c
b 5 6 l c
b 6 7 l c
b 7 8 l c
b 8 9 l c
b 9 0 l b
c * * l c
c _ * r v
v * * r v
v , * * 2
n * * r n
n _ * r halt
n , _ r n
n . _ r n
n p 0 r n
n q 1 r n
n w 2 r n
n e 3 r n
n r 4 r n
n t 5 r n
n y 6 r n
n u 7 r n
n i 8 r n
n o 9 r n

You can try it out here - link
Just set the initial input to the upper limit.

Supports arbitrarily large integers


问:
Which ghosts are missing?
In this challenge, given a list of ghosts from Pac-Man, you must output which ghosts are missing. You must do it in as few bytes as you can

Input

Input will consist of a string or list, which will include a number ghosts, which could include:

Blinky

Inky

Pinky

Clyde

However, input may also include Pac-Man (with that punctuation). So, the maximum amount of items in a list will be five, in any order. It can be assumed that no invalid items will be in the list

Output

Output will consist of a string, or list. This will include of all the ghosts that are not in the input, in any order. However, if Pac-Man is in the input, all ghosts will be considered missing (because he eats them).

Test cases

```<code>input: Clyde
output: Blinky, Inky, Pinky
alternate output: Inky, Pinky, Blinky
or one of the other 4 permutations

input: Clyde, Blinky # or however you delimit it
output: Inky, Pinky
alt: Pinky, Inky

input: Pac-Man, Clyde
Output: Blinky, Inky, Pinky, Clyde
or you could output one of the other 23 permutations

input:[null]
Output: Blinky, Inky, Pinky, Clyde
or you could output one of the other 23 permutations
</code>```

This is codegolf, so the lower the bytecount, the better.

答:
Python 3, 77 bytes

```<code>lambda i:[g for g in"Blinky Inky Pinky Clyde".split()if g not in i or"-"in i]
</code>```

Here is another answer at 89 bytes that I was playing with but didn't work out :(

```<code>lambda i:[g for g in[s+"nky"for s in"Bli I Pi".split()]+["Clyde"]if g not in i or"-"in i]
</code>```

And here's the original at 85 bytes:

```<code>lambda i,n="Blinky Inky Pinky Clyde":([g for g in n.split()if g not in i],n)["-"in i]
</code>```

These all take a single string of the names separated by spaces/commas.

ContentLicense: CC BY-SA 4.0

Title: Which ghosts are missing?

Body:
Python 3, 77 bytes

lambda i:[g for g in"Blinky Inky Pinky Clyde".split()if g not in i or"-"in i]

Here is another answer at 89 bytes that I was playing with but didn't work out :(

lambda i:[g for g in[s+"nky"for s in"Bli I Pi".split()]+["Clyde"]if g not in i or"-"in i]

And here's the original at 85 bytes:

lambda i,n="Blinky Inky Pinky Clyde":([g for g in n.split()if g not in i],n)["-"in i]

These all take a single string of the names separated by spaces/commas.


问:
Dijkstra's Challenge

Presented in honor of APL as an interactive tool turning 50 this year

Background

Ken [Iverson] presented his paper Formalism in Programming Languages in August 1963 at a Working Conference on Mechanical Language Structures, Princeton, N.J. The list of conferees is full of famous and soon-to-be famous names, and a few future Turing Award winners (Backus, Curry, Dijkstra, Floyd, Iverson, Newell, Perlis, Wilkes). The paper also records the discussion that occurred after the presentation, ending with an exchange between Ken and [Edsger] Dijkstra, in which Ken’s reply to Dijkstra’s question was a one-liner.

Challenge

How would you represent a more complex operation, for example, the sum of all elements of a matrix M which are equal to the sum of the corresponding row and column indices?

Write a snippet or expression (no need for a full program or function) to calculate the sum of each element in a given integer matrix which is equal to the sum of its indices. Or, as FryAmTheEggman puts it: given a matrix M with elements aij return the sum of each aij where aij = i + j.

You may assume the matrix already being in a variable or memory location, or you may take it as an argument or input. You may use either 0 or 1 based indices.

Test cases

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

0 for empty matrix

```<code>2
</code>```

0 for 0 based indices or 2 for 1-based

```<code>1 5 2
9 4 2
5 9 6
</code>```

2 for 0 based or 10 for 1 based

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

11

```<code>3 -1 3 3
3 -1 3 1
</code>```

6 for 0 based or 3 for 1 based

Anecdote

Iverson's answer was ++/(M = ⍳¹ ⨢ ⍳¹)//M, which is neither valid in the Iverson Notation as defined in A Programming Language, nor in what eventually became APL. In Iverson notation, it would have been +/(M = ⍳¹(μ(M)) ⨢ ⍳¹(ν(M)))/M. In the very first versions of APL it was +/(,M=(⍳1↑⍴M)∘.+⍳1↓⍴M)/,M.

答:
PHP, 59 bytes

```<code>foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y)*$v;
</code>```

expects array $a defined; must be empty or 2-dimensional, 0-indexed.

calculates sum to $s (previously 0 or undefined - 0 equals NULL)

insert +2 before final ) for 1-indexed behaviour

Happy Birthday APL!

functions and test suite

```<code>function f0($a) { foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y)*$v;return $s|0; }
function f1($a) { foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y+2)*$v;return $s|0;}
$samples = [
    [], 0, 0,
    [[2]], 0, 2,
    [[1,5,2],[9,4,2],[5,9,6]], 2, 10,
    [[0,3,0,4],[0,4,1,4],[4,3,1,2],[-2,4,-2,-1]],11,11,
    [[3,-1,3,3],[3,-1,3,1]],6,3
];
function test($x,$e,$y){static $h='<table border=1><tr><th>input</th><th>output</th><th>expected</th><th>ok?</th></tr>';echo"$h<tr><td>",out($x),'</td><td>',out($y),'</td><td>',out($e),'</td><td>',cmp($e,$y)?'N':'Y',"</td></tr>";$h='';}
while($samples)
{
    $a=array_shift($samples);
    test($a,'B0:'.array_shift($samples),'B0:'.f0($a));
    test($a,'B1:'.array_shift($samples),'B1:'.f1($a));
}
</code>```

Title: Dijkstra's Challenge

Body:
PHP, 59 bytes

foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y)*$v;

expects array $a defined; must be empty or 2-dimensional, 0-indexed.

calculates sum to $s (previously 0 or undefined - 0 equals NULL)

insert +2 before final ) for 1-indexed behaviour

Happy Birthday APL!

functions and test suite

function f0($a) { foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y)*$v;return $s|0; }
function f1($a) { foreach($a as$y=>$r)foreach($r as$x=>$v)$s+=($v==$x+$y+2)*$v;return $s|0;}
$samples = [
    [], 0, 0,
    [[2]], 0, 2,
    [[1,5,2],[9,4,2],[5,9,6]], 2, 10,
    [[0,3,0,4],[0,4,1,4],[4,3,1,2],[-2,4,-2,-1]],11,11,
    [[3,-1,3,3],[3,-1,3,1]],6,3
];
function test($x,$e,$y){static $h='<table border=1><tr><th>input</th><th>output</th><th>expected</th><th>ok?</th></tr>';echo"$h<tr><td>",out($x),'</td><td>',out($y),'</td><td>',out($e),'</td><td>',cmp($e,$y)?'N':'Y',"</td></tr>";$h='';}
while($samples)
{
    $a=array_shift($samples);
    test($a,'B0:'.array_shift($samples),'B0:'.f0($a));
    test($a,'B1:'.array_shift($samples),'B1:'.f1($a));
}


问:
Print all alphanumeric characters plus underscore
Write a program or function that prints or returns a string of the alphanumeric characters plus underscore, in any order. To be precise, the following characters need to be output, and no more:

```<code>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
</code>```

When printing to stdout, an optional trailing newline after your output is permitted.

Built-in constants that contain 9 or more of the above characters are disallowed.

Shortest code in bytes wins.

This is a very simple challenge, which I believe will generate some interesting answers nevertheless.

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=85666,OVERRIDE_USER=4162;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;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

```

答:
ZX Spectrum, (Machine Code) 27 bytes

start in BASIC with PRINT "" AND USR 4e4

```<code>      org 40000
      dump 40000

      ld b,"z"
      ld a,"_"
      rst 16
nchar ld a,b
      cp "/"
      ret z
      cp ":"
      jr c,ok ; print numbers
      sub "A"
      cp "Z"+1-“A”
      ld a,b ; undo change
      jr c,ok ; print A-Z
      cp "a"
      jr c,fnext ; in between ranges
ok    rst 16
fnext djnz nchar
</code>```

Hexcode

```<code>067A3E5FD778D641fe1a78380b
413809FE5B3804FE613801D710Ea
</code>```

Output: _zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210

Body:
ZX Spectrum, (Machine Code) 27 bytes

start in BASIC with PRINT "" AND USR 4e4

      org 40000
      dump 40000

      ld b,"z"
      ld a,"_"
      rst 16
nchar ld a,b
      cp "/"
      ret z
      cp ":"
      jr c,ok ; print numbers
      sub "A"
      cp "Z"+1-“A”
      ld a,b ; undo change
      jr c,ok ; print A-Z
      cp "a"
      jr c,fnext ; in between ranges
ok    rst 16
fnext djnz nchar

Hexcode

067A3E5FD778D641fe1a78380b
413809FE5B3804FE613801D710Ea

Output: _zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210


Title: Print all alphanumeric characters plus underscore

Body:
Write a program or function that prints or returns a string of the alphanumeric characters plus underscore, in any order. To be precise, the following characters need to be output, and no more:

```<code>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
</code>```

When printing to stdout, an optional trailing newline after your output is permitted.

Built-in constants that contain 9 or more of the above characters are disallowed.

Shortest code in bytes wins.

This is a very simple challenge, which I believe will generate some interesting answers nevertheless.

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=85666,OVERRIDE_USER=4162;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;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
K, 21 bytes

_ci95,(97+!26),65+!26


问:
Ordering a list

Summary

Given a list of integers, return the index each integer would end up at when sorted.

For example, if the list was [0,8,-1,5,8], you should return [1,3,0,2,4].  Note that the two 8s maintain their order relative to each other (the sort is stable).

Put another way:  For each element in the list, return the number of elements in the list that are: Smaller than the chosen element OR (equal to the element AND appears before the chosen element)

Indexes must start with 0 (not 1)EDIT: given the large pushback, I'll allow 1-based indicies.

Test cases:

```<code>0                -> 0
23               -> 0
2,3              -> 0,1
3,2              -> 1,0
2,2              -> 0,1
8,10,4,-1,-1,8   -> 3,5,2,0,1,4
0,1,2,3,4,5,6,7  -> 0,1,2,3,4,5,6,7
7,6,5,4,3,2,1,0  -> 7,6,5,4,3,2,1,0
4,4,0,1,1,2,0,1  -> 6,7,0,2,3,5,1,4
1,1,1,1,1,1,1,1  -> 0,1,2,3,4,5,6,7
1,1,1,1,1,1,1,0  -> 1,2,3,4,5,6,7,0
</code>```

答:
MATL, <s>10</s> <s>9</s> 4 bytes

4 Bytes saved thanks to @Luis

```<code>&S&S
</code>```

This solution uses 1-based indexing

Try it Online

Title: Ordering a list

Body:
MATL, <s>10</s> <s>9</s> 4 bytes

4 Bytes saved thanks to @Luis

&S&S

This solution uses 1-based indexing

Try it Online


Body:
O, 40 bytes

[[D2*(,]B6*(+{n.84*+}dC8*(C4*.9+mr]{nc}d


答:
APL, 2 bytes

```<code>⍋⍋
</code>```

The “grade up” built-in, applied twice. Works if indexing starts at 0, which isn’t the default for all flavors of APL. Try it here!

Why does this work?

⍋x returns a list of indices that would stably sort x. For example:

```<code>    x ← 4 4 0 1 1 2 0 1
    ⍋x
2 6 3 4 7 5 0 1
</code>```

because if you take element 2, then 6, then 3… you get a stably sorted list:

```<code>    x[⍋x]
0 0 1 1 1 2 4 4
</code>```

But the index list that answers this question is subtly different: first we want the index of the smallest element, then the second smallest, etc. — again, keeping the original order.

If we look at ⍋x, though, we see it can give us this list easily: the position of a 0 in ⍋x tells us where the smallest element would end up after sorting, and the position of a 1 in ⍋x tells us where the second smallest element would end up, etc.

But we know ⍋x contains exactly the numbers [0, 1… n−1]. If we grade it again, we’ll just get the index of 0 in ⍋x, then the index of 1 in ⍋x, etc., which is precisely what we’re interested in.

So the answer is ⍋⍋x.

Title: Ordering a list

Body:
Summary

Given a list of integers, return the index each integer would end up at when sorted.

For example, if the list was [0,8,-1,5,8], you should return [1,3,0,2,4].  Note that the two 8s maintain their order relative to each other (the sort is stable).

Put another way:  For each element in the list, return the number of elements in the list that are: Smaller than the chosen element OR (equal to the element AND appears before the chosen element)

Indexes must start with 0 (not 1)EDIT: given the large pushback, I'll allow 1-based indicies.

Test cases:

```<code>0                -> 0
23               -> 0
2,3              -> 0,1
3,2              -> 1,0
2,2              -> 0,1
8,10,4,-1,-1,8   -> 3,5,2,0,1,4
0,1,2,3,4,5,6,7  -> 0,1,2,3,4,5,6,7
7,6,5,4,3,2,1,0  -> 7,6,5,4,3,2,1,0
4,4,0,1,1,2,0,1  -> 6,7,0,2,3,5,1,4
1,1,1,1,1,1,1,1  -> 0,1,2,3,4,5,6,7
1,1,1,1,1,1,1,0  -> 1,2,3,4,5,6,7,0
</code>```

Body:
APL, 2 bytes

⍋⍋

The “grade up” built-in, applied twice. Works if indexing starts at 0, which isn’t the default for all flavors of APL. Try it here!

Why does this work?

⍋x returns a list of indices that would stably sort x. For example:

    x ← 4 4 0 1 1 2 0 1
    ⍋x
2 6 3 4 7 5 0 1

because if you take element 2, then 6, then 3… you get a stably sorted list:

    x[⍋x]
0 0 1 1 1 2 4 4

But the index list that answers this question is subtly different: first we want the index of the smallest element, then the second smallest, etc. — again, keeping the original order.

If we look at ⍋x, though, we see it can give us this list easily: the position of a 0 in ⍋x tells us where the smallest element would end up after sorting, and the position of a 1 in ⍋x tells us where the second smallest element would end up, etc.

But we know ⍋x contains exactly the numbers [0, 1… n−1]. If we grade it again, we’ll just get the index of 0 in ⍋x, then the index of 1 in ⍋x, etc., which is precisely what we’re interested in.

So the answer is ⍋⍋x.


Body:
brainfuck, 58 bytes

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

Try it online.

Initializes the tape to 3·2n, and works from there.

+++[[<+>->++<]>]    initialize the tape
                    |   0 |   3 |   6 |  12 |  24 |  48 |  96 | 192 | 128 |   0 |   0 |
                                                                                ^
<<[-<->]            subract 128 from 192
                    |   0 |   3 |   6 |  12 |  24 |  48 |  96 |  64 |   0 |   0 |   0 |
                                                                        ^
<<-.+<<++           ouput '_'; increment 24 twice
                    |   0 |   3 |   6 |  12 |  26 |  48 |  96 |  64 |   0 |   0 |   0 |
                                                ^
[->>+.>+.<<<]       output aAbBcC ~ zZ
                    |   0 |   3 |   6 |  12 |   0 |  48 | 122 |  90 |   0 |   0 |   0 |
                                                ^
<--[->>.+<<]        decrement 12 twice; output 0 ~ 9
                    |   0 |   3 |   6 |   0 |   0 |  58 | 122 |  90 |   0 |   0 |   0 |
                                          ^


答:
```<code>$($);
</code>```

May not meet your conditions, but I like it. (And it does crash your browser.)

More information about this: Why does $($) crash my page?

Title: Make an HTML page goto infinite loop?

Body:
Write a code using HTML, JavaScript, jQuery to make the page go into infinite loop.

Restrictions:

No looping or control structures of javascript and jQuery allowed. You can only use alert, events, etc.

Body:
$($);

May not meet your conditions, but I like it. (And it does crash your browser.)

More information about this: Why does $($) crash my page?


答:
Jelly, 2 bytes

```<code>ỤỤ
</code>```

Grade up twice. 1-indexed. Try it online!

Title: Ordering a list

Body:
Jelly, 2 bytes

ỤỤ

Grade up twice. 1-indexed. Try it online!


答:
CJam, 15 bytes

```<code>{{eeWf%$1f=}2*}
</code>```

Try it online!

Explanation

```<code>{             }       Delimits an anonymous block.
 {         }2*        Run this block on the argument twice:
  ee                  Enumerate ([A B C] → [[0 A] [1 B] [2 C]])
    Wf%               Reverse each ([[A 0] [B 1] [C 2]])
       $              Sort the pairs lexicographically;
                        i.e. first by value, then by index.
        1f=           Keep the indices.
</code>```

Title: Ordering a list

Body:
CJam, 15 bytes

{{eeWf%$1f=}2*}

Try it online!

Explanation

{             }       Delimits an anonymous block.
 {         }2*        Run this block on the argument twice:
  ee                  Enumerate ([A B C] → [[0 A] [1 B] [2 C]])
    Wf%               Reverse each ([[A 0] [B 1] [C 2]])
       $              Sort the pairs lexicographically;
                        i.e. first by value, then by index.
        1f=           Keep the indices.


答:
JavaScript ES6, <s>87</s> <s>82</s> <s>79</s> <s>74</s> 70 bytes

```<code>(a,b={})=>a.map(l=>[...a].sort((a,b)=>a-b).indexOf(l)+(b[l]=b[l]+1|0))
</code>```

Don't like using an object but it seems to be the shortest way to keep track of dupes

Explanation

```<code>(a,b={})=>          `a` is input
                    `b` stores the occurrences of each number
  a.map(l =>        Loop over the array, `l` is item
  [...a]            Copy `a`
    .sort(...)       Sort in ascending numerical order
    .indexOf(l)      Index of input in that array
  +                 Add the following to account for dupes
   (b[l]=            set and return the item `l` in hashmap `b` to...
     b[l]+1           Increase the counter by one if it exists yet
     |0               default is zero
   )
</code>```

Title: Ordering a list

Body:
JavaScript ES6, <s>87</s> <s>82</s> <s>79</s> <s>74</s> 70 bytes

(a,b={})=>a.map(l=>[...a].sort((a,b)=>a-b).indexOf(l)+(b[l]=b[l]+1|0))

Don't like using an object but it seems to be the shortest way to keep track of dupes

Explanation

(a,b={})=>          `a` is input
                    `b` stores the occurrences of each number
  a.map(l =>        Loop over the array, `l` is item
  [...a]            Copy `a`
    .sort(...)       Sort in ascending numerical order
    .indexOf(l)      Index of input in that array
  +                 Add the following to account for dupes
   (b[l]=            set and return the item `l` in hashmap `b` to...
     b[l]+1           Increase the counter by one if it exists yet
     |0               default is zero
   )


答:
Haskell, <s>50</s> 48 bytes

```<code>import Data.List
m x=map snd$sort$zip x[0..]
m.m
</code>```

Usage example: m.m $ [4,4,0,1,1,2,0,1]-> [6,7,0,2,3,5,1,4].

It's map snd.sort.zip x [0..] applied twice on the input, i.e pair each element e with it's index i ((e,i)), sort it remove the first elements.
Repeat one time.

@Lynn came up with m=map snd.sort.(`zip`[0..]) which has the same byte count.

Title: Ordering a list

Body:
Haskell, <s>50</s> 48 bytes

import Data.List
m x=map snd$sort$zip x[0..]
m.m

Usage example: m.m $ [4,4,0,1,1,2,0,1]-> [6,7,0,2,3,5,1,4].

It's map snd.sort.zip x [0..] applied twice on the input, i.e pair each element e with it's index i ((e,i)), sort it remove the first elements.
Repeat one time.

@Lynn came up with m=map snd.sort.(`zip`[0..]) which has the same byte count.


答:
Python 2, 67 bytes

```<code>a=input()
p=[]
for x in a:print sorted(a).index(x)+p.count(x);p+=x,
</code>```

xnor saved two bytes.

Title: Ordering a list

Body:
Python 2, 67 bytes

a=input()
p=[]
for x in a:print sorted(a).index(x)+p.count(x);p+=x,

xnor saved two bytes.


答:
PowerShell v2+, 63 bytes

```<code>param($n)$n|%{($n|sort).IndexOf($_)+($n[0..$i++]-eq$_).count-1}
</code>```

Takes input $n, pipes that through a loop over every element |%{...}. Each iteration, we sort $n and get the IndexOf our current element $_. This counts how many items are smaller than the current element. We add to that a slice of $n, that expands every loop iteration, of the elements that are equal to the current element $_ and take the .Count of that. We then subtract -1 so we don't count our current element, and that number is left on the pipeline. Output at the end is implicit.

Examples

```<code>PS C:\Tools\Scripts\golfing> .\ordering-a-list.ps1 @(4,4,0,1,1,2,0,1)
6
7
0
2
3
5
1
4

PS C:\Tools\Scripts\golfing> .\ordering-a-list.ps1 @(8,10,4,-1,-1)
3
4
2
0
1
</code>```

Title: Ordering a list

Body:
PowerShell v2+, 63 bytes

param($n)$n|%{($n|sort).IndexOf($_)+($n[0..$i++]-eq$_).count-1}

Takes input $n, pipes that through a loop over every element |%{...}. Each iteration, we sort $n and get the IndexOf our current element $_. This counts how many items are smaller than the current element. We add to that a slice of $n, that expands every loop iteration, of the elements that are equal to the current element $_ and take the .Count of that. We then subtract -1 so we don't count our current element, and that number is left on the pipeline. Output at the end is implicit.

Examples

PS C:\Tools\Scripts\golfing> .\ordering-a-list.ps1 @(4,4,0,1,1,2,0,1)
6
7
0
2
3
5
1
4

PS C:\Tools\Scripts\golfing> .\ordering-a-list.ps1 @(8,10,4,-1,-1)
3
4
2
0
1


问:
Calculate the Super-Logarithm
This should be a simple challenge.

Given a number \$n \ge 0\$, output the super-logarithm (or the \$\log^*\$, log-star, or iterated logarithm, which are equivalent since \$n\$ is never negative for this challenge.) of \$n\$.

$$\log^*(n) = \begin{cases}
0  & \text{ if } n \le 1 \\
1 + \log^*(\log(n)) & \text{ if } n > 1
\end{cases}$$

This is one of the two inverse functions to tetration. The other is the super-root, which is in a related question.

Examples

```<code>Input       Output
0           0
1           0
2           1
3           2
4           2
...
15          2
16          3
...
3814279     3
3814280     4
</code>```

Rules

You do not need to support decimals, though you may.

You need to support input of at least \$3814280 =  \left\lceil e^{e^e} \right\rceil\$.

You may not hard-code the values like 3814280. (Your program must theoretically support higher numbers.) I want an algorithm to be implemented.

Shortest code wins.

Related OEIS

答:
Pyth, 10 bytes

```<code>L&>b1hy.lb
</code>```

Test suite.

This defines a function.

Title: Calculate the Super-Logarithm

Body:
Pyth, 10 bytes

L&>b1hy.lb

Test suite.

This defines a function.


答:
J, 5 bytes

```<code>/:^:2
</code>```

Grade up (/:) twice (^:2). 0-indexed.

To try it out, type f =: /:^:2 and then f 4 4 0 1 1 2 0 1 into tryj.tk.

Title: Ordering a list

Body:
J, 5 bytes

/:^:2

Grade up (/:) twice (^:2). 0-indexed.

To try it out, type f =: /:^:2 and then f 4 4 0 1 1 2 0 1 into tryj.tk.


答:
How about a meta refresh?

```<code><meta http-equiv=refresh content=1>
</code>```

I removed the quotation marks around the parameter values because code golf.

Title: Make an HTML page goto infinite loop?

Body:
How about a meta refresh?

<meta http-equiv=refresh content=1>

I removed the quotation marks around the parameter values because code golf.


问:
Guard your can with your life!

Lets Play Kick The Can!

Although Moogie is the current winner, if anyone can take his crown they are encouraged to do so

Kick the can is a children's game. Involving one defender, and multiple attackers. Today it is no longer such a game! Your job is to write a bot that plays it, to win, king-of-the-hill style!

https://en.wikipedia.org/wiki/Kick_the_can

There are some key differences in this game. The first key difference is that the game is multiplayer (5v5). The second key difference is that both sets of bots can kill and eliminate enemy players with both mines and thrown bombs! Bots can not see any mines (regardless of distance) or players at greater than five blocks away!

The map is a maze as follows.

This maze is procedurally generated by first creating a maze using a depth first recursive backtracking algorithm. And then placing the shown holes in (as well as make the maze more "imperfect". The maze is 65x65 blocks wide, and zero indexed. Thus the blue flag (can) is at 1,1 and the red flag (can) is at 63,63. Blue team spawns at 2,2 and 3,3 4,4 etc. red team spawns at 62,62 and 61,61, 60,60 etc. The blocks in cyan are bots on the blue team, and the blocks in magenta are red bots. The game is always five versus five. Each bot on the team will use your code (but may store other instance variables (or create local files) to keep track of state and differentiate roles.

Gameplay

Mines can be placed as you can see in gray. And bombs can be thrown a maximum distance of up to four blocks. These travel for up to four blocks through walls and other players killing only the enemies which stand in your way. After each step they have a 40% chance of falling away. So they have 100% chance of 1 range 60% at 2 range 36% at 3 range and 21.6% at three range Placing a mine or throwing a bomb takes one team ammo. This starts at 0 and can be increased by collecting the orange boxes. Note that four (4) of these ammo caches will be conveniently centered. The Bots are lined up in an array of two red and two blue. I.E RRRRRBBBBB. Gaurding the flag is permitted, but beware that being near the flag(i.e less than five blocks) results in slowness, and only allows movent. every three turns. The Arena picks a random starter for each turn. I.E The order can be RBBBBBRRRRR BBBBBRRRRR BBBRRRRRBB etc..

Objective

Program your five bots (each has the same class file) to successfully navigate the maze and touch the opposing can while being careful not to accidentally knock over ones own can, or step on a mine.

Programming

The arena and bot entries are currently in Java however a stdin/out wrapper exists for other languages.

The arena code will be made available but here is the relevant details.

Bot Class

```<code>public class YourUniqueBotName extends Bot{
public YourUniqueBotName(int x , int y, int team){
super(x,y,team);
//optional code
}
public Move move(){//todo implement this method
//it should output  a Move();
//A move has two paramaters
//direction is from 0 - 3 as such
//         3
//       2-I-0
//         1
// a direction of 4 or higher means a no-op (i.e stay still)
//And a MoveType. This movetype can be
//MoveType.Throw
//MoveType.Mine
//MoveType.Defuse defuse any mine present in the direction given
//MoveType.Move
}
}
</code>```

Key Methods Available

Note that using any techniques to modify or access data you should generally not have access to is not permitted and will result in disqualification.

```<code>Arena.getAmmo()[team];//returns the shared ammo cache of your team

Arena.getMap();//returns an integer[] representing the map. Be careful since all enemies more than 5 blocks away (straight line distance) and all mines are replaced with constant for spaces
//constants for each block type are provided such as Bot.space Bot.wall Bot.mine Bot.redTeam Bot.blueTeam Bot.redFlag Bot.blueFlag

Arena.getAliveBots();//returns the number of bots left

getX();//returns a zero indexed x coordinate you may directly look at (but not change X)

getY();//returns a zero indexed y coordinate (y would work to, but do not change y's value)

//Although some state variables are public please do not cheat by accessing modifying these
</code>```

StdIn/Out wrapper Interface Specification

The interface consists of two modes: initialisation and running.

During initialisation mode, a single INIT frame is sent via stdout. This frame's specification is as follows:

```<code>INIT
{Team Membership Id}
{Game Map}
TINI
</code>```

Where:
{Team Membership Id} is an single character: R or B. B meaning blue team, R meaning red team.

{Game Map} is a series of rows of ascii characters representing one row of the map. The following ascii characters are valid:
    F = blue flag
    G = red flag
    O = open space
    W = wall

The game will then proceed to send game frames over stdout to each bot as so:

```<code>FRAME
{Ammo}
{Alive Bot Count}
{Bot X},{Bot Y}
{Local Map}
EMARF
</code>```

Where:

{Ammo} is a string of digits, value will be 0 or greater
{Alive Bot Count} is a string of digits, value will be 0 or greater
{Box X} is a string of digits representing the X co-ordinate of the bot on the game map. Value will be 0 <= X < Map Width.
{Box Y} is a string of digits representing the Y co-ordinate of the bot on the game map. Value will be 0 <= Y < Map Height.
{Local Map} is a series of rows of ascii characters representing the whole map surrounding the bot. The following ascii characters are valid:
    F = blue flag
    G = red flag
    O = open space
    W = wall
    R = red team bot
    B = blue team bot
    M = mine
    A = ammo

The Controller expects that your bot will then output (to stdout) a single line response in the format:

```<code>{Action},{Direction}
</code>```

Where:

{Action} is one of:
    Move
    Defuse
    Mine
    Throw

{Direction} is a single digit between 0 and 4 inclusive. (see direction information earlier)

NOTE: all strings will be delimited by \n End of Line character.

This will be an elimination tournament. My sample bots will participate as fillers, but I will not award myself the win. In the event of a victory by one of my bots, the title goes to the second place member, and will continue until there is a bot which is not one of mine. Each match consists of 11 rounds of kick the can. If neither team has won a single match by then they both are eliminated. If there is a tie of non-zero score one tie breaker match will be played. If a tie remains both are eliminated. Later rounds may consist of more matches. The seeding of the tournament will be based on the number of upvotes as of 7/31/16 (date subject to change).

Each match lasts 4096 turns. A victory grants one point. A tie or loss grants zero points. Good luck!

Feel free to look at the code or critique it at this GitHub Repo.

https://github.com/rjhunjhunwala/BotCTF/blob/master/src/botctf/Arena.java

Note that I do not have interpreters for too many languages on my computer, and I may need volunteers to run the simulation on their computer. Or I can download the language interpreter. Please ensure that your bots.

Respond in a reasonable amount of time (say 250 ms)

Will not damage my host machine

答:
Optimised Pathfinder JAVA

Thanks to @Moogie for helping me optimise my messy floodfill pathfinding. Here is the source for the bot. This guy knows how important it is to defend his flag. He alocates three defenders and two attackers. The defenders hang back and defend/gather ammo, the two attackers take (a fairly straight) path to the flag (and collect the ammo at the middle). He shoots anyone he sees, and should be fierce competition. The defenders place mines around the flag and camp until there is no opposition left so they can go and kick the can.

```<code>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * todo fight
 */
package botctf;

import botctf.Move.MoveType;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author rohan
 */
public class PathFinderOptimised extends Bot {
    private static final int[][] offsets = new int[][]{{0,-1},{1,0},{0,1},{-1,0}};
    public static boolean shouldCampingTroll = true;
    private int moveCounter = -1;//dont ask
    public boolean defend;

    public PathFinderOptimised(int inX, int inY, int inTeam) {

        super(inX, inY, inTeam);
        //System.out.println("Start");
        //floodFillMap(getX(), getY());
        //System.out.println("Finish");
        defend=inX%2==0;
    }
    public static int[][] navigationMap;

    boolean upMine = false;
    boolean sideMine = false;

        int[][] myMap;

    @Override
    public Move move() {
                moveCounter++;
        myMap=getMap();
        int targetX, targetY;
        int enemyTeam=team==redTeam?blueTeam:redTeam;
        ArrayList<Coord> enemyCoordinates=new ArrayList<>();
        for(int i = 0; i<65;i++){
            for(int j = 0;j<65;j++){
                if(map[i][j]==enemyTeam){
                    enemyCoordinates.add(new Coord(i,j));
                }
            }
        }
        for(Coord enemy:enemyCoordinates){
            int enemyX=enemy.x;
            int enemyY=enemy.y;
         int dX= enemy.x-this.x;
            int dY= enemy.y-this.y;
            //System.out.println(dX+"|"+dY);
            if((dX==0||dY==0)){

                if(Arena.getAmmo()[this.team]>0){

                    if(dX>0&&dX<5){
                    return new Move(0,MoveType.Throw);
                }
                if(dX<0&&dX>-5){
                    return new Move(2,MoveType.Throw);
                }
                if (dY>0&&dY<5){
                    return new Move(1, MoveType.Throw);
                }
                if(dY<0&&dY>-5){
                    return new Move(3,MoveType.Throw);
                }
            }
        }
        }
        if(myMap[x+1][y]==ammo){
            return new Move(0,MoveType.Move);
        }
                if(myMap[x-1][y]==ammo){
            return new Move(2,MoveType.Move);
        }
                                if(myMap[x][y+1]==ammo){
            return new Move(1,MoveType.Move);
        }
                                                                if(myMap[x][y-1]==ammo){
            return new Move(3,MoveType.Move);
        }

int bestOption = 4;
        if (defend) {
if(Arena.getAliveBots()==1){
    defend=false;
}
            int bestAmmoX = -1;
            int bestAmmoY = -1;
            int bestAmmoDist = Integer.MAX_VALUE;
            for (int i = 0; i < 65; i++) {
                for (int j = 0; j < 65; j++) {
                    if (myMap[i][j] == ammo) {
                        int path = pathFind(getX(),getY(),i,j,myMap);
                        if ((path & 0xFFFFFF) < bestAmmoDist) {
                            bestAmmoX = i;
                            bestAmmoY = j;
                            bestAmmoDist = (path & 0xFFFFFF);
                            bestOption = path >> 24;
                        }
                    }
                }
            }
            if (bestAmmoDist<15||Arena.getAmmo()[this.team]==0){
                targetX = bestAmmoX;
                targetY = bestAmmoY;
            } else {
                targetX = team == redTeam ? 62 : 2;
                targetY = team == redTeam ? 62 : 2;
            }
        } else {

            if(this.x>18&this.x<42&&this.y>16&&this.y<44&&myMap[33][33]==ammo){
                targetX=33;
                targetY=33;
            }else{
            if (this.team == redTeam) {
                targetX = 1;
                targetY = 1;
            } else {
                targetX = 63;
                targetY = 63;
            }
            }
        }
        if(upMine&&sideMine){
            if(targetX==2||targetX==62){
                if(targetY==2||targetY==62){
                    targetX+=targetX==2?3:-3;
                    targetY+=targetY==2?3:-3;
                }
            }
        }else if (targetX == getX() && targetY == getY()) {
            if (!upMine) {
                upMine = true;
                if (this.team == redTeam) {
                    return new Move(0, MoveType.Mine);
                } else {
                    return new Move(2, MoveType.Mine);
                }
            }else if(!sideMine){
                sideMine=true;
                if (this.team == redTeam) {
                    return new Move(1, MoveType.Mine);
                } else {
                    return new Move(3, MoveType.Mine);
                }
            }   else {
                return new Move(5, MoveType.Move);
            }
        }

        bestOption = pathFind(getX(),getY(),targetX,targetY,myMap) >> 24;

MoveType m=MoveType.Move;
if(moveCounter%2==0){
    if(this.team==redTeam?x<25&&y<25:x>39&&y>39){
        m=MoveType.Defuse;
    }
}
//System.out.println(bestOption);
        return new Move(bestOption, m);
    }

    /**
     * returns a result that is the combination of movement direction and length of a path found from the given start position to the target
     * position. result is ((direction) << 24 + path_length)
     */
    private int pathFind(int startX, int startY, int targetX,int targetY,int[][] map)
    {
        class PathSegment
        {
            public PathSegment(int tileX, int tileY, int fscore, int gscore, PathSegment parent)
            {
                super();
                this.tileX = tileX;
                this.tileY = tileY;
                this.fscore = fscore;
                this.gscore = gscore;
                this.parent = parent;
            }
            public PathSegment(PathSegment parent)
            {
                this.parent = parent;
            }
            int tileX;
            int tileY;
            int fscore;
            int gscore;
            PathSegment parent;
        }
        // A*
        if (startX==targetX && startY==targetY)
        {
            return 4;
        }
        else
        {
            int[][] tileIsClosed = new int[64][64];

            PathSegment curSegment = new PathSegment(targetX,targetY,1,1,null);
            PathSegment newSegment;
            Set<PathSegment> openList = new HashSet<PathSegment>();
            openList.add(curSegment);

            do
            {
                if (openList.isEmpty())
                {
                    break;
                }
              PathSegment currentBestScoringSegment = openList.iterator().next();
              //  Look for the lowest F cost square on the open list
              for (PathSegment segment : openList)
              {
                if (segment.fscore<currentBestScoringSegment.fscore)
                {
                  currentBestScoringSegment = segment;
                }
              }
              curSegment = currentBestScoringSegment;

              // found path
              if (startX==curSegment.tileX && startY==curSegment.tileY)
              {
                break;
              }

              // if not in closed list
              if (tileIsClosed[curSegment.tileX][curSegment.tileY]==0)
              {
                    // Switch it to the closed list.
                    tileIsClosed[curSegment.tileX][curSegment.tileY]=1;
                    // remove from openlist
                    openList.remove(curSegment);

                    // add neigbours to the open list if necessary
                    for (int i=0;i<4;i++)
                    {
                        final int surroundingCurrentTileX=curSegment.tileX+offsets[i][0];
                        final int surroundingCurrentTileY=curSegment.tileY+offsets[i][1];
                        if (surroundingCurrentTileX>=0 && surroundingCurrentTileX<64 &&
                            surroundingCurrentTileY>=0 && surroundingCurrentTileY<64 )
                        {
                            newSegment = new PathSegment( curSegment);
                            newSegment.tileX = surroundingCurrentTileX;
                            newSegment.tileY = surroundingCurrentTileY;

                          if (map[surroundingCurrentTileX][surroundingCurrentTileY]=='W')
                          {
                              continue;
                          }

                          int surroundingCurrentGscore=curSegment.gscore+1;
                          newSegment.gscore=surroundingCurrentGscore;
                          newSegment.fscore=surroundingCurrentGscore+Math.abs( surroundingCurrentTileX-startX)+Math.abs( surroundingCurrentTileY-startY);
                          openList.add(newSegment);
                        }
                    }
              }
              else
              {
                  // remove from openlist
                  openList.remove(curSegment);
              }
            } while(true);

            if (curSegment.parent.tileX-startX<0) return (2 << 24) | curSegment.gscore;
            else if (curSegment.parent.tileX-startX>0) return (0 << 24) | curSegment.gscore;
            else if (curSegment.parent.tileY-startY<0) return (3 << 24) | curSegment.gscore;
            else if (curSegment.parent.tileY-startY>0) return (1 << 24) | curSegment.gscore;
        }
        throw new RuntimeException("Path finding failed");
     }
}
</code>```

Title: Guard your can with your life!

Body:
Optimised Pathfinder JAVA

Thanks to @Moogie for helping me optimise my messy floodfill pathfinding. Here is the source for the bot. This guy knows how important it is to defend his flag. He alocates three defenders and two attackers. The defenders hang back and defend/gather ammo, the two attackers take (a fairly straight) path to the flag (and collect the ammo at the middle). He shoots anyone he sees, and should be fierce competition. The defenders place mines around the flag and camp until there is no opposition left so they can go and kick the can.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * todo fight
 */
package botctf;

import botctf.Move.MoveType;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author rohan
 */
public class PathFinderOptimised extends Bot {
    private static final int[][] offsets = new int[][]{{0,-1},{1,0},{0,1},{-1,0}};
    public static boolean shouldCampingTroll = true;
    private int moveCounter = -1;//dont ask
    public boolean defend;

    public PathFinderOptimised(int inX, int inY, int inTeam) {

        super(inX, inY, inTeam);
        //System.out.println("Start");
        //floodFillMap(getX(), getY());
        //System.out.println("Finish");
        defend=inX%2==0;
    }
    public static int[][] navigationMap;

    boolean upMine = false;
    boolean sideMine = false;

        int[][] myMap;

    @Override
    public Move move() {
                moveCounter++;
        myMap=getMap();
        int targetX, targetY;
        int enemyTeam=team==redTeam?blueTeam:redTeam;
        ArrayList<Coord> enemyCoordinates=new ArrayList<>();
        for(int i = 0; i<65;i++){
            for(int j = 0;j<65;j++){
                if(map[i][j]==enemyTeam){
                    enemyCoordinates.add(new Coord(i,j));
                }
            }
        }
        for(Coord enemy:enemyCoordinates){
            int enemyX=enemy.x;
            int enemyY=enemy.y;
         int dX= enemy.x-this.x;
            int dY= enemy.y-this.y;
            //System.out.println(dX+"|"+dY);
            if((dX==0||dY==0)){

                if(Arena.getAmmo()[this.team]>0){

                    if(dX>0&&dX<5){
                    return new Move(0,MoveType.Throw);
                }
                if(dX<0&&dX>-5){
                    return new Move(2,MoveType.Throw);
                }
                if (dY>0&&dY<5){
                    return new Move(1, MoveType.Throw);
                }
                if(dY<0&&dY>-5){
                    return new Move(3,MoveType.Throw);
                }
            }
        }
        }
        if(myMap[x+1][y]==ammo){
            return new Move(0,MoveType.Move);
        }
                if(myMap[x-1][y]==ammo){
            return new Move(2,MoveType.Move);
        }
                                if(myMap[x][y+1]==ammo){
            return new Move(1,MoveType.Move);
        }
                                                                if(myMap[x][y-1]==ammo){
            return new Move(3,MoveType.Move);
        }

int bestOption = 4;
        if (defend) {
if(Arena.getAliveBots()==1){
    defend=false;
}
            int bestAmmoX = -1;
            int bestAmmoY = -1;
            int bestAmmoDist = Integer.MAX_VALUE;
            for (int i = 0; i < 65; i++) {
                for (int j = 0; j < 65; j++) {
                    if (myMap[i][j] == ammo) {
                        int path = pathFind(getX(),getY(),i,j,myMap);
                        if ((path & 0xFFFFFF) < bestAmmoDist) {
                            bestAmmoX = i;
                            bestAmmoY = j;
                            bestAmmoDist = (path & 0xFFFFFF);
                            bestOption = path >> 24;
                        }
                    }
                }
            }
            if (bestAmmoDist<15||Arena.getAmmo()[this.team]==0){
                targetX = bestAmmoX;
                targetY = bestAmmoY;
            } else {
                targetX = team == redTeam ? 62 : 2;
                targetY = team == redTeam ? 62 : 2;
            }
        } else {

            if(this.x>18&this.x<42&&this.y>16&&this.y<44&&myMap[33][33]==ammo){
                targetX=33;
                targetY=33;
            }else{
            if (this.team == redTeam) {
                targetX = 1;
                targetY = 1;
            } else {
                targetX = 63;
                targetY = 63;
            }
            }
        }
        if(upMine&&sideMine){
            if(targetX==2||targetX==62){
                if(targetY==2||targetY==62){
                    targetX+=targetX==2?3:-3;
                    targetY+=targetY==2?3:-3;
                }
            }
        }else if (targetX == getX() && targetY == getY()) {
            if (!upMine) {
                upMine = true;
                if (this.team == redTeam) {
                    return new Move(0, MoveType.Mine);
                } else {
                    return new Move(2, MoveType.Mine);
                }
            }else if(!sideMine){
                sideMine=true;
                if (this.team == redTeam) {
                    return new Move(1, MoveType.Mine);
                } else {
                    return new Move(3, MoveType.Mine);
                }
            }   else {
                return new Move(5, MoveType.Move);
            }
        }

        bestOption = pathFind(getX(),getY(),targetX,targetY,myMap) >> 24;

MoveType m=MoveType.Move;
if(moveCounter%2==0){
    if(this.team==redTeam?x<25&&y<25:x>39&&y>39){
        m=MoveType.Defuse;
    }
}
//System.out.println(bestOption);
        return new Move(bestOption, m);
    }

    /**
     * returns a result that is the combination of movement direction and length of a path found from the given start position to the target
     * position. result is ((direction) << 24 + path_length)
     */
    private int pathFind(int startX, int startY, int targetX,int targetY,int[][] map)
    {
        class PathSegment
        {
            public PathSegment(int tileX, int tileY, int fscore, int gscore, PathSegment parent)
            {
                super();
                this.tileX = tileX;
                this.tileY = tileY;
                this.fscore = fscore;
                this.gscore = gscore;
                this.parent = parent;
            }
            public PathSegment(PathSegment parent)
            {
                this.parent = parent;
            }
            int tileX;
            int tileY;
            int fscore;
            int gscore;
            PathSegment parent;
        }
        // A*
        if (startX==targetX && startY==targetY)
        {
            return 4;
        }
        else
        {
            int[][] tileIsClosed = new int[64][64];

            PathSegment curSegment = new PathSegment(targetX,targetY,1,1,null);
            PathSegment newSegment;
            Set<PathSegment> openList = new HashSet<PathSegment>();
            openList.add(curSegment);

            do
            {
                if (openList.isEmpty())
                {
                    break;
                }
              PathSegment currentBestScoringSegment = openList.iterator().next();
              //  Look for the lowest F cost square on the open list
              for (PathSegment segment : openList)
              {
                if (segment.fscore<currentBestScoringSegment.fscore)
                {
                  currentBestScoringSegment = segment;
                }
              }
              curSegment = currentBestScoringSegment;

              // found path
              if (startX==curSegment.tileX && startY==curSegment.tileY)
              {
                break;
              }

              // if not in closed list
              if (tileIsClosed[curSegment.tileX][curSegment.tileY]==0)
              {
                    // Switch it to the closed list.
                    tileIsClosed[curSegment.tileX][curSegment.tileY]=1;
                    // remove from openlist
                    openList.remove(curSegment);

                    // add neigbours to the open list if necessary
                    for (int i=0;i<4;i++)
                    {
                        final int surroundingCurrentTileX=curSegment.tileX+offsets[i][0];
                        final int surroundingCurrentTileY=curSegment.tileY+offsets[i][1];
                        if (surroundingCurrentTileX>=0 && surroundingCurrentTileX<64 &&
                            surroundingCurrentTileY>=0 && surroundingCurrentTileY<64 )
                        {
                            newSegment = new PathSegment( curSegment);
                            newSegment.tileX = surroundingCurrentTileX;
                            newSegment.tileY = surroundingCurrentTileY;

                          if (map[surroundingCurrentTileX][surroundingCurrentTileY]=='W')
                          {
                              continue;
                          }

                          int surroundingCurrentGscore=curSegment.gscore+1;
                          newSegment.gscore=surroundingCurrentGscore;
                          newSegment.fscore=surroundingCurrentGscore+Math.abs( surroundingCurrentTileX-startX)+Math.abs( surroundingCurrentTileY-startY);
                          openList.add(newSegment);
                        }
                    }
              }
              else
              {
                  // remove from openlist
                  openList.remove(curSegment);
              }
            } while(true);

            if (curSegment.parent.tileX-startX<0) return (2 << 24) | curSegment.gscore;
            else if (curSegment.parent.tileX-startX>0) return (0 << 24) | curSegment.gscore;
            else if (curSegment.parent.tileY-startY<0) return (3 << 24) | curSegment.gscore;
            else if (curSegment.parent.tileY-startY>0) return (1 << 24) | curSegment.gscore;
        }
        throw new RuntimeException("Path finding failed");
     }
}


问:
Polar Bear, Polar Bear, what do you hear?
The text of the children's book Polar Bear, Polar Bear, What Do You Hear?  has a very simple pattern.  You might use the text to teach introductory programming concepts.

My son was quickly bored by this idea, so I decided to play some golf with it instead.

The Challenge

In your programming language of choice, write the smallest program possible which will print the following text.  Output should match exactly, including case, spacing, and punctuation.

```<code>Polar Bear, Polar Bear, what do you hear?
I hear a lion roaring in my ear.

Lion, Lion, what do you hear?
I hear a hippopotamus snorting in my ear.

Hippopotamus, Hippopotamus, what do you hear?
I hear a flamingo fluting in my ear.

Flamingo, Flamingo, what do you hear?
I hear a zebra braying in my ear.

Zebra, Zebra, what do you hear?
I hear a boa constrictor hissing in my ear.

Boa Constrictor, Boa Constrictor, what do you hear?
I hear an elephant trumpeting in my ear.

Elephant, Elephant, what do you hear?
I hear a leopard snarling in my ear.

Leopard, Leopard, what do you hear?
I hear a peacock yelping in my ear.

Peacock, Peacock, what do you hear?
I hear a walrus bellowing in my ear.

Walrus, Walrus, what do you hear?
I hear a zookeeper whistling in my ear.

Zookeeper, Zookeeper, what do you hear?
I hear children...

...growling like a polar bear,
roaring like a lion,
snorting like a hippopotamus,
fluting like a flamingo,
braying like a zebra,
hissing like a boa constrictor,
trumpeting like an elephant,
snarling like a leopard,
yelping like a peacock,
bellowing like a walrus...
that's what I hear.
</code>```

答:
clojure, 526 bytes

```<code>(use 'clojure.string)(let[l lower-case
a(partition 2(split"Polar Bear,...growl,Lion,roar,Hippopotamus,snort,Flamingo,flut,Zebra,bray,Boa Constrictor,hiss,Elephant,trumpet,Leopard,snarl,Peacock,yelp,Walrus,bellow,Zookeeper,whistl,children,x"#","))b(map(fn[[w x][y e]][(str
w", "w", what do you hear?
I hear a "(l y)" "e"ing in my ear.

")(str x"ing like a "(l w))])a(rest a))r
replace](print(r(str(r(join""(map first b))#".*x.*""I hear children...")(join",
"(butlast(map last b)))"...
that's what I hear.")#"(?i)a(?= e)""an")))
</code>```

Here's my initial attempt. Gotta love the formatting and how unreadable it is. Hope the warnings from use 'clojure.string are acceptable.

Try it online.

Formatted code:

```<code>(use 'clojure.string)
(let [animal-sound (partition 2 (split "Polar Bear,...growl,Lion,roar,Hippopotamus,snort,Flamingo,flut,Zebra,bray,Boa Constrictor,hiss,Elephant,trumpet,Leopard,snarl,Peacock,yelp,Walrus,bellow,Zookeeper,whistl,children,x" #","))
      sentences (map (fn [[animal-1 sound-1] [animal-2 sound-2]]
                       [(str animal-1 ", " animal-1 ", what do you hear?\nI hear a "
                             (lower-case animal-2) " " sound-2 "ing in my ear.\n\n") (str sound-1 "ing like a " (lower-case animal-1))])
                     animal-sound (rest animal-sound))]
  (print (replace (str
                    (replace (join "" (map first sentences)) #".*x.*" "I hear children...")
                    (join ",\n" (butlast (map last sentences)))
                    "...\nthat's what I hear.") #"(?i)a(?= e)" "an")))
</code>```

Body:
clojure, 526 bytes

(use 'clojure.string)(let[l lower-case
a(partition 2(split"Polar Bear,...growl,Lion,roar,Hippopotamus,snort,Flamingo,flut,Zebra,bray,Boa Constrictor,hiss,Elephant,trumpet,Leopard,snarl,Peacock,yelp,Walrus,bellow,Zookeeper,whistl,children,x"#","))b(map(fn[[w x][y e]][(str
w", "w", what do you hear?
I hear a "(l y)" "e"ing in my ear.

")(str x"ing like a "(l w))])a(rest a))r
replace](print(r(str(r(join""(map first b))#".*x.*""I hear children...")(join",
"(butlast(map last b)))"...
that's what I hear.")#"(?i)a(?= e)""an")))

Here's my initial attempt. Gotta love the formatting and how unreadable it is. Hope the warnings from use 'clojure.string are acceptable.

Try it online.

Formatted code:

(use 'clojure.string)
(let [animal-sound (partition 2 (split "Polar Bear,...growl,Lion,roar,Hippopotamus,snort,Flamingo,flut,Zebra,bray,Boa Constrictor,hiss,Elephant,trumpet,Leopard,snarl,Peacock,yelp,Walrus,bellow,Zookeeper,whistl,children,x" #","))
      sentences (map (fn [[animal-1 sound-1] [animal-2 sound-2]]
                       [(str animal-1 ", " animal-1 ", what do you hear?\nI hear a "
                             (lower-case animal-2) " " sound-2 "ing in my ear.\n\n") (str sound-1 "ing like a " (lower-case animal-1))])
                     animal-sound (rest animal-sound))]
  (print (replace (str
                    (replace (join "" (map first sentences)) #".*x.*" "I hear children...")
                    (join ",\n" (butlast (map last sentences)))
                    "...\nthat's what I hear.") #"(?i)a(?= e)" "an")))


答:
K, <s>5</s> 2 bytes

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

Grade up (<) twice. JohnE saved three bytes by pointing out tacit expressions exist in K! Super cool. Try it out.

Title: Ordering a list

Body:
K, <s>5</s> 2 bytes

<<

Grade up (<) twice. JohnE saved three bytes by pointing out tacit expressions exist in K! Super cool. Try it out.


答:
Dyalog APL, 13 bytes

Direct translation of OP:

```<code>{⍵≤1:0⋄1+∇⍟⍵}
</code>```

TryAPL online!

Title: Calculate the Super-Logarithm

Body:
This should be a simple challenge.

Given a number \$n \ge 0\$, output the super-logarithm (or the \$\log^*\$, log-star, or iterated logarithm, which are equivalent since \$n\$ is never negative for this challenge.) of \$n\$.

$$\log^*(n) = \begin{cases}
0  & \text{ if } n \le 1 \\
1 + \log^*(\log(n)) & \text{ if } n > 1
\end{cases}$$

This is one of the two inverse functions to tetration. The other is the super-root, which is in a related question.

Examples

```<code>Input       Output
0           0
1           0
2           1
3           2
4           2
...
15          2
16          3
...
3814279     3
3814280     4
</code>```

Rules

You do not need to support decimals, though you may.

You need to support input of at least \$3814280 =  \left\lceil e^{e^e} \right\rceil\$.

You may not hard-code the values like 3814280. (Your program must theoretically support higher numbers.) I want an algorithm to be implemented.

Shortest code wins.

Related OEIS

Body:
Dyalog APL, 13 bytes

Direct translation of OP:

{⍵≤1:0⋄1+∇⍟⍵}

TryAPL online!


答:
PureData, 462 bytes

As file:

```<code>#N canvas 778 126 591 616 10;
#X obj 136 137 until;
#X obj 175 177 f;
#X obj 258 160 + 1;
#X obj 352 194 + 1;
#X msg 215 126 0;
#X obj 393 211 log/normal;
#X obj 215 96 moses;
#X obj 215 66 - 1;
#X msg 136 49 1.84467e+019;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 1 1;
#X connect 3 0 5 0;
#X connect 3 0 6 1;
#X connect 4 0 1 1;
#X connect 6 0 4 0;
#X connect 6 0 0 1;
#X connect 7 0 6 0;
#X connect 8 0 0 0;
#X connect 8 0 7 0;
</code>```

Actual program, because it's a graphical programming language:

Note: Do NOT run it with this value as it will run for a very long time!

Title: Count up folks!

Body:
Introduction

It may sound strange, but we haven't got ONE challenge for counting from 1 to n, inclusive.

This is not the same thing. That one is a (closed) not well-explained challenge.

This is not the same thing. That one is about counting up indefinitely.

Challenge

Write a program or function that prints every integer from 1 to n inclusive.

Rules

You can get n any way.

You can assume that n will always be a positive integer.

You can get n in any base, but you should always output in decimal.

Output must be separated by any character (or pattern) not in 0123456789. Non-decimal leading or trailing characters are allowed (for example when using arrays such as [1, 2, 3, 4, 5, 6]).

Standard loopholes are denied.

We want to find the shortest approach in each language, not the shortest language, so I will not accept any answer.

You must update your answer(s) after this edit, answers posted before the last edit must comply with the change rule about standard loopholes (I didn't want to deny them, but I didn't want to make the community roar, so I denied them).

You can use any post-dating language version (or language). You cannot use any language or language version made just for this challenge.

Bonuses

20%

Your program must be able to count at least up to 18446744073709551615 (2^64-1). For example, if a new datatype is the only way to support big integers, you must construct it. If your language does not have any way to support huge integers up to 2^64-1, the upper limit of that particular language must be supported instead.

EDIT: I've changed the limit from 2^64 to 2^64-1 to allow more answers.

EDIT: I made the 2^64-1 rule a bonus, since there has not been much interest in this challenge. If your answer supports 2^64-1, you can now edit it to include the bonus. Also, you can post an answer not supporting it, if it is shorter.

Body:
PureData, 462 bytes

As file:

#N canvas 778 126 591 616 10;
#X obj 136 137 until;
#X obj 175 177 f;
#X obj 258 160 + 1;
#X obj 352 194 + 1;
#X msg 215 126 0;
#X obj 393 211 log/normal;
#X obj 215 96 moses;
#X obj 215 66 - 1;
#X msg 136 49 1.84467e+019;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 1 0 3 0;
#X connect 2 0 1 1;
#X connect 3 0 5 0;
#X connect 3 0 6 1;
#X connect 4 0 1 1;
#X connect 6 0 4 0;
#X connect 6 0 0 1;
#X connect 7 0 6 0;
#X connect 8 0 0 0;
#X connect 8 0 7 0;

Actual program, because it's a graphical programming language:

Note: Do NOT run it with this value as it will run for a very long time!


答:
Pyth, <s>10</s> 9 bytes

1 byte thanks to Jakube.

```<code>xLo@QNUQU
</code>```

Test suite.

There must be a shorter way...

Title: Ordering a list

Body:
Summary

Given a list of integers, return the index each integer would end up at when sorted.

For example, if the list was [0,8,-1,5,8], you should return [1,3,0,2,4].  Note that the two 8s maintain their order relative to each other (the sort is stable).

Put another way:  For each element in the list, return the number of elements in the list that are: Smaller than the chosen element OR (equal to the element AND appears before the chosen element)

Indexes must start with 0 (not 1)EDIT: given the large pushback, I'll allow 1-based indicies.

Test cases:

```<code>0                -> 0
23               -> 0
2,3              -> 0,1
3,2              -> 1,0
2,2              -> 0,1
8,10,4,-1,-1,8   -> 3,5,2,0,1,4
0,1,2,3,4,5,6,7  -> 0,1,2,3,4,5,6,7
7,6,5,4,3,2,1,0  -> 7,6,5,4,3,2,1,0
4,4,0,1,1,2,0,1  -> 6,7,0,2,3,5,1,4
1,1,1,1,1,1,1,1  -> 0,1,2,3,4,5,6,7
1,1,1,1,1,1,1,0  -> 1,2,3,4,5,6,7,0
</code>```

Body:
Pyth, <s>10</s> 9 bytes

1 byte thanks to Jakube.

xLo@QNUQU

Test suite.

There must be a shorter way...


答:
PHP, <s>74</s> 71 bytes

```<code>echo 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
</code>```

Body:
Write a program or function that prints or returns a string of the alphanumeric characters plus underscore, in any order. To be precise, the following characters need to be output, and no more:

```<code>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_
</code>```

When printing to stdout, an optional trailing newline after your output is permitted.

Built-in constants that contain 9 or more of the above characters are disallowed.

Shortest code in bytes wins.

This is a very simple challenge, which I believe will generate some interesting answers nevertheless.

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=85666,OVERRIDE_USER=4162;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;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
PHP, <s>74</s> 71 bytes

echo 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';


答:
05AB1E, <s>16</s> 13 bytes

```<code>[Dî2‹#¼žr.n]¾
</code>```

Explanation

```<code>              # implicit input n
[          ]  # infinite loop
 Dî2‹#        # break if n rounded up is less than 2
      ¼       # else, increase counter
       žr.n   # set next n = log(n)
            ¾ # push counter and implicitly print
</code>```

Try it online

Title: Calculate the Super-Logarithm

Body:
05AB1E, <s>16</s> 13 bytes

[Dî2‹#¼žr.n]¾

Explanation

              # implicit input n
[          ]  # infinite loop
 Dî2‹#        # break if n rounded up is less than 2
      ¼       # else, increase counter
       žr.n   # set next n = log(n)
            ¾ # push counter and implicitly print

Try it online


答:
Haskell, 23 bytes

```<code>l x|x>1=1+l(log x)|1<2=0
</code>```

Usage example: l 3814280 -> 4.

Title: Calculate the Super-Logarithm

Body:
Haskell, 23 bytes

l x|x>1=1+l(log x)|1<2=0

Usage example: l 3814280 -> 4.


答:
MATL, <s>15</s> 12 bytes

```<code>0`ZetG>~}x@q
</code>```

Try it online! Or verify all test cases (slightly modified version to handle several inputs).

How it works

Starting with 0, apply iterated exponentiation until exceeding the input. The output is the number of iterations minus 1.

```<code>0       % Push 0
`       % Do...while loop
  Ze    %   Exponential
  t     %   Duplicate
  G     %   Push input
  >~    %   Is current value less than or equal to the input? If so: next iteration
}       % Finally (code executed at the end of the last iteration)
  x     %   Delete
  @q    %   Iteration index minus 1
        % Implicitly end loop
        % Implicitly display stack
</code>```

Title: Calculate the Super-Logarithm

Body:
MATL, <s>15</s> 12 bytes

0`ZetG>~}x@q

Try it online! Or verify all test cases (slightly modified version to handle several inputs).

How it works

Starting with 0, apply iterated exponentiation until exceeding the input. The output is the number of iterations minus 1.

0       % Push 0
`       % Do...while loop
  Ze    %   Exponential
  t     %   Duplicate
  G     %   Push input
  >~    %   Is current value less than or equal to the input? If so: next iteration
}       % Finally (code executed at the end of the last iteration)
  x     %   Delete
  @q    %   Iteration index minus 1
        % Implicitly end loop
        % Implicitly display stack


答:
C--, 230 bytes

```<code>target byteorder little;export main;import putchar,isalnum;foreign"C"main(){bits32 v,t;v = 48;T:t=foreign"C"isalnum(v);if (t!=0){foreign"C"putchar(v);}if (v==95){foreign"C"putchar(v);}v=v+1;if (v<123){goto T;}foreign"C"return(0);}
</code>```

Ungolfed:

```<code>target byteorder little;

export main;
import putchar, isalnum;

foreign "C" main(){
    bits32 v, tmp;
    v = 48;
Top:
    tmp = foreign "C" isalnum(v);
    if (tmp != 0){
        foreign "C" putchar(v);
    }

    if (v == 95){
        foreign "C" putchar(v);
    }

    v=v+1;
    if (v < 123) { goto Top; }

    foreign "C" return (0);
}
</code>```

Body:
C--, 230 bytes

target byteorder little;export main;import putchar,isalnum;foreign"C"main(){bits32 v,t;v = 48;T:t=foreign"C"isalnum(v);if (t!=0){foreign"C"putchar(v);}if (v==95){foreign"C"putchar(v);}v=v+1;if (v<123){goto T;}foreign"C"return(0);}

Ungolfed:

target byteorder little;

export main;
import putchar, isalnum;

foreign "C" main(){
    bits32 v, tmp;
    v = 48;
Top:
    tmp = foreign "C" isalnum(v);
    if (tmp != 0){
        foreign "C" putchar(v);
    }

    if (v == 95){
        foreign "C" putchar(v);
    }

    v=v+1;
    if (v < 123) { goto Top; }

    foreign "C" return (0);
}


答:
Mathematica, 21 bytes

```<code>If[#>1,1+#0@Log@#,0]&
</code>```

Recursive anonymous function. Takes an integer as input and returns its super-logarithm as output. Just uses the given definition.

Title: Calculate the Super-Logarithm

Body:
Mathematica, 21 bytes

If[#>1,1+#0@Log@#,0]&

Recursive anonymous function. Takes an integer as input and returns its super-logarithm as output. Just uses the given definition.


答:
Julia, 17 bytes

```<code>~=sortperm;!x=~~x
</code>```

1-indexed. Grade up (sortperm) twice. Try it here.

EDIT: Dennis saved four bytes by giving stuff operator-y names! Julia is weird.

Title: Ordering a list

Body:
Julia, 17 bytes

~=sortperm;!x=~~x

1-indexed. Grade up (sortperm) twice. Try it here.

EDIT: Dennis saved four bytes by giving stuff operator-y names! Julia is weird.


答:
J, <s>21</s> <s>19</s> <s>18</s> 16 bytes

Saved 2 bytes to Leaky Nun, 1 byte to Galen Ivanov, and 2 bytes to FrownyFrog!

```<code>2#@}.(0>.^.)^:a:
</code>```

Try it online!

Test cases

```<code>ls =: >:@$:@^.`0:@.(<:&1)
   ls 0
0
   ls 1
0
   ls 2
1
   ls 3
2
   ls 4
2
   ls 15
2
   ls 16
3
   ls 3814280
4
</code>```

Title: Calculate the Super-Logarithm

Body:
J, <s>21</s> <s>19</s> <s>18</s> 16 bytes

Saved 2 bytes to Leaky Nun, 1 byte to Galen Ivanov, and 2 bytes to FrownyFrog!

2#@}.(0>.^.)^:a:

Try it online!

Test cases

ls =: >:@$:@^.`0:@.(<:&1)
   ls 0
0
   ls 1
0
   ls 2
1
   ls 3
2
   ls 4
2
   ls 15
2
   ls 16
3
   ls 3814280
4


答:
Jelly, 14 bytes

```<code>“09AZaz_”Or2/Ọ
</code>```

Try it online!

Body:
Jelly, 14 bytes

“09AZaz_”Or2/Ọ

Try it online!


答:
Javascript, <s>45</s> <s>27</s> 26 bytes

```<code>l=a=>a>1&&1+l(Math.log(a))
</code>```

Here is test suite (3rd rev)

Thanks @LeakyNun for saving 1 byte with conditional and then converting function to lambda, and @Neil for pointing out false is ok return value for <=1 (changed test to be == instead of ===)

Title: Calculate the Super-Logarithm

Body:
Javascript, <s>45</s> <s>27</s> 26 bytes

l=a=>a>1&&1+l(Math.log(a))

Here is test suite (3rd rev)

Thanks @LeakyNun for saving 1 byte with conditional and then converting function to lambda, and @Neil for pointing out false is ok return value for <=1 (changed test to be == instead of ===)


问:
Calculate ISBN-13 check digit
Write a function which, given the first 12 digits of an ISBN-13 code, will calculate the entire ISBN via calculating and appending an appropriate check digit.

Your function's input is a string containing the first 12 digits of the ISBN. Its output is a string containing all 13 digits.

Formal specification

Write a function which, when given a string s consisting entirely of exactly 12 decimal digits (and no other characters), returns a string t with the following properties:

t consists of exactly 13 decimal digits (and no other characters);

s is a prefix of t;

the sum of all digits in odd positions in t (i.e. the first, third, fifth, etc.), plus three times the sum of all digits in even positions in t (i.e. the second, fourth, sixth, etc), is a multiple of 10.

Example / test case

Input

978030640615

Output

9780306406157

Victory condition

As a code-golf challenge, the shortest answer wins.

答:
C# – <s>89</s> 77 characters

string I(string s){return s+(9992-s.Sum(x=>x-0)-2*s.Where((x,i)=>i%2>0).Sum(x=>x-0))%10;}
```

<p>Formatted for readability:</p>

<pre class="lang-cs prettyprint-override"><code>string I(string s)
{
    return s +
            (9992
            - s.Sum(x => x - 0)
            - 2 * s.Where((x, i) => i%2 > 0).Sum(x => x - 0)
            ) % 10;
}
</code>```

We do not multiply by one or three, we just add everything, plus we add all even-placed characters one more time, multiplied by two.

9992 is large enough so that the sum of all ASCII characters is less than that (so that we may mod by 10 and be sure the result is positive, no need to mod by 10 twice), and is not divisible by zero because we add up all those extra 2*12*48 (twelve ASCII digits, weighed by 1 and 3) == 1152, which allows us to spare one extra character (instead of twice subtracting 48, we subtract 0 just to convert from char to int, but instead of 990, we need to write 9992).

But then again, even though much less beautiful ;-), this old-school solution gets us to 80 characters (but this is almost C-compatible):

string T(string i){int s=2,j=0;for(;j<12;)s+=i[j]*(9-j++%2*2);return i+s%10;}
```

Title: Calculate ISBN-13 check digit

Body:
C# – <s>89</s> 77 characters

string I(string s){return s+(9992-s.Sum(x=>x-0)-2*s.Where((x,i)=>i%2>0).Sum(x=>x-0))%10;}

Formatted for readability:

string I(string s)
{
    return s +
            (9992
            - s.Sum(x => x - 0)
            - 2 * s.Where((x, i) => i%2 > 0).Sum(x => x - 0)
            ) % 10;
}

We do not multiply by one or three, we just add everything, plus we add all even-placed characters one more time, multiplied by two.

9992 is large enough so that the sum of all ASCII characters is less than that (so that we may mod by 10 and be sure the result is positive, no need to mod by 10 twice), and is not divisible by zero because we add up all those extra 2*12*48 (twelve ASCII digits, weighed by 1 and 3) == 1152, which allows us to spare one extra character (instead of twice subtracting 48, we subtract 0 just to convert from char to int, but instead of 990, we need to write 9992).

But then again, even though much less beautiful ;-), this old-school solution gets us to 80 characters (but this is almost C-compatible):

string T(string i){int s=2,j=0;for(;j<12;)s+=i[j]*(9-j++%2*2);return i+s%10;}


答:
Jelly, 9 bytes

```<code>Æl>1$Ð¿L’
</code>```

Try it online!

Test suite. (Slightly modified.)

Explanation

```<code>Æl>1$Ð¿L’
     Ð¿    while loop, collect all intermediate results.
  >1$      condition: z>1
Æl         body: natural logarithm.
       L   length of the array containing all intermediate results,
           meaning number of iterations
        ’  minus one.
</code>```

Title: Calculate the Super-Logarithm

Body:
This should be a simple challenge.

Given a number \$n \ge 0\$, output the super-logarithm (or the \$\log^*\$, log-star, or iterated logarithm, which are equivalent since \$n\$ is never negative for this challenge.) of \$n\$.

$$\log^*(n) = \begin{cases}
0  & \text{ if } n \le 1 \\
1 + \log^*(\log(n)) & \text{ if } n > 1
\end{cases}$$

This is one of the two inverse functions to tetration. The other is the super-root, which is in a related question.

Examples

```<code>Input       Output
0           0
1           0
2           1
3           2
4           2
...
15          2
16          3
...
3814279     3
3814280     4
</code>```

Rules

You do not need to support decimals, though you may.

You need to support input of at least \$3814280 =  \left\lceil e^{e^e} \right\rceil\$.

You may not hard-code the values like 3814280. (Your program must theoretically support higher numbers.) I want an algorithm to be implemented.

Shortest code wins.

Related OEIS

Body:
Jelly, 9 bytes

Æl>1$Ð¿L’

Try it online!

Test suite. (Slightly modified.)

Explanation

Æl>1$Ð¿L’
     Ð¿    while loop, collect all intermediate results.
  >1$      condition: z>1
Æl         body: natural logarithm.
       L   length of the array containing all intermediate results,
           meaning number of iterations
        ’  minus one.


答:
Python 3, 45 bytes

```<code>import math
s=lambda x:x>1and-~s(math.log(x))
</code>```

For x <= 1, this returns False (which is == 0 in Python).

Title: Calculate the Super-Logarithm

Body:
Python 3, 45 bytes

import math
s=lambda x:x>1and-~s(math.log(x))

For x <= 1, this returns False (which is == 0 in Python).


答:
Python 2, <s>67</s> 60 bytes

def f(x):x=zip(x,range(len(x)));print map(sorted(x).index,x)
```

Thanks to @xnor for golfing off 7 bytes!

Test it on Ideone.

Title: Ordering a list

Body:
Summary

Given a list of integers, return the index each integer would end up at when sorted.

For example, if the list was [0,8,-1,5,8], you should return [1,3,0,2,4].  Note that the two 8s maintain their order relative to each other (the sort is stable).

Put another way:  For each element in the list, return the number of elements in the list that are: Smaller than the chosen element OR (equal to the element AND appears before the chosen element)

Indexes must start with 0 (not 1)EDIT: given the large pushback, I'll allow 1-based indicies.

Test cases:

```<code>0                -> 0
23               -> 0
2,3              -> 0,1
3,2              -> 1,0
2,2              -> 0,1
8,10,4,-1,-1,8   -> 3,5,2,0,1,4
0,1,2,3,4,5,6,7  -> 0,1,2,3,4,5,6,7
7,6,5,4,3,2,1,0  -> 7,6,5,4,3,2,1,0
4,4,0,1,1,2,0,1  -> 6,7,0,2,3,5,1,4
1,1,1,1,1,1,1,1  -> 0,1,2,3,4,5,6,7
1,1,1,1,1,1,1,0  -> 1,2,3,4,5,6,7,0
</code>```

Body:
Python 2, <s>67</s> 60 bytes

def f(x):x=zip(x,range(len(x)));print map(sorted(x).index,x)

Thanks to @xnor for golfing off 7 bytes!

Test it on Ideone.


答:
Racket, 117 bytes

```<code>(λ(x)(build-list(length x)(λ(h)((λ(y)(+(count(λ(z)(< z y))x)(count(λ(z)(eq? z y))(take x h))))(list-ref x h)))))
</code>```

I am eternally disappointed by the lack of a builtin for this.

Title: Ordering a list

Body:
Racket, 117 bytes

(λ(x)(build-list(length x)(λ(h)((λ(y)(+(count(λ(z)(< z y))x)(count(λ(z)(eq? z y))(take x h))))(list-ref x h)))))

I am eternally disappointed by the lack of a builtin for this.