I'm resubmitting http://arclanguage.org/item?id=16697 because we didn't do it justice the first time around. I could swear I read it, and yet apparently I didn't notice many things:
b) The idea of overloading * analogously to +. And of making avg variadic. zck, do you want to update anarki? I'm happy to do it otherwise.
c) Quotable quote: "I thought of no simple way to do this but functionally, using recursion. The second place winner, who wrote in Python, approached this imperatively, using mutable state. We actually had to explain our solutions to each other, as the minified versions were not easy to gather the algorithm from. Programming styles can be restrictive."
All this was worthy of comment the first time it was submitted. Thanks, zck.
import math,itertools as i
def f(k,p):
while(len(p)>k):
m=()
for r in i.combinations(p,2):
d=math.sqrt(sum(map(lambda x,y:(x-y)**2,*r)))
if d<m:m=d;x,y=r
t=p.remove;t(x);t(y);p+=[map(lambda g,h:(g+h)/2,x,y)]
print p
Well, essentially we already have 'avg:list as the variadic version. In fact, it looks like we can shave off two characters:
(map(fn e avg.e)r t)
(map avg:list r t)
I don't remember ever using 'avg except maybe to average some time measurements at the REPL, and I think the idiom (avg:accum ...) comes in handy for that. But I generally don't use arithmetic operators in my programs, probably due to the subject matter I choose.
After I wrote that comment it seemed to me that variadic is more fundamental, because you can always convert lists using apply. But you're right that it's not hard to bounce between the two.