(a paradox, a paradox, a most ingenious paradox)
This is the first part of a multipart series inspired by different R functions.
The Task
Given a dataset \$D\$ of positive integers, I need you to compute the 5 number summary of \$D\$. However, I'm working on large datasets, so I need your code to be as small as possible, allowing me to store it on my computer.
The five number summary consists of:
- Minimum value
- First quartile (Q1)
- Median / Second quartile (Q2)
- Third quartile (Q3)
- Maximum value
There are several different ways of defining the quartiles, but we will use the one implemented by R:
Definitions:
- Minimum and maximum: the smallest and largest values, respectively.
- Median: the middle value if \$D\$ has an odd number of entries, and the arithmetic mean of the two middle-most values if \$D\$ has an even number of entries. Note that this means the median may be a non-integer value. We have had to Compute the Median before.
- First and Third Quartiles: Divide the data into two halves, including the central element in each half if \$D\$ has an odd number of entries, and find the median value of each half. The median of the lower half is the First Quartile, and the median of the upper half is the Third Quartile.
Examples:
\$D=[1,2,3,4,5]\$. The median is then \$3\$, and the lower half is \$[1,2,3]\$, yielding a first quartile of \$2\$, and the upper half is \$[3,4,5]\$, yielding a third quartile of \$4\$.
\$D=[1,3,3,4,5,6,7,10]\$. The median is \$4.5\$, and the lower half is \$[1,3,3,4]\$, yielding a first quartile of \$3\$, and the upper half is \$[5,6,7,10]\$, yielding a third quartile of \$6.5\$.
Additional rules:
- Input is as an array or your language's nearest equivalent.
- You may assume the array is sorted in either ascending or descending order (but please specify which).
- You may return/print the results in any consistent order, and in whichever flexible format you like, but please denote the order and format in your answer.
- Built-in functions equivalent to
fivenum
are allowed, but please also implement your own solution. - You may not assume each of the five numbers will be an integer.
- Explanations are encouraged.
- This is code-golf, so shortest answer in each language wins!
Randomly generated test cases
1 1 1 1 1 2 2 2 2 2 3 3 4 4 4 4 4 5 5 5 -> 1 1.5 2.5 4 5
1 2 2 2 4 4 5 5 6 7 7 8 9 9 9 9 9 10 10 10 -> 1 4 7 9 10
2 2 2 6 8 10 15 16 21 22 23 24 26 33 35 38 38 45 46 47 48 -> 2 10 23 38 48
1 2 9 -> 1 1.5 2 5.5 9
1 2 3 3 3 4 9 -> 1 2.5 3 3.5 9
1 1 2 5 7 7 8 8 15 16 18 24 24 26 26 27 27 28 28 28 29 29 39 39 40 45 46 48 48 48 48 49 50 52 60 63 72 73 79 85 86 87 88 90 91 93 94 95 95 97 100 -> 1 25 45 76 100
2 2 4 4 6 8 10 11 13 14 14 15 17 21 23 24 26 27 27 28 28 30 31 33 33 34 36 36 38 38 39 40 41 42 42 43 45 45 47 47 47 47 47 48 48 48 50 51 53 53 55 56 56 56 57 57 58 62 62 63 64 64 65 65 66 67 67 67 68 69 69 71 71 71 74 79 80 81 81 81 82 82 83 83 86 86 86 87 89 94 94 94 95 95 97 98 99 100 100 100 -> 2 33.5 54 76.5 100
1 3 3 4 -> 1 2 3 3.5 4
1 3 3 3 4 -> 1 3 3 3 4