Background
It was a normal presentation that I were in as a audience, until the presenter gave a math problem about repeat taking 2 number out of a list a replacing them with average, claiming that there will be something special about it, and our math teacher, sitting at the end of classroom, exciting rushed to me, and tasked me to code that out.
Task
2 input length and generation
Generate a range, start from 0, with length of
lengthRandomly choose 2 number (or item)
XandYand replace bothXandYwith the average ofXandYRepeat step 2 for
generationtimesOutput minimum, maximum, average, and the processed list.
Example
I'll let this semi-golfed python code explain itself :)
import random
a,b=map(int,input().split())
l=[*range(a)]
s=lambda:random.randint(0,a-1)
for i in range(b):
x,y=s(),s();l[x],l[y]=[(l[x]+l[y])/2]*2
print(min(l),max(l),sum(l)/a,l)
Rules
- Standard rules applies
- Input can be in any convenience form.
- As long as you output is clean, understandable, readable, it is allowed.
- The two random value
X,Yshould be uniform statistically independent random by itself(XandYare not affecting each other no matter what)
what you should do?
- Start golfing right now!
XandYbe equal? \$\endgroup\$