问:
Faro shuffle an array
A Faro shuffle is a technique frequently used by magicians to "shuffle" a deck. To perform a Faro shuffle you first cut the deck into 2 equal halves then you interleave the two halves. For example

```<code>[1 2 3 4 5 6 7 8]
</code>```

Faro shuffled is

```<code>[1 5 2 6 3 7 4 8]
</code>```

This can be repeated any number of times. Interestingly enough, if you repeat this enough times, you will always end up back at the original array. For example:

```<code>[1 2 3 4 5 6 7 8]
[1 5 2 6 3 7 4 8]
[1 3 5 7 2 4 6 8]
[1 2 3 4 5 6 7 8]
</code>```

Notice that 1 stays on the bottom and 8 stays on the top. That makes this an outer-shuffle. This is an important distinction.

The Challenge

Given an array of integers A, and a number N, output the array after N Faro shuffles. A may contain repeated or negative elements, but it will always have an even number of elements. You can assume the array will not be empty. You can also assume that N will be a non-negative integer, although it may be 0. You can take these inputs in any reasonable manner. The shortest answer in bytes wins!

Test IO:

```<code>#N, A,                                              Output
1,  [1, 2, 3, 4, 5, 6, 7, 8]                        [1, 5, 2, 6, 3, 7, 4, 8]
2,  [1, 2, 3, 4, 5, 6, 7, 8]                        [1, 3, 5, 7, 2, 4, 6, 8]
7,  [-23, -37, 52, 0, -6, -7, -8, 89]               [-23, -6, -37, -7, 52, -8, 0, 89]
0,  [4, 8, 15, 16, 23, 42]                          [4, 8, 15, 16, 23, 42]
11, [10, 11, 8, 15, 13, 13, 19, 3, 7, 3, 15, 19]    [10, 19, 11, 3, 8, 7, 15, 3, 13, 15, 13, 19]
</code>```

And, a massive test case:

```<code>23, [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, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
</code>```

Should output:

```<code>[1, 30, 59, 88, 18, 47, 76, 6, 35, 64, 93, 23, 52, 81, 11, 40, 69, 98, 28, 57, 86, 16, 45, 74, 4, 33, 62, 91, 21, 50, 79, 9, 38, 67, 96, 26, 55, 84, 14, 43, 72, 2, 31, 60, 89, 19, 48, 77, 7, 36, 65, 94, 24, 53, 82, 12, 41, 70, 99, 29, 58, 87, 17, 46, 75, 5, 34, 63, 92, 22, 51, 80, 10, 39, 68, 97, 27, 56, 85, 15, 44, 73, 3, 32, 61, 90, 20, 49, 78, 8, 37, 66, 95, 25, 54, 83, 13, 42, 71, 100]
</code>```

答:
java, 109 bytes

int[]f(int[]a,int n){for(int x,q=a.length,d[];0<n--;a=d){d=new int[q];for(x=0;x<q;x++)d[(2*x+2*x/q)%q]=a[x];}return a;}

Explanation:
There is a pattern to how the elements move when they are faro shuffled:

let x be the original index

let y be the new index

let L be the length of the array

y is double x

if x is greater than or equal to half of L then increment y

keep y within the array's bounds

or as code: y=(2*x+x/(L/2))%L

This assumes that indicies start at 0. Here's the code further explained:

```<code>int[] faroShuffle( int[] array, int numberOfShuffles ) {
    //repeat the faro shuffle n times
    for( int index, length=array.length, destination[]; 0<numberOfShuffles--; array=destination ) {
        //new array to copy over the elements
        destination=new int[length];
        //copy the elements into the new array
        for( index=0; index<length; index++ )
            destination[(2*index+2*index/length)%length]=array[index];
        //at the end of each loop, copy the reference to the new array and use it going forward
    }
    return array;
}
</code>```

see ideone for test cases

Title: Faro shuffle an array

Body:
java, 109 bytes

int[]f(int[]a,int n){for(int x,q=a.length,d[];0<n--;a=d){d=new int[q];for(x=0;x<q;x++)d[(2*x+2*x/q)%q]=a[x];}return a;}

Explanation:
There is a pattern to how the elements move when they are faro shuffled:

let x be the original index

let y be the new index

let L be the length of the array

y is double x

if x is greater than or equal to half of L then increment y

keep y within the array's bounds

or as code: y=(2*x+x/(L/2))%L

This assumes that indicies start at 0. Here's the code further explained:

int[] faroShuffle( int[] array, int numberOfShuffles ) {
    //repeat the faro shuffle n times
    for( int index, length=array.length, destination[]; 0<numberOfShuffles--; array=destination ) {
        //new array to copy over the elements
        destination=new int[length];
        //copy the elements into the new array
        for( index=0; index<length; index++ )
            destination[(2*index+2*index/length)%length]=array[index];
        //at the end of each loop, copy the reference to the new array and use it going forward
    }
    return array;
}

see ideone for test cases


问:
Generate a "GitHub" Avatar

Background / Description

Note: as @HelkaHomba points out, the actual GitHub identicons are not actually random but based on the hash of a username

The default GitHub avatar is a 5x5-pixel image. A color is picked randomly, and then random pixels are filled in on one side (right or left, 2x5 size) using that color. Then that side is copied & flipped to the other side, across the y-axis. The pixels left over that are not filled in are #F0F0F0, or rgb(240,240,240).

The center column's pixels (1x5 size) are then randomly filled in, using the same color as previously.

Output

Note: for this challenge we will ignore the space that encloses the GitHub avatars

The program should output a 5x5 pixel image file. See http://meta.codegolf.stackexchange.com/a/9095/42499 for specifics

Examples

Note: these were obviously scaled up from 5x5 so you can see them

Good luck!

答:
Actually, 53 bytes

```<code>3'≡*;╗`┘#8╙r-J┌`MΣ╝5`3"2rJ└"£n3╟;RdX+Σ`nkΣ"P6 5 5 255
</code>```

Try it online!

Actually is bad at string processing. I think I've mentioned that before. This program outputs a P6 netpbm image using CP437, like the following:

```<code>P6 5 5 255
εεεεεεå♠ƒεεεεεεå♠ƒå♠ƒεεεå♠ƒå♠ƒεεεεεεεεεεεεεεεεεεεεεå♠ƒεεεεεεå♠ƒå♠ƒå♠ƒå♠ƒå♠ƒ
</code>```

This can be converted to a PNG using ImageMagick:

```<code>seriously -f prog.srs | convert - out.png
</code>```

Scaled up PNG version:

Explanation:

```<code>3'≡*;╗`┘#8╙r-J┌`MΣ╝5`3"2rJ└"£n3╟;RdX+Σ`nkΣ"P6 5 5 255
3'≡*                                                   push "≡≡≡" (char 240, 3 times)
    ;╗                                                 save a copy to reg0
      `┘#8╙r-J┌`M                                      map:
       ┘#                                                cp437 char code, as list ([240])
         8╙r-J                                           random value in range(2**8) that is not 240
              ┌                                          char code
                 Σ╝                                    concatenate, push to reg1
                   5`3"2rJ└"£n3╟;RdX+Σ`n               do this 5 times:
                     3"2rJ└"£n                           do this 3 times:
                       2rJ└                                randomly pick 0 or 1, push the value in that register
                              3╟                         push the top 3 items to a list
                                ;RdX+                    duplicate, reverse, discard first value, append (mirror the list)
                                     Σ                   concatenate
                                       kΣ              push stack as list, concatenate
                                         "P6 5 5 255   prepend header
</code>```

ContentLicense: CC BY-SA 3.0

Title: Generate a "GitHub" Avatar

Body:
Actually, 53 bytes

3'≡*;╗`┘#8╙r-J┌`MΣ╝5`3"2rJ└"£n3╟;RdX+Σ`nkΣ"P6 5 5 255

Try it online!

Actually is bad at string processing. I think I've mentioned that before. This program outputs a P6 netpbm image using CP437, like the following:

P6 5 5 255
εεεεεεå♠ƒεεεεεεå♠ƒå♠ƒεεεå♠ƒå♠ƒεεεεεεεεεεεεεεεεεεεεεå♠ƒεεεεεεå♠ƒå♠ƒå♠ƒå♠ƒå♠ƒ

This can be converted to a PNG using ImageMagick:

seriously -f prog.srs | convert - out.png

Scaled up PNG version:

Explanation:

3'≡*;╗`┘#8╙r-J┌`MΣ╝5`3"2rJ└"£n3╟;RdX+Σ`nkΣ"P6 5 5 255
3'≡*                                                   push "≡≡≡" (char 240, 3 times)
    ;╗                                                 save a copy to reg0
      `┘#8╙r-J┌`M                                      map:
       ┘#                                                cp437 char code, as list ([240])
         8╙r-J                                           random value in range(2**8) that is not 240
              ┌                                          char code
                 Σ╝                                    concatenate, push to reg1
                   5`3"2rJ└"£n3╟;RdX+Σ`n               do this 5 times:
                     3"2rJ└"£n                           do this 3 times:
                       2rJ└                                randomly pick 0 or 1, push the value in that register
                              3╟                         push the top 3 items to a list
                                ;RdX+                    duplicate, reverse, discard first value, append (mirror the list)
                                     Σ                   concatenate
                                       kΣ              push stack as list, concatenate
                                         "P6 5 5 255   prepend header


问:
Geobitsian Language
Geobitsian language is a new perversion of English where a word is broken into segments that each must start with a different letter. Then every time one of those starting letters appears in another string, it is replaced with its entire corresponding segment, maintaining capitalization.

This process is called Geobitsizing.

For example the word "Geobits" could be broken into geo bits, and the nonsense poem

```<code>Algy met a Bear
A Bear met Algy
The Bear was bulgy
The bulge was Algy
</code>```

would be Geobitsized with it as

```<code>Algeoy met a Bitsear
A Bitsear met Algeoy
The Bitsear was bitsulgeoy
The bitsulgeoe was Algeoy
</code>```

because every g becomes geo, every G (though there are none) becomes Geo, every b becomes bits, and every B becomes Bits.

Note that each substitution is performed with respect to the original string, not any intermediate step. e.g. if geo had been gbo instead, the b's created would not replaced with bits.

Challenge

Write a program or function that can generate Geobitsian language.

Take in a single-line string made of lowercase letters (a-z) and spaces. This will be the word used as the Geobitsizing argument, with the spaces separating the segments. You can assume:

Segments will not be empty. So spaces will not neighbor each other nor be at the start or end of the string.

Each segment starts with a different letter. Thus there cannot be more than 26.

For example, some valid segmented strings you must support are geo bits, butt ner, alex, and do o r k nob (single letter segments have no effect but are valid). But geo , butt   ner, Alex, and do o r k n ob are invalid.

Your program or function also needs to take in another arbitrary string to apply the Geobitsizing to, and print or return the resulting Geobitsian language.

You can assume this string only contains newlines and printable ASCII.

Remember that letter cases must be preserved from the input to the output.

Here are some more examples using no pro gr am m ing as the Geobitsizing argument:

[empty string] → [empty string]

i → ing

I → Ing

Mmmm, mmm... MmmmMMM: m&m! → Mmmm, mmm... MmmmMMM: m&m! (no change)

People think bananas are great, don't you? → Proeoprole thingnok bamnoamnoams amre grreamt, dono't you?

```<code>Pet a Puppy
Google Wikipedia
</code>```

↓

```<code>Proet am Prouproproy
Groogrle Wingkingproedingam
</code>```

Note that the results should be identical no matter how the argument is arranged, e.g. ing pro m no am gr should yield the same results as above.

The shortest code in bytes wins.

答:
JavaScript ES6, <s>67</s> <s>63</s> 70 bytes

```<code>g=>s=>s.replace(/\S/g,l=>l+(g.match(`\\b\\${l}(\\S+)`,'i')||[,""])[1])
</code>```

Test this on Firefox. bugs are making this longer than I'd like

Explanation

```<code>function(gbarg, str) {
   return str.replace(/\S/g, function(chr) { // Replace non-whitespace w/...
        return chr + (
         gbarg.match(`\\b\\${l}(\\S+)`,'i')  // That word in the gbstr
        ||[,""])[1]                          // if not in gbstr, use blank str
   });
}
</code>```

Title: Geobitsian Language

Body:
JavaScript ES6, <s>67</s> <s>63</s> 70 bytes

g=>s=>s.replace(/\S/g,l=>l+(g.match(`\\b\\${l}(\\S+)`,'i')||[,""])[1])

Test this on Firefox. bugs are making this longer than I'd like

Explanation

function(gbarg, str) {
   return str.replace(/\S/g, function(chr) { // Replace non-whitespace w/...
        return chr + (
         gbarg.match(`\\b\\${l}(\\S+)`,'i')  // That word in the gbstr
        ||[,""])[1]                          // if not in gbstr, use blank str
   });
}


答:
Pyth, 19 bytes

```<code>.rzsC_hMBsm,rd0rd3c
</code>```

Try it online!

Title: Geobitsian Language

Body:
Geobitsian language is a new perversion of English where a word is broken into segments that each must start with a different letter. Then every time one of those starting letters appears in another string, it is replaced with its entire corresponding segment, maintaining capitalization.

This process is called Geobitsizing.

For example the word "Geobits" could be broken into geo bits, and the nonsense poem

```<code>Algy met a Bear
A Bear met Algy
The Bear was bulgy
The bulge was Algy
</code>```

would be Geobitsized with it as

```<code>Algeoy met a Bitsear
A Bitsear met Algeoy
The Bitsear was bitsulgeoy
The bitsulgeoe was Algeoy
</code>```

because every g becomes geo, every G (though there are none) becomes Geo, every b becomes bits, and every B becomes Bits.

Note that each substitution is performed with respect to the original string, not any intermediate step. e.g. if geo had been gbo instead, the b's created would not replaced with bits.

Challenge

Write a program or function that can generate Geobitsian language.

Take in a single-line string made of lowercase letters (a-z) and spaces. This will be the word used as the Geobitsizing argument, with the spaces separating the segments. You can assume:

Segments will not be empty. So spaces will not neighbor each other nor be at the start or end of the string.

Each segment starts with a different letter. Thus there cannot be more than 26.

For example, some valid segmented strings you must support are geo bits, butt ner, alex, and do o r k nob (single letter segments have no effect but are valid). But geo , butt   ner, Alex, and do o r k n ob are invalid.

Your program or function also needs to take in another arbitrary string to apply the Geobitsizing to, and print or return the resulting Geobitsian language.

You can assume this string only contains newlines and printable ASCII.

Remember that letter cases must be preserved from the input to the output.

Here are some more examples using no pro gr am m ing as the Geobitsizing argument:

[empty string] → [empty string]

i → ing

I → Ing

Mmmm, mmm... MmmmMMM: m&m! → Mmmm, mmm... MmmmMMM: m&m! (no change)

People think bananas are great, don't you? → Proeoprole thingnok bamnoamnoams amre grreamt, dono't you?

```<code>Pet a Puppy
Google Wikipedia
</code>```

↓

```<code>Proet am Prouproproy
Groogrle Wingkingproedingam
</code>```

Note that the results should be identical no matter how the argument is arranged, e.g. ing pro m no am gr should yield the same results as above.

The shortest code in bytes wins.

Body:
Pyth, 19 bytes

.rzsC_hMBsm,rd0rd3c

Try it online!


答:
Python, <s>126</s> <s>99</s> <s>95</s> 81 bytes

Alot thanks to Dennis:

```<code>lambda G,S,j=''.join:j(s+j(g[1:]for g in G.split()if g[0]==s.lower())for s in S)
</code>```

Edit1: don't need to append to a temporary

Edit2: S may contain uppercase...

Edit3: don't duplicate G

Edit4: compressed a little bit more and shoved it into one line

Edit5: using unnamed lambda and j=join' '

Title: Geobitsian Language

Body:
Python, <s>126</s> <s>99</s> <s>95</s> 81 bytes

Alot thanks to Dennis:

lambda G,S,j=''.join:j(s+j(g[1:]for g in G.split()if g[0]==s.lower())for s in S)

Edit1: don't need to append to a temporary

Edit2: S may contain uppercase...

Edit3: don't duplicate G

Edit4: compressed a little bit more and shoved it into one line

Edit5: using unnamed lambda and j=join' '


答:
Jelly, 18 bytes

```<code>ṣ⁶;Œu1¦€$;©ZḢiÐ€ị®
</code>```

Try it online!

Alternative version, 15 bytes

Jelly's title case function had a bug; it didn't capitalize the first word. That has been fixed, so the following works now.

```<code>ṣ⁶;Œt$;©ZḢiÐ€ị®
</code>```

This code does the same as in the competing version, except that Œt (title case) replaces the conditional uppercasing achieved by Œu1¦€.

How it works

```<code>ṣ⁶;Œu1¦€$;©ZḢiÐ€ị®  Main link. Left argument: w (words). Right argument: s (string)

ṣ⁶                  Split w at spaces.
        $           Combine the two links to the left into a monadic chain.
       €              Map over the words.
   Œu1¦                 Uppercase the item at index 1.
  ;                   Append the result to the unmodified words.
         ;          Append all characters in s to the list of words.
          ©         Copy the result to the register.
           Z        Zip/transpose, grouping the first chars into the first list.
            Ḣ       Head; extract the list of first characters.
             iÐ€    Find the first index of each character in s.
                ị®  Select the characters/strings from the list in the register
                    that are at those indices.
</code>```

Title: Geobitsian Language

Body:
Jelly, 18 bytes

ṣ⁶;Œu1¦€$;©ZḢiÐ€ị®

Try it online!

Alternative version, 15 bytes

Jelly's title case function had a bug; it didn't capitalize the first word. That has been fixed, so the following works now.

ṣ⁶;Œt$;©ZḢiÐ€ị®

This code does the same as in the competing version, except that Œt (title case) replaces the conditional uppercasing achieved by Œu1¦€.

How it works

ṣ⁶;Œu1¦€$;©ZḢiÐ€ị®  Main link. Left argument: w (words). Right argument: s (string)

ṣ⁶                  Split w at spaces.
        $           Combine the two links to the left into a monadic chain.
       €              Map over the words.
   Œu1¦                 Uppercase the item at index 1.
  ;                   Append the result to the unmodified words.
         ;          Append all characters in s to the list of words.
          ©         Copy the result to the register.
           Z        Zip/transpose, grouping the first chars into the first list.
            Ḣ       Head; extract the list of first characters.
             iÐ€    Find the first index of each character in s.
                ị®  Select the characters/strings from the list in the register
                    that are at those indices.

ContentLicense: CC BY-SA 4.0


答:
Vim, 46 keystrokes

Ugly, and Hacky.

```<code>A <esc>:s/\<\w/:%s\/\0\\c\/\\0/g<cr>:s/ /eg<C-v><Cr>/g<cr>dgg@"
</code>```

Title: Geobitsian Language

Body:
Vim, 46 keystrokes

Ugly, and Hacky.

A <esc>:s/\<\w/:%s\/\0\\c\/\\0/g<cr>:s/ /eg<C-v><Cr>/g<cr>dgg@"


答:
Julia, <s>72</s> 68 bytes

w%s=prod(c->"$c"join((W=w|>split)[find(t->t[1]==c|' ',W)])[2:end],s)
```

Try it online!

Title: Geobitsian Language

Body:
Julia, <s>72</s> 68 bytes

w%s=prod(c->"$c"join((W=w|>split)[find(t->t[1]==c|' ',W)])[2:end],s)

Try it online!


答:
CJam, 19 bytes

```<code>lq\S/_32af.^+_:c\er
</code>```

Test it here.

Explanation

```<code>l       e# Read first line of input (list of words).
q\      e# Read remaining input and swap with first line.
S/      e# Split around spaces.
_       e# Duplicate.
32af.^  e# Convert the first letter of each word to upper case by taking
        e# the element-wise XOR with the list [32].
+       e# Append the upper-cased words to the original ones.
_:c     e# Duplicate and convert each word to its first character.
\       e# Swap characters with words.
er      e# Transliteration, replacing each character with the corresponding word.
</code>```

Title: Geobitsian Language

Body:
CJam, 19 bytes

lq\S/_32af.^+_:c\er

Test it here.

Explanation

l       e# Read first line of input (list of words).
q\      e# Read remaining input and swap with first line.
S/      e# Split around spaces.
_       e# Duplicate.
32af.^  e# Convert the first letter of each word to upper case by taking
        e# the element-wise XOR with the list [32].
+       e# Append the upper-cased words to the original ones.
_:c     e# Duplicate and convert each word to its first character.
\       e# Swap characters with words.
er      e# Transliteration, replacing each character with the corresponding word.


答:
Python 2, <s>83</s> 78 bytes

lambda w,s:''.join(c+w[(' '+w).find(' '+c.lower()):].split()[0][1:]for c in s)
```

Test it on Ideone.

How it works

We iterate over all characters c in the string s.

We prepend a space to the string of words w, then search for a occurrence of lowercased c, preceded by a space.

If such an occurrence exists, find will return the index of the space in the string ' '+w, which matches the index of c in w.

w[...:] thus returns the tail of w, starting from the word with first letter c. split() splits the tail at spaces, [0] selects the first chunk (the word) and [1:] removes its first letter.

After prepending c to the previous result, we obtain the correctly cased word that starts with c.

If no word begins with c, find will return -1.

Thus, w[...:] yields the last character of w, split() wraps it in an array, [0] undoes the wrapping, and [1:] removes the only character from the string.

After prepending c, we obtain the singleton string whose character is c, so the whole operation is a no-op.

Finally, ''.join concatenates all resulting strings, returning the Geobitsized version of s.

Title: Geobitsian Language

Body:
Python 2, <s>83</s> 78 bytes

lambda w,s:''.join(c+w[(' '+w).find(' '+c.lower()):].split()[0][1:]for c in s)

Test it on Ideone.

How it works

We iterate over all characters c in the string s.

We prepend a space to the string of words w, then search for a occurrence of lowercased c, preceded by a space.

If such an occurrence exists, find will return the index of the space in the string ' '+w, which matches the index of c in w.

w[...:] thus returns the tail of w, starting from the word with first letter c. split() splits the tail at spaces, [0] selects the first chunk (the word) and [1:] removes its first letter.

After prepending c to the previous result, we obtain the correctly cased word that starts with c.

If no word begins with c, find will return -1.

Thus, w[...:] yields the last character of w, split() wraps it in an array, [0] undoes the wrapping, and [1:] removes the only character from the string.

After prepending c, we obtain the singleton string whose character is c, so the whole operation is a no-op.

Finally, ''.join concatenates all resulting strings, returning the Geobitsized version of s.


问:
Closest 7-Distinct-Prime Product
(via chat)

The OEIS entry A123321 lists the sequence of numbers that are the product of seven distinct primes. For brevity, we'll call this a 7DP number. The first few numbers and their corresponding divisors are below:

```<code>510510 = 2 * 3 * 5 * 7 * 11 * 13 * 17
570570 = 2 * 3 * 5 * 7 * 11 * 13 * 19
690690 = 2 * 3 * 5 * 7 * 11 * 13 * 23
746130 = 2 * 3 * 5 * 7 * 11 * 17 * 19
</code>```

The challenge here will be to find the closest 7DP number, in terms of absolute distance, from a given input.

Input

A single positive integer n in any convenient format.

Output

The closest 7DP number to n, again in any convenient format. If two 7DP numbers are tied for closest, you can output either or both.

Rules

Numbers can be assumed to fit in your language's default [int] datatype (or equivalent).

Either a full program or a function are acceptable.

Standard loopholes are forbidden.

This is code-golf, so all usual golfing rules apply, and the shortest code wins.

Examples

```<code>5 -> 510510
860782 -> 870870
1425060 -> 1438710 (or 1411410, or both)
</code>```

答:
Pyth, 30 bytes

```<code>L&{IPbq7lPby#.W!syMH,hhZa0teZ,
</code>```

Try it online!

Test suite.

(5 takes too long to run)

Explanation

```<code>L&{IPbq7lPby#.W!syMH,hhZa0teZ,

L&{IPbq7lPb     Defines a function y, whose argument is b:
 &                  Return if both the following are true:
  {IPb                  the prime factorization contains no duplicate; and:
      q7lPb             the number of prime factors is 7

           y#.W!syMH,hhZa0teZ,   The main programme. Input as Q.
                             ,QQ Implicit arguments, yield [Q,Q].
             .W                  While
               !syMH                   both numbers do not satisfy y:
                    ,hhZ             increment the first number
                          teZ        and decrement the second number
                        a0           while making it non-negative.
</code>```

Title: Closest 7-Distinct-Prime Product

Body:
Pyth, 30 bytes

L&{IPbq7lPby#.W!syMH,hhZa0teZ,

Try it online!

Test suite.

(5 takes too long to run)

Explanation

L&{IPbq7lPby#.W!syMH,hhZa0teZ,

L&{IPbq7lPb     Defines a function y, whose argument is b:
 &                  Return if both the following are true:
  {IPb                  the prime factorization contains no duplicate; and:
      q7lPb             the number of prime factors is 7

           y#.W!syMH,hhZa0teZ,   The main programme. Input as Q.
                             ,QQ Implicit arguments, yield [Q,Q].
             .W                  While
               !syMH                   both numbers do not satisfy y:
                    ,hhZ             increment the first number
                          teZ        and decrement the second number
                        a0           while making it non-negative.


问:
Determine the winner of a game of War
The card game War is interesting in that the final outcome is entirely determined by the initial arrangement of the deck, so long as certain rules are followed for the order in which cards are picked up from the playing field and moved to decks. In this challenge, there will only be 2 players, simplifying things greatly.

The Game

Each player is dealt a deck of 26 cards.

Each player places the top card in their deck face-up. The player with the higher-ranking card (Ace > King > Queen > Jack > 10 > 9 > 8 > 7 > 6 > 5 > 4 > 3 > 2) wins the round, and places their card on top of their opponent's card, flips them over, and adds them to the bottom of their deck (so their winning card is on the bottom of the deck, and the other player's losing card is just above it). This is done until one of the players runs out of cards.

If the cards are of equal rank, then each player places the top 2 cards of their deck face-up on top of their previous card (so that the card that was on top of the deck is the second card in the stack, and the card that was second-from-top is on top). Then, the ranks (of the top card of each stack) are compared again, and the winner places their entire stack on top of the loser's entire stack, turns the stack upside-down, and places it on the bottom of their deck. If there is another tie, more cards are played in the same way, until a winner is chosen or one player runs out of cards.

If at any point one of the players needs to draw a card from their deck, but their deck is empty, they immediately lose the game.

The Challenge

Given two lists of cards in the players' decks, in any convenient format, output a truthy value if Player 1 wins, and a falsey value if Player 2 wins.

For convenience, a 10 card will be represented with a T, and face cards will be abbreviated (Ace -> A, King -> K, Queen -> Q, Jack -> J), so that all cards are one character long. Alternatively, ranks may be represented with decimal integers 2-14 (Jack -> 11, Queen -> 12, King -> 13, Ace -> 14) or hex digits 2-E (10 -> A, Jack -> B, Queen -> C, King -> D, Ace -> E). Since suits don't matter, suit information will not be given.

You may assume that all games will terminate at some point (though it may take a very long time), and one player will always run out of cards before the other.

Each player places cards simultaneously, and one card at a time, so there is never any ambiguity about which player ran out of cards first.

Test Cases

The test cases use 23456789ABCDE to represent the ranks (in ascending order).

```<code>D58B35926B92C7C4C7E8D3DAA2, 8E47C38A2DEA43467EB9566B95 -> False
669D9D846D4B3BA52452C2EDEB, E747CA988CC76723935A3B8EA5 -> False
5744B95ECDC6D325B28A782A72, 68394D9DA96EBBA8533EE7C6C4 -> True
87DB6C7EBC6C8D722389923DC6, E28435DBEBEA543AA47956594A -> False
589EAB9DCD43E9EC264A5726A8, 48DC2577BD68AB9335263B7EC4 -> True
E3698D7C46A739AE5BE2C49286, BB54B7D78954ED526A83C3CDA2 -> True
32298B5E785DC394467D5C9CB2, 5ED6AAD93E873EA628B6A4BC47 -> True
B4AB985B34756C624C92DE5E97, 3EDD5BA2A68397C26CE837AD48 -> False
9A6D9A5457BB6ACBC5E8D7D4A9, 73E658CE2C3E289B837422D463 -> True
96E64D226BC8B7D6C5974BAE32, 58DC7A8C543E35978AEBA34D29 -> True
C2978A35E74D7652BA9762C458, 9A9BB332BE8C8DD44CE3DE66A5 -> False
BEDB44E947693CD284923CEA82, 8CC3B75756255A683A6AB9E7DD -> False
EEDDCCBBAA8877665544332299, EEDDCCBBAA9988776655443322 -> False
EEDDCCBBAA9988776655443322, DDCCBBAA9988776655443E3E22 -> True
</code>```

Reference Implementation

This reference implementation is written in Python 3, and takes input in the same format as the test cases (except separated by a newline instead of a comma and a space).

#!/usr/bin/env python3

from collections import deque

p1, p2 = [deque(s) for s in (input(),input())]
print(''.join(p1))
print(''.join(p2))

try:
    while p1 and p2:
        p1s = [p1.popleft()]
        p2s = [p2.popleft()]
        while p1s[-1] == p2s[-1]:
            p1s.append(p1.popleft())
            p2s.append(p2.popleft())
            p1s.append(p1.popleft())
            p2s.append(p2.popleft())
        if p1s[-1] > p2s[-1]:
            p1.extend(p2s+p1s)
        else:
            p2.extend(p1s+p2s)
except IndexError:
    pass
finally:
    print(len(p1) > 0)
```

答:
Python, 261 to 265 bytes

```<code>def f(a,b):
 if a==""or b=="":return b==""
 p=a[0];q=b[0];a=a[1:];b=b[1:]
 if p>q:a+=q+p
 if p<q:b+=p+q
 while p[-1]==q[-1]:
  if len(a)<2 or len(b)<2:return len(b)<2
  v=a[1];w=b[1];p+=a[0:2];q+=b[0:2];a=a[2:];b=b[2:]
  if v>w:a+=q+p
  if v<w:b+=p+q
 return f(a,b)
</code>```

As posted, this is 265 bytes and it works in both Python 2 and Python 3.  You can save 4 bytes in Python 2 by replacing the spaces with a single tab in the while loop.

Try it online

Title: Determine the winner of a game of War

Body:
Python, 261 to 265 bytes

def f(a,b):
 if a==""or b=="":return b==""
 p=a[0];q=b[0];a=a[1:];b=b[1:]
 if p>q:a+=q+p
 if p<q:b+=p+q
 while p[-1]==q[-1]:
  if len(a)<2 or len(b)<2:return len(b)<2
  v=a[1];w=b[1];p+=a[0:2];q+=b[0:2];a=a[2:];b=b[2:]
  if v>w:a+=q+p
  if v<w:b+=p+q
 return f(a,b)

As posted, this is 265 bytes and it works in both Python 2 and Python 3.  You can save 4 bytes in Python 2 by replacing the spaces with a single tab in the while loop.

Try it online


问:
N-chotomize a list
Given a list of integers L, and an integer N, output L splitted in N sublists of equal lenghts.

Non-divisible lengths

If N does not divide the length of L, then it is not possible that all sublists have equal length.

In any case, the last sublist of the output is the one that adapts its length to contain the remainder of the list.

This means that all sublists of L except for the last one should be of length length(L) // N, where // is floored division (e.g. 3//2 = 1).

Some rules

L can be empty.

N >= 1.

You may use any built-in you want.

You may take the input through STDIN, as a function argument, or anything similar.

You may print the output to STDOUT, return it from a function, or anything similar.

You may chose any format for the lists and the integer as long as it is the most natural representation of lists and integers in your language.

Test cases

```<code>Input:  [1,2,3,4], 2
Output: [[1,2],[3,4]]

Input:  [-1,-2,3,4,-5], 2
Output: [[-1,-2],[3,4,-5]]

Input:  [1,2,3,4], 1
Output: [[1,2,3,4]]

Input:  [4,8,15,16,23,42], 5
Output: [[4],[8],[15],[16],[23,42]]

Input:  [4,8,15,16,23,42], 7
Output: [[],[],[],[],[],[],[4,8,15,16,23,42]]

Input:  [2,3,5,7,11,13,17,19,23], 3
Output: [[2,3,5],[7,11,13],[17,19,23]]

Input:  [], 3
Output: [[],[],[]]

Input:  [1,2,3,4,5,6,7,8], 3
Output: [[1,2],[3,4],[5,6,7,8]]
</code>```

Scoring

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

答:
Python, <s>76</s> 73 bytes

```<code>lambda L,N:list(map(lambda x,r=len(L)//N:L[x*r:][:r+(x>N-2)*N],range(N)))
</code>```

Basically an unnamed function that performs the task.
Thanks to LeakyNun for the bytes saved!

Title: N-chotomize a list

Body:
Python, <s>76</s> 73 bytes

lambda L,N:list(map(lambda x,r=len(L)//N:L[x*r:][:r+(x>N-2)*N],range(N)))

Basically an unnamed function that performs the task.
Thanks to LeakyNun for the bytes saved!


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

1 byte thanks to @FryAmTheEggman.

```<code>cJEt*R/lJQ
</code>```

Test suite.

Takes inputs in reversed order.

Sample input:

```<code>5
[1,2,3,4,5,6,7]
</code>```

Sample output:

```<code>[[1], [2], [3], [4], [5, 6, 7]]
</code>```

Explanation

```<code>cJEt*R/lJQ     Main function, first input:Q, second input:E.
cJEt*R/lJQQ    Implicit arguments.

c              The function c is special.
               It can chop arrays.
               If the second argument is a list of integers,
               then it chops the first array at the indices
               specified by the second array.

 JE            The first argument is the second input, stored
               to the variable J.

   t*R/lJQQ    This is the second argument.
      /lJQ     Yield length of J, integer-divided by Q.
    *R    Q    Multiply it to the following respectively:
                   [0,1,2,3,...,Q-1]
   t           Then throw away the first element.
               For example, if Q=3 and E=[1,2,3,4,5,6,7,8],
               we would now have [3,6].
</code>```

Title: N-chotomize a list

Body:
Given a list of integers L, and an integer N, output L splitted in N sublists of equal lenghts.

Non-divisible lengths

If N does not divide the length of L, then it is not possible that all sublists have equal length.

In any case, the last sublist of the output is the one that adapts its length to contain the remainder of the list.

This means that all sublists of L except for the last one should be of length length(L) // N, where // is floored division (e.g. 3//2 = 1).

Some rules

L can be empty.

N >= 1.

You may use any built-in you want.

You may take the input through STDIN, as a function argument, or anything similar.

You may print the output to STDOUT, return it from a function, or anything similar.

You may chose any format for the lists and the integer as long as it is the most natural representation of lists and integers in your language.

Test cases

```<code>Input:  [1,2,3,4], 2
Output: [[1,2],[3,4]]

Input:  [-1,-2,3,4,-5], 2
Output: [[-1,-2],[3,4,-5]]

Input:  [1,2,3,4], 1
Output: [[1,2,3,4]]

Input:  [4,8,15,16,23,42], 5
Output: [[4],[8],[15],[16],[23,42]]

Input:  [4,8,15,16,23,42], 7
Output: [[],[],[],[],[],[],[4,8,15,16,23,42]]

Input:  [2,3,5,7,11,13,17,19,23], 3
Output: [[2,3,5],[7,11,13],[17,19,23]]

Input:  [], 3
Output: [[],[],[]]

Input:  [1,2,3,4,5,6,7,8], 3
Output: [[1,2],[3,4],[5,6,7,8]]
</code>```

Scoring

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

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

1 byte thanks to @FryAmTheEggman.

cJEt*R/lJQ

Test suite.

Takes inputs in reversed order.

Sample input:

5
[1,2,3,4,5,6,7]

Sample output:

[[1], [2], [3], [4], [5, 6, 7]]

Explanation

cJEt*R/lJQ     Main function, first input:Q, second input:E.
cJEt*R/lJQQ    Implicit arguments.

c              The function c is special.
               It can chop arrays.
               If the second argument is a list of integers,
               then it chops the first array at the indices
               specified by the second array.

 JE            The first argument is the second input, stored
               to the variable J.

   t*R/lJQQ    This is the second argument.
      /lJQ     Yield length of J, integer-divided by Q.
    *R    Q    Multiply it to the following respectively:
                   [0,1,2,3,...,Q-1]
   t           Then throw away the first element.
               For example, if Q=3 and E=[1,2,3,4,5,6,7,8],
               we would now have [3,6].


答:
Retina, 36 bytes

Byte count assumes ISO 8859-1 encoding.

```<code>i`(?<=^.*\b\2(\w+)[^·]*?(\w))
$1
A1`
</code>```

Try it online!

Title: Geobitsian Language

Body:
Retina, 36 bytes

Byte count assumes ISO 8859-1 encoding.

i`(?<=^.*\b\2(\w+)[^·]*?(\w))
$1
A1`

Try it online!


答:
JavaScript (ES6), 63 bytes

```<code>(a,n,l=a.length/n|0)=>[...Array(n)].map(_=>--n?a.splice(0,l):a)
</code>```

Title: N-chotomize a list

Body:
JavaScript (ES6), 63 bytes

(a,n,l=a.length/n|0)=>[...Array(n)].map(_=>--n?a.splice(0,l):a)


问:
Image Hide-and-Seek
In this challenge, you need to find a specific pixel within an photograph (taken with a real camera).

You are passed an (R, G, B) tuple and an image, and you need to return a point (x,y) within the image that matches the RGB color given.  The image may have multiple points that match the color; you only need to find 1.

The challenge is that you need to do it while reading as few pixels as possible.  Your score will be total number of pixels read across all test cases.

If you wish, you can read the entire image into an array of RGB values, as long as you don't do any processing on the pixels.  I allow this purely for efficiency purposes.  For example, in Python, list(Image.open("image_name+".jpg").convert("RGB").getdata()) is ok.

Hardcoding locations is not allowed.  Your algorithm should work well for more than just the test cases listed below.  You are not allowed to save data between test cases.  I've chosen RGB values that appear infrequently (<10) in the image (in case that makes a difference for your algorithm).  If you are using randomness in your algorithm, please set a seed, so that your score is constant.

Images can be found on Github

Test cases:

```<code>image_name:
(r, g, b) [all possible answers]

barn:
(143,91,33) [(887,1096),(2226,1397),(2007,1402),(2161,1508),(1187,1702)]
(53,35,59) [(1999,1260)]
(20,24,27) [(1328,1087),(154,1271)]
(167,148,176) [(1748,1204)]
(137,50,7) [(596,1498)]
(116,95,94) [(1340,1123)]
(72,49,59) [(1344,857),(1345,858),(1380,926),(1405,974),(1480,1117)]
(211,163,175) [(1963,745)]
(30,20,0) [(1609,1462),(1133,1477),(1908,1632)]
(88,36,23) [(543,1494),(431,1575)]
daisy:
(21,57,91) [(1440,1935),(2832,2090),(2232,2130),(1877,2131),(1890,2132)]
(201,175,140) [(1537,1749),(2319,1757)]
(169,160,0) [(2124,759)]
(113,123,114) [(1012,994),(2134,1060),(1803,1183),(1119,1335)]
(225,226,231) [(3207,829),(3256,889),(3257,889),(1434,981),(2599,1118),(2656,1348),(2656,1351)]
(17,62,117) [(2514,3874),(2336,3885)]
(226,225,204) [(3209,812)]
(119,124,146) [(2151,974),(2194,1021),(2194,1022),(2202,1034),(2812,1500)]
(2,63,120) [(2165,3881),(2326,3882),(2330,3882),(2228,3887)]
(200,167,113) [(1453,1759)]
dandelion:
(55,2,46) [(667,825),(668,825)]
(95,37,33) [(1637,1721),(1625,1724),(1405,1753),(2026,2276),(2016,2298)]
(27,41,50) [(1267,126),(424,519),(2703,1323),(1804,3466)]
(58,92,129) [(2213,3274)]
(136,159,105) [(1300,2363),(2123,2645),(1429,3428),(1430,3432),(1417,3467),(1393,3490),(1958,3493)]
(152,174,63) [(2256,2556)]
(78,49,19) [(2128,2836)]
(217,178,205) [(2736,3531)]
(69,95,130) [(870,305),(493,460),(2777,1085),(2791,1292),(2634,3100)]
(150,171,174) [(2816,1201),(2724,2669),(1180,2706),(1470,3215),(1471,3215)]
gerbera:
(218,186,171) [(4282,1342)]
(180,153,40) [(4596,1634),(4369,1682),(4390,1708),(4367,1750)]
(201,179,119) [(4282,1876),(4479,1928)]
(116,112,149) [(5884,252),(4168,371),(4169,372),(4164,384),(5742,576)]
(222,176,65) [(4232,1548)]
(108,129,156) [(5341,3574),(5339,3595),(5302,3734)]
(125,99,48) [(4548,1825),(4136,1932),(5054,2013),(5058,2023),(5058,2035),(5055,2050),(5031,2073)]
(170,149,32) [(4461,1630),(4520,1640)]
(156,185,203) [(3809,108)]
(103,67,17) [(4844,1790)]
hot-air:
(48,21,36) [(1992,1029),(2005,1030),(2015,1034),(2018,1036)]
(104,65,36) [(3173,1890),(3163,1893)]
(169,89,62) [(4181,931),(4210,938),(4330,1046),(4171,1056),(3117,1814)]
(68,59,60) [(1872,220),(1874,220),(1878,220),(1696,225),(3785,429)]
(198,96,74) [(4352,1057)]
(136,43,53) [(1700,931)]
(82,42,32) [(4556,961),(4559,973),(4563,989),(4563,990),(4441,1004),(4387,1126),(4378,1128)]
(192,132,72) [(1399,900),(3105,1822),(3104,1824),(3105,1824),(3107,1826),(3107,1827),(3104,1839),(3119,1852)]
(146,21,63) [(1716,993)]
(125,64,36) [(4332,937)]
in-input:
(204,90,1) [(1526,1997),(1385,2145),(4780,2807),(4788,3414)]
(227,163,53) [(1467,1739),(2414,1925),(2441,2198),(134,2446)]
(196,179,135) [(3770,2740),(1110,3012),(3909,3216),(1409,3263),(571,3405)]
(208,59,27) [(1134,1980),(4518,2108),(4515,2142)]
(149,70,1) [(4499,1790),(2416,2042),(1338,2150),(3731,2408),(3722,2409),(4400,3618)]
(168,3,7) [(987,402),(951,432),(1790,1213),(1790,1214),(1848,1217),(4218,1840),(4344,1870),(1511,1898)]
(218,118,4) [(3857,1701),(1442,1980),(1411,2156),(25,2606)]
(127,153,4) [(3710,2813)]
(224,230,246) [(2086,160),(2761,222),(4482,1442)]
(213,127,66) [(4601,1860),(4515,2527),(4757,2863)]
klatschmohn:
(170,133,19) [(1202,2274),(1202,2275),(957,2493),(1034,2633),(3740,3389),(3740,3391),(3683,3439)]
(162,92,4) [(489,2854)]
(159,175,104) [(3095,2475),(3098,2481)]
(199,139,43) [(1956,3055)]
(171,169,170) [(3669,1487),(3674,1490),(3701,1507)]
(184,115,58) [(1958,2404)]
(228,169,5) [(1316,2336),(1317,2336)]
(179,165,43) [(3879,2380),(1842,2497),(1842,2498)]
(67,21,6) [(1959,2197),(2157,2317),(2158,2317),(2158,2318),(2116,2373)]
(213,100,106) [(1303,1816)]
tajinaste-rojo:
(243,56,99) [(1811,2876),(1668,4141),(2089,4518),(1981,4732),(1659,4778),(2221,5373),(1779,5598),(2210,5673),(2373,5860)]
(147,157,210) [(1835,1028),(1431,3358)]
(114,37,19) [(1792,3572),(1818,3592)]
(108,117,116) [(2772,4722),(1269,5672),(2512,5811),(2509,5830),(2186,5842),(2186,5846),(2190,5851),(2211,5884)]
(214,197,93) [(1653,4386)]
(163,102,101) [(2226,2832),(2213,3683),(1894,4091),(1875,4117)]
(192,192,164) [(2175,2962),(2206,3667),(2315,3858),(1561,3977),(3039,5037),(3201,5641)]
(92,118,45) [(1881,1704),(1983,1877),(2254,2126),(3753,5862),(3766,5883)]
(145,180,173) [(1826,1585)]
(181,124,105) [(1969,3892)]
turret-arch:
(116,70,36) [(384,648),(516,669)]
(121,115,119) [(2419,958)]
(183,222,237) [(172,601),(183,601),(110,611),(111,617)]
(237,136,82) [(2020,282),(676,383),(748,406),(854,482),(638,497),(647,661),(1069,838),(1809,895),(1823,911)]
(193,199,215) [(1567,919),(1793,1047)]
(33,30,25) [(1307,861),(309,885),(1995,895),(504,1232),(2417,1494)]
(17,23,39) [(1745,1033),(788,1090),(967,1250)]
(192,139,95) [(1445,1337)]
(176,125,98) [(1197,1030)]
(178,83,0) [(2378,1136)]
water-lilies:
(86,140,80) [(2322,2855),(4542,3005),(4540,3006),(4577,3019)]
(218,124,174) [(1910,2457)]
(191,77,50) [(2076,1588)]
(197,211,186) [(4402,1894)]
(236,199,181) [(2154,1836)]
(253,242,162) [(1653,1430)]
(114,111,92) [(1936,2499)]
(111,93,27) [(2301,2423),(2127,2592),(2137,2717),(2147,2717)]
(139,92,102) [(1284,2243),(1297,2258)]
(199,157,117) [(3096,993)]
</code>```

答:
Python, score: 396,250,646

While there are no PNGs to parse and there are still problems with the testcases, I decided to program anyway.

Those testcases where the value is not present in the image were ignored (checked against a traditional linear search, which had a score of 544,017,431)

```<code>from PIL import Image

def dist(x,y):
 d = 0
 for i in range(3):
  d += (x[i]-y[i])**2
 return d

def mid(x,y):
 return (x+y)/2

class Finder:
 def __init__(self, image_name, c):
  self.image_name = image_name,
  self.c = c
  self.found = False
  self.position = None
  self.im = Image.open(image_name+".jpg").convert("RGB")
  self.L = self.im.load()
  self.visited = set()

 def quadsearch(self,x0,x1,y0,y1):
  if x0==x1 and y0==y1: return
  xm=mid(x0,x1)
  ym=mid(y0,y1)
  R = [
   (x0,xm,y0,ym),
   (xm,x1,y0,ym),
   (x0,xm,ym,y1),
   (xm,x1,ym,y1),
   ]
  P = [(mid(t[0],t[1]), mid(t[2],t[3])) for t in R]
  DR = []
  for i in range(len(P)):
   p = P[i]
   if p in self.visited: continue
   self.visited.add(p)
   u = self.L[p[0], p[1]]
   d = dist(u, self.c)
   if d == 0:
    self.found = True
    self.position = (p[0], p[1])
    return
   DR.append((d,R[i]))
  S = sorted(range(len(DR)), key=lambda k: DR[k][0])
  for i in S:
   if self.found == True: return
   r = DR[i][1]
   self.quadsearch(r[0], r[1], r[2], r[3])

 def start(self):
  sx,sy = self.im.size
  self.quadsearch(0,sx,0,sy)

 def result(self):
  if self.found:
   count = len(self.visited)
   sx,sy = self.im.size
   ratio = float(count)/(sx*sy)
   print len(self.visited), ratio, self.position, self.L[self.position[0], self.position[1]], "=", self.c
  else:
   print self.c, "not found"

if __name__ == "__main__":
 image_name="turret-arch"
 c=(116,70,36)
 F = Finder(image_name, c)
 F.start()
 F.result()
</code>```

It is a recursive quad-section search. Sometimes it finds the correct value in a few percent, sometimes over 75%. Here are the results for all testcases:

pixels_visited, percentage, (position) (RGB at position) = (RGB searched)

```<code>tajinaste-rojo
1500765 0.062531875 (2329, 5146) (243, 56, 99) = (243, 56, 99)
(147, 157, 210) not found
335106 0.01396275 (2116, 5791) (114, 37, 19) = (114, 37, 19)
1770396 0.0737665 (1269, 5672) (108, 117, 116) = (108, 117, 116)
(214, 197, 93) not found
8086276 0.336928166667 (1546, 4867) (163, 102, 101) = (163, 102, 101)
12859 0.000535791666667 (1476, 4803) (192, 192, 164) = (192, 192, 164)
7505961 0.312748375 (3766, 5883) (92, 118, 45) = (92, 118, 45)
15057489 0.627395375 (1871, 1139) (145, 180, 173) = (145, 180, 173)
(181, 124, 105) not found
in-input
35754 0.00201500551852 (4695, 2559) (204, 90, 1) = (204, 90, 1)
5029615 0.283456451895 (10, 2680) (227, 163, 53) = (227, 163, 53)
6986547 0.393744217722 (1383, 3446) (196, 179, 135) = (196, 179, 135)
1608341 0.090642053775 (4518, 2108) (208, 59, 27) = (208, 59, 27)
581774 0.0327873194757 (3750, 2798) (149, 70, 1) = (149, 70, 1)
1302581 0.0734101891628 (4374, 1941) (168, 3, 7) = (168, 3, 7)
6134761 0.345739701008 (25, 2606) (218, 118, 4) = (218, 118, 4)
(127, 153, 4) not found
9760033 0.550050913352 (4482, 1442) (224, 230, 246) = (224, 230, 246)
212816 0.0119937745268 (4701, 2579) (213, 127, 66) = (213, 127, 66)
water-lilies
5649260 0.390767412093 (4577, 3019) (86, 140, 80) = (86, 140, 80)
12600699 0.871608412215 (1910, 2457) (218, 124, 174) = (218, 124, 174)
(191, 77, 50) not found
3390653 0.234536328318 (4402, 1894) (197, 211, 186) = (197, 211, 186)
(236, 199, 181) not found
7060220 0.488365537823 (1672, 1379) (253, 242, 162) = (253, 242, 162)
(114, 111, 92) not found
6852380 0.473988947097 (2147, 2717) (111, 93, 27) = (111, 93, 27)
(139, 92, 102) not found
14105709 0.975712111261 (3096, 993) (199, 157, 117) = (199, 157, 117)
dandelion
(55, 2, 46) not found
9094264 0.619162854031 (1637, 1721) (95, 37, 33) = (95, 37, 33)
2358912 0.16060130719 (1526, 3129) (27, 41, 50) = (27, 41, 50)
11729837 0.798600013617 (1905, 756) (58, 92, 129) = (58, 92, 129)
6697060 0.455954520697 (2246, 2685) (136, 159, 105) = (136, 159, 105)
6429635 0.437747480937 (2148, 2722) (152, 174, 63) = (152, 174, 63)
(78, 49, 19) not found
(217, 178, 205) not found
80727 0.00549611928105 (2481, 3133) (69, 95, 130) = (69, 95, 130)
239962 0.0163372821351 (2660, 917) (150, 171, 174) = (150, 171, 174)
turret-arch
210562 0.0467313240712 (725, 655) (116, 70, 36) = (116, 70, 36)
(121, 115, 119) not found
2548703 0.565649385237 (140, 604) (183, 222, 237) = (183, 222, 237)
150733 0.033453104887 (2165, 601) (237, 136, 82) = (237, 136, 82)
3458188 0.767497003862 (2259, 953) (193, 199, 215) = (193, 199, 215)
2430256 0.539361711572 (265, 1222) (33, 30, 25) = (33, 30, 25)
638995 0.141816103689 (1778, 1062) (17, 23, 39) = (17, 23, 39)
2506522 0.556287895601 (1127, 970) (192, 139, 95) = (192, 139, 95)
1344400 0.298370988504 (147, 734) (176, 125, 98) = (176, 125, 98)
(178, 83, 0) not found
hot-air
17474837 0.875411434688 (1992, 1029) (48, 21, 36) = (48, 21, 36)
1170064 0.0586149905099 (3191, 1846) (104, 65, 36) = (104, 65, 36)
(169, 89, 62) not found
11891624 0.595717352134 (3948, 470) (68, 59, 60) = (68, 59, 60)
(198, 96, 74) not found
(136, 43, 53) not found
12476811 0.625032612198 (4387, 1126) (82, 42, 32) = (82, 42, 32)
4757856 0.238347376116 (3105, 1822) (192, 132, 72) = (192, 132, 72)
(146, 21, 63) not found
(125, 64, 36) not found
daisy
5322196 0.220287235367 (2171, 2128) (21, 57, 91) = (21, 57, 91)
(201, 175, 140) not found
22414990 0.9277629343 (2124, 759) (169, 160, 0) = (169, 160, 0)
20887184 0.864526601043 (1119, 1335) (113, 123, 114) = (113, 123, 114)
595712 0.0246566923794 (2656, 1349) (225, 226, 231) = (225, 226, 231)
3397561 0.140626034757 (2514, 3874) (17, 62, 117) = (17, 62, 117)
201068 0.00832226281046 (1978, 1179) (226, 225, 204) = (226, 225, 204)
18693250 0.773719036752 (2357, 917) (119, 124, 146) = (119, 124, 146)
3091040 0.127939041706 (2165, 3881) (2, 63, 120) = (2, 63, 120)
3567932 0.147677739839 (1453, 1759) (200, 167, 113) = (200, 167, 113)
barn
314215 0.0697356740202 (784, 1065) (143, 91, 33) = (143, 91, 33)
2448863 0.543491277908 (1999, 1260) (53, 35, 59) = (53, 35, 59)
(20, 24, 27) not found
(167, 148, 176) not found
(137, 50, 7) not found
(116, 95, 94) not found
2042891 0.453391406631 (1345, 858) (72, 49, 59) = (72, 49, 59)
(211, 163, 175) not found
(30, 20, 0) not found
(88, 36, 23) not found
klatschmohn
3048249 0.191409829222 (3683, 3439) (170, 133, 19) = (170, 133, 19)
1057649 0.0664133456509 (489, 2854) (162, 92, 4) = (162, 92, 4)
2058022 0.129230138206 (3095, 2475) (159, 175, 104) = (159, 175, 104)
(199, 139, 43) not found
2060805 0.129404892156 (3674, 1490) (171, 169, 170) = (171, 169, 170)
7725501 0.485110247577 (1958, 2404) (184, 115, 58) = (184, 115, 58)
2986734 0.187547095028 (1316, 2336) (228, 169, 5) = (228, 169, 5)
497709 0.0312528257017 (3879, 2379) (179, 165, 43) = (179, 165, 43)
3996978 0.250983720944 (2157, 2318) (67, 21, 6) = (67, 21, 6)
3332106 0.209234167028 (1303, 1816) (213, 100, 106) = (213, 100, 106)
gerbera
(218, 186, 171) not found
9445576 0.390955128952 (4377, 1750) (180, 153, 40) = (180, 153, 40)
(201, 179, 119) not found
6140398 0.254152853347 (5742, 576) (116, 112, 149) = (116, 112, 149)
6500717 0.269066561215 (4233, 1541) (222, 176, 65) = (222, 176, 65)
13307056 0.550782905612 (5302, 3734) (108, 129, 156) = (108, 129, 156)
13808847 0.571552180573 (5058, 2023) (125, 99, 48) = (125, 99, 48)
9454870 0.391339810307 (4478, 1647) (170, 149, 32) = (170, 149, 32)
2733978 0.113160142012 (4096, 368) (156, 185, 203) = (156, 185, 203)
11848606 0.490417237301 (4844, 1790) (103, 67, 17) = (103, 67, 17)
</code>```

Title: Image Hide-and-Seek

Body:
Python, score: 396,250,646

While there are no PNGs to parse and there are still problems with the testcases, I decided to program anyway.

Those testcases where the value is not present in the image were ignored (checked against a traditional linear search, which had a score of 544,017,431)

from PIL import Image

def dist(x,y):
 d = 0
 for i in range(3):
  d += (x[i]-y[i])**2
 return d

def mid(x,y):
 return (x+y)/2

class Finder:
 def __init__(self, image_name, c):
  self.image_name = image_name,
  self.c = c
  self.found = False
  self.position = None
  self.im = Image.open(image_name+".jpg").convert("RGB")
  self.L = self.im.load()
  self.visited = set()

 def quadsearch(self,x0,x1,y0,y1):
  if x0==x1 and y0==y1: return
  xm=mid(x0,x1)
  ym=mid(y0,y1)
  R = [
   (x0,xm,y0,ym),
   (xm,x1,y0,ym),
   (x0,xm,ym,y1),
   (xm,x1,ym,y1),
   ]
  P = [(mid(t[0],t[1]), mid(t[2],t[3])) for t in R]
  DR = []
  for i in range(len(P)):
   p = P[i]
   if p in self.visited: continue
   self.visited.add(p)
   u = self.L[p[0], p[1]]
   d = dist(u, self.c)
   if d == 0:
    self.found = True
    self.position = (p[0], p[1])
    return
   DR.append((d,R[i]))
  S = sorted(range(len(DR)), key=lambda k: DR[k][0])
  for i in S:
   if self.found == True: return
   r = DR[i][1]
   self.quadsearch(r[0], r[1], r[2], r[3])

 def start(self):
  sx,sy = self.im.size
  self.quadsearch(0,sx,0,sy)

 def result(self):
  if self.found:
   count = len(self.visited)
   sx,sy = self.im.size
   ratio = float(count)/(sx*sy)
   print len(self.visited), ratio, self.position, self.L[self.position[0], self.position[1]], "=", self.c
  else:
   print self.c, "not found"

if __name__ == "__main__":
 image_name="turret-arch"
 c=(116,70,36)
 F = Finder(image_name, c)
 F.start()
 F.result()

It is a recursive quad-section search. Sometimes it finds the correct value in a few percent, sometimes over 75%. Here are the results for all testcases:

pixels_visited, percentage, (position) (RGB at position) = (RGB searched)

tajinaste-rojo
1500765 0.062531875 (2329, 5146) (243, 56, 99) = (243, 56, 99)
(147, 157, 210) not found
335106 0.01396275 (2116, 5791) (114, 37, 19) = (114, 37, 19)
1770396 0.0737665 (1269, 5672) (108, 117, 116) = (108, 117, 116)
(214, 197, 93) not found
8086276 0.336928166667 (1546, 4867) (163, 102, 101) = (163, 102, 101)
12859 0.000535791666667 (1476, 4803) (192, 192, 164) = (192, 192, 164)
7505961 0.312748375 (3766, 5883) (92, 118, 45) = (92, 118, 45)
15057489 0.627395375 (1871, 1139) (145, 180, 173) = (145, 180, 173)
(181, 124, 105) not found
in-input
35754 0.00201500551852 (4695, 2559) (204, 90, 1) = (204, 90, 1)
5029615 0.283456451895 (10, 2680) (227, 163, 53) = (227, 163, 53)
6986547 0.393744217722 (1383, 3446) (196, 179, 135) = (196, 179, 135)
1608341 0.090642053775 (4518, 2108) (208, 59, 27) = (208, 59, 27)
581774 0.0327873194757 (3750, 2798) (149, 70, 1) = (149, 70, 1)
1302581 0.0734101891628 (4374, 1941) (168, 3, 7) = (168, 3, 7)
6134761 0.345739701008 (25, 2606) (218, 118, 4) = (218, 118, 4)
(127, 153, 4) not found
9760033 0.550050913352 (4482, 1442) (224, 230, 246) = (224, 230, 246)
212816 0.0119937745268 (4701, 2579) (213, 127, 66) = (213, 127, 66)
water-lilies
5649260 0.390767412093 (4577, 3019) (86, 140, 80) = (86, 140, 80)
12600699 0.871608412215 (1910, 2457) (218, 124, 174) = (218, 124, 174)
(191, 77, 50) not found
3390653 0.234536328318 (4402, 1894) (197, 211, 186) = (197, 211, 186)
(236, 199, 181) not found
7060220 0.488365537823 (1672, 1379) (253, 242, 162) = (253, 242, 162)
(114, 111, 92) not found
6852380 0.473988947097 (2147, 2717) (111, 93, 27) = (111, 93, 27)
(139, 92, 102) not found
14105709 0.975712111261 (3096, 993) (199, 157, 117) = (199, 157, 117)
dandelion
(55, 2, 46) not found
9094264 0.619162854031 (1637, 1721) (95, 37, 33) = (95, 37, 33)
2358912 0.16060130719 (1526, 3129) (27, 41, 50) = (27, 41, 50)
11729837 0.798600013617 (1905, 756) (58, 92, 129) = (58, 92, 129)
6697060 0.455954520697 (2246, 2685) (136, 159, 105) = (136, 159, 105)
6429635 0.437747480937 (2148, 2722) (152, 174, 63) = (152, 174, 63)
(78, 49, 19) not found
(217, 178, 205) not found
80727 0.00549611928105 (2481, 3133) (69, 95, 130) = (69, 95, 130)
239962 0.0163372821351 (2660, 917) (150, 171, 174) = (150, 171, 174)
turret-arch
210562 0.0467313240712 (725, 655) (116, 70, 36) = (116, 70, 36)
(121, 115, 119) not found
2548703 0.565649385237 (140, 604) (183, 222, 237) = (183, 222, 237)
150733 0.033453104887 (2165, 601) (237, 136, 82) = (237, 136, 82)
3458188 0.767497003862 (2259, 953) (193, 199, 215) = (193, 199, 215)
2430256 0.539361711572 (265, 1222) (33, 30, 25) = (33, 30, 25)
638995 0.141816103689 (1778, 1062) (17, 23, 39) = (17, 23, 39)
2506522 0.556287895601 (1127, 970) (192, 139, 95) = (192, 139, 95)
1344400 0.298370988504 (147, 734) (176, 125, 98) = (176, 125, 98)
(178, 83, 0) not found
hot-air
17474837 0.875411434688 (1992, 1029) (48, 21, 36) = (48, 21, 36)
1170064 0.0586149905099 (3191, 1846) (104, 65, 36) = (104, 65, 36)
(169, 89, 62) not found
11891624 0.595717352134 (3948, 470) (68, 59, 60) = (68, 59, 60)
(198, 96, 74) not found
(136, 43, 53) not found
12476811 0.625032612198 (4387, 1126) (82, 42, 32) = (82, 42, 32)
4757856 0.238347376116 (3105, 1822) (192, 132, 72) = (192, 132, 72)
(146, 21, 63) not found
(125, 64, 36) not found
daisy
5322196 0.220287235367 (2171, 2128) (21, 57, 91) = (21, 57, 91)
(201, 175, 140) not found
22414990 0.9277629343 (2124, 759) (169, 160, 0) = (169, 160, 0)
20887184 0.864526601043 (1119, 1335) (113, 123, 114) = (113, 123, 114)
595712 0.0246566923794 (2656, 1349) (225, 226, 231) = (225, 226, 231)
3397561 0.140626034757 (2514, 3874) (17, 62, 117) = (17, 62, 117)
201068 0.00832226281046 (1978, 1179) (226, 225, 204) = (226, 225, 204)
18693250 0.773719036752 (2357, 917) (119, 124, 146) = (119, 124, 146)
3091040 0.127939041706 (2165, 3881) (2, 63, 120) = (2, 63, 120)
3567932 0.147677739839 (1453, 1759) (200, 167, 113) = (200, 167, 113)
barn
314215 0.0697356740202 (784, 1065) (143, 91, 33) = (143, 91, 33)
2448863 0.543491277908 (1999, 1260) (53, 35, 59) = (53, 35, 59)
(20, 24, 27) not found
(167, 148, 176) not found
(137, 50, 7) not found
(116, 95, 94) not found
2042891 0.453391406631 (1345, 858) (72, 49, 59) = (72, 49, 59)
(211, 163, 175) not found
(30, 20, 0) not found
(88, 36, 23) not found
klatschmohn
3048249 0.191409829222 (3683, 3439) (170, 133, 19) = (170, 133, 19)
1057649 0.0664133456509 (489, 2854) (162, 92, 4) = (162, 92, 4)
2058022 0.129230138206 (3095, 2475) (159, 175, 104) = (159, 175, 104)
(199, 139, 43) not found
2060805 0.129404892156 (3674, 1490) (171, 169, 170) = (171, 169, 170)
7725501 0.485110247577 (1958, 2404) (184, 115, 58) = (184, 115, 58)
2986734 0.187547095028 (1316, 2336) (228, 169, 5) = (228, 169, 5)
497709 0.0312528257017 (3879, 2379) (179, 165, 43) = (179, 165, 43)
3996978 0.250983720944 (2157, 2318) (67, 21, 6) = (67, 21, 6)
3332106 0.209234167028 (1303, 1816) (213, 100, 106) = (213, 100, 106)
gerbera
(218, 186, 171) not found
9445576 0.390955128952 (4377, 1750) (180, 153, 40) = (180, 153, 40)
(201, 179, 119) not found
6140398 0.254152853347 (5742, 576) (116, 112, 149) = (116, 112, 149)
6500717 0.269066561215 (4233, 1541) (222, 176, 65) = (222, 176, 65)
13307056 0.550782905612 (5302, 3734) (108, 129, 156) = (108, 129, 156)
13808847 0.571552180573 (5058, 2023) (125, 99, 48) = (125, 99, 48)
9454870 0.391339810307 (4478, 1647) (170, 149, 32) = (170, 149, 32)
2733978 0.113160142012 (4096, 368) (156, 185, 203) = (156, 185, 203)
11848606 0.490417237301 (4844, 1790) (103, 67, 17) = (103, 67, 17)


答:
Pyth, 18 16

```<code>MsXGhMJcjdrBH3)J
</code>```

Try it here

Defines a function g that performs the geobitsising. As a program this would be a bit shorter if the second string is single line, but multiline input isn't worth it:

```<code>sXwhMJcjdrBz3)J
</code>```

The general idea here was to title case the geobitsian string and append that to the original string. Then split that on spaces and for each string, take the first letter and map it to the string it represents. That way X will turn the first letter of each word into the full word.

Title: Geobitsian Language

Body:
Pyth, 18 16

MsXGhMJcjdrBH3)J

Try it here

Defines a function g that performs the geobitsising. As a program this would be a bit shorter if the second string is single line, but multiline input isn't worth it:

sXwhMJcjdrBz3)J

The general idea here was to title case the geobitsian string and append that to the original string. Then split that on spaces and for each string, take the first letter and map it to the string it represents. That way X will turn the first letter of each word into the full word.


答:
F#, <s>100</s> 98 bytes

```<code>fun n l->
let a=List.length l/n
List.init n (fun i->if i<n-1 then l.[a*i..a*i+a-1] else l.[a*i..])
</code>```

Using F# list slicing, with an if clause deciding whether to pick a elements or all remaining elements.

Title: N-chotomize a list

Body:
F#, <s>100</s> 98 bytes

fun n l->
let a=List.length l/n
List.init n (fun i->if i<n-1 then l.[a*i..a*i+a-1] else l.[a*i..])

Using F# list slicing, with an if clause deciding whether to pick a elements or all remaining elements.


答:
PowerShell v2+, 125 bytes

```<code>param($l,$n)if($p=[math]::Floor(($c=$l.count)/$n)){1..$n|%{$l[(($_-1)*$p)..((($_*$p-1),$c)[!($_-$n)])]}}else{(,''*($n-1))+$l}
</code>```

Feels too long, but I can't seem to come up with a way to get the slicing to work happily if there are empty arrays in the output, so I need the encapsulating if/else to handle those cases. Additionally, since PowerShell's default .ToString() for arrays via console output can look a little weird, you can tack on a -join',' to show the arrays as comma-separated rather than newline-separated on the console. I've done that in the examples below to make the output more clear, but you won't want to do that if you're leaving the output on the pipeline for another command to pick up.

Explanation

Takes input param($l,$n) for the list and number of partitions, respectively. We then enter an if/else statement. If the size of each partition, $p is non-zero (setting helper $c to be the .count along the way), we're in the if.

Inside the if, we loop from 1 to $n with |%{...}, and each iteration we're doing a pretty complex-looking array slice $l[(($_-1)*$p)..((($_*$p-1),$c)[!($_-$n)])]. The first parens is our start index, based on what partition we're on and how big our partition size is. We range that .. with our end index, which is formed from a pseudo-ternary. Here, we're choosing between either $c (the literal end of the array), or the length of our partition, based on whether we're in the last chunk $_-$n or not.

Otherwise, we're in the else. We construct an empty array with the comma-operator ,''* equal to one fewer partitions than requested, and then tack on the input array as the final element.

Examples

Here I'm showing the partitions separated with newlines and each individual element separated with ,, as described above.

```<code>PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (1,2,3,4) 2
1,2
3,4

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (-1,-2,3,4,-5) 2
-1,-2
3,4,-5

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (1,2,3,4) 1
1,2,3,4

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (4,8,15,16,23,42) 5
4
8
15
16
23,42

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (4,8,15,16,23,42) 7

4,8,15,16,23,42

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (2,3,5,7,11,13,17,19,23) 3
2,3,5
7,11,13
17,19,23

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 $null 3

PS C:\Tools\Scripts\golfing>
</code>```

Title: N-chotomize a list

Body:
PowerShell v2+, 125 bytes

param($l,$n)if($p=[math]::Floor(($c=$l.count)/$n)){1..$n|%{$l[(($_-1)*$p)..((($_*$p-1),$c)[!($_-$n)])]}}else{(,''*($n-1))+$l}

Feels too long, but I can't seem to come up with a way to get the slicing to work happily if there are empty arrays in the output, so I need the encapsulating if/else to handle those cases. Additionally, since PowerShell's default .ToString() for arrays via console output can look a little weird, you can tack on a -join',' to show the arrays as comma-separated rather than newline-separated on the console. I've done that in the examples below to make the output more clear, but you won't want to do that if you're leaving the output on the pipeline for another command to pick up.

Explanation

Takes input param($l,$n) for the list and number of partitions, respectively. We then enter an if/else statement. If the size of each partition, $p is non-zero (setting helper $c to be the .count along the way), we're in the if.

Inside the if, we loop from 1 to $n with |%{...}, and each iteration we're doing a pretty complex-looking array slice $l[(($_-1)*$p)..((($_*$p-1),$c)[!($_-$n)])]. The first parens is our start index, based on what partition we're on and how big our partition size is. We range that .. with our end index, which is formed from a pseudo-ternary. Here, we're choosing between either $c (the literal end of the array), or the length of our partition, based on whether we're in the last chunk $_-$n or not.

Otherwise, we're in the else. We construct an empty array with the comma-operator ,''* equal to one fewer partitions than requested, and then tack on the input array as the final element.

Examples

Here I'm showing the partitions separated with newlines and each individual element separated with ,, as described above.

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (1,2,3,4) 2
1,2
3,4

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (-1,-2,3,4,-5) 2
-1,-2
3,4,-5

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (1,2,3,4) 1
1,2,3,4

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (4,8,15,16,23,42) 5
4
8
15
16
23,42

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (4,8,15,16,23,42) 7

4,8,15,16,23,42

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 (2,3,5,7,11,13,17,19,23) 3
2,3,5
7,11,13
17,19,23

PS C:\Tools\Scripts\golfing> .\n-chotomize-a-list.ps1 $null 3

PS C:\Tools\Scripts\golfing>


答:
Common Lisp, 114 bytes

```<code>(defun f(l n &optional(p(floor(length l)n))(i 1))(if(= i n)(list l)(cons(subseq l 0 p)(f(subseq l p)n p(+ i 1)))))
</code>```

Ungolfed:

```<code>(defun f (l n &optional (p (floor (length l) n)) (i 1))
  (if (= i n) (list l)
              (cons (subseq l 0 p)
                    (f (subseq l p) n p (+ i 1))))
  )
</code>```

Example call:

```<code>(format t "~A~C~C" (f (read) (read)) #\return #\newline)
</code>```

Try it here!

Basically:

If we are cutting the last group, return whatever's left of the initial list.

Otherwise take p = |L| / N elements out of the list and join that to the result of a recursive call on the remainder. i is an iteration counter used for the stop condition.

I had misunderstood the challenge at first, thinking the program should build groups of N elements rather than N groups. Anyway, this version does the job for an extra 10 bytes. LisP won't win this time but I couldn't really miss the opportunity :')

Title: N-chotomize a list

Body:
Common Lisp, 114 bytes

(defun f(l n &optional(p(floor(length l)n))(i 1))(if(= i n)(list l)(cons(subseq l 0 p)(f(subseq l p)n p(+ i 1)))))

Ungolfed:

(defun f (l n &optional (p (floor (length l) n)) (i 1))
  (if (= i n) (list l)
              (cons (subseq l 0 p)
                    (f (subseq l p) n p (+ i 1))))
  )

Example call:

(format t "~A~C~C" (f (read) (read)) #\return #\newline)

Try it here!

Basically:

If we are cutting the last group, return whatever's left of the initial list.

Otherwise take p = |L| / N elements out of the list and join that to the result of a recursive call on the remainder. i is an iteration counter used for the stop condition.

I had misunderstood the challenge at first, thinking the program should build groups of N elements rather than N groups. Anyway, this version does the job for an extra 10 bytes. LisP won't win this time but I couldn't really miss the opportunity :')


问:
Partition of a positive integer N
Find the number of partitions of a positive integer n. Hope someone uses the explicit finite formula for the partition function defined in Jan Hendrik Brunier and Ken Ono paper here.

```<code>Sample Input
8
Sample Output
22
</code>```

N is less than or equal to 1000.
Write the complete program. More than anything I would like to see the different approaches.

ContentLicense: CC BY-SA 2.5

Title: Partition of a positive integer N

Body:
Python (109 89)

n=input()
s=0
l=[(n,n)]
while l:a,i=l.pop(0);s+=a==0;l+=[(a-i,i),(a,i-1)]*(a*i>0)
print s


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

The factorial, represented with ! is defined as such

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

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

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

Requirements:

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

Can calculate factorials for numbers up to 125

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

Completes in under a minute for numbers up to 125

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

答:
JavaScript ES6, <s>19</s> 17 bytes

```<code>f=n=>n?n*f(n-1):1
</code>```

Saved two bytes by changing the conditional to n instead of n>1, because they are effectively equal.

Ungolfed

```<code>var factorial = function(n) {
  if (n > 1) {
    return f(n-1)*n;
  } else {
    return 1;
  }
}
</code>```

Works just like a standard factorial. Defines a function f which multiplies it's input n by f(n-1). If n is equal to 0 or 1, then the function returns 1.

See it in Action

Check it out on JSFiddle!

Title: Find the Factorial!

Body:
JavaScript ES6, <s>19</s> 17 bytes

f=n=>n?n*f(n-1):1

Saved two bytes by changing the conditional to n instead of n>1, because they are effectively equal.

Ungolfed

var factorial = function(n) {
  if (n > 1) {
    return f(n-1)*n;
  } else {
    return 1;
  }
}

Works just like a standard factorial. Defines a function f which multiplies it's input n by f(n-1). If n is equal to 0 or 1, then the function returns 1.

See it in Action

Check it out on JSFiddle!


答:
Desmos, 18 bytes

```<code>a=1
\prod _{n=1}^an
</code>```

Uses the formula for a! instead of a!

Title: Find the Factorial!

Body:
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

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

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

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

Requirements:

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

Can calculate factorials for numbers up to 125

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

Completes in under a minute for numbers up to 125

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

Body:
Desmos, 18 bytes

a=1
\prod _{n=1}^an

Uses the formula for a! instead of a!


答:
Haskell, <s>69</s> 67 bytes

```<code>a%b=a#b where l#1=[l];l#n|(h,t)<-splitAt(div(length a)b)l=h:t#(n-1)
</code>```

Usage example: [1,2,3,4] % 3 -> [[1],[2],[3,4]].

A simple recursive approach, similar to @xnor's answer.

Edit: @Will Ness saved 2 bytes. Thanks!

Title: N-chotomize a list

Body:
Haskell, <s>69</s> 67 bytes

a%b=a#b where l#1=[l];l#n|(h,t)<-splitAt(div(length a)b)l=h:t#(n-1)

Usage example: [1,2,3,4] % 3 -> [[1],[2],[3,4]].

A simple recursive approach, similar to @xnor's answer.

Edit: @Will Ness saved 2 bytes. Thanks!


问:
How's your string theory?
Back to the basics! You're in you comp sci class again, except wiser and golfier. You have the tools, you have the power… but do you have the skill? Probably.

Crash Course for the non-Computer Scientist (skip if you don't need it)

A string is symbolically represented by an arbitrary letter (usually, for our purposes, will be  etc. Of course, we know a string as something like "Hello, World!" or 'Hello, World!', or, if you're the snarky Python user, """Hello, World!""".

An alphabet can be thought of as a set (i.e. no repeating characters) of symbols, of which strings can be made. For example, ; this is the binary alphabet, of which contains strings like  and .  These strings can said to be strings over , or, alternatively, .

The length of any string is denoted . For example, .

There is the empty or null string , which is equivalent to "". It is a valid string in over any alphabet. In other words,  is the unique string satisfying the property .

The set  is the set of all strings  over  for which .

The set  is called the Kleene closure of , and is the set of all strings over . This can be considered the language of .

The concatenation of two strings  and  is denoted , and is the string containing the characters of  followed by the characters of .

 is said to be a prefix of  if there is some string  that satisfies the equality . (If , then  is said to be a proper prefix of .)

The alphabet of a string  is denoted , and is the minimal alphabet  so that  is a string over

The projection of a string  relative to an alphabet  is defined as

and is essentially the removal of all characters in  not in .

TL;DR

Objective Write a program, series of functions, series of programs etc. that can calculate as many of the following tasks as possible:

(1) Calculate, given a string s, its length.

(2) Arrive at, given a string s and an alphabet Σ, whether or not (output a truthy/falsy value) that string is over said alphabet.

(1) Given an alphabet, arrive at whether or not (output a truthy/falsy value) the alphabet is valid (a valid alphabet can have no repeating characters, but is otherwise valid).

(4) Given an alphabet Σ and a positive integer n, display .

(6) Given an alphabet Σ and an integer n, display the first n entries in  (Remember that ε ∈ Σ!)

(1) Given a string s and a string t, output st.

(3) Given a string s, output Al(s).

(5) Given a string s and an alphabet Σ, output πΣ(s).

Input is given by a string or your language's closest equivalent for a string input, an array, tuple, or n-ordinate of characters for an alphabet  (your language's closest equivalent), and a number for a number (or your language's closest equivalent, heaven forbid your language does not support numbers!).

Each task has a score (the number in parenthesis). Your submission's score is calculated as follows:

```<code>        sum points scored
score = —————————————————
         length of bytes
</code>```

Highest score wins.

Bonuses

×4 final score iff you output (with the correct symbols!) the input query. E.g., outputting \pi_{\{0,1\}}(012345678910111213)=01101111 for an input of Σ = [0,1]; s = 012345678910111213. (You may choose to do this in either HTML or (La)TeX. Either counts.)

(I'm open to suggestions.)

答:
Java, score: 8 / 491 467 465 462 ~= 0.0173

I just wanted to see how many tasks I can figure out.

```<code>import static java.lang.System.*;interface a{static void main(String[]A){char[]Z=A[1].toCharArray();switch(A[0]){case"a":out.print(A[1].length());break;case"b":int b=1;for(char B:Z)b=A[2].contains(new String(c))?b:0;out.print(b>0);break;case"c":String B="";int c=1;for(char C:Z){c=B.contains(new String(C))?0:c;B+=C;}out.print(c>0);break;case"d":out.print(A[1]+A[2]);break;case"e":String C="";for(char d:Z)C+=C.contains(new String(d))?"":d;out.print(C);break;}}}
</code>```

The program (ab)uses command line arguments to get the tasks done. Here's how it works (note that every argument should be enclosed in double quotes like "arg1" "arg2" "arg3"):

If the first argument is a, the second argument's length is printed (calculates the length of a given string). Syntax: a <string>

If the first argument is b, true is printed in case of the second argument being over the third argument, which is taken as an alphabet (given a string and an alphabet, find out if the string is over the alphabet). Syntax: b <string> <alphabet>

If the first argument is c, true is printed if the second argument is a valid alphabet where every character occurs only once (given an alphabet, find out if it's valid). Syntax: c <alphabet>

If the first argument is d, the concatenation of the second and third arguments is printed - the second argument comes first (given two strings, concatenate them). Syntax: d <first string> <second string>

If the first argument is e, the smallest alphabet which the second argument is over is printed (given a string, find out its alphabet). Syntax: e <string>

Oh wait, let me ungolf the program for you:

```<code>import static java.lang.System.*;
interface a {
    static void main(String[] A) {
        char[] Z = A[1].toCharArray();
        switch (A[0]) {
        case "a":
            out.print(A[1].length());
            break;
        case "b":
            int b = 1;
            for (char B : Z)
                b = A[2].contains(new String(c)) ? b : 0;
            out.print(b > 0);
            break;
        case "c":
            String B = ""; int c = 1;
            for (char C : Z){
                c = B.contains(new String(C)) ? 0 : c;
                B += C;
            }
            out.print(c > 0);
            break;
        case "d":
            out.print(A[1] + A[2]);
            break;
        case "e":
            String C = "";
            for (char d : Z)
                C += C.contains(new String(d)) ? "" : d;
            out.print(C);
            break;
        }
    }
}
</code>```

Title: How's your string theory?

Body:
Java, score: 8 / 491 467 465 462 ~= 0.0173

I just wanted to see how many tasks I can figure out.

import static java.lang.System.*;interface a{static void main(String[]A){char[]Z=A[1].toCharArray();switch(A[0]){case"a":out.print(A[1].length());break;case"b":int b=1;for(char B:Z)b=A[2].contains(new String(c))?b:0;out.print(b>0);break;case"c":String B="";int c=1;for(char C:Z){c=B.contains(new String(C))?0:c;B+=C;}out.print(c>0);break;case"d":out.print(A[1]+A[2]);break;case"e":String C="";for(char d:Z)C+=C.contains(new String(d))?"":d;out.print(C);break;}}}

The program (ab)uses command line arguments to get the tasks done. Here's how it works (note that every argument should be enclosed in double quotes like "arg1" "arg2" "arg3"):

If the first argument is a, the second argument's length is printed (calculates the length of a given string). Syntax: a <string>

If the first argument is b, true is printed in case of the second argument being over the third argument, which is taken as an alphabet (given a string and an alphabet, find out if the string is over the alphabet). Syntax: b <string> <alphabet>

If the first argument is c, true is printed if the second argument is a valid alphabet where every character occurs only once (given an alphabet, find out if it's valid). Syntax: c <alphabet>

If the first argument is d, the concatenation of the second and third arguments is printed - the second argument comes first (given two strings, concatenate them). Syntax: d <first string> <second string>

If the first argument is e, the smallest alphabet which the second argument is over is printed (given a string, find out its alphabet). Syntax: e <string>

Oh wait, let me ungolf the program for you:

import static java.lang.System.*;
interface a {
    static void main(String[] A) {
        char[] Z = A[1].toCharArray();
        switch (A[0]) {
        case "a":
            out.print(A[1].length());
            break;
        case "b":
            int b = 1;
            for (char B : Z)
                b = A[2].contains(new String(c)) ? b : 0;
            out.print(b > 0);
            break;
        case "c":
            String B = ""; int c = 1;
            for (char C : Z){
                c = B.contains(new String(C)) ? 0 : c;
                B += C;
            }
            out.print(c > 0);
            break;
        case "d":
            out.print(A[1] + A[2]);
            break;
        case "e":
            String C = "";
            for (char d : Z)
                C += C.contains(new String(d)) ? "" : d;
            out.print(C);
            break;
        }
    }
}


问:
Remove more than n consecutive vowels from input string
I don't like strings with more than three vowels in a row. Can you write a program that removes all the vowels I don't want from words?

You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.

Input is a string containing only printable ASCII character (0x20 to 0x7E, inclusive).

Output is a string containing only runs of at most 3 consecutive vowels. If there is a run of more than 3 consecutive vowels in the input string, your program should produce an output string including the first three vowels encountered in that run, discarding any further consecutive vowels.

Y is not a vowel for the purposes of this challenge.

This is code golf, so the shortest code (in bytes) wins.

Test Cases

```<code>"Aeiou" => "Aei"
"screeeen" => "screeen"
"We're queueing up for the Hawaiian movie." => "We're queung up for the Hawaiin movie."
"Spaces break runs: aei iou." => "Spaces break runs: aei iou."
</code>```

答:
V, 21 bytes (noncompeting)

```<code>ñ[aeiou]ñÍãqû3}úsq*
</code>```

Try it online!

Explanation:

```<code>ñ[aeiou]ñ                     "Assign the string `[aeiou]` to register 'q'
         Íã                   "Search and replace on multiple lines (case insensitive):
           <C-r>q             "Register 'q'
                 û3}          "Repeated 3 times
                    ús        "Mark the following to be removed:
                      <C-r>q* "Register 'q' repeated any number of times
</code>```

This is just barely shorter than the more straightforward solution:

```<code>Íã[aeiou]û3}ús[aeiou]*
</code>```

(22 bytes)

Body:
V, 21 bytes (noncompeting)

ñ[aeiou]ñÍãqû3}úsq*

Try it online!

Explanation:

ñ[aeiou]ñ                     "Assign the string `[aeiou]` to register 'q'
         Íã                   "Search and replace on multiple lines (case insensitive):
           <C-r>q             "Register 'q'
                 û3}          "Repeated 3 times
                    ús        "Mark the following to be removed:
                      <C-r>q* "Register 'q' repeated any number of times

This is just barely shorter than the more straightforward solution:

Íã[aeiou]û3}ús[aeiou]*

(22 bytes)


答:
Python 3, 71 bytes

lambda w,s:s.translate({ord(t[0]):t for t in(w+' '+w.title()).split()})
```

Test it on Ideone.

How it works

In Python 3, the built-in str.translate takes a string and a dictionary, and replaces each character in the string whose code point is a key of that dictionary with the corresponding value, which may be a string, an integer or None (equivalent to the empty string).

Converting the string of words w to title case (i.e., capitalizing the first letter of each word) and appending it to the result of w+' ' creates a string of space separated words with lower- and uppercase version (first letter). Without a second argument, str.split splits at whitespace, so (w+' '+w.title()).split() creates the list of all words.

Finally, the dictionary comprehension {ord(t[0]):t for t in...} turns each word t into a dictionary entry with key ord(t[0]) (code point of the first letter) and value t, so str.translate will perform the intended substitutions.

Title: Geobitsian Language

Body:
Geobitsian language is a new perversion of English where a word is broken into segments that each must start with a different letter. Then every time one of those starting letters appears in another string, it is replaced with its entire corresponding segment, maintaining capitalization.

This process is called Geobitsizing.

For example the word "Geobits" could be broken into geo bits, and the nonsense poem

```<code>Algy met a Bear
A Bear met Algy
The Bear was bulgy
The bulge was Algy
</code>```

would be Geobitsized with it as

```<code>Algeoy met a Bitsear
A Bitsear met Algeoy
The Bitsear was bitsulgeoy
The bitsulgeoe was Algeoy
</code>```

because every g becomes geo, every G (though there are none) becomes Geo, every b becomes bits, and every B becomes Bits.

Note that each substitution is performed with respect to the original string, not any intermediate step. e.g. if geo had been gbo instead, the b's created would not replaced with bits.

Challenge

Write a program or function that can generate Geobitsian language.

Take in a single-line string made of lowercase letters (a-z) and spaces. This will be the word used as the Geobitsizing argument, with the spaces separating the segments. You can assume:

Segments will not be empty. So spaces will not neighbor each other nor be at the start or end of the string.

Each segment starts with a different letter. Thus there cannot be more than 26.

For example, some valid segmented strings you must support are geo bits, butt ner, alex, and do o r k nob (single letter segments have no effect but are valid). But geo , butt   ner, Alex, and do o r k n ob are invalid.

Your program or function also needs to take in another arbitrary string to apply the Geobitsizing to, and print or return the resulting Geobitsian language.

You can assume this string only contains newlines and printable ASCII.

Remember that letter cases must be preserved from the input to the output.

Here are some more examples using no pro gr am m ing as the Geobitsizing argument:

[empty string] → [empty string]

i → ing

I → Ing

Mmmm, mmm... MmmmMMM: m&m! → Mmmm, mmm... MmmmMMM: m&m! (no change)

People think bananas are great, don't you? → Proeoprole thingnok bamnoamnoams amre grreamt, dono't you?

```<code>Pet a Puppy
Google Wikipedia
</code>```

↓

```<code>Proet am Prouproproy
Groogrle Wingkingproedingam
</code>```

Note that the results should be identical no matter how the argument is arranged, e.g. ing pro m no am gr should yield the same results as above.

The shortest code in bytes wins.

Body:
Python 3, 71 bytes

lambda w,s:s.translate({ord(t[0]):t for t in(w+' '+w.title()).split()})

Test it on Ideone.

How it works

In Python 3, the built-in str.translate takes a string and a dictionary, and replaces each character in the string whose code point is a key of that dictionary with the corresponding value, which may be a string, an integer or None (equivalent to the empty string).

Converting the string of words w to title case (i.e., capitalizing the first letter of each word) and appending it to the result of w+' ' creates a string of space separated words with lower- and uppercase version (first letter). Without a second argument, str.split splits at whitespace, so (w+' '+w.title()).split() creates the list of all words.

Finally, the dictionary comprehension {ord(t[0]):t for t in...} turns each word t into a dictionary entry with key ord(t[0]) (code point of the first letter) and value t, so str.translate will perform the intended substitutions.


答:
Python 3, 27 / 158 ≈ 0.1709

I tried for as many tasks as possible instead of the highest score possible.

```<code>from itertools import*
L=len
lambda s,a:all(c in a for c in s)
lambda a:L(set(a))==L(a)
permutations
str.__add__
set
lambda s,a:filter(a.__contains__,s)
</code>```

Task 1:

```<code>L=len
</code>```

Pretty self-explanatory. I assign it because it's used later, and naming it L saved 4 bytes.

Task 2:

```<code>lambda s,a:all(c in a for c in s)
</code>```

This maps s to a list of boolean values telling if the corresponding character is in the string. If they are all True, then s is over a.

Task 3:

```<code>lambda a:L(set(a))==L(a)
</code>```

Here's where I used that len rename. In Python, the set class is a container of unique objects, and if the constructor is given a container with duplicates, it removes them.

Task 4:

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

The Python library function itertools.permutations does exactly what is needed.

Task 5:

nope

Task 6:

```<code>str.__add__
</code>```

Shamelessly co-opting class methods. Not much else to say.

Task 7:

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

Once again, the beautiful uniquefying set comes in handy. Here, it automatically finds the minimal alphabet.

Task 8:

```<code>lambda s,a:filter(a.__contains__,s)
</code>```

Filters out the characters in s s which are not also in a. Alternative with the same length: [c for c in s if c in a]

Title: How's your string theory?

Body:
Back to the basics! You're in you comp sci class again, except wiser and golfier. You have the tools, you have the power… but do you have the skill? Probably.

Crash Course for the non-Computer Scientist (skip if you don't need it)

A string is symbolically represented by an arbitrary letter (usually, for our purposes, will be  etc. Of course, we know a string as something like "Hello, World!" or 'Hello, World!', or, if you're the snarky Python user, """Hello, World!""".

An alphabet can be thought of as a set (i.e. no repeating characters) of symbols, of which strings can be made. For example, ; this is the binary alphabet, of which contains strings like  and .  These strings can said to be strings over , or, alternatively, .

The length of any string is denoted . For example, .

There is the empty or null string , which is equivalent to "". It is a valid string in over any alphabet. In other words,  is the unique string satisfying the property .

The set  is the set of all strings  over  for which .

The set  is called the Kleene closure of , and is the set of all strings over . This can be considered the language of .

The concatenation of two strings  and  is denoted , and is the string containing the characters of  followed by the characters of .

 is said to be a prefix of  if there is some string  that satisfies the equality . (If , then  is said to be a proper prefix of .)

The alphabet of a string  is denoted , and is the minimal alphabet  so that  is a string over

The projection of a string  relative to an alphabet  is defined as

and is essentially the removal of all characters in  not in .

TL;DR

Objective Write a program, series of functions, series of programs etc. that can calculate as many of the following tasks as possible:

(1) Calculate, given a string s, its length.

(2) Arrive at, given a string s and an alphabet Σ, whether or not (output a truthy/falsy value) that string is over said alphabet.

(1) Given an alphabet, arrive at whether or not (output a truthy/falsy value) the alphabet is valid (a valid alphabet can have no repeating characters, but is otherwise valid).

(4) Given an alphabet Σ and a positive integer n, display .

(6) Given an alphabet Σ and an integer n, display the first n entries in  (Remember that ε ∈ Σ!)

(1) Given a string s and a string t, output st.

(3) Given a string s, output Al(s).

(5) Given a string s and an alphabet Σ, output πΣ(s).

Input is given by a string or your language's closest equivalent for a string input, an array, tuple, or n-ordinate of characters for an alphabet  (your language's closest equivalent), and a number for a number (or your language's closest equivalent, heaven forbid your language does not support numbers!).

Each task has a score (the number in parenthesis). Your submission's score is calculated as follows:

```<code>        sum points scored
score = —————————————————
         length of bytes
</code>```

Highest score wins.

Bonuses

×4 final score iff you output (with the correct symbols!) the input query. E.g., outputting \pi_{\{0,1\}}(012345678910111213)=01101111 for an input of Σ = [0,1]; s = 012345678910111213. (You may choose to do this in either HTML or (La)TeX. Either counts.)

(I'm open to suggestions.)

Body:
Python 3, 27 / 158 ≈ 0.1709

I tried for as many tasks as possible instead of the highest score possible.

from itertools import*
L=len
lambda s,a:all(c in a for c in s)
lambda a:L(set(a))==L(a)
permutations
str.__add__
set
lambda s,a:filter(a.__contains__,s)

Task 1:

L=len

Pretty self-explanatory. I assign it because it's used later, and naming it L saved 4 bytes.

Task 2:

lambda s,a:all(c in a for c in s)

This maps s to a list of boolean values telling if the corresponding character is in the string. If they are all True, then s is over a.

Task 3:

lambda a:L(set(a))==L(a)

Here's where I used that len rename. In Python, the set class is a container of unique objects, and if the constructor is given a container with duplicates, it removes them.

Task 4:

permutations

The Python library function itertools.permutations does exactly what is needed.

Task 5:

nope

Task 6:

str.__add__

Shamelessly co-opting class methods. Not much else to say.

Task 7:

set

Once again, the beautiful uniquefying set comes in handy. Here, it automatically finds the minimal alphabet.

Task 8:

lambda s,a:filter(a.__contains__,s)

Filters out the characters in s s which are not also in a. Alternative with the same length: [c for c in s if c in a]


Title: Geobitsian Language

Body:
Ruby, <s>65</s> <s>60</s> 58 bytes

->w,s{s.gsub(/\w/){|c|w=~/\b#{c}(\w+)/i;c+($1||c)[1..-1]}}

Try it online!


问:
The happy Ender problem
The happy ending problem (actually a theorem) states that

Any set of five points in the plane in general position has a subset of four points that form the vertices of a convex quadrilateral.

The problem was so named by Paul Erdős when two mathematicians who first worked on the problem, Ester Klein and George Szekeres, became engaged and subsequently married.

Clarifications:

General position here means that no three points are collinear.

The quadrilateral formed by the four vertices will always be considered to be non-intersecting, irrespective of the order of the points. For example, given the four points [1 1], [1 2], [2 1], [2 2] the intended quadrilateral is the square, not the bow-tie:

A non-intersecting quadrilateral is convex if no interior angle exceeds 180 degrees; or equivalently if both diagonals lie inside the quadrilateral.

The challenge

Given 5 points with positive integer coordinates, output 4 of those points that form a convex quadrilateral.

Rules

If there are several solutions (that is, several sets of 4 points), you can consistently choose to output one of them or all.

Input and output formats are flexible as usual (arrays, lists, list of lists, strings with reasonable separators, etc).

Code golf, fewest bytes wins.

Test cases

Input:

```<code>[6 8] [1 10] [6 6] [5 9] [8 10]
</code>```

There is only one possible output:

```<code>[6 8] [1 10] [6 6] [5 9]
</code>```

Input:

```<code>[3 8] [7 5] [6 9] [7 8] [5 1]
</code>```

There are five solutions:

```<code>[3 8] [7 5] [6 9] [7 8]
[3 8] [7 5] [6 9] [5 1]
[3 8] [7 5] [7 8] [5 1]
[3 8] [6 9] [7 8] [5 1]
[7 5] [6 9] [7 8] [5 1]
</code>```

Input:

```<code>[4 8] [1 9] [9 9] [10 2] [1 6]
</code>```

There are three solutions:

```<code>[4 8] [1 9] [10 2] [1 6]
[4 8] [9 9] [10 2] [1 6]
[1 9] [9 9] [10 2] [1 6]
</code>```

To illustrate, here are the three solutions to this case:

答:
MATLAB, 67 bytes

```<code>I=input('');for k=~eye(5);if nnz(convhull(I(k,:)))>4;I(k,:),end;end
</code>```

Input is in the form of a 2D matrix where the columns are X and Y respectively:

```<code>[6 8; 1 10; 6 6; 5 9; 8 10]
[3 8; 7 5; 6 9; 7 8; 5 1]
[4 8; 1 9; 9 9; 10 2; 1 6]
</code>```

All sets of 4 points that create convex quadrilaterals are displayed in the same format.

Here is a demo that is slightly modified to work with Octave

Explanation

This solution takes all subsets of 4 points of the input (order doesn't matter). To do this, we create the identity matrix and negate it: ~eye(5). We loop through the columns of this matrix and k (the loop index) is a logical array which specifies which of the 4 points to consider. We then use this to grab these 4 XY points from the input (I(k,:)).

We then compute the convex hull of these 4 points (convhull). The output of convhull is the indices of the input that correspond with the points that make up the convex hull (with the first index duplicated to close the hull).

For a convex quadrilateral, all four points will be part of the convex hull of the same points (nnz(convhull(points)) > 4). If we detect that this is the case, we display the points that were used for this particular iteration.

Title: The happy Ender problem

Body:
MATLAB, 67 bytes

I=input('');for k=~eye(5);if nnz(convhull(I(k,:)))>4;I(k,:),end;end

Input is in the form of a 2D matrix where the columns are X and Y respectively:

[6 8; 1 10; 6 6; 5 9; 8 10]
[3 8; 7 5; 6 9; 7 8; 5 1]
[4 8; 1 9; 9 9; 10 2; 1 6]

All sets of 4 points that create convex quadrilaterals are displayed in the same format.

Here is a demo that is slightly modified to work with Octave

Explanation

This solution takes all subsets of 4 points of the input (order doesn't matter). To do this, we create the identity matrix and negate it: ~eye(5). We loop through the columns of this matrix and k (the loop index) is a logical array which specifies which of the 4 points to consider. We then use this to grab these 4 XY points from the input (I(k,:)).

We then compute the convex hull of these 4 points (convhull). The output of convhull is the indices of the input that correspond with the points that make up the convex hull (with the first index duplicated to close the hull).

For a convex quadrilateral, all four points will be part of the convex hull of the same points (nnz(convhull(points)) > 4). If we detect that this is the case, we display the points that were used for this particular iteration.