How does Sophia find the median problem?

Hi, everyone
I defined an int array in Sophia. How do I find the middle number in the array
Since Sophia is a functional language, I have been working on this problem for a long time

For example


How do I find an intermediate value in an array?

If possible, please help to write out, thank you

@hanssv.chain @hanssv2 You know what?

  • sort the list (List.sort)
  • if the number of elements is:
    • odd: pick the middle one in the sorted list
    • even: compute the average of the two middle elements (x + y) / 2

Also I think it will help if you don’t think of it as an array :wink:

1 Like