text:
Make a flag wave
Take a flag, like this one:
-----------------------------
|             |             |
|             |             |
|=============+=============|
|             |             |
|             |             |
-----------------------------

And a number input: the "wave length"
Say the wave length was 5. Then, every 5 characters along the line from the beginning, replace the next character a - with \ and shift all the characters after it one row down. Repeat this until the end. You end up with:
-----\
|     -----\
|           -----\
|=====        |   -----\
|     ======  |         -----
|           ==+===          |
-----\        |   ======    |
      -----\  |         ====|
            -----\          |
                  -----\    |
                        -----

If you end up not being able to make a full wave length along at the end, the flag is finished. Just remain flat until the end.
You can assume that all the lines are of the same length and that the top and bottom lines are composed entirely of - (0x2D) and the rest of the characters are in !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~, or is a space (). (So it's ascii value is x, where 31 < x < 127)
The flag will be at least 3 tall and 3 wide.
Wave length will be a non-negative integer (>= 0).
(You can also have wave length 1 be the smallest wavelength, so the above example would have wave length 6. This is OK.)
Your i/o of flag can be as arrays of lines or a string with multiple lines.
The output flag may have trailing spaces, but can only have leading spaces so long as it is the same on every flag. Trailing space on an input flag may be deleted.
Scoring
This is code-golf, so the shortest solution, in bytes, wins.
Test cases
---
abc
---
2
--\
abc
--\

-----
| + |
-----
10
-----
| + |
-----

---------------------------------------
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&          .\^/.          &&&&&&|
|&&&&&&        . |   | .        &&&&&&|
|&&&&&&        |\|   |/|        &&&&&&|
|&&&&&&     .--'       '--.     &&&&&&|
|&&&&&&      \           /      &&&&&&|
|&&&&&&       >         <       &&&&&&|
|&&&&&&      '~|/~~|~~\|~'      &&&&&&|
|&&&&&&            |            &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
---------------------------------------
12
------------\
|&&&&&&      ------------\
|&&&&&&                   ------------\
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&          .\^/.          &&&&&&|
|&&&&&&        . |   | .        &&&&&&|
|&&&&&&     .  |\|   |/|        &&&&&&|
|&&&&&&      --'       '--      &&&&&&|
|&&&&&&      \           /.     &&&&&&|
|&&&&&&       >         <       &&&&&&|
|&&&&&&      '~|/~~|~~\|~'      &&&&&&|
|&&&&&&            |            &&&&&&|
|&&&&&&                         &&&&&&|
------------\                   &&&&&&|
             ------------\      &&&&&&|
                          ------------\

-----------------------
|-._`-._ :| |: _.-'_.-|
|   `-._`:| |:`_.-'   |
|-------`-' '-'-------|
|------_.-. .-._------|
|  _.-'_.:| |:._`-._  |
|-'_.-'  :| |:  `-._`-|
-----------------------
4
----\
|-._`----\
|   `-._ :----\
|-----._`:| |: ----\
|-------`-| |:`_.-'_---
|  _.--_.-' '-'_.-' .-|
|-'_.-'_.:. .-.-----  |
----\-'  :| |:._------|
     ----\| |: _`-._--|
          ----\ `-._  |
               ----\`-|
                    ---

---------------
---------------
---------------
---------------
---------------
5
-----\
-----------\
---------------
---------------
-----\---------
      -----\---
            ---

-------------------------------------------
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
|---------------                          |
|#########################################|
|                                         |
|#########################################|
|                                         |
|#########################################|
-------------------------------------------
0
\
|\
|*\
|  \
|** \
|   *\
|**   \
|   ** \
|**    *\
|-  **   \
|#-    ** \
| #-**    *\
|# #-  **   \
| # #-    ** \
\# # #-**    *\
 \# # #-  **   \
  \# # #-    **|\
   \# # #-**   |#\
    \# # #-  **| #\
     \# # #-   |# #\
      \# # #-**| # #\
       \# # #- |# # #\
        \# # #-| # # #\
         \# # #-# # # #\
          \# # # # # # #\
           \# # # # # # #\
            \# # # # # # #\
             \# # # # # # #\
              \# # # # # # #\
               \# # # # # # #\
                \# # # # # # #\
                 \# # # # # # #\
                  \# # # # # # #\
                   \# # # # # # #\
                    \# # # # # # #\
                     \# # # # # # #\
                      \# # # # # # #\
                       \# # # # # # #\
                        \# # # # # # #\
                         \# # # # # # #\
                          \# # # # # # #\
                           \# # # # # # #\
                            \# # # # # # #\
                             \# # # # # # |
                              \# # # # # #|
                               \# # # # # |
                                \# # # # #|
                                 \# # # # |
                                  \# # # #|
                                   \# # # |
                                    \# # #|
                                     \# # |
                                      \# #|
                                       \# |
                                        \#|
                                         \|
                                          \

Expecting @LuisMendo to come here and blow this away within the next day or so.

Crap... Forgot @ doesn't link those who haven't responded... Someone kick my butt using MATL please so I can delete the comments.

Anyone animate this

The first testcase seems to contradict this statement of yours: If you end up not being able to make a full wave length along at the end, the flag is finished. Just remain flat until the end.

@SIGSEGV Done, though maybe not what you had in mind.

@KritixiLithos So the rest of the flag (Nothing) goes down, and that nothingness stays flat.

@carusocomputing Did someone call me? 31 bytes, though

Is the Canadian flag example wrong? The second shifted column contains a . that doesnt shift with the row.

@Marie It's in the column that has a \. Only the columns after the \ shift down.

Line 9 column 27, it is directly in line with the first - of the last turn-downed section.

@Marie Oh yeah, that's a mistake. I was looking at the wrong dot. Thanks!

No problem. I only noticed it because my solution didnt match and diffchecker highlighted that dot

05AB1E, 25 23 26 25 bytes
-2 thanks to Adnan
-1 thanks to Emigna
+3 thanks to Jonathan Allan (thanks for spending the time to catch that invalidity!)
øvyN>²Öi¦¨'\.ø}N²÷ú}).Bø»

Try it online!
This is 1-indexed instead of 0, +2 bytes if that isn't okay.
ø                                    # Transpose.
 vy                }                 # For each column...
   N>²Öi¦¨'\.ø}                      # Replace outside dashes with slants.
               N²÷                   # Current index / input #2.
                  ú                  # Prepend that many spaces to current column.
                    ).Bø             # Join, pad, transpose back.
                        »            # Print with newlines.

Emigna/Adnan/Anyone - There HAS to be a better solution to replace those slants, but I'm stumped.

The 1-indexing is OK.

ú is the same as ð×ì :)

@Adnan that's GOTTA  be new, right? No ideas on "replace last" though? I feel like 05AB1E needs replace first and replace last.

@JonathanAllan fixed for +3 byte penalty.

+3 thanks to Johnathan Allen sounds so passive aggressive...

@Artyer not at all! +3 thanks to him for pointing out my answer wasn't valid, I like it when people actually care enough to read an answer long enough to notice it isn't correct. Did I reword it enough to sound less sarcastic :P?

@Adnan NO WONDER I CAN NEVER REPLY TO HIM. Sorry about butchering your name Jonathan Allan.

Really not a problem :)

Very nice answer. Only improvement I can see is %_ => Ö.

Pyth, 35 bytes
j.ts.e+L*k;?qQtlb+PbjPteb*2\\bcC.zh

Try it online!

Python 2, 129 bytes
lambda f,n,j=''.join:map(j,zip(*[i/n*' '+'-\\'[i%n>n-2]+j(s[1:-1])+'-\\'[i%n>n-2]+len(f[0])/n*' 'for i,s in enumerate(zip(*f))]))

Try it online!

Jelly, 29 bytes
s”\⁹¦€Fð€0,1¦Zsð⁶ẋ;Ð€µ@"J;/z⁶

Input and output flags are lists of lines.
Wave length is 1-indexed.
Always produces one line of spaces.
(all of the above is explicitly allowed in the posted question)
Try it online! (footer to make IO look pretty - takes and receives flags as multiline text)
How?
A pretty similar method to carusocomputing's 05ab1e answer, which I have not managed to golf down more.
s”\⁹¦€Fð€0,1¦Zsð⁶ẋ;Ð€µ@"J;/z⁶ - Main link: list of lists f, number p
            ¦                 - apply to indexes (of f)
         0,1                  - ... 0 paired with 1 (i.e. last & first -> bottom & top)
       ð€                     - the previous chain with p as right argument for €ach:
s                             -   split into chunks of length p
    ¦€                        -   apply to indexes for €ach
   ⁹                          -   ... link's right argument, p
 ”\                           -   the character '\' (a replacement - if the index is out of bounds this has no effect - although this might change in the future.)
             Z                - transpose the edited flag
              s               - split into chunks of length p
                        J     - range of length = [1,2,...,nChunks]
               ð     µ@"      - zip with reversed arguments (call those i):
                ⁶             -   literal space
                 ẋ            -    repeated i times
                  ;Ð€         -    concatenate mapped across the chunks
                         ;/   - undo the split (reduce with concatenation)
                           z⁶ - transpose with a filler of space characters

Why is it always Jelly that does this?

05AB1E clearly won this round!

OK, why is it always either Jelly or 05AB1E that does this?  (Rhetorical question, I know it's because they're golfing languages)

MATL, 31 bytes
x"X@q1GQ&\Z"@b1G=?'\'5L(]h]Xhc!

Try it online! Or verify all test cases:
1,
2,
3,
4,
5,
6,
7.

Wow, what was the expensive part? The replacing the - with the [\]?

@carusocomputing Yes, I think that's the most expensive part

PHP, 168 164 187 172 167 153 150 152 149 bytes
for($r=count($f=file(a));$y<$r+$e/$n=$argn;$y+=print"
")for($x=0;$x+1<$e=strlen($f[0])-1;)echo("\\".$f[$z=$y-($x/$n|0)][$x++]." ")[$z%($r-1)||$x%$n];

takes flag from static file a and wave length (minimum 1) from STDIN.
Run as pipe with php -nr or try it online.
breakdown
for($r=count($f=file(a));       # import file, count lines
    $y<$r+$e/$n=$argn;          # loop $y through lines
    $y+=print"\n")                      # 2. print newline
    for($x=0;$x+1<$e=strlen($f[0])-1;)  # 1. loop $x through columns
    echo("\\".$f[                           # 3. create string=backslash+character+space
            $z=$y-($x/$n|0)                 # 1. line no. = $y - wave offset
        ][$x++]." "                         # 2. pick character from line
        )
    [
        $z%($r-1)                           # if not first or last line
        ||$x%$n                             # or not last position of wave
    ]                                       # then index 1 (character or space), else "\\"
    ;

Doesn't work for lines in the middle: http://sandbox.onlinephpfunctions.com/code/83b3163b402e0a675bc8bffa419e1424acee2d86

It shouldn't turn the middle lines into \. See the test case after the British one

It seems to be cutting off some of the bottoms of flags that increase in size a lot:
http://sandbox.onlinephpfunctions.com/code/b6b259e033d3e3d48f9aa23e71dbd6c6dbfcc0c6

@Artyer That should be it.

$z&&$z!=$r-1 should be equivalent to $z%($r-1) saving 3 byte.

JavaScript (ES6), 175 bytes

f=(s,l,p=++l,t=s.replace(/^-*|-*$/g,s=>s.replace(/-/g,(c,i)=>++i%l?c:`\\`)))=>t.search`
`<p?t:(f(s,l,p+l,t)+`
`+` `.repeat(p)).replace(eval(`/(^|(.*)\\n)(.{${p}})/g`),`
$3$2`)
;
test=(s,l)=>document.write(`<pre>${s}
${l}${f(s,l)}</pre>`);
test(`---
abc
---`,2);
test(`-----
| + |
-----`,10);
test(`---------------------------------------
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&          .\\^/.          &&&&&&|
|&&&&&&        . |   | .        &&&&&&|
|&&&&&&        |\\|   |/|        &&&&&&|
|&&&&&&     .--'       '--.     &&&&&&|
|&&&&&&      \\           /      &&&&&&|
|&&&&&&       >         <       &&&&&&|
|&&&&&&      '~|/~~|~~\\|~'      &&&&&&|
|&&&&&&            |            &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
---------------------------------------`,12);
test(`-----------------------
|-._\`-._ :| |: _.-'_.-|
|   \`-._\`:| |:\`_.-'   |
|-------\`-' '-'-------|
|------_.-. .-._------|
|  _.-'_.:| |:._\`-._  |
|-'_.-'  :| |:  \`-._\`-|
-----------------------`,4);
test(`---------------
---------------
---------------
---------------
---------------`,5);
test(`-------------------------------------------
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
|---------------                          |
|#########################################|
|                                         |
|#########################################|
|                                         |
|#########################################|
-------------------------------------------`,0);

I/O is as a newline-delimited string. Output includes a leading newline; this can be removed at a cost of 3 bytes. I tried computing the output string directly but that took me... 176 bytes:

f=
(a,l,h=a.length)=>[...Array(h+(a[0].length-1)/++l|0)].map((_,i)=>a[0].replace(/./g,(k,j)=>((k=i-(j/l|0))&&h+~k)|-~j%l?(a[k]||'')[j]||' ':'\\'))
;
test=(s,l)=>document.write(`<pre>${s}
${l}
${f(s.split`
`,l).join`
`}</pre>`);
test(`---
abc
---`,2);
test(`-----
| + |
-----`,10);
test(`---------------------------------------
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&          .\\^/.          &&&&&&|
|&&&&&&        . |   | .        &&&&&&|
|&&&&&&        |\\|   |/|        &&&&&&|
|&&&&&&     .--'       '--.     &&&&&&|
|&&&&&&      \\           /      &&&&&&|
|&&&&&&       >         <       &&&&&&|
|&&&&&&      '~|/~~|~~\\|~'      &&&&&&|
|&&&&&&            |            &&&&&&|
|&&&&&&                         &&&&&&|
|&&&&&&                         &&&&&&|
---------------------------------------`,12);
test(`-----------------------
|-._\`-._ :| |: _.-'_.-|
|   \`-._\`:| |:\`_.-'   |
|-------\`-' '-'-------|
|------_.-. .-._------|
|  _.-'_.:| |:._\`-._  |
|-'_.-'  :| |:  \`-._\`-|
-----------------------`,4);
test(`---------------
---------------
---------------
---------------
---------------`,5);
test(`-------------------------------------------
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
| *  *  *  *  *|                          |
|*  *  *  *  * |##########################|
|---------------                          |
|#########################################|
|                                         |
|#########################################|
|                                         |
|#########################################|
-------------------------------------------`,0);

I/O is as a string array.

It looks like the only test case yours passes is the one that doesnt change.

Yes, this doesn't work properly for most test cases. (The first one was what I tried)

@Artyer Sorry, that was subtle; I didn't spot the off-by-one error.


text:
ASCII-Art Venn Diagram
Given two lists that contain no duplicate elements a and b, find the crossover  between the two lists and output an ASCII-Art Venn Diagram. The Venn Diagram will use a squarified version of the traditional circles for simplicity.
Example
Given:
a = [1, 11, 'Fox', 'Bear', 333, 'Bee']
b = ['1', 333, 'Bee', 'SchwiftyFive', 4]

Output (Order is 100% arbitrary, as long as the Venn Diagram is correct):
+-----+----+-------------+
|11   |333 |SchwiftyFive |
|Fox  |Bee |4            |
|Bear |1   |             |
+-----+----+-------------+

The program may either consider '1' == 1 or '1' != 1, up to your implementation. You may also choose to just handle everything as strings, and only accept string input.

Given:
a=[]
b=[1,2,3]

Output (Notice how the two empty parts still have the right-pad space):
+-+-+--+
| | |1 |
| | |2 |
| | |3 |
+-+-+--+

Given:
a=[1]
b=[1]

Output:
+-+--+-+
| |1 | |
+-+--+-+

Rules

Elements of the Venn Diagram are left-aligned and padded to the max length entry plus 1.
The ordering of the elements within sub-sections of the Venn-Diagram are arbitrary.
Corners of the Venn Diagram (where | meets -) must be represented by a +.
You are garuanteed that a.join(b).length() > 0, if both are empty, you may do whatever.

You may even print a picture of Abe Lincoln, don't care.

This is code-golf, ascii-art and set-theory.

Bonus
Charcoal renders boxes like this naturally, but the whole set theory part... Don't know how well it does that. +100 bounty for the shortest charcoal submission before I am able to add a bounty to the question (2 days from being asked).

Personally, I feel that being able to support '1' == 1 is a bit too much of a stretch

@KritixiLithos fair enough, updated the challenge spec so that it doesn't hurt those who have started. It is now your choice on how you want string to integer comparison to work, both choices being equally valid submissions.

Can we assume that the input will only contain strings?

Related.

@Rod well, to be honest, yeah, sure; lets just go with that.

In the first example, why does the middle box have two right-padding spaces?

@L3viathan one mobile edit and your post is over.

Husk, 72 58 bytes
mṙ1₁Fz+m(₁TT' Ṡ:→S:öR'-→▲mL)TTømėF`-FnF-
Ṡz:(`:'+:'+R'|-2L

Try it online!
Husk does not support arrays of multiple types, so the arguments must be string arrays.
I am not sure whether I want to explain this monstrosity.
Due to it's sheer size, it takes about 28 secs(due to type inference) for the first test case mentioned. Without some of the type inference issues, this could be a lot shorter.
-14 bytes with a lot of adjustments(I got better at Husk).

FYI Charcoal could be as low as 48 bytes if I used implicit input: Try it online!

woah why not use that

I was only here for Best of 2020; I don't normally bother editing very old answers, and I'd now need to beat 47 anyway.

Charcoal, 106 89 87 bytes:
Ａ⟦⟧ςＡ⟦⟧λＡ⟦⟧ρＡ⟦⟧τＷＳ⊞ςιＷＳ⊞⎇№ςιτριＦς⊞⎇№τι⟦⟧λιＦ⟦λτρ⟧«Ｆι«↓Ｐκ»ＭＬι↑←Ａ⁺⌈ＥιＬκ³ζＵＲζ⁺⌈⟦ＬλＬτＬρ⟧²Ｍζ→

Try it online! Note that link is to verbose code for explanatory purposes, with the -sl option that shows the equivalent native Charcoal code. Takes input as newline-separated strings with a blank line after each set.
Edit: Saved 11 bytes thanks to @ASCII-only. Previous version actually had a bug when the last word in the first set was not in the second set and also the first column was the tallest, which manifested as an apparently inability to optimise away a temporary. Saved 2 bytes by optimising two Move commands (the deverbosifier now does this automatically but the resulting code was always valid so the answer is still competing).
Edit: I don't think Multiprint used to work with multiline output but it does currently and making use of that would save 6 bytes, plus a further 4 bytes because current Charcoal preinitialises the u variable to the empty list: Try it online!

Oh, if you want to print without moving the cursor, use Multiprint (Ｐ)

Okay, 95 bytes, remember to remove commas/semicolons to remove delimiter in non-verbose form (will fix later), also Map exists (sorry, will document asap)

@ASCII-only Huh, well, I'm sure I tried Multiprint at some point, so I don't know why I wasn't able to get it to work. Also, thanks for Map, it helped me optimise the answer a bit more. Finally, I think Charcoal sometimes lets you use ← without an Ｍ which would save a byte here, or is that a bug?

Directions without an Ｍ are intentional (but always remember a direction with a variable after is a directional print)

@ASCII-only Good, but that means that my Move(:Left); could just be ← instead of the Ｍ← that -dv generates.

Okay, done, now all we need to do is wait for Dennis to pull for the better Move deverbosifying (it also now removes more unneeded separators so you'll be able to add the commas back in if you want)

@ASCII-only Looks like it's live, thanks!

Python 2, 221 210 212 bytes
m=map
A,B=m(set,input())
d=A-B,B&A,B-A
e=[max(m(len,s))+1for s in d]
p,i,n='+|\n'
o=b=p+p.join(m('-'.__mul__,e))+p+n
while sum(m(len,d)):o+=i+i.join(m(str.ljust,[len(s)and s.pop()or''for s in d],e))+i+n
print o+b

Try it online!

Slightly wrong, you're missing the one space char right-pad.

@carusocomputing fixed

PHP>=7.1, 287 Bytes
<?for([$a,$b]=$_GET,$x=max(($m=array_map)(count,$r=[($d=array_diff)($a,$b),array_intersect($a,$b),$d($b,$a)]));$n<3;$n++)for(sort($r[+$n]),$i=-1;$i<=$x;$i++){$o[$i].="|+"[$b=$i<0||$i==$x].str_pad($b?"":$r[+$n][$i],max($m(strlen,$r[+$n]))+1," -"[$b]).("|+"[$b][$n<2]);}echo join("
",$o);

Online Version
Expanded
for([$a,$b]=$_GET, # store input arrays in shorter variables
$x=max(($m=array_map)(count,   # get maximum of
$r=[($d=array_diff)($a,$b),array_intersect($a,$b),$d($b,$a)])); #the set array
$n<3;$n++)
  for(sort($r[+$n]),$i=-1;$i<=$x;$i++){ # sort array to remove keys
    $o[$i].="|+"[$b=$i<0||$i==$x].   # concat line $b boolean for first and last line beginning char
    str_pad($b?"":$r[+$n][$i]   # string of item in array if not first or last line
    ,max($m(strlen,$r[+$n]))+1  # fill till maximum length of items in array
    ," -"[$b]) # with char depends on first/last line or item line
    .("|+"[$b][$n<2]); # make end of string if last array is reach
}
echo join("
",$o); #Output

05AB1E, 47 bytes
ʒå}©K®¹®Kr)õζ'|ìøε€SζøJ}ø'|δªðý¬„|+`:D¬мS'-:.ø»

Try it online or verify all test cases.
Explanation:
ʒ               # Filter the first (implicit) input-list by:
 å              #  Check if the current item is in the second (implicit) input-list
}©              # After the filter: store this overlap in variable `®` (without popping)
  K             # Pop and remove those items from the second (implicit) input-list
®               # Push overlap `®`
¹               # Push the first input-list again
 ®K             # Remove overlap `®`
r               # Reverse the three lists on the stack
 )              # And wrap them into a list
 ζ              # Zip/transpose this list, swapping rows/columns,
õ               # with "" as filler if the lists are of unequal length
  '|ì          '# Prepend an "|" in front of each inner string
ø               # Zip/transpose back, swapping rows/columns
 ε              # Map over each row:
  €             #  Map over each string in this row:
   S            #   Convert it to a list of characters
    ζ           #  Zip/transpose, swapping rows/columns, with " " as default filler
     ø          #  And then zip/transpose back
      J         #  And join the strings back together
 }ø             # After the map: zip/transpose back
  δ             # Map over each row:
'| ª           '#  And append an "|" to it
    ðý          # Then join each inner-most list by spaces
¬               # Push the first row (without popping the list)
 „|+`:          # Replace all "|" with "+"
      D         # Duplicate this string
       ¬        # Push its first characters (without popping), which is a "+"
        м       # Remove all "+" from the duplicated string
         S      # Convert what remains to a list of characters
          '-:  '# Replace each character (except for "+") with "-"
             .ø # Surround the list of rows with this string as leading/trailing items
»               # And finally join the list by newlines
                # (after which the result is output implicitly)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
PPCG's Unanswered Questions
This dear StackExchange site has so many challenges, and so many good answers. But what about the challenges that were never answered?
Task
Write a program or a function that will print a pseudo-random open unanswered (as in, a question with exactly zero answers) challenge from PPCG. All possible challenges should be produced with the same probability.
Input

No input will be taken.

Output

Must only be the title, tags and the link which should be separated by newlines.

The title must be exactly like it is in the challenge.
The tags don't have a strict output format but must include all tags.
The link may or may not include the question-name after the question id and must lead to the challenge.

May or may not be translated to a human readable format.

& to &

Leading and trailing whitespace is allowed.

Examples
Encode a steganographic encoder into a package
code-challenge,unicode,steganography
https://codegolf.stackexchange.com/questions/65159/encode-a-steganographic-encoder-into-a-package

Simple predictive keyboard CG
code-golf
https://codegolf.stackexchange.com/questions/76196/simple-predictive-keyboard-cg

Scoring
As this is code-golf, shortest answer in bytes wins.

I'm getting really sick of [tag:stack-exchange-api] challenges.

@Riker Uhm... thanks for your feedback? I really don't know why you would downvote for that reason but more power to you, I guess.

I didn't downvote for that. I downvoted because I think the question is boring. Also, would closed questions need to have the equal probability of being outputted?

Thank you for expressing concerns with the question even after disliking it.

While I don't feel as strongly about it as @Riker, there does seem to have be a lot of API-related challenges lately; so much so that I managed to get myself blocked from using the API for ~21 hours!

I will admit I got this idea after seeing the sudden influx of API questions.

At this rate, we'll have to ask SE for an unthrottled "sanbox" API to work with on all these challenges! :D

Interestingly enough, this challenge will show up during testing, but once I answer it, it won't show up in testing anymore.

I suggest, to avoid hammering the API with multiple requests and having people hit the throttle trying to retrieve all unanswered that you add a minimum number of answers that we should work with that can be retrieved with a single API request, i.e. <=100.

I also suggest that translating the output to "human readable format" be removed from the question as it adds an unnecessary (in my opinion) extra complication to the challenge that not all languages will be able to handle while remaining competitive. I think there's a post on Meta that covers this, I'll see if I can dig it out.

Note your example list is now wrong as the Tetris challenge has been answered :D

JavaScript + HTML, 271 250 232 bytes
Apparantly you can use Dates as pseudo-random numbers. I stole this from Shaggy's answer.
(Only uses about 4 of your quota)

q=[]
g=f=>fetch('//api.stackexchange.com/questions/unanswered?site=codegolf&page='+f).then(r=>r.json().then(j=>(q=[...q,...j.items])^j.has_more?g(f+1):document.write(`<pre>${(q=q[new Date%q.length]).title}
${q.tags}
`+q.link)))
g(1)

It makes an array q, then calls g(1), which fetches the first page of results and adds it to q. Then, if the request says it has_more, then it calls g(f+1), which fetches the next page, until it reaches the end and writes out to the HTML document (Which will automatically unescape the response)
If we don't care about all of the unanswered questions, just the most recent 30 (Only uses 1 of your quota):
JavaScript + HTML, 213 196 179 bytes

fetch`//api.stackexchange.com/questions/unanswered?site=codegolf`.then(r=>r.json().then(j=>document.write(`<pre>${(j=j.items[new Date%j.items.length]).title}
${j.tags}
`+j.link)))

Sorry, @Artyer, I was so focused on working on my own answer, I never spotted that you'd beaten me to the punch by a few minutes. I'm happy to delete my answer, if you feel it's to similar to yours.

@Shaggy It's alright. I also wrote the second answer at the same time as you wrote your answer, so it's a happy coincidence that they ended up similar.

You could save a few byes by hardcoding in the number of pages that need to be fetched. Instead of j.has_more?g(f+1), try ++f<5?g(f)

You could also replace q=q.concat(j.items) with q=[...q,...j.items]. It looks like Tags:  is optional, so you can drop that too. And no need to join q.tags, it will be coerced into a string when being concatenated to a string. Finally, using a template literal for the final should save you a few bytes, too.

@Shaggy Unfortunately, I've met my quota. It resets in 425 seconds though.

After further consideration, I've decided to delete my answer. Your paging solution is now almost identical to the one I was working before I decided to ditch the paging in order to save multiple requests to the API.

TIP: To avoid being booted from the API when testing, grab a sample set of data and use it as I did in the second Snippet here

Your code also returns answered questions: https://codegolf.stackexchange.com/questions/143220/simple-complexity was returned and that question has two answers.

Python + requests + json + random + html, 249 239 bytes
import requests as r,json,random as R,html
j=R.choice(json.loads(r.get('http://api.stackexchange.com/questions/no-answers?site=codegolf').text)['items'])
print('\n'.join([html.unescape(j['title']),'Tags: '+', '.join(j['tags']),j['link']]))

Turned out longer than I'd like.
-10 bytes thanks to @totallyhuman by using R.choice rather than R.shuffle and taking the first element.

Can you save a few bytes by using random.shuffle?

...Wait, or even better, random.choice()?

@totallyhuman Changing the inpurt name happens to actually make no difference in bytecount :P But thanks for .choice()!

You don't need the json library, use r.get(url).json() instead

This doesn't account for has_more. It only randomly chooses from the first 30.

Bash 255 232 bytes
a="api.stackexchange.com/questions/";b="?site=codegolf";c=$(w3m $a"unanswered"$b"&filter=total"|tr -cd 0-9);w3m $a"no-answers"$b"&pagesize=1&page="$((RANDOM%c))|jq -r ".items[0]|.title,(.tags|join(\", \")),.link"|recode html..utf-8

Looks like a wrong results returns for totals for no-answers/unanswered. General idea - get total, than get random page with one item.
Bash 174 153 bytes
w3m api.stackexchange.com/questions/no-answers?site=codegolf|jq -r ".items[$RANDOM%(.items|length)]|.title,(.tags|join(\", \")),.link"|recode html..utf-8

It select one random question from last 30, not from all questions. Works from command line. Required curl w3m, jq and recode.
result:
Tips for golfing in Charcoal
code-golf, tips
https://codegolf.stackexchange.com/questions/117269/tips-for-golfing-in-charcoal

I'm pretty sure you need to choose from all of them. But welcome to PPCG anyway!

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Sum the diagonals
Take a matrix of positive integers as input, and output the individual sums of the elements on the diagonal lines through the matrix.
You shall only count the lines that goes diagonally down and to the right. You must start with the diagonal that contains only the bottom-left element, then the length-two diagonal above that (if it exists) and so on through to the diagonal that contains only the top-right element, as illustrated below.
Example:
Input:
 8   14    5    1
10    5    5    8
 6    6    8   10
15   15    4   11

Output:
15, 21, 20, 32, 29, 13, 1
(Diagonals: {{15},{6,15},{10,6,4},{8,5,8,11},{14,5,10},{5,8},{1}})

Input:
1
Output:
1

Input:
1 5
Output:
1, 5

Input:
4
1

Output:
1, 4

Input:
17    4    5
24   16    5
 9   24   10
 1   14   22
 1   21   24
 4    4   17
24   25   17

Output:
24, 29, 22, 39, 47, 70, 43, 9, 5

Input and output formats are optional as always.
This is code-golf, so the shortest submission in each language wins.

Related

Mathematica, 53 54 bytes
l=Length@#-1&;Tr@Diagonal[#,k]~Table~{k,-l@#,l@#&@@#}&

Pure function taking a 2D-array as input and returning a list. (Entries don't have to be integers or even numbers.) Diagonal[#,k] returns the kth diagonal above (or below, if k is negative) the main diagonal. {k,-l@#,l@#&@@#} computes the range of diagonals needed based on the dimensions of the input array. And Tr sums the entries of each diagonal.

Alternative at the same byte count, but maybe you can golf it further? Those parentheses look bad. Tr@Diagonal[m,#]&/@Range@@({-1,1}(Dimensions[m=#]-1))&

Haskell, 40 37 bytes
z=0:z
foldl1$(.(++z)).zipWith(+).(0:)

Try it online! Usage: (foldl1$(.(++z)).zipWith(+).(0:)) [[1,2,3],[4,5,6]].
Edit: Thanks to  Ørjan Johansen for -3 bytes!
Ungolfed:
z = 0:z
s#t = zipWith(+)(0:s)(t++z)
f m = foldl1 (#) m

z is a list of infinitely many zeros. In f we fold over the list of lists m by combining two lists with the function #. In # the first list s contains  the accumulated column sums so far and the second list t is the new row which should be added. We shift s one element to the right by adding a zero to the front and element-wise add s and t with zipWith(+). Because s might be arbitrarily large, we have to pad t with enough zeros by appending z.

That's shorter point-free: foldl1$(.(++z)).zipWith(+).(0:).

JavaScript (ES6), 65 58 bytes
a=>a.map(b=>b.map((c,i)=>r[i]=~~r[i]+c,r=[,...r]),r=[])&&r

63-byte variant: a=>a.map(r=>r.map(v=>s[i]=~~s[i++]+v,i=--y),s=[],y=a.length)&&s

@Arnauld I agree, reversing was a bad move. But taking the length is too long too!

MATL, 6 bytes
T&XdXs

Try it online! Or verify all test cases.
Explanation
T&Xd   % All diagonals of implicit input arranged as zero-padded columns
Xs     % Sum of each column. Implicitly display

Just curious: Do you think it would be better overall to have s==sum(x(:)), instead of sticking to the MATLAB convention, as MATL seems to do?

@StewieGriffin I have sometimes thought about that. My doubt was more between sum(x) and sum(x,1). For a matrix x, the fact that sum(x) behaves differently if the matrix has 1 row is sometimes annoying. But in the end I decided to go with Matlab, so the two languages are closer; and add some fun(x,1) functions for the most common cases

Jelly, 5 bytes
0;+µ/

Try it online!
How it works
0;+µ/  Main link. Argument: M (matrix / array of rows)

   µ   Combine all links to the left into a chain (arity unknown at parse time) and
       begin a new monadic chain.
    /  Reduce M by that chain. This makes the chain dyadic.
       Let's call the arguments of the chain L and R (both flat arrays).
0;         Prepend a 0 to L.
  +        Perform element-wise addition of the result and R.
           When the chain is called for the n-th time, R has n less elements, so
           the last n elements of L won't have matching elements in R and will be
           left unaltered.

Only the first R to reduce has one less element; it increases by one more element each row.

This is just clever... no ŒD?

@EriktheOutgolfer Once again, ŒD's weird ordering prevented it from being useful.

@Dennis Then I think I'd make something that doesn't have so weird ordering... oh, maybe 3 monads might be incoming.

CJam, 22 21 bytes
Saved 1 byte thanks to Martin Ender
{_,({0\f+}*ee::m<:.+}

Anonymous block expecting the argument on the stack and leaves the result on the stack.
Try it online!
How it works
_                   e# Duplicate the matrix
 ,(                 e# Get its length (# of rows) minus 1
   {0\f+}*          e# Prepend that many 0s to each row
          ee        e# Enumerate; map each row to [index, row]
            ::m<    e# Rotate each row left a number of spaces equal to its index
                :.+ e# Sum each column

05AB1E, 17 bytes
Rvy¹gÅ0«NFÁ}})øO¨

Try it online!
Explanation
R                  # reverse input
 v                 # for each N,y (index, item)
  y¹gÅ0«           # pad y with as many zeroes as the number of rows in the input
        NFÁ}       # rotate each row N times right
            })     # wrap the result in a list
              øO   # sum the columns
                ¨  # remove the last element of the resulting list (the padded zeroes)

J, 7 bytes
+//.@|.

Try it online!
This is pretty simple:
+//.@|.
+/        sum
  /.      on oblique lines
    @|.   on the reversed array

Oblique reversed lines are the diagonals of the array, so this is just summing the diagonals.

Python 2, 62 bytes
lambda M:reduce(lambda x,y:map(sum,zip([0]+x,y+[0]*len(x))),M)

Try it online!

Jelly, 8 bytes
ŒDS€ṙZL$

Try it online!
Half of the code is used to put the results into the correct order.
How?
ŒDS€ṙZL$ - Main link: list of lists of numbers
ŒD       - diagonals (starts with the diagonal containing the top left element,
         -            then the next diagonal to the right, and so on wrapping around)
  S€     - sum €each
       $ - last two links as a monad
     Z   - transpose the matrix
      L  - length (width of the matrix)
    ṙ    - rotate the results left by that amount

Perl 5, 47 bytes
map{$j=--$.;map{@a[$j++]+=$_}split}<>
print"@a"

R, 45 bytes
Unnamed function taking a matrix-class object as input:
function(x)sapply(split(x,col(x)-row(x)),sum)

Using the idea explained in  this answer.

I believe the rules in this challenge allow for you to get rid of the call to unname, but this is an awesome solution regardless!

Octave, 71 bytes
Assuming A is a matrix, for example:
A = [17 4 5;24 16 5; 9 24 10; 1 14 22; 1 21 24; 4 4 17;24 25 17];

Then we have:
[m,n]=size(A);
a=[zeros(m,m-1),A]';
for i=1:m+n-1
trace(a(i:end,:))
end

Notice that transposing the matrix reverses the ordering of the diagonal sums, which saved an overall two bytes in the for loop.
Output:
ans =  24
ans =  29
ans =  22
ans =  39
ans =  47
ans =  70
ans =  43
ans =  9
ans =  5

[m,n]=size(A);for i=1:m+n-1,trace([zeros(m-1,m);A'](i:end,:)),end saves 6 bytes. Octave can do direct indexing and inline assignments. Unfortunately, assuming that a variable exist in the work space prior to running the code is not allowed, so I think you must use input, like this bringing it back up to 75 bytes. Nice approach though, so +1 from me :) And welcome to PPCG! =)

Also, zeros(m-1,m) can be written ~e(m-1,m), saving 4 bytes :) Neat huh?

Vyxal, 7 bytes
ÞD?L‹ǔṠ

Try it Online!
Takes 4 bytes to get it in the right order. If the order didn't matter, it would be 3 bytes (remove the ?L‹ǔ).

Python, 126 bytes
x=input()
f=lambda k:[x[i+k][i]for i in range(len(x)-k)]
a=map(f,range(4)[::-1])
x=zip(*x)
print(map(sum,a+map(f,range(1,4))))

f only works on the lower triangular section, so I transpose it and get the upper triangular section that way. Don't know why the f function doesn't work for negative values (I changed f to be shorter because the part to get the negatives didn't work).

I get an error for the last test case. https://tio.run/nexus/python2#TctBCsMgEAXQvaeYpTYGqpiGBjyJuLA0KUMSKzYB6eVTTVPowMB/zPwtafRhXSgjg57cfLs7GDuTDFajNWiHZwQE9BCdf/R06j1NrB6ZJU7PLtCBfw@Kma6rhWUk6TcGekqMhIh@oeXrtc7cVf//giuWZ9uMES0HxaGxHIzMQVwOXDnsPheIHDKkPCDLqgK110X768tml/0A

C, 148 bytes
Try Online
s;g(int i,int j,int**m,int x){for(s=0;x;x--)s+=m[i++][j++];printf(" %d",s);}
k;f(int n,int**m){for(k=n;--k;)g(k,0,m,n-k);for(;k<n;k++)g(0,k,m,n-k);}

PHP, 81 Bytes
Take Input as 2 D Array

<?foreach($_GET as$k=>$v)foreach($v as$x=>$y)$r[$x-$k]+=$y;ksort($r);print_r($r);

Try it online!

Awk, 67 Bytes
{for(f=0;f++<NF;)s[NF-NR+f]+=$f}END{i=0;while(i++<NR*2)print s[i]}

Ungolfed:
{
    for (f = 0; f++ < NF;)
        s[NF-NR+f] += $f
}
END {
    i = 0
    while (i++ < NR*2)
        print s[i]
}

Awk splits on whitespace $n is the nth field (1-indexed); NF is the number of fields on the line, NR is the number of the current row. Undefined variables are 0 and created on first use.

PHP, 86 bytes
a memory friendly solution in two variants:
<?for($i=$c=count($a=$_GET);--$i>-$c;print$s._)for($s=0,$d=$c;$d--;)$s+=$a[$i+$d][$d];
<?for($i=$c=count($a=$_GET);--$i>-$c;print$s._)for($s=$d=0;$d<$c;)$s+=$a[$i+$d][$d++];

takes input from script parameters, uses underscore as delimiter;
use default settings (not default php.ini) or try them online

Clojure, 81 bytes
#(apply map +(map(fn[i c](concat(repeat(-(count %)i 1)0)c(repeat i 0)))(range)%))

Quite verbose, as it pads lists with zeros so that we can just calculate the column-wise sum.

mathematica 73 bytes
Plus@@@Table[Diagonal[Partition[#1,#2[[1]]],k],{k,-#2[[2]]+1,#2[[1]]-1}]&

This one works for ANY 2D-array m x n  (not only nxn)
input the array at the end of the code like this (the last test case)
[{17,4,5,24,16,5,9,24,10,1,14,22,1,21,24,4,4,17,24,25,17},{3,7}]

{24, 29, 22, 39, 47, 70, 43, 9, 5}

input in form [{a,b,c,d...},{m,n}]

Husk, 6 bytes
mΣ∂m↔T

Try it online.
Explanation:
     T  # Transpose the (implicit) argument; swapping rows/columns
   m↔   # Reverse each row
  ∂     # Take the anti-diagonals of this matrix
mΣ      # And sum each inner anti-diagonal list
        # (after which the result is output implicitly)


text:
Given a Tree generate its Prüfer Code
In graph-theory a Prüfer code is a unique sequence of integers that denotes a specific tree.
You can find the Prüfer code of a tree with the following algorithm taken from Wikipedia:

Consider a labeled tree T with vertices {1, 2, ..., n}. At step i, remove the leaf with the smallest label and set the ith element of the Prüfer sequence to be the label of this leaf's neighbor.

(Note that since it's a leaf it will only have one neighbor).
You should stop the iteration when only two vertices remain in the graph.
Task
Given a labeled tree as input output its Prüfer code.  You may take input in any reasonable manner.  Such as an adjacency matrix or your languages builtin graph representation. (You may not take input as a Prüfer code).
This is code-golf so you should aim to minimize the bytes in your source.
Test cases
Here are some inputs in ASCII with their outputs below.  You do not need to support ASCII input like this.
    3
    |
1---2---4---6
    |
    5

{2,2,2,4}

1---4---3
    |
5---2---6---7
|
8

{4,4,2,6,2,5}

5---1---4   6
    |       |
    2---7---3

{1,1,2,7,3}

Can we take in a rooted tree as input?

Can we take input as something like [[2,1],[2,3],[2,5],[2,4,6]] for the first case? (i.e. each branch)

@xnor Yes you can

I feel like taking an input with edges or paths directed towards a root is  precomputation towards the Prüfer Code. Either way, I think you should be clearer on "You may take input in any reasonable manner (You may not take input as a Prüfer code)."

@xnor Oh I didn't understand what Hyper Neutrino was asking.

@WheatWizard My rooted tree question also goes in that direction, since each vertex points upwards towards the root.

@xnor I think a rooted tree is alright, It is a pretty standard way of representing trees and it doesn't give you that much of an advantage.

@HyperNeutrino Did you assume there is only 4 branches?

@LeakyNun No. The reason I deleted my answer is because my input format made finding the leaves trivial.

@HyperNeutrino I'm not referring to your deleted answer.

@AnderBiguri, because the fourth node deleted is the 2 and it's adjacent to the 4.

@LeakyNun Oh, sorry. In that case still, I'm not assuming anything about the number of branches.

@HyperNeutrino How would you represent subbranches?

@LeakyNun Every leaf has a unique path from the root node. Thus, we represent the tree by a list of all paths to the leaf. But that presents an unfair advantage to me because the leaves are precalculated.

@HyperNeutrino I wouldn't say that it is unfair. It is in essence what a tree is. But good luck finding common branches.

@LeakyNun My deleted answer did that using a strange method (though it is still over twice the length of the other valid Python answer).

Mathematica, 34 bytes
<<Combinatorica`
LabeledTreeToCode

Somebody had to do it....
After loading the Combinatorica package, the function LabeledTreeToCode expects a tree input as an undirected graph with explicitly listed edges and vertices; for example, the input in the second test case could be Graph[{{{1, 4}}, {{4, 3}}, {{4, 2}}, {{2, 5}}, {{2, 6}}, {{6, 7}}, {{5, 8}}}, {1, 2, 3, 4, 5, 6, 7, 8}].

Of course there's a built-in to do this. >_>

Python 3, 136 131 127 bytes
def f(t):
 while len(t)>2:
  m=min(x for x in t if len(t[x])<2);yield t[m][0];del t[m]
  for x in t:m in t[x]and t[x].remove(m)

Takes input as an adjacency matrix. First example:
>>> [*f({1:[2],2:[1,3,4,5],3:[2],4:[2,6],5:[2],6:[4]})]
[2, 2, 2, 4]

well I failed...

@HyperNeutrino You were about 4 seconds faster!

Hehe yup! And about 2.7 times as long! :D gg

You could probably avoid naming your function pruefer

@WheatWizard Right. Still testing and golfing.

del exists? >_>

Now it actually works in all cases.

You can use spaces for single indent and tabs for double.  There are also some places you could use semicolons.

@WheatWizard You're right about the semicolons, but mixing tabs and spaces is an error in Python 3.

Jelly, 31 bytes
FĠLÞḢḢ
0ịµÇHĊṙ@µÇCịṪ,
WÇÐĿḢ€ṖṖḊ

A monadic link which takes a list of pairs of nodes (defining the edges) in any order (and each in any orientation) and returns the Prüfer Code as a list.
Try it online!
How?
FĠLÞḢḢ - Link 1, find leaf location: list of edges (node pairs)
F      - flatten
 Ġ     - group indices by value (sorted smallest to largest by value)
  LÞ   - sort by length (stable sort, so equal lengths remain in prior order)
    ḢḢ - head head (get the first of the first group. If there are leaves this yields
       -   the index of the smallest leaf in the flattened version of the list of edges)

0ịµÇHĊṙ@µÇCịṪ, - Link 2, separate smallest leaf: list with last item a list of edges
0ị             - item at index zero - the list of edges
  µ            - monadic chain separation (call that g)
   Ç           - call last link (1) as a monad (index of smallest leaf if flattened)
    H          - halve
     Ċ         - ceiling (round up)
      ṙ@       - rotate g left by that amount (places the edge to remove at the right)
        µ      - monadic chain separation (call that h)
         Ç     - call last link (1) as a monad (again)
          C    - complement (1-x)
            Ṫ  - tail h (removes and yields the edge)
           ị   - index into, 1-based and modular (gets the other node of the edge)
             , - pair with the modified h
               -    (i.e. [otherNode, restOfTree], ready for the next iteration)

WÇÐĿḢ€ṖṖḊ - Main link: list of edges (node pairs)
W         - wrap in a list (this is so the first iteration works)
  ÐĿ      - loop and collect intermediate results until no more change:
 Ç        -   call last link (2) as a monad
    Ḣ€    - head €ach (get the otherNodes, although the original tree is also collected)
      ṖṖ  - discard the two last results (they are excess to requirements)
        Ḋ - discard the first result (the tree, leaving just the Prüfer Code)

05AB1E, 29 bytes
[Dg#ÐD˜{γé¬`U\X.å©Ï`XK`ˆ®_Ï]¯

Try it online!
Explanation
[Dg#                           # loop until only 1 link (2 vertices) remain
    ÐD                         # quadruple the current list of links
      ˜{                       # flatten and sort values
        γé                     # group by value and order by length of runs
          ¬`U                  # store the smallest leaf in X
             \X                # discard the sorted list and push X
               .å©             # check each link in the list if X is in that link
                  Ï`           # keep only that link
                    XK`ˆ       # add the value that isn't X to the global list
                        ®_Ï    # remove the handled link from the list of links
                           ]   # end loop
                            ¯  # output global list

Clojure, 111 bytes
#(loop[r[]G %](if-let[i(first(sort(remove(set(vals G))(keys G))))](recur(conj r(G i))(dissoc G i))(butlast r)))

Requires the input to be a hash-map, having "leaf-like" labels as keys and "root-like" labels as values. For example:
{1 2, 3 2, 5 2, 4 2, 6 4}
{1 4, 3 4, 4 2, 8 5, 5 2, 7 6, 6 2}

On each iteration it finds the smallest key which is not referenced by any other node, adds it to the result r and removes the node from the graph definition G. if-let goes to else case when G is empty, as first returns nil. Also the last element has to be dropped.

Python 2, 91 bytes
d=input()
while len(d)>2:m=min(d,key=lambda k:len(d[k]));n,=d[m];del d[m];d[n]-={m};print n

Try it online!
Based on L3viathan's solution. Takes a dictionary of sets representing adjacency lists.


text:
Average an array until all numbers are (almost) equal
Given an array of numbers, find out how many iterations of averaging* it takes for the average of every element to be no more than 1 higher or lower than the first element (absolute difference between the array's average and the first element is less than or equal to 1).
*Array averaging
To "average" a number in our array, we take the average of itself, the number behind it, and the number ahead of it. The last number of the array assumes the number ahead of it is the first number of the array (wrapping). Do this for all but the first number of the array, it needs to stay constant. The averages should all be applied at the same time (i.e. don't take the average of a number, put it back into the array, then average the next number).
Example:
ITERATION 0: [-1,4,3.5,7]
          1: [-1, 2.1666666666666665, 4.833333333333333, 3.1666666666666665]
          2: [-1, 2.0, 3.388888888888889, 2.3333333333333335]
          3: [-1, 1.462962962962963, 2.5740740740740744, 1.5740740740740742]
          4: [-1, 1.0123456790123457, 1.8703703703703705, 1.049382716049383]
          5: [-1, 0.6275720164609054, 1.3106995884773662, 0.6399176954732511]
          6: [-1, 0.31275720164609055, 0.8593964334705076, 0.3168724279835391]
          7: [-1, 0.057384545038866065, 0.4963420210333791, 0.058756287151348875]
abs(AVERAGE - FIRST_ELEMENT) = 0.903120713306 (IS LESS THAN 1)
OUTPUT: 7

Other I/O
INPUT >> OUTPUT
[-3, 9]  >>  2
[0, 0, 0, 0]  >>  0
[64, -66, -9, 78, -60]  >>  29
[9, 4, 5, 3, 3, 3, 10, 1, 1, 1]  >>  44
[-6, 5, -4, 3, -2, 1, -1, 2, -3, 4, -5, 6]  >>  70
[100000000, 2.11, 0.0, 16.88, 8.44, 6.33, 16.88, 100000000]  >>  348
[-8245, 6832, 9525, -3397, 5595, -9242, 1954, 6427, 36, -9647, -8887, 3062, -4424, -4806, -3803, 3608, -5115, -3725, -3308, -277]  >>  1038

Though not a part of the challenge; technically we are dealing with absolute values therefore complex numbers should also work. Your program does NOT need to handle complex numbers.:
[(20-1j), (5-4j), 7, (-0-100j)]  >>  15

Notes:

Other mathematical methods are accepted
You are to assume there are at least two elements in the array
This is code-golf so the shortest code in bytes wins

I feel like there's a better mathematical way to doing this than just the straightforward method...

My program is slightly off for the longer test cases due to floating point issues. Is that acceptable?

That's acceptable for me! @HyperNeutrino

How do you get the number 0.8978052126200274 from [-1, 0.057384545038866065, 0.4963420210333791, 0.058756287151348875]?

Yeah, the result should be 0.903120713306

Forgot to change that! Thanks @mbomb007

Perl 6,  83  82 bytes
->\a(\b,|c){(c,{[(b,|$_,b).rotor(3=>-2).map: *.sum/3]}...{(b+.sum)/a~~b-1..b+1})-1}

Try it
->\a(\b,|c){(c,{[(b,|$_,b).rotor(3=>-2).map: *.sum/3]}...{1>abs (b+.sum)/a -b})-1}

Try it (also works for complex numbers
Expanded
->      # pointy block lambda

  \a    # the input array
  (
    \b, # the first value
    |c  # all the rest of the values
  )

{
  (
    # generate a sequence

    c,                 # initialize the sequence starting with the second value

    {                  # bare block lambda with implicit parameter ｢$_｣

      [                # turn the result from a Seq into an array

        ( b, |$_, b )  # re-add the first element
                       # and add it to the end

        .rotor(3=>-2)  # grab 3 at a time, backing up 2

        .map: *.sum/3  # return the average for each sub sequence

      ]
    }

    ...                # keep calling that to generate values until

    {
      1 > abs ( b + .sum )/a - b     # they are almost equal
    }

  ) - 1 # count them and reduce by one (ignore initial value)
}

R, 107 101 98 95 bytes
Edit: -6 bytes thanks to Giuseppe (who has now outgolfed this with his own shorter answer)
function(x){while(abs(mean(x)-x)>1){for(j in seq(y<-x)[-1])x[j]=mean(c(y,y)[j+-1:1]);F=F+1};+F}

Try it online!

This is also 101 bytes but doesn't work since [ screws up. Maybe you can take some inspiration from it.

Though I guess you can get the -3 bytes from mean(x)-x rather than mean(x)-x[1].

@Giuseppe - Thanks!  I love it when 'there were 50 or more warnings...'!  I also had the [ problem, and drop=F made that approach too long...

You can get to 95 bytes using c(y,y) instead of c(y,y[1]) but I found a 90 byter :-)

Jelly, 30 bytes
L‘ṁ@µ+3\÷3;@Ḣ
ÇµS÷L_1ị$Ị¬µÐ¿L’

A monadic link taking the list and returning the number of iterations required.
Test suite at Try it online!
How?
L‘ṁ@µ+3\÷3;@Ḣ - Link 1, perform an iteration: list x
L             - length of x
 ‘            - incremented
  ṁ@          - mould with swapped @rguments (i.e.. [a,b,c,...] -> [a,b,c,...,a])
    µ         - monadic chain separation (call that v)
      3\      - three-wise reduce v with:
     +        -    addition (sum up the overlapping slices of 3)
        ÷3    - divide those by three (get the averages)
            Ḣ - head v (get the first element)
          ;@  - concatenate with swapped @rguments

ÇµS÷L_1ị$Ị¬µÐ¿L’ - Main link: list a
 µ         µÐ¿   - collect results while loop
Ç                -   body: call last link as a monad
                 -   condition:
  S              -     sum
    L            -     length
   ÷             -     divide (average)
        $        -     last two links as a monad:
      1          -       literal one
       ị         -       index into (the first element)
     _           -     subtract
         Ị       -     insignificant (absolute value is less than or equal to 1)
          ¬      -     not
              L  - length (count the results)
               ’ - decrement (the first result is number zero)

Python 2, 130 bytes
x=map(float,input())
l=len(x)
q=0
while abs(x[0]-sum(x)/(l+.0))>=1:x=x[:1]+[sum((x+x)[i-1:i+2])/3for i in range(1,l)];q+=1
print q

Slightly off for the larger test cases Apparently not!
BONUS: Change float to complex and it will be able to handle complex numbers correctly (at a cost of two bytes).
Edited once ehhh.... I found a bug.... fixed now!

My algorithm to produce the examples were slightly wrong, yours works perfectly fine for all inputs now!

@Graviton Oh, that's interesting, I thought mine were off! Thanks! :P

Mathematica, 83 bytes
(a=#;0//.n_/;Mean@a-First@a>=1:>(a={#&@@a,##}&@@Mean/@Partition[a,3,1,{1,2}];n+1))&

JavaScript (ES6), 106 bytes
f=(a,l=a.length,m=a.reduce((s,e)=>s+e-a[0],0))=>m>l|m<-l&&1+f(a.map((e,i)=>i?(a[i-1]+e+a[++i<l?i:0])/3:e))

Haskell, 81 bytes
g l@(a:_)|abs(sum l/sum(1<$l)-a)<1=0|1<2=1+g(a:[(x+y+z)/3|x:y:z:_<-scanr(:)[a]l])

Usage example: g [64,-66,-9,78,-60] -> 29. Try it online!
How it works
g l@(a:b)                -- function g takes a list l where the first element
                         -- is bound to a
    |abs (      ) = 0    -- if the end condition is true, return 0
          sum(1<$l)      -- computes the length of l. The library function "length"
                         -- won't work, because it returns an "Int"
    | 1+g                -- else return 1 + a recursive call with one step of
                         -- averaging
  x:y:z:_<-scanr(:)[a]l  -- picks all 3 element sublists of l appended by a
                         -- the elements are bound to x, y and z

Octave, 146 bytes
function k=f(a)n=numel(a);I=eye(n-1,n)/3;A=[resize(1,1,n);I+circshift(I,[0,1])+circshift(I,[0,2])];k=0;while(abs(mean(a)-a(1))>1)k++;a=A*a;end;end

Try it online!
Multi-line version:
function k = f(a)
    n = numel(a);
    I = eye(n - 1, n) / 3;
    A = [resize(1, 1, n);
         I + circshift(I, [0, 1]) + circshift(I, [0, 2])];
    k = 0;
    while(abs(mean(a) - a(1)) > 1)
        k++;
        a = A * a;
    end;
end

Pretty sure it's rather suboptimal.

Ruby, 88 bytes
f=->a{x,=a;(x-1.0*a.sum/a.size).abs>1?f[[x,*[*a,x].each_cons(3).map{|a|a.sum/3.0}]]+1:0}

Try it online!
Recursive lambda, works with complex numbers. As usual, 2 bytes can be saved in Ruby 2.7+ by using a numbered block parameter. If we can assume that array values will always be provided as floats, we can save some more by avoiding float conversions.

Jelly, 22 bytes
;®Æm3Ƥ®;µḷ/©ạÆmỊ¬µÐ¿L’

Try it online!
How it works
;®Æm3Ƥ®;µḷ/©ạÆmỊ¬µÐ¿L’ - Main link. Takes an array A on the left
                  Ð¿   - While loop, collecting the results
                 µ     -   Condition:
         ḷ/            -     Get the first element of A
           ©           -     Save into the register R
             Æm        -     Get the mean of A
            ạ          -     Absolute difference
               Ị       -     Less than or equal to 1?
                ¬      -     Logical NOT
        µ              -   Body:
 ®                     -     Retrieve the first element of A
;                      -     Append to A
    3Ƥ                 -     Over overlapping windows of size 3:
  Æm                   -       Return the mean
      ®                -     Retrieve the first element of A
       ;               -     Prepend to the means
                    L  - Count the steps of the while loop
                     ’ - Decrement to account for the first iteration (A)

APL (Dyalog Unicode), 35 33 bytes
Saved 2 bytes thanks to Adám (and would have saved 1 with a tip from Bubbler)
{1≥|⊃⍵-⍵⌹=⍨⍵:0⋄1+∇h,3÷⍨3+/⍵,h←⊃⍵}

Try it online!
A recursive function.
Adám's idea of using ⌹ to find the average is really cool. See their explanation in the comments. R is the result of X⌹Y, and it's chosen to minimize the square of the difference between X and the matrix product of R and Y. In this case, since Y is a vector of all 1s, the average of X minimizes that squared difference.
Explanation:
{
  1≥|⊃⍵-(+/÷≢)⍵: 0        ⍝ Base case: If it's the last iteration, return 0
         ⍵⌹=⍨⍵           ⍝ Average of ⍵ (the array)
            =⍨⍵           ⍝ Compare ⍵ to itself to create an array of 1s the same size as ⍵
         ⍵⌹               ⍝ ⍵ divided by that (matrix division)
       ⍵-                  ⍝ Subtract that from all elements of ⍵
      ⊃                    ⍝ Take only the first of those differences
     |                     ⍝ Absolute value
   1≥                      ⍝ Is it less than or equal to 1?
⋄1+∇h,3÷⍨3+/⍵,h←⊃⍵
               h←⊃⍵        ⍝ Assign the first element of ⍵ to h
            ⍵,             ⍝ Append to ⍵ (because of wrapping)
         3+/               ⍝ Take groups of 3 adjacent elements and sum each
      3÷⍨                  ⍝ Divide each sum by 3 (to get average)
    h,                     ⍝ Prepend h, which stays constant
   ∇                       ⍝ Call on this new iteration
 1+                        ⍝ Add 1 to that
}

⊃⍵-(+/÷≢)⍵ → ⊃⍵-⍵⌹=⍨⍵ for -2 bytes.

@Adám Using ⌹ is pretty smart! I need to look up how that works

Think of it as finding the best fit $x$ for the over-determined equation system $\begin{matrix}
x=\omega_1\
x=\omega_2\
x=\omega_3\
⋮=⋮\
x=\omega_n
\end{matrix}$ or actually $\begin{align}
[\omega_1=\omega_1]x=\omega_1\
[\omega_3=\omega_2]x=\omega_2\
[\omega_3=\omega_3]x=\omega_3\
⋮=⋮\
[\omega_n=\omega_n]x=\omega_n
\end{align}$.

@Adám Ah, I think I understand now (at least the vector version). This is a pretty interesting primitive!

Husk, 18 bytes
←V§≈←A¡λ:←¹mAX3S:←

Try it online!
Explanation
←V§≈←A¡λ:←¹mAX3S:←
      ¡λ             Infinitely iterate the following function and build a list of results
               S:←   Append the first element to the list
             X3      Get all the contiguous sequences of 3 elements
           mA        Compute the average of each
        :←¹          Prepend the first element of the original list to this result
                     Now we have an infinite list with all the steps
 V§                  Find the index of the first position where:
     A                 the average
   ≈                   is similar (absolute difference <=1)
    ←                  to the first element
←                    Finally, subtract 1 (lists in Husk are 1-indexed)

05AB1E, 22 bytes
[¬UDÅAXα1›≠#Ćü3ÅAXš¼}¾

Try it online or verify all test cases.
Explanation:
[           # Start an infinite loop:
 ¬          #  Get the first item of the list (without popping the list itself)
            #  (which will use the implicit input-list in the first iteration)
  U         #  Pop and store this first item in variable `X`
 D          #  Duplicate the list
  ÅA        #  Pop and get the arithmetic mean
    Xα      #  Get the absolute difference with `X`
      1›≠   #  If this is NOT larger than 1 (thus it's <=1):
         #  #   Stop the infinite loop
  Ć         #  Enclose the list; append its own first item
   ü3       #  Create overlapping triplets
     ÅA     #  Get the arithmetic mean of each inner triplet
       Xš   #  Prepend `X` at the front of this list
 ¼          #  Increase the counter variable by 1 (0 by default)
}¾          # After the infinite loop: push the counter variable
            # (after which it is output implicitly as result)

R, 90 bytes
function(l){while(abs(mean(l)-l)>1){l[-1]=colMeans(array(l,sum(l|1)+1:0)[1:3,])
F=F+1}
+F}

Try it online!
Test harness stolen from Dominic van Essen's answer.
Uses R's recycling to construct the appropriate neighbor-means to replace in the original array.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Maximal mutually co-prime factorization
Definitions

Two numbers are co-prime if their only positive common divisor is 1.
A list of numbers is mutually co-prime if every pair of numbers within that list are co-prime with each other.
A factorization of number n is a list of numbers whose product is n.

Task
Given a positive number n, output the mutually co-prime factorization of n with the maximum length that does not include 1.
Example
For n=60, the answer is [3,4,5], because 3*4*5=60 and no other mutually co-prime factorization without 1 has length greater than or equal to 3, the length of the factorization.
Rules and freedoms

You can use any reasonable input/output format.
The entries in the output list do not need to be sorted.

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

Scoring
This is code-golf. Shortest answer in bytes wins.

OEIS for the length of the output.

OEIS for the flattened sequence. (With a leading 1.)

Harder follow-up challenge: only adjacent pairs in the resulting list need to be co-prime.

@MartinEnder you can post that yourself.

Is this just a factorization into prime powers?

@PaŭloEbermann yes, it is.

Mathics, 24 bytes
#^#2&@@@FactorInteger@#&

Try it online!

#^#2&@@@FactorInteger@#&[1] returns {1} in Mathematica. But it works in Mathics.

@alephalpha Thanks, it wouldn't even have occurred to me to see whether Mathics implements FactorInteger differently. :)

Brachylog, 4 bytes
ḋḅ×ᵐ

Try it online!
Explanation
       # output is the list of
  ×ᵐ   # products of each
 ḅ     # block of consecutive equal elements
ḋ      # of the prime factors
       # of the input

Congrats on your first Brachylog answer! ...at least I think?

@Fatalize: My 2nd I think. I had this one from before. Definitely my shortest one though :)

05AB1E, 3 5 bytes
+2 bytes to fix the edge case of 1. Thanks to Riley for the patch (and for the test suite, my 05ab1e is not that strong!)
ÒγP1K

Test suite at Try it online!
How?
Ò     - prime factorisation, with duplicates
 γ    - split into chunks of consecutive equal elements
  P   - product of each list
   1  - literal one
    K - removed instances of top from previous
      - implicitly display top of stack

@Adnan is that the best link for "bytes" or is there a formatted code page somewhere?

Yeah, there is a code-page that displays all bytes.

Oh, how'd I miss it >_< Thanks ever so much :)

Does not work for 1.

@LeakyNun fixed up with help :)

MATL, 7 bytes
&YF^1X-

Try it online! Or verify all test cases.
Explanation
Consider input 80  as an example.
&YF    % Implicit input. Push array of unique prime factors and array of exponents
       % STACK: [2 3 5], [4 0 1]
^      % Power, element-wise
       % STACK: [16 1 5]
1      % Push 1
       % STACK: [16 1 5], 1
X-     % Set difference, keeping order. Implicitly display
       % STACK: [16 5]

EDIT (June 9, 2017): YF with two outputs has been modified in release 20.1.0: non-factor primes and their (zero) exponents are skipped. This doesn't affect the above code, which works without requiring any changes (but 1X- could be removed).

I assume the change means 1X- is redundant in the new release... also, that looks like set difference rather than intersection to me.

@ØrjanJohansen Correct on both. Thanks!

CJam, 9 bytes
{mF::#1-}

Try it online!
Simply separates the input into its constituent prime powers and removes 1s (only necessary for input 1).

Haskell, 51 bytes
(2#) is an anonymous function taking an integer and returning a list.
Use as (2#) 99.
m#n|m>n=[]|x<-gcd(m^n)n=[x|x>1]++(m+1)#div n x
(2#)

Try it online!
Inspired by the power trick some people used in the recent squarefree number challenge.

m#n generates factors of n, starting with m.
If m>n, we stop, concluding we've already found all factors.
x=gcd(m^n)n is the largest factor of n whose prime factors are all in m. Note that because smaller m are tested first, this will be 1 unless m is prime.
We include x in the resulting list if it's not 1, and then recurse with the next m, dividing n by x. Note that x and div n x cannot have common factors.
(2#) takes a number and starts finding its factors from 2.

Jelly, 5 bytes
ÆF*/€

Test suite at Try it online!
How?
ÆF*/€ - Main link: n
ÆF    - prime factors as [prime, exponent] pairs
   /€ - reduce €ach with:
  *   - exponentiation

An alternate 6-byte solution in an attempt to find another method that would tie with yours (unfortunately failing): ÆfŒgZP. It has the same number of tokens but too many two-byte atoms ;)

...and like my deleted 05ab1e entry it returns 1 for an input of 1 which is disallowed (the effect of performing an empty product).

:( Well, whoops, overlooked that. Darn. :P

Alice, 10 bytes
Ifw.n$@EOK

Try it online!
Unfortunately, this uses code points as integer I/O again. The test case in the TIO link is input 191808 which decomposes into 64, 81 and 37. Note that this solution prints the prime powers in order from largest to smallest prime, so we get the output %Q@.
For convenience, here is a 16-byte solution with decimal I/O which uses the same core algorithm:
/O/\K
\i>fw.n$@E

Try it online!
Explanation
As the other answers, this decomposes the input into prime powers.
I      Read a code point as input.
f      Compute its prime factorisation a prime/exponent pairs and push them
       to the stack in order from smallest to largest prime.
w      Remember the current IP position on the return address stack. This
       starts a loop.
  .      Duplicate the current exponent. This will be zero once all primes
         have been processed.
  n$@    Terminate the program if this was zero.
  E      Raise the prime to its corresponding power.
  O      Output the result as a character.
K      Return to the w to run the next loop iteration.

mathematica 46 bytes
#[[1]]^#[[2]]&/@If[#==1,#={},FactorInteger@#]&

Try it online!

Nice answer, but it's giving slightly incorrect output for some of the test cases. Currently your code outputs {}; {2}; {3}; {2}; {5}; {2,3}; {7}; {2}; {3}; {2,5}; {11}; {2,3}; {13}; ... but it should output {}; {2}; {3}; {4}; {5}; {2,3}; {7}; {8}; {9}; {2,5}; {11}; {4,3}; {13}; ... instead.

I think I fixed it

Seems to work in TIO indeed. +1 Oh, and welcome to PPCG, I see you're fairly new here. You've probably already seen it, but if not, Tips for golfing in Mathematica might be interesting to read through. Enjoy your stay! :)

If you find yourself accessing the components of # more than # itself, you can save a lot of bytes by using Apply (@@@) instead of Map (/@): #^#2&@@@If...

Pari/GP, 28 bytes
n->[x[1]^x[2]|x<-factor(n)~]

Try it online!

PHP, 62 Bytes
prints a associative array with the prime as key and how often the prime is use as value and nothing for input 1

for($i=2;1<$n=&$argn;)$n%$i?++$i:$n/=$i+!++$r[$i];print_r($r);

Try it online!
Output for 60
Array
(
    [2] => 2
    [3] => 1
    [5] => 1
)

PHP, 82 Bytes
for($i=2;1<$n=&$argn;)$n%$i?++$i:$n/=$i+!($r[$i]=$r[$i]?$r[$i]*$i:$i);print_r($r);

Try it online!
prints nothing for input 1 if you wish a empty array instead and a sorted array it will be a little longer

for($r=[],$i=2;1<$n=&$argn;)$n%$i?++$i:$n/=$i+!($r[$i]=$r[$i]?$r[$i]*$i:$i);sort($r);print_r($r);

Actually, 6 bytes
w⌠iⁿ⌡M

Try it online!
Explanation:
w⌠iⁿ⌡M
w       factor into [prime, exponent] pairs
 ⌠iⁿ⌡M  for each pair:
  i       flatten
   ⁿ      prime**exponent

miniML, 47 bytes
Challenges involving prime factorization are terribly over-represented here, so we are all sadly forced to have factorization in the standard library.
fun n->map(fun p->ipow(fst p)(snd p))(factor n)

Note that the 'mini' in miniml refers to the size of the feature set, not the size of source code written in it.

Ruby, 61 bytes
require 'prime'
->n{(2..n).select{|e|n/e.to_f%1==0&&e.prime?}}

I'm really disappointed after looking 6-7 byte solutions -))

Mathematica, 24 bytes
Power@@@FactorInteger@#&

Too bad @@@* is not a thing. Also, I'd like /@*, @@*, and in fact, change @@@ to /@@, //@ to @@@ or whatever and add the infinite family of //@, ///@, ...