Introduction:
In Dutch, the words leading and suffering, being 'leiden' and 'lijden' respectively, are pronounced the same way. One is written with a "short ei", and one with a "long ij", as we Dutchman would say, but both 'ei' and 'ij' are pronounced [ɛi].
Challenge:
Given a list of numbers, determine which (if any) are leading, and which (if any) are suffering.
A leading number is:
- A positive number
- Has at least four digits
- Is in the highest 50% of the list in terms of value
- Is still in the highest 50% of the list in terms of value, if it's 3rd digit is replaced with its 2nd digit, and it's 2nd digit-position is filled with a 0 (i.e.
1234
would become1024
)
A suffering number is:
- A negative number
- Has at least four digits
- Is in the lowest 50% of the list in terms of value
- Is still in the lowest 50% of the list in terms of value, if it's 3rd digit is replaced with its 2nd digit, and it's 2nd digit-position is filled with a 0 (i.e.
-4321
would become-4031
)
Example:
Input: [5827, 281993, 3918, 3854, -32781, -2739, 37819, 0, 37298, -389]
Output: leading: [5827, 281993, 37819, 37298]
; suffering: [-32781, -2739]
Explanation:
If we sort and split the numbers into two halves, it would be:
[[-32781, -2739, -389, 0, 3798], [3854, 3918, 5827, 37819, 281993]]
There are only two negative numbers with at least four digits: [-32781, -2739]
. Changing the digits as described above wouldn't change their position, so they are both suffering numbers.
For the largest halve, all the numbers have at least four digits: [3854, 3918, 5827, 37819, 281993]
. Changing the digits as described above would change some of their positions however. The 3854
would become 3084
, putting it below 3798
which is in the lowest 50%, so 3854
is not a leading number in this list. The same applies to 3918
which would become 3098
, also putting it below 3798
. The other three numbers are leading, as 5827
which would become 5087
, which is still above 3798
and is in fact still at the same index of the sorted list. So [5827, 37819, 281993]
are the leading numbers.
Challenge rules:
- I/O is flexible. Input-list can be a list of integers, 2D digit lists, list of strings, etc. Output can be a list of lists of integers, two separated lists, two strings, both printed to STDOUT, etc.
- When determining if a number is leading/suffering, we only look at its new position of that number if only its digits are changed accordingly, not after we've applied the modifications to all numbers.
- We output the original numbers, not the modified ones.
- The numbers in the leading and suffering output-lists can be in any order.
- If the size of the input-list is odd, the number at the center doesn't belong to either halve.
- Numbers are guaranteed to remain unique after its modification. So a list like
[0, 1, 1045, 1485]
isn't a valid input-list, since1485
would be equal to1045
after it's modification.
General rules:
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language. - Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (i.e. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input: [5827, 281993, 3918, 3854, -32781, -2739, 37819, 0, 37298, -389]
Output: leading: [5827, 281993, 37819, 37298]; suffering: [-32781, -2739]
Input: [-100, 472, 413, -1782]
Output: leading: []; suffering: [-1782]
Input: [-1234, -1235, -1236, 1234, 1235, 1236]
Output: leading: [1234, 1235, 1236]; suffering: [-1234, -1235, -1236]
Input: [-1919, -1819, -1719, -1619, -1500, -1444, 40, 4444, 18]
Output: leading: [4444]; suffering: []
Input: [-1004, -1111, -1000]
Output: leading: []; suffering: [-1111]
Input: [-1004, -1111, -1010, 1000]
Output: leading: [1000]; suffering: [-1111]
Input: [1000, -1000]
Output: leading: [1000]; suffering: [-1000]
Input: [1000, -5000, 4000]
Output: leading: [4000]; suffering: [-5000]