[Question]
      [
# Challenge :
Count the number of ones `1` in the binary representation of all number between a range.
---
# Input :
Two non-decimal positive integers
---
# Output :
The sum of all the `1`s in the range between the two numbers.
---
# Example :
```
4 , 7        ---> 8
4  = 100 (adds one)   = 1
5  = 101 (adds two)   = 3
6  = 110 (adds two)   = 5
7  = 111 (adds three) = 8
10 , 20     ---> 27
100 , 200   ---> 419
1 , 3       ---> 4
1 , 2       ---> 2
1000, 2000  ---> 5938
```
I have only explained the first example otherwise it would have taken up a huge amount of space if I tried to explain for all of them.
---
# Note :
* Numbers can be apart by over a 1000
* All input will be valid.
* The minimum output will be one.
* You can accept number as an array of two elements.
* You can choose how the numbers are ordered.
---
# Winning criteria :
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest code in bytes for each language wins.

[Answer]
# [Python 2](https://docs.python.org/2/), 47 bytes
```
f=lambda x,y:y/x and bin(x).count('1')+f(x+1,y)
```
[Try it online!](https://tio.run/##LYzNCsIwEAbP@hTfpSRLV21aQSjou6SWYEA3paSQPH38iZeZOc2S4yNIX4q7Pu1rmi0S5zGfEqzMmLzoRMd72CRqZRS1TqfWcKbiwgqdGJngBfrMuBBDm47Rd7V@WZsx/N3TuN8tq5cI1Qwb4wMcbl8pNHXJcHVN5Q0 "Python 2 – Try It Online")
[Answer]
# JavaScript (ES6), 38 bytes
Takes input in currying syntax `(a)(b)`.
```
a=>b=>(g=c=>a>b?0:1+g(c^c&-c||++a))(a)
```
[Try it online!](https://tio.run/##bcxBCsIwEIXhvaeYlWQItUksVAuJNxGmYxuU0kgrrnr3GDGr4OZtPt7/oDetvNyfr2oOtyGONpJ1vXXCW7aOXH9RnZZe8JX3FW@blIQoCCOHeQ3TcJiCF6MAaDBNiwh1DaddoVolNeqnpi1Yq8RGZW70ubyD/saP2f@ryfH4AQ "JavaScript (Node.js) – Try It Online")
### Commented
```
a => b => (         // given the input values a and b
  g = c =>          // g = recursive function taking c = current value
    a > b ?         // if a is greater than b:
      0             //   stop recursion and return 0
    :               // else:
      1 +           //   add 1 to the final result
      g(            //   and do a recursive call to g() with:
        c ^ c & -c  //     the current value with the least significant bit thrown away
        || ++a      //     or the next value in the range if the above result is 0
      )             //   end of recursive call
)(a)                // initial call to g() with c = a
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
rBFS
```
[Try it online!](https://tio.run/##y0rNyan8/7/IyS34////Jv/NAQ "Jelly – Try It Online")
### Explanation
```
rBFS – Full program. Takes the two inputs from the commands line arguments.
r    – Range.
 B   – For each, convert to binary.
  FS – Flatten and sum.
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 4 bytes
```
ŸbSO
```
[Try it online!](https://tio.run/##MzBNTDJM/f//6I6kYP///024zAE "05AB1E – Try It Online")
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 55 bytes
```
a->b->{int c=0;for(;a<=b;)c+=a.bitCount(b--);return c;}
```
[Try it online!](https://tio.run/##LY5BS8QwEIXv/RVzTNQED4KHbAsiCB7Ew@JJPEyyaUlNk5BMFsrS317j6umbx5uZ92Y8o5hP37tbUswEc9OykvNyrMGQi0HeqM54LAXe0AW4dACpau8MFEJqOEd3gqV57EjZhenzCzBPhV9XAV7@/xxeA9nJ5rvGj4B5fU82I8U8wNjvKAYthosLBKa/V2PMTOGh14qb2x6ldvQcayCmheAqW6o5gFHbrq4Zx7WQXWSsJFOrQD6wUWJKfmUP/G94Ki2XPXL@e7F12/4D "Java (JDK 10) – Try It Online")
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), ~~8~~ 7 bytes
1 byte thanks to Mr. Xcoder.
```
ssjR2}F
```
[Try it online!](http://pyth.herokuapp.com/?code=ssjR2%7DF&input=4%2C7&debug=0)
[Answer]
# [Python 2](https://docs.python.org/2/), 45 bytes
```
lambda x,y:`map(bin,range(x,y+1))`.count('1')
```
[Try it online!](https://tio.run/##LYxBCsIwFETXeorZlOTjV5pUEAp6EhdN1WihTUJJwZw@VuNm3mMGJqT48k5nizOueTRTfzd4c2q7yQTZD45n454PuVY7RdQdbn5xUQolKFs/Yx2QCIODPDJOxJCqZui62E@LM5o/NbXbTZgHFyGqZmGsgf3lC4GqXDJsuab8AQ "Python 2 – Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~5~~ 4 bytes
```
&:Bz
```
[Try it online!](https://tio.run/##y00syfn/X83Kqer/fxMucwA "MATL – Try It Online")
*Thanks to Luis Mendo for saving a byte!*
```
(implicit input a and b, a<b)
&:                              % two-element input range, construct [a..b]
  B                             % convert to Binary as a logical vector (matrix)
   z                            % number of nonzero entries
(implicit output of the result)
```
[Answer]
# [R](https://www.r-project.org/), ~~41~~ 34 bytes
```
function(a,b)sum(intToBits(a:b)>0)
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jUSdJs7g0VyMzryQk3ymzpFgj0SpJ085A83@ahomOuSZXmoahgY6RAYQBYkGYOsYQykjzPwA "R – Try It Online")
Heavily inspired by [the other R solution by ngm](https://codegolf.stackexchange.com/a/166216/80010). This uses a different approach after the conversion to bits. Huge thanks to Giuseppe for hinting at a possible 34 bytes solution.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 38 bytes
```
->a,b{("%b"*(b-a+1)%[*a..b]).count ?1}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y5RJ6laQ0k1SUlLI0k3UdtQUzVaK1FPLylWUy85vzSvRMHesPZ/QWlJsUJatImOeex/AA "Ruby – Try It Online")
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 16 [bytes](https://github.com/abrudz/SBCS)
```
{≢⍸(⍵⍴2)⊤⍺↓0,⍳⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/pR56JHvTs0HvVufdS7xUjzUdeSR727HrVNNtB51LsZKFr7//@j3rkK4Zk5OQq5idmpCpklCkmpJSWpRQo5iUBSj4vL0MBAoVr7Uc9@HTzGKBgZGAAA "APL (Dyalog Unicode) – Try It Online")
-1 thanks to [H.PWiz](https://codegolf.stackexchange.com/users/71256/h-pwiz).
Left argument = min
Right argument = max
[Answer]
# [Octave](https://www.gnu.org/software/octave/) with Communication toolbox, 21 bytes
```
@(a,b)nnz(de2bi(a:b))
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999BI1EnSTMvr0ojJdUoKVMj0SpJU/N/moaJjrkmV5qGoYGOkQGEAWJBmDrGEMpI8z8A "Octave – Try It Online")
The code should be fairly obvious. Number of nonzero elements in the binary representation of each of the numbers in the range.
This would be `@(a,b)nnz(dec2bin(a:b)-48)` without the communication toolbox.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~56~~ ~~54~~ 52 bytes
~~This can be golfed more imo.~~
-2 Bytes thanks to Mr.Xcoder
-2 More bytes thanks to M. I. Wright
```
lambda a,b:''.join(map(bin,range(a,b+1))).count('1')
```
[Try it online!](https://tio.run/##K6gsycjPM/6fbhvzPycxNyklUSFRJ8lKXV0vKz8zTyM3sUAjKTNPpygxLz1VAyijbaipqamXnF@aV6Khbqiu@b@gKBPITNcw0THX1ORC8Cw0Nf8DAA "Python 3 – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal) `d`, 2 bytes
```
ṡb
```
[Try it online](https://vyxal.pythonanywhere.com/#WyJkIiwiIiwi4bmhYiIsIiIsIjRcbjciXQ==) or see a [four byte flagless version](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLhuaFiZuKIkSIsIiIsIjRcbjciXQ==).
Gets the range between the two inputs, converts each to a list of 1s and 0s, then deep flattens and sums with the `d` flag.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 6 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
çy╠Æ¼☻
```
[Run and debug it](https://staxlang.xyz/#p=8779cc92ac02&i=4+7&a=1)
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 72 bytes
```
param($x,$y)$x..$y|%{$o+=([convert]::ToString($_,2)-replace0).length};$o
```
[Try it online!](https://tio.run/##BcFRCoMwDADQy2TQMi3RT8VTuD@RUSSoUJuSlU3RnT2@l/hH8lkoBNXkxW8G9gIOC7tzcFyPE/jZmWHi@CXJY9O8uM@yxtnAu6htKZSCnwitCxTnvPxbYFWtELVGvAE "PowerShell – Try It Online")
Long because of the conversion to binary `[convert]::ToString($_,2)` and getting rid of the zeros `-replace0`. Otherwise we just take the input numbers, make a range `$x..$y` and for each number in the range convert it to binary, remove the zeros, take the `.length` thereof (i.e., the number of ones remaining), and add it to our `$o`utput.
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + common utilities, 50
```
jot -w%o - $@|tr 247356 1132|fold -1|paste -sd+|bc
```
[Try it online!](https://tio.run/##S0oszvj/Pyu/REG3XDVfQVdBxaGmpEjByMTc2NRMwdDQ2KgmLT8nRUHXsKYgsbgkVUG3OEW7Jin5////hgb/jQwA "Bash – Try It Online")
Converting integers to binary strings is always a bit of pain in bash. The approach here is slightly different - convert the integers to octal, then replace each octal digit with the number of binary 1s it contains. Then we can just sum all converted digits
[Answer]
# APL+WIN, ~~33~~ 26 bytes
Prompts for vector of integers:
```
+/,((↑v)⍴2)⊤(1↓v)+0,⍳-/v←⎕
```
[Try it online! Courtesy of Dalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcjzra0/5r6@toaDxqm1im@ah3i5Hmo64lGoaP2iaXaWob6Dzq3ayrXwZUC9TzH6j6fxqXuYIJVxqXkYGCoQGYBjFALGMFQxBfwRAA "APL (Dyalog Classic) – Try It Online")
Explanation:
```
v←⎕ prompt for input of a vector of two integers max first
(v←1↓v)+0,⍳-/ create a vector of integers from min to max
(↑v)⍴2 set max power of 2 to max
⊤ convert integers to a matrix of binaries
+/, convert matrix to a vector and sum
```
[Answer]
# [R](https://www.r-project.org/), ~~44 40~~ 37 bytes
```
function(a,b)sum(c(0,intToBits(a:b)))
```
[Try it online!](https://tio.run/##K/qfZvs/rTQvuSQzP08jUSdJs7g0VyNZw0AnM68kJN8ps6RYI9EqSVNT83@ahomOueZ/AA "R – Try It Online")
Previously:
```
function(a,b)sum(strtoi(intToBits(a:b)))
function(a,b)sum(as.integer(intToBits(a:b)))
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 8 bytes
```
⟦₂ḃᵐcọht
```
[Try it online!](https://tio.run/##ASkA1v9icmFjaHlsb2cy///in6bigoLhuIPhtZBj4buNaHT//1sxMCwyMF3/Wg "Brachylog – Try It Online")
### Explanation
```
⟦₂         Ascending range between the two elements in the input
  ḃᵐ       Map to base 2
    c      Concatenate
     ọ     Occurrences of each element
      h    Head: take the list [1, <number of occurrences of 1>]
       t   Tail: the number of occurrences of 1
```
[Answer]
# [Forth (gforth)](http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/), 69 bytes
```
: f 1+ 0 -rot swap do i begin 2 /mod -rot + swap ?dup 0= until loop ;
```
[Try it online!](https://tio.run/##LY3NDsIgEITvPsWk14ZK8S9poz6LilSS2t0gjY@PC3iZ@TazmXEU4ktNLltKAxz6FhoqUMTne2NYgsf9OfkFBts32Zq1Nb3alaHPWJfoZ8xEjFFaGCYH5eWALlTpGkCpSyMjx3w/wrjppZVFd6J7nDJrGF08w58KCqcf "Forth (gforth) – Try It Online")
### Explanation
The basic algorithm is to loop over every number in range, and sum the binary digits (divide by two, add remainder to sum, repeat until number is 0)
### Code Explanation
```
1+                   \ add one to the higher number to make it inclusive
0 -rot swap          \ create a sum value of 0 and put loop parameters in high low order
do                   \ start a loop over the range provided
  i                  \ place the index on the stack
  begin              \ start an indefinite loop
    2 /mod           \ get the quotient and remainder of dividing by 2
    -rot             \ move the quotient to the back
    + swap           \ add the remainder to the sum and move it down the stack
    ?dup             \ duplicate the quotient unless it equals 0
    0=               \ check if it equals 0
  until              \ if it does equal 0, end the inner loop
loop                 \ end the outer loop
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
Σṁḋ…
```
[Try it online!](https://tio.run/##yygtzv7//9zihzsbH@7oftSw7P///yb/zQE "Husk – Try It Online")
### Explanation
```
Σṁḋ…
   …     Get the (inclusive) range.
 ṁḋ      Convert each to binary and concatenate.
Σ        Get the sum.
```
[Answer]
## PHP, 97 Bytes
(sure this can be shortened, but wanted to use the functions)
[**Try it online**](https://tio.run/##K8go@G9jX5BRwKWSWJReFm0Qa2tiDWUbxtqaW3PZ2wEV2BaXJhWXFMUn55fmlWhk5hbk5KekaiQWFSVWxucmFmikleYll2Tm52molGlWF6WWlBblKaSkJidlgkWsa3WKEvPSUzVgdujALNDU1NQx1LT@/x8A)
**Code**
```
<?=substr_count(implode(array_map(function($v){return decbin($v);},
 range($argv[0],$argv[1]))),1);
```
**Explanation**
```
<?=
 substr_count(   //Implode the array and count every "1"
  implode(
    array_map(function($v){return decbin($v);}, //Transform every decimal to bin
          range($argv[0],$argv[1])   //generate a range between the arguments
     )
),1);   //count "1"'s
```
[Answer]
# [Haskell](https://www.haskell.org/), 42 bytes
```
import Data.Bits
a%b=sum$popCount<$>[a..b]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/PzO3IL@oRMElsSRRzymzpJgrUTXJtrg0V6Ugv8A5vzSvxEbFLjpRTy8p9n9uYmaegq1CQVFmXomCioKhgYGqhpGBgZWVZ16JpsJ/AA "Haskell – Try It Online")
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 10 bytes
```
$+JTB:a\,b
```
[Try it online!](https://tio.run/##K8gs@P9fRdsrxMkqMUYn6f///4YGBv@NDAwA "Pip – Try It Online")
### Explanation
```
            a and b are command-line args (implicit)
      a\,b  Inclusive range from a to b
   TB:      Convert to binary (: forces TB's precedence down)
  J         Join into a single string of 1's and 0's
$+          Sum (fold on +)
```
[Answer]
# [Proton](https://github.com/alexander-liao/proton), ~~[40](https://codegolf.stackexchange.com/revisions/166208/1)~~ 37 bytes
```
x=>y=>str(map(bin,x..y+1)).count("1")
```
[Try it online!](https://tio.run/##KyjKL8nP@59m@7/C1q7S1q64pEgjN7FAIykzT6dCT69S21BTUy85vzSvREPJUEnzf0FRJpCZpmGiqWGuqfkfAA "Proton – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 10 bytes
```
ＩΣ⭆…·ＮＮ⍘ι²
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0VyO4BMhP900s0MjMS84pLc4sSw1KzEtP1fDMKygt8SvNTUot0tDUUUDhAvlOicWpEL0amToKRpogYP3/vwmXxX/dshwA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
     ＮＮ     Input numbers
   …·       Inclusive range
  ⭆         Map over range and join
        ι   Current value
         ²  Literal 2
       ⍘    Convert to base as string
 Σ          Sum of digits
Ｉ           Cast to string
            Implicitly print
```
[Answer]
# [Bash](https://www.gnu.org/software/bash/) + coreutils, ~~38~~ 32 bytes
```
seq -f2o%.fn $*|dc|tr -d 0|wc -c
```
*Thanks to @Cowsquack for golfing off 6 bytes!*
[Try it online!](https://tio.run/##S0oszvj/vzi1UEE3zShfVS8tT0FFqyYluaakSEE3RcGgpjxZQTf5////hgb/jQwA "Bash – Try It Online")
[Answer]
# [K (ngn/k)](https://gitlab.com/n9n/k), ~~19~~ 13 bytes
```
{+//2\x_!1+y}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/NqlpbX98opiJe0VC7svZ/WrSJtXnsfwA "K (ngn/k) – Try It Online")
`{` `}` is a function with arguments `x` and `y`
`!1+y` is the list 0 1 ... y
`x_` drops the first x elements
`2\` encodes each int as a list of binary digits of the same length (this is specific to ngn/k)
`+/` sum
`+//` sum until convergence; in this case sum of the sum of all binary digit lists
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~32~~ 30 bytes
*-1 bytes thanks to Brad Gillbert*
```
{[…](@_)>>.base(2).comb.sum}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJKmYKvwvzr6UcOyWA2HeE07O72kxOJUDSNNveT83CS94tLc2v/FiSCFGoYGBjoKRgYGmtZccBGQgOZ/AA "Perl 6 – Try It Online")
Explanation:
```
[…](@_)    #Range of parameter 1 to parameter 2
       >>    #Map each number to
                      .sum  #The sum of
                 .comb      #The string of
         .base(2)    #The binary form of the number
```
]


[Question]
      [
**The challenge**
Create a function which takes an array of numbers and subtract from each element the lowest element in the array that has not yet been subtracted from another.
* After using the lowest value, It can not be used again.
* Numbers in the array are decimal numbers, and not necessarily integers.
**Example:**
```
Input: [6, 4, 7, 8, 9, 2, 1, 4]
Next lowest value:          Output:
[6, 4, 7, 8, 9, 2, 1, 4]    [6, 4, 7, 8, 9, 2, 1, 4]
                   ^         ^
                            6-1 = 5
[6, 4, 7, 8, 9, 2, -, 4]    [5, 4, 7, 8, 9, 2, 1, 4]
                ^               ^
                            4-2 = 2
[6, 4, 7, 8, 9, -, -, 4]    [5, 2, 7, 8, 9, 2, 1, 4]
    ^                              ^
                            7-4 = 3
[6, -, 7, 8, 9, -, -, 4]    [5, 2, 3, 8, 9, 2, 1, 4]
                      ^               ^
                            8-4 = 4
[6, -, 7, 8, 9, -, -, -]    [5, 2, 3, 4, 9, 2, 1, 4]
 ^                                       ^
                            9-6 = 3
[-, -, 7, 8, 9, -, -, -]    [5, 2, 3, 4, 3, 2, 1, 4]
       ^                                    ^
                            2-7 = -5
[-, -, -, 8, 9, -, -, -]    [5, 2, 3, 4, 3,-5, 1, 4]
          ^                                    ^
                            1-8 = -7
[-, -, -, -, 9, -, -, -]    [5, 2, 3, 4, 3,-5,-7, 4]
             ^                                    ^
                            4-9 = -5
Final output: [5, 2, 3, 4, 3, -5, -7, -5]
```
**Test Cases**
`Input: [6, 4, 7, 8, 9, 2, 1, 4] => Output: [5, 2, 3, 4, 3, -5, -7, -5]`
`Input: [4, 7, 4, 9, -10, 8, 40] => Output: [14, 3, 0, 2, -18, -1, 0]`
`Input: [0.25, -0.5, 8, 9, -10] => Output: [10.25, 0, 7.75, 1, -19]`
`Input: [3, 4, 9, 1, 1, 1, -5] => Output: [8, 3, 8, 0, -2, -3, -14]`
---
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes win.

[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
_Ṣ
```
[Try it online!](https://tio.run/##y0rNyan8/z/@4c5F////jzbTUTDRUTDXUbDQUbDUUTDSUTAEisQCAA "Jelly – Try It Online")
or [Try all test cases](https://tio.run/##y0rNyan8/z/@4c5F/w@3P2pa4w3Ekf//R0eb6SiY6CiY6yhY6ChY6igY6SgYAkVidbiiIcImYGFdQwOwChMDkIyBnpEpUMxAzxSmDSgPkjCGqTeEIV3T2FgA)
```
_   # Subtract from...
 Ṣ  # The input array sorted
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 3 bytes
```
tS-
```
[Try it online!](https://tio.run/##y00syfn/vyRY9///aDMdBRMdBXMdBQsdBUsdBSMdBUOgSCwA "MATL – Try It Online")
```
(implicit input as an array)
t                              # duplicate
 S                             # sort
  -                            # element-wise subtract
(implicit output)
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
Ṡz-O
```
[Try it online!](https://tio.run/##yygtzv7//@HOBVW6/v///4820THXMdGx1NE1NNCx0DExiAUA "Husk – Try It Online")
**Explanation**
```
      -- input, e.g. [6,4,7,8,9,2,1,4]
   O  -- sort        [1,2,4,4,6,7,8,9]
Ṡz-   -- element wise difference to input: [6-1,4-2,7-4,8-4,9-6,2-7,1-8,4-9]
      -- return result [5,2,3,4,3,-5,-7,-5]
```
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~93~~ ~~80~~ 68 bytes
```
[H|T]/[A|B]/[X|Y]:-X is H-A,(T=[],Y=T;T/B/Y).
X*Y:-msort(X,S),X/S/Y.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/P9qjJiRWP9qxxglIRtRExlrpRihkFit46DrqaITYRsfqRNqGWIfoO@lHaupxRWhFWunmFucXlWhE6ARr6kToB@tH6gFNMdAzMtVR0DXQA5IWOgqWQLahQaxWhB4A "Prolog (SWI) – Try It Online")
[Answer]
# Ruby, 32 chars
```
->a{a.zip(a.sort).map{|x,y|x-y}}
```
[Answer]
# JavaScript (ES6), 44 bytes
```
a=>[...a].map(x=>x-a.sort((a,b)=>b-a).pop())
```
[Try it online!](https://tio.run/##Zc9LDoMgEAbgfU/BEhJmBB9VF3oR4wKtNm2sGDWNt7cwxk1NCGQG@Ph5m69Z2vk1rTDaR7f3xW6KskJEU@PHTHwryg0MLnZeOTeyEUXZgBE42YkLsbd2XOzQ4WCfvOfVXbJYslSyTLJcslAy7Tq1ECwIWJVQJ6IzbgZXQ@rX@vbnHEhMCGhFXqxORx/3FXGgMz@58qIoDP0TCpMzkLM8cijHtlNSTBNKCjq/INGZQ5/D5fUGIRklyYgBn8b/S8f1/gM "JavaScript (Node.js) – Try It Online")
### Commented
```
a =>                 // given the input array a[]
  [...a]             // create a copy of a[]
  .map(x =>          // for each integer x in the copy:
    x -              //   update x by ...
    a.sort((a, b) => //     sorting the original array in descending order
      b - a          //     (we only need to sort it once, but it's shorter to do it here)
    ).pop()          //     taking the element at the top of a[] and subtracting it from x
  )                  // end of map()
```
[Answer]
# Java 10, 83 bytes
```
a->{var b=a.clone();java.util.Arrays.sort(b);for(int i=0;i<a.length;a[i]-=b[i++]);}
```
Modifies the input-array instead of returning a new one to save bytes.
[Try it online.](https://tio.run/##dZBfa8IwFMXf/RT3McU2VKf7Q9bBPsB88VF8uG2ji4uJJNcOkX72LqYWBiqEQC7n5Hfu2WGD2a7@6SqN3sMXKnMeAShD0m2wkrC4PAEaq2qoWG2PpZarNWAiwrwdhcsTkqpgAQYK6DD7ODfooCyQV9oayRKxCxB@JKX5p3N48txbR6xMxMY6FlCgilyod@Rami19C1ypdVaUKzUerxPRduKCOQRywFxpMc8@pGVLcspsY6Q@KklPzMhfGMKen1OYpfCSwmsKbylMU5iESRtXuKfvxbMoziZ59M3yx/qcT@dBmfP5gAiux/Kn4e/JcLJ5e9Nn3DCa/5Xeb2h4xfD6/fLkSe65PRI/hCJIG3ZTN9m@pGC6YtruDw)
**Explanation:**
```
a->{                         // Method with double-array parameter and no return-type
  var b=a.clone();           //  Create a copy of the input-array
  java.util.Arrays.sort(b);  //  Sort this copy
  for(int i=0;i<a.length;    //  Loop over the indices
    a[i]-=                   //   Subtract from the `i`'th item in the input-array:
          b[i++]);}          //    The `i`'th item of the sorted array
```
[Answer]
# [R](https://www.r-project.org/), 18 bytes
```
(x=scan())-sort(x)
```
[Try it online!](https://tio.run/##K/r/X6PCtjg5MU9DU1O3OL@oRKNC87@ZgomCuYKFgqWCkYKhgsl/AA "R – Try It Online")
Does what it says :)
[Answer]
# Python 3, ~~42~~ 40 bytes
 ~~`lambda a:[b-c for b,c in zip(a,sorted(a))]`~~
```
lambda a:[a.pop(0)-b for b in sorted(a)]
```
[Answer]
# [Haskell](https://www.haskell.org/), 34 bytes
```
import Data.List
zipWith(-)<*>sort
```
[Try it online!](https://tio.run/##y0gszk7NyfmfmVuQX1Si4JJYkqjnk1lcwpVmG/O/KrMgPLMkQ0NX00bLrhgo/z83MTNPwVahoCgzr0RBRSFNIdpMR8FER8FcR8FCR8FSR8FIR8EQKBL7/19yWk5ievF/3eSCAgA "Haskell – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~8~~ ~~6~~ 4 bytes
```
í-Uñ
```
[Try it here](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=7S1V8Q&input=WzAuMjUsIC0wLjUsIDgsIDksIC0xMF0)
---
## Explanation
```
           :Implicit input of array U
c          :Flatten (simply creates a 2nd copy of the array because JavaScript's sort mutates the original array)
  í        :Interleave
    Un     :U sorted
   -       :Reduce each pair by subtraction
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 2 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
{-
```
[Try it online](https://tio.run/##MzBNTDJM/f@/Wvf//2gzHRMdcx0LHUsdIx1DHZNYAA) or [verify all test cases](https://tio.run/##MzBNTDJM/X9u66GVh9b9r9b9H3to9//oaDMdEx1zHQsdSx0jHUMdk1gdhWiQgAlQQNfQAChhYgASM9AzMtXRNdAzBSsFyoAEjcHKDMFQ1zQ2FgA).
**Explanation:**
```
{     # Sort the input-array
 -    # Subtract all values in this sorted array from the input-array
```
[Answer]
# Common Lisp, 46 bytes
```
(lambda(x)(mapcar #'- x(sort(copy-seq x)#'<)))
```
[Try it online!](https://tio.run/##Fcg7DoAgEAXAq7yEgt2CQkP8JF5mRQsSEAQLPD3GKccFX3OnXPz1gDoFifsh1JiiZCcFShs0qqk85FJ@TT1vNFZ6Y@auaYLFjAUrRgywf34)
[Answer]
# [J](http://jsoftware.com/), 4 bytes
```
-/:~
```
[Try it online!](https://tio.run/##NctBCsIwEEbhfU7xcBMEnU5qUttAz5JFMRQ3LrrWq6cxEGb3vX/eJR@roES03If4K1dzEWxexXLjG8mHMa9t/5CZ8DyZWRhx@M5/9BWT0xq9dlcZA0kltJdae3i0uWuXQjkB "J – Try It Online")
## Explanation:
From the argument subtract `-` the sorted `/:~` argument
[Answer]
# [Coconut](http://coconut-lang.org/), 23 bytes
```
a->map((-),a,sorted(a))
```
[Try it online!](https://tio.run/##PY7LDoMgEEX3fsUsuoBkIGChj4X@iHVBLCYmVYzgrv9OEUOT2cw5dzJ3cINb9hDH5hUNa2ezEsIoGvRuC/ZNDKUxWB88NNDdEBTCHeGB8ESoEWQiPUJ3YpUxkyInlDiM4LVOTHBdzpI/xLXkZRmm@6o6n31bSFUu5DP5AJzDSP9o3aYl5DU19/ts4w8 "Coconut – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 15 bytes
```
{@^a [[email protected]](/cdn-cgi/l/email-protection)}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJKmYPu/2iEuUSFK1yFRrzi/qKT2f3EiSEIj2kxHwURHwVxHwUJHwVJHwUhHwRAoEqtpzQVTAZE2AUvrGhqAVZoYxGr@BwA "Perl 6 – Try It Online")
Anonymous function that takes one list and returns a list.
[Answer]
# [Julia 0.6](http://julialang.org/), 12 bytes
```
A->A-sort(A)
```
[Try it online!](https://tio.run/##NY1BCsMgFET3nmKWCXyDJpq0ixY8h7gopAVDMOU3Pb8VizCrN2@Y7bvHx5z5lp28O/k5@Oxcn18HwyEmeD8TDGEhXAhXwkjQZAJB@D82FUutqmFUrdQw2gLVYNuuCLWZ2kK3SBsCxJtjOvfUcbnvxTOt@Qc "Julia 0.6 – Try It Online")
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 8 bytes
```
{x-x@<x}
```
[Try it online!](https://ngn.codeberg.page/k#eJxLs6qu0K1wsKmo5eJKt0pzSMiy50pXijbTUTDRUTDXUbDQUbDUUTDSUTAEisQqgeQgEiZgCV1DA7AaEwOInIGekSlQ1EDPFKYVqAIiZQzTYwhDuqaxSgAxlxpa)
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 9 bytes
```
íNc n
®r-
```
[Try it online!](https://tio.run/##y0osKPn///Bav2SFPK5D64p0//@PNtNRMNFRMNdRsNBRsNRRMNJRMASKxAIA "Japt – Try It Online")
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 5 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
ÿ◙┘¿N
```
[Run and debug it](https://staxlang.xyz/#p=980ad9a84e&i=[6,+4,+7,+8,+9,+2,+1,+4]%0A[4,+7,+4,+9,+-10,+8,+40]%0A[0.25,+-0.5,+8,+9,+-10]+%0A[3,+4,+9,+1,+1,+1,+-5]&a=1&m=2)
To show how it works, here's the unpacked, commented version.
```
m       for each element execute, then pop and print:
  xo    sort the original input
  i@    index into array using iteration index
  -     subtract
```
[Run this one](https://staxlang.xyz/#c=m+++%09for+each+element+execute,+then+pop+and+print%3A%0A++xo%09sort+the+original+input%0A++i%40%09index+into+array+using+iteration+index%0A++-+%09subtract&i=[6,+4,+7,+8,+9,+2,+1,+4]%0A[4,+7,+4,+9,+-10,+8,+40]%0A[0.25,+-0.5,+8,+9,+-10]+%0A[3,+4,+9,+1,+1,+1,+-5]&a=1&m=2)
[Answer]
# SmileBASIC, 49 bytes
```
DEF R A
DIM B[0]COPY B,A
SORT B
ARYOP 1,A,A,B
END
```
The input array is modified in place.
`ARYOP` does operations on entire arrays at once. In this case it subtracts `B` from `A` and stores the result in `A`.
[Answer]
# [PHP](https://php.net/), 86 bytes
```
function f($a){$b=$a;sort($b);return array_map(function($x,$y){return $y-$x;},$b,$a);}
```
[Try it online!](https://tio.run/##hc3dCoJAEAXg@55ikAF3YRQ17YetfJCKWMtQSF02BUV8dlssoYsgGOZiON8clalxFyuz7015rfOqhDtDyXtM9ijFs9I1w4QLndaNLkFqLbtLIRWb4wxbwo73nwB2DrZiIEzIfBHDmF6zCvJCPapbymyyyfw/rghCgjXBhmBLEBD45nLmHFywTqUlFj/Z24STcXxv4qH3l3luEBngudFcaPBftZyb/Hmc6BvFh/EF "PHP – Try It Online")
[Answer]
# [Tcl](http://tcl.tk/), 49 bytes
```
proc S L {lmap n $L m [lsort -r $L] {expr $n-$m}}
```
[Try it online!](https://tio.run/##HY07CsMwEER7nWIwbmUkR8rvDO5cmhTBpJNsISsQWPbsylpss/PmwZQ11JryvmLGBArxnbChnxCxhGPPBTpLfIE@vyTfpvvIXJsnvqIrHG6444ERFo4VndlJ1tYId0aQGUYPbQbfRCmEXZpk22nPikHpWw50Mv7EMp@rHdc/ "Tcl – Try It Online")
[Answer]
# [Factor](https://factorcode.org), 23 bytes
```
[ dup natural-sort v- ]
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PY4xDoJAEEV7T_EvsAQQFPUAxsbGWBmLDS5KhAWXWRJDOInNNngFz-JtXECdKebnvfxkHs-Ex1Qo8zb73Wa7XuIqlBQZck4Xpxa9q1AqQXQvVSoJlbhpIWNRoSoUpfKM1aSZwE6DGQLMEWEBH57N7Zf3NLCUea61gfsXruOHYK4TDqVe_8x0KHjDstDittOUsOh1wEmXkJy04hnrf0DNcBxtl_MSzpiNGe8H)
]


[Question]
      [
[Minesweeper](https://en.wikipedia.org/wiki/Minesweeper_(video_game)) is a puzzle game where mines are hidden around a board of nondescript tiles with the goal of identifying the location of all mines. Clicking on a mine loses the game, but clicking on any other tile will reveal a number from 0-8 which signifies how many mines directly surround it.
Given a number, you must display a random\* possible combination of empty tiles and mines surrounding it. This should be in the form of a 3x3 array. The center tile should be the number of mines taken as input.
\*Must have a non-zero chance for all combinations to occur.
---
## Examples
```
_ = blank square
X = mine
0
___
_0_
___
1
_X_
_1_
___
1
___
_1_
X__
___
_1_
__X
4
_X_
X4X
_X_
4
X_X
_4_
X_X
4
___
X4X
X_X
8
XXX
X8X
XXX
```
---
### Input
* The number of mines surrounding the center tile (0-8)
---
### Output
* Any reasonable form of output that displays the 3x3 array of tiles
---
## Other rules
* Each combination does not have to have an equal chance of happening. There just must be a non-zero chance of each combination to occur when executing your program.
* Any 2 characters can be chosen for the mine and empty tile.
* This is code golf, the program with fewest bytes wins.

[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 28 15 bytes
-13 bytes thanks to ngn!
```
{3 3⍴5⌽⍵,⍵≥8?8}
```
## Explanation:
`{...}` A direct function (D-Fn), `⍵` is its right argument.
`8?8` deal 8 random numbers from the list 1..8:
```
      8?8
7 2 1 8 4 6 5 3
```
`⍵≥` is the argument greater or equal to each of them?:
```
      5 ≥ 7 2 1 8 4 6 5 3
0 1 1 0 1 0 1 1
```
`⍵,` prepend the argument to the boolean list:
```
      5 , 0 1 1 0 1 0 1 1
5 0 1 1 0 1 0 1 1
```
`5⌽` rotate the list 5 positions to the left, so that the argument is in the center:
```
      5 ⌽ 5 0 1 1 0 1 0 1 1
1 0 1 1 5 0 1 1 0
```
`3 3⍴` reshape the list to a 3x3 matrix:
```
      3 3 ⍴ 1 0 1 1 5 0 1 1 0
1 0 1
1 5 0
1 1 0
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24RqYwXjR71bTB/17H3Uu1UHiB91LrWwt6gFSisYc6nrKgChOleagikS2xwA "APL (Dyalog Unicode) – Try It Online")
# [J](http://jsoftware.com/), 15 bytes
Also many bytes thanks to ngn!
```
3 3$5|.],]>8?8:
```
[Try it online!](https://tio.run/##y/qfVmyrp2CgYKVg8N9YwVjFtEYvVifWzsLewuq/JpeSnoJ6mq2euoKOQq2VQloxF1dqcka@QpqCEYShrqsAhOowUROsoub/AQ "J – Try It Online")
[Answer]
# JavaScript (ES6), 67 bytes
*Shorter version suggested by @tsh*
Empty slots are `0`, mines are `1`.
```
n=>`___
_${t=9,n}_
___`.replace(/_/g,_=>n-(n-=Math.random()<n/--t))
```
[Try it online!](https://tio.run/##DcpBDoIwEEDRPaeYhUnblIJLFYYbeAOToYGCEpyS0rghnL129d/iL/Zn9yF8tmjYjy5NmBi7nogKuhwR7yWfmUR9Fdy22sHJmuq5JOzYSDb4tPFdBcuj/0rVcm1MVCpNPkgGhGsDDC3CLVdrBUcBMHje/eqq1c/50SAeLxa5k2SlRbZqijP9AQ "JavaScript (Node.js) – Try It Online")
---
# Original trial-and-error version, 78 bytes
Empty slots are `_`, mines are `7`.
```
f=(n,o=`___
_${k=n}_
___`.replace(/_/g,c=>Math.random()<.5?--k|7:c))=>k?f(n):o
```
[Try it online!](https://tio.run/##FYtBDoIwEADvvGIPJrQpFC9GAxRe4A9MalMKKrhLCvGCvL3W08xh5mU@ZrH@Oa85UudC6BXDjNRda53owzYq3KNofZfezZOxjhW6GDKrmqtZH9Ib7OjNeC1PbZ6P33NpOVfN2PYMeUmhJ88QFBwrQKgVXCKF4LAlAJZwocnJiYbYCEjLG6aR/1Wk0XmV7OEH "JavaScript (Node.js) – Try It Online")
### Commented
```
f = (                         // f = recursive function
  n,                          // n = input
  o = `___\n_${k = n}_\n___`  // o = minesweeper field / k = backup of n
    .replace(/_/g, c =>       // for each underscore character c in o:
      Math.random() < .5 ?    //   random action:
        --k | 7               //     either decrement k and yield 7
      :                       //   or:
        c                     //     let the underscore unchanged
    )                         // end of replace()
) =>                          //
  k ?                         // if k is not equal to 0:
    f(n)                      //   try again
  :                           // else:
    o                         //   stop recursion and return o
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~13~~ 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
8Ẉ>RẊs4js3
```
The returned list of lists has the displayed integer in the centre surrounded by 0s and 1s representing mines and blanks respectively.
**[Try it online!](https://tio.run/##y0rNyan8/9/i4a4Ou6CHu7qKTbKKjf8fbo/8/98YAA "Jelly – Try It Online")** (footer pretty prints the array)
### How?
```
8Ẉ>RẊs4js3 - Link: integer, n                   e.g.  3
8          - eight                                    8
 Ẉ         - length of each (implicit range of eight) [1,1,1,1,1,1,1,1]
   R       - range of n                               [1,2,3]
  >        - greater than? (vectorises)               [0,0,0,1,1,1,1,1]
    Ẋ      - shuffle                                  [1,1,1,0,0,1,1,0]
     s4    - split into chunks of 4                   [[1,1,1,0],[0,1,1,0]]
       j   - join (with n)                            [1,1,1,0,3,0,1,1,0]
        s3 - split into chunks of 3                   [[1,1,1],[0,3,0],[1,1,0]]
```
[Answer]
# Pyth, ~~16~~ 14 bytes
```
c3jQc2.S.[d8*N
```
Saved 2 bytes thanks to isaacg.
Uses spaces for safe spots and quotes for mines.
[Try it here](https://pyth.herokuapp.com/?code=c3jQc2.S.%5Bd8%2aN&input=2&debug=0)
### Explanation
```
c3jQc2.S.[d8*N
            *NQ     Get (implicit) input number of quotes...
        .[d8        ... and pad to length 8 with spaces.
      .S            Shuffle.
  jQc2              Stick the input in the middle.
c3                  Split into three.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
<Ɱ8Ẋs4js3
```
[Try it online!](https://tio.run/##y0rNyan8/9/m0cZ1Fg93dRWbZBUb/z/c7v7/vzEA "Jelly – Try It Online")
empty = `1`
mine = `0`
Note that `1` and `0` are integers.
Another note: this is somewhat similar to Jonathan Allan's 10-byte answer, but it's not really influenced by it in any way, and the mechanism, if you pay close attention, is actually more different than at first glance.
[Answer]
# Oracle 18 SQL, 230 bytes
Not a golfing language but...
```
WITH v(v)AS(SELECT*FROM SYS.ODCINUMBERLIST(0,1))SELECT v.v||b.v||c.v||'
'||d.v||n||e.v||'
'||f.v||g.v||h.v
FROM n,v,v b,v c,v d,v e,v f,v g,v h
WHERE v.v+b.v+c.v+d.v+e.v+f.v+g.v+h.v=n
ORDER BY DBMS_RANDOM.VALUE
FETCH NEXT ROW ONLY
```
The input value is in a table `n` with column `n`:
```
CREATE TABLE n(n) AS
SELECT 7 FROM DUAL;
```
Try it online - log onto <https://livesql.oracle.com> and paste it into a worksheet.
Output:
```
V.V||B.V||C.V||''||D.V||N||E.V||''||F.V||G.V||H.V
-------------------------------------------------
101
171
111
```
To get all possible combinations (183 Bytes):
```
WITH v(v)AS(SELECT*FROM SYS.ODCINUMBERLIST(0,1))SELECT v.v||b.v||c.v||'
'||d.v||n||e.v||'
'||f.v||g.v||h.v
FROM n,v,v b,v c,v d,v e,v f,v g,v h
WHERE v.v+b.v+c.v+d.v+e.v+f.v+g.v+h.v=n
```
Output:
```
V.V||B.V||C.V||''||D.V||N||E.V||''||F.V||G.V||H.V
-------------------------------------------------
111
171
110
111
171
101
111
171
011
111
170
111
111
071
111
110
171
111
101
171
111
011
171
111
```
[Answer]
# Japt, 13 bytes
```
çÊú8 öÊi4U ò3
```
[Try it](https://ethproductions.github.io/japt/?v=1.4.5&code=58r6OCD2ymk0VSDyMw==&input=NAotUg==)
---
## Explanation
```
                   :Implicit input of integer U
 Ê                 :"l"
ç                  :Repeat U times
  ú8               :Pad right to length 8
    öÊ             :Random permutation
       i4U         :Insert U at index 4
            ò3     :Split at every 3rd character
```
[Answer]
# [QBasic 1.1](http://www.qbasic.net/), ~~206~~ 186 bytes
```
RANDOMIZE TIMER
INPUT N
O=N
Z=8-N
FOR I=0TO 7
IF O*Z THEN
R=RND<.5
O=O+R
Z=Z-1-R
A(I)=-R
ELSEIF O THEN
O=O-1
A(I)=1
ELSE
Z=Z-1
A(I)=0
ENDIF
NEXT I
?A(0)A(1)A(2)
?A(3)N;A(4)
?A(5)A(6)A(7)
```
-20 thanks to [DLosc](https://codegolf.stackexchange.com/users/16766/dlosc) (newly-posted golfing trick).
Empty = `0`
Mine = `1`
Note that `0` and `1` are integers, but I'm using STDOUT anyway, so...
Output appears like this:
```
 A  B  C
 D  x  E
 F  G  H
```
Where A-H are 0/1 and x is the input.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 19 bytes
```
Ｗ¬⁼ΣＩＫＡ⁸«Ｅ³⭆³‽²↑↗↖θ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/788IzMnVUHDL79Ew7WwNDGnWCO4NFfDObG4RCMgNTXbMSdHQ1NTU0fBAkgqVHNxBhRl5pVo@CYWaBjrKASXAHnpUE5QYl5Kfq6GEVChpjUXp29@WaqGVWgBMjsoMz2jBCQAMQUo4pOaVqKjUAgUq/3/3@S/blkOAA "Charcoal – Try It Online") Link is to verbose version of code. Uses `0` for a mine, `1` for an empty space. Explanation:
```
     ＫＡ             Peek the entire canvas
    Ｉ               Cast to integer
   Σ                Take the sum
       ⁸            Literal 8
  ⁼                 Equals
 ¬                  Logical Not
Ｗ       «           While
          ³ ³       Literal 3
         Ｅ          Map over implicit range
           ⭆        Map over implicit range and join
              ²     Literal 2
             ‽      Random element of implicit range
                    Implicitly print on separate lines
               ↑↗↖θ Print the original input in the middle
```
* `Peek` returns an array of strings, which `Sum` simply concatenates, which is why we have to cast to integer first. (`Sum(Sum(PeekAll()))` also works.)
* `Sum` returns `None` for an empty array (first loop), so the only safe comparison is `Not(Equals(...))`.
* Nilary `Random` always returns `0`, although its documentation says otherwise.
Alternative solution, was 19 bytes, now 17 bytes after a Charcoal bugfix:
```
θ←9Ｗ⁻ΣＩＫＡ⁸ＵＭＫＭＩ‽²
```
[Try it online!](https://tio.run/##HcoxDsIwDEDRnVN4tKWwIAZEJ9Q5UgUniEqkRjhxmyZwfGN1/f/NS6izBFb1nVtaayoN7w9mBxP3HTcHG9Fw@i2JI6BPxeKrZxzD3nCK8WMWicjBjQh8WEfJOZT38bxIjWjv0E/LkvFielC96vnLfw "Charcoal – Try It Online") Link is to verbose version of code. Uses `0` for a mine, `1` for an empty space. Explanation:
```
θ
```
Print the original input.
```
←9
```
Print a `9` leftwards. This moves the cursor back over the original input, and also forces at least one iteration of the while loop (otherwise an input of `8` would do nothing).
```
Ｗ⁻ΣＩＫＡ⁸
```
Repeat while the difference between the sum of all the digits on the canvas and 8 is nonzero:
```
ＵＭＫＭＩ‽²
```
Replace each of the surrounding characters randomly with `0` or `1`.
[Answer]
# [R](https://www.r-project.org/), ~~67 63 62~~ 59 bytes
```
matrix(c(sample(rep(1:0,c(n<-scan(),8-n))),n),6,5)[2:4,1:3]
```
[Try it online!](https://tio.run/##K/r/PzexpCizQiNZozgxtyAnVaMotUDD0MpAJ1kjz0a3ODkxT0NTx0I3T1NTUydPU8dMx1Qz2sjKRMfQyjj2v@l/AA "R – Try It Online")
Uses `1` and `0`. Build a `n* 1 +(8-n)* 0` vector, shuffles it, appends `n`, builds the bigger matrix shown below(where `a...i` stand for the elements of the original vector) and extracts the proper sub-matrix shown in uppercase:
```
     [,1] [,2] [,3] [,4] [,5]
[1,] "a"  "g"  "d"  "a"  "g"
[2,] "B"  "H"  "E"  "b"  "h"
[3,] "C"  "I"  "F"  "c"  "i"
[4,] "D"  "A"  "G"  "d"  "a"
[5,] "e"  "b"  "h"  "e"  "b"
[6,] "f"  "c"  "i"  "f"  "c"
```
[Answer]
# [Python 2](https://docs.python.org/2/), 93 bytes
```
from random import*
def f(n):a=[1]*n+[0]*(8-n);shuffle(a);a[4:4]=[n];return zip(*[iter(a)]*3)
```
[Try it online!](https://tio.run/##FY27DgIhEAB7v2JLFmPi4wqF3JcQCpJjvU28haxcoT@PWE0xyUz9tLXItXfSsoEmWQZ4q0WbPSyZgIygS3O4RCvHcI7W3E@C/r3uRK9sEvoUJjfFOUj0mtuuAl@uxgZuWYeP9oadigIDy//wzOaBDqqytJFn7D8 "Python 2 – Try It Online")
`0` for empty; `1` for a mine; and `n` for one's self.
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 51 bytes
```
{[3,3]&Rotate[Sample[{Sum@_=_2}&_\BinBelow@8]'_,4]}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fZmX7vzraWMc4Vi0ovySxJDU6ODG3ICc1ujq4NNch3jbeqFYtPsYpM88pNSe/3MEiVj1exyS29n9JcnRerIKVrYJGQFFmXkl0no6Ckq6dUqyCtbWCS2ZxQU5iZXQaUAlYAKIkVpOrJFnB1k7BwMriPwA "Attache – Try It Online")
## Explanation
Similar to [Galen's J/APL answer](https://codegolf.stackexchange.com/a/166070/31957), the basic technique is to generate an array of 1s and 0s with the correct number of mines, inserting the input by appending it to the end, rotating the array such that the input lies in the center, then reshaping into a 3x3 matrix.
### Part 1: generating the binary array
There are many ways to go about doing this, but I mainly happened across two types: brute force and selection.
The primary brute force method looks like this:
```
NestWhile[{Random[8&2]},0,{Sum@_/=_2}&_]
```
This generates random arrays of 8 binary digits (`Random[8&2]`) while their sums do not equal the input `{Sum@_/=_2}&_`. This is a bit verbose, as the following emphasized portions of the code are there "just to make it work":
```
NestWhile[{Random[8&2]},0,{Sum@_/=_2}&_]
          ^           ^^^^^        ^^^^
```
And I discarded the idea.
Selection is more interesting. The main concept is to use the `BaseBelow[b, n]` builtin, which generates a list of all base-`b` integers of width `n` (as digit arrays), from `0` to `b^n-1`. For example, `BaseBelow[3, 2]` generates all ternary integers of width 2:
```
A> BaseBelow[3, 2]
 0 0
 0 1
 0 2
 1 0
 1 1
 1 2
 2 0
 2 1
 2 2
```
We specifically use `BaseBelow[2, 8]` for all binary integers of width 8. These represent all possible minefields of all lengths. This is the first step.
The second step is selecting all such arrays with only `N` 1s, where `N` is the input. My first idea was to translate this English statement directly into Attache:
```
Chunk[SortBy[Sum,BaseBelow[2,8]],Sum]@N@1
```
However, not only did this come out to be 1 byte longer than the aforementioned approach, it's also highly repetitive—and it isn't even randomized yet!. Sure, I could probably save 1 byte by reorganizing how `BaseBelow` is called, but it simply isn't worth using the approach.
So I decided to kill two birds with one stone and use a `Shuffle` based approach. The following gives all valid minefields of length `N` in random order:
```
{Sum@_=_2}&N\Shuffle[BaseBelow&8!2]
```
Then, all that needs to be done is to select the first. But I can do better—surely it'd be better to simply `Sample` the filtered array? This approach comes out to be something like this:
```
Sample[{Sum@_=_2}&_\BaseBelow[2,8]]
```
I had to revert the `BaseBelow&8!2` golf because `\`s precedence is too high. Otherwise satisfied, I proceeded to chop a byte off of that:
```
Sample[{Sum@_=_2}&_\2&BaseBelow@8]
```
(I discovered another way to succinctly call a dyadic function here: `x&f@y` is a high-precedence expression which evaluates to `f[x, y]`.)
However, despite this, I remembered that, all along, an alias for `2&BaseBelow` existed: `BinBelow`. So I used that:
```
Sample[{Sum@_=_2}&_\BinBelow@8]
```
This generates the desired minefield. I'm convinced this is near optimal.
### Part 2: Forming the array
As said earlier, the forming technique I used is similar to the J/APL answer, so I won't go into too much detail. Suppose `MINEFIELD` is the result from the last section. The function then becomes:
```
{[3,3]&Rotate[MINEFIELD'_,4]}
```
`MINEFIELD'_` concatenates the minefield with the original input `_`, giving us something like this:
```
[1, 0, 0, 0, 1, 0, 0, 1, 3]
```
Then, `Rotate[MINEFIELD'_,4]` rotates this list `4` times to the left, placing the center:
```
[1, 0, 0, 1, 3, 1, 0, 0, 0]
```
The last step is using `[3,3]&` to reshape the list into a 3x3 matrix:
```
 1 0 0
 1 3 1
 0 0 0
```
[Answer]
# Java 10, ~~165~~ ~~157~~ 141 bytes
```
n->{var r="___\n_"+n+"_\n___";for(int i;n>0;r=r.charAt(i*=Math.random())>58?r.substring(0*n--,i)+(i>9?0:0+r.substring(i+1)):r)i=11;return r;}
```
Empty tiles are `_` (any character with a unicode value above 58 is fine) and mines are `0`.
[Try it online.](https://tio.run/##TZBBbsIwEEX3PcUoKxs3UbJAorgO6gFgw7JUkQmhDIUJjB2kCnH21CRpqWRbHn/rz/uztxcb7zdfbXmwzsHcIl2fAJB8xVtbVrC4lwBLz0ifUIqgAEkdHm9hh@W89VjCAggMtBTn14tlYBMVRbGiIlKkovulKCK9rbkzQE15qtlwUu4sv3mBIzO3fpewpU19FFLm48mME9esXddYpCOK42eUSmD@MkunqfqvosqknLJEk2WaK98wAetbq3vEU7M@BMSB9FLjBo4hqOhDvX@AlX1KXzkv0i4dwB@syTTg6yQcSslOeohnM9ZwjuMQB361wQcHn66YDCN7DKzD6D/emwwEy2/nq2NSNz45BTh/IEFJmLpU0YqiweTW/gA)
**Explanation:**
```
n->{                           // Method with integer parameter and String return-type
  var r="___\n_"+n+"_\n___";   //  Result-String, starting at:
                               //   "___
                               //    _n_
                               //    ___"
  for(int i;n>0                //  Loop as long as `n` isn't 0 yet:
      ;                        //    After every iteration:
       r=r.charAt(i*=Math.random())
                               //     Select a random integer in the range [0,11)
         >58?                  //     And if the character at this random index is a '_':
          r.substring(0*n--,i) //      Set `r` to the first part excluding character `i`,
                               //      (and decrease `n` by 1 in the process)
          +(i>9?0:0+           //      appended with a '0',
           r.substring(i+1))   //      appended with the second part
         :                     //     Else:
          r)                   //      Leave `r` unchanged
     i=11;                     //   Set `i` to 11 so a new random integer can be chosen
  return r;}                   //  Return the result
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 77 bytes
```
param($n)-join(0..7|random -c 8|%{'X_'[$_-ge$n]
$n[++$i-ne4]
'
'*($i-in3,5)})
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfmvkqZgq1D9vyCxKDFXQyVPUzcrPzNPw0BPz7ymKDEvJT9XQTdZwaJGtVo9Il49WiVeNz1VJS@WSyUvWltbJVM3L9UklkudS11LA8jJzDPWMdWs1fxfy8UFNAGki0sBCNSAlqjEg5nq6ly1/wE "PowerShell – Try It Online")
[Answer]
# [PHP](https://php.net/), ~~135~~ ~~134~~ ~~123~~ ~~117~~ ~~122~~ 121 bytes
Looping over str to print instead saves 1 byte
str\_split and implode to insert the centre number saves 11 bytes
~~Don't need to assign the string to $s anymore saving 6 bytes~~
Yes you do. Otherwise the string is shuffled after every echo...
Removing whitespace after echo saves 1 byte
Replacing "\n" with an ctual line break saves 1 byte
```
$n=$argv[1];$s=implode($n,str_split(str_shuffle(str_pad(str_repeat(m,$n),8,n)),4));for(;$i<9;)echo$s[$i].(++$i%3?"":"
");
```
[Try it online!](https://tio.run/##HcZBCsIwEEDRvccII2RoFKQu1LT0CB6glBJs2gTazJBEj2@Ubv5/7Lg0Hf8LoQUTl09/GTSk1m@80mQlBJVyHBOvPstd7j3Pq93NZtofLVuT5aYgoLqpgKiuiHqmKDX45q7RvhxB6sEPZ1lV4I91J8RDHATqUkr9Jc6eQiqnKTmKeSS2YcxmaZ/hBw "PHP – Try It Online")
[Answer]
# [Alice](https://github.com/m-ender/alice), 24 bytes
```
a8E/be?SZ!@
~E-\ita*.o/a
```
[Try it online!](https://tio.run/##S8zJTE79/z/RwlU/KdU@OErRgavOVTcmsyRRSy9fP/H/f2MA "Alice – Try It Online")
Empty slots are `9`, and mines are `0`.
I also made a 27-byte program with `1` for mines and `0` for empty slots:
```
a8Ea8/be?SZ!@
-E-9:\ita*.o/
```
[Try it online!](https://tio.run/##S8zJTE79/z/RwjXRQj8p1T44StGBS9dV19IqJrMkUUsvX///f2MA "Alice – Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 81 bytes
```
f(n,i,j,k){for(j=i=8,k=n;--i+5;putchar(i%4?i-2?rand()%j--<k?k--,88:95:48+n:10));}
```
[Try it online!](https://tio.run/##VcxBCoMwEADAu68IgrBLsmCLQjQG3yIptpvQWFJ7Et@e5lToeWAc3Z3LeYWoWHkV8Fi3BN6y1SrYaIhY9ub12d1jScBNNzNd57TEG2DjiaYwByKl9Tj0Y6dlHC8tojnzc@EIeFSlE8BxF2xbw9NgWEpVvjfUNWIlfu6L@@L@38UKjKY68xc "C (gcc) – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~91~~ 86 bytes
-5 bytes thanks to mazzy
```
param($n)$x=,'X'*$n+,'_'*(8-$n)|random -c 8
-join$x[0..2]
$x[3,4]-join$n
-join$x[5..7]
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfmvkmZb/b8gsSgxV0MlT1OlwlZHPUJdSyVPW0c9Xl1Lw0IXKFpTlJiXkp@roJusYMGlm5WfmadSEW2gp2cUywVkGOuYxEIE8@CSpnp65rH/a7m4gKosalSruTjVVNIUVOK5OJWUuDhr/wMA "PowerShell – Try It Online")
Shuffles a generated string ranging from `________` to `XXXXXXXX` (replacing from the left). It then slices through it multiple times, inserting `$n` in the middle, to build the output string. This last part can probably be greatly optimized because each index costs a minimum of 5 bytes.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 59 bytes
Returns a list of strings (one for each line).
```
->n{a=([0]*(8-n)+[1]*n).shuffle;a[4,0]=n;a.join.scan /.../}
```
[Try it online!](https://tio.run/##BcFNCoUgFAbQrTTUfr4MGgRhGzEH90WSEbfIHES1dt85Z/zdyekxVQM/pIVRNhddxbIwjc1ZIizRuW3uybSlspp7wrp7RpiIsxpA/SWhgE5ipml5Xv8e8QqZM96Wx5f@ "Ruby – Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/) `-pa`, ~~105~~ 101 bytes
```
@o=grep!/^....1/&&y/1//=="@F",map{sprintf"%09b",$_}0..2**9-1;$_=$o[rand@o];s/....\K./@F/;s/...\K/\n/g
```
[Try it online!](https://tio.run/##K0gtyjH9/98h3za9KLVAUT9ODwgM9dXUKvUN9fVtbZUc3JR0chMLqosLijLzStKUVA0sk5R0VOJrDfT0jLS0LHUNrVXibVXyo4sS81Ic8mOti/VBRsR46@k7uOlDeDHe@jF5@un//5v8yy8oyczPK/6v62uqZ2Bo8F@3IBEA "Perl 5 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 12 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
$×8j.r2äIý3ô
```
Uses `0` for mines, spaces for blank squares. Outputs a list of lines, which is pretty printed in the TIOs below by joining with newline delimiter (`»`).
[Try it online](https://tio.run/##yy9OTMpM/f9f5fB0iyy9IqPDSzwP7zU@vOX/od3/TQA) or [verify a few more test cases at once](https://tio.run/##ATAAz/9vc2FiaWX/N0w10Lh7MMWhOMKqdnn/MHnDlzhqLnIyw6R5w70zw7T/PcK7LMK2P/8).
**Explanation:**
```
$             # Push 0 and the input-digit
 ×            # Repeat the 0 the input-digit amount of times as string
              #  i.e. 4 → "0000"
  8j          # Prepend spaces to make the size 8
              #  → "    0000"
    .r        # Randomly shuffle the characters in this string
              #  i.e. "    0000" → " 00 0  0"
      2ä      # Split it into two equal halves (of 4 characters)
              #  → [" 00 ","0  0"]
        Iý    # Join it with the input-digit
              #  → " 00 40  0"
          3ô  # And then split it into (three) parts of 3 characters
              #  → [" 00"," 40","  0"]
              # (which is output implicitly as result)
```
**12 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage) alternative:**
```
[[email protected]](/cdn-cgi/l/email-protection)š5._3ô
```
Uses `1` for mines, `0` for blank squares. Outputs a matrix of digits, which is pretty printed in the TIOs below by joining each row, and then these rows with newline delimiter (`J»`).
[Try it online](https://tio.run/##yy9OTMpM/f/fwsdBr@hRw6zTc0z14o0Pb/n/3xgA) or [verify a few more test cases at once](https://tio.run/##ATIAzf9vc2FiaWX/N0w10Lh7MMWhOMKqdnnDkP84TEAucuKAmsucNS5fM8O0/z1KwrsswrY//w).
**Explanation:**
```
8L            # Push the list [1,2,3,4,5,6,7,8]
  @           # Check for each if the (implicit) input-integer is >= it
              # (1 if truthy; 0 if falsey)
              #  i.e. 4 → [1,1,1,1,0,0,0,0]
   .r         # Randomly shuffle this list
              #  i.e. [1,1,1,1,0,0,0,0] → [0,1,1,0,1,0,0,1]
     Iš       # Prepend the input-digit to the list
              #  → [4,0,1,1,0,1,0,0,1]
       5._    # Rotate the list five times towards the left
              #  → [1,0,0,1,4,0,1,1,0]
          3ô  # And then split it into (three) parts of 3 digits each
              #  → [[1,0,0],[1,4,0],[1,1,0]]
              # (which is output implicitly as result)
```
]


[Question]
      [
 This was inspired by a function I recently added to my language [Add++](https://github.com/SatansSon/AddPlusPlus). Therefore I will submit an short answer in Add++ but I won't accept it if it wins (it wouldn't be fair)
Don't you hate it when you can multiply numbers but not strings? So you should correct that, right?
You are to write a function or full program that takes two non-empty strings as input and output their multiplied version.
How do you multiply strings? I'll tell you!
To multiply two strings, you take two strings and compare each character. The character with the highest code point is then added to the output. If they are equal, simply add the character to the output.
Strings are not guaranteed to be equal in length. If the lengths are different, the length of the final string is the length of the shortest string. The input will always be lowercase and may contain any character in the printable ASCII range (`0x20 - 0x7E`), excluding uppercase letters.
You may output in any reasonable format, such as string, list etc. Be sensible, integers aren't a sensible way to output in this challenge.
With inputs of `hello,` and `world!`, this is how it works
```
hello,
world!
w > h so "w" is added ("w")
o > e so "o" is added ("wo")
r > l so "r" is added ("wor")
l = l so "l" is added ("worl")
d < o so "o" is added ("worlo")
! < , so "," is added ("worlo,")
```
So the final output for `hello,` and `world!` would be `worlo,`.
# More test cases
(without steps)
```
input1
input2 => output
programming puzzles & code golf!?
not yet graduated, needs a rehaul => prtgyetmirgduuzzlesneedsde rolful
king
object => oing
blended
bold => boln
lab0ur win.
the "super bowl" => the0usuwir.
donald j.
trumfefe! => trumlefj.
```
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so shortest code wins! Luok!

[Answer]
## PowerShell, 75 bytes
```
-join(1..(($a,$b=$args)|sort l*)[0].length|%{(,$a[$_-1],$b[$_-1]|sort)[1]})
#            ^input array unpack
#       ^string index generation offset by 1
#                         ^sort by length property, so output length matches shorter input
#                                           ^loop over indices
#                                       max of the two characters^
# ^output join
```
Save as .ps1 file and run
```
PS C:\> .\Get-MultipliedString.ps1 'hello,' 'world!'
worlo,
```
Previously, 78 bytes:
```
$i=0;-join$(while(($a=$args[0][$i])-and($b=$args[1][$i++])){($a,$b)[$b-gt$a]})
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 22 bytes
Takes two (or more!) strings as right argument.
```
{‚éïUCS‚åà‚åø‚éïUCS‚Üë‚çµ‚Üë¬®‚ç®‚åä/‚â¢¬®‚çµ}
```
[Try it online!](https://tio.run/##VY1NbsIwEIX3nGJgQTZQuEEXPULFAWxmEgITj@XYQgF1i1oUEF30Al1xAdZIPYovQt2qFcpm5knf@1GWx9goluJ2qwL70nITd6dtPH7Mnp5j@xrb65/evcfDJd2vczycY7ufxLfPH315uUchK40NPvv/vd6dWCeFU1VVmgJs2GyYahjCXJCgEM77jyllxENDHpIRg/KEIzBEWIMCRwsVuNO4SlUpJHpJ8@6WZjJImKAWxg5ipafBwbo0Dwn7BcGgDpYcaFnzoGNFMYoRlr9GF6qccupn3w "APL (Dyalog Unicode) ‚Äì Try It Online")
`{`‚ÄÉan anonymous function where the right argument is represented by *‚çµ*
‚ÄÉ`‚éïUCS`‚ÄÉthe symbols from the **U**nicode **C**haracter **S**et which correspond to the
‚ÄÉ`‚åà‚åø`‚ÄÉmaximum value in each column of
‚ÄÉ`‚éïUCS`‚ÄÉthe code points from the **U**nicode **C**haracter **S**et for the
‚ÄÉ`‚Üë`‚ÄÉmatrified (matrix from list of strings)
‚ÄÉ`‚çµ`‚ÄÉarguments
‚ÄÉ`‚Üë¬®‚ç®`‚ÄÉeach capped at the
‚ÄÉ`‚åä/`‚ÄÉminimum of
‚ÄÉ`‚â¢¬®`‚ÄÉthe lengths
‚ÄÉ`‚çµ`‚ÄÉof the arguments
`}`
[Answer]
# [Aceto](https://github.com/aceto/aceto), 43 bytes
```
]w(x^
o|p
d(
do
X0l)x
`=`X(
‚Ç¨(=0p
rr‚Ç¨l<
```
### Explanation:
First, we read the first string, and explode it, then we move a stack to the left, read the second string, and explode it:
```
‚Ç¨(
rr‚Ç¨
```
Now, we check for emptiness of either of the stacks and exit if that is the case:
```
X0l)
`=`X
  =0
   l
```
Next, we duplicate the top letter of both stacks, and convert them to code points, then move them both (and us) on the right stack:
```
]
o
d(
do
```
The `w` tests if something is less or equal. If so, we get mirrored to the right. Otherwise, we print the top letter, go on the left stack, drop the top element (the other letter) and move up (`^`), which moves us on the bottom `<`, which moves us back to the length check.
```
 w(x^
 |p
```
If however, the test was truthy, we get mirrored into the emptiness on the right, and we need to do the opposite. Eventually we reach the three commands that now drop, *then* move to the left stack and print *its* top element. The `<` is the same symbol we land on in the other case, so here too we are lead back to the length check.
```
x
(
p
<
```
This repeats until one of the length checks succeeds, i.e. if one of the input strings is exhausted.
[Answer]
# k, 14 bytes
```
{|/(&/#:'x)$'x}
```
Examples:
```
k)F:{|/(&/#:'x)$'x}
k)F("hello,";"world!")
"worlo,"
```
[`q`](http://code.kx.com/q/ref/card/) translation:
```
{max(min count each x)$/:x}
```
Free interpreter available [here](https://kx.com/download/)
[Answer]
# [J](http://jsoftware.com/), 22 bytes
```
0({"1\:~@,"0/)<.&#$&>;
```
[Try it online!](https://tio.run/##HczNTsMwEEXhfZ/iNqAYpCgNXTZQWLHiESohO578MfVEjq2IIvHqwWR79OmM69ri5YTq4Sd7upx@34qsOjw@l/ndfX6udztqesHHO0YZ3Bz84Dp8HtHm5flwgeqJWQpVq0U8271CDTV56by@Xv/pFG83phk5GrGETrjdvybuJOCbAhK0UQeyBRyRnaHhqdeRt9NXWiQsZqQmbMUwOUs2RSNst8TaVNFjGVyZcugJ2Rwn8jCycKbW9Q8 "J ‚Äì Try It Online")
## Explanation
```
0({"1\:~@,"0/)<.&#$&>;  Input: string x (LHS), string y (RHS)
                 #      Get length of x and y
              <.&       Minimum of those
                     ;  Link x and y as a pair of boxed strings
                  $&>   Shape each to the minimum length
         ,"0/           Reduce by joining elementwise
     \:~@               Grade down each pair
0 {"1                   Select the value at index 0 from each
```
[Answer]
# Java 8 + Eclipse Collections, ~~70~~ 64 bytes
```
a->b->a.zip(b).collect(p->(char)Math.max(p.getOne(),p.getTwo()))
```
`a` and `b` are both `MutableList<Character>` from eclipse collections.
[Answer]
# Java, ~~158~~ 151 bytes
Golfed:
```
String s(String a,String b){String r="";for(int i=0;i<Math.min(a.length(),b.length());i++){char c=a.charAt(i);char d=b.charAt(i);r+=c>d?c:d;}return r;}
```
Ungolfed:
```
String s(String a,String b) {
    String r = "";
    for(int i=0; i < Math.min(a.length(),b.length()); i++) {
        char c = a.charAt(i);
        char d = b.charAt(i);
        r += c > d ? c : d; //absolute ternary abuse
    }
    return r;
}
```
Takes two strings in `a` and `b`.
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 55 bytes
```
[A|T]*[B|U]-[C|R]:-(A>B,C=A;C=B),T*U-R.
[]*_-[].
_*L-L.
```
[Try it online!](https://tio.run/##jc1BboMwEIXhfU4xyaIiyEZdt0ojYJsVSVYIgYknQDp4kDFCjXJ36vYE7N/3v8EycSPHuVuWPH5dijBPXtdC5ukrKz5kEH8lIj3En@kh2YtLeJVZtMmLsJR5EW3K8CRP0XKUULVIxKIKq5kt6W0lMwGjs51pylur7BicBWR7AbPtHJIJzvto8@cGy41Vfe@HMEzPJ@EIb3BjjdAw3bdHnzTs4Acd@KGelEMtwCDqERRYbNVEq9@@/cIHuX7gza1WNaHRqD2smfRqRqp@nyzMnYk8dS3CbpwGtFDzTLvVGc1GkYbHf8RO/R3vuF3Fl18 "Prolog (SWI) ‚Äì Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 9 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
Can't seem to do better than 9. Takes input as a 2D array of characters, outputs an array of characters
```
√±√ä√ïf√é√ã√± √å
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVA&header=Tm1x&code=8crVZs7L8SDM&input=ImhlbGxvLCIKIndvcmxkISI) (header formats the input)
```
√±√ä√ïf√é√ã√± √å     :Implicit input of 2D array
√±             :Sort by
 √ä            :  Length
  √ï           :Transpose, padding the shorter array with null if necessary
   f          :Filter by
    √é         :  First element (removing the arrays that contain null)
     √ã        :Map
      √±       :  Sort
        √å     :  Last element
```
[Answer]
# [Knight](https://github.com/knight-lang/knight-lang/), ~~70~~ ~~51~~ 48 bytes
```
;=aP;=bP W&a b;O+A I>a bAaAb"\";=aGa 1La=bGb 1Lb
```
[Try it online!](https://tio.run/##rVlRU9tIEn62f8XgFLbGlhNZcFVbNrKLZIGilgALyeUBfIksj7HqZMknybCEsH89190zI41sk7vcLQ@WNfN1T/c3Pd09JujeBcH3V2EcRKupOMjyaZi8ng/r5kgUTipDQf64FGugNIzvKkN5uJCYqZiFsWBRxKIkvqOPejH64fzje9YrX68/XDG3fP374RXbL1@Pz9@xX8rXq4@sV4KPz64N7PnHMwP68fz94fVvVsaZhR9N9mfvb7yYPbyGZeVkMPdT1ualgIkCWwsVwyHbL@fOjz7hZAyT5NE3ht8PDtYwuAxh0E3ARBFHYAXz9uLijED4MSIn@@ibYcjViQSAvGHrvR@tBOc38ZjX6@QH7MrN2LtqHF0cW98Hnn858CaX7FPTZ5PBReeQnQ7h26F/OGncNmD6xGe9M9@bnEzgOfnOQawxkJraoEr4C@ahzkG9Dgsv/TQTFmdP9VoY5ywc1GswSkbYrD1bxQGMkHAA7/liaWfL@MYde0@O7TyDjloI6ggPTwcH3rxB9eGSPczDXGRLPxD1GnyPhAXjIG5JM2zWuM1v49vZbcqenm/GFu@/anAypRbOmFVY67HWqxZnUoUe3YHR2xiGOx05AnbWRJQJc@BZmhPMRfBPNktSFq8WE5Fmyh5mhdk0vAtzrRVWR3d6duGRfLZZz2Ed1laWdzqcdVnLacESaGnIWSryVRozHTZSjCJnsG7DvZ@G/iQS2gowIkoeRGoFsJ42hH37xrRxAb0FRMTnFlf0hFtcD72eDXvkFcNr1uFBVAELkHi6Wlq4pUxx2mXwtmmwTAuZ1CbNuG21SpsaLblpIAweFEYxUAJpBL6DZUs/y1k@F6DMT3MAqw1oa0ZxQwOOnmhjjdP1orHw2eO00bWSDDIfQzcPkxjMxoh1xmBaoBnJVsslEs51VOkRk34z/oB2g2zUoUN5GUMcQ0rDyFWWS1Y@tIpzLweOcQDTWx/TGpqpg4wyonTVQrvRVD@KksDad@weRwdxuHCCHIxXUeSnj6aj5f5cGdtz2SosowWV/Cpek6YleriESgrbPD08evvuy@87Z79eGA6baifhVr3upt6diuKT0@sXNOYiJZV@PGX/Wvn6FdXem0vsbS4hCThpFVycbuGChPerwlXMM6XKdBXjDg1UWm7nSWbpXEkHAEI7DwNGs5PV7MbdHys75EY3KT0UBmRLOFb5zAIo@L8bRdOGzjtUlmxUsq4ADkWhQBY8uX4Fd8B6e1U/0XmMxRFr5OlKNCAGi3EMSRif@ZBBcKKBkdUoSUA/0XdVmYiOz2@TJIKZSZWBF30t3fqRQ@2f98g0c7JhZoQ2xn@pjRC0eRJFlmmqzRwbKsT/YHK8YTJW4feHl@c21mIZaPB6etNzHAfCCVyBV/2WhV/F55zhY2DEqOEtMgBvNn649Lnn9XRJxwyHVR0f9OnKxx4Ajk/PjtpsBslxUCtCW62HaTjwl3YkYuoADK504yQ5g3P3EhnrglibsLRhwbFC6iWgFh8QFwMoKiFOFnkjWCzXdoBICsdlCkGawjEukz2EeTC32sDMRp8FHDH1F2Cdah22@gxXkQAPCcVODbIwb5JTSr3qFSshywdUhUsENaR5iqWLetKbMX8qwwwaKMrtcuErWLiqO4WMZ/Gm88cM/0rkJSBBq@ToTuQRtJNWk/ayiTuEJXIaxnwQziyL9hMbgmCeoi02xCnncps9Z7DVVnhwagPkekdyPdk5YjZQhAy0vUiSyp2llW9LfyS@mHlXzqCkSXGB@QIYjAaIP2@ZLEVsGQvbjbRBrQJY5S1kpYR49Fxn/xcaV82FJTuSGZg@RaeghYOQtbG/Azj0DvSGa8DSOrwsGGQdj1ohPLGA5Ipu0ENrEdWooe0x1@xZShpLT34HT8Qf0Mbhad/wc6ey63Rr2MFMtgE82wgPWCWq8mLAf231VZ@4JZCLzKcqUOOc2mILaxDXRWg43OdlY7mRDrXoNTWH1m6GgtXDsCkMdELrY64LmZQ3SqiewPIi/FipfamEqZpl7oDKLYqFi5IFPBjy4oOkyf2sUMeaTbpqdbsIHcs295ba7Zo2a/d1OwN7LHjjTB@11DB/lWd694uYkL2eNKhTGER5EvIlpmQMLWN7ZDddq@62vLciGvp@pmPJlXuO/S8dBrkBhMJhPOWe9tLl20M18HP9UF1nr1PSxPV31MWhG7XpmascofzqbkSnEe3YqlftlULtcne2sLBenrfw0N7gQe7rNhYWW1xrE8YzlZAA1CCLMqTXuoVLHoIG3S7pU0RRyVzfaMloXjn9b35IzJvtxOz@UGh3u9A/iM2KQ/LqQGOu6eVA0S5Z91i3V7BMWKC@B@es24Mz1jPB7k@iDyA9VrCeh1Bat69HHE05Ee0OHcW1y6ldaXvEf339QNAkuQJ3BEqwWGLgO14Z5iIVrYzFCfTQYZSHMXvwH4E3Nk3gTpqLO5GCzDKJRZyHPt4i4CQn7EGwuX8vAKgUITxnCz9eQfg8vsZR9G6CjAMVxES2inL80YAWLxKehnRNjF5yjTJTroCsqUd9LyOdlw0pYAcVlEP3cz/C2vgIXsfTSEzZl9LsL4WWJ/wmGzNjkdKZISrrdvU7J3hNQduG6c9FHjygYF0rfJj0KnnRq2bFETMP/4F5DFC0r36RazIJGLFKo0iDNjOyIepwpKQuua6sA4jd8aDaGF3QEA4lhlYyTfpsIRbBEsMsZsMvo//XleFf4MpQu7KzxRdP@aJcGb3Mvlx1i8k4PWIVgFsgXF1Ad7bZWb4U7unMYyoozGuW6Q992VYbRqakSiWF/Lf/Rl7lIENNIT9o9U10pc1dx3pl1q1O//RFRve25U0GcbXKbaZIhYRBjWOvIm2kSZRARKdTiEmTP4F78lcvs9GseMfM3kWJnVa7doQa8iO3v2fQciKvDJ7RYXXMArR5R4rVxcMuzsJepaG9lkSvKR2slzx3W8nb40Uf4BbS@zT4HxoiNAyfuBVB0fwX7ZDZG7ngIa7a6WGTRA2CjH85SQ9CdNRJgNWnYuZDkgTPdIcZxjAZTulHJD/IoUy1doMW9pw4wtkLt1hUVtRA6AbVDwkLP4yxWWV@ehfYpLTdhu/3HH@uovsl/oPHcsia6jXu@fsyTe5Sf7GA/h46269fI5HB0Q@SqWB3STTbGdXjJGePImcAm@Ivc1ObxUJMM@bDBs/BtX8D)
Ungolfed & explained:
```
; = a PROMPT                                  # a = input()
; = b PROMPT                                  # b = input()
: WHILE & a b                                 # while a != "" and b != "":
    ; OUTPUT + ASCII IF > a b ASCII           #
               a ASCII b "\"                  #    print(a[0] if a > b else a[1]) # (without newline)
    ; = a GET a 1 LENGTH a                    #    a = a[1:]
    : = b GET b 1 LENGTH b                    #    b = b[1:]
```
-19 bytes thanks to Adam.
-3 bytes thanks to Bubbler.
[Answer]
# [Go](https://go.dev), ~~131~~ 121 bytes
```
func f(a,b string)(o string){
if""==a||b==""{o=""}else{A,B:=a[:1],b[:1]
if A>B{o+=A}else{o+=B}
o+=f(a[1:],b[1:])}
return}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=XZBBasMwEEXp1vQQEy2KTd3Q7ErALckJug8FS9bIcSJrjCwREscn6SYUeogepT1N5aSF1ps_A__N10evbyWdPhpebHmJUPPKRFXdkHVTpmrH3r1Tdw-fe-VNASrmqYDW2cqUSUy_WxdVirEs48ejyDLGOgrSo26xW6TLecZX89lLKgYNJCwelx3dZosLEbZlHwUN4avZfOCCJn1k0Xlr-kuBr6vrc4OhX5xAFz2Hl502sYrZGrWmlEEKbEdWywlLkj9-3lgqLa_rUBUafzhobOEGCpIIJWk1ecrT3JCDPToIoPTcoUzBIMoWOFhcc6_z_5nbEBbOSGywcCNPaDQSZbAFaTkyNRf33sKuMtMAuDUCa32DFgTtNBvBkgzXEjZn1PpaocIB-fmU0-kyvwE)
* -10 by @The Thonnu
[Answer]
# [Rust](https://www.rust-lang.org), 34 bytes
```
|a,b|a.zip(b).map(|(i,j)|i.max(j))
```
which takes in two iterators over `char`s and returns another. This only works by shunting the following obscene type into the header code:
```
for<'a> fn(std::str::Chars<'a>, std::str::Chars<'a>) -> std::iter::Map<std::iter::Zip<std::str::Chars<'a>, std::str::Chars<'a>>, fn((char, char))->char>
```
[Attempt This Online!](https://ato.pxeger.com/run?1=jVK7stMwEB1K5ys2LkCacTyXWzEm1xTUVHTkZhg5khwFWTJ6TCCJv4QmBbT8At9x-RpWdjxDQUFhrc7Zs2dHu_723UUfrk8_pYGOKUMonBeZFgFkBdK69QtWgzTEB15VPriqertnzie6gH-QFFb1xKsgMPGO9eu_4Ad1g_9hhSw2JjvEBaST0lWdYg0PP2KQq1dP-YUVzYWVJ9WThpYd68mFqOJALwrBF3KgdFL-fvYre73I8EGwUeZlAcrcF2Bj2OINNossS1-W9862jnWdMi308XTSwsNz2FkuoLVaLt_kxagzNsBXHBKKeWRB8AKMENwDAyf2LOq8gJthaFHYKdfyOBmOQjR0aIhClG2T6Sb_hF2xLrfNQezCeEvMLdtoYbjgiW6snqOZ05o1d9HBUZkypcJewGPuYy8cNPaoH_Mbexd9PCpXznXcGqY5HKYqFzsppFjOQAuJme0i26bfIuudMmFJcknOOMWhAAz3A4UHyCmON2PeCxc-is9LIgkqyrQuT-g47xnQcme1xhdW1fp9QMe2Tgpcxugx9tAGu5yRGkbjYTFMe7xep_gH)
If iterators over chars do not count as reasonable input/output I can instead manage
# 60 bytes
```
|a,b|a.chars().zip(b.chars()).map(|(i,j)|i.max(j)).collect()
```
which has the much more reasonable type of
```
fn(&str, &str) -> String
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NVFLbtswEEWX1CnGXAQkwAhpVkXzO0SXjlFQJinToUiFH7i1rZNk40V7qPQ0HUnWQhrO-5GY-fgTS8qXz9p46KT1jMOpIk5nMN_BeHaTchQw_jncPsOPHK1v4elvyeb22-fjWYrmLOvtTsbEeH20PWuWjted7NmZWbHnZ4vNL7ZHcBuc09vM-Jzx78sHeaiICRHW1n8VYP29gFDyBk-wrggZP0L7GNoou268vi_Ho9MJbmAblIY2OLN6oWLS-ZDhNz4fxarIrJUAr7VKICHqnSyOCrgG5haFnY2tKnPgJMTAiIEoRNlmDF3TN7wVfTQ0e3z6dBqRK9s47ZVWI9wEt1S_0E42dyXCwfp6pPJOwytNpdcRmnBwr_SK3pVUDjbWi08FL52C_eyKpTPa6NXSOG2Q2VRkMy6M9LiXvGLUsBNOcRCA5X7g8ASU43iJTEnH_FO_r5hhy5z5NOiJn_zOY8IJoWEyDdUw7-hymet_)
[Answer]
# [tinylisp 2](https://github.com/dloscutoff/tinylisp2), 28 bytes
```
(\(S T)(,(zip-with max S T)"
```
Try it at [Replit](https://replit.com/@dloscutoff/tinylisp2)! Example session:
```
tl2> (\(S T)(,(zip-with max S T)"
(() (S T) (, (zip-with max S T) ""))
tl2> (d F _
F
tl2> (F "hello," "world!")
"worlo,"
```
### Explanation
The library functions `zip-with` and `max` do almost the entire task.\* The only catch is that `zip-with` returns a list of codepoints, and we want a string. The easiest way to convert is to concatenate an empty string using `,` (short for `concat`).
---
\* When I first answered this challenge, I had not yet implemented `zip-with` and `max` in the standard library. Here's my original **46-byte** solution without those functions:
```
(\(S T)(,(m(p a(\(C D)(?(< C D)D C)))(z S T))"
```
Explanation:
```
(\(S T)(,(m(p a(\(C D)(?(< C D)D C)))(z S T))""))
(\                                              ) ; Lambda function
  (S T)                                           ; taking two strings S and T:
                                     (z S T)      ; Zip (-> list of pairs of codepoints)
         (m                                 )     ; Map to each pair:
           (p a                     )             ; Apply to its two items:
               (\                  )              ; Lambda function
                 (C D)                            ; taking two integers C and D:
                      (?(< C D)D C)               ; If C < D, then D, else C (i.e. max)
                                                  ; Now we have a list of codepoints...
       (,                                    "")  ; Concat "", converting to string
```
[Answer]
# Mathematica, 102 bytes
```
T=ToCharacterCode;L=Length;(a=T@#;b=T@#2;FromCharacterCode@Table[Max[a[[i]],b[[i]]],{i,L@a~Min~L@b}])&
```

**input**
>
> ["blended
> ", "bold"]
>
>
>
[Answer]
# [Micro](http://esolangs.org/wiki/Micro), 119 bytes
```
{R b i m+:R}:X{R a i m+:R}:Y
""\\:a:b:R
{b:M}:N
a:M
b a<if(N,)
0:i{i1+:i
a i m C b i m C~:> if(X,Y)
i M=if(,Z)}:Z
Z
R:\
```
[Answer]
# C#, ~~71~~, 67 bytes
*saved a few bytes by using `string.Join()` instead of `new string()`*
added 18 bytes to both versions for needing `using System.Linq;`
**67 bytes**
```
(a,b)=>string.Join("",(a.Zip(b,(x,y)=>x>y?x:y)));
```
**71 bytes:**
```
(a,b)=>new string(a.Zip(b,(x,y)=>x>y?x:y).ToArray());
```
[DotNetFiddle](https://dotnetfiddle.net/ePb5Ee)
[Answer]
# Modern Pascal
***version 1 of algorithm (func:139bytes)***
```
   for var l:=1 to min(length(paramstr(1)),length(paramstr(2))) do
      result+=iif(paramstr(1)[l]>paramstr(b)[l],paramstr(1)[l],paramstr(2)[l]);
```
**Explanation**
The for loop is designed to crawl to the length of the shortest string.
The output is compared appending to result the highest ASCII value of
each letter crawled. Since we are using shortest length, we can access
the strings elements directly - see v2 below, uses Copy() to be safer.
***version 2 of algorithm (func:166bytes)***
```
   for var l:=1 to max(length(paramstr(1)),length(paramstr(2))) do
      result+=iif(copy(paramstr(1),l,1)>copy(paramstr(2),l,1),copy(paramstr(1),l,1),copy(paramstr(2),l,1));
```
// Author of Modern Pascal
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 17 bytes
```
Ôº¶‚åä‚ü¶Ôº¨Œ∏Ôº¨Œ∑‚üß‚åà‚ü¶¬ßŒ∏Œπ¬ßŒ∑Œπ‚üß
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z8tv0hBwzczLzO3NFcj2ic1L70kQ6NQU0cByszQjNXUVAgoyswr0fBNrIAocyzxzEtJrdAo1FHIBCqFcTNAXKBy6///szPz0rnyk7JSk0v@65b91y3OAQA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Edit: `Slice` got added a few days later, which would have allowed the following code for 15 bytes: [Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMMqtEBHwTexQCM4JzM5VaNQR8FAR8EnNS@9JEMjQ1NHwVATJF2RmVuaqxGdqaPgWOKZl5JaoZGho5CtGaupqWn9/392Zl46V35SVmpyyX/dsv@6xTkA "Charcoal ‚Äì Try It Online")
```
‚ÜëÔº•‚úÇŒ∏‚Å∞Ôº¨Œ∑¬π‚åà‚ü¶Œπ¬ßŒ∑Œ∫‚üß
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 9 bytes
```
DQSS_MaZb
```
[Try it online!](https://tio.run/##K8gs@P/fJTA4ON43MSrp////Gak5Ofk6/8vzi3JSFAE "Pip ‚Äì Try It Online")
Pip doesn't have a string max operator, so I used `SS` (Sort String) instead:
```
      aZb  Zip the two cmdline args together, truncating to shorter length
     M     To that list of 2-element lists of characters, map a function:
  SS_       Sort each pair of characters stringwise
DQ          and dequeue the second (larger) one
           Autoprint the resulting list of characters
```
[Answer]
# [*Acc!!*](https://github.com/dloscutoff/Esolangs/tree/master/Acc!!), 186 bytes
```
N
Count i while _/128^i/32 {
_+128^(i+1)*N
}
_*128+N
Count i while _%128/32*(_/4096) {
Count j while _/128%128/(_%128+1) {
_/128^2*128^2+_/128%128+_%128*128
}
Write _%128
_/128^2*128+N
}
```
Input strings should be given on stdin, newline-separated. [Try it online!](https://tio.run/##S0xOTkr6/9@Pyzm/NK9EIVOhPCMzJ1UhXt/QyCIuU9/YSKGaK14bxNHI1DbU1PLjquWK1wLytTG0qAJFgRq0NOL1TQwszTSBOiEqspANBavSACsGmgcyHWyVkRaY1Iar0QYrAYkCbQwvyiyB2oCsHuiG2v//M1JzcvJ1uMrzi3JSFAE "Acc!! ‚Äì Try It Online")
### Explanation
We conceptually partition the accumulator into 7-bit registers, each of which can hold an input character. The first `Count i` loops until the input's ASCII code is smaller than 32, storing the first line of input into the accumulator, with the first character in the least-significant position:
```
, o l l e h
5 4 3 2 1 0
Accumulator value = asc(h) + 128*asc(e) + 128^2*asc(l) + ... = 1541853098728
```
Next, we shift everything left by one register, read the first character of the second line, and store it into register 0:
```
, o l l e h w
6 5 4 3 2 1 0
```
We `Count i` again while register 0 (`_%128`) and register 1 (`_/128%128`, though the formula can be golfed a bit in this context) are both >= 32. Inside the loop, we use a nested `Count j` loop to check if register 1 is strictly greater than register 0. (Comparisons are done via integer division: if `a/(b+1)` is `0`, then `a<=b`; if `a/(b+1)` is nonzero, then `a>b`.) If it is greater, we swap the registers' contents. This loop executes at most once, because after swapping, the condition is guaranteed not to be true anymore.
After the (potential) swap, the larger of the two characters is in register 0, which we output. We then shift two registers to the right (`_/128^2`), shift one register back to the left (`*128`), and store the next input character in register 0 (`+N`):
```
, o l l e o
5 4 3 2 1 0
```
The `Count i` loop exits once one or both strings reach the newline at their end.
[Answer]
# Common Lisp, 59 bytes
```
(lambda(x y)(map'string(lambda(a b)(if(char> a b)a b))x y))
```
[Try it online!](https://tio.run/##NYpBDoAgDAS/UnuxTXyDfymgQlKEgIn6eoSDhzns7FgNNTfKJZwWqJFKNE7ogZcpSp7r1Z/j1wKGKexkvZQVxhrwqLmh31TTgoB3Kuom5C4/)
[Answer]
# Axiom, ~~67~~ 20 bytes
```
f(a,b)==map(max,a,b)
```
And with this we now surpass JavaScript, Lisp until perhaps J and APL too.
The previous solution:
```
f(a,b)==concat[max(a.x,b.y)::String for x in 1..#a for y in 1..#b]
```
[Answer]
# [Whispers](https://github.com/cairdcoinheringaahing/Whispers), 49 bytes
```
> Input
> Input
>> L¬ªR
>> Each 3 1 2
>> Output 4
```
[Try it online!](https://tio.run/##K8/ILC5ILSr@/99OwTOvoLSEC07bKfgc2h0Eol0TkzMUjBUMFYxAPP/SEqC8gsn//0k5qXkpqSlcSfk5KQA "Whispers ‚Äì Try It Online")
## How it works
Each line consists of `(line no.) (> or >>) (command)` (the line numbers are implicitly added in the actual program)
```
1 > Input        - Retrieve the first input
2 > Input        - Retrieve the second input
3 >>  ¬ª          - Take the maximum of...
     L           -   the left argument and...
       R         -   the right argument
4 >> Each        - For each value in...
            1    -   the first line zipped with...
              2  -   the second input,
          3      -   call the third line
5 >>        4    - Run the fourth line, then...
     Output      - Output the result
```
[Answer]
# [Swift](https://swift.org), 66 bytes
```
func f(a:String,b:String){print(String(zip(a,b).map{max($0,$1)}))}
```
Straight forward solution
[Answer]
# [Japt](https://github.com/ETHproductions/japt) v2.0a0, 13 bytes
```
√ämVl)√ÆUc√àwVcY
```
[Try it online!](https://ethproductions.github.io/japt/?v=2.0a0&code=ym1WbCnuVWNAWHdWY1k=&input=IkhlbGxvLCIgIldvcmxkIg==)
### Unpacked & How it works
```
Ul mVl)√ÆUcXYZ{XwVcY
Ul      Length of 1st input (U)
mVl)    Minimum of above and length of 2nd input (V)
√Æ       Take this length out of the following string...
UcXYZ{    Map on charcodes of U and convert back to string...
Xw          Maximum of this and...
VcY         V's charcode at the same index.
```
Japt doesn't have min/max on strings, but does have one on numbers. Turns out that it helped reduce bytes on both "Compute minimum length of two strings" and "Map on two strings to take higher chars".
[Answer]
# Cjam, 3 bytes
This is so easy...
```
.e>
```
Pretty much the same as the Haskell answer, `.` takes an operator and performs "`zipWith`", and `e>` means take the max of the two inputs.
[Try it online!](https://tio.run/#cjam)
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 23 bytes
```
~zip{.,({$1=}{;}if}%''+
```
[Try it online!](https://tio.run/##JY1BTsQwDADvvMIbKEViVS1nhHjIikPaONmUNImcWBWtyteLt9wSz3jsUrBlIJ/rHpt1/118Xrvzy/r09rGt75u3W9O2r3vmWrZmv6pMyZGeJh8dZF6WgAWeYUgGwUnq9KlAxVThByuIaFhXNGeIiKaABsKb5qC@4BEyVSfW5MkZ/i8dlpRIShwerupbzkgw9SMO9dhKMhHQB4wGjbA@BXMQeUQhQfcXJph97BS09YagCmck4XNQ7d2U4YULz546WTAp6mBgFF1V4smixdNRvP8C2rH7Aw "GolfScript ‚Äì Try It Online")
[Answer]
# [R](https://www.r-project.org/), 96 bytes
```
for(i in 1:min(lengths(m<-sapply(scan(,""),utf8ToInt))))cat(intToUtf8(max(m[[1]][i],m[[2]][i])))
```
[Try it online!](https://tio.run/##HYpBCsMgEAC/Il7cgC1NT6X0A72nJ/FggmkWdBXdkPb1VjqnYZjS2poKoEAS4z0iQfD05q1CfJyqyzl8oS6OQEs56J3X25SexENncQxIPKVXrxDdB6Ixo7UGre52/Vv/mgpuvuxFHEhnJRRvXsi6Z1/EnI4gVfsB "R ‚Äì Try It Online")
Using ASCII code.
[Answer]
# [Burlesque](https://github.com/FMNSSun/Burlesque), 9 bytes
```
lnp^q>]Z[
```
[Try it online!](https://tio.run/##SyotykktLixN/f8/J68grtAuNir6//@M1JycfB2u8vyinBRFAA "Burlesque ‚Äì Try It Online")
Returns a list of characters add 2 bytes for concat (`\[`)
```
ln  # Split on newlines
p^  # Push to arr
q>] # Boxed maximum
Z[  # ZipWith
```
[Answer]
# [Kotlin](https://kotlinlang.org),  ~~23~~  17 bytes
```
{zip(it,::maxOf)}
```
[Try it online!](https://tio.run/##bY1BDoIwEEXX9hQjqzapHqARXLAlceEJhlBk4tCSUtRIOHuFsHX1k/@S954@Mrn0Qoaxn9jAPQZyj7PcV8GpgIrGeCk7DAXkaf7SIClqY3r83Fq1pHZy0CM5qWAWh82EkEOw2FTk7PpeDWTZTuq/ZFhTUW59ibpWSiyps8xei7cP3Bx/ "Kotlin ‚Äì Try It Online")
]


[Question]
      [
I thought of a new way to generate my passwords, and even though it's probably not very clever in the long run, it could still make for a fun code-golf.
Taking a string of words, the password is generated thus:
* Pick the *nth* character in the *nth* word
* If *n* is larger than the word, continue counting backwards
Example:
```
This is a fun task!
T     s a  u      !
```
T is the first character
s is the second
a is the first, but going back and forth it is also the third
u is the second but because of counting backwards it's also the fourth
'!' is the fifth character in 'task!' and thus will be included in the final password, `Tsau!`
**Rules**
* Input will be a string
* Separate the string on spaces, all other characters must be included
* Uppercase letters must remain uppercase, same with lowercase
* You take *n* steps in each word, where *n* is the number of words that have come before plus one
* If *n* is larger than the word, you must step backwards through the word, if you hit the start, you go forward again until you have stepped *n* times
* The first and last character is only stepped once, so 'fun' on the seventh position as an example goes 'funufun' and ends on n, not 'funnuff' and ends on f
* Output must be a string
Examples:
```
Input              Output
Once Upon A Time   OpAe
There was a man    Taaa
Who made a task    Waak
That was neat!     Taa
This is a long string to display how the generator is supposed to work  Tsagnoyotoipto
```
The shortest code in bytes wins!

[Answer]
# [Python 2](https://docs.python.org/2/), 72 bytes
```
lambda s:''.join((-~i*(w+w[-2:0:-1]))[i]for i,w in enumerate(s.split()))
```
[Try it online!](https://tio.run/##bZCxTsNADIb3PIUjhtwBqaBjJIY@QZegDqWDIU5ybWKfchedsvDq4Q5R6IDlzZ8@@7ddfC@8XduXt3XA8b1BcFVRbM5iWKny09yr8BCO5bZ6qsrnk9ZHc2plAvMYwDAQzyNN6Em5jbOD8UprvdrJsIdWFXVvHMRGaGcGj@6SF/oOaodznv1Se/4geLXCsIPajJSQWHu7o@xGRRNBwCQbkX8YqBHxDzr0EocNRSYtu0IHxMutCf23iAl9fmWSKfvn8EG4A@fjoAMv0JgYExfoJYDvCTrilD99xIGbrRVHTQKDTHE/RHlM27Es4sVYkfUL "Python 2 – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 11 bytes
```
#vyN©Fû}®è?
```
[Try it online!](https://tio.run/##MzBNTDJM/f9fuazS79BKt8O7aw@tO7zC/v//kIzMYgUgSlTIyc9LVyguKcoEUiX5CimZxQU5iZUKGfnlCiUZqQrpqXmpRYkl@UUg1cWlBQX5xakpIIXl@UXZAA "05AB1E – Try It Online")
**Explanation**
```
#             # split input on spaces
 vy           # for each word in input
   N©F        # N times do, where N is the current iteration
      û}      # palendromize the word
        ®è    # use N to index into the resulting word
          ?   # print
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
ḲJị"ŒBṖȯ$€$Ɗ
```
[Try it online!](https://tio.run/##y0rNyan8///hjk1eD3d3Kx2d5PRw57QT61UeNa1ROdb1////kIzMYgUgSlTIyc9LVyguKcoEUiX5CimZxQU5iZUKGfnlCiUZqQrpqXmpRYkl@UUg1cWlBQX5xakpIIXl@UXZAA "Jelly – Try It Online")
[Answer]
# Java 10, ~~148~~ ~~117~~ ~~114~~ 110 bytes
```
s->{int i=-1,j;for(var a:s.split(" "))System.out.print(a.charAt((j=a.length()-1)>0*i++?i/j%2<1?i%j:j-i%j:0));}
```
-31 bytes thanks to *@SamYonnou* by creating a port of [*@user71546*'s JavaScript answer](https://codegolf.stackexchange.com/a/165808/52210).
-4 bytes thanks to *@SamYonnou* again, optimizing the algorithm for Java.
[Try it online.](https://tio.run/##hVJNTwIxEL37KwYSk1bdRTyyouHgUT2I8WA8jLsD22Vpm3YWJIbfjt0PFdHEpm3SZl7f67xX4AqjIlvs0hK9h1tU@v0IQGkmN8OU4K4@AqyMyiAVD@yUnoOXSbjdhhWmZ2SVwh1oGMPOR1fvAQ1qHA3PimRmnFihAxz52NtSsehDX8qHjWdaxqbi2IYXWWCc5ugmLEQxxrgkPedcyGgor85P1OnptRoUxxeXw2t1XIyKqN7PpUy2u6TVYKvXMmjopDRil@Ernd7nF0DZ/oPJBwnTXHkIE2FWaWD0i15fJgCDAdy8WUqZshFMPVa9PdC9Du14tEbDBKZqSQ0CDkD3dkI/iMgRrLGmWqL@hBwQIeIe5ik3oTajAKmV/Y15Qlz84EFuaDQh974gv3j@7EFpaktbZ9lApoJRuIHcrIFzgjlpcsjG1dW@stZ4yurCtXG1uiP4dxz2da7NxrBRlk2To@8UNdY1AruoKW0r7szTcSrac0t6mKJSiy6Y290H)
**Explanation:**
```
s->{                            // Method with String parameter and no return-type
  int i=-1,                     // Step integer, starting at -1
      j;                        // Temp integer
  for(var a:s.split(" "))       // Loop over the parts split by spaces
    System.out.print(           // Print:
     a.charAt((j=a.length()-1)  //  Set `j` to the the length of the part minus 1
               >0               //  If the length of the part is larger than 1 (`j` > 0)
                 *i++?          //  (and increase `i` by 1 in the process with `i++`)
                i/j%2<1?        //   If `i` integer-divided by `j` is even:
                 i%j            //    Print the character at index `i` modulo-`j`
                :               //   Else:
                 j-i%j          //    Print the character at index `j` minus `i` modulo-`j`
               :                //  Else:
                0));}           //   Print the first (and only) character
                                //   (the >0 check is added to prevent divided-by-0 errors)
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes
```
⭆⪪Ｓ §⁺ι✂ι±²¦⁰±¹κ
```
[Try it online!](https://tio.run/##PYzBCsIwEETvfsXiaQsV1Ksnjz0ohfoDS7skoSEbkq3Vr4@pgrDMzgyPGS2lUciX0icXFAetz9wo4hC9U@xCXPRXYtPCHvZVr9qFiV/Y@yWja2HwbuTN3NmQMp4rc/ynU9PUPFe9lPKwLkM9Ai/BQP4ugwpMLkdPb7CygloGw4ETqaSNzkuMknnawFXSvCuHp/8A "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  Ｓ                 Input string
 ⪪                  Split on spaces
⭆                   Map over words and join
      ι ι           Current word
       ✂ ±²¦⁰±¹     Slice backwards from 2nd last character to start exclusive
     ⁺              Concatenate
    §          κ    Cyclically index on current word index
                    Implicitly print
```
I don't often get to use Slice's last parameter.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 9 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
éñ~╗D¡┤Gq
```
[Run and debug it](https://staxlang.xyz/#p=82a47ebb44adb44771&i=Once+Upon+A+Time%0AThere+was+a+man%0AWho+made+a+task%0AThat+was+neat%21%0AThis+is+a+long+string+to+display+how+the+generator+is+supposed+to+work&a=1&m=2)
Unpacked, ungolfed, and commented, it looks like this.
```
j       split into words
{       start block for mapping
  cDrD  copy word; remove first and last character; reverse
  +     concatenate with original word
  i@    modularly (wrap-around) index using map iteration index
m       perform map
```
[Run this one](https://staxlang.xyz/#c=j+++++%09split+into+words%0A%7B+++++%09start+block+for+mapping%0A++cDrD%09copy+word%3B+remove+first+and+last+character%3B+reverse%0A++%2B+++%09concatenate+with+original+word%0A++i%40++%09modularly+%28wrap-around%29+index+using+map+iteration+index%0Am+++++%09perform+map&i=Once+Upon+A+Time%0AThere+was+a+man%0AWho+made+a+task%0AThat+was+neat%21%0AThis+is+a+long+string+to+display+how+the+generator+is+supposed+to+work&a=1&m=2)
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~78~~ ~~70~~ ~~69~~ 68 bytes
-1 byte @Arnauld
```
x=>x.split` `.map((y,i)=>y[a=i%(l=y.length-1)|0,i/l&1?l-a:a]).join``
```
[Try it online!](https://tio.run/##ddDBasMwDAbg@55CLWwk0HjrdSUde4JdMnYYg4hEid06krHdpYG9e@YUdhktCHTQxy@hA35jaLxxsWBpae7K@Vzuzyo4a2INtRrQZdm0MXm5nz6xNPeZLSdlifuoi23@87Qxj/Zh@2ILfMavXB3EcF3Pu0Y4iCVlpc@6bF1pEyAVQndiiBiOq3We7@7@uzduCN6dMLxCZQa6iipNnmDEJW5Avmo@tKRZS4ks227kYLzEMGFc3SB/d1vhHkL0JrUo0Jr0IpxAywhRE/TE5DGKX3Q4OSeB2gWO4i/b518 "JavaScript (Node.js) – Try It Online")
**Explanation**
```
x=>
 x.split` `                    // Split the words by spaces
 .map((y,i)=>                  // For each word:
  y[                           //  Get the character at index:
                               //   A walk has cycle of length (2 * y.length - 2)
   a=i%(l=y.length-1)|0,       //   Calculate index a = i % (y.length - 1)
   i/l&1                       //   Check in which half the index i in
   ?l-a                        //   If in the second half of cycle, use y.length - 1 - a
   :a                          //   If in the first half of cycle, use a
  ]
 ).join``                      // Join back the letters
```
[Answer]
# [Red](http://www.red-lang.org), 135 bytes
```
func[s][n: 0 p: copy""foreach w split s" "[append/dup r: copy""append w
reverse copy/part next w back tail w n: n + 1 append p r/(n)]p]
```
[Try it online!](https://tio.run/##VZDBTsMwEETv/YppTiAOgWtufAESCuIQ5bDEm9hKul7ZDqFC/fbgFIpaaQ@reTPjlQOb9ZVN0@76au1n6ZrYNlLhEVqh83osit4Hps5iQdTJJcQCRUOqLKY0syJcjL8all3gTw6Rz3KpFBKEv1Iu@KBuRCI35T0/InjAE/5iuai8k/tW21WDk4Qe37V1EXkI@bQcjOP@tPunL9Ix3tQLnlG7A1@h2nJgLLRFDyRX5N36rBjOYOu7yVA6R4Qp7W/A5YrJy4CYMhiQPIzLP0JHWL8gWcbAwoGSD5s7zqo@stmMiw/jaf0B "Red – Try It Online")
## Readable:
```
f: func[s][
    n: 0
    p: copy ""
    foreach w split s "  "[
        r: copy ""
        append/dup r append w reverse copy/part next w back tail w n: n + 1
        append p r/(n)
    ]
    p
]
```
[Answer]
# [Perl 5](https://www.perl.org/), 76 bytes
```
print map{$l=length;substr$_.reverse,$i++%(2*$l-2||1)*(1+1/$l),1}split" ",<>
```
[Try it online!](https://tio.run/##FczLCsIwEIXhVxlKhN5UUnDl5SncS6RDExyTMJNaxPrsMcKBf/NxIjIdco7sfIKniR9FZ0I/JXuU@S6J1W3H@EIW7JXruk09tIq2w7rqpq11p/eKml5/JZJLFVT96ZLz1TqBMgMU/ATlxZWkAKMrzrzBhgWSRZjQI5sU@K9ljjEIjn@4BH78AA "Perl 5 – Try It Online")
[Answer]
# [k](https://en.wikipedia.org/wiki/K_(programming_language)), ~~31~~ ~~30~~ 28 bytes
```
{x{*|y#x,1_|1_x}'1+!#x}@" "\
```
[Try it online!](https://tio.run/##NYzLCoMwEEV/ZYwL@1y4bTftF3Rj6aYgQx0bUTMhiRhRv91GoTBwL4dzpz5zvSzlZfTjYRpif0rzKc39nKTHKPbzTYB4L2WyE5msLIRDKDsFDm0diat4qA/BU7OCO2RVSwFlkgxBj6vaogrkJTm0ggJYd5uDblMUoYs28P/esPqCdaYK4RiKyuoGB5Dcg5MEX1Jk0LFZbdtpzZaKVezZ1GK//AA "K (oK) – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~14~~ 11 bytes
```
SzS!ö!…¢ŀŀw
```
[Try it online!](https://tio.run/##RYyxDcIwFER7T/E9ChNQJIj6i3xiy4m/ZTuyoAqMQsEIGSAoi2QRY9MgnXQ63btTUzB53J@PdcnNvZGfRe7ze31t8zannHOrdIAihOtkIWIwUhztheDk2MIBWj2SaBV5goQVG9GKs@LiHZVYF6XH@KstYZTi/zmw7SFEr4tFhk4HN@ANFCeIiqAnSx4j@0qHyTkO1FUwsTdf "Husk – Try It Online") Inspiration was taken from [this program](https://codegolf.stackexchange.com/a/174140) by Zgarb for the forward-and-reverse stepping.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 12 bytes
```
s.e@+b_Ptbkc
```
[Try it online](https://pyth.herokuapp.com/?code=s.e%40%2Bb_Ptbkc&test_suite=1&test_suite_input=%22This%20is%20a%20fun%20task%21%22%0A%22Once%20Upon%20A%20Time%22%0A%22There%20was%20a%20man%22%0A%22Who%20made%20a%20task%22%0A%22That%20was%20neat%21%22%0A%22This%20is%20a%20long%20string%20to%20display%20how%20the%20generator%20is%20supposed%20to%20work%22&debug=0)
```
s.e@+b_PtbkcQ   Final Q (input) implicit
           cQ   Split on spaces
 .e             Map the above with b=element, k=index
       Ptb        Remove 1st and last character
      _           Reverse
    +b            Prepend the unaltered element ('abcd' -> 'abcdcb')
   @      k       Get the kth character (0 indexed, wrapping)
s               Join on empty string, implicit output
```
[Answer]
# Japt, `-P`, 11 bytes
```
¸Ëê ÅªD gEÉ
```
[Try it](https://ethproductions.github.io/japt/?v=2.0a0&code=uMvqIMWqRCBnRck=&input=IlRoaXMgaXMgYSBsb25nIHN0cmluZyB0byBkaXNwbGF5IGhvdyB0aGUgZ2VuZXJhdG9yIGlzIHN1cHBvc2VkIHRvIHdvcmsiCi1Q)
```
¸Ë+s1J w)gE
```
[Try it](https://ethproductions.github.io/japt/?v=2.0a0&code=uMsrczFKIHcpZ0U=&input=IlRoaXMgaXMgYSBsb25nIHN0cmluZyB0byBkaXNwbGF5IGhvdyB0aGUgZ2VuZXJhdG9yIGlzIHN1cHBvc2VkIHRvIHdvcmsiCi1Q)
---
## Explanations
```
¸Ëê ÅªD gEÉ
¸               :Split on spaces
 Ë              :Map over each element D at index E
  ê             :  Palindromise
    Å           :  Slice off the first character
     ªD         :  Logical OR with the original element (the above will return an empty string for single character words)
        g       :  Get the character at index
         EÉ     :  E-1
```
```
¸Ë+s1J w)gE
¸               :Split on spaces
 Ë              :Map over each element D at index E
   s1J          :  Slice off the first and last characters
       w        :  Reverse
  +     )       :  Append to D
         gE     :  Get the character at index E
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 148 bytes (string version), 114 bytes (print version)
If I must return a string (long version):
```
char c[99]={0};char*f(s,t,u,i,j,k)char*s,*t,*u;{for(u=c,i=0;t=strtok(s," ");s=0,i++)*u++=t[j=strlen(t),k=2*j-(j>1)-1,(i%k<j?i%k:k-i%k)%j];return c;}
```
[Try it online!](https://tio.run/##TU/LboMwELzzFatUkWxjqtBb4jj9id4QB2QcMFAb2etEFeLbqUkvlVajnYdGu6rolNrejFVTbDVcA7bGvfe37L/kje2Stqm@8aCq87mWy2kVO2V3EjjyyA0f@EhfUuAMOYtiuTtPolTcyJNAmXrQjSl@gAMVQZ64yXPKYp5LrIbdnrQlSPkoP9hQkOFW0qLkxBzH6/CZ8DIWCelxqIXXGL0FJdbNWITvxliyL43vFH@dyVjaHxSWDMDcyW6kPpgjBvKij6qsKRXZum1fvQmQpoHJ2Q7@HgZ00JowT80P9O4J2GvotNW@Qef3dIjz7IJu9@DT@fEX "C (gcc) – Try It Online")
Otherwise, I just print and don't worry about a buffer (short version):
```
f(s,t,i,j,k)char*s,*t;{for(i=0;t=strtok(s," ");s=0,i++)putchar(t[j=strlen(t),k=2*j-(j>1)-1,(i%k<j?i%k:k-i%k)%j]);}
```
[Try it online!](https://tio.run/##TY/BasMwEETv/oolJSApcol7jOP0J3oLPQhZtldyJSOtE0rIt7tSeykswzD7dmB1PWq9vaDX89obOCfqMbxOl@p/FNGPOdsGliRJlFY6ricVRZKC2scQIsPu2FKXUQouUzvY8TZ1R4mHA19WKjSjqy3EbDwjLl33JmzN7KXhdSMZ7t3Zvmc9uTor39tP3j439ARfCj0rRsVRy1IFQmR/4/CoAHBgZZF74Nfdrk0@rZ7b9jFhgjwK5uBH@HsEKECPaZnVN0zhDjQZGI03UVGIhU7rsoRk@gLeQ3Q/ "C (gcc) – Try It Online")
[Answer]
# AWK, 79 bytes
Mostly because I'm curious to see any better awk or bash solutions!
```
{for(i=1;i<=NF;i++){l=length($i);k=int(i/l)%2?l-i%l:k%l;printf substr($i,k,1)}}
```
[Try it online!](https://tio.run/##FcrBCsMgEATQX9lDA5GklPRYK7n12FN/wBITFxdX1BBKyLdbAwMDM09vrpR95tiiGiQ@1fslsevEToqMX7JtLyikU@hzizcSzX2kKzb0cA3JEOs8Q1q/KccKe9cP4jhK@VhMUKOB2C9QX6yVGSZMgfQPLG@QrYHFeBN15njqtIbAyUwn3Di6Pw "AWK – Try It Online")
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 111 bytes
```
s=>{int i=-1,j;return String.Concat(s.Split(' ').Select(a=>a[++i>(j=a.Length-1)?j>0?i/j%2<1?i%j:j-i%j:0:i]));};
```
[Try it online!](https://tio.run/##fdFBa8IwFAfws/0UT0Fs0Xa6o7WVMdjJsYEOD@Lh0T7bdG3SJa8TET9711oGO0whJCT88k9eEhk3UprqygiZwPpkmArf@jvzVkJ@@VaUozHwrlWisYCz1TOMLCL4ViKGVxTSNqybXbs9oE6M05KXSkaLbnkC3RjCAQLo1SYIz0IyiMCdTTJfE1dawvpqvGclI2TbeOsyF2yPYOR4a8opYhuDEHfjsQjtLEBvRTLh1J05yyycLsVDNnxczJZimM0zt@2nc7F3HP/i102kUTl5Wy2YmorIPtiDTSoMNA3hUElgNJ/9QcOtf/GbjAg@SiXhCTaioNtyk5ImOGIbXKC8DbepakBMjWsPv5eIfA2UhNy/534LylXzgd2TAyuIhSlzPEGqjsApQUKSNLLSrTZVWSpDcQuPSnf3sHoX61L/AA "C# (.NET Core) – Try It Online")
[Answer]
## Haskell, ~~65~~ ~~62~~ 61 bytes
```
zipWith(\i->(!!i).cycle.(id<>reverse.drop 1.init))[0..].words
```
[Try it online!](https://tio.run/##FYyxTsNADEB3vsKtGJKhJ9hpJ0a2VmKgDKecc7F6OVu2QxU@niOVnvSWpzdFu2EpjWZhdXiPHsMZZ8rKizyNcLy2X5JP8qm70uHU7XbUh2EdCoaO0ttJ8QfVMCRlgddAlbzvv15C@A531mRtjlThCLL42fWjwjOMsL9MZLARoXDNYK60yRkSmZS4wsR38AkhY0WNzvqobRFhw/QIt/lt39rFYq68sjOJ898wlpitHQaRfw "Haskell – Try It Online")
It requires the latest version of `Prelude` which features the `<>` function.
```
                   words    -- split the input string into a list of words
zipWith(\i->     )[0..]     -- zip the elements i of [0..] and the words pairwise
                            -- with the function
      ... <> ...            --   call the functions with a word and concatenate
                            --   the results. The functions are
        id                  --     id: do nothing
        reverse.drop 1.init --     drop last and first element and reverse
    cycle                   --   repeat infinitely
(!!i)                       -- take the ith elemnt of
```
Edit: -3 bytes thanks to @user28667, -1 byte thanks to @B. Mehta
[Answer]
# [PHP](https://php.net/), 77 bytes
```
while(ord($w=$argv[++$i]))echo($w.=strrev(substr($w,1,-1)))[~-$i%strlen($w)];
```
[Try it online!](https://tio.run/##FYrBCsMgEER/xkIkSSHnNs1P9BZysHVRqbiymkgv/fXtBoaZ4c1kn/m@ZPHmQ4QOyXaqzcqQO9a@V2HTGt4eBV7nUong6Mr@kiZkmIZx0lqvv1GFi7AISbDebrw8mJ8@FBYZjpgcyx4kKrINJUfzZY@Nqwd2kIBMRTrfZc8ZC9jz2JA@fw "PHP – Try It Online")
* -3 bytes thanks to Kevin
* -10 bytes thanks to Titus
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 11 bytes
```
⌈₅(ʁ):ẏ¨£i∑
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCLijIjigoUoyoEpOuG6j8KowqNp4oiRIiwiIiwiVGhpcyBpcyBhIGZ1biB0YXNrISJd)
```
⌈           # Input split on spaces
 ₅( )       # repeat len(that) times...
   ʁ        # Palindromise each word
       ¨£   # Zipping...
     :      # Words
      ẏ     # range(0, len(words))
         i  # Index the numbers into the words
          ∑ # Stringify
```
[Answer]
# Powershell ~~208~~ ~~186~~ 170 bytes
```
$args|%{$i=0;-join($_.Split()|%{$l=($b=($a=$_)).Length;if($l-gt2){$b=($a|%{-join$a[($l-2)..1]})}for($j=0;$a.Length-le$i;$j++){$a+=($b,$_)[$j%2]}$a.Substring($i,1);$i++})}
```
Ungolfed:
```
$args|%{
   $i=0;
    -join($_.Split()|%{
        $l=($b=($a=$_)).Length;
        if($l-gt2){
            $b=($a|%{-join$a[($l-2)..1]})
        }
        for($j=0;$a.Length-le$i;$j++){
            $a+=($b,$_)[$j%2]
        }
        $a.Substring($i,1);
        $i++
    })
}
```
Test cases below or [try it online](https://tio.run/##TY7BasMwDIZfRQsqxKQJa66hh94HO7Rjh1KKuqiJU9cOtkMYXZ49s9MdBjKIX9//4d6MbF3LSs0zkm3cz@qBcvta5Z2ROsVzse@V9KmIudqmeAmPtngWonhj3fi2ktcUVd74Ujye14AubaRjvJSiKDanSUxXY1Psghvpr5srRllhl2WhS1nUr4P6iN2qPE0B2w8X563UTYpyvREVyiwLpnmek0MrHYQhuA4aPLnbSzIn7/qL4aM3GnZwkHdOIsiWYaSI3kmH5LM1Yas5BLG3MOQXRDP55L9cGd3A8w/gDdTS9Yq@oTUj@JahYc2WvLGRdkPfG8d1BEdjb8kv)
```
@(
    "This is a fun task!",
    "Once Upon A Time",
    "There was a man",
    "Who made a task",
    "That was neat",
    "This is a long string to display how the generator is supposed to work"
)|%{$i=0;-join($_.Split()|%{$l=($b=($a=$_)).Length;if($l-gt2){$b=($a|%{-join$a[($l-2)..1]})}for($j=0;$a.Length-le$i;$j++){$a+=($b,$_)[$j%2]}$a.Substring($i,1);$i++})}
```
[Answer]
# J, 43 bytes
```
[:(>{~"_1#@>|i.@#)[:(,}.@}:)&.>[:<;._1' '&,
```
## ungolfed
```
[: (> {~"_1 #@> | i.@#) [: (, }.@}:)&.> [: <;._1 ' '&,
```
* `<;._1 ' '&,` split on spaces
* `(, }.@}:)&.>` for each word, kill the first and last elm and append to word
* `#@> | i.@#` take the remainder of each word's length divided into its index
* `> {~"_1` take that result and pluck it from each word.
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o6007KrrlOINlR3sajL1HJQ1gSI6tXoOtVaaanp20VY21nrxhuoK6mo6/zW5uFKTM/IV0hTUQzIyixWAKFEhrTRPoSSxOFtRHS7pn5ecqhBakJ@n4KgQkpmbqo6kLbUoVaE8EaQxNzFP/T8A "J – Try It Online")
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 22 bytes
```
qS/{_);1>W%+T_):T@*=}%
```
[Try it online!](https://tio.run/##FcqxCsIwEIDhVzmHDtWCuCqKo7uFjiVNr3j1cqdJahDx2aNZ/@@3s3E5P6/bT18fdqeu2rR9vW/P6@O3yvmiqQGPhvndQCJmUB4hoJB6mJTvoeR4Ax1mtJFUzMAIViV6faEPhP9jWpBBTOFEIwK5R1GHElc/ "CJam – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-pl`, 60 bytes
```
gsub(/(\S+) ?/){w=$1+$1.reverse[1..-2]
w[(-2+$.+=1)%w.size]}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcnm0km5BjlLsgqWlJWm6Fjdt0otLkzT0NWKCtTUV7PU1q8ttVQy1VQz1ilLLUouKU6MN9fR0jWK5yqM1dI20VfS0bQ01Vcv1ijOrUmNrIWZAjVpw0y0kI7NYAYgSFXLy89IVikuKMoFUSb5CSmZxQU5ipUJGfrlCSUaqQnpqXmpRYkl-EUh1cWlBQX5xagpIYXl-UTbEOAA)
]