答:
Ruby, 64 + 6 = 70 bytes

+6 bytes for -rset flag.

A straight port of Leaky Nun's Python answer.

->s{d=Set.new
q=0
s.each_char{|c|d^=[q+=1i**(c.ord%11)]}
d.size}
```

See it on repl.it: https://repl.it/Cnjy

Title: How many lights are on?

Body:
You are little speck on a Cartesian plane. Pondering your existence, you decide to roam around your plane and touch things. You notice that every coordinate pair you visit has a light switch. To entertain yourself, you decide to toggle every switch that you come across.

The Challenge: Create a program that will take an input of random length, using only the characters v,^,<, and >. These characters correspond to movements.

< moves you one unit to the left

^ moves you one unit up

> moves you one unit to the right

v moves you one unit down

Using this randomly generated input, calculate how many switches will be left in the ON position, assuming you start at (0,0), all lights begin in the OFF state, and you don't turn on any lights until you make your first move. (Meaning, if you start at (0,0), and move up 1 unit to (0,1), there will now be 1 light on). If you come across a switch that is on the ON position, it will be turned OFF.

Test cases:

```<code>v>v<^^<v<<^<^><<>^^>>><v>vv^v>v^><><<^>><<<vvv^vvv>v>>v><vv^^<<>vv^^>v^<>>^^<^^>^^v<^>^<vvv^v^v><^<<v<<>><<>v>>^><^>^^<>>>>vv>^<<^<<><vvv<v^>>vvv>v^>>><<v^>^^^^v>>^>^v>v<vv^<>^<<v>vv>><^^<^><vv^^v<v<v^^^>v<^vv^v<><vv^^^>v^>v>vv<<^><v<^v><<v^^v>>v<vv<><^^^v<^v><><<^^<>^>><^^^>vv^<>>>>^<^<<<<>>>v<<v<v<vv><<vv<vv<^v^^^>>vv<>v>><<<v^>vv><v<<<v<<>^vvv^<v^v>^^v^v><<v^>>>v<v<v^>>>v><>>>^<><<<<>vv>v><v>v><^v<>v>>>vv<<>^>^>v<^><^<^vv^><^^>v<^^v>v^v<^^^^vv<>v<>><v^^><>v<<<>v^<v^^><>^<>^<>><>^^<>^v><>>><v<^^>>v>^^^<v
</code>```

yields 125 lights on.

```<code>>>><^>>>^vv><^^v^<<<>>^<>>^<^>^<<^^v^<v^>>^<<><<>^v<^^^vv>v><^>>^<^<v><^v<^<<^^v><>>^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>>vv<^^^v><^v><<^>^^v>^<>><v<>>^^<<<v><>^>^><vvvv<>^<<<><<<^<>>v^vv^>><^vv^^>^<v^<v>><^^>>>^v>^v<>^v<><^><vv>v^^^<^>>^<<^<^><<<^^<v<<^vv<^<>v<^<<^^<v<vv<<><v<v^<>^<>v>>v<^v>v<>^^vvv<>vv^v^<><v^vv^<^v^v><>^><v^<>>^^^<>>vv^<v>^^v><v<^>^^^^^^><>>vvv<<><><v<^>v<>v^v<<<<>v^>>>>^v>^^<v^>v><v^<^^v<<<<v<<<>^v<^>^v>v^^>v^^vvv>vv<>^>v><v<>^<vv><>>><<^>>><<v>v^^<^<<<<v^<>>>v<<<^v^vv<>^v>v<<<<>^^>><v><>v<v><^^>><>^>^>v>>><v>^vvvv<><><^>>^v^><<>^v<><><^><<<>v^^>v>^>v^<v^vv<>><^vv^^>^^><vv<<>v>v^^>><v^>^<^<>>>vv<>^>v>v^<>v<^<<v>>>^<>v^>v>>vv^^<>>v<v<<^<>v>v^<^^^>v^^>v>v>vv<^<v>v^^><<<v<><>^^<>v>v>^^v>v>v^v>>^<v^v>><>^^>^<>>>^vv^><v^<^>v^>^v><^>^^^vv^^v<>vv<>>^><<^v>^v^>>v>^v^<<^^^vv<<vvv>^vv^v<<<v^^<<><vv<>>^^vv>^^^vv>><><v>v<^v^>>>vv^><>><v<^v<>^><v<^^^^>><^<>v>^v<^vv>v>v<^<>v>v>^<vv>v<^>vvv<v^<vv<vv<>v>^><v^v<>>>>>v>><^v<>v>^v><v^v^vv<>^<vvv^>><v^<vvv^^<^vvv^v^<>><v>v^^v<><>v^^^v<<<^><v<<<>><<vv<<><vvv^v>>v^v<v^>>><<v<>^v><>vv<<v>v^vv>v^v<^<vv<><><^v>^<vv>v^^>>^^^><vv<><^>>>^<v^<<^^>^>vv^><v<vvv>^^>>>^><<vv>vv>^<>>^^><^v><<>^<<<v^>^
</code>```

yields 1408 lights on.

To generate input, you may use the following Python script:

import random
length = random.randint(15, 10000)
walk = ''
chars = ['v', '<', '>', '^']
for i in range(length):
    walk += random.choice(chars)
print(walk)
```

Standard code-golf scoring, winner is the smallest number of bytes.

Body:
Ruby, 64 + 6 = 70 bytes

+6 bytes for -rset flag.

A straight port of Leaky Nun's Python answer.

->s{d=Set.new
q=0
s.each_char{|c|d^=[q+=1i**(c.ord%11)]}
d.size}

See it on repl.it: https://repl.it/Cnjy


问:
How many lights are on?
You are little speck on a Cartesian plane. Pondering your existence, you decide to roam around your plane and touch things. You notice that every coordinate pair you visit has a light switch. To entertain yourself, you decide to toggle every switch that you come across.

The Challenge: Create a program that will take an input of random length, using only the characters v,^,<, and >. These characters correspond to movements.

< moves you one unit to the left

^ moves you one unit up

> moves you one unit to the right

v moves you one unit down

Using this randomly generated input, calculate how many switches will be left in the ON position, assuming you start at (0,0), all lights begin in the OFF state, and you don't turn on any lights until you make your first move. (Meaning, if you start at (0,0), and move up 1 unit to (0,1), there will now be 1 light on). If you come across a switch that is on the ON position, it will be turned OFF.

Test cases:

```<code>v>v<^^<v<<^<^><<>^^>>><v>vv^v>v^><><<^>><<<vvv^vvv>v>>v><vv^^<<>vv^^>v^<>>^^<^^>^^v<^>^<vvv^v^v><^<<v<<>><<>v>>^><^>^^<>>>>vv>^<<^<<><vvv<v^>>vvv>v^>>><<v^>^^^^v>>^>^v>v<vv^<>^<<v>vv>><^^<^><vv^^v<v<v^^^>v<^vv^v<><vv^^^>v^>v>vv<<^><v<^v><<v^^v>>v<vv<><^^^v<^v><><<^^<>^>><^^^>vv^<>>>>^<^<<<<>>>v<<v<v<vv><<vv<vv<^v^^^>>vv<>v>><<<v^>vv><v<<<v<<>^vvv^<v^v>^^v^v><<v^>>>v<v<v^>>>v><>>>^<><<<<>vv>v><v>v><^v<>v>>>vv<<>^>^>v<^><^<^vv^><^^>v<^^v>v^v<^^^^vv<>v<>><v^^><>v<<<>v^<v^^><>^<>^<>><>^^<>^v><>>><v<^^>>v>^^^<v
</code>```

yields 125 lights on.

```<code>>>><^>>>^vv><^^v^<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<v^>^
</code>```

yields 1408 lights on.

To generate input, you may use the following Python script:

import random
length = random.randint(15, 10000)
walk = ''
chars = ['v', '<', '>', '^']
for i in range(length):
    walk += random.choice(chars)
print(walk)
```

Standard code-golf scoring, winner is the smallest number of bytes.

答:
Jelly, 13 bytes

A port of Luis Mendo's answer in MATL

```<code>O%11*@ı+\œ^/L
</code>```

Try it online!

```<code>O%11*@ı+\œ^/L
O             convert to codepoint
 %11          modulo 11
    *@ı       power of i (imaginary unit)
       +\     cumulative sum
         œ^/  reduce by multiset symmetric difference
            L length
</code>```

Credits of the œ^/ trick to Dennis

ContentLicense: CC BY-SA 3.0

Title: How many lights are on?

Body:
Jelly, 13 bytes

A port of Luis Mendo's answer in MATL

O%11*@ı+\œ^/L

<a href="http://jelly.tryitonline.net/#code=TyUxMSpAxLErXMWTXi9M&input=&[encoded data, 10261 characters]" rel="nofollow noreferrer">Try it online!

O%11*@ı+\œ^/L
O             convert to codepoint
 %11          modulo 11
    *@ı       power of i (imaginary unit)
       +\     cumulative sum
         œ^/  reduce by multiset symmetric difference
            L length

Credits of the œ^/ trick to Dennis


问:
Alphabet to Number and Number to Alphabet

Challenge

In this challenge you have to take a number as input and output the corresponding letter of the alphabet, and vice versa. (1 <=> A, 2 <=> B) etc.

```<code>1 -> A
2 -> B
...
26 -> Z

A -> 1
B -> 2
...
Z -> 26
</code>```

Rules

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

The input will only consist of either an uppercase letter from A to Z or an integer from 1 to 26 inclusive.

Trailing whitespaces (space and newline) are allowed.

答:
Python 2, 38 bytes

lambda x:x>''and 64^ord(x)or chr(64^x)
```

Test it on Ideone.

Body:
Python 2, 38 bytes

lambda x:x>''and 64^ord(x)or chr(64^x)

Test it on Ideone.


Title: Alphabet to Number and Number to Alphabet

Body:
Challenge

In this challenge you have to take a number as input and output the corresponding letter of the alphabet, and vice versa. (1 <=> A, 2 <=> B) etc.

```<code>1 -> A
2 -> B
...
26 -> Z

A -> 1
B -> 2
...
Z -> 26
</code>```

Rules

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

The input will only consist of either an uppercase letter from A to Z or an integer from 1 to 26 inclusive.

Trailing whitespaces (space and newline) are allowed.

Body:
C, 55 bytes

i;f(char*s){i=atol(s);printf(i?"%c":"%d",64^(i?i:*s));}


答:
Pure Bash, 51

Most of the rest of the answers use some sort of conditional.  This one dispenses with conditionals entirely, and instead treats the input as a base-36 number which indexes into an appropriately constructed bash-brace-expansion array:

```<code>a=(_ {A..I} {1..26} {J..Z} {A..Z})
echo ${a[36#$1]}
</code>```

Ideone.

Body:
Pure Bash, 51

Most of the rest of the answers use some sort of conditional.  This one dispenses with conditionals entirely, and instead treats the input as a base-36 number which indexes into an appropriately constructed bash-brace-expansion array:

a=(_ {A..I} {1..26} {J..Z} {A..Z})
echo ${a[36#$1]}

Ideone.


问:
Turn an Array into a Math Problem
Given a nonempty list of nonnegative integers, consider rewriting it as an arithmetic problem where:

A plus sign (+) is inserted between pairs of numbers that increase from left to right (a.k.a. from the start of the list to the end).

A minus sign (-) is inserted between pairs of numbers that decrease from left to right.

A multiplication sign (*) is inserted between pairs of numbers that are equal.

Said another way: any sublist a,b becomes a+b if a<b, a-b if  a>b, and a*b if a==b.

For example, the list

```<code>[12, 0, 7, 7, 29, 10, 2, 2, 1]
</code>```

would become the expression

```<code>12 - 0 + 7*7 + 29 - 10 - 2*2 - 1
</code>```

which evaluates to 75.

Write a program or function that takes in such a list and evaluates it, printing or returning the result.

Order of operations matters. Multiplications should be done before any addition or subtraction.

If the input list has one number, that should be what it evaluates to. e.g. [64] should give 64.

Use of eval or exec or similar constructs is allowed.

Here are some additional examples:

```<code>[list]
expression
value

[0]
0
0

[1]
1
1

[78557]
78557
78557

[0,0]
0*0
0

[1,1]
1*1
1

[2,2]
2*2
4

[0,1]
0+1
1

[1,0]
1-0
1

[1,2]
1+2
3

[2,1]
2-1
1

[15,4,4]
15-4*4
-1

[9,8,1]
9-8-1
0

[4,2,2,4]
4-2*2+4
4

[10,9,9,12]
10-9*9+12
-59

[1,1,2,2,3,3]
1*1+2*2+3*3
14

[5,5,4,4,3,3]
5*5-4*4-3*3
0

[3,1,4,1,5,9,2,6,5,3,5,9]
3-1+4-1+5+9-2+6-5-3+5+9
29

[7637,388,389,388,387,12,0,0,34,35,35,27,27,2]
7637-388+389-388-387-12-0*0+34+35*35-27*27-2
7379
</code>```

The shortest code in bytes wins. Tiebreaker is earlier answer.

答:
Actually, 30 bytes

```<code>;2@VpXdX`i-su"+*-"E`M' @o♀+εj≡
</code>```

Unfortunately, because the eval (≡) command only evaluates literals on TIO, this program does not work on TIO.

Explanation:

```<code>;2@VpXdX`i-su"+*-"E`M' @o♀+εj≡
;                               duplicate input
 2@V                            overlapping sublists of length <= 2
    pXdX                        discard first and last element (length-1 sublists)
        `i-su"+*-"E`M           map: for each pair of elements
         i-su                     flatten, subtract, sign, increment (results in a 0 if b < a, 1 if b == a, and 2 if b > a)
             "+*-"E               select the correct operation
                     ' @o       put a space at the beginning of the list to pad it properly
                         ♀+     pairwise addition (since addition is not defined for strings and integers, this just zips the lists and flattens the result into a single flat list)
                           εj   join with empty string
                             ≡  eval
</code>```

Title: Turn an Array into a Math Problem

Body:
Actually, 30 bytes

;2@VpXdX`i-su"+*-"E`M' @o♀+εj≡

Unfortunately, because the eval (≡) command only evaluates literals on TIO, this program does not work on TIO.

Explanation:

;2@VpXdX`i-su"+*-"E`M' @o♀+εj≡
;                               duplicate input
 2@V                            overlapping sublists of length <= 2
    pXdX                        discard first and last element (length-1 sublists)
        `i-su"+*-"E`M           map: for each pair of elements
         i-su                     flatten, subtract, sign, increment (results in a 0 if b < a, 1 if b == a, and 2 if b > a)
             "+*-"E               select the correct operation
                     ' @o       put a space at the beginning of the list to pad it properly
                         ♀+     pairwise addition (since addition is not defined for strings and integers, this just zips the lists and flattens the result into a single flat list)
                           εj   join with empty string
                             ≡  eval


问:
Evaluate an expression of ternary operators
Consider a grammar over the alphabet {0, 1, ?, :} defined by the production rule

s → 0 ┃ 1 ┃ 0 ? s : s ┃ 1 ? s : s

Given a string generated from s, parse it as an expression where ?: is right-associative (for example, a?B?X:Y:c?d:e?f:g means a?(B?X:Y):(c?d:(e?f:g))) and evaluate it with the following semantics:

```<code>eval(0) = 0
eval(1) = 1
eval(0?a:b) = eval(b)
eval(1?a:b) = eval(a)
</code>```

If the result is 0, output some fixed value; if the output is 1, output a different fixed value. Specify your chosen output values (e.g. 0/1, or False/True) in your answer.

Test cases

```<code>0 -> 0
1 -> 1
0?0:1 -> 1
0?1:0 -> 0
1?0:1 -> 0
1?1:0 -> 1
0?1?0:1:1 -> 1
1?0?1:1:1 -> 1
1?0:1?0:1?1:1 -> 0
1?1?1:0?1?0:0:0:0 -> 1
1?0:1?0?1:1?1:0:1?1?1:1:1?0:1 -> 0
1?1?1:0?0?1:1:0?1:0:1?1?0?0:0:1?1:0:0?1?0:1:1?0:1 -> 1
0?0?1?0?0:1:0?0:0:0?0?1:1:1?0:1:0?0?0?1:0:0?1:1:1?1?0:1:1 -> 0
</code>```

Rules

You may not use language built-ins that interpret strings as code in some programming language and run it (such as JavaScript/Perl/Ruby/Python’s eval).

That said, your code doesn’t actually have to parse and then evaluate the input string. You can take any approach the achieves equivalent results and doesn’t violate the previous rule.

Your program will be checked against perl -le 'print eval<>'.

The shortest code (in bytes) wins.

答:
Brainfuck, <s>82</s> <s>64</s> 63 bytes

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

The output is \xff for 0 and \x00 for 1. The brainfuck implementation must allow going to the left of the starting cell.

This uses essentially the same approach as xsot's Python answer, but the branching is probably harder to follow compared with my initial 82-byte submission:

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

(For this solution, the output is \xfe for 0 and \xff for 1, and wider compatibility is achieved when the input ends with a newline.)

If you can't be bothered to analyse xsot's solution, the idea is this: Proceed from left to right. If you see 1? then greedily discard it. If you see 0? then discard everything between that and the corresponding :. When ? does not appear as the second character, stop looping and print the first character of the remaining string.

So, the 82-byte solution actually mirrors that scheme pretty closely. The inner loop handles 0?, just like xsot's inner loop. Some care is taken in order to enter the main loop without checking any input characters; i.e., we want to check whether the second character is ? just once at the end of the main loop, and not also at the beginning before entering the main loop.

The 63-byte solution essentially combines the inner and outer loops into one, which I suspected was possible given the similarity between those loops. The memory layout in the main loop could be described as:

```<code>[s] d c
</code>```

where [x] means current cell -- the s starts as a dummy nonzero value that just indicates we are still looping, and is immediately overwritten with an input character (either 0 or 1). The d cell holds the (negative) depth in case we are in the middle of a 0?, otherwise 0. The c is going to be either ? or : or newline or EOF.

After updating s and c, we handle the 0? case by updating d accordingly and adjusting the pointer, otherwise we use the current value of c as the value of d in the next iteration, or stop if we are done.

Body:
Brainfuck, <s>82</s> <s>64</s> 63 bytes

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

The output is \xff for 0 and \x00 for 1. The brainfuck implementation must allow going to the left of the starting cell.

This uses essentially the same approach as xsot's Python answer, but the branching is probably harder to follow compared with my initial 82-byte submission:

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

(For this solution, the output is \xfe for 0 and \xff for 1, and wider compatibility is achieved when the input ends with a newline.)

If you can't be bothered to analyse xsot's solution, the idea is this: Proceed from left to right. If you see 1? then greedily discard it. If you see 0? then discard everything between that and the corresponding :. When ? does not appear as the second character, stop looping and print the first character of the remaining string.

So, the 82-byte solution actually mirrors that scheme pretty closely. The inner loop handles 0?, just like xsot's inner loop. Some care is taken in order to enter the main loop without checking any input characters; i.e., we want to check whether the second character is ? just once at the end of the main loop, and not also at the beginning before entering the main loop.

The 63-byte solution essentially combines the inner and outer loops into one, which I suspected was possible given the similarity between those loops. The memory layout in the main loop could be described as:

[s] d c

where [x] means current cell -- the s starts as a dummy nonzero value that just indicates we are still looping, and is immediately overwritten with an input character (either 0 or 1). The d cell holds the (negative) depth in case we are in the middle of a 0?, otherwise 0. The c is going to be either ? or : or newline or EOF.

After updating s and c, we handle the 0? case by updating d accordingly and adjusting the pointer, otherwise we use the current value of c as the value of d in the next iteration, or stop if we are done.


答:
Actually, 7 bytes

```<code>ú' +ûEí
</code>```

Try it online!

Explanation:

```<code>ú' +ûEí
ú' +     lowercase English alphabet, prepend space
    û    uppercase
     E   element (pushes the nth letter if input is an integer, leaves stack alone otherwise)
      í  index (pushes index of input if input is a string, leaves stack alone otherwise)
</code>```

If lowercase is acceptable, this is 6 bytes:

```<code>ú' +Eí
</code>```

Try it online!

Body:
Actually, 7 bytes

ú' +ûEí

Try it online!

Explanation:

ú' +ûEí
ú' +     lowercase English alphabet, prepend space
    û    uppercase
     E   element (pushes the nth letter if input is an integer, leaves stack alone otherwise)
      í  index (pushes index of input if input is a string, leaves stack alone otherwise)

If lowercase is acceptable, this is 6 bytes:

ú' +Eí

Try it online!


问:
Match up to 10 in an array

Challenge

Given an array of single digit number, work out if any 2 of them add up to 10 and print them out

Example

Input

(1,2,3,4,5,5,6,7)

This returns ((4,6),(5,5),(3,7))

Input

(1,2,3,4,5)

This returns (). as there is only one 5

Input

(5,5,5,5,5)

This returns ((5,5),(5,5)) as there is odd number of 5s and each 5 can be used only once

Rules

Here are the rules!

Assume input will only be an unsorted array of positive single digit integers

Each number will be pair up only once, which means if there are three 5s it only form 1 pair (5,5). If there are (3,3,7) it will only form 1 pair (3,7)

For the input: You can use any type of parentheses(or lack of) as long as readers can tell that the input is a single array of numbers.

For the output: It must look like an array of pairs. Where the array is the same form as your input.(If you did not use any parenheses in your input, you have to use some kind of symbols so that any readers can tell they are pairs in an array)

Test Cases

```<code>(1,2,3,4,5,5,6,7) =((4,6),(5,5),(3,7))
(1,2,3,4,5) = ()
(5,5,5,5,5) = ((5,5),(5,5))
(1,2,3,3,4,5,6,7)=((3,7),(4,6))
(9,8,7,6,4,4,3,1)=((9,1),(7,3),(6,4))
</code>```

Good luck!

The shorter an answer is, the better!

Edit 1: update the rules and Testcases from comments

Edit 2: update rules to define format of input.

Edit 3: update rules to define format of output. trying to be as accommodating as possible.

Title: Match up to 10 in an array

Body:
Python 2.7 (70)

y=input()
while y:
 g=10-y.pop()
 if g in y:y.remove(g);print(g,10-g)

Testcases:

$ echo '[1, 2, 3, 4, 5, 5, 6, 7]' | python p.py
(3, 7)
(4, 6)
(5, 5)

$ echo '[1,2,3,4,5]' | python p.py

$ echo '[5,5,5,5,5]' | python p.py
(5, 5)
(5, 5)

$ echo '[1,2,3,3,4,5,6,7]' | python p.py
(3, 7)
(4, 6)

$ echo '[9,8,7,6,4,4,3,1]' | python p.py
(9, 1)
(7, 3)
(6, 4)

One byte extra for the nice parenthesis.


问:
Dense Number Sequence
OEIS: A167171

A dense number is a number that has exactly as many prime divisors as non-prime divisors (including 1 and itself as divisors). Equivalently, it is either a prime or a product of two distinct primes. The first 100 dense numbers are:

```<code>2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 19, 21, 22, 23, 26, 29, 31, 33, 34, 35, 37, 38, 39, 41, 43, 46, 47, 51, 53, 55, 57, 58, 59, 61, 62, 65, 67, 69, 71, 73, 74, 77, 79, 82, 83, 85, 86, 87, 89, 91, 93, 94, 95, 97, 101, 103, 106, 107, 109, 111, 113, 115, 118, 119, 122, 123, 127, 129, 131, 133, 134, 137, 139, 141, 142, 143, 145, 146, 149, 151, 155, 157, 158, 159, 161, 163, 166, 167, 173, 177, 178, 179, 181, 183, 185, 187, 191, 193, 194
</code>```

Given a nonnegative integer n, output dense(n). n may be 0-indexed or 1-indexed.

Reference implementation (Sage)

import itertools

def dense_numbers():
    n = 1
    while True:
        prime_divisors = [x for x in divisors(n) if x.is_prime()]
        non_prime_divisors = [x for x in divisors(n) if not x.is_prime()]
        if len(prime_divisors) == len(non_prime_divisors):
            yield n
        n += 1

N = 20

print itertools.islice(dense_numbers(), N, N+1).next()
```

Try it online

答:
Jelly, 9 bytes

```<code>ÆE²Sḍ2µ#Ṫ
</code>```

Reads from STDIN and uses 1-based indexing. Try it online!

How it works

```<code>ÆE²Sḍ2µ#Ṫ  Main link. No arguments. Implicit argument: 0

      µ#   Read an integer n from STDIN and execute the chain to the left for
           k = 0, 1, 2, ... until n of them return a truthy value.
           Return the array of matches.
ÆE           Compute the exponents of k's prime factorization.
  ²          Square each exponent.
   S         Compute the sum of all squares.
    ḍ2       Test if 2 is divisible by the result (true iff  the sum is 1 or 2).
        Ṫ  Tail; extract the last (n-th) matching value of k.
</code>```

Title: Dense Number Sequence

Body:
Jelly, 9 bytes

ÆE²Sḍ2µ#Ṫ

Reads from STDIN and uses 1-based indexing. Try it online!

How it works

ÆE²Sḍ2µ#Ṫ  Main link. No arguments. Implicit argument: 0

      µ#   Read an integer n from STDIN and execute the chain to the left for
           k = 0, 1, 2, ... until n of them return a truthy value.
           Return the array of matches.
ÆE           Compute the exponents of k's prime factorization.
  ²          Square each exponent.
   S         Compute the sum of all squares.
    ḍ2       Test if 2 is divisible by the result (true iff  the sum is 1 or 2).
        Ṫ  Tail; extract the last (n-th) matching value of k.


问:
Is it a wordinian?
What is the shortest way to see if an input is a wordinian using any programming language?

A wordinian is a word that contains words of length 1 to the original word's length. For example,

bin

'I' is a word

  'in' is a word

  'bin' is a word

Or,

stage

'a' is a word

  'ta' is a word (yes it is)

  'age' is a word

  'stag' is a word

  'stage' is a word

Input

Your code should take a word and a dictionary as inputs, in any reasonable format.

Output

The output should be a value to indicate true or false, to tell us if the word is a wordinian.

For more info on wordinians click here.

Here is a list of words that I will be using as inputs and subwords. Also, in response to @xnor, it has to contain subwords of each length, not a chain of subwords. Note that only one word will be used as an input.

答:
Python, 52 bytes

lambda w,d:len({len(x)for x in d if x in w})==len(w)
```

An anonymous function that takes a word w and dictionary d. It takes the words in d that are substrings of w, makes a set of their lengths, and then checks that there as many distinct lengths as there are letters in w.

Title: Is it a wordinian?

Body:
Python, 52 bytes

lambda w,d:len({len(x)for x in d if x in w})==len(w)

An anonymous function that takes a word w and dictionary d. It takes the words in d that are substrings of w, makes a set of their lengths, and then checks that there as many distinct lengths as there are letters in w.


问:
Tips for Golfing in ECMAScript 6 and above
This is similar to other "Tips for golfing in <...>" but specifically targeting the newer features in JavaScript brought up in ECMAScript 6 and above.

JavaScript inherently is a very verbose language, function(){}, .forEach(), converting string to array, array-like object to array, etc, etc are super bloats and not healthy for Golfing.

ES6+, on the other hand, has some super handy features and reduced footprint. x=>y, [...x], etc. are just some of the examples.

Please post some nice tricks that can help shave off those few extra bytes from your code.

NOTE: Tricks for ES5 are already available in Tips for golfing in JavaScript; answers to this thread should focus on tricks only available in ES6 and other future ES versions.

However, this thread is also for users who currently golf using ES5 features. Answers may also contain tips to help them understand and map ES6 features to their style of ES5 coding.

答:
(strawman) Use do expressions instead of evaling strings

[Babel preset] and [proposal].

Comes with the added bonus of keeping syntax highlighting.  This might be a stretch in some contests, but is nonetheless interesting.  I think if it's supported in Babel, it should qualify as competing.

Consider the following function (37 bytes):

```<code>f=n=>{for(o=i=0;i<n;o+=++i);return o}
</code>```

This might be golfed down with the classic eval trick (34 bytes (thank you everyone)):

```<code>f=n=>eval("for(o=i=0;i<n;)o+=++i")
</code>```

But we can do better with do (30 bytes):

```<code>f=n=>do{for(o=i=0;i<n;)o+=++i}
</code>```

Working example - note that Babel needs let statements in all above functions as well.

Essentially what I'm trying to say is if a solution can be done with eval, you can almost always shave off a few bytes using do.

Body:
(strawman) Use do expressions instead of evaling strings

[Babel preset] and [proposal].

Comes with the added bonus of keeping syntax highlighting.  This might be a stretch in some contests, but is nonetheless interesting.  I think if it's supported in Babel, it should qualify as competing.

Consider the following function (37 bytes):

f=n=>{for(o=i=0;i<n;o+=++i);return o}

This might be golfed down with the classic eval trick (34 bytes (thank you everyone)):

f=n=>eval("for(o=i=0;i<n;)o+=++i")

But we can do better with do (30 bytes):

f=n=>do{for(o=i=0;i<n;)o+=++i}

Working example - note that Babel needs let statements in all above functions as well.

Essentially what I'm trying to say is if a solution can be done with eval, you can almost always shave off a few bytes using do.


答:
C#, 32 bytes

```<code>n=>(n^=64)>26?(object)(char)n:n;
</code>```

Casts to Func<int, object>.

Input: char implicitely converts to int so can be called with int (1-26) or char ('A'-Z').

Output: Either a char or int.

Body:
C#, 32 bytes

n=>(n^=64)>26?(object)(char)n:n;

Casts to Func<int, object>.

Input: char implicitely converts to int so can be called with int (1-26) or char ('A'-Z').

Output: Either a char or int.


问:
Random Golf of the Day #7: A distinctly random character

About the Series

This is a guest entry for the Random Golf of the Day series.

First off, you may treat this like any other code golf challenge, and answer it without worrying about the series at all. However, there is a leaderboard across all challenges. You can find the leaderboard along with some more information about the series in the first post.

Input

No input is taken.

Output

A single letter of the alphabet (case irrelevant), with an optional trailing newline. Each letter must have non-zero probability of being chosen, and all 26 probabilities must be distinct. To remove all ambiguity: Distinct means that there must not be two probabilities that are equal to each other.

Scoring

This is code golf. Shortest code in bytes wins.

A valid entry is a full program or function that has zero probability of not terminating.

Alphabet

To avoid confusion, the particular alphabet to be used is the Latin alphabet:

Either

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

or

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

You may choose to output upper case or lower case. Alternatively, you may choose to output different cases on different runs if that helps. The probability for a given letter is the probability of that letter appearing in either case (upper or lower).

Explanation

As it won't be at all obvious from the output, please include a clear explanation of how you achieved the 26 distinct probabilities.

Leaderboard

(from here)

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```
</div>
</div>
</p>

<p><strong>The first post of the series also generates an overall leaderboard.</strong></p>

<p>To make sure that your answers show up, please start every answer with a headline, using the following Markdown template:</p>

```## Language Name, N bytes
```

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

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

(The language is not currently shown, but the snippet does require and parse it, and I may add a by-language leaderboard in the future.)

答:
Perl 6, 30 bytes

{('a'..'z'Zxx 1..*).flat.pick}
```

<h2>Explanation:</h2>

<pre class="lang-perl6 prettyprint-override"><code># bare block lambda
{
  (

    'a' .. 'z' # the alphabet
    Z[xx]      # zipped ｢Z｣ using the list repeat operator ｢xx｣
    1 .. *     # with 1 to 26

    # ((a)(b b)(c c c)(d d d d)(e e e e e)...

  )
  .flat # flatten it from a list of lists into a single list
  .pick # pick an element from the list
}
</code>```

Body:
Perl 6, 30 bytes

{('a'..'z'Zxx 1..*).flat.pick}

Explanation:

# bare block lambda
{
  (

    'a' .. 'z' # the alphabet
    Z[xx]      # zipped ｢Z｣ using the list repeat operator ｢xx｣
    1 .. *     # with 1 to 26

    # ((a)(b b)(c c c)(d d d d)(e e e e e)...

  )
  .flat # flatten it from a list of lists into a single list
  .pick # pick an element from the list
}


答:
Perl 6, 25 bytes

{+$_??chr $_+64!!.ord-64}
```

<h2>Explanation:</h2>

<pre class="lang-perl6 prettyprint-override"><code># bare block lambda with implicit parameter of ｢$_｣
{
    +$_         # is the input numeric
  ??
    chr $_ + 64 # if it is add 64 and get the character
  !!
    $_.ord - 64 # otherwise get the ordinal and subtract 64
}
</code>```

Example:

say ('A'..'Z').map: {+$_??chr $_+64!!.ord-64}
# (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26)

say (1..26).map: {+$_??chr $_+64!!.ord-64}
# (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
```

Body:
Perl 6, 25 bytes

{+$_??chr $_+64!!.ord-64}

Explanation:

# bare block lambda with implicit parameter of ｢$_｣
{
    +$_         # is the input numeric
  ??
    chr $_ + 64 # if it is add 64 and get the character
  !!
    $_.ord - 64 # otherwise get the ordinal and subtract 64
}

Example:

say ('A'..'Z').map: {+$_??chr $_+64!!.ord-64}
# (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26)

say (1..26).map: {+$_??chr $_+64!!.ord-64}
# (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)


问:
Executable haiku that outputs a haiku
Puzzle:

Write a short, three-line program which:

has 5/7/5 syllables per line when read aloud

outputs a haiku when run.

An example of a program having the correct structure, but non-haiku output, is (Python):

```<code>>>> for x in range(3):
...     print "EXTERMINATE HUMANS"
... # I am a Dalek.
...
EXTERMINATE HUMANS
EXTERMINATE HUMANS
EXTERMINATE HUMANS
</code>```

(The comment is a bit of a cop-out.)

This reads aloud as:

for x in range three

print EXTERMINATE HUMANS!

I am a Dalek.

Any language is acceptable. For the purposes of reading aloud, symbols like !@#$%^&*()_+ can be ignored if you want, or pronounced aloud, admitting something like Waka Waka Bang Splat. (I'm sure there will be a Perl entry like !***(!:, )(*@@@#, )_(*)!.)

Extra points if either the code or the output is especially funny, or especially zen.

Edit: If your language requires boilerplate before it can do anything interesting (#include <iostream>?) then I'm happy to ignore the boilerplate.

I've accepted Paul Richter's Common Lisp haiku on the grounds that it made me laugh for a good five minutes.

Honorable mention for Timwi's creative rule-bending (compiler output?!) and for the extremely memorable line "Static void. I long for you."

Now this question ends;

Many more haikus await.

Continue posting!

答:
Vim

```<code>ia0 <esc><c-x>
YpA-<esc>
px5<c-x><c-x>
</code>```

read as

```<code>i a zero x
Y p A hyphen escape
p x five x x
</code>```

Writes:

```<code>a-1
a-1-
-7
</code>```

read as:

```<code>a negative one
a minus one negative
negative seven
</code>```

Title: Executable haiku that outputs a haiku

Body:
Vim

ia0 <esc><c-x>
YpA-<esc>
px5<c-x><c-x>

read as

i a zero x
Y p A hyphen escape
p x five x x

Writes:

a-1
a-1-
-7

read as:

a negative one
a minus one negative
negative seven


答:
Python 3

```<code>print(print.__doc__[:15])
print(print.__doc__[13:][:13])
print(print.__doc__[32])
</code>```

Read as:

```<code>print print doc one five
print print doc one three one three
print print doc three two
</code>```

Prints:

```<code>print(value, ..
..., sep=' ',
\
</code>```

Read as:

```<code>print value dot dot
ellipses, sep equals blank
reverse solidus
</code>```

Title: Executable haiku that outputs a haiku

Body:
Puzzle:

Write a short, three-line program which:

has 5/7/5 syllables per line when read aloud

outputs a haiku when run.

An example of a program having the correct structure, but non-haiku output, is (Python):

```<code>>>> for x in range(3):
...     print "EXTERMINATE HUMANS"
... # I am a Dalek.
...
EXTERMINATE HUMANS
EXTERMINATE HUMANS
EXTERMINATE HUMANS
</code>```

(The comment is a bit of a cop-out.)

This reads aloud as:

for x in range three

print EXTERMINATE HUMANS!

I am a Dalek.

Any language is acceptable. For the purposes of reading aloud, symbols like !@#$%^&*()_+ can be ignored if you want, or pronounced aloud, admitting something like Waka Waka Bang Splat. (I'm sure there will be a Perl entry like !***(!:, )(*@@@#, )_(*)!.)

Extra points if either the code or the output is especially funny, or especially zen.

Edit: If your language requires boilerplate before it can do anything interesting (#include <iostream>?) then I'm happy to ignore the boilerplate.

I've accepted Paul Richter's Common Lisp haiku on the grounds that it made me laugh for a good five minutes.

Honorable mention for Timwi's creative rule-bending (compiler output?!) and for the extremely memorable line "Static void. I long for you."

Now this question ends;

Many more haikus await.

Continue posting!

Body:
Python 3

print(print.__doc__[:15])
print(print.__doc__[13:][:13])
print(print.__doc__[32])

Read as:

print print doc one five
print print doc one three one three
print print doc three two

Prints:

print(value, ..
..., sep=' ',
\

Read as:

print value dot dot
ellipses, sep equals blank
reverse solidus


答:
Python 3, 43 bytes

lambda x:x!=str(x)and chr(64|x)or ord(x)^64
```

The interesting thing about this solution is that it incorporates all the senses of OR, bitwise OR |, logical OR or, bitwise XOR ^ and logical XOR != ...

Body:
Python 3, 43 bytes

lambda x:x!=str(x)and chr(64|x)or ord(x)^64

The interesting thing about this solution is that it incorporates all the senses of OR, bitwise OR |, logical OR or, bitwise XOR ^ and logical XOR != ...


问:
Fibonacci function or sequence
The Fibonacci sequence is a sequence of numbers, where every number in the sequence is the sum of the two numbers preceding it.  The first two numbers in the sequence are both 1. Here are the first few terms:

```<code>1 1 2 3 5 8 13 21 34 55 89 ...
</code>```

Write the shortest code that either:

Generates the Fibonacci sequence without end.

Given n calculates the nth term of the sequence. (Either 1 or zero indexed)

You may use standard forms of input and output.

(I gave both options in case one is easier to do in your chosen language than the other.)

For the function that takes an n, a reasonably large return value (the largest Fibonacci number that fits your computer's normal word size, at a minimum) has to be supported.

Leaderboard

/* Configuration */

var QUESTION_ID = 85; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 3; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];

  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '
' + c.body.replace(OVERRIDE_REG, '') + '
';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    else console.log(body);
  });

  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    lang = jQuery(''+lang+'').text();

    languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
    if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body {
  text-align: left !important;
  display: block !important;
}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Python

```<code>a,b,n=0,1,10
while n:a,b,n=b,a+b,n-1;print b
</code>```

ContentLicense: CC BY-SA 4.0

Title: Fibonacci function or sequence

Body:
Python

a,b,n=0,1,10
while n:a,b,n=b,a+b,n-1;print b

ContentLicense: CC BY-SA 2.5


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

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

Please post one tip per answer.

答:
Use the splat operator to get the tail and head of an array:

```<code>head, *tail = [1,2,3]
head => 1
tail => [2,3]
</code>```

This also works the other way:

```<code>*head, tail = [1,2,3]
head => [1,2]
tail => 3
</code>```

Use the * method with a string on an array to join elements:

```<code>[1,2,3]*?,
=> "1,2,3"
</code>```

Title: Tips for golfing in Ruby

Body:
Use the splat operator to get the tail and head of an array:

head, *tail = [1,2,3]
head => 1
tail => [2,3]

This also works the other way:

*head, tail = [1,2,3]
head => [1,2]
tail => 3

Use the * method with a string on an array to join elements:

[1,2,3]*?,
=> "1,2,3"


问:
Find the minimum edit distance between two strings

Explanation

The edit distance between two strings is a function of the minimum possible number of insertions, deletions, or substitutions to convert one word into another word.

Insertions and deletions cost 1, and substitutions cost 2.

For example, the distance between AB and A is 1, because deletions cost 1 and the only edit needed is the deletion of the B character.

The distance between CAR and FAR is 2, because substitutions cost 2. Another way to look at this is one deletion and one insertion.

Rules

Given two input strings (supplied however is convenient in your language), your program must find the minimum edit distance between the two strings.

You may assume that the strings only contain the characters A-Z and have fewer than 100 characters and more than 0 characters.

This is code golf, so the shortest solution wins.

Sample Test Cases

```<code>ISLANDER, SLANDER
> 1
MART, KARMA
> 5
KITTEN, SITTING
> 5
INTENTION, EXECUTION
> 8
</code>```

答:
Ruby 1.9, 124

```<code>l=->a,b{a[0]?b[0]?[(a[0]==b[0]?-1:1)+l[a[1..-1],b[1..-1]],l[a[1..-1],b],l[a,b[1..-1]]].min+1: a.size: b.size}
puts l[*ARGV]
</code>```

Golfed version of the slow, recursive Ruby method here, modified to double the weight for substitutions. The fact that it takes 7 characters to remove the first character of a string really hurts, and it'd be cool to replace (a[0]==b[0]?-1:1) with something like -1**a[0]<=>b[0] but the order of operations is not my friend.

Body:
Ruby 1.9, 124

l=->a,b{a[0]?b[0]?[(a[0]==b[0]?-1:1)+l[a[1..-1],b[1..-1]],l[a[1..-1],b],l[a,b[1..-1]]].min+1: a.size: b.size}
puts l[*ARGV]

Golfed version of the slow, recursive Ruby method here, modified to double the weight for substitutions. The fact that it takes 7 characters to remove the first character of a string really hurts, and it'd be cool to replace (a[0]==b[0]?-1:1) with something like -1**a[0]<=>b[0] but the order of operations is not my friend.