Leading and Suffering NumbersStandardise leading zeroes in an input stringThe Unholy numbersFinite Cantor's DiagonalThe Squaring SequenceFind the numbers and calculate outputRange, Reverse, Sum!How many Lynch-Bell numbers are there?Digit OccurrencesSort by what the digit pairs describeMake the biggest and smallest numbers

Modeling the Round (Nearest Integer) function

What can I wear to avoid getting frisked and crotch searched by TSA at the airport?

出かけることにしました - What is the meaning of this?

When applying for a visa has there ever been a case of embassy asking for proof of right to be in the present country?

Do the KKT conditions hold for mixed integer nonlinear problems?

Is it really better for the environment if I take the stairs as opposed to a lift?

Is using a photo reference for pose fair use?

Meaning of “Bulldog drooled courses through his jowls”

Most optimal hallways with random gravity inside?

Use GPLv3 library in a closed system (no software distribution)

Other database besides UTXO?

Examples of problems with non-convex constraint functions but convex feasible region

What are the advantages to banks being located in the City of London (the Square Mile)?

Can every type of linear filter be modelled by a convolution?

How much does freezing grapes longer sweeten them more?

What is gerrymandering called if it's not the result of redrawing districts?

UK inheritance: partner, sibling, child

Can Microsoft employees see my data in Azure?

How can I seal 8 inch round holes in my siding?

Can I exit and reenter a UK station while waiting for a connecting train?

If equal temperament divides octave into 12 equal parts, why hertz differences are not the same but element 12th of two?

Is this a new characteristic function for the primes?

Who inspired the character Geordi La Forge?

Was Hitler exclaiming "Heil Hitler!" himself when saluting?



Leading and Suffering Numbers


Standardise leading zeroes in an input stringThe Unholy numbersFinite Cantor's DiagonalThe Squaring SequenceFind the numbers and calculate outputRange, Reverse, Sum!How many Lynch-Bell numbers are there?Digit OccurrencesSort by what the digit pairs describeMake the biggest and smallest numbers






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









8














$begingroup$


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 become 1024)

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, since 1485 would be equal to 1045 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]









share|improve this question












$endgroup$














  • $begingroup$
    Judging from the test cases, it seems you mean for the 50% to round down when the list's length is odd. You might want to specify that explicitly.
    $endgroup$
    – Grimy
    May 27 at 13:07










  • $begingroup$
    Suggested test case: [1000, -1000]
    $endgroup$
    – Grimy
    May 27 at 13:16










  • $begingroup$
    @Grimy As for your first comment, the rule "If the size of the input-list is odd, the number at the center doesn't belong to either halve" should cover that, right? And added the suggested test case.
    $endgroup$
    – Kevin Cruijssen
    May 27 at 13:21

















8














$begingroup$


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 become 1024)

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, since 1485 would be equal to 1045 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]









share|improve this question












$endgroup$














  • $begingroup$
    Judging from the test cases, it seems you mean for the 50% to round down when the list's length is odd. You might want to specify that explicitly.
    $endgroup$
    – Grimy
    May 27 at 13:07










  • $begingroup$
    Suggested test case: [1000, -1000]
    $endgroup$
    – Grimy
    May 27 at 13:16










  • $begingroup$
    @Grimy As for your first comment, the rule "If the size of the input-list is odd, the number at the center doesn't belong to either halve" should cover that, right? And added the suggested test case.
    $endgroup$
    – Kevin Cruijssen
    May 27 at 13:21













8












8








8


2



$begingroup$


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 become 1024)

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, since 1485 would be equal to 1045 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]









share|improve this question












$endgroup$




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 become 1024)

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, since 1485 would be equal to 1045 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]






code-golf number integer permutations






share|improve this question
















share|improve this question













share|improve this question




share|improve this question








edited May 27 at 13:43







Kevin Cruijssen

















asked May 27 at 12:54









Kevin CruijssenKevin Cruijssen

52.3k7 gold badges85 silver badges252 bronze badges




52.3k7 gold badges85 silver badges252 bronze badges














  • $begingroup$
    Judging from the test cases, it seems you mean for the 50% to round down when the list's length is odd. You might want to specify that explicitly.
    $endgroup$
    – Grimy
    May 27 at 13:07










  • $begingroup$
    Suggested test case: [1000, -1000]
    $endgroup$
    – Grimy
    May 27 at 13:16










  • $begingroup$
    @Grimy As for your first comment, the rule "If the size of the input-list is odd, the number at the center doesn't belong to either halve" should cover that, right? And added the suggested test case.
    $endgroup$
    – Kevin Cruijssen
    May 27 at 13:21
















  • $begingroup$
    Judging from the test cases, it seems you mean for the 50% to round down when the list's length is odd. You might want to specify that explicitly.
    $endgroup$
    – Grimy
    May 27 at 13:07










  • $begingroup$
    Suggested test case: [1000, -1000]
    $endgroup$
    – Grimy
    May 27 at 13:16










  • $begingroup$
    @Grimy As for your first comment, the rule "If the size of the input-list is odd, the number at the center doesn't belong to either halve" should cover that, right? And added the suggested test case.
    $endgroup$
    – Kevin Cruijssen
    May 27 at 13:21















$begingroup$
Judging from the test cases, it seems you mean for the 50% to round down when the list's length is odd. You might want to specify that explicitly.
$endgroup$
– Grimy
May 27 at 13:07




$begingroup$
Judging from the test cases, it seems you mean for the 50% to round down when the list's length is odd. You might want to specify that explicitly.
$endgroup$
– Grimy
May 27 at 13:07












$begingroup$
Suggested test case: [1000, -1000]
$endgroup$
– Grimy
May 27 at 13:16




$begingroup$
Suggested test case: [1000, -1000]
$endgroup$
– Grimy
May 27 at 13:16












$begingroup$
@Grimy As for your first comment, the rule "If the size of the input-list is odd, the number at the center doesn't belong to either halve" should cover that, right? And added the suggested test case.
$endgroup$
– Kevin Cruijssen
May 27 at 13:21




$begingroup$
@Grimy As for your first comment, the rule "If the size of the input-list is odd, the number at the center doesn't belong to either halve" should cover that, right? And added the suggested test case.
$endgroup$
– Kevin Cruijssen
May 27 at 13:21










4 Answers
4






active

oldest

votes


















6
















$begingroup$


05AB1E, 27 24 23 22 21 bytes



(‚εÅmyεD1è0šāǝ}‹y*₄@Ï


Try it online!






share|improve this answer












$endgroup$










  • 1




    $begingroup$
    22 bytes based on your current 23-byter
    $endgroup$
    – Kevin Cruijssen
    May 27 at 13:53










  • $begingroup$
    @KevinCruijssen I just edited my answer to another 22 I found independently. Now to see if we can combine those optimizations for a 21...
    $endgroup$
    – Grimy
    May 27 at 14:03






  • 1




    $begingroup$
    Probably not. I used the © and ®Åm instead of your ÅmUy and X to save a byte, but you now removed the UX as well by doing the Åm ... ‹y after the map, so it's a similar optimization. I actually like yours better, since it doesn't use any unnecessary variables in that case. :)
    $endgroup$
    – Kevin Cruijssen
    May 27 at 14:07










  • $begingroup$
    Dang, very nice find with 0šāǝ! :D Would have never thought of that!
    $endgroup$
    – Kevin Cruijssen
    May 27 at 17:27










  • $begingroup$
    @KevinCruijssen Thanks! There's also D¦0š2Lǝ, which is the same byte-count as D1è0šāǝ.
    $endgroup$
    – Grimy
    May 27 at 19:33


















5
















$begingroup$


Python 2, 119 118 111 107 bytes





lambda a:[[n for n in a if sorted(a)[::d][~len(a)/2]*d<int('0'.join(`n*d`[:2])+`n*d`[3:])>999]for d in-1,1]


Try it online!



Outputs as suffering, leading.






share|improve this answer












$endgroup$






















    2
















    $begingroup$


    Jelly, 30 bytes



    ,NµD2ị;0Ʋ2,3¦ḌƊ>ẠɗƇÆṁ;999Ɗ)N2¦


    Try it online!



    Given the length of Grimy’s 05AB1E answer, I’m sure this can be golfed better, but here it is.






    share|improve this answer










    $endgroup$






















      1
















      $begingroup$


      JavaScript (Node.js), 162 bytes





      a=>[(g=i=>a.filter(n=>n*i>999&(h=t=>a.reduce((a,c)=>a+(c!=n&i*c<i*t(n)),0)>=a.length/2)(x=>x)&h(m=x=>x<0?-m(-x):x>999?m(x/10)*10+x%10:x-x%100+x/10%10)))(1),g(-1)]


      Try it online!



      Anonymous function that take an array of numbers as input and outputs a 2-element array as output. The first element in the output array is an array of leading numbers, the second element in the output array is an array of following numbers.



      // a: input array of numbers
      a=>
      // begin output array
      [
      // define a function g with input i
      // when i is 1, generate leading
      // when i is -1, generate following
      (g=i=>
      // function g returns a subset of a,
      // use filter() to select elements
      a.filter(n=>
      // n must be 4 digits and explicitly
      // positive or negative depending
      // on whether we are calculating
      // leading or following numbers
      n*i>999&
      // function h determines whether
      // the current number is in the
      // larger or smaller half,
      // depending on whether we are
      // calculating the leading or
      // following numbers.
      // argument t defines a
      // transformation that should
      // be applied to th current number
      (h=t=>
      // use reduce() to count the
      // number of numbers greater or
      // less than the transformed
      // current number
      a.reduce((a,c)=>
      // add the current total to...
      a+
      // either 0 or 1 depending on
      // whether the transformed
      // current number is in the
      // opposite group (leading vs
      // following
      (c!=n&i*c<i*t(n)),0)>=
      // are at least half in the
      // opposite group?
      a.length/2)
      // invoke h with the identity
      // transform
      (x=>x)&
      // invoke h again with a
      // transform m that moves the
      // 2nd digit to the 3rd digit and
      // 0's out the 2nd digit.
      // input for m is number x
      h(m=x=>
      // is x negative?
      x<0
      // invoke m with negated input
      // to force it to a positive value
      // and negate the result to
      // convert back to negative
      ?-m(-x)
      // otherwise, does x have 4 or
      // more digits?
      :x>999
      // recursively call m with 1
      // fewer digit, then add digit
      // back to the result
      ?m(x/10)*10+x%10
      // 3 or fewer digits, move
      // the 2nd digit to the 3rd
      // and 0 put the 2nd digit
      :x-x%100+x/10%10
      )
      )
      )
      // invoke g with input 1 for leading
      (1),
      // invoke g with input -1 for following
      g(-1)
      ]





      share|improve this answer












      $endgroup$
















        Your Answer






        StackExchange.ifUsing("editor", function ()
        StackExchange.using("externalEditor", function ()
        StackExchange.using("snippets", function ()
        StackExchange.snippets.init();
        );
        );
        , "code-snippets");

        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "200"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );














        draft saved

        draft discarded
















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186143%2fleading-and-suffering-numbers%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown


























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        6
















        $begingroup$


        05AB1E, 27 24 23 22 21 bytes



        (‚εÅmyεD1è0šāǝ}‹y*₄@Ï


        Try it online!






        share|improve this answer












        $endgroup$










        • 1




          $begingroup$
          22 bytes based on your current 23-byter
          $endgroup$
          – Kevin Cruijssen
          May 27 at 13:53










        • $begingroup$
          @KevinCruijssen I just edited my answer to another 22 I found independently. Now to see if we can combine those optimizations for a 21...
          $endgroup$
          – Grimy
          May 27 at 14:03






        • 1




          $begingroup$
          Probably not. I used the © and ®Åm instead of your ÅmUy and X to save a byte, but you now removed the UX as well by doing the Åm ... ‹y after the map, so it's a similar optimization. I actually like yours better, since it doesn't use any unnecessary variables in that case. :)
          $endgroup$
          – Kevin Cruijssen
          May 27 at 14:07










        • $begingroup$
          Dang, very nice find with 0šāǝ! :D Would have never thought of that!
          $endgroup$
          – Kevin Cruijssen
          May 27 at 17:27










        • $begingroup$
          @KevinCruijssen Thanks! There's also D¦0š2Lǝ, which is the same byte-count as D1è0šāǝ.
          $endgroup$
          – Grimy
          May 27 at 19:33















        6
















        $begingroup$


        05AB1E, 27 24 23 22 21 bytes



        (‚εÅmyεD1è0šāǝ}‹y*₄@Ï


        Try it online!






        share|improve this answer












        $endgroup$










        • 1




          $begingroup$
          22 bytes based on your current 23-byter
          $endgroup$
          – Kevin Cruijssen
          May 27 at 13:53










        • $begingroup$
          @KevinCruijssen I just edited my answer to another 22 I found independently. Now to see if we can combine those optimizations for a 21...
          $endgroup$
          – Grimy
          May 27 at 14:03






        • 1




          $begingroup$
          Probably not. I used the © and ®Åm instead of your ÅmUy and X to save a byte, but you now removed the UX as well by doing the Åm ... ‹y after the map, so it's a similar optimization. I actually like yours better, since it doesn't use any unnecessary variables in that case. :)
          $endgroup$
          – Kevin Cruijssen
          May 27 at 14:07










        • $begingroup$
          Dang, very nice find with 0šāǝ! :D Would have never thought of that!
          $endgroup$
          – Kevin Cruijssen
          May 27 at 17:27










        • $begingroup$
          @KevinCruijssen Thanks! There's also D¦0š2Lǝ, which is the same byte-count as D1è0šāǝ.
          $endgroup$
          – Grimy
          May 27 at 19:33













        6














        6










        6







        $begingroup$


        05AB1E, 27 24 23 22 21 bytes



        (‚εÅmyεD1è0šāǝ}‹y*₄@Ï


        Try it online!






        share|improve this answer












        $endgroup$




        05AB1E, 27 24 23 22 21 bytes



        (‚εÅmyεD1è0šāǝ}‹y*₄@Ï


        Try it online!







        share|improve this answer















        share|improve this answer




        share|improve this answer








        edited May 27 at 14:17

























        answered May 27 at 13:29









        GrimyGrimy

        9,03219 silver badges42 bronze badges




        9,03219 silver badges42 bronze badges










        • 1




          $begingroup$
          22 bytes based on your current 23-byter
          $endgroup$
          – Kevin Cruijssen
          May 27 at 13:53










        • $begingroup$
          @KevinCruijssen I just edited my answer to another 22 I found independently. Now to see if we can combine those optimizations for a 21...
          $endgroup$
          – Grimy
          May 27 at 14:03






        • 1




          $begingroup$
          Probably not. I used the © and ®Åm instead of your ÅmUy and X to save a byte, but you now removed the UX as well by doing the Åm ... ‹y after the map, so it's a similar optimization. I actually like yours better, since it doesn't use any unnecessary variables in that case. :)
          $endgroup$
          – Kevin Cruijssen
          May 27 at 14:07










        • $begingroup$
          Dang, very nice find with 0šāǝ! :D Would have never thought of that!
          $endgroup$
          – Kevin Cruijssen
          May 27 at 17:27










        • $begingroup$
          @KevinCruijssen Thanks! There's also D¦0š2Lǝ, which is the same byte-count as D1è0šāǝ.
          $endgroup$
          – Grimy
          May 27 at 19:33












        • 1




          $begingroup$
          22 bytes based on your current 23-byter
          $endgroup$
          – Kevin Cruijssen
          May 27 at 13:53










        • $begingroup$
          @KevinCruijssen I just edited my answer to another 22 I found independently. Now to see if we can combine those optimizations for a 21...
          $endgroup$
          – Grimy
          May 27 at 14:03






        • 1




          $begingroup$
          Probably not. I used the © and ®Åm instead of your ÅmUy and X to save a byte, but you now removed the UX as well by doing the Åm ... ‹y after the map, so it's a similar optimization. I actually like yours better, since it doesn't use any unnecessary variables in that case. :)
          $endgroup$
          – Kevin Cruijssen
          May 27 at 14:07










        • $begingroup$
          Dang, very nice find with 0šāǝ! :D Would have never thought of that!
          $endgroup$
          – Kevin Cruijssen
          May 27 at 17:27










        • $begingroup$
          @KevinCruijssen Thanks! There's also D¦0š2Lǝ, which is the same byte-count as D1è0šāǝ.
          $endgroup$
          – Grimy
          May 27 at 19:33







        1




        1




        $begingroup$
        22 bytes based on your current 23-byter
        $endgroup$
        – Kevin Cruijssen
        May 27 at 13:53




        $begingroup$
        22 bytes based on your current 23-byter
        $endgroup$
        – Kevin Cruijssen
        May 27 at 13:53












        $begingroup$
        @KevinCruijssen I just edited my answer to another 22 I found independently. Now to see if we can combine those optimizations for a 21...
        $endgroup$
        – Grimy
        May 27 at 14:03




        $begingroup$
        @KevinCruijssen I just edited my answer to another 22 I found independently. Now to see if we can combine those optimizations for a 21...
        $endgroup$
        – Grimy
        May 27 at 14:03




        1




        1




        $begingroup$
        Probably not. I used the © and ®Åm instead of your ÅmUy and X to save a byte, but you now removed the UX as well by doing the Åm ... ‹y after the map, so it's a similar optimization. I actually like yours better, since it doesn't use any unnecessary variables in that case. :)
        $endgroup$
        – Kevin Cruijssen
        May 27 at 14:07




        $begingroup$
        Probably not. I used the © and ®Åm instead of your ÅmUy and X to save a byte, but you now removed the UX as well by doing the Åm ... ‹y after the map, so it's a similar optimization. I actually like yours better, since it doesn't use any unnecessary variables in that case. :)
        $endgroup$
        – Kevin Cruijssen
        May 27 at 14:07












        $begingroup$
        Dang, very nice find with 0šāǝ! :D Would have never thought of that!
        $endgroup$
        – Kevin Cruijssen
        May 27 at 17:27




        $begingroup$
        Dang, very nice find with 0šāǝ! :D Would have never thought of that!
        $endgroup$
        – Kevin Cruijssen
        May 27 at 17:27












        $begingroup$
        @KevinCruijssen Thanks! There's also D¦0š2Lǝ, which is the same byte-count as D1è0šāǝ.
        $endgroup$
        – Grimy
        May 27 at 19:33




        $begingroup$
        @KevinCruijssen Thanks! There's also D¦0š2Lǝ, which is the same byte-count as D1è0šāǝ.
        $endgroup$
        – Grimy
        May 27 at 19:33













        5
















        $begingroup$


        Python 2, 119 118 111 107 bytes





        lambda a:[[n for n in a if sorted(a)[::d][~len(a)/2]*d<int('0'.join(`n*d`[:2])+`n*d`[3:])>999]for d in-1,1]


        Try it online!



        Outputs as suffering, leading.






        share|improve this answer












        $endgroup$



















          5
















          $begingroup$


          Python 2, 119 118 111 107 bytes





          lambda a:[[n for n in a if sorted(a)[::d][~len(a)/2]*d<int('0'.join(`n*d`[:2])+`n*d`[3:])>999]for d in-1,1]


          Try it online!



          Outputs as suffering, leading.






          share|improve this answer












          $endgroup$

















            5














            5










            5







            $begingroup$


            Python 2, 119 118 111 107 bytes





            lambda a:[[n for n in a if sorted(a)[::d][~len(a)/2]*d<int('0'.join(`n*d`[:2])+`n*d`[3:])>999]for d in-1,1]


            Try it online!



            Outputs as suffering, leading.






            share|improve this answer












            $endgroup$




            Python 2, 119 118 111 107 bytes





            lambda a:[[n for n in a if sorted(a)[::d][~len(a)/2]*d<int('0'.join(`n*d`[:2])+`n*d`[3:])>999]for d in-1,1]


            Try it online!



            Outputs as suffering, leading.







            share|improve this answer















            share|improve this answer




            share|improve this answer








            edited May 28 at 7:48

























            answered May 27 at 13:13









            TFeldTFeld

            18.7k3 gold badges14 silver badges58 bronze badges




            18.7k3 gold badges14 silver badges58 bronze badges
























                2
















                $begingroup$


                Jelly, 30 bytes



                ,NµD2ị;0Ʋ2,3¦ḌƊ>ẠɗƇÆṁ;999Ɗ)N2¦


                Try it online!



                Given the length of Grimy’s 05AB1E answer, I’m sure this can be golfed better, but here it is.






                share|improve this answer










                $endgroup$



















                  2
















                  $begingroup$


                  Jelly, 30 bytes



                  ,NµD2ị;0Ʋ2,3¦ḌƊ>ẠɗƇÆṁ;999Ɗ)N2¦


                  Try it online!



                  Given the length of Grimy’s 05AB1E answer, I’m sure this can be golfed better, but here it is.






                  share|improve this answer










                  $endgroup$

















                    2














                    2










                    2







                    $begingroup$


                    Jelly, 30 bytes



                    ,NµD2ị;0Ʋ2,3¦ḌƊ>ẠɗƇÆṁ;999Ɗ)N2¦


                    Try it online!



                    Given the length of Grimy’s 05AB1E answer, I’m sure this can be golfed better, but here it is.






                    share|improve this answer










                    $endgroup$




                    Jelly, 30 bytes



                    ,NµD2ị;0Ʋ2,3¦ḌƊ>ẠɗƇÆṁ;999Ɗ)N2¦


                    Try it online!



                    Given the length of Grimy’s 05AB1E answer, I’m sure this can be golfed better, but here it is.







                    share|improve this answer













                    share|improve this answer




                    share|improve this answer










                    answered May 27 at 22:28









                    Nick KennedyNick Kennedy

                    7,2991 gold badge9 silver badges19 bronze badges




                    7,2991 gold badge9 silver badges19 bronze badges
























                        1
















                        $begingroup$


                        JavaScript (Node.js), 162 bytes





                        a=>[(g=i=>a.filter(n=>n*i>999&(h=t=>a.reduce((a,c)=>a+(c!=n&i*c<i*t(n)),0)>=a.length/2)(x=>x)&h(m=x=>x<0?-m(-x):x>999?m(x/10)*10+x%10:x-x%100+x/10%10)))(1),g(-1)]


                        Try it online!



                        Anonymous function that take an array of numbers as input and outputs a 2-element array as output. The first element in the output array is an array of leading numbers, the second element in the output array is an array of following numbers.



                        // a: input array of numbers
                        a=>
                        // begin output array
                        [
                        // define a function g with input i
                        // when i is 1, generate leading
                        // when i is -1, generate following
                        (g=i=>
                        // function g returns a subset of a,
                        // use filter() to select elements
                        a.filter(n=>
                        // n must be 4 digits and explicitly
                        // positive or negative depending
                        // on whether we are calculating
                        // leading or following numbers
                        n*i>999&
                        // function h determines whether
                        // the current number is in the
                        // larger or smaller half,
                        // depending on whether we are
                        // calculating the leading or
                        // following numbers.
                        // argument t defines a
                        // transformation that should
                        // be applied to th current number
                        (h=t=>
                        // use reduce() to count the
                        // number of numbers greater or
                        // less than the transformed
                        // current number
                        a.reduce((a,c)=>
                        // add the current total to...
                        a+
                        // either 0 or 1 depending on
                        // whether the transformed
                        // current number is in the
                        // opposite group (leading vs
                        // following
                        (c!=n&i*c<i*t(n)),0)>=
                        // are at least half in the
                        // opposite group?
                        a.length/2)
                        // invoke h with the identity
                        // transform
                        (x=>x)&
                        // invoke h again with a
                        // transform m that moves the
                        // 2nd digit to the 3rd digit and
                        // 0's out the 2nd digit.
                        // input for m is number x
                        h(m=x=>
                        // is x negative?
                        x<0
                        // invoke m with negated input
                        // to force it to a positive value
                        // and negate the result to
                        // convert back to negative
                        ?-m(-x)
                        // otherwise, does x have 4 or
                        // more digits?
                        :x>999
                        // recursively call m with 1
                        // fewer digit, then add digit
                        // back to the result
                        ?m(x/10)*10+x%10
                        // 3 or fewer digits, move
                        // the 2nd digit to the 3rd
                        // and 0 put the 2nd digit
                        :x-x%100+x/10%10
                        )
                        )
                        )
                        // invoke g with input 1 for leading
                        (1),
                        // invoke g with input -1 for following
                        g(-1)
                        ]





                        share|improve this answer












                        $endgroup$



















                          1
















                          $begingroup$


                          JavaScript (Node.js), 162 bytes





                          a=>[(g=i=>a.filter(n=>n*i>999&(h=t=>a.reduce((a,c)=>a+(c!=n&i*c<i*t(n)),0)>=a.length/2)(x=>x)&h(m=x=>x<0?-m(-x):x>999?m(x/10)*10+x%10:x-x%100+x/10%10)))(1),g(-1)]


                          Try it online!



                          Anonymous function that take an array of numbers as input and outputs a 2-element array as output. The first element in the output array is an array of leading numbers, the second element in the output array is an array of following numbers.



                          // a: input array of numbers
                          a=>
                          // begin output array
                          [
                          // define a function g with input i
                          // when i is 1, generate leading
                          // when i is -1, generate following
                          (g=i=>
                          // function g returns a subset of a,
                          // use filter() to select elements
                          a.filter(n=>
                          // n must be 4 digits and explicitly
                          // positive or negative depending
                          // on whether we are calculating
                          // leading or following numbers
                          n*i>999&
                          // function h determines whether
                          // the current number is in the
                          // larger or smaller half,
                          // depending on whether we are
                          // calculating the leading or
                          // following numbers.
                          // argument t defines a
                          // transformation that should
                          // be applied to th current number
                          (h=t=>
                          // use reduce() to count the
                          // number of numbers greater or
                          // less than the transformed
                          // current number
                          a.reduce((a,c)=>
                          // add the current total to...
                          a+
                          // either 0 or 1 depending on
                          // whether the transformed
                          // current number is in the
                          // opposite group (leading vs
                          // following
                          (c!=n&i*c<i*t(n)),0)>=
                          // are at least half in the
                          // opposite group?
                          a.length/2)
                          // invoke h with the identity
                          // transform
                          (x=>x)&
                          // invoke h again with a
                          // transform m that moves the
                          // 2nd digit to the 3rd digit and
                          // 0's out the 2nd digit.
                          // input for m is number x
                          h(m=x=>
                          // is x negative?
                          x<0
                          // invoke m with negated input
                          // to force it to a positive value
                          // and negate the result to
                          // convert back to negative
                          ?-m(-x)
                          // otherwise, does x have 4 or
                          // more digits?
                          :x>999
                          // recursively call m with 1
                          // fewer digit, then add digit
                          // back to the result
                          ?m(x/10)*10+x%10
                          // 3 or fewer digits, move
                          // the 2nd digit to the 3rd
                          // and 0 put the 2nd digit
                          :x-x%100+x/10%10
                          )
                          )
                          )
                          // invoke g with input 1 for leading
                          (1),
                          // invoke g with input -1 for following
                          g(-1)
                          ]





                          share|improve this answer












                          $endgroup$

















                            1














                            1










                            1







                            $begingroup$


                            JavaScript (Node.js), 162 bytes





                            a=>[(g=i=>a.filter(n=>n*i>999&(h=t=>a.reduce((a,c)=>a+(c!=n&i*c<i*t(n)),0)>=a.length/2)(x=>x)&h(m=x=>x<0?-m(-x):x>999?m(x/10)*10+x%10:x-x%100+x/10%10)))(1),g(-1)]


                            Try it online!



                            Anonymous function that take an array of numbers as input and outputs a 2-element array as output. The first element in the output array is an array of leading numbers, the second element in the output array is an array of following numbers.



                            // a: input array of numbers
                            a=>
                            // begin output array
                            [
                            // define a function g with input i
                            // when i is 1, generate leading
                            // when i is -1, generate following
                            (g=i=>
                            // function g returns a subset of a,
                            // use filter() to select elements
                            a.filter(n=>
                            // n must be 4 digits and explicitly
                            // positive or negative depending
                            // on whether we are calculating
                            // leading or following numbers
                            n*i>999&
                            // function h determines whether
                            // the current number is in the
                            // larger or smaller half,
                            // depending on whether we are
                            // calculating the leading or
                            // following numbers.
                            // argument t defines a
                            // transformation that should
                            // be applied to th current number
                            (h=t=>
                            // use reduce() to count the
                            // number of numbers greater or
                            // less than the transformed
                            // current number
                            a.reduce((a,c)=>
                            // add the current total to...
                            a+
                            // either 0 or 1 depending on
                            // whether the transformed
                            // current number is in the
                            // opposite group (leading vs
                            // following
                            (c!=n&i*c<i*t(n)),0)>=
                            // are at least half in the
                            // opposite group?
                            a.length/2)
                            // invoke h with the identity
                            // transform
                            (x=>x)&
                            // invoke h again with a
                            // transform m that moves the
                            // 2nd digit to the 3rd digit and
                            // 0's out the 2nd digit.
                            // input for m is number x
                            h(m=x=>
                            // is x negative?
                            x<0
                            // invoke m with negated input
                            // to force it to a positive value
                            // and negate the result to
                            // convert back to negative
                            ?-m(-x)
                            // otherwise, does x have 4 or
                            // more digits?
                            :x>999
                            // recursively call m with 1
                            // fewer digit, then add digit
                            // back to the result
                            ?m(x/10)*10+x%10
                            // 3 or fewer digits, move
                            // the 2nd digit to the 3rd
                            // and 0 put the 2nd digit
                            :x-x%100+x/10%10
                            )
                            )
                            )
                            // invoke g with input 1 for leading
                            (1),
                            // invoke g with input -1 for following
                            g(-1)
                            ]





                            share|improve this answer












                            $endgroup$




                            JavaScript (Node.js), 162 bytes





                            a=>[(g=i=>a.filter(n=>n*i>999&(h=t=>a.reduce((a,c)=>a+(c!=n&i*c<i*t(n)),0)>=a.length/2)(x=>x)&h(m=x=>x<0?-m(-x):x>999?m(x/10)*10+x%10:x-x%100+x/10%10)))(1),g(-1)]


                            Try it online!



                            Anonymous function that take an array of numbers as input and outputs a 2-element array as output. The first element in the output array is an array of leading numbers, the second element in the output array is an array of following numbers.



                            // a: input array of numbers
                            a=>
                            // begin output array
                            [
                            // define a function g with input i
                            // when i is 1, generate leading
                            // when i is -1, generate following
                            (g=i=>
                            // function g returns a subset of a,
                            // use filter() to select elements
                            a.filter(n=>
                            // n must be 4 digits and explicitly
                            // positive or negative depending
                            // on whether we are calculating
                            // leading or following numbers
                            n*i>999&
                            // function h determines whether
                            // the current number is in the
                            // larger or smaller half,
                            // depending on whether we are
                            // calculating the leading or
                            // following numbers.
                            // argument t defines a
                            // transformation that should
                            // be applied to th current number
                            (h=t=>
                            // use reduce() to count the
                            // number of numbers greater or
                            // less than the transformed
                            // current number
                            a.reduce((a,c)=>
                            // add the current total to...
                            a+
                            // either 0 or 1 depending on
                            // whether the transformed
                            // current number is in the
                            // opposite group (leading vs
                            // following
                            (c!=n&i*c<i*t(n)),0)>=
                            // are at least half in the
                            // opposite group?
                            a.length/2)
                            // invoke h with the identity
                            // transform
                            (x=>x)&
                            // invoke h again with a
                            // transform m that moves the
                            // 2nd digit to the 3rd digit and
                            // 0's out the 2nd digit.
                            // input for m is number x
                            h(m=x=>
                            // is x negative?
                            x<0
                            // invoke m with negated input
                            // to force it to a positive value
                            // and negate the result to
                            // convert back to negative
                            ?-m(-x)
                            // otherwise, does x have 4 or
                            // more digits?
                            :x>999
                            // recursively call m with 1
                            // fewer digit, then add digit
                            // back to the result
                            ?m(x/10)*10+x%10
                            // 3 or fewer digits, move
                            // the 2nd digit to the 3rd
                            // and 0 put the 2nd digit
                            :x-x%100+x/10%10
                            )
                            )
                            )
                            // invoke g with input 1 for leading
                            (1),
                            // invoke g with input -1 for following
                            g(-1)
                            ]






                            share|improve this answer















                            share|improve this answer




                            share|improve this answer








                            edited May 30 at 5:40

























                            answered May 28 at 21:26









                            danadana

                            2,4911 gold badge8 silver badges9 bronze badges




                            2,4911 gold badge8 silver badges9 bronze badges































                                draft saved

                                draft discarded















































                                If this is an answer to a challenge…



                                • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                  Explanations of your answer make it more interesting to read and are very much encouraged.


                                • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                More generally…



                                • …Please make sure to answer the question and provide sufficient detail.


                                • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f186143%2fleading-and-suffering-numbers%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown









                                Popular posts from this blog

                                Tamil (spriik) Luke uk diar | Nawigatjuun

                                Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?